@protonradio/proton-ui 0.11.18-beta.4 → 0.11.18-beta.5

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.
@@ -1,2 +1,2 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=async(o,c)=>{let e=!1;const n=t=>{const l=t instanceof Error?t.message:"Failed to copy to clipboard";console.error(l),c==null||c(new Error(l))};if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){console.log("clipboard API detected, attempting to use it");try{await navigator.clipboard.writeText(o),e=!0,console.log("clipboard API succeeded")}catch(t){console.log("clipboard API failed, trying fallback",{error:t});try{e=d(o),e?console.log("fallback succeeded after clipboard API failure"):(console.log("fallback unsuccessful, calling onErrorCallback",{error:t}),n(t))}catch(l){console.log("fallback errored, calling onErrorCallback",{fallbackError:l}),n(l)}}}else{console.log("clipboard API NOT available, using fallback",{hasNavigator:typeof navigator<"u",hasClipboard:typeof navigator<"u"&&!!navigator.clipboard,hasWriteText:typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function"});try{e=d(o),console.log("fallback result",{copySuccess:e,text:o}),e?(console.log("fallback successful - copy should have worked"),console.warn("Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions.")):(console.log("fallback unsuccessful, calling onErrorCallback",{copySuccess:e}),n(new Error("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, or Modal/Portal focus management).")))}catch(t){console.log("fallback errored, calling onErrorCallback",{error:t}),n(t)}}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"),n=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("tabindex","-1"),e.setAttribute("aria-hidden","true");const t=document.getSelection(),l=t.rangeCount>0&&t.getRangeAt(0);i.appendChild(e);let r=!1,s=null;try{if(e.focus({preventScroll:!0}),e.select(),e.setSelectionRange)try{e.setSelectionRange(0,o.length)}catch{e.select()}const a=e.selectionStart===0&&e.selectionEnd===o.length;console.log("element selection state before execCommand",{isSelected:a,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd,textLength:o.length,isConnected:e.isConnected,ownerDocument:e.ownerDocument===document,hasFocus:document.activeElement===e}),(!a||document.activeElement!==e)&&o.length>0&&(e.focus({preventScroll:!0}),e.select(),e.setSelectionRange&&e.setSelectionRange(0,o.length)),r=document.execCommand("copy"),console.log("document.execCommand('copy') result",{isSuccess:r,textLength:o.length,activeElement:document.activeElement===e}),r?console.log("execCommand returned true - copy should have succeeded (but may be blocked by browser security)"):console.warn("execCommand returned false - copy failed")}catch(a){s=a,console.error("document.execCommand('copy') threw an error",a)}return e.remove(),l&&(t.removeAllRanges(),t.addRange(l)),n instanceof HTMLElement&&setTimeout(()=>{try{n.focus()}catch(a){console.log("Could not restore focus (non-critical)",a)}},0),s?(console.error("execCommand error",s),!1):r};exports.copyTextToClipboard=u;
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\"\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,EAC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AM,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"}
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: The Clipboard API handles its own security checks.\n // If not in a secure context (HTTPS), navigator.clipboard will be undefined\n // or writeText() will throw an error. We don't need to manually check isSecureContext.\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 detected, attempting to use it\");\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n console.log(\"clipboard API succeeded\");\n } catch (error) {\n // Clipboard API failed (could be security restriction, permission denied, etc.)\n // Fall back to execCommand method\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 } else {\n console.log(\"fallback succeeded after clipboard API failure\");\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Clipboard API not available, use fallback method\n console.log(\"clipboard API NOT available, using fallback\", {\n hasNavigator: typeof navigator !== \"undefined\",\n hasClipboard: typeof navigator !== \"undefined\" && !!navigator.clipboard,\n hasWriteText:\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\",\n });\n\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, or Modal/Portal focus management).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // WARNING: In some contexts (iframes, cross-origin, Modal portals),\n // execCommand may return true but the copy may still be blocked by the browser.\n // There's no reliable way to verify if the copy actually succeeded.\n console.warn(\n \"Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions.\"\n );\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 // NOTE: Do NOT set readonly - some browsers require the element to be editable\n // for execCommand to work properly, especially in Modal/Portal contexts\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 let isSuccess = false;\n let execCommandError = null;\n\n try {\n // Focus and select - must happen synchronously within user activation\n // Try multiple approaches to ensure it works in Modal contexts\n element.focus({ preventScroll: true });\n\n // Use both select() and setSelectionRange for maximum compatibility\n element.select();\n\n // Explicit selection workaround for iOS and ensure full selection\n if (element.setSelectionRange) {\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail, try select() again\n element.select();\n }\n }\n\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 hasFocus: document.activeElement === element,\n });\n\n // If not properly selected or focused, try again\n if (\n (!isSelected || document.activeElement !== element) &&\n text.length > 0\n ) {\n element.focus({ preventScroll: true });\n element.select();\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n }\n\n // Execute copy command - must be synchronous within user activation\n // Some browsers will return true even if copy fails (security restriction)\n isSuccess = document.execCommand(\"copy\");\n\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n activeElement: document.activeElement === element,\n });\n\n if (!isSuccess) {\n console.warn(\"execCommand returned false - copy failed\");\n } else {\n // Even if execCommand returns true, the copy might have been blocked\n // by browser security. There's no reliable way to verify, but we log it.\n console.log(\n \"execCommand returned true - copy should have succeeded (but may be blocked by browser security)\"\n );\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","isSuccess","execCommandError","isSelected","e"],"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,EAYnC,GAJE,O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,IAC3CT,EAAK,OAAS,IAEdS,EAAQ,MAAM,CAAE,cAAe,EAAM,CAAA,EACrCA,EAAQ,OAAO,EACXA,EAAQ,mBACFA,EAAA,kBAAkB,EAAGT,EAAK,MAAM,GAMhCc,EAAA,SAAS,YAAY,MAAM,EAEvC,QAAQ,IAAI,sCAAuC,CACjD,UAAAA,EACA,WAAYd,EAAK,OACjB,cAAe,SAAS,gBAAkBS,CAAA,CAC3C,EAEIK,EAKK,QAAA,IACN,iGAAA,EALF,QAAQ,KAAK,0CAA0C,QAQlDV,EAAO,CACKW,EAAAX,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,QACxBO,EAAG,CAEF,QAAA,IAAI,yCAA0CA,CAAC,CACzD,GACC,CAAC,EAGFF,GACM,QAAA,MAAM,oBAAqBA,CAAgB,EAC5C,IAGFD,CACT"}
@@ -1,39 +1,43 @@
1
1
  const g = async (o, c) => {
2
2
  let e = !1;
3
- const a = (l) => {
4
- const n = l instanceof Error ? l.message : "Failed to copy to clipboard";
5
- console.error(n), c == null || c(new Error(n));
3
+ const n = (t) => {
4
+ const l = t instanceof Error ? t.message : "Failed to copy to clipboard";
5
+ console.error(l), c == null || c(new Error(l));
6
6
  };
7
7
  if (typeof navigator < "u" && navigator.clipboard && typeof navigator.clipboard.writeText == "function") {
8
- console.log("clipboard API IS available, using clipboard API", {
9
- navigator
10
- });
8
+ console.log("clipboard API detected, attempting to use it");
11
9
  try {
12
- await navigator.clipboard.writeText(o), e = !0;
13
- } catch (l) {
14
- console.log("clipboard API failed, trying fallback", { error: l });
10
+ await navigator.clipboard.writeText(o), e = !0, console.log("clipboard API succeeded");
11
+ } catch (t) {
12
+ console.log("clipboard API failed, trying fallback", { error: t });
15
13
  try {
16
- e = d(o), e || (console.log("fallback unsuccessful, calling onErrorCallback", {
17
- error: l
18
- }), a(l));
19
- } catch (n) {
14
+ e = d(o), e ? console.log("fallback succeeded after clipboard API failure") : (console.log("fallback unsuccessful, calling onErrorCallback", {
15
+ error: t
16
+ }), n(t));
17
+ } catch (l) {
20
18
  console.log("fallback errored, calling onErrorCallback", {
21
- fallbackError: n
22
- }), a(n);
19
+ fallbackError: l
20
+ }), n(l);
23
21
  }
24
22
  }
25
23
  } else {
26
- console.log("clipboard API NOT available, using fallback");
24
+ console.log("clipboard API NOT available, using fallback", {
25
+ hasNavigator: typeof navigator < "u",
26
+ hasClipboard: typeof navigator < "u" && !!navigator.clipboard,
27
+ hasWriteText: typeof navigator < "u" && navigator.clipboard && typeof navigator.clipboard.writeText == "function"
28
+ });
27
29
  try {
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", {
30
+ e = d(o), console.log("fallback result", { copySuccess: e, text: o }), e ? (console.log("fallback successful - copy should have worked"), console.warn(
31
+ "Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions."
32
+ )) : (console.log("fallback unsuccessful, calling onErrorCallback", {
29
33
  copySuccess: e
30
- }), a(
34
+ }), n(
31
35
  new Error(
32
- "Failed to copy to clipboard: Clipboard API not available and fallback method failed"
36
+ "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, or Modal/Portal focus management)."
33
37
  )
34
38
  ));
35
- } catch (l) {
36
- console.log("fallback errored, calling onErrorCallback", { error: l }), a(l);
39
+ } catch (t) {
40
+ console.log("fallback errored, calling onErrorCallback", { error: t }), n(t);
37
41
  }
