@arkyn/components 3.0.6 → 3.0.7

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.
@@ -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.6",
3
+ "version": "3.0.7",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -112,7 +112,7 @@
112
112
  "devDependencies": {
113
113
  "@react-google-maps/api": "^2.20.8",
114
114
  "@react-input/mask": "^2.0.4",
115
- "@testing-library/jest-dom": "^6.9.1",
115
+ "@testing-library/jest-dom": "^7.0.0",
116
116
  "@testing-library/react": "^16.3.2",
117
117
  "@testing-library/user-event": "^14.6.1",
118
118
  "@types/bun": "catalog:",
@@ -715,6 +715,11 @@
715
715
  "types": "./dist/hooks/useAutomation.d.ts",
716
716
  "default": "./dist/modules/hooks/useAutomation.js"
717
717
  },
718
+ "./useCopyToClipboard": {
719
+ "import": "./dist/modules/hooks/useCopyToClipboard.js",
720
+ "types": "./dist/hooks/useCopyToClipboard.d.ts",
721
+ "default": "./dist/modules/hooks/useCopyToClipboard.js"
722
+ },
718
723
  "./useDrawer": {
719
724
  "import": "./dist/modules/hooks/useDrawer.js",
720
725
  "types": "./dist/hooks/useDrawer.d.ts",
@@ -1105,6 +1110,9 @@
1105
1110
  "useAutomation": [
1106
1111
  "./dist/hooks/useAutomation.d.ts"
1107
1112
  ],
1113
+ "useCopyToClipboard": [
1114
+ "./dist/hooks/useCopyToClipboard.d.ts"
1115
+ ],
1108
1116
  "useDrawer": [
1109
1117
  "./dist/hooks/useDrawer.d.ts"
1110
1118
  ],