@zag-js/pin-input 0.2.6 → 0.2.8
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-3SENCEI3.mjs +212 -0
- package/dist/chunk-APRO2TYE.mjs +82 -0
- package/dist/chunk-BJXKBZJG.mjs +9 -0
- package/dist/chunk-CDDLX3AG.mjs +344 -0
- package/dist/chunk-NT4W6JYX.mjs +7 -0
- package/dist/index.d.ts +7 -1002
- package/dist/index.js +54 -56
- 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 +310 -0
- package/dist/pin-input.connect.mjs +9 -0
- package/dist/pin-input.dom.d.ts +34 -0
- package/dist/pin-input.dom.js +103 -0
- package/dist/pin-input.dom.mjs +6 -0
- package/dist/pin-input.machine.d.ts +7 -0
- package/dist/pin-input.machine.js +442 -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) => {
|
|
@@ -64,36 +92,22 @@ function defineDomHelpers(helpers) {
|
|
|
64
92
|
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
65
93
|
},
|
|
66
94
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
67
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
68
|
-
createEmitter: (ctx, target) => {
|
|
69
|
-
const win = dom2.getWin(ctx);
|
|
70
|
-
return function emit(evt, detail, options) {
|
|
71
|
-
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
72
|
-
const eventName = `zag:${evt}`;
|
|
73
|
-
const init = { bubbles, cancelable, composed, detail };
|
|
74
|
-
const event = new win.CustomEvent(eventName, init);
|
|
75
|
-
target.dispatchEvent(event);
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
createListener: (target) => {
|
|
79
|
-
return function listen(evt, handler) {
|
|
80
|
-
const eventName = `zag:${evt}`;
|
|
81
|
-
const listener = (e) => handler(e);
|
|
82
|
-
target.addEventListener(eventName, listener);
|
|
83
|
-
return () => target.removeEventListener(eventName, listener);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
95
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
86
96
|
};
|
|
87
97
|
return {
|
|
88
98
|
...dom2,
|
|
89
99
|
...helpers
|
|
90
100
|
};
|
|
91
101
|
}
|
|
102
|
+
|
|
103
|
+
// ../../utilities/dom/src/event.ts
|
|
92
104
|
function getNativeEvent(e) {
|
|
93
105
|
var _a;
|
|
94
106
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
95
107
|
}
|
|
96
108
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
109
|
+
|
|
110
|
+
// ../../utilities/dom/src/keyboard-event.ts
|
|
97
111
|
var rtlKeyMap = {
|
|
98
112
|
ArrowLeft: "ArrowRight",
|
|
99
113
|
ArrowRight: "ArrowLeft"
|
|
@@ -118,16 +132,22 @@ function getEventKey(event, options = {}) {
|
|
|
118
132
|
}
|
|
119
133
|
return key;
|
|
120
134
|
}
|
|
135
|
+
|
|
136
|
+
// ../../utilities/dom/src/next-tick.ts
|
|
121
137
|
function raf(fn) {
|
|
122
138
|
const id = globalThis.requestAnimationFrame(fn);
|
|
123
139
|
return function cleanup() {
|
|
124
140
|
globalThis.cancelAnimationFrame(id);
|
|
125
141
|
};
|
|
126
142
|
}
|
|
143
|
+
|
|
144
|
+
// ../../utilities/dom/src/nodelist.ts
|
|
127
145
|
function queryAll(root, selector) {
|
|
128
146
|
var _a;
|
|
129
147
|
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
130
148
|
}
|
|
149
|
+
|
|
150
|
+
// ../../utilities/dom/src/visually-hidden.ts
|
|
131
151
|
var visuallyHiddenStyle = {
|
|
132
152
|
border: "0",
|
|
133
153
|
clip: "rect(0 0 0 0)",
|
|
@@ -141,24 +161,6 @@ var visuallyHiddenStyle = {
|
|
|
141
161
|
wordWrap: "normal"
|
|
142
162
|
};
|
|
143
163
|
|
|
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
164
|
// src/pin-input.dom.ts
|
|
163
165
|
var dom = defineDomHelpers({
|
|
164
166
|
getRootId: (ctx) => {
|
|
@@ -333,11 +335,7 @@ function connect(state, send, normalize) {
|
|
|
333
335
|
// src/pin-input.machine.ts
|
|
334
336
|
var import_core = require("@zag-js/core");
|
|
335
337
|
|
|
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
|
-
}
|
|
338
|
+
// ../../utilities/form-utils/src/input-event.ts
|
|
341
339
|
function getDescriptor(el, options) {
|
|
342
340
|
var _a;
|
|
343
341
|
const { type, property = "value" } = options;
|
|
@@ -386,24 +384,24 @@ function machine(userContext) {
|
|
|
386
384
|
},
|
|
387
385
|
watch: {
|
|
388
386
|
focusedIndex: ["focusInput", "setInputSelection"],
|
|
389
|
-
value: ["
|
|
387
|
+
value: ["dispatchInputEvent"],
|
|
390
388
|
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
391
389
|
},
|
|
392
390
|
on: {
|
|
393
391
|
SET_VALUE: [
|
|
394
392
|
{
|
|
395
393
|
guard: "hasIndex",
|
|
396
|
-
actions: "setValueAtIndex"
|
|
394
|
+
actions: ["setValueAtIndex", "invokeOnChange"]
|
|
397
395
|
},
|
|
398
|
-
{ actions: "setValue" }
|
|
396
|
+
{ actions: ["setValue", "invokeOnChange"] }
|
|
399
397
|
],
|
|
400
398
|
CLEAR_VALUE: [
|
|
401
399
|
{
|
|
402
400
|
guard: "isDisabled",
|
|
403
|
-
actions: "clearValue"
|
|
401
|
+
actions: ["clearValue", "invokeOnChange"]
|
|
404
402
|
},
|
|
405
403
|
{
|
|
406
|
-
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
404
|
+
actions: ["clearValue", "invokeOnChange", "setFocusIndexToFirst"]
|
|
407
405
|
}
|
|
408
406
|
]
|
|
409
407
|
},
|
|
@@ -436,19 +434,19 @@ function machine(userContext) {
|
|
|
436
434
|
INPUT: [
|
|
437
435
|
{
|
|
438
436
|
guard: and("isFinalValue", "isValidValue"),
|
|
439
|
-
actions: ["setFocusedValue", "dispatchInputEventIfNeeded"]
|
|
437
|
+
actions: ["setFocusedValue", "invokeOnChange", "dispatchInputEventIfNeeded"]
|
|
440
438
|
},
|
|
441
439
|
{
|
|
442
440
|
guard: "isValidValue",
|
|
443
|
-
actions: ["setFocusedValue", "setNextFocusedIndex", "dispatchInputEventIfNeeded"]
|
|
441
|
+
actions: ["setFocusedValue", "invokeOnChange", "setNextFocusedIndex", "dispatchInputEventIfNeeded"]
|
|
444
442
|
}
|
|
445
443
|
],
|
|
446
444
|
PASTE: [
|
|
447
445
|
{
|
|
448
446
|
guard: "isValidValue",
|
|
449
|
-
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
447
|
+
actions: ["setPastedValue", "invokeOnChange", "setLastValueFocusIndex"]
|
|
450
448
|
},
|
|
451
|
-
{ actions: "resetFocusedValue" }
|
|
449
|
+
{ actions: ["resetFocusedValue", "invokeOnChange"] }
|
|
452
450
|
],
|
|
453
451
|
BLUR: {
|
|
454
452
|
target: "idle",
|
|
@@ -456,7 +454,7 @@ function machine(userContext) {
|
|
|
456
454
|
},
|
|
457
455
|
DELETE: {
|
|
458
456
|
guard: "hasValue",
|
|
459
|
-
actions: "clearFocusedValue"
|
|
457
|
+
actions: ["clearFocusedValue", "invokeOnChange"]
|
|
460
458
|
},
|
|
461
459
|
ARROW_LEFT: {
|
|
462
460
|
actions: "setPrevFocusedIndex"
|
|
@@ -467,10 +465,10 @@ function machine(userContext) {
|
|
|
467
465
|
BACKSPACE: [
|
|
468
466
|
{
|
|
469
467
|
guard: "hasValue",
|
|
470
|
-
actions: "clearFocusedValue"
|
|
468
|
+
actions: ["clearFocusedValue", "invokeOnChange"]
|
|
471
469
|
},
|
|
472
470
|
{
|
|
473
|
-
actions: ["setPrevFocusedIndex", "clearFocusedValue"]
|
|
471
|
+
actions: ["setPrevFocusedIndex", "clearFocusedValue", "invokeOnChange"]
|
|
474
472
|
}
|
|
475
473
|
],
|
|
476
474
|
ENTER: {
|
|
@@ -577,7 +575,7 @@ function machine(userContext) {
|
|
|
577
575
|
setPastedValue(ctx2, evt) {
|
|
578
576
|
raf(() => {
|
|
579
577
|
const startIndex = ctx2.focusedValue ? 1 : 0;
|
|
580
|
-
const value = evt.value.substring(startIndex, ctx2.valueLength);
|
|
578
|
+
const value = evt.value.substring(startIndex, startIndex + ctx2.valueLength);
|
|
581
579
|
assign(ctx2, value);
|
|
582
580
|
});
|
|
583
581
|
},
|