@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.mjs
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// ../../utilities/dom/dist/index.mjs
|
|
22
2
|
var dataAttr = (guard) => {
|
|
23
3
|
return guard ? "" : void 0;
|
|
@@ -25,9 +5,37 @@ var dataAttr = (guard) => {
|
|
|
25
5
|
var ariaAttr = (guard) => {
|
|
26
6
|
return guard ? "true" : void 0;
|
|
27
7
|
};
|
|
8
|
+
function isDocument(el) {
|
|
9
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
10
|
+
}
|
|
11
|
+
function isWindow(value) {
|
|
12
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
13
|
+
}
|
|
14
|
+
function getDocument(el) {
|
|
15
|
+
if (isWindow(el))
|
|
16
|
+
return el.document;
|
|
17
|
+
if (isDocument(el))
|
|
18
|
+
return el;
|
|
19
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
20
|
+
}
|
|
21
|
+
function defineDomHelpers(helpers) {
|
|
22
|
+
const dom2 = {
|
|
23
|
+
getRootNode: (ctx) => {
|
|
24
|
+
var _a;
|
|
25
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
26
|
+
},
|
|
27
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
28
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
29
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
30
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
...dom2,
|
|
34
|
+
...helpers
|
|
35
|
+
};
|
|
36
|
+
}
|
|
28
37
|
function getNativeEvent(e) {
|
|
29
|
-
|
|
30
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
38
|
+
return e.nativeEvent ?? e;
|
|
31
39
|
}
|
|
32
40
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
33
41
|
var rtlKeyMap = {
|
|
@@ -46,29 +54,15 @@ var sameKeyMap = {
|
|
|
46
54
|
Right: "ArrowRight"
|
|
47
55
|
};
|
|
48
56
|
function getEventKey(event, options = {}) {
|
|
49
|
-
var _a;
|
|
50
57
|
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
51
58
|
let { key } = event;
|
|
52
|
-
key =
|
|
59
|
+
key = sameKeyMap[key] ?? key;
|
|
53
60
|
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
54
61
|
if (isRtl && key in rtlKeyMap) {
|
|
55
62
|
key = rtlKeyMap[key];
|
|
56
63
|
}
|
|
57
64
|
return key;
|
|
58
65
|
}
|
|
59
|
-
function nextTick(fn) {
|
|
60
|
-
const set = /* @__PURE__ */ new Set();
|
|
61
|
-
function raf2(fn2) {
|
|
62
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
63
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
64
|
-
}
|
|
65
|
-
raf2(() => raf2(fn));
|
|
66
|
-
return function cleanup() {
|
|
67
|
-
set.forEach(function(fn2) {
|
|
68
|
-
fn2();
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
66
|
function raf(fn) {
|
|
73
67
|
const id = globalThis.requestAnimationFrame(fn);
|
|
74
68
|
return function cleanup() {
|
|
@@ -76,47 +70,54 @@ function raf(fn) {
|
|
|
76
70
|
};
|
|
77
71
|
}
|
|
78
72
|
function queryAll(root, selector) {
|
|
79
|
-
|
|
80
|
-
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
73
|
+
return Array.from((root == null ? void 0 : root.querySelectorAll(selector)) ?? []);
|
|
81
74
|
}
|
|
75
|
+
var visuallyHiddenStyle = {
|
|
76
|
+
border: "0",
|
|
77
|
+
clip: "rect(0 0 0 0)",
|
|
78
|
+
height: "1px",
|
|
79
|
+
margin: "-1px",
|
|
80
|
+
overflow: "hidden",
|
|
81
|
+
padding: "0",
|
|
82
|
+
position: "absolute",
|
|
83
|
+
width: "1px",
|
|
84
|
+
whiteSpace: "nowrap",
|
|
85
|
+
wordWrap: "normal"
|
|
86
|
+
};
|
|
82
87
|
|
|
83
88
|
// ../../utilities/core/dist/index.mjs
|
|
84
|
-
var fromLength = (length) => Array.from(Array(length).keys());
|
|
85
89
|
function invariant(...a) {
|
|
86
90
|
const m = a.length === 1 ? a[0] : a[1];
|
|
87
91
|
const c = a.length === 2 ? a[0] : true;
|
|
88
|
-
if (c &&
|
|
92
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
89
93
|
throw new Error(m);
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
// src/pin-input.dom.ts
|
|
94
|
-
var dom = {
|
|
95
|
-
|
|
96
|
-
var _a;
|
|
97
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
98
|
-
},
|
|
99
|
-
getRootNode: (ctx) => {
|
|
98
|
+
var dom = defineDomHelpers({
|
|
99
|
+
getRootId: (ctx) => {
|
|
100
100
|
var _a;
|
|
101
|
-
return (_a = ctx.
|
|
101
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `pin-input:${ctx.id}`;
|
|
102
102
|
},
|
|
103
|
-
|
|
103
|
+
getInputId: (ctx, id) => {
|
|
104
104
|
var _a, _b;
|
|
105
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.
|
|
105
|
+
return ((_b = (_a = ctx.ids) == null ? void 0 : _a.input) == null ? void 0 : _b.call(_a, id)) ?? `pin-input:${ctx.id}:${id}`;
|
|
106
106
|
},
|
|
107
|
-
|
|
108
|
-
var _a
|
|
109
|
-
return (
|
|
107
|
+
getHiddenInputId: (ctx) => {
|
|
108
|
+
var _a;
|
|
109
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.hiddenInput) ?? `pin-input:${ctx.id}:hidden`;
|
|
110
110
|
},
|
|
111
|
-
getRootEl: (ctx) => dom.
|
|
111
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
112
112
|
getElements: (ctx) => {
|
|
113
113
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
114
114
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
115
115
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
116
116
|
},
|
|
117
117
|
getFocusedEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
118
|
-
getFirstInputEl: (ctx) => dom.getElements(ctx)[0]
|
|
119
|
-
|
|
118
|
+
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
119
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
120
|
+
});
|
|
120
121
|
|
|
121
122
|
// src/pin-input.connect.ts
|
|
122
123
|
function connect(state, send, normalize) {
|
|
@@ -152,6 +153,16 @@ function connect(state, send, normalize) {
|
|
|
152
153
|
"data-disabled": dataAttr(state.context.disabled),
|
|
153
154
|
"data-complete": dataAttr(isValueComplete)
|
|
154
155
|
}),
|
|
156
|
+
hiddenInputProps: normalize.input({
|
|
157
|
+
"aria-hidden": true,
|
|
158
|
+
type: "text",
|
|
159
|
+
tabIndex: -1,
|
|
160
|
+
id: dom.getHiddenInputId(state.context),
|
|
161
|
+
name: state.context.name,
|
|
162
|
+
style: visuallyHiddenStyle,
|
|
163
|
+
maxLength: state.context.valueLength,
|
|
164
|
+
defaultValue: state.context.valueAsString
|
|
165
|
+
}),
|
|
155
166
|
getInputProps({ index }) {
|
|
156
167
|
const inputType = state.context.type === "numeric" ? "tel" : "text";
|
|
157
168
|
return normalize.input({
|
|
@@ -200,6 +211,9 @@ function connect(state, send, normalize) {
|
|
|
200
211
|
},
|
|
201
212
|
ArrowRight() {
|
|
202
213
|
send("ARROW_RIGHT");
|
|
214
|
+
},
|
|
215
|
+
Enter() {
|
|
216
|
+
send("ENTER");
|
|
203
217
|
}
|
|
204
218
|
};
|
|
205
219
|
const key = getEventKey(event, { dir: state.context.dir });
|
|
@@ -223,230 +237,265 @@ function connect(state, send, normalize) {
|
|
|
223
237
|
}
|
|
224
238
|
|
|
225
239
|
// src/pin-input.machine.ts
|
|
226
|
-
import { createMachine, guards
|
|
240
|
+
import { createMachine, guards } from "@zag-js/core";
|
|
241
|
+
|
|
242
|
+
// ../../utilities/form-utils/dist/index.mjs
|
|
243
|
+
function getWindow(el) {
|
|
244
|
+
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
245
|
+
}
|
|
246
|
+
function getDescriptor(el, options) {
|
|
247
|
+
const { type, property } = options;
|
|
248
|
+
const proto = getWindow(el)[type].prototype;
|
|
249
|
+
return Object.getOwnPropertyDescriptor(proto, property) ?? {};
|
|
250
|
+
}
|
|
251
|
+
function dispatchInputValueEvent(el, value) {
|
|
252
|
+
var _a;
|
|
253
|
+
if (!el)
|
|
254
|
+
return;
|
|
255
|
+
const win = getWindow(el);
|
|
256
|
+
if (!(el instanceof win.HTMLInputElement))
|
|
257
|
+
return;
|
|
258
|
+
const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
|
|
259
|
+
(_a = desc.set) == null ? void 0 : _a.call(el, value);
|
|
260
|
+
const event = new win.Event("input", { bubbles: true });
|
|
261
|
+
el.dispatchEvent(event);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/pin-input.machine.ts
|
|
227
265
|
var { and, not } = guards;
|
|
228
|
-
function machine(ctx
|
|
229
|
-
return createMachine(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}),
|
|
244
|
-
computed: {
|
|
245
|
-
valueLength: (ctx2) => ctx2.value.length,
|
|
246
|
-
filledValueLength: (ctx2) => ctx2.value.filter((v) => (v == null ? void 0 : v.trim()) !== "").length,
|
|
247
|
-
isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
|
|
248
|
-
valueAsString: (ctx2) => ctx2.value.join("")
|
|
249
|
-
},
|
|
250
|
-
watch: {
|
|
251
|
-
focusedIndex: "focusInput",
|
|
252
|
-
value: "invokeOnChange",
|
|
253
|
-
isValueComplete: ["invokeComplete", "blurFocusedInputIfNeeded"]
|
|
254
|
-
},
|
|
255
|
-
on: {
|
|
256
|
-
SET_VALUE: [
|
|
257
|
-
{
|
|
258
|
-
guard: "hasIndex",
|
|
259
|
-
actions: "setValueAtIndex"
|
|
260
|
-
},
|
|
261
|
-
{ actions: "setValue" }
|
|
262
|
-
],
|
|
263
|
-
CLEAR_VALUE: [
|
|
264
|
-
{
|
|
265
|
-
guard: "isDisabled",
|
|
266
|
-
actions: "clearValue"
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
270
|
-
}
|
|
271
|
-
]
|
|
272
|
-
},
|
|
273
|
-
states: {
|
|
274
|
-
unknown: {
|
|
275
|
-
on: {
|
|
276
|
-
SETUP: [
|
|
277
|
-
{
|
|
278
|
-
guard: "autoFocus",
|
|
279
|
-
target: "focused",
|
|
280
|
-
actions: ["setupDocument", "setupValue", "setFocusIndexToFirst"]
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
target: "idle",
|
|
284
|
-
actions: ["setupDocument", "setupValue"]
|
|
285
|
-
}
|
|
286
|
-
]
|
|
266
|
+
function machine(ctx) {
|
|
267
|
+
return createMachine(
|
|
268
|
+
{
|
|
269
|
+
id: "pin-input",
|
|
270
|
+
initial: "unknown",
|
|
271
|
+
context: {
|
|
272
|
+
value: [],
|
|
273
|
+
focusedIndex: -1,
|
|
274
|
+
placeholder: "\u25CB",
|
|
275
|
+
otp: false,
|
|
276
|
+
type: "numeric",
|
|
277
|
+
...ctx,
|
|
278
|
+
messages: {
|
|
279
|
+
inputLabel: (index, length) => `pin code ${index + 1} of ${length}`,
|
|
280
|
+
...ctx.messages
|
|
287
281
|
}
|
|
288
282
|
},
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
}
|
|
283
|
+
computed: {
|
|
284
|
+
valueLength: (ctx2) => ctx2.value.length,
|
|
285
|
+
filledValueLength: (ctx2) => ctx2.value.filter((v) => (v == null ? void 0 : v.trim()) !== "").length,
|
|
286
|
+
isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
|
|
287
|
+
valueAsString: (ctx2) => ctx2.value.join("")
|
|
296
288
|
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
],
|
|
309
|
-
PASTE: {
|
|
310
|
-
guard: "isValidValue",
|
|
311
|
-
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
312
|
-
},
|
|
313
|
-
BLUR: {
|
|
314
|
-
target: "idle",
|
|
315
|
-
actions: "clearFocusedIndex"
|
|
316
|
-
},
|
|
317
|
-
DELETE: {
|
|
318
|
-
guard: "hasValue",
|
|
319
|
-
actions: "clearFocusedValue"
|
|
320
|
-
},
|
|
321
|
-
ARROW_LEFT: {
|
|
322
|
-
actions: "setPrevFocusedIndex"
|
|
289
|
+
watch: {
|
|
290
|
+
focusedIndex: "focusInput",
|
|
291
|
+
value: "invokeOnChange",
|
|
292
|
+
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
293
|
+
},
|
|
294
|
+
on: {
|
|
295
|
+
SET_VALUE: [
|
|
296
|
+
{
|
|
297
|
+
guard: "hasIndex",
|
|
298
|
+
actions: "setValueAtIndex"
|
|
323
299
|
},
|
|
324
|
-
|
|
325
|
-
|
|
300
|
+
{ actions: "setValue" }
|
|
301
|
+
],
|
|
302
|
+
CLEAR_VALUE: [
|
|
303
|
+
{
|
|
304
|
+
guard: "isDisabled",
|
|
305
|
+
actions: "clearValue"
|
|
326
306
|
},
|
|
327
|
-
|
|
328
|
-
|
|
307
|
+
{
|
|
308
|
+
actions: ["clearValue", "setFocusIndexToFirst"]
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
},
|
|
312
|
+
states: {
|
|
313
|
+
unknown: {
|
|
314
|
+
on: {
|
|
315
|
+
SETUP: [
|
|
316
|
+
{
|
|
317
|
+
guard: "autoFocus",
|
|
318
|
+
target: "focused",
|
|
319
|
+
actions: ["setupValue", "setFocusIndexToFirst"]
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
target: "idle",
|
|
323
|
+
actions: "setupValue"
|
|
324
|
+
}
|
|
325
|
+
]
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
idle: {
|
|
329
|
+
on: {
|
|
330
|
+
FOCUS: {
|
|
331
|
+
target: "focused",
|
|
332
|
+
actions: "setFocusedIndex"
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
focused: {
|
|
337
|
+
on: {
|
|
338
|
+
INPUT: [
|
|
339
|
+
{
|
|
340
|
+
guard: and("isFinalValue", "isValidValue"),
|
|
341
|
+
actions: "setFocusedValue"
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
guard: "isValidValue",
|
|
345
|
+
actions: ["setFocusedValue", "setNextFocusedIndex"]
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
PASTE: {
|
|
349
|
+
guard: "isValidValue",
|
|
350
|
+
actions: ["setPastedValue", "setLastValueFocusIndex"]
|
|
351
|
+
},
|
|
352
|
+
BLUR: {
|
|
353
|
+
target: "idle",
|
|
354
|
+
actions: "clearFocusedIndex"
|
|
355
|
+
},
|
|
356
|
+
DELETE: {
|
|
329
357
|
guard: "hasValue",
|
|
330
358
|
actions: "clearFocusedValue"
|
|
331
359
|
},
|
|
332
|
-
{
|
|
333
|
-
actions:
|
|
360
|
+
ARROW_LEFT: {
|
|
361
|
+
actions: "setPrevFocusedIndex"
|
|
362
|
+
},
|
|
363
|
+
ARROW_RIGHT: {
|
|
364
|
+
actions: "setNextFocusedIndex"
|
|
365
|
+
},
|
|
366
|
+
BACKSPACE: [
|
|
367
|
+
{
|
|
368
|
+
guard: "hasValue",
|
|
369
|
+
actions: "clearFocusedValue"
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
actions: ["setPrevFocusedIndex", "clearFocusedValue"]
|
|
373
|
+
}
|
|
374
|
+
],
|
|
375
|
+
ENTER: {
|
|
376
|
+
guard: "isValueComplete",
|
|
377
|
+
actions: "requestFormSubmit"
|
|
378
|
+
},
|
|
379
|
+
KEY_DOWN: {
|
|
380
|
+
guard: not("isValidValue"),
|
|
381
|
+
actions: ["preventDefault", "invokeOnInvalid"]
|
|
334
382
|
}
|
|
335
|
-
],
|
|
336
|
-
KEY_DOWN: {
|
|
337
|
-
guard: not("isValidValue"),
|
|
338
|
-
actions: ["preventDefault", "invokeOnInvalid"]
|
|
339
383
|
}
|
|
340
384
|
}
|
|
341
385
|
}
|
|
342
|
-
}
|
|
343
|
-
}, {
|
|
344
|
-
guards: {
|
|
345
|
-
autoFocus: (ctx2) => !!ctx2.autoFocus,
|
|
346
|
-
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
347
|
-
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
348
|
-
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
349
|
-
isValidValue: (ctx2, evt) => isValidType(evt.value, ctx2.type),
|
|
350
|
-
isFinalValue: (ctx2) => {
|
|
351
|
-
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
352
|
-
},
|
|
353
|
-
isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
|
|
354
|
-
hasIndex: (_ctx, evt) => evt.index !== void 0,
|
|
355
|
-
isDisabled: (ctx2) => !!ctx2.disabled
|
|
356
386
|
},
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
ctx2
|
|
387
|
+
{
|
|
388
|
+
guards: {
|
|
389
|
+
autoFocus: (ctx2) => !!ctx2.autoFocus,
|
|
390
|
+
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
391
|
+
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
392
|
+
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
393
|
+
isValidValue: (ctx2, evt) => {
|
|
394
|
+
if (!ctx2.pattern)
|
|
395
|
+
return isValidType(evt.value, ctx2.type);
|
|
396
|
+
const regex = new RegExp(ctx2.pattern, "g");
|
|
397
|
+
return regex.test(evt.value);
|
|
398
|
+
},
|
|
399
|
+
isFinalValue: (ctx2) => {
|
|
400
|
+
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
401
|
+
},
|
|
402
|
+
isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
|
|
403
|
+
hasIndex: (_ctx, evt) => evt.index !== void 0,
|
|
404
|
+
isDisabled: (ctx2) => !!ctx2.disabled
|
|
364
405
|
},
|
|
365
|
-
|
|
366
|
-
|
|
406
|
+
actions: {
|
|
407
|
+
setupValue: (ctx2) => {
|
|
367
408
|
const inputs = dom.getElements(ctx2);
|
|
368
|
-
const empty =
|
|
409
|
+
const empty = Array.from({ length: inputs.length }).map(() => "");
|
|
369
410
|
ctx2.value = Object.assign(empty, ctx2.value);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
411
|
+
},
|
|
412
|
+
focusInput: (ctx2) => {
|
|
413
|
+
raf(() => {
|
|
414
|
+
var _a;
|
|
415
|
+
if (ctx2.focusedIndex === -1)
|
|
416
|
+
return;
|
|
417
|
+
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.focus();
|
|
418
|
+
});
|
|
419
|
+
},
|
|
420
|
+
invokeOnComplete: (ctx2) => {
|
|
374
421
|
var _a;
|
|
375
|
-
if (ctx2.
|
|
422
|
+
if (!ctx2.isValueComplete)
|
|
376
423
|
return;
|
|
377
|
-
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.focus();
|
|
378
|
-
});
|
|
379
|
-
},
|
|
380
|
-
invokeComplete: (ctx2) => {
|
|
381
|
-
var _a;
|
|
382
|
-
if (ctx2.isValueComplete) {
|
|
383
424
|
(_a = ctx2.onComplete) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
425
|
+
},
|
|
426
|
+
invokeOnChange: (ctx2, evt) => {
|
|
427
|
+
var _a;
|
|
428
|
+
if (evt.type === "SETUP")
|
|
429
|
+
return;
|
|
389
430
|
(_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: Array.from(ctx2.value) });
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
431
|
+
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
432
|
+
},
|
|
433
|
+
invokeOnInvalid: (ctx2, evt) => {
|
|
434
|
+
var _a;
|
|
435
|
+
(_a = ctx2.onInvalid) == null ? void 0 : _a.call(ctx2, { value: evt.value, index: ctx2.focusedIndex });
|
|
436
|
+
},
|
|
437
|
+
clearFocusedIndex: (ctx2) => {
|
|
438
|
+
ctx2.focusedIndex = -1;
|
|
439
|
+
},
|
|
440
|
+
setValue: (ctx2, evt) => {
|
|
441
|
+
assign(ctx2, evt.value);
|
|
442
|
+
},
|
|
443
|
+
setFocusedIndex: (ctx2, evt) => {
|
|
444
|
+
ctx2.focusedIndex = evt.index;
|
|
445
|
+
},
|
|
446
|
+
setFocusedValue: (ctx2, evt) => {
|
|
447
|
+
ctx2.value[ctx2.focusedIndex] = lastChar(evt.value);
|
|
448
|
+
},
|
|
449
|
+
setPastedValue(ctx2, evt) {
|
|
450
|
+
raf(() => {
|
|
451
|
+
const value = evt.value.substring(0, ctx2.valueLength);
|
|
452
|
+
assign(ctx2, value.split("").filter(Boolean));
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
setValueAtIndex: (ctx2, evt) => {
|
|
456
|
+
ctx2.value[evt.index] = lastChar(evt.value);
|
|
457
|
+
},
|
|
458
|
+
clearValue: (ctx2) => {
|
|
459
|
+
assign(ctx2, "");
|
|
460
|
+
},
|
|
461
|
+
clearFocusedValue: (ctx2) => {
|
|
462
|
+
ctx2.value[ctx2.focusedIndex] = "";
|
|
463
|
+
},
|
|
464
|
+
setFocusIndexToFirst: (ctx2) => {
|
|
465
|
+
ctx2.focusedIndex = 0;
|
|
466
|
+
},
|
|
467
|
+
setNextFocusedIndex: (ctx2) => {
|
|
468
|
+
ctx2.focusedIndex = Math.min(ctx2.focusedIndex + 1, ctx2.valueLength - 1);
|
|
469
|
+
},
|
|
470
|
+
setPrevFocusedIndex: (ctx2) => {
|
|
471
|
+
ctx2.focusedIndex = Math.max(ctx2.focusedIndex - 1, 0);
|
|
472
|
+
},
|
|
473
|
+
setLastValueFocusIndex: (ctx2) => {
|
|
474
|
+
raf(() => {
|
|
475
|
+
ctx2.focusedIndex = Math.min(ctx2.filledValueLength, ctx2.valueLength - 1);
|
|
476
|
+
});
|
|
477
|
+
},
|
|
478
|
+
preventDefault(_, evt) {
|
|
479
|
+
evt.preventDefault();
|
|
480
|
+
},
|
|
481
|
+
blurFocusedInputIfNeeded(ctx2) {
|
|
482
|
+
if (!ctx2.blurOnComplete)
|
|
483
|
+
return;
|
|
484
|
+
raf(() => {
|
|
485
|
+
var _a;
|
|
486
|
+
(_a = dom.getFocusedEl(ctx2)) == null ? void 0 : _a.blur();
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
requestFormSubmit(ctx2) {
|
|
444
490
|
var _a;
|
|
445
|
-
|
|
446
|
-
|
|
491
|
+
if (!ctx2.name)
|
|
492
|
+
return;
|
|
493
|
+
const input = dom.getHiddenInputEl(ctx2);
|
|
494
|
+
(_a = input == null ? void 0 : input.form) == null ? void 0 : _a.requestSubmit();
|
|
495
|
+
}
|
|
447
496
|
}
|
|
448
497
|
}
|
|
449
|
-
|
|
498
|
+
);
|
|
450
499
|
}
|
|
451
500
|
var REGEX = {
|
|
452
501
|
numeric: /^[0-9]+$/,
|