@arkyn/components 3.0.6 → 3.0.8
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/AGENTS.md +906 -0
- package/dist/hooks/useCopyToClipboard.d.ts +38 -0
- package/dist/hooks/useCopyToClipboard.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -20
- package/dist/index.js.map +1 -1
- package/dist/modules/hooks/useCopyToClipboard.js +28 -0
- package/dist/modules/hooks/useCopyToClipboard.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/hooks/useCopyToClipboard.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = document.createElement("textarea");
|
|
4
|
+
t.value = e, t.style.position = "fixed", t.style.opacity = "0", document.body.appendChild(t), t.select();
|
|
5
|
+
try {
|
|
6
|
+
return document.execCommand("copy");
|
|
7
|
+
} finally {
|
|
8
|
+
document.body.removeChild(t);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function t() {
|
|
12
|
+
async function t(t) {
|
|
13
|
+
try {
|
|
14
|
+
return await navigator.clipboard.writeText(t), !0;
|
|
15
|
+
} catch {
|
|
16
|
+
try {
|
|
17
|
+
return e(t);
|
|
18
|
+
} catch {
|
|
19
|
+
return !1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { copyToClipboard: t };
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { t as useCopyToClipboard };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=useCopyToClipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCopyToClipboard.js","names":[],"sources":["../../../src/hooks/useCopyToClipboard.ts"],"sourcesContent":["/**\n * copyWithFallback, copies `text` using a hidden `<textarea>` + `document.execCommand(\"copy\")`.\n *\n * Used internally by `useCopyToClipboard` when `navigator.clipboard` is unavailable or rejects,\n * e.g. insecure contexts (non-HTTPS) or older browsers.\n *\n * @param text - Text to copy.\n * @returns `true` if the copy command succeeded, `false` otherwise.\n */\n\nfunction copyWithFallback(text: string) {\n\tconst textarea = document.createElement(\"textarea\");\n\ttextarea.value = text;\n\ttextarea.style.position = \"fixed\";\n\ttextarea.style.opacity = \"0\";\n\tdocument.body.appendChild(textarea);\n\ttextarea.select();\n\n\ttry {\n\t\treturn document.execCommand(\"copy\");\n\t} finally {\n\t\tdocument.body.removeChild(textarea);\n\t}\n}\n\n/**\n * useCopyToClipboard, copies text to the clipboard and reports whether it succeeded.\n *\n * Tries `navigator.clipboard.writeText` first. If it's unavailable or rejects, falls back\n * to a hidden `<textarea>` with `document.execCommand(\"copy\")`. Never throws; any failure\n * simply resolves to `false`.\n *\n * @returns An object with `copyToClipboard`, an async function that copies `text` and resolves\n * to `true` on success, `false` on failure.\n *\n * @example\n * ```tsx\n * function CopyButton({ value }) {\n * const { copyToClipboard } = useCopyToClipboard();\n *\n * async function handleClick() {\n * const success = await copyToClipboard(value);\n * if (success) console.log(\"Copied!\");\n * }\n *\n * return <button onClick={handleClick}>Copy</button>;\n * }\n * ```\n */\n\nfunction useCopyToClipboard() {\n\tasync function copyToClipboard(text: string) {\n\t\ttry {\n\t\t\tawait navigator.clipboard.writeText(text);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\ttry {\n\t\t\t\treturn copyWithFallback(text);\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { copyToClipboard };\n}\n\nexport { useCopyToClipboard };\n"],"mappings":";AAUA,SAAS,EAAiB,GAAc;CACvC,IAAM,IAAW,SAAS,cAAc,UAAU;CAKlD,AAJA,EAAS,QAAQ,GACjB,EAAS,MAAM,WAAW,SAC1B,EAAS,MAAM,UAAU,KACzB,SAAS,KAAK,YAAY,CAAQ,GAClC,EAAS,OAAO;CAEhB,IAAI;EACH,OAAO,SAAS,YAAY,MAAM;CACnC,UAAU;EACT,SAAS,KAAK,YAAY,CAAQ;CACnC;AACD;AA2BA,SAAS,IAAqB;CAC7B,eAAe,EAAgB,GAAc;EAC5C,IAAI;GAEH,OADA,MAAM,UAAU,UAAU,UAAU,CAAI,GACjC;EACR,QAAQ;GACP,IAAI;IACH,OAAO,EAAiB,CAAI;GAC7B,QAAQ;IACP,OAAO;GACR;EACD;CACD;CAEA,OAAO,EAAE,mBAAgB;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkyn/components",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"files": [
|
|
39
39
|
"dist",
|
|
40
40
|
"README.md",
|
|
41
|
+
"AGENTS.md",
|
|
41
42
|
"LICENSE.txt",
|
|
42
43
|
"styles.d.ts"
|
|
43
44
|
],
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
"devDependencies": {
|
|
113
114
|
"@react-google-maps/api": "^2.20.8",
|
|
114
115
|
"@react-input/mask": "^2.0.4",
|
|
115
|
-
"@testing-library/jest-dom": "^
|
|
116
|
+
"@testing-library/jest-dom": "^7.0.0",
|
|
116
117
|
"@testing-library/react": "^16.3.2",
|
|
117
118
|
"@testing-library/user-event": "^14.6.1",
|
|
118
119
|
"@types/bun": "catalog:",
|
|
@@ -715,6 +716,11 @@
|
|
|
715
716
|
"types": "./dist/hooks/useAutomation.d.ts",
|
|
716
717
|
"default": "./dist/modules/hooks/useAutomation.js"
|
|
717
718
|
},
|
|
719
|
+
"./useCopyToClipboard": {
|
|
720
|
+
"import": "./dist/modules/hooks/useCopyToClipboard.js",
|
|
721
|
+
"types": "./dist/hooks/useCopyToClipboard.d.ts",
|
|
722
|
+
"default": "./dist/modules/hooks/useCopyToClipboard.js"
|
|
723
|
+
},
|
|
718
724
|
"./useDrawer": {
|
|
719
725
|
"import": "./dist/modules/hooks/useDrawer.js",
|
|
720
726
|
"types": "./dist/hooks/useDrawer.d.ts",
|
|
@@ -1105,6 +1111,9 @@
|
|
|
1105
1111
|
"useAutomation": [
|
|
1106
1112
|
"./dist/hooks/useAutomation.d.ts"
|
|
1107
1113
|
],
|
|
1114
|
+
"useCopyToClipboard": [
|
|
1115
|
+
"./dist/hooks/useCopyToClipboard.d.ts"
|
|
1116
|
+
],
|
|
1108
1117
|
"useDrawer": [
|
|
1109
1118
|
"./dist/hooks/useDrawer.d.ts"
|
|
1110
1119
|
],
|