38
42
  }
39
43
  return console.log("copyTextToClipboard final result", { copySuccess: e }), e;
@@ -44,39 +48,44 @@ const g = async (o, c) => {
44
48
  );
45
49
  if (!document.execCommand)
46
50
  return console.error("document.execCommand is not available"), !1;
47
- const e = document.createElement("textarea"), a = document.activeElement;
51
+ const e = document.createElement("textarea"), n = document.activeElement;
48
52
  e.value = o;
49
53
  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();
53
- try {
54
- e.setSelectionRange && e.setSelectionRange(0, o.length);
55
- } catch (t) {
56
- console.log("setSelectionRange failed (non-critical)", t);
57
- }
54
+ 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("tabindex", "-1"), e.setAttribute("aria-hidden", "true");
55
+ const t = document.getSelection(), l = t.rangeCount > 0 && t.getRangeAt(0);
56
+ i.appendChild(e);
58
57
  let r = !1, s = null;
59
58
  try {
60
- const t = e.selectionStart === 0 && e.selectionEnd === o.length;
59
+ if (e.focus({ preventScroll: !0 }), e.select(), e.setSelectionRange)
60
+ try {
61
+ e.setSelectionRange(0, o.length);
62
+ } catch {
63
+ e.select();
64
+ }
65
+ const a = e.selectionStart === 0 && e.selectionEnd === o.length;
61
66
  console.log("element selection state before execCommand", {
62
- isSelected: t,
67
+ isSelected: a,
63
68
  selectionStart: e.selectionStart,
64
69
  selectionEnd: e.selectionEnd,
65
70
  textLength: o.length,
66
71
  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", {
72
+ ownerDocument: e.ownerDocument === document,
73
+ hasFocus: document.activeElement === e
74
+ }), (!a || document.activeElement !== e) && o.length > 0 && (e.focus({ preventScroll: !0 }), e.select(), e.setSelectionRange && e.setSelectionRange(0, o.length)), r = document.execCommand("copy"), console.log("document.execCommand('copy') result", {
69
75
  isSuccess: r,
70
- textLength: o.length
71
- }), r || console.warn("execCommand returned false - copy failed");
72
- } catch (t) {
73
- s = t, console.error("document.execCommand('copy') threw an error", t);
76
+ textLength: o.length,
77
+ activeElement: document.activeElement === e
78
+ }), r ? console.log(
79
+ "execCommand returned true - copy should have succeeded (but may be blocked by browser security)"
80
+ ) : console.warn("execCommand returned false - copy failed");
81
+ } catch (a) {
82
+ s = a, console.error("document.execCommand('copy') threw an error", a);
74
83
  }
