@zag-js/pin-input 0.2.5 → 0.2.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.
- package/dist/chunk-6HKN4SOY.mjs +344 -0
- package/dist/chunk-BJXKBZJG.mjs +9 -0
- package/dist/chunk-NT4W6JYX.mjs +7 -0
- package/dist/chunk-OI3DK2PT.mjs +100 -0
- package/dist/chunk-QX3A66VS.mjs +212 -0
- package/dist/index.d.ts +7 -1002
- package/dist/index.js +52 -36
- package/dist/index.mjs +11 -623
- package/dist/pin-input.anatomy.d.ts +6 -0
- package/dist/pin-input.anatomy.js +34 -0
- package/dist/pin-input.anatomy.mjs +8 -0
- package/dist/pin-input.connect.d.ts +22 -0
- package/dist/pin-input.connect.js +328 -0
- package/dist/pin-input.connect.mjs +9 -0
- package/dist/pin-input.dom.d.ts +38 -0
- package/dist/pin-input.dom.js +121 -0
- package/dist/pin-input.dom.mjs +6 -0
- package/dist/pin-input.machine.d.ts +7 -0
- package/dist/pin-input.machine.js +460 -0
- package/dist/pin-input.machine.mjs +8 -0
- package/dist/pin-input.types.d.ts +133 -0
- package/dist/pin-input.types.js +18 -0
- package/dist/pin-input.types.mjs +0 -0
- package/package.json +22 -12
package/dist/index.js
CHANGED
|
@@ -31,13 +31,37 @@ var import_anatomy = require("@zag-js/anatomy");
|
|
|
31
31
|
var anatomy = (0, import_anatomy.createAnatomy)("pinInput").parts("root", "label", "hiddenInput", "input", "control");
|
|
32
32
|
var parts = anatomy.build();
|
|
33
33
|
|
|
34
|
-
// ../../utilities/dom/
|
|
34
|
+
// ../../utilities/dom/src/attrs.ts
|
|
35
35
|
var dataAttr = (guard) => {
|
|
36
36
|
return guard ? "" : void 0;
|
|
37
37
|
};
|
|
38
38
|
var ariaAttr = (guard) => {
|
|
39
39
|
return guard ? "true" : void 0;
|
|
40
40
|
};
|
|
41
|
+
|
|
42
|
+
// ../../utilities/core/src/guard.ts
|
|
43
|
+
var isArray = (v) => Array.isArray(v);
|
|
44
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
45
|
+
|
|
46
|
+
// ../../utilities/core/src/object.ts
|
|
47
|
+
function compact(obj) {
|
|
48
|
+
if (obj === void 0)
|
|
49
|
+
return obj;
|
|
50
|
+
return Object.fromEntries(
|
|
51
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ../../utilities/core/src/warning.ts
|
|
56
|
+
function invariant(...a) {
|
|
57
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
58
|
+
const c = a.length === 2 ? a[0] : true;
|
|
59
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
60
|
+
throw new Error(m);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ../../utilities/dom/src/query.ts
|
|
41
65
|
function isDocument(el) {
|
|
42
66
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
43
67
|
}
|
|
@@ -52,6 +76,10 @@ function getDocument(el) {
|
|
|
52
76
|
return el;
|
|
53
77
|
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
54
78
|
}
|
|
79
|
+
function getWindow(el) {
|
|
80
|
+
var _a;
|
|
81
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
82
|
+
}
|
|
55
83
|
function defineDomHelpers(helpers) {
|
|
56
84
|
const dom2 = {
|
|
57
85
|
getRootNode: (ctx) => {
|
|
@@ -89,11 +117,15 @@ function defineDomHelpers(helpers) {
|
|
|
89
117
|
...helpers
|
|
90
118
|
};
|
|
91
119
|
}
|
|
120
|
+
|
|
121
|
+
// ../../utilities/dom/src/event.ts
|
|
92
122
|
function getNativeEvent(e) {
|
|
93
123
|
var _a;
|
|
94
124
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
95
125
|
}
|
|
96
126
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
127
|
+
|
|
128
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
97
129
|
var rtlKeyMap = {
|
|
98
130
|
ArrowLeft: "ArrowRight",
|
|
99
131
|
ArrowRight: "ArrowLeft"
|
|
@@ -118,16 +150,22 @@ function getEventKey(event, options = {}) {
|
|
|
118
150
|
}
|
|
119
151
|
return key;
|
|
120
152
|
}
|
|
153
|
+
|
|
154
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
121
155
|
function raf(fn) {
|
|
122
156
|
const id = globalThis.requestAnimationFrame(fn);
|
|
123
157
|
return function cleanup() {
|
|
124
158
|
globalThis.cancelAnimationFrame(id);
|
|
125
159
|
};
|
|
126
160
|
}
|
|
161
|
+
|
|
162
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
127
163
|
function queryAll(root, selector) {
|
|
128
164
|
var _a;
|
|
129
165
|
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
130
166
|
}
|
|
167
|
+
|
|
168
|
+
// ../../utilities/dom/src/visually-hidden.ts
|
|
131
169
|
var visuallyHiddenStyle = {
|
|
132
170
|
border: "0",
|
|
133
171
|
clip: "rect(0 0 0 0)",
|
|
@@ -141,24 +179,6 @@ var visuallyHiddenStyle = {
|
|
|
141
179
|
wordWrap: "normal"
|
|
142
180
|
};
|
|
143
181
|
|
|
144
|
-
// ../../utilities/core/dist/index.mjs
|
|
145
|
-
var isArray = (v) => Array.isArray(v);
|
|
146
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
147
|
-
function compact(obj) {
|
|
148
|
-
if (obj === void 0)
|
|
149
|
-
return obj;
|
|
150
|
-
return Object.fromEntries(
|
|
151
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
function invariant(...a) {
|
|
155
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
156
|
-
const c = a.length === 2 ? a[0] : true;
|
|
157
|
-
if (c && process.env.NODE_ENV !== "production") {
|
|
158
|
-
throw new Error(m);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
182
|
// src/pin-input.dom.ts
|
|
163
183
|
var dom = defineDomHelpers({
|
|
164
184
|
getRootId: (ctx) => {
|
|
@@ -333,11 +353,7 @@ function connect(state, send, normalize) {
|
|
|
333
353
|
// src/pin-input.machine.ts
|
|
334
354
|
var import_core = require("@zag-js/core");
|
|
335
355
|
|
|
336
|
-
// ../../utilities/form-utils/
|
|
337
|
-
function getWindow(el) {
|
|
338
|
-
var _a;
|
|
339
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
340
|
-
}
|
|
356
|
+
// ../../utilities/form-utils/src/input-event.ts
|
|
341
357
|
function getDescriptor(el, options) {
|
|
342
358
|
var _a;
|
|
343
359
|
const { type, property = "value" } = options;
|
|
@@ -386,24 +402,24 @@ function machine(userContext) {
|
|
|
386
402
|
},
|
|
387
403
|
watch: {
|
|
388
404
|
focusedIndex: ["focusInput", "setInputSelection"],
|
|
389
|
-
value: ["
|
|
405
|
+
value: ["dispatchInputEvent"],
|
|
390
406
|
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
391
407
|
},
|
|
392
408
|
on: {
|
|
393
409
|
SET_VALUE: [
|
|
394
410
|
{
|
|
395
411
|
guard: "hasIndex",
|
|
396
|
-
actions: "setValueAtIndex"
|
|
412
|
+
actions: ["setValueAtIndex", "invokeOnChange"]
|
|
397
413
|
},
|
|
398
|
-
{ actions: "setValue" }
|
|
414
|
+
{ actions: ["setValue", "invokeOnChange"] }
|
|
399
415
|
],
|
|
400
416
|
CLEAR_VALUE: [
|
|
401
417
|
{
|
|
402
418
|
guard: "isDisabled",
|
|
403
|
-
actions: "clearValue"
|
|
419
|
+
actions: ["clearValue", "invokeOnChange"]
|
|
404
420
|
},
|
|
405
421
|
{
|
|
406
|
-
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
422
|
+
actions: ["clearValue", "invokeOnChange", "setFocusIndexToFirst"]
|
|
407
423
|
}
|
|
408
424
|
]
|
|
409
425
|
},
|
|
@@ -436,19 +452,19 @@ function machine(userContext) {
|
|
|
436
452
|
INPUT: [
|
|
437
453
|
{
|
|
438
454
|
guard: and("isFinalValue", "isValidValue"),
|
|
439
|
-
actions: ["setFocusedValue", "dispatchInputEventIfNeeded"]
|
|
455
|
+
actions: ["setFocusedValue", "invokeOnChange", "dispatchInputEventIfNeeded"]
|
|
440
456
|
},
|
|
441
457
|
{
|
|
442
458
|
guard: "isValidValue",
|
|
443
|
-
actions: ["setFocusedValue", "setNextFocusedIndex", "dispatchInputEventIfNeeded"]
|
|
459
|
+
actions: ["setFocusedValue", "invokeOnChange", "setNextFocusedIndex", "dispatchInputEventIfNeeded"]
|
|
444
460
|
}
|
|
445
461
|
],
|
|
446
462
|
PASTE: [
|
|
447
463
|
{
|
|
448
464
|
guard: "isValidValue",
|
|
449
|
-
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
465
|
+
actions: ["setPastedValue", "invokeOnChange", "setLastValueFocusIndex"]
|
|
450
466
|
},
|
|
451
|
-
{ actions: "resetFocusedValue" }
|
|
467
|
+
{ actions: ["resetFocusedValue", "invokeOnChange"] }
|
|
452
468
|
],
|
|
453
469
|
BLUR: {
|
|
454
470
|
target: "idle",
|
|
@@ -456,7 +472,7 @@ function machine(userContext) {
|
|
|
456
472
|
},
|
|
457
473
|
DELETE: {
|
|
458
474
|
guard: "hasValue",
|
|
459
|
-
actions: "clearFocusedValue"
|
|
475
|
+
actions: ["clearFocusedValue", "invokeOnChange"]
|
|
460
476
|
},
|
|
461
477
|
ARROW_LEFT: {
|
|
462
478
|
actions: "setPrevFocusedIndex"
|
|
@@ -467,10 +483,10 @@ function machine(userContext) {
|
|
|
467
483
|
BACKSPACE: [
|
|
468
484
|
{
|
|
469
485
|
guard: "hasValue",
|
|
470
|
-
actions: "clearFocusedValue"
|
|
486
|
+
actions: ["clearFocusedValue", "invokeOnChange"]
|
|
471
487
|
},
|
|
472
488
|
{
|
|
473
|
-
actions: ["setPrevFocusedIndex", "clearFocusedValue"]
|
|
489
|
+
actions: ["setPrevFocusedIndex", "clearFocusedValue", "invokeOnChange"]
|
|
474
490
|
}
|
|
475
491
|
],
|
|
476
492
|
ENTER: {
|