@zag-js/pin-input 0.1.7 → 0.1.10
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.d.ts +0 -1
- package/dist/index.js +141 -124
- package/dist/index.mjs +141 -125
- package/dist/pin-input.connect.d.ts +4 -4
- package/dist/pin-input.dom.d.ts +19 -4
- package/dist/pin-input.machine.d.ts +2 -3
- package/dist/pin-input.types.d.ts +12 -4
- package/package.json +6 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -7
- package/dist/index.mjs.map +0 -7
- package/dist/pin-input.connect.d.ts.map +0 -1
- package/dist/pin-input.dom.d.ts.map +0 -1
- package/dist/pin-input.machine.d.ts.map +0 -1
- package/dist/pin-input.types.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -19,37 +19,85 @@ 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
|
};
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function raf2(fn2) {
|
|
31
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
32
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
33
|
-
}
|
|
34
|
-
raf2(() => raf2(fn));
|
|
35
|
-
return function cleanup() {
|
|
36
|
-
set.forEach(function(fn2) {
|
|
37
|
-
fn2();
|
|
38
|
-
});
|
|
39
|
-
};
|
|
44
|
+
function isDocument(el) {
|
|
45
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
40
46
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 getWindow(el) {
|
|
59
|
+
var _a;
|
|
60
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
61
|
+
}
|
|
62
|
+
function defineDomHelpers(helpers) {
|
|
63
|
+
const dom2 = {
|
|
64
|
+
getRootNode: (ctx) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
67
|
+
},
|
|
68
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
69
|
+
getWin: (ctx) => {
|
|
70
|
+
var _a;
|
|
71
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
72
|
+
},
|
|
73
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
74
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
45
75
|
};
|
|
76
|
+
return __spreadValues2(__spreadValues2({}, dom2), helpers);
|
|
46
77
|
}
|
|
47
|
-
var isDom = () => typeof window !== "undefined";
|
|
48
|
-
var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
|
|
49
78
|
function getNativeEvent(e) {
|
|
50
79
|
var _a;
|
|
51
80
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
52
81
|
}
|
|
82
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
83
|
+
function getDescriptor(el, options) {
|
|
84
|
+
var _a;
|
|
85
|
+
const { type, property } = options;
|
|
86
|
+
const proto = getWindow(el)[type].prototype;
|
|
87
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
88
|
+
}
|
|
89
|
+
function dispatchInputValueEvent(el, value) {
|
|
90
|
+
var _a;
|
|
91
|
+
if (!el)
|
|
92
|
+
return;
|
|
93
|
+
const win = getWindow(el);
|
|
94
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
95
|
+
return;
|
|
96
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
97
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
98
|
+
const event = new win.Event("input", { bubbles: true });
|
|
99
|
+
el.dispatchEvent(event);
|
|
100
|
+
}
|
|
53
101
|
var rtlKeyMap = {
|
|
54
102
|
ArrowLeft: "ArrowRight",
|
|
55
103
|
ArrowRight: "ArrowLeft",
|
|
@@ -76,78 +124,30 @@ function getEventKey(event, options = {}) {
|
|
|
76
124
|
}
|
|
77
125
|
return key;
|
|
78
126
|
}
|
|
127
|
+
function raf(fn) {
|
|
128
|
+
const id = globalThis.requestAnimationFrame(fn);
|
|
129
|
+
return function cleanup() {
|
|
130
|
+
globalThis.cancelAnimationFrame(id);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
79
133
|
function queryAll(root, selector) {
|
|
80
134
|
var _a;
|
|
81
135
|
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
82
136
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
|
|
95
|
-
var wrap = (v, idx) => {
|
|
96
|
-
return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
|
|
97
|
-
};
|
|
98
|
-
function findByText(v, text, currentId) {
|
|
99
|
-
const index = currentId ? indexOfId(v, currentId) : -1;
|
|
100
|
-
let items = currentId ? wrap(v, index) : v;
|
|
101
|
-
const isSingleKey = text.length === 1;
|
|
102
|
-
if (isSingleKey) {
|
|
103
|
-
items = items.filter((item) => item.id !== currentId);
|
|
104
|
-
}
|
|
105
|
-
return items.find((item) => match(getValueText(item), text));
|
|
106
|
-
}
|
|
107
|
-
function findByTypeahead(_items, options) {
|
|
108
|
-
const { state: state2, activeId, key, timeout = 350 } = options;
|
|
109
|
-
const search = state2.keysSoFar + key;
|
|
110
|
-
const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
|
|
111
|
-
const query2 = isRepeated ? search[0] : search;
|
|
112
|
-
let items = _items.slice();
|
|
113
|
-
const next = findByText(items, query2, activeId);
|
|
114
|
-
function cleanup() {
|
|
115
|
-
clearTimeout(state2.timer);
|
|
116
|
-
state2.timer = -1;
|
|
117
|
-
}
|
|
118
|
-
function update(value) {
|
|
119
|
-
state2.keysSoFar = value;
|
|
120
|
-
cleanup();
|
|
121
|
-
if (value !== "") {
|
|
122
|
-
state2.timer = +setTimeout(() => {
|
|
123
|
-
update("");
|
|
124
|
-
cleanup();
|
|
125
|
-
}, timeout);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
update(search);
|
|
129
|
-
return next;
|
|
130
|
-
}
|
|
131
|
-
findByTypeahead.defaultOptions = {
|
|
132
|
-
keysSoFar: "",
|
|
133
|
-
timer: -1
|
|
137
|
+
var visuallyHiddenStyle = {
|
|
138
|
+
border: "0",
|
|
139
|
+
clip: "rect(0 0 0 0)",
|
|
140
|
+
height: "1px",
|
|
141
|
+
margin: "-1px",
|
|
142
|
+
overflow: "hidden",
|
|
143
|
+
padding: "0",
|
|
144
|
+
position: "absolute",
|
|
145
|
+
width: "1px",
|
|
146
|
+
whiteSpace: "nowrap",
|
|
147
|
+
wordWrap: "normal"
|
|
134
148
|
};
|
|
135
149
|
|
|
136
|
-
// ../../types/dist/index.mjs
|
|
137
|
-
function createNormalizer(fn) {
|
|
138
|
-
return new Proxy({}, {
|
|
139
|
-
get() {
|
|
140
|
-
return fn;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
var normalizeProp = createNormalizer((v) => v);
|
|
145
|
-
|
|
146
150
|
// ../../utilities/core/dist/index.mjs
|
|
147
|
-
var fromLength = (length) => Array.from(Array(length).keys());
|
|
148
|
-
var isDom2 = () => typeof window !== "undefined";
|
|
149
|
-
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
150
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
151
151
|
function invariant(...a) {
|
|
152
152
|
const m = a.length === 1 ? a[0] : a[1];
|
|
153
153
|
const c = a.length === 2 ? a[0] : true;
|
|
@@ -157,35 +157,32 @@ function invariant(...a) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// src/pin-input.dom.ts
|
|
160
|
-
var dom = {
|
|
161
|
-
getDoc: (ctx) => {
|
|
162
|
-
var _a;
|
|
163
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
164
|
-
},
|
|
165
|
-
getRootNode: (ctx) => {
|
|
166
|
-
var _a;
|
|
167
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
168
|
-
},
|
|
160
|
+
var dom = defineDomHelpers({
|
|
169
161
|
getRootId: (ctx) => {
|
|
170
162
|
var _a, _b;
|
|
171
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `pin-input:${ctx.
|
|
163
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `pin-input:${ctx.id}`;
|
|
172
164
|
},
|
|
173
165
|
getInputId: (ctx, id) => {
|
|
174
166
|
var _a, _b, _c;
|
|
175
|
-
return (_c = (_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) != null ? _c : `pin-input:${ctx.
|
|
167
|
+
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}`;
|
|
176
168
|
},
|
|
177
|
-
|
|
169
|
+
getHiddenInputId: (ctx) => {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.hiddenInput) != null ? _b : `pin-input:${ctx.id}:hidden`;
|
|
172
|
+
},
|
|
173
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
178
174
|
getElements: (ctx) => {
|
|
179
175
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
180
176
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
181
177
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
182
178
|
},
|
|
183
179
|
getFocusedEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
184
|
-
getFirstInputEl: (ctx) => dom.getElements(ctx)[0]
|
|
185
|
-
|
|
180
|
+
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
181
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
182
|
+
});
|
|
186
183
|
|
|
187
184
|
// src/pin-input.connect.ts
|
|
188
|
-
function connect(state, send, normalize
|
|
185
|
+
function connect(state, send, normalize) {
|
|
189
186
|
const isValueComplete = state.context.isValueComplete;
|
|
190
187
|
const isInvalid = state.context.invalid;
|
|
191
188
|
const focusedIndex = state.context.focusedIndex;
|
|
@@ -218,6 +215,16 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
218
215
|
"data-disabled": dataAttr(state.context.disabled),
|
|
219
216
|
"data-complete": dataAttr(isValueComplete)
|
|
220
217
|
}),
|
|
218
|
+
hiddenInputProps: normalize.input({
|
|
219
|
+
"aria-hidden": true,
|
|
220
|
+
type: "text",
|
|
221
|
+
tabIndex: -1,
|
|
222
|
+
id: dom.getHiddenInputId(state.context),
|
|
223
|
+
name: state.context.name,
|
|
224
|
+
style: visuallyHiddenStyle,
|
|
225
|
+
maxLength: state.context.valueLength,
|
|
226
|
+
defaultValue: state.context.valueAsString
|
|
227
|
+
}),
|
|
221
228
|
getInputProps({ index }) {
|
|
222
229
|
const inputType = state.context.type === "numeric" ? "tel" : "text";
|
|
223
230
|
return normalize.input({
|
|
@@ -266,6 +273,9 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
266
273
|
},
|
|
267
274
|
ArrowRight() {
|
|
268
275
|
send("ARROW_RIGHT");
|
|
276
|
+
},
|
|
277
|
+
Enter() {
|
|
278
|
+
send("ENTER");
|
|
269
279
|
}
|
|
270
280
|
};
|
|
271
281
|
const key = getEventKey(event, { dir: state.context.dir });
|
|
@@ -289,14 +299,13 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
289
299
|
}
|
|
290
300
|
|
|
291
301
|
// src/pin-input.machine.ts
|
|
292
|
-
import { createMachine, guards
|
|
302
|
+
import { createMachine, guards } from "@zag-js/core";
|
|
293
303
|
var { and, not } = guards;
|
|
294
|
-
function machine(ctx
|
|
304
|
+
function machine(ctx) {
|
|
295
305
|
return createMachine({
|
|
296
306
|
id: "pin-input",
|
|
297
307
|
initial: "unknown",
|
|
298
308
|
context: __spreadProps(__spreadValues({
|
|
299
|
-
uid: "pin-input",
|
|
300
309
|
value: [],
|
|
301
310
|
focusedIndex: -1,
|
|
302
311
|
placeholder: "\u25CB",
|
|
@@ -316,7 +325,7 @@ function machine(ctx = {}) {
|
|
|
316
325
|
watch: {
|
|
317
326
|
focusedIndex: "focusInput",
|
|
318
327
|
value: "invokeOnChange",
|
|
319
|
-
isValueComplete: ["
|
|
328
|
+
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
320
329
|
},
|
|
321
330
|
on: {
|
|
322
331
|
SET_VALUE: [
|
|
@@ -343,11 +352,11 @@ function machine(ctx = {}) {
|
|
|
343
352
|
{
|
|
344
353
|
guard: "autoFocus",
|
|
345
354
|
target: "focused",
|
|
346
|
-
actions: ["
|
|
355
|
+
actions: ["setupValue", "setFocusIndexToFirst"]
|
|
347
356
|
},
|
|
348
357
|
{
|
|
349
358
|
target: "idle",
|
|
350
|
-
actions:
|
|
359
|
+
actions: "setupValue"
|
|
351
360
|
}
|
|
352
361
|
]
|
|
353
362
|
}
|
|
@@ -399,6 +408,10 @@ function machine(ctx = {}) {
|
|
|
399
408
|
actions: ["setPrevFocusedIndex", "clearFocusedValue"]
|
|
400
409
|
}
|
|
401
410
|
],
|
|
411
|
+
ENTER: {
|
|
412
|
+
guard: "isValueComplete",
|
|
413
|
+
actions: "requestFormSubmit"
|
|
414
|
+
},
|
|
402
415
|
KEY_DOWN: {
|
|
403
416
|
guard: not("isValidValue"),
|
|
404
417
|
actions: ["preventDefault", "invokeOnInvalid"]
|
|
@@ -412,7 +425,12 @@ function machine(ctx = {}) {
|
|
|
412
425
|
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
413
426
|
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
414
427
|
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
415
|
-
isValidValue: (ctx2, evt) =>
|
|
428
|
+
isValidValue: (ctx2, evt) => {
|
|
429
|
+
if (!ctx2.pattern)
|
|
430
|
+
return isValidType(evt.value, ctx2.type);
|
|
431
|
+
const regex = new RegExp(ctx2.pattern, "g");
|
|
432
|
+
return regex.test(evt.value);
|
|
433
|
+
},
|
|
416
434
|
isFinalValue: (ctx2) => {
|
|
417
435
|
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
418
436
|
},
|
|
@@ -421,19 +439,10 @@ function machine(ctx = {}) {
|
|
|
421
439
|
isDisabled: (ctx2) => !!ctx2.disabled
|
|
422
440
|
},
|
|
423
441
|
actions: {
|
|
424
|
-
setupDocument: (ctx2, evt) => {
|
|
425
|
-
if (evt.doc)
|
|
426
|
-
ctx2.doc = ref(evt.doc);
|
|
427
|
-
if (evt.root)
|
|
428
|
-
ctx2.rootNode = ref(evt.root);
|
|
429
|
-
ctx2.uid = evt.id;
|
|
430
|
-
},
|
|
431
442
|
setupValue: (ctx2) => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
ctx2.value = Object.assign(empty, ctx2.value);
|
|
436
|
-
});
|
|
443
|
+
const inputs = dom.getElements(ctx2);
|
|
444
|
+
const empty = Array.from({ length: inputs.length }).map(() => "");
|
|
445
|
+
ctx2.value = Object.assign(empty, ctx2.value);
|
|
437
446
|
},
|
|
438
447
|
focusInput: (ctx2) => {
|
|
439
448
|
raf(() => {
|
|
@@ -443,17 +452,18 @@ function machine(ctx = {}) {
|
|
|
443
452
|
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.focus();
|
|
444
453
|
});
|
|
445
454
|
},
|
|
446
|
-
|
|
455
|
+
invokeOnComplete: (ctx2) => {
|
|
447
456
|
var _a;
|
|
448
|
-
if (ctx2.isValueComplete)
|
|
449
|
-
|
|
450
|
-
}
|
|
457
|
+
if (!ctx2.isValueComplete)
|
|
458
|
+
return;
|
|
459
|
+
(_a = ctx2.onComplete) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
451
460
|
},
|
|
452
461
|
invokeOnChange: (ctx2, evt) => {
|
|
453
462
|
var _a;
|
|
454
|
-
if (evt.type
|
|
455
|
-
|
|
456
|
-
}
|
|
463
|
+
if (evt.type === "SETUP")
|
|
464
|
+
return;
|
|
465
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value) });
|
|
466
|
+
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
457
467
|
},
|
|
458
468
|
invokeOnInvalid: (ctx2, evt) => {
|
|
459
469
|
var _a;
|
|
@@ -510,6 +520,13 @@ function machine(ctx = {}) {
|
|
|
510
520
|
var _a;
|
|
511
521
|
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.blur();
|
|
512
522
|
});
|
|
523
|
+
},
|
|
524
|
+
requestFormSubmit(ctx2) {
|
|
525
|
+
var _a;
|
|
526
|
+
if (!ctx2.name)
|
|
527
|
+
return;
|
|
528
|
+
const input = dom.getHiddenInputEl(ctx2);
|
|
529
|
+
(_a = input == null ? void 0 : input.form) == null ? void 0 : _a.requestSubmit();
|
|
513
530
|
}
|
|
514
531
|
}
|
|
515
532
|
});
|
|
@@ -544,4 +561,3 @@ export {
|
|
|
544
561
|
connect,
|
|
545
562
|
machine
|
|
546
563
|
};
|
|
547
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Send, State } from "./pin-input.types";
|
|
3
|
-
export declare function connect<T extends PropTypes
|
|
1
|
+
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
+
import type { Send, State } from "./pin-input.types";
|
|
3
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
4
|
value: string[];
|
|
5
5
|
valueAsString: string;
|
|
6
6
|
isValueComplete: boolean;
|
|
@@ -9,8 +9,8 @@ export declare function connect<T extends PropTypes = ReactPropTypes>(state: Sta
|
|
|
9
9
|
setValueAtIndex(index: number, value: string): void;
|
|
10
10
|
focus(): void;
|
|
11
11
|
rootProps: T["element"];
|
|
12
|
+
hiddenInputProps: T["input"];
|
|
12
13
|
getInputProps({ index }: {
|
|
13
14
|
index: number;
|
|
14
15
|
}): T["input"];
|
|
15
16
|
};
|
|
16
|
-
//# sourceMappingURL=pin-input.connect.d.ts.map
|
package/dist/pin-input.dom.d.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import { MachineContext as Ctx } from "./pin-input.types";
|
|
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
|
+
getActiveElement: (ctx: {
|
|
13
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
14
|
+
}) => HTMLElement;
|
|
15
|
+
getById: <T_1 = HTMLElement>(ctx: {
|
|
16
|
+
getRootNode?: () => Node | Document | ShadowRoot;
|
|
17
|
+
}, id: string) => T_1;
|
|
18
|
+
} & {
|
|
5
19
|
getRootId: (ctx: Ctx) => string;
|
|
6
20
|
getInputId: (ctx: Ctx, id: string) => string;
|
|
21
|
+
getHiddenInputId: (ctx: Ctx) => string;
|
|
7
22
|
getRootEl: (ctx: Ctx) => HTMLElement;
|
|
8
23
|
getElements: (ctx: Ctx) => HTMLInputElement[];
|
|
9
24
|
getFocusedEl: (ctx: Ctx) => HTMLInputElement;
|
|
10
25
|
getFirstInputEl: (ctx: Ctx) => HTMLInputElement;
|
|
26
|
+
getHiddenInputEl: (ctx: Ctx) => HTMLInputElement;
|
|
11
27
|
};
|
|
12
|
-
//# sourceMappingURL=pin-input.dom.d.ts.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { MachineContext, MachineState, UserDefinedContext } from "./pin-input.types";
|
|
2
|
-
export declare function machine(ctx
|
|
3
|
-
//# sourceMappingURL=pin-input.machine.d.ts.map
|
|
1
|
+
import type { MachineContext, MachineState, UserDefinedContext } from "./pin-input.types";
|
|
2
|
+
export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
|
|
@@ -1,13 +1,22 @@
|
|
|
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
|
};
|
|
6
6
|
declare type ElementIds = Partial<{
|
|
7
7
|
root: string;
|
|
8
|
+
hiddenInput: string;
|
|
8
9
|
input(id: string): string;
|
|
9
10
|
}>;
|
|
10
|
-
declare type PublicContext = DirectionProperty & {
|
|
11
|
+
declare type PublicContext = DirectionProperty & CommonProperties & {
|
|
12
|
+
/**
|
|
13
|
+
* The name of the input element. Useful for form submission.
|
|
14
|
+
*/
|
|
15
|
+
name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The regular expression that the user-entered input value is checked against.
|
|
18
|
+
*/
|
|
19
|
+
pattern?: string;
|
|
11
20
|
/**
|
|
12
21
|
* The ids of the elements in the pin input. Useful for composition.
|
|
13
22
|
*/
|
|
@@ -74,7 +83,7 @@ declare type PublicContext = DirectionProperty & {
|
|
|
74
83
|
*/
|
|
75
84
|
messages: IntlMessages;
|
|
76
85
|
};
|
|
77
|
-
export declare type UserDefinedContext =
|
|
86
|
+
export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
78
87
|
declare type ComputedContext = Readonly<{
|
|
79
88
|
/**
|
|
80
89
|
* @computed
|
|
@@ -111,4 +120,3 @@ export declare type MachineState = {
|
|
|
111
120
|
export declare type State = S.State<MachineContext, MachineState>;
|
|
112
121
|
export declare type Send = S.Send<S.AnyEventObject>;
|
|
113
122
|
export {};
|
|
114
|
-
//# sourceMappingURL=pin-input.types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/pin-input",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Core logic for the pin-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,9 +29,11 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/
|
|
34
|
-
|
|
32
|
+
"@zag-js/core": "0.1.8",
|
|
33
|
+
"@zag-js/types": "0.2.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@zag-js/dom-utils": "0.1.7",
|
|
35
37
|
"@zag-js/utils": "0.1.2"
|
|
36
38
|
},
|
|
37
39
|
"scripts": {
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,YAAY,EAAE,kBAAkB,IAAI,OAAO,EAAE,MAAM,mBAAmB,CAAA"}
|