@zag-js/clipboard 2.0.0-next.0 → 2.0.0-next.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/clipboard.connect.js +11 -2
- package/dist/clipboard.connect.mjs +11 -2
- package/dist/clipboard.machine.js +1 -5
- package/dist/clipboard.machine.mjs +1 -5
- package/dist/clipboard.types.d.mts +23 -8
- package/dist/clipboard.types.d.ts +23 -8
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +11 -8
|
@@ -34,12 +34,19 @@ __export(clipboard_connect_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(clipboard_connect_exports);
|
|
36
36
|
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var import_utils = require("@zag-js/utils");
|
|
37
38
|
var import_clipboard = require("./clipboard.anatomy.js");
|
|
38
39
|
var dom = __toESM(require("./clipboard.dom.js"));
|
|
40
|
+
var defaultTranslations = {
|
|
41
|
+
triggerLabel: (copied) => copied ? "Copied to clipboard" : "Copy to clipboard"
|
|
42
|
+
};
|
|
39
43
|
function connect(service, normalize) {
|
|
40
44
|
const { state, send, context, scope, prop } = service;
|
|
41
45
|
const copied = state.matches("copied");
|
|
42
|
-
const translations = prop("translations");
|
|
46
|
+
const translations = (0, import_utils.mergeWithDefault)(defaultTranslations, prop("translations"));
|
|
47
|
+
function getIndicatorState(props) {
|
|
48
|
+
return { copied: props.copied, visible: props.copied === copied };
|
|
49
|
+
}
|
|
43
50
|
return {
|
|
44
51
|
copied,
|
|
45
52
|
value: context.get("value"),
|
|
@@ -96,10 +103,12 @@ function connect(service, normalize) {
|
|
|
96
103
|
}
|
|
97
104
|
});
|
|
98
105
|
},
|
|
106
|
+
getIndicatorState,
|
|
99
107
|
getIndicatorProps(props) {
|
|
108
|
+
const indicatorState = getIndicatorState(props);
|
|
100
109
|
return normalize.element({
|
|
101
110
|
...import_clipboard.parts.indicator.attrs(scope.id),
|
|
102
|
-
hidden:
|
|
111
|
+
hidden: !indicatorState.visible
|
|
103
112
|
});
|
|
104
113
|
}
|
|
105
114
|
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
// src/clipboard.connect.ts
|
|
2
2
|
import { dataAttr } from "@zag-js/dom-query";
|
|
3
|
+
import { mergeWithDefault } from "@zag-js/utils";
|
|
3
4
|
import { parts } from "./clipboard.anatomy.mjs";
|
|
4
5
|
import * as dom from "./clipboard.dom.mjs";
|
|
6
|
+
var defaultTranslations = {
|
|
7
|
+
triggerLabel: (copied) => copied ? "Copied to clipboard" : "Copy to clipboard"
|
|
8
|
+
};
|
|
5
9
|
function connect(service, normalize) {
|
|
6
10
|
const { state, send, context, scope, prop } = service;
|
|
7
11
|
const copied = state.matches("copied");
|
|
8
|
-
const translations = prop("translations");
|
|
12
|
+
const translations = mergeWithDefault(defaultTranslations, prop("translations"));
|
|
13
|
+
function getIndicatorState(props) {
|
|
14
|
+
return { copied: props.copied, visible: props.copied === copied };
|
|
15
|
+
}
|
|
9
16
|
return {
|
|
10
17
|
copied,
|
|
11
18
|
value: context.get("value"),
|
|
@@ -62,10 +69,12 @@ function connect(service, normalize) {
|
|
|
62
69
|
}
|
|
63
70
|
});
|
|
64
71
|
},
|
|
72
|
+
getIndicatorState,
|
|
65
73
|
getIndicatorProps(props) {
|
|
74
|
+
const indicatorState = getIndicatorState(props);
|
|
66
75
|
return normalize.element({
|
|
67
76
|
...parts.indicator.attrs(scope.id),
|
|
68
|
-
hidden:
|
|
77
|
+
hidden: !indicatorState.visible
|
|
69
78
|
});
|
|
70
79
|
}
|
|
71
80
|
};
|
|
@@ -42,11 +42,7 @@ var machine = (0, import_core.createMachine)({
|
|
|
42
42
|
return {
|
|
43
43
|
timeout: 3e3,
|
|
44
44
|
defaultValue: "",
|
|
45
|
-
...props
|
|
46
|
-
translations: {
|
|
47
|
-
triggerLabel: (copied) => copied ? "Copied to clipboard" : "Copy to clipboard",
|
|
48
|
-
...props.translations
|
|
49
|
-
}
|
|
45
|
+
...props
|
|
50
46
|
};
|
|
51
47
|
},
|
|
52
48
|
initialState() {
|
|
@@ -8,11 +8,7 @@ var machine = createMachine({
|
|
|
8
8
|
return {
|
|
9
9
|
timeout: 3e3,
|
|
10
10
|
defaultValue: "",
|
|
11
|
-
...props
|
|
12
|
-
translations: {
|
|
13
|
-
triggerLabel: (copied) => copied ? "Copied to clipboard" : "Copy to clipboard",
|
|
14
|
-
...props.translations
|
|
15
|
-
}
|
|
11
|
+
...props
|
|
16
12
|
};
|
|
17
13
|
},
|
|
18
14
|
initialState() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Service, Machine } from '@zag-js/core';
|
|
2
|
-
import {
|
|
2
|
+
import { CommonProperties, PropTypes } from '@zag-js/types';
|
|
3
3
|
|
|
4
4
|
interface CopyStatusDetails {
|
|
5
5
|
copied: boolean;
|
|
@@ -10,11 +10,11 @@ interface ValueChangeDetails {
|
|
|
10
10
|
interface IntlTranslations {
|
|
11
11
|
triggerLabel?: ((copied: boolean) => string) | undefined;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
root
|
|
15
|
-
input
|
|
16
|
-
label
|
|
17
|
-
}
|
|
13
|
+
interface ElementIds {
|
|
14
|
+
root?: string | undefined;
|
|
15
|
+
input?: string | undefined;
|
|
16
|
+
label?: string | undefined;
|
|
17
|
+
}
|
|
18
18
|
interface ClipboardProps extends CommonProperties {
|
|
19
19
|
/**
|
|
20
20
|
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
@@ -49,7 +49,8 @@ interface ClipboardProps extends CommonProperties {
|
|
|
49
49
|
}
|
|
50
50
|
interface ClipboardSchema {
|
|
51
51
|
state: "idle" | "copied";
|
|
52
|
-
props:
|
|
52
|
+
props: ClipboardProps;
|
|
53
|
+
defaultPropKey: "timeout" | "translations";
|
|
53
54
|
context: {
|
|
54
55
|
value: string;
|
|
55
56
|
};
|
|
@@ -62,6 +63,16 @@ type ClipboardMachine = Machine<ClipboardSchema>;
|
|
|
62
63
|
interface IndicatorProps {
|
|
63
64
|
copied: boolean;
|
|
64
65
|
}
|
|
66
|
+
interface IndicatorState {
|
|
67
|
+
/**
|
|
68
|
+
* The copied state this indicator represents
|
|
69
|
+
*/
|
|
70
|
+
copied: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the indicator matches the current copied state
|
|
73
|
+
*/
|
|
74
|
+
visible: boolean;
|
|
75
|
+
}
|
|
65
76
|
interface ClipboardApi<T extends PropTypes = PropTypes> {
|
|
66
77
|
/**
|
|
67
78
|
* Whether the value has been copied to the clipboard
|
|
@@ -84,7 +95,11 @@ interface ClipboardApi<T extends PropTypes = PropTypes> {
|
|
|
84
95
|
getControlProps: () => T["element"];
|
|
85
96
|
getTriggerProps: () => T["button"];
|
|
86
97
|
getInputProps: () => T["input"];
|
|
98
|
+
/**
|
|
99
|
+
* Returns the state of the indicator
|
|
100
|
+
*/
|
|
101
|
+
getIndicatorState: (props: IndicatorProps) => IndicatorState;
|
|
87
102
|
getIndicatorProps: (props: IndicatorProps) => T["element"];
|
|
88
103
|
}
|
|
89
104
|
|
|
90
|
-
export type { ClipboardApi, ClipboardMachine, ClipboardProps, ClipboardSchema, ClipboardService, CopyStatusDetails, ElementIds, IndicatorProps, IntlTranslations, ValueChangeDetails };
|
|
105
|
+
export type { ClipboardApi, ClipboardMachine, ClipboardProps, ClipboardSchema, ClipboardService, CopyStatusDetails, ElementIds, IndicatorProps, IndicatorState, IntlTranslations, ValueChangeDetails };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Service, Machine } from '@zag-js/core';
|
|
2
|
-
import {
|
|
2
|
+
import { CommonProperties, PropTypes } from '@zag-js/types';
|
|
3
3
|
|
|
4
4
|
interface CopyStatusDetails {
|
|
5
5
|
copied: boolean;
|
|
@@ -10,11 +10,11 @@ interface ValueChangeDetails {
|
|
|
10
10
|
interface IntlTranslations {
|
|
11
11
|
triggerLabel?: ((copied: boolean) => string) | undefined;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
root
|
|
15
|
-
input
|
|
16
|
-
label
|
|
17
|
-
}
|
|
13
|
+
interface ElementIds {
|
|
14
|
+
root?: string | undefined;
|
|
15
|
+
input?: string | undefined;
|
|
16
|
+
label?: string | undefined;
|
|
17
|
+
}
|
|
18
18
|
interface ClipboardProps extends CommonProperties {
|
|
19
19
|
/**
|
|
20
20
|
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
@@ -49,7 +49,8 @@ interface ClipboardProps extends CommonProperties {
|
|
|
49
49
|
}
|
|
50
50
|
interface ClipboardSchema {
|
|
51
51
|
state: "idle" | "copied";
|
|
52
|
-
props:
|
|
52
|
+
props: ClipboardProps;
|
|
53
|
+
defaultPropKey: "timeout" | "translations";
|
|
53
54
|
context: {
|
|
54
55
|
value: string;
|
|
55
56
|
};
|
|
@@ -62,6 +63,16 @@ type ClipboardMachine = Machine<ClipboardSchema>;
|
|
|
62
63
|
interface IndicatorProps {
|
|
63
64
|
copied: boolean;
|
|
64
65
|
}
|
|
66
|
+
interface IndicatorState {
|
|
67
|
+
/**
|
|
68
|
+
* The copied state this indicator represents
|
|
69
|
+
*/
|
|
70
|
+
copied: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the indicator matches the current copied state
|
|
73
|
+
*/
|
|
74
|
+
visible: boolean;
|
|
75
|
+
}
|
|
65
76
|
interface ClipboardApi<T extends PropTypes = PropTypes> {
|
|
66
77
|
/**
|
|
67
78
|
* Whether the value has been copied to the clipboard
|
|
@@ -84,7 +95,11 @@ interface ClipboardApi<T extends PropTypes = PropTypes> {
|
|
|
84
95
|
getControlProps: () => T["element"];
|
|
85
96
|
getTriggerProps: () => T["button"];
|
|
86
97
|
getInputProps: () => T["input"];
|
|
98
|
+
/**
|
|
99
|
+
* Returns the state of the indicator
|
|
100
|
+
*/
|
|
101
|
+
getIndicatorState: (props: IndicatorProps) => IndicatorState;
|
|
87
102
|
getIndicatorProps: (props: IndicatorProps) => T["element"];
|
|
88
103
|
}
|
|
89
104
|
|
|
90
|
-
export type { ClipboardApi, ClipboardMachine, ClipboardProps, ClipboardSchema, ClipboardService, CopyStatusDetails, ElementIds, IndicatorProps, IntlTranslations, ValueChangeDetails };
|
|
105
|
+
export type { ClipboardApi, ClipboardMachine, ClipboardProps, ClipboardSchema, ClipboardService, CopyStatusDetails, ElementIds, IndicatorProps, IndicatorState, IntlTranslations, ValueChangeDetails };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ export { anatomy } from './clipboard.anatomy.mjs';
|
|
|
2
2
|
export { connect } from './clipboard.connect.mjs';
|
|
3
3
|
export { machine } from './clipboard.machine.mjs';
|
|
4
4
|
export { contextProps, indicatorProps, props, splitIndicatorProps } from './clipboard.props.mjs';
|
|
5
|
-
export { ClipboardApi as Api, CopyStatusDetails, ElementIds, IndicatorProps, IntlTranslations, ClipboardMachine as Machine, ClipboardProps as Props, ClipboardService as Service, ValueChangeDetails } from './clipboard.types.mjs';
|
|
5
|
+
export { ClipboardApi as Api, CopyStatusDetails, ElementIds, IndicatorProps, IndicatorState, IntlTranslations, ClipboardMachine as Machine, ClipboardProps as Props, ClipboardService as Service, ValueChangeDetails } from './clipboard.types.mjs';
|
|
6
6
|
import '@zag-js/anatomy';
|
|
7
7
|
import '@zag-js/types';
|
|
8
8
|
import '@zag-js/core';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { anatomy } from './clipboard.anatomy.js';
|
|
|
2
2
|
export { connect } from './clipboard.connect.js';
|
|
3
3
|
export { machine } from './clipboard.machine.js';
|
|
4
4
|
export { contextProps, indicatorProps, props, splitIndicatorProps } from './clipboard.props.js';
|
|
5
|
-
export { ClipboardApi as Api, CopyStatusDetails, ElementIds, IndicatorProps, IntlTranslations, ClipboardMachine as Machine, ClipboardProps as Props, ClipboardService as Service, ValueChangeDetails } from './clipboard.types.js';
|
|
5
|
+
export { ClipboardApi as Api, CopyStatusDetails, ElementIds, IndicatorProps, IndicatorState, IntlTranslations, ClipboardMachine as Machine, ClipboardProps as Props, ClipboardService as Service, ValueChangeDetails } from './clipboard.types.js';
|
|
6
6
|
import '@zag-js/anatomy';
|
|
7
7
|
import '@zag-js/types';
|
|
8
8
|
import '@zag-js/core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/clipboard",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.2",
|
|
4
4
|
"description": "Core logic for the clipboard widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"main": "dist/index.js",
|
|
18
|
-
"repository":
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/chakra-ui/zag/tree/main/packages/clipboard"
|
|
21
|
+
},
|
|
19
22
|
"sideEffects": false,
|
|
20
23
|
"files": [
|
|
21
24
|
"dist"
|
|
@@ -27,11 +30,11 @@
|
|
|
27
30
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@zag-js/anatomy": "2.0.0-next.
|
|
31
|
-
"@zag-js/
|
|
32
|
-
"@zag-js/
|
|
33
|
-
"@zag-js/
|
|
34
|
-
"@zag-js/
|
|
33
|
+
"@zag-js/anatomy": "2.0.0-next.2",
|
|
34
|
+
"@zag-js/dom-query": "2.0.0-next.2",
|
|
35
|
+
"@zag-js/utils": "2.0.0-next.2",
|
|
36
|
+
"@zag-js/types": "2.0.0-next.2",
|
|
37
|
+
"@zag-js/core": "2.0.0-next.2"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"clean-package": "2.2.0"
|
|
@@ -64,7 +67,7 @@
|
|
|
64
67
|
},
|
|
65
68
|
"scripts": {
|
|
66
69
|
"build": "tsup",
|
|
67
|
-
"lint": "
|
|
70
|
+
"lint": "oxlint src",
|
|
68
71
|
"typecheck": "tsc --noEmit"
|
|
69
72
|
}
|
|
70
73
|
}
|