@zag-js/pin-input 0.0.0-dev-20220707125149 → 0.0.0-dev-20220709094318
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/index.js +51 -23
- package/dist/index.mjs +52 -24
- package/dist/pin-input.dom.d.ts +10 -2
- package/dist/pin-input.machine.d.ts +1 -1
- package/dist/pin-input.types.d.ts +3 -3
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -43,12 +43,56 @@ __export(src_exports, {
|
|
|
43
43
|
module.exports = __toCommonJS(src_exports);
|
|
44
44
|
|
|
45
45
|
// ../../utilities/dom/dist/index.mjs
|
|
46
|
+
var __defProp2 = Object.defineProperty;
|
|
47
|
+
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
48
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
49
|
+
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
50
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
51
|
+
var __spreadValues2 = (a, b) => {
|
|
52
|
+
for (var prop in b || (b = {}))
|
|
53
|
+
if (__hasOwnProp2.call(b, prop))
|
|
54
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
55
|
+
if (__getOwnPropSymbols2)
|
|
56
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
57
|
+
if (__propIsEnum2.call(b, prop))
|
|
58
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
59
|
+
}
|
|
60
|
+
return a;
|
|
61
|
+
};
|
|
46
62
|
var dataAttr = (guard) => {
|
|
47
63
|
return guard ? "" : void 0;
|
|
48
64
|
};
|
|
49
65
|
var ariaAttr = (guard) => {
|
|
50
66
|
return guard ? "true" : void 0;
|
|
51
67
|
};
|
|
68
|
+
function isDocument(el) {
|
|
69
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
70
|
+
}
|
|
71
|
+
function isWindow(value) {
|
|
72
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
73
|
+
}
|
|
74
|
+
function getDocument(el) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (isWindow(el))
|
|
77
|
+
return el.document;
|
|
78
|
+
if (isDocument(el))
|
|
79
|
+
return el;
|
|
80
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
81
|
+
}
|
|
82
|
+
function withRootHelpers(domUtils) {
|
|
83
|
+
const roots = {
|
|
84
|
+
getRootNode: (ctx) => {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
87
|
+
},
|
|
88
|
+
getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
|
|
89
|
+
getWin: (ctx) => {
|
|
90
|
+
var _a;
|
|
91
|
+
return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return __spreadValues2(__spreadValues2({}, roots), domUtils);
|
|
95
|
+
}
|
|
52
96
|
function getNativeEvent(e) {
|
|
53
97
|
var _a;
|
|
54
98
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
@@ -115,22 +159,14 @@ function invariant(...a) {
|
|
|
115
159
|
}
|
|
116
160
|
|
|
117
161
|
// src/pin-input.dom.ts
|
|
118
|
-
var dom = {
|
|
119
|
-
getDoc: (ctx) => {
|
|
120
|
-
var _a;
|
|
121
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
122
|
-
},
|
|
123
|
-
getRootNode: (ctx) => {
|
|
124
|
-
var _a;
|
|
125
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
126
|
-
},
|
|
162
|
+
var dom = withRootHelpers({
|
|
127
163
|
getRootId: (ctx) => {
|
|
128
164
|
var _a, _b;
|
|
129
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `pin-input:${ctx.
|
|
165
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `pin-input:${ctx.id}`;
|
|
130
166
|
},
|
|
131
167
|
getInputId: (ctx, id) => {
|
|
132
168
|
var _a, _b, _c;
|
|
133
|
-
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) != null ? _c : `pin-input:${ctx.
|
|
169
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) != null ? _c : `pin-input:${ctx.id}:${id}`;
|
|
134
170
|
},
|
|
135
171
|
getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
|
|
136
172
|
getElements: (ctx) => {
|
|
@@ -140,7 +176,7 @@ var dom = {
|
|
|
140
176
|
},
|
|
141
177
|
getFocusedEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
142
178
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0]
|
|
143
|
-
};
|
|
179
|
+
});
|
|
144
180
|
|
|
145
181
|
// src/pin-input.connect.ts
|
|
146
182
|
function connect(state, send, normalize) {
|
|
@@ -249,12 +285,11 @@ function connect(state, send, normalize) {
|
|
|
249
285
|
// src/pin-input.machine.ts
|
|
250
286
|
var import_core = require("@zag-js/core");
|
|
251
287
|
var { and, not } = import_core.guards;
|
|
252
|
-
function machine(ctx
|
|
288
|
+
function machine(ctx) {
|
|
253
289
|
return (0, import_core.createMachine)({
|
|
254
290
|
id: "pin-input",
|
|
255
291
|
initial: "unknown",
|
|
256
292
|
context: __spreadProps(__spreadValues({
|
|
257
|
-
uid: "pin-input",
|
|
258
293
|
value: [],
|
|
259
294
|
focusedIndex: -1,
|
|
260
295
|
placeholder: "\u25CB",
|
|
@@ -301,11 +336,11 @@ function machine(ctx = {}) {
|
|
|
301
336
|
{
|
|
302
337
|
guard: "autoFocus",
|
|
303
338
|
target: "focused",
|
|
304
|
-
actions: ["
|
|
339
|
+
actions: ["setupValue", "setFocusIndexToFirst"]
|
|
305
340
|
},
|
|
306
341
|
{
|
|
307
342
|
target: "idle",
|
|
308
|
-
actions:
|
|
343
|
+
actions: "setupValue"
|
|
309
344
|
}
|
|
310
345
|
]
|
|
311
346
|
}
|
|
@@ -379,13 +414,6 @@ function machine(ctx = {}) {
|
|
|
379
414
|
isDisabled: (ctx2) => !!ctx2.disabled
|
|
380
415
|
},
|
|
381
416
|
actions: {
|
|
382
|
-
setupDocument: (ctx2, evt) => {
|
|
383
|
-
if (evt.doc)
|
|
384
|
-
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
385
|
-
if (evt.root)
|
|
386
|
-
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
387
|
-
ctx2.uid = evt.id;
|
|
388
|
-
},
|
|
389
417
|
setupValue: (ctx2) => {
|
|
390
418
|
nextTick(() => {
|
|
391
419
|
const inputs = dom.getElements(ctx2);
|
package/dist/index.mjs
CHANGED
|
@@ -19,12 +19,56 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
21
|
// ../../utilities/dom/dist/index.mjs
|
|
22
|
+
var __defProp2 = Object.defineProperty;
|
|
23
|
+
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
24
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
25
|
+
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
26
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
27
|
+
var __spreadValues2 = (a, b) => {
|
|
28
|
+
for (var prop in b || (b = {}))
|
|
29
|
+
if (__hasOwnProp2.call(b, prop))
|
|
30
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
31
|
+
if (__getOwnPropSymbols2)
|
|
32
|
+
for (var prop of __getOwnPropSymbols2(b)) {
|
|
33
|
+
if (__propIsEnum2.call(b, prop))
|
|
34
|
+
__defNormalProp2(a, prop, b[prop]);
|
|
35
|
+
}
|
|
36
|
+
return a;
|
|
37
|
+
};
|
|
22
38
|
var dataAttr = (guard) => {
|
|
23
39
|
return guard ? "" : void 0;
|
|
24
40
|
};
|
|
25
41
|
var ariaAttr = (guard) => {
|
|
26
42
|
return guard ? "true" : void 0;
|
|
27
43
|
};
|
|
44
|
+
function isDocument(el) {
|
|
45
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
46
|
+
}
|
|
47
|
+
function isWindow(value) {
|
|
48
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
49
|
+
}
|
|
50
|
+
function getDocument(el) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (isWindow(el))
|
|
53
|
+
return el.document;
|
|
54
|
+
if (isDocument(el))
|
|
55
|
+
return el;
|
|
56
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
57
|
+
}
|
|
58
|
+
function withRootHelpers(domUtils) {
|
|
59
|
+
const roots = {
|
|
60
|
+
getRootNode: (ctx) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
63
|
+
},
|
|
64
|
+
getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
|
|
65
|
+
getWin: (ctx) => {
|
|
66
|
+
var _a;
|
|
67
|
+
return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return __spreadValues2(__spreadValues2({}, roots), domUtils);
|
|
71
|
+
}
|
|
28
72
|
function getNativeEvent(e) {
|
|
29
73
|
var _a;
|
|
30
74
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
@@ -91,22 +135,14 @@ function invariant(...a) {
|
|
|
91
135
|
}
|
|
92
136
|
|
|
93
137
|
// src/pin-input.dom.ts
|
|
94
|
-
var dom = {
|
|
95
|
-
getDoc: (ctx) => {
|
|
96
|
-
var _a;
|
|
97
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
98
|
-
},
|
|
99
|
-
getRootNode: (ctx) => {
|
|
100
|
-
var _a;
|
|
101
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
102
|
-
},
|
|
138
|
+
var dom = withRootHelpers({
|
|
103
139
|
getRootId: (ctx) => {
|
|
104
140
|
var _a, _b;
|
|
105
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `pin-input:${ctx.
|
|
141
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `pin-input:${ctx.id}`;
|
|
106
142
|
},
|
|
107
143
|
getInputId: (ctx, id) => {
|
|
108
144
|
var _a, _b, _c;
|
|
109
|
-
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) != null ? _c : `pin-input:${ctx.
|
|
145
|
+
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) != null ? _c : `pin-input:${ctx.id}:${id}`;
|
|
110
146
|
},
|
|
111
147
|
getRootEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getRootId(ctx)),
|
|
112
148
|
getElements: (ctx) => {
|
|
@@ -116,7 +152,7 @@ var dom = {
|
|
|
116
152
|
},
|
|
117
153
|
getFocusedEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
118
154
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0]
|
|
119
|
-
};
|
|
155
|
+
});
|
|
120
156
|
|
|
121
157
|
// src/pin-input.connect.ts
|
|
122
158
|
function connect(state, send, normalize) {
|
|
@@ -223,14 +259,13 @@ function connect(state, send, normalize) {
|
|
|
223
259
|
}
|
|
224
260
|
|
|
225
261
|
// src/pin-input.machine.ts
|
|
226
|
-
import { createMachine, guards
|
|
262
|
+
import { createMachine, guards } from "@zag-js/core";
|
|
227
263
|
var { and, not } = guards;
|
|
228
|
-
function machine(ctx
|
|
264
|
+
function machine(ctx) {
|
|
229
265
|
return createMachine({
|
|
230
266
|
id: "pin-input",
|
|
231
267
|
initial: "unknown",
|
|
232
268
|
context: __spreadProps(__spreadValues({
|
|
233
|
-
uid: "pin-input",
|
|
234
269
|
value: [],
|
|
235
270
|
focusedIndex: -1,
|
|
236
271
|
placeholder: "\u25CB",
|
|
@@ -277,11 +312,11 @@ function machine(ctx = {}) {
|
|
|
277
312
|
{
|
|
278
313
|
guard: "autoFocus",
|
|
279
314
|
target: "focused",
|
|
280
|
-
actions: ["
|
|
315
|
+
actions: ["setupValue", "setFocusIndexToFirst"]
|
|
281
316
|
},
|
|
282
317
|
{
|
|
283
318
|
target: "idle",
|
|
284
|
-
actions:
|
|
319
|
+
actions: "setupValue"
|
|
285
320
|
}
|
|
286
321
|
]
|
|
287
322
|
}
|
|
@@ -355,13 +390,6 @@ function machine(ctx = {}) {
|
|
|
355
390
|
isDisabled: (ctx2) => !!ctx2.disabled
|
|
356
391
|
},
|
|
357
392
|
actions: {
|
|
358
|
-
setupDocument: (ctx2, evt) => {
|
|
359
|
-
if (evt.doc)
|
|
360
|
-
ctx2.doc = ref(evt.doc);
|
|
361
|
-
if (evt.root)
|
|
362
|
-
ctx2.rootNode = ref(evt.root);
|
|
363
|
-
ctx2.uid = evt.id;
|
|
364
|
-
},
|
|
365
393
|
setupValue: (ctx2) => {
|
|
366
394
|
nextTick(() => {
|
|
367
395
|
const inputs = dom.getElements(ctx2);
|
package/dist/pin-input.dom.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { MachineContext as Ctx } from "./pin-input.types";
|
|
2
2
|
export declare const dom: {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
getRootNode: (ctx: {
|
|
4
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
5
|
+
}) => Document | ShadowRoot;
|
|
6
|
+
getDoc: (ctx: {
|
|
7
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
8
|
+
}) => Document;
|
|
9
|
+
getWin: (ctx: {
|
|
10
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
11
|
+
}) => Window & typeof globalThis;
|
|
12
|
+
} & {
|
|
5
13
|
getRootId: (ctx: Ctx) => string;
|
|
6
14
|
getInputId: (ctx: Ctx, id: string) => string;
|
|
7
15
|
getRootEl: (ctx: Ctx) => HTMLElement;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MachineContext, MachineState, UserDefinedContext } from "./pin-input.types";
|
|
2
|
-
export declare function machine(ctx
|
|
2
|
+
export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StateMachine as S } from "@zag-js/core";
|
|
2
|
-
import type { Context, DirectionProperty } from "@zag-js/types";
|
|
2
|
+
import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
|
|
3
3
|
declare type IntlMessages = {
|
|
4
4
|
inputLabel: (index: number, length: number) => string;
|
|
5
5
|
};
|
|
@@ -7,7 +7,7 @@ declare type ElementIds = Partial<{
|
|
|
7
7
|
root: string;
|
|
8
8
|
input(id: string): string;
|
|
9
9
|
}>;
|
|
10
|
-
declare type PublicContext = DirectionProperty & {
|
|
10
|
+
declare type PublicContext = DirectionProperty & CommonProperties & {
|
|
11
11
|
/**
|
|
12
12
|
* The ids of the elements in the pin input. Useful for composition.
|
|
13
13
|
*/
|
|
@@ -74,7 +74,7 @@ declare type PublicContext = DirectionProperty & {
|
|
|
74
74
|
*/
|
|
75
75
|
messages: IntlMessages;
|
|
76
76
|
};
|
|
77
|
-
export declare type UserDefinedContext =
|
|
77
|
+
export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
78
78
|
declare type ComputedContext = Readonly<{
|
|
79
79
|
/**
|
|
80
80
|
* @computed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/pin-input",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220709094318",
|
|
4
4
|
"description": "Core logic for the pin-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
34
|
-
"@zag-js/types": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.1.7",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220709094318",
|
|
34
|
+
"@zag-js/types": "0.0.0-dev-20220709094318",
|
|
35
35
|
"@zag-js/utils": "0.1.2"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|