75
- return e.remove(), n && (l.removeAllRanges(), l.addRange(n)), a instanceof HTMLElement && setTimeout(() => {
84
+ return e.remove(), l && (t.removeAllRanges(), t.addRange(l)), n instanceof HTMLElement && setTimeout(() => {
76
85
  try {
77
- a.focus();
78
- } catch (t) {
79
- console.log("Could not restore focus (non-critical)", t);
86
+ n.focus();
87
+ } catch (a) {
88
+ console.log("Could not restore focus (non-critical)", a);
80
89
  }
81
90
  }, 0), s ? (console.error("execCommand error", s), !1) : r;
82
91
  };
@@ -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\"\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,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,OAAO,GAGXI,MACFD,EAAU,gBAAgB,GAC1BA,EAAU,SAASC,CAAa,IAK9BH,aAAoC,eAEtC,WAAW,MAAM;AACX,QAAA;AACF,MAAAA,EAAyB,MAAM;AAAA,aACxBI,GAAG;AAEF,cAAA,IAAI,0CAA0CA,CAAC;AAAA,IACzD;AAAA,KACC,CAAC,GAGFE,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: The Clipboard API handles its own security checks.\n // If not in a secure context (HTTPS), navigator.clipboard will be undefined\n // or writeText() will throw an error. We don't need to manually check isSecureContext.\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 detected, attempting to use it\");\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n console.log(\"clipboard API succeeded\");\n } catch (error) {\n // Clipboard API failed (could be security restriction, permission denied, etc.)\n // Fall back to execCommand method\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 } else {\n console.log(\"fallback succeeded after clipboard API failure\");\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Clipboard API not available, use fallback method\n console.log(\"clipboard API NOT available, using fallback\", {\n hasNavigator: typeof navigator !== \"undefined\",\n hasClipboard: typeof navigator !== \"undefined\" && !!navigator.clipboard,\n hasWriteText:\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\",\n });\n\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, or Modal/Portal focus management).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // WARNING: In some contexts (iframes, cross-origin, Modal portals),\n // execCommand may return true but the copy may still be blocked by the browser.\n // There's no reliable way to verify if the copy actually succeeded.\n console.warn(\n \"Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions.\"\n );\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 // NOTE: Do NOT set readonly - some browsers require the element to be editable\n // for execCommand to work properly, especially in Modal/Portal contexts\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 let isSuccess = false;\n let execCommandError = null;\n\n try {\n // Focus and select - must happen synchronously within user activation\n // Try multiple approaches to ensure it works in Modal contexts\n element.focus({ preventScroll: true });\n\n // Use both select() and setSelectionRange for maximum compatibility\n element.select();\n\n // Explicit selection workaround for iOS and ensure full selection\n if (element.setSelectionRange) {\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail, try select() again\n element.select();\n }\n }\n\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 hasFocus: document.activeElement === element,\n });\n\n // If not properly selected or focused, try again\n if (\n (!isSelected || document.activeElement !== element) &&\n text.length > 0\n ) {\n element.focus({ preventScroll: true });\n element.select();\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n }\n\n // Execute copy command - must be synchronous within user activation\n // Some browsers will return true even if copy fails (security restriction)\n isSuccess = document.execCommand(\"copy\");\n\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n activeElement: document.activeElement === element,\n });\n\n if (!isSuccess) {\n console.warn(\"execCommand returned false - copy failed\");\n } else {\n // Even if execCommand returns true, the copy might have been blocked\n // by browser security. There's no reliable way to verify, but we log it.\n console.log(\n \"execCommand returned true - copy should have succeeded (but may be blocked by browser security)\"\n );\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","isSuccess","execCommandError","isSelected","e"],"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;AAYnC,MAJE,OAAO,YAAc,OACrB,UAAU,aACV,OAAO,UAAU,UAAU,aAAc,YAEjB;AACxB,YAAQ,IAAI,8CAA8C;AACtD,QAAA;AACI,YAAA,UAAU,UAAU,UAAUL,CAAI,GAC1BE,IAAA,IACd,QAAQ,IAAI,yBAAyB;AAAA,aAC9BE,GAAO;A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SAAS,kBAAkBA;AAAA,IAAA,CACtC,IAIE,CAACO,KAAc,SAAS,kBAAkBP,MAC3CT,EAAK,SAAS,MAEdS,EAAQ,MAAM,EAAE,eAAe,GAAM,CAAA,GACrCA,EAAQ,OAAO,GACXA,EAAQ,qBACFA,EAAA,kBAAkB,GAAGT,EAAK,MAAM,IAMhCc,IAAA,SAAS,YAAY,MAAM,GAEvC,QAAQ,IAAI,uCAAuC;AAAA,MACjD,WAAAA;AAAA,MACA,YAAYd,EAAK;AAAA,MACjB,eAAe,SAAS,kBAAkBS;AAAA,IAAA,CAC3C,GAEIK,IAKK,QAAA;AAAA,MACN;AAAA,IAAA,IALF,QAAQ,KAAK,0CAA0C;AAAA,WAQlDV,GAAO;AACK,IAAAW,IAAAX,GACX,QAAA,MAAM,+CAA+CA,CAAK;AAAA,EACpE;AAyBA,SAtBAK,EAAQ,OAAO,GAGXI,MACFD,EAAU,gBAAgB,GAC1BA,EAAU,SAASC,CAAa,IAK9BH,aAAoC,eAEtC,WAAW,MAAM;AACX,QAAA;AACF,MAAAA,EAAyB,MAAM;AAAA,aACxBO,GAAG;AAEF,cAAA,IAAI,0CAA0CA,CAAC;AAAA,IACzD;AAAA,KACC,CAAC,GAGFF,KACM,QAAA,MAAM,qBAAqBA,CAAgB,GAC5C,MAGFD;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protonradio/proton-ui",
3
- "version": "0.11.18-beta.4",
3
+ "version": "0.11.18-beta.5",
4
4
  "description": "",
5
5
  "main": "./dist/proton-ui.umd.js",
6
6
  "module": "./dist/proton-ui.es.js",