@entry-ui/utilities 0.6.0 → 0.7.0

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,2 @@
1
+ var n=async a=>{let{value:p,onSuccess:e,onError:r}=a,t=document.defaultView||window;try{if(!t.navigator.clipboard?.writeText){r?.({type:"NOT_SUPPORTED"});return}await t.navigator.clipboard.writeText(p),e?.();}catch(o){let i=o instanceof Error?o.message:String(o);r?.({type:"COPY_FAILED",message:i});}};export{n as a};//# sourceMappingURL=chunk-P7NW64IN.js.map
2
+ //# sourceMappingURL=chunk-P7NW64IN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/copy-to-clipboard/copy-to-clipboard.ts"],"names":["copyToClipboard","params","value","onSuccess","onError","win","error","message"],"mappings":"AAqBO,IAAMA,CAAAA,CAAkB,MAAOC,CAAAA,EAAkC,CACtE,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,SAAA,CAAAC,CAAAA,CAAW,OAAA,CAAAC,CAAQ,EAAIH,CAAAA,CAEhCI,CAAAA,CAAM,QAAA,CAAS,WAAA,EAAe,MAAA,CAEpC,GAAI,CACF,GAAI,CAACA,CAAAA,CAAI,SAAA,CAAU,SAAA,EAAW,SAAA,CAAW,CACvCD,CAAAA,GAAU,CAAE,KAAM,eAAgB,CAAC,CAAA,CACnC,MACF,CAEA,MAAMC,CAAAA,CAAI,SAAA,CAAU,SAAA,CAAU,SAAA,CAAUH,CAAK,CAAA,CAC7CC,CAAAA,KACF,CAAA,MAASG,CAAAA,CAAO,CACd,IAAMC,CAAAA,CAAUD,CAAAA,YAAiB,KAAA,CAAQA,CAAAA,CAAM,OAAA,CAAU,MAAA,CAAOA,CAAK,CAAA,CACrEF,CAAAA,GAAU,CAAE,IAAA,CAAM,aAAA,CAAe,OAAA,CAAAG,CAAQ,CAAC,EAC5C,CACF","file":"chunk-P7NW64IN.js","sourcesContent":["import type { CopyToClipboardParams } from './copy-to-clipboard.types';\n\n/**\n * Asynchronously transfers text to the system clipboard using the Clipboard API.\n *\n * This utility provides a structured wrapper around `navigator.clipboard.writeText`,\n * offering specific error types to distinguish between unsupported environments\n * and runtime failures.\n *\n * This function expects a browser environment where `window` or\n * `document` is globally available.\n *\n * @example\n * ```ts\n * copyToClipboard({\n * \tvalue: \"Hello World\",\n * \tonSuccess: () => console.log(\"Text copied!\"),\n * \tonError: (err) => console.error(`Copy failed: ${err.type}, ${err.message}`),\n * });\n * ```\n */\nexport const copyToClipboard = async (params: CopyToClipboardParams) => {\n const { value, onSuccess, onError } = params;\n\n const win = document.defaultView || window;\n\n try {\n if (!win.navigator.clipboard?.writeText) {\n onError?.({ type: 'NOT_SUPPORTED' });\n return;\n }\n\n await win.navigator.clipboard.writeText(value);\n onSuccess?.();\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n onError?.({ type: 'COPY_FAILED', message });\n }\n};\n"]}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Represents a structured error object returned when a clipboard operation fails.
3
+ *
4
+ * This interface provides a uniform error shape to distinguish between
5
+ * environment-level limitations and unexpected runtime failures,
6
+ * allowing consumers to handle each case appropriately.
7
+ */
8
+ interface ClipboardError {
9
+ /**
10
+ * The classification of the failure.
11
+ * - `"NOT_SUPPORTED"`: The browser lacks `navigator.clipboard.writeText` support.
12
+ * - `"COPY_FAILED"`: The operation was rejected (e.g., lack of permissions).
13
+ */
14
+ type: 'NOT_SUPPORTED' | 'COPY_FAILED';
15
+ /**
16
+ * A descriptive message detailing the cause of the failure.
17
+ * This field is populated exclusively when the error `type` is `"COPY_FAILED"`,
18
+ * typically containing the message from the native `Error` object.
19
+ */
20
+ message?: string;
21
+ }
22
+ /**
23
+ * Configuration object for the `copyToClipboard` utility.
24
+ *
25
+ * This interface encapsulates the parameters required to perform a clipboard write operation.
26
+ * It allows the caller to define custom behavior for both successful data persistence
27
+ * and potential browser-level restrictions or runtime failures through dedicated
28
+ * callback handlers.
29
+ */
30
+ interface CopyToClipboardParams {
31
+ /**
32
+ * The plaintext string to be transferred to the system clipboard.
33
+ * This value is processed as a standard UTF-16 string by the Clipboard API.
34
+ */
35
+ value: string;
36
+ /**
37
+ * An optional callback executed immediately after the value has been successfully
38
+ * written to the clipboard. Use this to trigger UI feedback like "Copied!" toasts
39
+ * or success state updates.
40
+ *
41
+ * @default undefined
42
+ */
43
+ onSuccess?: () => void;
44
+ /**
45
+ * An optional callback executed when the copy operation fails or is not supported.
46
+ * It provides structured error information to distinguish between environment
47
+ * limitations (`"NOT_SUPPORTED"`) and unexpected runtime rejections (`"COPY_FAILED"`).
48
+ *
49
+ * @default undefined
50
+ */
51
+ onError?: (error: ClipboardError) => void;
52
+ }
53
+
54
+ /**
55
+ * Asynchronously transfers text to the system clipboard using the Clipboard API.
56
+ *
57
+ * This utility provides a structured wrapper around `navigator.clipboard.writeText`,
58
+ * offering specific error types to distinguish between unsupported environments
59
+ * and runtime failures.
60
+ *
61
+ * This function expects a browser environment where `window` or
62
+ * `document` is globally available.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * copyToClipboard({
67
+ * value: "Hello World",
68
+ * onSuccess: () => console.log("Text copied!"),
69
+ * onError: (err) => console.error(`Copy failed: ${err.type}, ${err.message}`),
70
+ * });
71
+ * ```
72
+ */
73
+ declare const copyToClipboard: (params: CopyToClipboardParams) => Promise<void>;
74
+
75
+ export { type ClipboardError, type CopyToClipboardParams, copyToClipboard };
@@ -0,0 +1,2 @@
1
+ export{a as copyToClipboard}from'../chunk-P7NW64IN.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { AddEventListenerOnceParams, AllEventMaps, addEventListenerOnce } from './add-event-listener-once/index.js';
2
2
  export { ClampParams, clamp } from './clamp/index.js';
