@protonradio/proton-ui 0.11.18-beta.1 → 0.11.18-beta.2
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 i=async(l,c)=>{let e=!1;const t=o=>{const a=o instanceof Error?o.message:"Failed to copy to clipboard";console.error(a),c==null||c(new Error(a))};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(l),e=!0}catch(o){console.log("clipboard API failed, trying fallback",{error:o});try{e=n(l),e||(console.log("fallback unsuccessful, calling onErrorCallback",{error:o}),t(o))}catch(a){console.log("fallback errored, calling onErrorCallback",{fallbackError:a}),t(a)}}}else{console.log("clipboard API NOT available, using fallback");try{e=n(l),e||(console.log("fallback unsuccessful, calling onErrorCallback",{copySuccess:e}),t(new Error("Failed to copy to clipboard: Clipboard API not available and fallback method failed")))}catch(o){console.log("fallback errored, calling onErrorCallback",{error:o}),t(o)}}return e},n=(l,{target:c=document.body}={})=>{if(typeof l!="string")throw new TypeError(`Expected parameter \`text\` to be a \`string\`, got \`${typeof l}\`.`);const e=document.createElement("textarea"),t=document.activeElement;e.value=l,e.setAttribute("readonly",""),e.style.contain="strict",e.style.position="absolute",e.style.left="-9999px",e.style.fontSize="12pt";const r=document.getSelection(),o=r.rangeCount>0&&r.getRangeAt(0);c.append(e),e.select(),e.selectionStart=0,e.selectionEnd=l.length;let a=!1;try{a=document.execCommand("copy")}catch{}return e.remove(),o&&(r.removeAllRanges(),r.addRange(o)),t instanceof HTMLElement&&t.focus(),a};exports.copyTextToClipboard=i;
|
|
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
|
|
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 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 }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\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 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.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 element.select();\n\n // Explicit selection workaround for iOS\n element.selectionStart = 0;\n element.selectionEnd = text.length;\n\n let isSuccess = false;\n try {\n isSuccess = document.execCommand(\"copy\");\n } catch {}\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 return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","selection","originalRange","isSuccess"],"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,WAA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,OAE5B,IAAIa,EAAY,GACZ,GAAA,CACUA,EAAA,SAAS,YAAY,MAAM,CAAA,MACjC,CAAC,CAET,OAAAJ,EAAQ,OAAO,EAEXG,IACFD,EAAU,gBAAgB,EAC1BA,EAAU,SAASC,CAAa,GAI9BF,aAAoC,aACtCA,EAAyB,MAAM,EAG1BG,CACT"}
|
package/dist/utils/copy.es.js
CHANGED
|
@@ -1,32 +1,59 @@
|
|
|
1
|
-
const
|
|
1
|
+
const i = async (l, c) => {
|
|
2
2
|
let e = !1;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const t = (o) => {
|
|
4
|
+
const a = o instanceof Error ? o.message : "Failed to copy to clipboard";
|
|
5
|
+
console.error(a), c == null || c(new Error(a));
|
|
6
|
+
};
|
|
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
|
+
});
|
|
5
11
|
try {
|
|
6
|
-
await navigator.clipboard.writeText(
|
|
7
|
-
} catch (
|
|
8
|
-
|
|
12
|
+
await navigator.clipboard.writeText(l), e = !0;
|
|
13
|
+
} catch (o) {
|
|
14
|
+
console.log("clipboard API failed, trying fallback", { error: o });
|
|
15
|
+
try {
|
|
16
|
+
e = n(l), e || (console.log("fallback unsuccessful, calling onErrorCallback", {
|
|
17
|
+
error: o
|
|
18
|
+
}), t(o));
|
|
19
|
+
} catch (a) {
|
|
20
|
+
console.log("fallback errored, calling onErrorCallback", {
|
|
21
|
+
fallbackError: a
|
|
22
|
+
}), t(a);
|
|
23
|
+
}
|
|
9
24
|
}
|
|
10
|
-
} else
|
|
11
|
-
console.log("
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
} else {
|
|
26
|
+
console.log("clipboard API NOT available, using fallback");
|
|
27
|
+
try {
|
|
28
|
+
e = n(l), e || (console.log("fallback unsuccessful, calling onErrorCallback", {
|
|
29
|
+
copySuccess: e
|
|
30
|
+
}), t(
|
|
31
|
+
new Error(
|
|
32
|
+
"Failed to copy to clipboard: Clipboard API not available and fallback method failed"
|
|
33
|
+
)
|
|
34
|
+
));
|
|
35
|
+
} catch (o) {
|
|
36
|
+
console.log("fallback errored, calling onErrorCallback", { error: o }), t(o);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return e;
|
|
40
|
+
}, n = (l, { target: c = document.body } = {}) => {
|
|
41
|
+
if (typeof l != "string")
|
|
15
42
|
throw new TypeError(
|
|
16
|
-
`Expected parameter \`text\` to be a \`string\`, got \`${typeof
|
|
43
|
+
`Expected parameter \`text\` to be a \`string\`, got \`${typeof l}\`.`
|
|
17
44
|
);
|
|
18
|
-
const e = document.createElement("textarea"),
|
|
19
|
-
e.value =
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
let
|
|
45
|
+
const e = document.createElement("textarea"), t = document.activeElement;
|
|
46
|
+
e.value = l, e.setAttribute("readonly", ""), e.style.contain = "strict", e.style.position = "absolute", e.style.left = "-9999px", e.style.fontSize = "12pt";
|
|
47
|
+
const r = document.getSelection(), o = r.rangeCount > 0 && r.getRangeAt(0);
|
|
48
|
+
c.append(e), e.select(), e.selectionStart = 0, e.selectionEnd = l.length;
|
|
49
|
+
let a = !1;
|
|
23
50
|
try {
|
|
24
|
-
|
|
51
|
+
a = document.execCommand("copy");
|
|
25
52
|
} catch {
|
|
26
53
|
}
|
|
27
|
-
return e.remove(),
|
|
54
|
+
return e.remove(), o && (r.removeAllRanges(), r.addRange(o)), t instanceof HTMLElement && t.focus(), a;
|
|
28
55
|
};
|
|
29
56
|
export {
|
|
30
|
-
|
|
57
|
+
i as copyTextToClipboard
|
|
31
58
|
};
|
|
32
59
|
//# 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
|
|
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 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 }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\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 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.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 element.select();\n\n // Explicit selection workaround for iOS\n element.selectionStart = 0;\n element.selectionEnd = text.length;\n\n let isSuccess = false;\n try {\n isSuccess = document.execCommand(\"copy\");\n } catch {}\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 return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","selection","originalRange","isSuccess"],"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,I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