@zag-js/pin-input 0.1.10 → 0.1.13
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/LICENSE +21 -0
- package/dist/index.d.ts +136 -3
- package/dist/index.js +260 -286
- package/dist/index.mjs +255 -289
- package/package.json +13 -11
- package/dist/pin-input.connect.d.ts +0 -16
- package/dist/pin-input.dom.d.ts +0 -27
- package/dist/pin-input.machine.d.ts +0 -2
- package/dist/pin-input.types.d.ts +0 -122
package/dist/index.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
6
|
var __export = (target, all) => {
|
|
24
7
|
for (var name in all)
|
|
25
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,22 +26,6 @@ __export(src_exports, {
|
|
|
43
26
|
module.exports = __toCommonJS(src_exports);
|
|
44
27
|
|
|
45
28
|
// ../../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
|
-
};
|
|
62
29
|
var dataAttr = (guard) => {
|
|
63
30
|
return guard ? "" : void 0;
|
|
64
31
|
};
|
|
@@ -72,56 +39,32 @@ function isWindow(value) {
|
|
|
72
39
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
73
40
|
}
|
|
74
41
|
function getDocument(el) {
|
|
75
|
-
var _a;
|
|
76
42
|
if (isWindow(el))
|
|
77
43
|
return el.document;
|
|
78
44
|
if (isDocument(el))
|
|
79
45
|
return el;
|
|
80
|
-
return (
|
|
81
|
-
}
|
|
82
|
-
function getWindow(el) {
|
|
83
|
-
var _a;
|
|
84
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
46
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
85
47
|
}
|
|
86
48
|
function defineDomHelpers(helpers) {
|
|
87
49
|
const dom2 = {
|
|
88
50
|
getRootNode: (ctx) => {
|
|
89
|
-
var _a, _b;
|
|
90
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
91
|
-
},
|
|
92
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
93
|
-
getWin: (ctx) => {
|
|
94
51
|
var _a;
|
|
95
|
-
return (_a =
|
|
52
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
96
53
|
},
|
|
54
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
55
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
97
56
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
98
57
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
99
58
|
};
|
|
100
|
-
return
|
|
59
|
+
return {
|
|
60
|
+
...dom2,
|
|
61
|
+
...helpers
|
|
62
|
+
};
|
|
101
63
|
}
|
|
102
64
|
function getNativeEvent(e) {
|
|
103
|
-
|
|
104
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
65
|
+
return e.nativeEvent ?? e;
|
|
105
66
|
}
|
|
106
67
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
107
|
-
function getDescriptor(el, options) {
|
|
108
|
-
var _a;
|
|
109
|
-
const { type, property } = options;
|
|
110
|
-
const proto = getWindow(el)[type].prototype;
|
|
111
|
-
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
112
|
-
}
|
|
113
|
-
function dispatchInputValueEvent(el, value) {
|
|
114
|
-
var _a;
|
|
115
|
-
if (!el)
|
|
116
|
-
return;
|
|
117
|
-
const win = getWindow(el);
|
|
118
|
-
if (!(el instanceof win.HTMLInputElement))
|
|
119
|
-
return;
|
|
120
|
-
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
121
|
-
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
122
|
-
const event = new win.Event("input", { bubbles: true });
|
|
123
|
-
el.dispatchEvent(event);
|
|
124
|
-
}
|
|
125
68
|
var rtlKeyMap = {
|
|
126
69
|
ArrowLeft: "ArrowRight",
|
|
127
70
|
ArrowRight: "ArrowLeft",
|
|
@@ -138,10 +81,9 @@ var sameKeyMap = {
|
|
|
138
81
|
Right: "ArrowRight"
|
|
139
82
|
};
|
|
140
83
|
function getEventKey(event, options = {}) {
|
|
141
|
-
var _a;
|
|
142
84
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
143
85
|
let { key } = event;
|
|
144
|
-
key =
|
|
86
|
+
key = sameKeyMap[key] ?? key;
|
|
145
87
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
146
88
|
if (isRtl && key in rtlKeyMap) {
|
|
147
89
|
key = rtlKeyMap[key];
|
|
@@ -155,8 +97,7 @@ function raf(fn) {
|
|
|
155
97
|
};
|
|
156
98
|
}
|
|
157
99
|
function queryAll(root, selector) {
|
|
158
|
-
|
|
159
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
100
|
+
return Array.from((root == null ? void 0 : root.querySelectorAll(selector)) ?? []);
|
|
160
101
|
}
|
|
161
102
|
var visuallyHiddenStyle = {
|
|
162
103
|
border: "0",
|
|
@@ -175,7 +116,7 @@ var visuallyHiddenStyle = {
|
|
|
175
116
|
function invariant(...a) {
|
|
176
117
|
const m = a.length === 1 ? a[0] : a[1];
|
|
177
118
|
const c = a.length === 2 ? a[0] : true;
|
|
178
|
-
if (c &&
|
|
119
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
179
120
|
throw new Error(m);
|
|
180
121
|
}
|
|
181
122
|
}
|
|
@@ -183,16 +124,16 @@ function invariant(...a) {
|
|
|
183
124
|
// src/pin-input.dom.ts
|
|
184
125
|
var dom = defineDomHelpers({
|
|
185
126
|
getRootId: (ctx) => {
|
|
186
|
-
var _a
|
|
187
|
-
return (
|
|
127
|
+
var _a;
|
|
128
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `pin-input:${ctx.id}`;
|
|
188
129
|
},
|
|
189
130
|
getInputId: (ctx, id) => {
|
|
190
|
-
var _a, _b
|
|
191
|
-
return (
|
|
131
|
+
var _a, _b;
|
|
132
|
+
return ((_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) ?? `pin-input:${ctx.id}:${id}`;
|
|
192
133
|
},
|
|
193
134
|
getHiddenInputId: (ctx) => {
|
|
194
|
-
var _a
|
|
195
|
-
return (
|
|
135
|
+
var _a;
|
|
136
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.hiddenInput) ?? `pin-input:${ctx.id}:hidden`;
|
|
196
137
|
},
|
|
197
138
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
198
139
|
getElements: (ctx) => {
|
|
@@ -324,236 +265,264 @@ function connect(state, send, normalize) {
|
|
|
324
265
|
|
|
325
266
|
// src/pin-input.machine.ts
|
|
326
267
|
var import_core = require("@zag-js/core");
|
|
268
|
+
|
|
269
|
+
// ../../utilities/form-utils/dist/index.mjs
|
|
270
|
+
function getWindow(el) {
|
|
271
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
272
|
+
}
|
|
273
|
+
function getDescriptor(el, options) {
|
|
274
|
+
const { type, property } = options;
|
|
275
|
+
const proto = getWindow(el)[type].prototype;
|
|
276
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
277
|
+
}
|
|
278
|
+
function dispatchInputValueEvent(el, value) {
|
|
279
|
+
var _a;
|
|
280
|
+
if (!el)
|
|
281
|
+
return;
|
|
282
|
+
const win = getWindow(el);
|
|
283
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
284
|
+
return;
|
|
285
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
286
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
287
|
+
const event = new win.Event("input", { bubbles: true });
|
|
288
|
+
el.dispatchEvent(event);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/pin-input.machine.ts
|
|
327
292
|
var { and, not } = import_core.guards;
|
|
328
293
|
function machine(ctx) {
|
|
329
|
-
return (0, import_core.createMachine)(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
computed: {
|
|
344
|
-
valueLength: (ctx2) => ctx2.value.length,
|
|
345
|
-
filledValueLength: (ctx2) => ctx2.value.filter((v) => (v == null ? void 0 : v.trim()) !== "").length,
|
|
346
|
-
isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
|
|
347
|
-
valueAsString: (ctx2) => ctx2.value.join("")
|
|
348
|
-
},
|
|
349
|
-
watch: {
|
|
350
|
-
focusedIndex: "focusInput",
|
|
351
|
-
value: "invokeOnChange",
|
|
352
|
-
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
353
|
-
},
|
|
354
|
-
on: {
|
|
355
|
-
SET_VALUE: [
|
|
356
|
-
{
|
|
357
|
-
guard: "hasIndex",
|
|
358
|
-
actions: "setValueAtIndex"
|
|
359
|
-
},
|
|
360
|
-
{ actions: "setValue" }
|
|
361
|
-
],
|
|
362
|
-
CLEAR_VALUE: [
|
|
363
|
-
{
|
|
364
|
-
guard: "isDisabled",
|
|
365
|
-
actions: "clearValue"
|
|
366
|
-
},
|
|
367
|
-
{
|
|
368
|
-
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
369
|
-
}
|
|
370
|
-
]
|
|
371
|
-
},
|
|
372
|
-
states: {
|
|
373
|
-
unknown: {
|
|
374
|
-
on: {
|
|
375
|
-
SETUP: [
|
|
376
|
-
{
|
|
377
|
-
guard: "autoFocus",
|
|
378
|
-
target: "focused",
|
|
379
|
-
actions: ["setupValue", "setFocusIndexToFirst"]
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
target: "idle",
|
|
383
|
-
actions: "setupValue"
|
|
384
|
-
}
|
|
385
|
-
]
|
|
294
|
+
return (0, import_core.createMachine)(
|
|
295
|
+
{
|
|
296
|
+
id: "pin-input",
|
|
297
|
+
initial: "unknown",
|
|
298
|
+
context: {
|
|
299
|
+
value: [],
|
|
300
|
+
focusedIndex: -1,
|
|
301
|
+
placeholder: "\u25CB",
|
|
302
|
+
otp: false,
|
|
303
|
+
type: "numeric",
|
|
304
|
+
...ctx,
|
|
305
|
+
messages: {
|
|
306
|
+
inputLabel: (index, length) => `pin code ${index + 1} of ${length}`,
|
|
307
|
+
...ctx.messages
|
|
386
308
|
}
|
|
387
309
|
},
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
}
|
|
310
|
+
computed: {
|
|
311
|
+
valueLength: (ctx2) => ctx2.value.length,
|
|
312
|
+
filledValueLength: (ctx2) => ctx2.value.filter((v) => (v == null ? void 0 : v.trim()) !== "").length,
|
|
313
|
+
isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
|
|
314
|
+
valueAsString: (ctx2) => ctx2.value.join("")
|
|
395
315
|
},
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
],
|
|
408
|
-
PASTE: {
|
|
409
|
-
guard: "isValidValue",
|
|
410
|
-
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
411
|
-
},
|
|
412
|
-
BLUR: {
|
|
413
|
-
target: "idle",
|
|
414
|
-
actions: "clearFocusedIndex"
|
|
415
|
-
},
|
|
416
|
-
DELETE: {
|
|
417
|
-
guard: "hasValue",
|
|
418
|
-
actions: "clearFocusedValue"
|
|
419
|
-
},
|
|
420
|
-
ARROW_LEFT: {
|
|
421
|
-
actions: "setPrevFocusedIndex"
|
|
316
|
+
watch: {
|
|
317
|
+
focusedIndex: "focusInput",
|
|
318
|
+
value: "invokeOnChange",
|
|
319
|
+
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
320
|
+
},
|
|
321
|
+
on: {
|
|
322
|
+
SET_VALUE: [
|
|
323
|
+
{
|
|
324
|
+
guard: "hasIndex",
|
|
325
|
+
actions: "setValueAtIndex"
|
|
422
326
|
},
|
|
423
|
-
|
|
424
|
-
|
|
327
|
+
{ actions: "setValue" }
|
|
328
|
+
],
|
|
329
|
+
CLEAR_VALUE: [
|
|
330
|
+
{
|
|
331
|
+
guard: "isDisabled",
|
|
332
|
+
actions: "clearValue"
|
|
425
333
|
},
|
|
426
|
-
|
|
427
|
-
|
|
334
|
+
{
|
|
335
|
+
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
},
|
|
339
|
+
states: {
|
|
340
|
+
unknown: {
|
|
341
|
+
on: {
|
|
342
|
+
SETUP: [
|
|
343
|
+
{
|
|
344
|
+
guard: "autoFocus",
|
|
345
|
+
target: "focused",
|
|
346
|
+
actions: ["setupValue", "setFocusIndexToFirst"]
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
target: "idle",
|
|
350
|
+
actions: "setupValue"
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
idle: {
|
|
356
|
+
on: {
|
|
357
|
+
FOCUS: {
|
|
358
|
+
target: "focused",
|
|
359
|
+
actions: "setFocusedIndex"
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
focused: {
|
|
364
|
+
on: {
|
|
365
|
+
INPUT: [
|
|
366
|
+
{
|
|
367
|
+
guard: and("isFinalValue", "isValidValue"),
|
|
368
|
+
actions: "setFocusedValue"
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
guard: "isValidValue",
|
|
372
|
+
actions: ["setFocusedValue", "setNextFocusedIndex"]
|
|
373
|
+
}
|
|
374
|
+
],
|
|
375
|
+
PASTE: {
|
|
376
|
+
guard: "isValidValue",
|
|
377
|
+
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
378
|
+
},
|
|
379
|
+
BLUR: {
|
|
380
|
+
target: "idle",
|
|
381
|
+
actions: "clearFocusedIndex"
|
|
382
|
+
},
|
|
383
|
+
DELETE: {
|
|
428
384
|
guard: "hasValue",
|
|
429
385
|
actions: "clearFocusedValue"
|
|
430
386
|
},
|
|
431
|
-
{
|
|
432
|
-
actions:
|
|
387
|
+
ARROW_LEFT: {
|
|
388
|
+
actions: "setPrevFocusedIndex"
|
|
389
|
+
},
|
|
390
|
+
ARROW_RIGHT: {
|
|
391
|
+
actions: "setNextFocusedIndex"
|
|
392
|
+
},
|
|
393
|
+
BACKSPACE: [
|
|
394
|
+
{
|
|
395
|
+
guard: "hasValue",
|
|
396
|
+
actions: "clearFocusedValue"
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
actions: ["setPrevFocusedIndex", "clearFocusedValue"]
|
|
400
|
+
}
|
|
401
|
+
],
|
|
402
|
+
ENTER: {
|
|
403
|
+
guard: "isValueComplete",
|
|
404
|
+
actions: "requestFormSubmit"
|
|
405
|
+
},
|
|
406
|
+
KEY_DOWN: {
|
|
407
|
+
guard: not("isValidValue"),
|
|
408
|
+
actions: ["preventDefault", "invokeOnInvalid"]
|
|
433
409
|
}
|
|
434
|
-
],
|
|
435
|
-
ENTER: {
|
|
436
|
-
guard: "isValueComplete",
|
|
437
|
-
actions: "requestFormSubmit"
|
|
438
|
-
},
|
|
439
|
-
KEY_DOWN: {
|
|
440
|
-
guard: not("isValidValue"),
|
|
441
|
-
actions: ["preventDefault", "invokeOnInvalid"]
|
|
442
410
|
}
|
|
443
411
|
}
|
|
444
412
|
}
|
|
445
|
-
}
|
|
446
|
-
}, {
|
|
447
|
-
guards: {
|
|
448
|
-
autoFocus: (ctx2) => !!ctx2.autoFocus,
|
|
449
|
-
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
450
|
-
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
451
|
-
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
452
|
-
isValidValue: (ctx2, evt) => {
|
|
453
|
-
if (!ctx2.pattern)
|
|
454
|
-
return isValidType(evt.value, ctx2.type);
|
|
455
|
-
const regex = new RegExp(ctx2.pattern, "g");
|
|
456
|
-
return regex.test(evt.value);
|
|
457
|
-
},
|
|
458
|
-
isFinalValue: (ctx2) => {
|
|
459
|
-
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
460
|
-
},
|
|
461
|
-
isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
|
|
462
|
-
hasIndex: (_ctx, evt) => evt.index !== void 0,
|
|
463
|
-
isDisabled: (ctx2) => !!ctx2.disabled
|
|
464
413
|
},
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
ctx2.value
|
|
414
|
+
{
|
|
415
|
+
guards: {
|
|
416
|
+
autoFocus: (ctx2) => !!ctx2.autoFocus,
|
|
417
|
+
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
418
|
+
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
419
|
+
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
420
|
+
isValidValue: (ctx2, evt) => {
|
|
421
|
+
if (!ctx2.pattern)
|
|
422
|
+
return isValidType(evt.value, ctx2.type);
|
|
423
|
+
const regex = new RegExp(ctx2.pattern, "g");
|
|
424
|
+
return regex.test(evt.value);
|
|
425
|
+
},
|
|
426
|
+
isFinalValue: (ctx2) => {
|
|
427
|
+
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
428
|
+
},
|
|
429
|
+
isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
|
|
430
|
+
hasIndex: (_ctx, evt) => evt.index !== void 0,
|
|
431
|
+
isDisabled: (ctx2) => !!ctx2.disabled
|
|
470
432
|
},
|
|
471
|
-
|
|
472
|
-
|
|
433
|
+
actions: {
|
|
434
|
+
setupValue: (ctx2) => {
|
|
435
|
+
const inputs = dom.getElements(ctx2);
|
|
436
|
+
const empty = Array.from({ length: inputs.length }).map(() => "");
|
|
437
|
+
ctx2.value = Object.assign(empty, ctx2.value);
|
|
438
|
+
},
|
|
439
|
+
focusInput: (ctx2) => {
|
|
440
|
+
raf(() => {
|
|
441
|
+
var _a;
|
|
442
|
+
if (ctx2.focusedIndex === -1)
|
|
443
|
+
return;
|
|
444
|
+
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.focus();
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
invokeOnComplete: (ctx2) => {
|
|
473
448
|
var _a;
|
|
474
|
-
if (ctx2.
|
|
449
|
+
if (!ctx2.isValueComplete)
|
|
475
450
|
return;
|
|
476
|
-
(_a =
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
invokeOnComplete: (ctx2) => {
|
|
480
|
-
var _a;
|
|
481
|
-
if (!ctx2.isValueComplete)
|
|
482
|
-
return;
|
|
483
|
-
(_a = ctx2.onComplete) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
484
|
-
},
|
|
485
|
-
invokeOnChange: (ctx2, evt) => {
|
|
486
|
-
var _a;
|
|
487
|
-
if (evt.type === "SETUP")
|
|
488
|
-
return;
|
|
489
|
-
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value) });
|
|
490
|
-
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
491
|
-
},
|
|
492
|
-
invokeOnInvalid: (ctx2, evt) => {
|
|
493
|
-
var _a;
|
|
494
|
-
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, { value: evt.value, index: ctx2.focusedIndex });
|
|
495
|
-
},
|
|
496
|
-
clearFocusedIndex: (ctx2) => {
|
|
497
|
-
ctx2.focusedIndex = -1;
|
|
498
|
-
},
|
|
499
|
-
setValue: (ctx2, evt) => {
|
|
500
|
-
assign(ctx2, evt.value);
|
|
501
|
-
},
|
|
502
|
-
setFocusedIndex: (ctx2, evt) => {
|
|
503
|
-
ctx2.focusedIndex = evt.index;
|
|
504
|
-
},
|
|
505
|
-
setFocusedValue: (ctx2, evt) => {
|
|
506
|
-
ctx2.value[ctx2.focusedIndex] = lastChar(evt.value);
|
|
507
|
-
},
|
|
508
|
-
setPastedValue(ctx2, evt) {
|
|
509
|
-
raf(() => {
|
|
510
|
-
const value = evt.value.substring(0, ctx2.valueLength);
|
|
511
|
-
assign(ctx2, value.split("").filter(Boolean));
|
|
512
|
-
});
|
|
513
|
-
},
|
|
514
|
-
setValueAtIndex: (ctx2, evt) => {
|
|
515
|
-
ctx2.value[evt.index] = lastChar(evt.value);
|
|
516
|
-
},
|
|
517
|
-
clearValue: (ctx2) => {
|
|
518
|
-
assign(ctx2, "");
|
|
519
|
-
},
|
|
520
|
-
clearFocusedValue: (ctx2) => {
|
|
521
|
-
ctx2.value[ctx2.focusedIndex] = "";
|
|
522
|
-
},
|
|
523
|
-
setFocusIndexToFirst: (ctx2) => {
|
|
524
|
-
ctx2.focusedIndex = 0;
|
|
525
|
-
},
|
|
526
|
-
setNextFocusedIndex: (ctx2) => {
|
|
527
|
-
ctx2.focusedIndex = Math.min(ctx2.focusedIndex + 1, ctx2.valueLength - 1);
|
|
528
|
-
},
|
|
529
|
-
setPrevFocusedIndex: (ctx2) => {
|
|
530
|
-
ctx2.focusedIndex = Math.max(ctx2.focusedIndex - 1, 0);
|
|
531
|
-
},
|
|
532
|
-
setLastValueFocusIndex: (ctx2) => {
|
|
533
|
-
raf(() => {
|
|
534
|
-
ctx2.focusedIndex = Math.min(ctx2.filledValueLength, ctx2.valueLength - 1);
|
|
535
|
-
});
|
|
536
|
-
},
|
|
537
|
-
preventDefault(_, evt) {
|
|
538
|
-
evt.preventDefault();
|
|
539
|
-
},
|
|
540
|
-
blurFocusedInputIfNeeded(ctx2) {
|
|
541
|
-
if (!ctx2.blurOnComplete)
|
|
542
|
-
return;
|
|
543
|
-
raf(() => {
|
|
451
|
+
(_a = ctx2.onComplete) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
452
|
+
},
|
|
453
|
+
invokeOnChange: (ctx2, evt) => {
|
|
544
454
|
var _a;
|
|
545
|
-
(
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
455
|
+
if (evt.type === "SETUP")
|
|
456
|
+
return;
|
|
457
|
+
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value) });
|
|
458
|
+
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
459
|
+
},
|
|
460
|
+
invokeOnInvalid: (ctx2, evt) => {
|
|
461
|
+
var _a;
|
|
462
|
+
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, { value: evt.value, index: ctx2.focusedIndex });
|
|
463
|
+
},
|
|
464
|
+
clearFocusedIndex: (ctx2) => {
|
|
465
|
+
ctx2.focusedIndex = -1;
|
|
466
|
+
},
|
|
467
|
+
setValue: (ctx2, evt) => {
|
|
468
|
+
assign(ctx2, evt.value);
|
|
469
|
+
},
|
|
470
|
+
setFocusedIndex: (ctx2, evt) => {
|
|
471
|
+
ctx2.focusedIndex = evt.index;
|
|
472
|
+
},
|
|
473
|
+
setFocusedValue: (ctx2, evt) => {
|
|
474
|
+
ctx2.value[ctx2.focusedIndex] = lastChar(evt.value);
|
|
475
|
+
},
|
|
476
|
+
setPastedValue(ctx2, evt) {
|
|
477
|
+
raf(() => {
|
|
478
|
+
const value = evt.value.substring(0, ctx2.valueLength);
|
|
479
|
+
assign(ctx2, value.split("").filter(Boolean));
|
|
480
|
+
});
|
|
481
|
+
},
|
|
482
|
+
setValueAtIndex: (ctx2, evt) => {
|
|
483
|
+
ctx2.value[evt.index] = lastChar(evt.value);
|
|
484
|
+
},
|
|
485
|
+
clearValue: (ctx2) => {
|
|
486
|
+
assign(ctx2, "");
|
|
487
|
+
},
|
|
488
|
+
clearFocusedValue: (ctx2) => {
|
|
489
|
+
ctx2.value[ctx2.focusedIndex] = "";
|
|
490
|
+
},
|
|
491
|
+
setFocusIndexToFirst: (ctx2) => {
|
|
492
|
+
ctx2.focusedIndex = 0;
|
|
493
|
+
},
|
|
494
|
+
setNextFocusedIndex: (ctx2) => {
|
|
495
|
+
ctx2.focusedIndex = Math.min(ctx2.focusedIndex + 1, ctx2.valueLength - 1);
|
|
496
|
+
},
|
|
497
|
+
setPrevFocusedIndex: (ctx2) => {
|
|
498
|
+
ctx2.focusedIndex = Math.max(ctx2.focusedIndex - 1, 0);
|
|
499
|
+
},
|
|
500
|
+
setLastValueFocusIndex: (ctx2) => {
|
|
501
|
+
raf(() => {
|
|
502
|
+
ctx2.focusedIndex = Math.min(ctx2.filledValueLength, ctx2.valueLength - 1);
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
preventDefault(_, evt) {
|
|
506
|
+
evt.preventDefault();
|
|
507
|
+
},
|
|
508
|
+
blurFocusedInputIfNeeded(ctx2) {
|
|
509
|
+
if (!ctx2.blurOnComplete)
|
|
510
|
+
return;
|
|
511
|
+
raf(() => {
|
|
512
|
+
var _a;
|
|
513
|
+
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.blur();
|
|
514
|
+
});
|
|
515
|
+
},
|
|
516
|
+
requestFormSubmit(ctx2) {
|
|
517
|
+
var _a;
|
|
518
|
+
if (!ctx2.name)
|
|
519
|
+
return;
|
|
520
|
+
const input = dom.getHiddenInputEl(ctx2);
|
|
521
|
+
(_a = input == null ? void 0 : input.form) == null ? void 0 : _a.requestSubmit();
|
|
522
|
+
}
|
|
554
523
|
}
|
|
555
524
|
}
|
|
556
|
-
|
|
525
|
+
);
|
|
557
526
|
}
|
|
558
527
|
var REGEX = {
|
|
559
528
|
numeric: /^[0-9]+$/,
|
|
@@ -581,3 +550,8 @@ function assign(ctx, value) {
|
|
|
581
550
|
function lastChar(value) {
|
|
582
551
|
return value.charAt(value.length - 1);
|
|
583
552
|
}
|
|
553
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
554
|
+
0 && (module.exports = {
|
|
555
|
+
connect,
|
|
556
|
+
machine
|
|
557
|
+
});
|