diff --git a/package-lock.json b/package-lock.json index ab83257..9456a3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "smartblocks", - "version": "1.12.0", + "version": "1.12.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "smartblocks", - "version": "1.12.0", + "version": "1.12.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 228c2a4..884d965 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/utils/core.ts b/src/utils/core.ts index bf2f282..0d50b50 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -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 ""; }, }, @@ -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 }; }, {}),