@zag-js/pin-input 0.1.9 → 0.1.12
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 +309 -252
- package/dist/index.mjs +305 -256
- package/package.json +15 -11
- package/dist/pin-input.connect.d.ts +0 -15
- package/dist/pin-input.dom.d.ts +0 -11
- package/dist/pin-input.machine.d.ts +0 -2
- package/dist/pin-input.types.d.ts +0 -113
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 });
|
|
@@ -49,9 +32,37 @@ var dataAttr = (guard) => {
|
|
|
49
32
|
var ariaAttr = (guard) => {
|
|
50
33
|
return guard ? "true" : void 0;
|
|
51
34
|
};
|
|
35
|
+
function isDocument(el) {
|
|
36
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
37
|
+
}
|
|
38
|
+
function isWindow(value) {
|
|
39
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
40
|
+
}
|
|
41
|
+
function getDocument(el) {
|
|
42
|
+
if (isWindow(el))
|
|
43
|
+
return el.document;
|
|
44
|
+
if (isDocument(el))
|
|
45
|
+
return el;
|
|
46
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
47
|
+
}
|
|
48
|
+
function defineDomHelpers(helpers) {
|
|
49
|
+
const dom2 = {
|
|
50
|
+
getRootNode: (ctx) => {
|
|
51
|
+
var _a;
|
|
52
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
53
|
+
},
|
|
54
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
55
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
56
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
57
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...dom2,
|
|
61
|
+
...helpers
|
|
62
|
+
};
|
|
63
|
+
}
|
|
52
64
|
function getNativeEvent(e) {
|
|
53
|
-
|
|
54
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
65
|
+
return e.nativeEvent ?? e;
|
|
55
66
|
}
|
|
56
67
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
57
68
|
var rtlKeyMap = {
|
|
@@ -70,29 +81,15 @@ var sameKeyMap = {
|
|
|
70
81
|
Right: "ArrowRight"
|
|
71
82
|
};
|
|
72
83
|
function getEventKey(event, options = {}) {
|
|
73
|
-
var _a;
|
|
74
84
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
75
85
|
let { key } = event;
|
|
76
|
-
key =
|
|
86
|
+
key = sameKeyMap[key] ?? key;
|
|
77
87
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
78
88
|
if (isRtl && key in rtlKeyMap) {
|
|
79
89
|
key = rtlKeyMap[key];
|
|
80
90
|
}
|
|
81
91
|
return key;
|
|
82
92
|
}
|
|
83
|
-
function nextTick(fn) {
|
|
84
|
-
const set = /* @__PURE__ */ new Set();
|
|
85
|
-
function raf2(fn2) {
|
|
86
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
87
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
88
|
-
}
|
|
89
|
-
raf2(() => raf2(fn));
|
|
90
|
-
return function cleanup() {
|
|
91
|
-
set.forEach(function(fn2) {
|
|
92
|
-
fn2();
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
93
|
function raf(fn) {
|
|
97
94
|
const id = globalThis.requestAnimationFrame(fn);
|
|
98
95
|
return function cleanup() {
|
|
@@ -100,47 +97,54 @@ function raf(fn) {
|
|
|
100
97
|
};
|
|
101
98
|
}
|
|
102
99
|
function queryAll(root, selector) {
|
|
103
|
-
|
|
104
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
100
|
+
return Array.from((root == null ? void 0 : root.querySelectorAll(selector)) ?? []);
|
|
105
101
|
}
|
|
102
|
+
var visuallyHiddenStyle = {
|
|
103
|
+
border: "0",
|
|
104
|
+
clip: "rect(0 0 0 0)",
|
|
105
|
+
height: "1px",
|
|
106
|
+
margin: "-1px",
|
|
107
|
+
overflow: "hidden",
|
|
108
|
+
padding: "0",
|
|
109
|
+
position: "absolute",
|
|
110
|
+
width: "1px",
|
|
111
|
+
whiteSpace: "nowrap",
|
|
112
|
+
wordWrap: "normal"
|
|
113
|
+
};
|
|
106
114
|
|
|
107
115
|
// ../../utilities/core/dist/index.mjs
|
|
108
|
-
var fromLength = (length) => Array.from(Array(length).keys());
|
|
109
116
|
function invariant(...a) {
|
|
110
117
|
const m = a.length === 1 ? a[0] : a[1];
|
|
111
118
|
const c = a.length === 2 ? a[0] : true;
|
|
112
|
-
if (c &&
|
|
119
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
113
120
|
throw new Error(m);
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
// src/pin-input.dom.ts
|
|
118
|
-
var dom = {
|
|
119
|
-
|
|
120
|
-
var _a;
|
|
121
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
122
|
-
},
|
|
123
|
-
getRootNode: (ctx) => {
|
|
125
|
+
var dom = defineDomHelpers({
|
|
126
|
+
getRootId: (ctx) => {
|
|
124
127
|
var _a;
|
|
125
|
-
return (_a = ctx.
|
|
128
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `pin-input:${ctx.id}`;
|
|
126
129
|
},
|
|
127
|
-
|
|
130
|
+
getInputId: (ctx, id) => {
|
|
128
131
|
var _a, _b;
|
|
129
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.
|
|
132
|
+
return ((_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) ?? `pin-input:${ctx.id}:${id}`;
|
|
130
133
|
},
|
|
131
|
-
|
|
132
|
-
var _a
|
|
133
|
-
return (
|
|
134
|
+
getHiddenInputId: (ctx) => {
|
|
135
|
+
var _a;
|
|
136
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.hiddenInput) ?? `pin-input:${ctx.id}:hidden`;
|
|
134
137
|
},
|
|
135
|
-
getRootEl: (ctx) => dom.
|
|
138
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
136
139
|
getElements: (ctx) => {
|
|
137
140
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
138
141
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
139
142
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
140
143
|
},
|
|
141
144
|
getFocusedEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
142
|
-
getFirstInputEl: (ctx) => dom.getElements(ctx)[0]
|
|
143
|
-
|
|
145
|
+
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
146
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
147
|
+
});
|
|
144
148
|
|
|
145
149
|
// src/pin-input.connect.ts
|
|
146
150
|
function connect(state, send, normalize) {
|
|
@@ -176,6 +180,16 @@ function connect(state, send, normalize) {
|
|
|
176
180
|
"data-disabled": dataAttr(state.context.disabled),
|
|
177
181
|
"data-complete": dataAttr(isValueComplete)
|
|
178
182
|
}),
|
|
183
|
+
hiddenInputProps: normalize.input({
|
|
184
|
+
"aria-hidden": true,
|
|
185
|
+
type: "text",
|
|
186
|
+
tabIndex: -1,
|
|
187
|
+
id: dom.getHiddenInputId(state.context),
|
|
188
|
+
name: state.context.name,
|
|
189
|
+
style: visuallyHiddenStyle,
|
|
190
|
+
maxLength: state.context.valueLength,
|
|
191
|
+
defaultValue: state.context.valueAsString
|
|
192
|
+
}),
|
|
179
193
|
getInputProps({ index }) {
|
|
180
194
|
const inputType = state.context.type === "numeric" ? "tel" : "text";
|
|
181
195
|
return normalize.input({
|
|
@@ -224,6 +238,9 @@ function connect(state, send, normalize) {
|
|
|
224
238
|
},
|
|
225
239
|
ArrowRight() {
|
|
226
240
|
send("ARROW_RIGHT");
|
|
241
|
+
},
|
|
242
|
+
Enter() {
|
|
243
|
+
send("ENTER");
|
|
227
244
|
}
|
|
228
245
|
};
|
|
229
246
|
const key = getEventKey(event, { dir: state.context.dir });
|
|
@@ -248,229 +265,264 @@ function connect(state, send, normalize) {
|
|
|
248
265
|
|
|
249
266
|
// src/pin-input.machine.ts
|
|
250
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
|
|
251
292
|
var { and, not } = import_core.guards;
|
|
252
|
-
function machine(ctx
|
|
253
|
-
return (0, import_core.createMachine)(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}),
|
|
268
|
-
computed: {
|
|
269
|
-
valueLength: (ctx2) => ctx2.value.length,
|
|
270
|
-
filledValueLength: (ctx2) => ctx2.value.filter((v) => (v == null ? void 0 : v.trim()) !== "").length,
|
|
271
|
-
isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
|
|
272
|
-
valueAsString: (ctx2) => ctx2.value.join("")
|
|
273
|
-
},
|
|
274
|
-
watch: {
|
|
275
|
-
focusedIndex: "focusInput",
|
|
276
|
-
value: "invokeOnChange",
|
|
277
|
-
isValueComplete: ["invokeComplete", "blurFocusedInputIfNeeded"]
|
|
278
|
-
},
|
|
279
|
-
on: {
|
|
280
|
-
SET_VALUE: [
|
|
281
|
-
{
|
|
282
|
-
guard: "hasIndex",
|
|
283
|
-
actions: "setValueAtIndex"
|
|
284
|
-
},
|
|
285
|
-
{ actions: "setValue" }
|
|
286
|
-
],
|
|
287
|
-
CLEAR_VALUE: [
|
|
288
|
-
{
|
|
289
|
-
guard: "isDisabled",
|
|
290
|
-
actions: "clearValue"
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
294
|
-
}
|
|
295
|
-
]
|
|
296
|
-
},
|
|
297
|
-
states: {
|
|
298
|
-
unknown: {
|
|
299
|
-
on: {
|
|
300
|
-
SETUP: [
|
|
301
|
-
{
|
|
302
|
-
guard: "autoFocus",
|
|
303
|
-
target: "focused",
|
|
304
|
-
actions: ["setupDocument", "setupValue", "setFocusIndexToFirst"]
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
target: "idle",
|
|
308
|
-
actions: ["setupDocument", "setupValue"]
|
|
309
|
-
}
|
|
310
|
-
]
|
|
293
|
+
function machine(ctx) {
|
|
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
|
|
311
308
|
}
|
|
312
309
|
},
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
}
|
|
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("")
|
|
320
315
|
},
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
],
|
|
333
|
-
PASTE: {
|
|
334
|
-
guard: "isValidValue",
|
|
335
|
-
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
336
|
-
},
|
|
337
|
-
BLUR: {
|
|
338
|
-
target: "idle",
|
|
339
|
-
actions: "clearFocusedIndex"
|
|
340
|
-
},
|
|
341
|
-
DELETE: {
|
|
342
|
-
guard: "hasValue",
|
|
343
|
-
actions: "clearFocusedValue"
|
|
344
|
-
},
|
|
345
|
-
ARROW_LEFT: {
|
|
346
|
-
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"
|
|
347
326
|
},
|
|
348
|
-
|
|
349
|
-
|
|
327
|
+
{ actions: "setValue" }
|
|
328
|
+
],
|
|
329
|
+
CLEAR_VALUE: [
|
|
330
|
+
{
|
|
331
|
+
guard: "isDisabled",
|
|
332
|
+
actions: "clearValue"
|
|
350
333
|
},
|
|
351
|
-
|
|
352
|
-
|
|
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: {
|
|
353
384
|
guard: "hasValue",
|
|
354
385
|
actions: "clearFocusedValue"
|
|
355
386
|
},
|
|
356
|
-
{
|
|
357
|
-
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"]
|
|
358
409
|
}
|
|
359
|
-
],
|
|
360
|
-
KEY_DOWN: {
|
|
361
|
-
guard: not("isValidValue"),
|
|
362
|
-
actions: ["preventDefault", "invokeOnInvalid"]
|
|
363
410
|
}
|
|
364
411
|
}
|
|
365
412
|
}
|
|
366
|
-
}
|
|
367
|
-
}, {
|
|
368
|
-
guards: {
|
|
369
|
-
autoFocus: (ctx2) => !!ctx2.autoFocus,
|
|
370
|
-
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
371
|
-
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
372
|
-
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
373
|
-
isValidValue: (ctx2, evt) => isValidType(evt.value, ctx2.type),
|
|
374
|
-
isFinalValue: (ctx2) => {
|
|
375
|
-
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
376
|
-
},
|
|
377
|
-
isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
|
|
378
|
-
hasIndex: (_ctx, evt) => evt.index !== void 0,
|
|
379
|
-
isDisabled: (ctx2) => !!ctx2.disabled
|
|
380
413
|
},
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
ctx2
|
|
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
|
|
388
432
|
},
|
|
389
|
-
|
|
390
|
-
|
|
433
|
+
actions: {
|
|
434
|
+
setupValue: (ctx2) => {
|
|
391
435
|
const inputs = dom.getElements(ctx2);
|
|
392
|
-
const empty =
|
|
436
|
+
const empty = Array.from({ length: inputs.length }).map(() => "");
|
|
393
437
|
ctx2.value = Object.assign(empty, ctx2.value);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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) => {
|
|
398
448
|
var _a;
|
|
399
|
-
if (ctx2.
|
|
449
|
+
if (!ctx2.isValueComplete)
|
|
400
450
|
return;
|
|
401
|
-
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.focus();
|
|
402
|
-
});
|
|
403
|
-
},
|
|
404
|
-
invokeComplete: (ctx2) => {
|
|
405
|
-
var _a;
|
|
406
|
-
if (ctx2.isValueComplete) {
|
|
407
451
|
(_a = ctx2.onComplete) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
452
|
+
},
|
|
453
|
+
invokeOnChange: (ctx2, evt) => {
|
|
454
|
+
var _a;
|
|
455
|
+
if (evt.type === "SETUP")
|
|
456
|
+
return;
|
|
413
457
|
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value) });
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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) {
|
|
468
517
|
var _a;
|
|
469
|
-
|
|
470
|
-
|
|
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
|
+
}
|
|
471
523
|
}
|
|
472
524
|
}
|
|
473
|
-
|
|
525
|
+
);
|
|
474
526
|
}
|
|
475
527
|
var REGEX = {
|
|
476
528
|
numeric: /^[0-9]+$/,
|
|
@@ -498,3 +550,8 @@ function assign(ctx, value) {
|
|
|
498
550
|
function lastChar(value) {
|
|
499
551
|
return value.charAt(value.length - 1);
|
|
500
552
|
}
|
|
553
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
554
|
+
0 && (module.exports = {
|
|
555
|
+
connect,
|
|
556
|
+
machine
|
|
557
|
+
});
|