3
+ export { ClipboardError, CopyToClipboardParams, copyToClipboard } from './copy-to-clipboard/index.js';
3
4
  export { ErrorParams, error } from './error/index.js';
4
5
  export { FailParams, fail } from './fail/index.js';
5
6
  export { getComputedStyle } from './get-computed-style/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export{a as warn}from'./chunk-6L6DIP5N.js';export{a as mergeStyles}from'./chunk-NBN5PUZ6.js';export{a as scrollIntoViewIfNeeded}from'./chunk-YFUOSM2Q.js';export{a as visuallyHiddenInputStyle}from'./chunk-AYHMR4G2.js';export{a as visuallyHiddenStyle}from'./chunk-YRBGPPKC.js';export{a as wait}from'./chunk-OUZ54COH.js';export{a as addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as clamp}from'./chunk-BVBN4VWU.js';export{a as isValidNumber}from'./chunk-TAV72HQS.js';export{a as error}from'./chunk-GG6DRWSS.js';export{a as fail}from'./chunk-O4WYO5SA.js';export{a as getHiddenElementHeight}from'./chunk-RZEIOZGJ.js';export{a as getCssDimensions}from'./chunk-TJWADQ7V.js';export{a as isHTMLElement}from'./chunk-KSDRQLOI.js';export{a as hasWindow}from'./chunk-V3434ODU.js';export{a as getComputedStyle}from'./chunk-5BI2X7JA.js';export{a as getWindow}from'./chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
1
+ export{a as visuallyHiddenStyle}from'./chunk-YRBGPPKC.js';export{a as wait}from'./chunk-OUZ54COH.js';export{a as warn}from'./chunk-6L6DIP5N.js';export{a as getHiddenElementHeight}from'./chunk-RZEIOZGJ.js';export{a as mergeStyles}from'./chunk-NBN5PUZ6.js';export{a as scrollIntoViewIfNeeded}from'./chunk-YFUOSM2Q.js';export{a as visuallyHiddenInputStyle}from'./chunk-AYHMR4G2.js';export{a as addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as clamp}from'./chunk-BVBN4VWU.js';export{a as isValidNumber}from'./chunk-TAV72HQS.js';export{a as copyToClipboard}from'./chunk-P7NW64IN.js';export{a as error}from'./chunk-GG6DRWSS.js';export{a as fail}from'./chunk-O4WYO5SA.js';export{a as getCssDimensions}from'./chunk-TJWADQ7V.js';export{a as isHTMLElement}from'./chunk-KSDRQLOI.js';export{a as hasWindow}from'./chunk-V3434ODU.js';export{a as getComputedStyle}from'./chunk-5BI2X7JA.js';export{a as getWindow}from'./chunk-H2U5U7XY.js';//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entry-ui/utilities",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/ZAHON/entry-ui/tree/main/packages/utilities#readme",