@protonradio/proton-ui 0.11.18-beta.3 → 0.11.18-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils/copy.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=async(o,c)=>{let e=!1;const a=l=>{const n=l instanceof Error?l.message:"Failed to copy to clipboard";console.error(n),c==null||c(new Error(n))};if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){console.log("clipboard API IS available, using clipboard API",{navigator});try{await navigator.clipboard.writeText(o),e=!0}catch(l){console.log("clipboard API failed, trying fallback",{error:l});try{e=d(o),e||(console.log("fallback unsuccessful, calling onErrorCallback",{error:l}),a(l))}catch(n){console.log("fallback errored, calling onErrorCallback",{fallbackError:n}),a(n)}}}else{console.log("clipboard API NOT available, using fallback");try{e=d(o),console.log("fallback result",{copySuccess:e,text:o}),e?console.log("fallback successful - copy should have worked"):(console.log("fallback unsuccessful, calling onErrorCallback",{copySuccess:e}),a(new Error("Failed to copy to clipboard: Clipboard API not available and fallback method failed")))}catch(l){console.log("fallback errored, calling onErrorCallback",{error:l}),a(l)}}return console.log("copyTextToClipboard final result",{copySuccess:e}),e},d=(o,{target:c=document.body}={})=>{if(typeof o!="string")throw new TypeError(`Expected parameter \`text\` to be a \`string\`, got \`${typeof o}\`.`);if(!document.execCommand)return console.error("document.execCommand is not available"),!1;const e=document.createElement("textarea"),a=document.activeElement;e.value=o;const i=document.body;e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="2px",e.style.height="2px",e.style.padding="0",e.style.border="none",e.style.margin="0",e.style.outline="none",e.style.boxShadow="none",e.style.background="transparent",e.style.opacity="0",e.style.zIndex="-1",e.style.fontSize="12pt",e.setAttribute("readonly",""),e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true");const l=document.getSelection(),n=l.rangeCount>0&&l.getRangeAt(0);i.appendChild(e),e.focus(),e.select();try{e.setSelectionRange&&e.setSelectionRange(0,o.length)}catch(t){console.log("setSelectionRange failed (non-critical)",t)}let r=!1,s=null;try{const t=e.selectionStart===0&&e.selectionEnd===o.length;console.log("element selection state before execCommand",{isSelected:t,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd,textLength:o.length,isConnected:e.isConnected,ownerDocument:e.ownerDocument===document}),!t&&o.length>0&&(e.focus(),e.select(),e.setSelectionRange&&e.setSelectionRange(0,o.length)),r=document.execCommand("copy"),console.log("document.execCommand('copy') result",{isSuccess:r,textLength:o.length}),r||console.warn("execCommand returned false - copy failed")}catch(t){s=t,console.error("document.execCommand('copy') threw an error",t)}return e.remove(),n&&(l.removeAllRanges(),l.addRange(n)),a instanceof HTMLElement&&setTimeout(()=>{try{a.focus()}catch(t){console.log("Could not restore focus (non-critical)",t)}},0),s?(console.error("execCommand error",s),!1):r};exports.copyTextToClipboard=g;
|
|
2
2
|
//# sourceMappingURL=copy.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.cjs.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n\n const onErrorCallback = (error: Error) => {\n const errorMessage =\n error instanceof Error ? error.message : \"Failed to copy to clipboard\";\n\n console.error(errorMessage);\n onError?.(new Error(errorMessage));\n };\n\n // Check if clipboard API is available\n // Note: navigator.clipboard may be undefined in non-secure contexts (non-HTTPS)\n const isClipboardAvailable =\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\";\n\n if (isClipboardAvailable) {\n console.log(\"clipboard API IS available, using clipboard API\", {\n navigator,\n });\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n } catch (error) {\n // If clipboard API fails, try fallback\n\n console.log(\"clipboard API failed, trying fallback\", { error });\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n error,\n });\n onErrorCallback(error);\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Use fallback method when clipboard API is not available\n\n console.log(\"clipboard API NOT available, using fallback\");\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n console.log(\"fallback result\", { copySuccess, text });\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n copySuccess,\n });\n onErrorCallback(\n new Error(\n \"Failed to copy to clipboard: Clipboard API not available and fallback method failed. This may be due to browser security restrictions (e.g., iframe permissions, non-HTTPS context).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // Note: In some contexts (iframes, cross-origin), execCommand may return true\n // but the copy may still be blocked by the browser. There's no reliable way to verify.\n }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\n console.log(\"copyTextToClipboard final result\", { copySuccess });\n return copySuccess;\n};\n\n/**\n * Fallback legacy function to copy text to clipboard for browsers that don't support navigator.clipboard.writeText\n * @reference https://github.com/sindresorhus/copy-text-to-clipboard/blob/main/index.js\n * @deprecated Use navigator.clipboard.writeText instead\n */\nconst DEPRECATED_copyTextToClipboard = (\n text,\n { target = document.body } = {}\n) => {\n if (typeof text !== \"string\") {\n throw new TypeError(\n `Expected parameter \\`text\\` to be a \\`string\\`, got \\`${typeof text}\\`.`\n );\n }\n\n // Check if execCommand is available\n if (!document.execCommand) {\n console.error(\"document.execCommand is not available\");\n return false;\n }\n\n const element = document.createElement(\"textarea\");\n const previouslyFocusedElement = document.activeElement;\n\n element.value = text;\n\n // Prevent keyboard from showing on mobile\n element.setAttribute(\"readonly\", \"\");\n\n element.style.contain = \"strict\";\n element.style.position = \"absolute\";\n element.style.left = \"-9999px\";\n element.style.top = \"-9999px\";\n element.style.width = \"2em\";\n element.style.height = \"2em\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n target.append(element);\n\n // Focus and select the element\n // Use setTimeout to ensure the element is in the DOM and can receive focus\n element.focus();\n element.select();\n\n // Explicit selection workaround for iOS and ensure selection is set\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail on non-text inputs, but that's okay\n console.log(\"setSelectionRange failed (non-critical)\", e);\n }\n\n let isSuccess = false;\n let execCommandError = null;\n\n // Small delay to ensure the element is properly focused and selected\n // This is especially important in some browsers/contexts\n try {\n // Check if the element is actually selected\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n console.log(\"element selection state\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n });\n\n if (!isSelected && text.length > 0) {\n // Try to select again\n element.select();\n element.setSelectionRange(0, text.length);\n }\n\n isSuccess = document.execCommand(\"copy\");\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n });\n\n // Additional verification: check if execCommand actually worked\n // Some browsers return true even when copy fails\n if (isSuccess) {\n console.log(\"execCommand returned true - copy should have succeeded\");\n } else {\n console.warn(\"execCommand returned false - copy failed\");\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Verify the copy worked by checking if we can read back (if possible)\n // Note: This is a best-effort check since we can't always read clipboard\n\n element.remove();\n\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Get the focus back on the previously focused element, if any\n if (previouslyFocusedElement instanceof HTMLElement) {\n previouslyFocusedElement.focus();\n }\n\n if (execCommandError) {\n console.error(\"execCommand error\", execCommandError);\n return false;\n }\n\n return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","selection","originalRange","e","isSuccess","execCommandError","isSelected"],"mappings":"gFAAa,MAAAA,EAAsB,MACjCC,EACAC,IACqB,CACrB,IAAIC,EAAc,GAEZ,MAAAC,EAAmBC,GAAiB,CACxC,MAAMC,EACJD,aAAiB,MAAQA,EAAM,QAAU,8BAE3C,QAAQ,MAAMC,CAAY,EAChBJ,GAAA,MAAAA,EAAA,IAAI,MAAMI,CAAY,EAAC,EAUnC,GAJE,OAAO,UAAc,KACrB,UAAU,WACV,OAAO,UAAU,UAAU,WAAc,WAEjB,CACxB,QAAQ,IAAI,kDAAmD,CAC7D,SAAA,CACD,EACG,GAAA,CACI,MAAA,UAAU,UAAU,UAAUL,CAAI,EAC1BE,EAAA,SACPE,EAAO,CAGd,QAAQ,IAAI,wCAAyC,CAAE,MAAAA,CAAO,CAAA,EAC1D,GAAA,CACFF,EAAcI,EAA+BN,CAAI,EAE5CE,IACH,QAAQ,IAAI,iDAAkD,CAC5D,MAAAE,CAAA,CACD,EACDD,EAAgBC,CAAK,SAEhBG,EAAe,CACtB,QAAQ,IAAI,4CAA6C,CACvD,cAAAA,CAAA,CACD,EACDJ,EAAgBI,CAAa,CAC/B,CACF,CAAA,KACK,CAGL,QAAQ,IAAI,8CAA8C,EACtD,GAAA,CACFL,EAAcI,EAA+BN,CAAI,EACjD,QAAQ,IAAI,kBAAmB,CAAE,YAAAE,EAAa,KAAAF,CAAM,CAAA,EAC/CE,EAUH,QAAQ,IAAI,+CAA+C,GAT3D,QAAQ,IAAI,iDAAkD,CAC5D,YAAAA,CAAA,CACD,EACDC,EACE,IAAI,MACF,sLACF,CAAA,SAOGC,EAAO,CACd,QAAQ,IAAI,4CAA6C,CAAE,MAAAA,CAA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gB,GAAchB,EAAK,OAAS,IAE/BS,EAAQ,OAAO,EACPA,EAAA,kBAAkB,EAAGT,EAAK,MAAM,GAG9Bc,EAAA,SAAS,YAAY,MAAM,EACvC,QAAQ,IAAI,sCAAuC,CACjD,UAAAA,EACA,WAAYd,EAAK,MAAA,CAClB,EAIGc,EACF,QAAQ,IAAI,wDAAwD,EAEpE,QAAQ,KAAK,0CAA0C,QAElDV,EAAO,CACKW,EAAAX,EACX,QAAA,MAAM,8CAA+CA,CAAK,CACpE,CAiBA,OAZAK,EAAQ,OAAO,EAEXG,IACFD,EAAU,gBAAgB,EAC1BA,EAAU,SAASC,CAAa,GAI9BF,aAAoC,aACtCA,EAAyB,MAAM,EAG7BK,GACM,QAAA,MAAM,oBAAqBA,CAAgB,EAC5C,IAGFD,CACT"}
|
|
1
|
+
{"version":3,"file":"copy.cjs.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n\n const onErrorCallback = (error: Error) => {\n const errorMessage =\n error instanceof Error ? error.message : \"Failed to copy to clipboard\";\n\n console.error(errorMessage);\n onError?.(new Error(errorMessage));\n };\n\n // Check if clipboard API is available\n // Note: navigator.clipboard may be undefined in non-secure contexts (non-HTTPS)\n const isClipboardAvailable =\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\";\n\n if (isClipboardAvailable) {\n console.log(\"clipboard API IS available, using clipboard API\", {\n navigator,\n });\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n } catch (error) {\n // If clipboard API fails, try fallback\n\n console.log(\"clipboard API failed, trying fallback\", { error });\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n error,\n });\n onErrorCallback(error);\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Use fallback method when clipboard API is not available\n\n console.log(\"clipboard API NOT available, using fallback\");\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n console.log(\"fallback result\", { copySuccess, text });\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n copySuccess,\n });\n onErrorCallback(\n new Error(\n \"Failed to copy to clipboard: Clipboard API not available and fallback method failed\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // Note: In some contexts (iframes, cross-origin), execCommand may return true\n // but the copy may still be blocked by the browser. There's no reliable way to verify.\n }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\n console.log(\"copyTextToClipboard final result\", { copySuccess });\n return copySuccess;\n};\n\n/**\n * Fallback legacy function to copy text to clipboard for browsers that don't support navigator.clipboard.writeText\n * @reference https://github.com/sindresorhus/copy-text-to-clipboard/blob/main/index.js\n * @deprecated Use navigator.clipboard.writeText instead\n */\nconst DEPRECATED_copyTextToClipboard = (\n text,\n { target = document.body } = {}\n) => {\n if (typeof text !== \"string\") {\n throw new TypeError(\n `Expected parameter \\`text\\` to be a \\`string\\`, got \\`${typeof text}\\`.`\n );\n }\n\n // Check if execCommand is available\n if (!document.execCommand) {\n console.error(\"document.execCommand is not available\");\n return false;\n }\n\n const element = document.createElement(\"textarea\");\n const previouslyFocusedElement = document.activeElement;\n\n element.value = text;\n\n // IMPORTANT: Always append to document.body, not the target\n // This ensures the element is in the active document, which is required\n // for execCommand to work, especially when inside portals/modals\n const container = document.body;\n\n // Style the element to be invisible but still \"visible\" to the browser\n // Some browsers require the element to be in the render tree and \"visible\"\n element.style.position = \"fixed\";\n element.style.top = \"0\";\n element.style.left = \"0\";\n element.style.width = \"2px\";\n element.style.height = \"2px\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.margin = \"0\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.opacity = \"0\";\n element.style.zIndex = \"-1\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n element.setAttribute(\"readonly\", \"\");\n element.setAttribute(\"tabindex\", \"-1\");\n element.setAttribute(\"aria-hidden\", \"true\");\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n // Append to document.body (critical for Modal/Portal contexts)\n container.appendChild(element);\n\n // Focus and select - must happen synchronously within user activation\n element.focus();\n element.select();\n\n // Explicit selection workaround for iOS\n try {\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n } catch (e) {\n // setSelectionRange may fail, but that's okay\n console.log(\"setSelectionRange failed (non-critical)\", e);\n }\n\n let isSuccess = false;\n let execCommandError = null;\n\n try {\n // Verify selection before attempting copy\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n\n console.log(\"element selection state before execCommand\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n isConnected: element.isConnected,\n ownerDocument: element.ownerDocument === document,\n });\n\n // If not properly selected, try one more time\n if (!isSelected && text.length > 0) {\n element.focus();\n element.select();\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n }\n\n // Execute copy command\n isSuccess = document.execCommand(\"copy\");\n\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n });\n\n if (!isSuccess) {\n console.warn(\"execCommand returned false - copy failed\");\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Clean up immediately\n element.remove();\n\n // Restore original selection\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Restore focus to previously focused element\n // Use setTimeout to avoid focus conflicts with Modal's FocusScope\n if (previouslyFocusedElement instanceof HTMLElement) {\n // Small delay to let the Modal's focus management settle\n setTimeout(() => {\n try {\n previouslyFocusedElement.focus();\n } catch (e) {\n // Focus might fail if element is no longer in DOM, that's okay\n console.log(\"Could not restore focus (non-critical)\", e);\n }\n }, 0);\n }\n\n if (execCommandError) {\n console.error(\"execCommand error\", execCommandError);\n return false;\n }\n\n return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","container","selection","originalRange","e","isSuccess","execCommandError","isSelected"],"mappings":"gFAAa,MAAAA,EAAsB,MACjCC,EACAC,IACqB,CACrB,IAAIC,EAAc,GAEZ,MAAAC,EAAmBC,GAAiB,CACxC,MAAMC,EACJD,aAAiB,MAAQA,EAAM,QAAU,8BAE3C,QAAQ,MAAMC,CAAY,EAChBJ,GAAA,MAAAA,EAAA,IAAI,MAAMI,CAAY,EAAC,EAUnC,GAJE,OAAO,UAAc,KACrB,UAAU,WACV,OAAO,UAAU,UAAU,WAAc,WAEjB,CACxB,QAAQ,IAAI,kDAAmD,CAC7D,SAAA,CACD,EACG,GAAA,CACI,MAAA,UAAU,UAAU,UAAUL,CAAI,EAC1BE,EAAA,SACPE,EAAO,CAGd,QAAQ,IAAI,wCAAyC,CAAE,MAAAA,CAAO,CAAA,EAC1D,GAAA,CACFF,EAAcI,EAA+BN,CAAI,EAE5CE,IACH,QAAQ,IAAI,iDAAkD,CAC5D,MAAAE,CAAA,CACD,EACDD,EAAgBC,CAAK,SAEhBG,EAAe,CACtB,QAAQ,IAAI,4CAA6C,CACvD,cAAAA,CAAA,CACD,EACDJ,EAAgBI,CAAa,CAC/B,CACF,CAAA,KACK,CAGL,QAAQ,IAAI,8CAA8C,EACtD,GAAA,CACFL,EAAcI,EAA+BN,CAAI,EACjD,QAAQ,IAAI,kBAAmB,CAAE,YAAAE,EAAa,KAAAF,CAAM,CAAA,EAC/CE,EAUH,QAAQ,IAAI,+CAA+C,GAT3D,QAAQ,IAAI,iDAAkD,CAC5D,YAAAA,CAAA,CACD,EACDC,EACE,IAAI,MACF,qFACF,CAA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EAAY,GACZC,EAAmB,KAEnB,GAAA,CAEF,MAAMC,EACJR,EAAQ,iBAAmB,GAAKA,EAAQ,eAAiBT,EAAK,OAEhE,QAAQ,IAAI,6CAA8C,CACxD,WAAAiB,EACA,eAAgBR,EAAQ,eACxB,aAAcA,EAAQ,aACtB,WAAYT,EAAK,OACjB,YAAaS,EAAQ,YACrB,cAAeA,EAAQ,gBAAkB,QAAA,CAC1C,EAGG,CAACQ,GAAcjB,EAAK,OAAS,IAC/BS,EAAQ,MAAM,EACdA,EAAQ,OAAO,EACXA,EAAQ,mBACFA,EAAA,kBAAkB,EAAGT,EAAK,MAAM,GAKhCe,EAAA,SAAS,YAAY,MAAM,EAEvC,QAAQ,IAAI,sCAAuC,CACjD,UAAAA,EACA,WAAYf,EAAK,MAAA,CAClB,EAEIe,GACH,QAAQ,KAAK,0CAA0C,QAElDX,EAAO,CACKY,EAAAZ,EACX,QAAA,MAAM,8CAA+CA,CAAK,CACpE,CAyBA,OAtBAK,EAAQ,OAAO,EAGXI,IACFD,EAAU,gBAAgB,EAC1BA,EAAU,SAASC,CAAa,GAK9BH,aAAoC,aAEtC,WAAW,IAAM,CACX,GAAA,CACFA,EAAyB,MAAM,QACxBI,EAAG,CAEF,QAAA,IAAI,yCAA0CA,CAAC,CACzD,GACC,CAAC,EAGFE,GACM,QAAA,MAAM,oBAAqBA,CAAgB,EAC5C,IAGFD,CACT"}
|
package/dist/utils/copy.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const g = async (o, c) => {
|
|
2
2
|
let e = !1;
|
|
3
|
-
const
|
|
3
|
+
const a = (l) => {
|
|
4
4
|
const n = l instanceof Error ? l.message : "Failed to copy to clipboard";
|
|
5
5
|
console.error(n), c == null || c(new Error(n));
|
|
6
6
|
};
|
|
@@ -13,64 +13,74 @@ const d = async (o, c) => {
|
|
|
13
13
|
} catch (l) {
|
|
14
14
|
console.log("clipboard API failed, trying fallback", { error: l });
|
|
15
15
|
try {
|
|
16
|
-
e =
|
|
16
|
+
e = d(o), e || (console.log("fallback unsuccessful, calling onErrorCallback", {
|
|
17
17
|
error: l
|
|
18
|
-
}),
|
|
18
|
+
}), a(l));
|
|
19
19
|
} catch (n) {
|
|
20
20
|
console.log("fallback errored, calling onErrorCallback", {
|
|
21
21
|
fallbackError: n
|
|
22
|
-
}),
|
|
22
|
+
}), a(n);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
} else {
|
|
26
26
|
console.log("clipboard API NOT available, using fallback");
|
|
27
27
|
try {
|
|
28
|
-
e =
|
|
28
|
+
e = d(o), console.log("fallback result", { copySuccess: e, text: o }), e ? console.log("fallback successful - copy should have worked") : (console.log("fallback unsuccessful, calling onErrorCallback", {
|
|
29
29
|
copySuccess: e
|
|
30
|
-
}),
|
|
30
|
+
}), a(
|
|
31
31
|
new Error(
|
|
32
|
-
"Failed to copy to clipboard: Clipboard API not available and fallback method failed
|
|
32
|
+
"Failed to copy to clipboard: Clipboard API not available and fallback method failed"
|
|
33
33
|
)
|
|
34
34
|
));
|
|
35
35
|
} catch (l) {
|
|
36
|
-
console.log("fallback errored, calling onErrorCallback", { error: l }),
|
|
36
|
+
console.log("fallback errored, calling onErrorCallback", { error: l }), a(l);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
return console.log("copyTextToClipboard final result", { copySuccess: e }), e;
|
|
40
|
-
},
|
|
40
|
+
}, d = (o, { target: c = document.body } = {}) => {
|
|
41
41
|
if (typeof o != "string")
|
|
42
42
|
throw new TypeError(
|
|
43
43
|
`Expected parameter \`text\` to be a \`string\`, got \`${typeof o}\`.`
|
|
44
44
|
);
|
|
45
45
|
if (!document.execCommand)
|
|
46
46
|
return console.error("document.execCommand is not available"), !1;
|
|
47
|
-
const e = document.createElement("textarea"),
|
|
48
|
-
e.value = o
|
|
49
|
-
const
|
|
50
|
-
|
|
47
|
+
const e = document.createElement("textarea"), a = document.activeElement;
|
|
48
|
+
e.value = o;
|
|
49
|
+
const i = document.body;
|
|
50
|
+
e.style.position = "fixed", e.style.top = "0", e.style.left = "0", e.style.width = "2px", e.style.height = "2px", e.style.padding = "0", e.style.border = "none", e.style.margin = "0", e.style.outline = "none", e.style.boxShadow = "none", e.style.background = "transparent", e.style.opacity = "0", e.style.zIndex = "-1", e.style.fontSize = "12pt", e.setAttribute("readonly", ""), e.setAttribute("tabindex", "-1"), e.setAttribute("aria-hidden", "true");
|
|
51
|
+
const l = document.getSelection(), n = l.rangeCount > 0 && l.getRangeAt(0);
|
|
52
|
+
i.appendChild(e), e.focus(), e.select();
|
|
51
53
|
try {
|
|
52
|
-
e.setSelectionRange(0, o.length);
|
|
53
|
-
} catch (
|
|
54
|
-
console.log("setSelectionRange failed (non-critical)",
|
|
54
|
+
e.setSelectionRange && e.setSelectionRange(0, o.length);
|
|
55
|
+
} catch (t) {
|
|
56
|
+
console.log("setSelectionRange failed (non-critical)", t);
|
|
55
57
|
}
|
|
56
|
-
let
|
|
58
|
+
let r = !1, s = null;
|
|
57
59
|
try {
|
|
58
|
-
const
|
|
59
|
-
console.log("element selection state", {
|
|
60
|
-
isSelected:
|
|
60
|
+
const t = e.selectionStart === 0 && e.selectionEnd === o.length;
|
|
61
|
+
console.log("element selection state before execCommand", {
|
|
62
|
+
isSelected: t,
|
|
61
63
|
selectionStart: e.selectionStart,
|
|
62
64
|
selectionEnd: e.selectionEnd,
|
|
65
|
+
textLength: o.length,
|
|
66
|
+
isConnected: e.isConnected,
|
|
67
|
+
ownerDocument: e.ownerDocument === document
|
|
68
|
+
}), !t && o.length > 0 && (e.focus(), e.select(), e.setSelectionRange && e.setSelectionRange(0, o.length)), r = document.execCommand("copy"), console.log("document.execCommand('copy') result", {
|
|
69
|
+
isSuccess: r,
|
|
63
70
|
textLength: o.length
|
|
64
|
-
}),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}), n ? console.log("execCommand returned true - copy should have succeeded") : console.warn("execCommand returned false - copy failed");
|
|
68
|
-
} catch (a) {
|
|
69
|
-
s = a, console.error("document.execCommand('copy') threw an error", a);
|
|
71
|
+
}), r || console.warn("execCommand returned false - copy failed");
|
|
72
|
+
} catch (t) {
|
|
73
|
+
s = t, console.error("document.execCommand('copy') threw an error", t);
|
|
70
74
|
}
|
|
71
|
-
return e.remove(),
|
|
75
|
+
return e.remove(), n && (l.removeAllRanges(), l.addRange(n)), a instanceof HTMLElement && setTimeout(() => {
|
|
76
|
+
try {
|
|
77
|
+
a.focus();
|
|
78
|
+
} catch (t) {
|
|
79
|
+
console.log("Could not restore focus (non-critical)", t);
|
|
80
|
+
}
|
|
81
|
+
}, 0), s ? (console.error("execCommand error", s), !1) : r;
|
|
72
82
|
};
|
|
73
83
|
export {
|
|
74
|
-
|
|
84
|
+
g as copyTextToClipboard
|
|
75
85
|
};
|
|
76
86
|
//# sourceMappingURL=copy.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.es.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n\n const onErrorCallback = (error: Error) => {\n const errorMessage =\n error instanceof Error ? error.message : \"Failed to copy to clipboard\";\n\n console.error(errorMessage);\n onError?.(new Error(errorMessage));\n };\n\n // Check if clipboard API is available\n // Note: navigator.clipboard may be undefined in non-secure contexts (non-HTTPS)\n const isClipboardAvailable =\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\";\n\n if (isClipboardAvailable) {\n console.log(\"clipboard API IS available, using clipboard API\", {\n navigator,\n });\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n } catch (error) {\n // If clipboard API fails, try fallback\n\n console.log(\"clipboard API failed, trying fallback\", { error });\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n error,\n });\n onErrorCallback(error);\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Use fallback method when clipboard API is not available\n\n console.log(\"clipboard API NOT available, using fallback\");\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n console.log(\"fallback result\", { copySuccess, text });\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n copySuccess,\n });\n onErrorCallback(\n new Error(\n \"Failed to copy to clipboard: Clipboard API not available and fallback method failed. This may be due to browser security restrictions (e.g., iframe permissions, non-HTTPS context).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // Note: In some contexts (iframes, cross-origin), execCommand may return true\n // but the copy may still be blocked by the browser. There's no reliable way to verify.\n }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\n console.log(\"copyTextToClipboard final result\", { copySuccess });\n return copySuccess;\n};\n\n/**\n * Fallback legacy function to copy text to clipboard for browsers that don't support navigator.clipboard.writeText\n * @reference https://github.com/sindresorhus/copy-text-to-clipboard/blob/main/index.js\n * @deprecated Use navigator.clipboard.writeText instead\n */\nconst DEPRECATED_copyTextToClipboard = (\n text,\n { target = document.body } = {}\n) => {\n if (typeof text !== \"string\") {\n throw new TypeError(\n `Expected parameter \\`text\\` to be a \\`string\\`, got \\`${typeof text}\\`.`\n );\n }\n\n // Check if execCommand is available\n if (!document.execCommand) {\n console.error(\"document.execCommand is not available\");\n return false;\n }\n\n const element = document.createElement(\"textarea\");\n const previouslyFocusedElement = document.activeElement;\n\n element.value = text;\n\n // Prevent keyboard from showing on mobile\n element.setAttribute(\"readonly\", \"\");\n\n element.style.contain = \"strict\";\n element.style.position = \"absolute\";\n element.style.left = \"-9999px\";\n element.style.top = \"-9999px\";\n element.style.width = \"2em\";\n element.style.height = \"2em\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n target.append(element);\n\n // Focus and select the element\n // Use setTimeout to ensure the element is in the DOM and can receive focus\n element.focus();\n element.select();\n\n // Explicit selection workaround for iOS and ensure selection is set\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail on non-text inputs, but that's okay\n console.log(\"setSelectionRange failed (non-critical)\", e);\n }\n\n let isSuccess = false;\n let execCommandError = null;\n\n // Small delay to ensure the element is properly focused and selected\n // This is especially important in some browsers/contexts\n try {\n // Check if the element is actually selected\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n console.log(\"element selection state\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n });\n\n if (!isSelected && text.length > 0) {\n // Try to select again\n element.select();\n element.setSelectionRange(0, text.length);\n }\n\n isSuccess = document.execCommand(\"copy\");\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n });\n\n // Additional verification: check if execCommand actually worked\n // Some browsers return true even when copy fails\n if (isSuccess) {\n console.log(\"execCommand returned true - copy should have succeeded\");\n } else {\n console.warn(\"execCommand returned false - copy failed\");\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Verify the copy worked by checking if we can read back (if possible)\n // Note: This is a best-effort check since we can't always read clipboard\n\n element.remove();\n\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Get the focus back on the previously focused element, if any\n if (previouslyFocusedElement instanceof HTMLElement) {\n previouslyFocusedElement.focus();\n }\n\n if (execCommandError) {\n console.error(\"execCommand error\", execCommandError);\n return false;\n }\n\n return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previ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A,MACtB,YAAYT,EAAK;AAAA,IAAA,CAClB,GAEG,CAACgB,KAAchB,EAAK,SAAS,MAE/BS,EAAQ,OAAO,GACPA,EAAA,kBAAkB,GAAGT,EAAK,MAAM,IAG9Bc,IAAA,SAAS,YAAY,MAAM,GACvC,QAAQ,IAAI,uCAAuC;AAAA,MACjD,WAAAA;AAAA,MACA,YAAYd,EAAK;AAAA,IAAA,CAClB,GAIGc,IACF,QAAQ,IAAI,wDAAwD,IAEpE,QAAQ,KAAK,0CAA0C;AAAA,WAElDV,GAAO;AACK,IAAAW,IAAAX,GACX,QAAA,MAAM,+CAA+CA,CAAK;AAAA,EACpE;AAiBA,SAZAK,EAAQ,OAAO,GAEXG,MACFD,EAAU,gBAAgB,GAC1BA,EAAU,SAASC,CAAa,IAI9BF,aAAoC,eACtCA,EAAyB,MAAM,GAG7BK,KACM,QAAA,MAAM,qBAAqBA,CAAgB,GAC5C,MAGFD;AACT;"}
|
|
1
|
+
{"version":3,"file":"copy.es.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n\n const onErrorCallback = (error: Error) => {\n const errorMessage =\n error instanceof Error ? error.message : \"Failed to copy to clipboard\";\n\n console.error(errorMessage);\n onError?.(new Error(errorMessage));\n };\n\n // Check if clipboard API is available\n // Note: navigator.clipboard may be undefined in non-secure contexts (non-HTTPS)\n const isClipboardAvailable =\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\";\n\n if (isClipboardAvailable) {\n console.log(\"clipboard API IS available, using clipboard API\", {\n navigator,\n });\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n } catch (error) {\n // If clipboard API fails, try fallback\n\n console.log(\"clipboard API failed, trying fallback\", { error });\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n error,\n });\n onErrorCallback(error);\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Use fallback method when clipboard API is not available\n\n console.log(\"clipboard API NOT available, using fallback\");\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n console.log(\"fallback result\", { copySuccess, text });\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n copySuccess,\n });\n onErrorCallback(\n new Error(\n \"Failed to copy to clipboard: Clipboard API not available and fallback method failed\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // Note: In some contexts (iframes, cross-origin), execCommand may return true\n // but the copy may still be blocked by the browser. There's no reliable way to verify.\n }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\n console.log(\"copyTextToClipboard final result\", { copySuccess });\n return copySuccess;\n};\n\n/**\n * Fallback legacy function to copy text to clipboard for browsers that don't support navigator.clipboard.writeText\n * @reference https://github.com/sindresorhus/copy-text-to-clipboard/blob/main/index.js\n * @deprecated Use navigator.clipboard.writeText instead\n */\nconst DEPRECATED_copyTextToClipboard = (\n text,\n { target = document.body } = {}\n) => {\n if (typeof text !== \"string\") {\n throw new TypeError(\n `Expected parameter \\`text\\` to be a \\`string\\`, got \\`${typeof text}\\`.`\n );\n }\n\n // Check if execCommand is available\n if (!document.execCommand) {\n console.error(\"document.execCommand is not available\");\n return false;\n }\n\n const element = document.createElement(\"textarea\");\n const previouslyFocusedElement = document.activeElement;\n\n element.value = text;\n\n // IMPORTANT: Always append to document.body, not the target\n // This ensures the element is in the active document, which is required\n // for execCommand to work, especially when inside portals/modals\n const container = document.body;\n\n // Style the element to be invisible but still \"visible\" to the browser\n // Some browsers require the element to be in the render tree and \"visible\"\n element.style.position = \"fixed\";\n element.style.top = \"0\";\n element.style.left = \"0\";\n element.style.width = \"2px\";\n element.style.height = \"2px\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.margin = \"0\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.opacity = \"0\";\n element.style.zIndex = \"-1\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n element.setAttribute(\"readonly\", \"\");\n element.setAttribute(\"tabindex\", \"-1\");\n element.setAttribute(\"aria-hidden\", \"true\");\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n // Append to document.body (critical for Modal/Portal contexts)\n container.appendChild(element);\n\n // Focus and select - must happen synchronously within user activation\n element.focus();\n element.select();\n\n // Explicit selection workaround for iOS\n try {\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n } catch (e) {\n // setSelectionRange may fail, but that's okay\n console.log(\"setSelectionRange failed (non-critical)\", e);\n }\n\n let isSuccess = false;\n let execCommandError = null;\n\n try {\n // Verify selection before attempting copy\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n\n console.log(\"element selection state before execCommand\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n isConnected: element.isConnected,\n ownerDocument: element.ownerDocument === document,\n });\n\n // If not properly selected, try one more time\n if (!isSelected && text.length > 0) {\n element.focus();\n element.select();\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n }\n\n // Execute copy command\n isSuccess = document.execCommand(\"copy\");\n\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n });\n\n if (!isSuccess) {\n console.warn(\"execCommand returned false - copy failed\");\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Clean up immediately\n element.remove();\n\n // Restore original selection\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Restore focus to previously focused element\n // Use setTimeout to avoid focus conflicts with Modal's FocusScope\n if (previouslyFocusedElement instanceof HTMLElement) {\n // Small delay to let the Modal's focus management settle\n setTimeout(() => {\n try {\n previouslyFocusedElement.focus();\n } catch (e) {\n // Focus might fail if element is no longer in DOM, that's okay\n console.log(\"Could not restore focus (non-critical)\", e);\n }\n }, 0);\n }\n\n if (execCommandError) {\n console.error(\"execCommand error\", execCommandError);\n return false;\n }\n\n return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","container","selection","originalRange","e","isSuccess","execCommandError","isSelected"],"mappings":"AAAa,MAAAA,IAAsB,OACjCC,GACAC,MACqB;AACrB,MAAIC,IAAc;AAEZ,QAAAC,IAAkB,CAACC,MAAiB;AACxC,UAAMC,IACJD,aAAiB,QAAQA,EAAM,UAAU;AAE3C,YAAQ,MAAMC,CAAY,GAChBJ,KAAA,QAAAA,EAAA,IAAI,MAAMI,CAAY;AAAA,EAAC;AAUnC,MAJE,OAAO,YAAc,OACrB,UAAU,aACV,OAAO,UAAU,UAAU,aAAc,YAEjB;AACxB,YAAQ,IAAI,mDAAmD;AAAA,MAC7D;AAAA,IAAA,CACD;AACG,QAAA;AACI,YAAA,UAAU,UAAU,UAAUL,CAAI,GAC1BE,IAAA;AAAA,aACPE,GAAO;AAGd,cAAQ,IAAI,yCAAyC,EAAE,OAAAA,EAAO,CAAA;AAC1D,UAAA;AACF,QAAAF,IAAcI,EAA+BN,CAAI,GAE5CE,MACH,QAAQ,IAAI,kDAAkD;AAAA,UAC5D,OAAAE;AAAA,QAAA,CACD,GACDD,EAAgBC,CAAK;AAAA,eAEhBG,GAAe;AACtB,gBAAQ,IAAI,6CAA6C;AAAA,UACvD,eAAAA;AAAA,QAAA,CACD,GACDJ,EAAgBI,CAAa;AAAA,MAC/B;AAAA,IACF;AAAA,EAAA,OACK;AAGL,YAAQ,IAAI,8CAA8C;AACtD,QAAA;AACF,MAAAL,IAAcI,EAA+BN,CAAI,GACjD,QAAQ,IA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