Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smartblocks",
"version": "1.12.0",
"version": "1.12.1",
"description": "Create custom and programmable templates from within Roam!",
"main": "./build/main.js",
"scripts": {
Expand Down
42 changes: 39 additions & 3 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1742,8 +1742,42 @@ export const COMMANDS: {
{
text: "CLIPBOARDCOPY",
help: "Writes text to the clipboard\n\n1: text",
handler: (text = "") => {
navigator.clipboard.writeText(text);
handler: async (text = "") => {
try {
// Try modern clipboard API first
if (navigator.clipboard && navigator.clipboard.writeText) {
await navigator.clipboard.writeText(text);
return "";
}
} catch (error) {
console.warn("Clipboard API failed, trying fallback:", error);
}

// Fallback for Safari and other browsers
let textArea: HTMLTextAreaElement | null = null;
try {
textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();

const successful = document.execCommand("copy");

if (!successful) {
throw new Error("execCommand('copy') failed");
}
} catch (e) {
const error = e as Error;
console.error("Failed to copy to clipboard:", error);
} finally {
if (textArea?.parentNode) {
textArea.parentNode.removeChild(textArea);
}
}
return "";
},
},
Expand Down Expand Up @@ -2474,7 +2508,9 @@ const processBlockTextToPromises = (s: string) => {
return {
args: s.flatMap((c) => flattenText(c)),
nodeProps: s.reduce((prev, cur) => {
const nodeProps = { ...cur[0] } || ({} as InputTextNode);
const nodeProps = cur[0]
? { ...cur[0] }
: ({} as InputTextNode);
const { text, uid, children, ...rest } = nodeProps;
return { ...prev, ...rest };
}, {}),
Expand Down
Loading