@zag-js/clipboard 1.34.0 → 1.35.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,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "control" | "trigger" | "indicator" | "input" | "label">;
4
+ declare const parts: Record<"root" | "control" | "trigger" | "indicator" | "input" | "label", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "control" | "trigger" | "indicator" | "input" | "label">;
4
+ declare const parts: Record<"root" | "control" | "trigger" | "indicator" | "input" | "label", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/clipboard.anatomy.ts
21
+ var clipboard_anatomy_exports = {};
22
+ __export(clipboard_anatomy_exports, {
23
+ anatomy: () => anatomy,
24
+ parts: () => parts
25
+ });
26
+ module.exports = __toCommonJS(clipboard_anatomy_exports);
27
+ var import_anatomy = require("@zag-js/anatomy");
28
+ var anatomy = (0, import_anatomy.createAnatomy)("clipboard").parts("root", "control", "trigger", "indicator", "input", "label");
29
+ var parts = anatomy.build();
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ anatomy,
33
+ parts
34
+ });
@@ -0,0 +1,8 @@
1
+ // src/clipboard.anatomy.ts
2
+ import { createAnatomy } from "@zag-js/anatomy";
3
+ var anatomy = createAnatomy("clipboard").parts("root", "control", "trigger", "indicator", "input", "label");
4
+ var parts = anatomy.build();
5
+ export {
6
+ anatomy,
7
+ parts
8
+ };
@@ -0,0 +1,7 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { ClipboardService, ClipboardApi } from './clipboard.types.mjs';
3
+ import '@zag-js/core';
4
+
5
+ declare function connect<T extends PropTypes>(service: ClipboardService, normalize: NormalizeProps<T>): ClipboardApi<T>;
6
+
7
+ export { connect };
@@ -0,0 +1,7 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { ClipboardService, ClipboardApi } from './clipboard.types.js';
3
+ import '@zag-js/core';
4
+
5
+ declare function connect<T extends PropTypes>(service: ClipboardService, normalize: NormalizeProps<T>): ClipboardApi<T>;
6
+
7
+ export { connect };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/clipboard.connect.ts
31
+ var clipboard_connect_exports = {};
32
+ __export(clipboard_connect_exports, {
33
+ connect: () => connect
34
+ });
35
+ module.exports = __toCommonJS(clipboard_connect_exports);
36
+ var import_dom_query = require("@zag-js/dom-query");
37
+ var import_clipboard = require("./clipboard.anatomy.cjs");
38
+ var dom = __toESM(require("./clipboard.dom.cjs"));
39
+ function connect(service, normalize) {
40
+ const { state, send, context, scope } = service;
41
+ const copied = state.matches("copied");
42
+ return {
43
+ copied,
44
+ value: context.get("value"),
45
+ setValue(value) {
46
+ send({ type: "VALUE.SET", value });
47
+ },
48
+ copy() {
49
+ send({ type: "COPY" });
50
+ },
51
+ getRootProps() {
52
+ return normalize.element({
53
+ ...import_clipboard.parts.root.attrs,
54
+ "data-copied": (0, import_dom_query.dataAttr)(copied),
55
+ id: dom.getRootId(scope)
56
+ });
57
+ },
58
+ getLabelProps() {
59
+ return normalize.label({
60
+ ...import_clipboard.parts.label.attrs,
61
+ htmlFor: dom.getInputId(scope),
62
+ "data-copied": (0, import_dom_query.dataAttr)(copied),
63
+ id: dom.getLabelId(scope)
64
+ });
65
+ },
66
+ getControlProps() {
67
+ return normalize.element({
68
+ ...import_clipboard.parts.control.attrs,
69
+ "data-copied": (0, import_dom_query.dataAttr)(copied)
70
+ });
71
+ },
72
+ getInputProps() {
73
+ return normalize.input({
74
+ ...import_clipboard.parts.input.attrs,
75
+ defaultValue: context.get("value"),
76
+ "data-copied": (0, import_dom_query.dataAttr)(copied),
77
+ readOnly: true,
78
+ "data-readonly": "true",
79
+ id: dom.getInputId(scope),
80
+ onFocus(event) {
81
+ event.currentTarget.select();
82
+ },
83
+ onCopy() {
84
+ send({ type: "INPUT.COPY" });
85
+ }
86
+ });
87
+ },
88
+ getTriggerProps() {
89
+ return normalize.button({
90
+ ...import_clipboard.parts.trigger.attrs,
91
+ type: "button",
92
+ "aria-label": copied ? "Copied to clipboard" : "Copy to clipboard",
93
+ "data-copied": (0, import_dom_query.dataAttr)(copied),
94
+ onClick() {
95
+ send({ type: "COPY" });
96
+ }
97
+ });
98
+ },
99
+ getIndicatorProps(props) {
100
+ return normalize.element({
101
+ ...import_clipboard.parts.indicator.attrs,
102
+ hidden: props.copied !== copied
103
+ });
104
+ }
105
+ };
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ connect
110
+ });
@@ -0,0 +1,75 @@
1
+ // src/clipboard.connect.ts
2
+ import { dataAttr } from "@zag-js/dom-query";
3
+ import { parts } from "./clipboard.anatomy.mjs";
4
+ import * as dom from "./clipboard.dom.mjs";
5
+ function connect(service, normalize) {
6
+ const { state, send, context, scope } = service;
7
+ const copied = state.matches("copied");
8
+ return {
9
+ copied,
10
+ value: context.get("value"),
11
+ setValue(value) {
12
+ send({ type: "VALUE.SET", value });
13
+ },
14
+ copy() {
15
+ send({ type: "COPY" });
16
+ },
17
+ getRootProps() {
18
+ return normalize.element({
19
+ ...parts.root.attrs,
20
+ "data-copied": dataAttr(copied),
21
+ id: dom.getRootId(scope)
22
+ });
23
+ },
24
+ getLabelProps() {
25
+ return normalize.label({
26
+ ...parts.label.attrs,
27
+ htmlFor: dom.getInputId(scope),
28
+ "data-copied": dataAttr(copied),
29
+ id: dom.getLabelId(scope)
30
+ });
31
+ },
32
+ getControlProps() {
33
+ return normalize.element({
34
+ ...parts.control.attrs,
35
+ "data-copied": dataAttr(copied)
36
+ });
37
+ },
38
+ getInputProps() {
39
+ return normalize.input({
40
+ ...parts.input.attrs,
41
+ defaultValue: context.get("value"),
42
+ "data-copied": dataAttr(copied),
43
+ readOnly: true,
44
+ "data-readonly": "true",
45
+ id: dom.getInputId(scope),
46
+ onFocus(event) {
47
+ event.currentTarget.select();
48
+ },
49
+ onCopy() {
50
+ send({ type: "INPUT.COPY" });
51
+ }
52
+ });
53
+ },
54
+ getTriggerProps() {
55
+ return normalize.button({
56
+ ...parts.trigger.attrs,
57
+ type: "button",
58
+ "aria-label": copied ? "Copied to clipboard" : "Copy to clipboard",
59
+ "data-copied": dataAttr(copied),
60
+ onClick() {
61
+ send({ type: "COPY" });
62
+ }
63
+ });
64
+ },
65
+ getIndicatorProps(props) {
66
+ return normalize.element({
67
+ ...parts.indicator.attrs,
68
+ hidden: props.copied !== copied
69
+ });
70
+ }
71
+ };
72
+ }
73
+ export {
74
+ connect
75
+ };
@@ -0,0 +1,9 @@
1
+ import { Scope } from '@zag-js/core';
2
+
3
+ declare const getRootId: (ctx: Scope) => any;
4
+ declare const getInputId: (ctx: Scope) => any;
5
+ declare const getLabelId: (ctx: Scope) => any;
6
+ declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
7
+ declare const writeToClipboard: (ctx: Scope, value: string) => Promise<void>;
8
+
9
+ export { getInputEl, getInputId, getLabelId, getRootId, writeToClipboard };
@@ -0,0 +1,9 @@
1
+ import { Scope } from '@zag-js/core';
2
+
3
+ declare const getRootId: (ctx: Scope) => any;
4
+ declare const getInputId: (ctx: Scope) => any;
5
+ declare const getLabelId: (ctx: Scope) => any;
6
+ declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
7
+ declare const writeToClipboard: (ctx: Scope, value: string) => Promise<void>;
8
+
9
+ export { getInputEl, getInputId, getLabelId, getRootId, writeToClipboard };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/clipboard.dom.ts
21
+ var clipboard_dom_exports = {};
22
+ __export(clipboard_dom_exports, {
23
+ getInputEl: () => getInputEl,
24
+ getInputId: () => getInputId,
25
+ getLabelId: () => getLabelId,
26
+ getRootId: () => getRootId,
27
+ writeToClipboard: () => writeToClipboard
28
+ });
29
+ module.exports = __toCommonJS(clipboard_dom_exports);
30
+ var import_dom_query = require("@zag-js/dom-query");
31
+ var getRootId = (ctx) => ctx.ids?.root ?? `clip:${ctx.id}`;
32
+ var getInputId = (ctx) => ctx.ids?.input ?? `clip:${ctx.id}:input`;
33
+ var getLabelId = (ctx) => ctx.ids?.label ?? `clip:${ctx.id}:label`;
34
+ var getInputEl = (ctx) => ctx.getById(getInputId(ctx));
35
+ var writeToClipboard = (ctx, value) => copyText(ctx.getDoc(), value);
36
+ function createNode(doc, text) {
37
+ const node = doc.createElement("pre");
38
+ Object.assign(node.style, {
39
+ width: "1px",
40
+ height: "1px",
41
+ position: "fixed",
42
+ top: "5px"
43
+ });
44
+ node.textContent = text;
45
+ return node;
46
+ }
47
+ function copyNode(node) {
48
+ const win = (0, import_dom_query.getWindow)(node);
49
+ const selection = win.getSelection();
50
+ if (selection == null) {
51
+ return Promise.reject(new Error());
52
+ }
53
+ selection.removeAllRanges();
54
+ const doc = node.ownerDocument;
55
+ const range = doc.createRange();
56
+ range.selectNodeContents(node);
57
+ selection.addRange(range);
58
+ doc.execCommand("copy");
59
+ selection.removeAllRanges();
60
+ return Promise.resolve();
61
+ }
62
+ function copyText(doc, text) {
63
+ const win = doc.defaultView || window;
64
+ if (win.navigator.clipboard?.writeText !== void 0) {
65
+ return win.navigator.clipboard.writeText(text);
66
+ }
67
+ if (!doc.body) {
68
+ return Promise.reject(new Error());
69
+ }
70
+ const node = createNode(doc, text);
71
+ doc.body.appendChild(node);
72
+ copyNode(node);
73
+ doc.body.removeChild(node);
74
+ return Promise.resolve();
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ getInputEl,
79
+ getInputId,
80
+ getLabelId,
81
+ getRootId,
82
+ writeToClipboard
83
+ });
@@ -0,0 +1,54 @@
1
+ // src/clipboard.dom.ts
2
+ import { getWindow } from "@zag-js/dom-query";
3
+ var getRootId = (ctx) => ctx.ids?.root ?? `clip:${ctx.id}`;
4
+ var getInputId = (ctx) => ctx.ids?.input ?? `clip:${ctx.id}:input`;
5
+ var getLabelId = (ctx) => ctx.ids?.label ?? `clip:${ctx.id}:label`;
6
+ var getInputEl = (ctx) => ctx.getById(getInputId(ctx));
7
+ var writeToClipboard = (ctx, value) => copyText(ctx.getDoc(), value);
8
+ function createNode(doc, text) {
9
+ const node = doc.createElement("pre");
10
+ Object.assign(node.style, {
11
+ width: "1px",
12
+ height: "1px",
13
+ position: "fixed",
14
+ top: "5px"
15
+ });
16
+ node.textContent = text;
17
+ return node;
18
+ }
19
+ function copyNode(node) {
20
+ const win = getWindow(node);
21
+ const selection = win.getSelection();
22
+ if (selection == null) {
23
+ return Promise.reject(new Error());
24
+ }
25
+ selection.removeAllRanges();
26
+ const doc = node.ownerDocument;
27
+ const range = doc.createRange();
28
+ range.selectNodeContents(node);
29
+ selection.addRange(range);
30
+ doc.execCommand("copy");
31
+ selection.removeAllRanges();
32
+ return Promise.resolve();
33
+ }
34
+ function copyText(doc, text) {
35
+ const win = doc.defaultView || window;
36
+ if (win.navigator.clipboard?.writeText !== void 0) {
37
+ return win.navigator.clipboard.writeText(text);
38
+ }
39
+ if (!doc.body) {
40
+ return Promise.reject(new Error());
41
+ }
42
+ const node = createNode(doc, text);
43
+ doc.body.appendChild(node);
44
+ copyNode(node);
45
+ doc.body.removeChild(node);
46
+ return Promise.resolve();
47
+ }
48
+ export {
49
+ getInputEl,
50
+ getInputId,
51
+ getLabelId,
52
+ getRootId,
53
+ writeToClipboard
54
+ };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { ClipboardSchema } from './clipboard.types.mjs';
3
+ import '@zag-js/types';
4
+
5
+ declare const machine: _zag_js_core.Machine<ClipboardSchema>;
6
+
7
+ export { machine };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { ClipboardSchema } from './clipboard.types.js';
3
+ import '@zag-js/types';
4
+
5
+ declare const machine: _zag_js_core.Machine<ClipboardSchema>;
6
+
7
+ export { machine };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/clipboard.machine.ts
31
+ var clipboard_machine_exports = {};
32
+ __export(clipboard_machine_exports, {
33
+ machine: () => machine
34
+ });
35
+ module.exports = __toCommonJS(clipboard_machine_exports);
36
+ var import_core = require("@zag-js/core");
37
+ var import_dom_query = require("@zag-js/dom-query");
38
+ var import_utils = require("@zag-js/utils");
39
+ var dom = __toESM(require("./clipboard.dom.cjs"));
40
+ var machine = (0, import_core.createMachine)({
41
+ props({ props }) {
42
+ return {
43
+ timeout: 3e3,
44
+ defaultValue: "",
45
+ ...props
46
+ };
47
+ },
48
+ initialState() {
49
+ return "idle";
50
+ },
51
+ context({ prop, bindable }) {
52
+ return {
53
+ value: bindable(() => ({
54
+ defaultValue: prop("defaultValue"),
55
+ value: prop("value"),
56
+ onChange(value) {
57
+ prop("onValueChange")?.({ value });
58
+ }
59
+ }))
60
+ };
61
+ },
62
+ watch({ track, context, action }) {
63
+ track([() => context.get("value")], () => {
64
+ action(["syncInputElement"]);
65
+ });
66
+ },
67
+ on: {
68
+ "VALUE.SET": {
69
+ actions: ["setValue"]
70
+ },
71
+ COPY: {
72
+ target: "copied",
73
+ actions: ["copyToClipboard", "invokeOnCopy"]
74
+ }
75
+ },
76
+ states: {
77
+ idle: {
78
+ on: {
79
+ "INPUT.COPY": {
80
+ target: "copied",
81
+ actions: ["invokeOnCopy"]
82
+ }
83
+ }
84
+ },
85
+ copied: {
86
+ effects: ["waitForTimeout"],
87
+ on: {
88
+ "COPY.DONE": {
89
+ target: "idle"
90
+ },
91
+ COPY: {
92
+ target: "copied",
93
+ actions: ["copyToClipboard", "invokeOnCopy"]
94
+ },
95
+ "INPUT.COPY": {
96
+ actions: ["invokeOnCopy"]
97
+ }
98
+ }
99
+ }
100
+ },
101
+ implementations: {
102
+ effects: {
103
+ waitForTimeout({ prop, send }) {
104
+ return (0, import_utils.setRafTimeout)(() => {
105
+ send({ type: "COPY.DONE" });
106
+ }, prop("timeout"));
107
+ }
108
+ },
109
+ actions: {
110
+ setValue({ context, event }) {
111
+ context.set("value", event.value);
112
+ },
113
+ copyToClipboard({ context, scope }) {
114
+ dom.writeToClipboard(scope, context.get("value"));
115
+ },
116
+ invokeOnCopy({ prop }) {
117
+ prop("onStatusChange")?.({ copied: true });
118
+ },
119
+ syncInputElement({ context, scope }) {
120
+ const inputEl = dom.getInputEl(scope);
121
+ if (!inputEl) return;
122
+ (0, import_dom_query.setElementValue)(inputEl, context.get("value"));
123
+ }
124
+ }
125
+ }
126
+ });
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ machine
130
+ });
@@ -0,0 +1,95 @@
1
+ // src/clipboard.machine.ts
2
+ import { createMachine } from "@zag-js/core";
3
+ import { setElementValue } from "@zag-js/dom-query";
4
+ import { setRafTimeout } from "@zag-js/utils";
5
+ import * as dom from "./clipboard.dom.mjs";
6
+ var machine = createMachine({
7
+ props({ props }) {
8
+ return {
9
+ timeout: 3e3,
10
+ defaultValue: "",
11
+ ...props
12
+ };
13
+ },
14
+ initialState() {
15
+ return "idle";
16
+ },
17
+ context({ prop, bindable }) {
18
+ return {
19
+ value: bindable(() => ({
20
+ defaultValue: prop("defaultValue"),
21
+ value: prop("value"),
22
+ onChange(value) {
23
+ prop("onValueChange")?.({ value });
24
+ }
25
+ }))
26
+ };
27
+ },
28
+ watch({ track, context, action }) {
29
+ track([() => context.get("value")], () => {
30
+ action(["syncInputElement"]);
31
+ });
32
+ },
33
+ on: {
34
+ "VALUE.SET": {
35
+ actions: ["setValue"]
36
+ },
37
+ COPY: {
38
+ target: "copied",
39
+ actions: ["copyToClipboard", "invokeOnCopy"]
40
+ }
41
+ },
42
+ states: {
43
+ idle: {
44
+ on: {
45
+ "INPUT.COPY": {
46
+ target: "copied",
47
+ actions: ["invokeOnCopy"]
48
+ }
49
+ }
50
+ },
51
+ copied: {
52
+ effects: ["waitForTimeout"],
53
+ on: {
54
+ "COPY.DONE": {
55
+ target: "idle"
56
+ },
57
+ COPY: {
58
+ target: "copied",
59
+ actions: ["copyToClipboard", "invokeOnCopy"]
60
+ },
61
+ "INPUT.COPY": {
62
+ actions: ["invokeOnCopy"]
63
+ }
64
+ }
65
+ }
66
+ },
67
+ implementations: {
68
+ effects: {
69
+ waitForTimeout({ prop, send }) {
70
+ return setRafTimeout(() => {
71
+ send({ type: "COPY.DONE" });
72
+ }, prop("timeout"));
73
+ }
74
+ },
75
+ actions: {
76
+ setValue({ context, event }) {
77
+ context.set("value", event.value);
78
+ },
79
+ copyToClipboard({ context, scope }) {
80
+ dom.writeToClipboard(scope, context.get("value"));
81
+ },
82
+ invokeOnCopy({ prop }) {
83
+ prop("onStatusChange")?.({ copied: true });
84
+ },
85
+ syncInputElement({ context, scope }) {
86
+ const inputEl = dom.getInputEl(scope);
87
+ if (!inputEl) return;
88
+ setElementValue(inputEl, context.get("value"));
89
+ }
90
+ }
91
+ }
92
+ });
93
+ export {
94
+ machine
95
+ };
@@ -0,0 +1,10 @@
1
+ import { ClipboardProps, IndicatorProps } from './clipboard.types.mjs';
2
+ import '@zag-js/core';
3
+ import '@zag-js/types';
4
+
5
+ declare const props: (keyof ClipboardProps)[];
6
+ declare const contextProps: <Props extends ClipboardProps>(props: Props) => [ClipboardProps, Omit<Props, keyof ClipboardProps>];
7
+ declare const indicatorProps: "copied"[];
8
+ declare const splitIndicatorProps: <Props extends IndicatorProps>(props: Props) => [IndicatorProps, Omit<Props, "copied">];
9
+
10
+ export { contextProps, indicatorProps, props, splitIndicatorProps };