@zag-js/pin-input 0.15.0 → 0.17.0

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.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
2
+ import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
3
3
  import * as _zag_js_core from '@zag-js/core';
4
4
  import { StateMachine } from '@zag-js/core';
5
5
 
@@ -98,7 +98,42 @@ type PublicContext = DirectionProperty & CommonProperties & {
98
98
  */
99
99
  translations: IntlTranslations;
100
100
  };
101
- type PublicApi<T extends PropTypes = PropTypes> = {
101
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
102
+ type ComputedContext = Readonly<{
103
+ /**
104
+ * @computed
105
+ * The number of inputs
106
+ */
107
+ valueLength: number;
108
+ /**
109
+ * @computed
110
+ * The number of inputs that are not empty
111
+ */
112
+ filledValueLength: number;
113
+ /**
114
+ * @computed
115
+ * Whether all input values are valid
116
+ */
117
+ isValueComplete: boolean;
118
+ /**
119
+ * @computed
120
+ * The string representation of the input values
121
+ */
122
+ valueAsString: string;
123
+ /**
124
+ * @computed
125
+ * The value at focused index
126
+ */
127
+ focusedValue: string;
128
+ }>;
129
+ type PrivateContext = Context<{}>;
130
+ type MachineContext = PublicContext & PrivateContext & ComputedContext;
131
+ type MachineState = {
132
+ value: "idle" | "focused";
133
+ };
134
+ type State = StateMachine.State<MachineContext, MachineState>;
135
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
136
+ type MachineApi<T extends PropTypes = PropTypes> = {
102
137
  /**
103
138
  * The value of the input as an array of strings.
104
139
  */
@@ -135,44 +170,9 @@ type PublicApi<T extends PropTypes = PropTypes> = {
135
170
  index: number;
136
171
  }): T["input"];
137
172
  };
138
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
139
- type ComputedContext = Readonly<{
140
- /**
141
- * @computed
142
- * The number of inputs
143
- */
144
- valueLength: number;
145
- /**
146
- * @computed
147
- * The number of inputs that are not empty
148
- */
149
- filledValueLength: number;
150
- /**
151
- * @computed
152
- * Whether all input values are valid
153
- */
154
- isValueComplete: boolean;
155
- /**
156
- * @computed
157
- * The string representation of the input values
158
- */
159
- valueAsString: string;
160
- /**
161
- * @computed
162
- * The value at focused index
163
- */
164
- focusedValue: string;
165
- }>;
166
- type PrivateContext = Context<{}>;
167
- type MachineContext = PublicContext & PrivateContext & ComputedContext;
168
- type MachineState = {
169
- value: "idle" | "focused";
170
- };
171
- type State = StateMachine.State<MachineContext, MachineState>;
172
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
173
173
 
174
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T>;
174
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
175
175
 
176
176
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
177
177
 
178
- export { UserDefinedContext as Context, PublicApi, anatomy, connect, machine };
178
+ export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
2
+ import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, Context, NormalizeProps } from '@zag-js/types';
3
3
  import * as _zag_js_core from '@zag-js/core';
4
4
  import { StateMachine } from '@zag-js/core';
5
5
 
@@ -98,7 +98,42 @@ type PublicContext = DirectionProperty & CommonProperties & {
98
98
  */
99
99
  translations: IntlTranslations;
100
100
  };
101
- type PublicApi<T extends PropTypes = PropTypes> = {
101
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
102
+ type ComputedContext = Readonly<{
103
+ /**
104
+ * @computed
105
+ * The number of inputs
106
+ */
107
+ valueLength: number;
108
+ /**
109
+ * @computed
110
+ * The number of inputs that are not empty
111
+ */
112
+ filledValueLength: number;
113
+ /**
114
+ * @computed
115
+ * Whether all input values are valid
116
+ */
117
+ isValueComplete: boolean;
118
+ /**
119
+ * @computed
120
+ * The string representation of the input values
121
+ */
122
+ valueAsString: string;
123
+ /**
124
+ * @computed
125
+ * The value at focused index
126
+ */
127
+ focusedValue: string;
128
+ }>;
129
+ type PrivateContext = Context<{}>;
130
+ type MachineContext = PublicContext & PrivateContext & ComputedContext;
131
+ type MachineState = {
132
+ value: "idle" | "focused";
133
+ };
134
+ type State = StateMachine.State<MachineContext, MachineState>;
135
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
136
+ type MachineApi<T extends PropTypes = PropTypes> = {
102
137
  /**
103
138
  * The value of the input as an array of strings.
104
139
  */
@@ -135,44 +170,9 @@ type PublicApi<T extends PropTypes = PropTypes> = {
135
170
  index: number;
136
171
  }): T["input"];
137
172
  };
138
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
139
- type ComputedContext = Readonly<{
140
- /**
141
- * @computed
142
- * The number of inputs
143
- */
144
- valueLength: number;
145
- /**
146
- * @computed
147
- * The number of inputs that are not empty
148
- */
149
- filledValueLength: number;
150
- /**
151
- * @computed
152
- * Whether all input values are valid
153
- */
154
- isValueComplete: boolean;
155
- /**
156
- * @computed
157
- * The string representation of the input values
158
- */
159
- valueAsString: string;
160
- /**
161
- * @computed
162
- * The value at focused index
163
- */
164
- focusedValue: string;
165
- }>;
166
- type PrivateContext = Context<{}>;
167
- type MachineContext = PublicContext & PrivateContext & ComputedContext;
168
- type MachineState = {
169
- value: "idle" | "focused";
170
- };
171
- type State = StateMachine.State<MachineContext, MachineState>;
172
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
173
173
 
174
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T>;
174
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
175
175
 
176
176
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
177
177
 
178
- export { UserDefinedContext as Context, PublicApi, anatomy, connect, machine };
178
+ export { MachineApi as Api, UserDefinedContext as Context, anatomy, connect, machine };
package/dist/index.js CHANGED
@@ -46,14 +46,14 @@ var dom = (0, import_dom_query.createScope)({
46
46
  getLabelId: (ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`,
47
47
  getControlId: (ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`,
48
48
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
49
- getElements: (ctx) => {
49
+ getInputEls: (ctx) => {
50
50
  const ownerId = CSS.escape(dom.getRootId(ctx));
51
51
  const selector = `input[data-ownedby=${ownerId}]`;
52
52
  return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), selector);
53
53
  },
54
54
  getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
55
- getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
56
- getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
55
+ getFocusedInputEl: (ctx) => dom.getInputEls(ctx)[ctx.focusedIndex],
56
+ getFirstInputEl: (ctx) => dom.getInputEls(ctx)[0],
57
57
  getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
58
58
  });
59
59
 
@@ -225,8 +225,8 @@ function machine(userContext) {
225
225
  focusedValue: (ctx2) => ctx2.value[ctx2.focusedIndex]
226
226
  },
227
227
  watch: {
228
- focusedIndex: ["focusInput", "setInputSelection"],
229
- value: ["dispatchInputEvent", "syncInputElements"],
228
+ focusedIndex: ["focusInput", "selectInputIfNeeded"],
229
+ value: ["syncInputElements"],
230
230
  isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
231
231
  },
232
232
  entry: ctx.autoFocus ? ["setupValue", "setFocusIndexToFirst"] : ["setupValue"],
@@ -234,17 +234,17 @@ function machine(userContext) {
234
234
  SET_VALUE: [
235
235
  {
236
236
  guard: "hasIndex",
237
- actions: ["setValueAtIndex", "invokeOnChange"]
237
+ actions: ["setValueAtIndex"]
238
238
  },
239
- { actions: ["setValue", "invokeOnChange"] }
239
+ { actions: ["setValue"] }
240
240
  ],
241
241
  CLEAR_VALUE: [
242
242
  {
243
243
  guard: "isDisabled",
244
- actions: ["clearValue", "invokeOnChange"]
244
+ actions: ["clearValue"]
245
245
  },
246
246
  {
247
- actions: ["clearValue", "invokeOnChange", "setFocusIndexToFirst"]
247
+ actions: ["clearValue", "setFocusIndexToFirst"]
248
248
  }
249
249
  ]
250
250
  },
@@ -262,19 +262,19 @@ function machine(userContext) {
262
262
  INPUT: [
263
263
  {
264
264
  guard: and("isFinalValue", "isValidValue"),
265
- actions: ["setFocusedValue", "invokeOnChange", "syncInputValue"]
265
+ actions: ["setFocusedValue", "syncInputValue"]
266
266
  },
267
267
  {
268
268
  guard: "isValidValue",
269
- actions: ["setFocusedValue", "invokeOnChange", "setNextFocusedIndex", "syncInputValue"]
269
+ actions: ["setFocusedValue", "setNextFocusedIndex", "syncInputValue"]
270
270
  }
271
271
  ],
272
272
  PASTE: [
273
273
  {
274
274
  guard: "isValidValue",
275
- actions: ["setPastedValue", "invokeOnChange", "setLastValueFocusIndex"]
275
+ actions: ["setPastedValue", "setLastValueFocusIndex"]
276
276
  },
277
- { actions: ["resetFocusedValue", "invokeOnChange"] }
277
+ { actions: ["revertInputValue"] }
278
278
  ],
279
279
  BLUR: {
280
280
  target: "idle",
@@ -282,7 +282,7 @@ function machine(userContext) {
282
282
  },
283
283
  DELETE: {
284
284
  guard: "hasValue",
285
- actions: ["clearFocusedValue", "invokeOnChange"]
285
+ actions: ["clearFocusedValue"]
286
286
  },
287
287
  ARROW_LEFT: {
288
288
  actions: "setPrevFocusedIndex"
@@ -293,10 +293,10 @@ function machine(userContext) {
293
293
  BACKSPACE: [
294
294
  {
295
295
  guard: "hasValue",
296
- actions: ["clearFocusedValue", "invokeOnChange"]
296
+ actions: ["clearFocusedValue"]
297
297
  },
298
298
  {
299
- actions: ["setPrevFocusedIndex", "clearFocusedValue", "invokeOnChange"]
299
+ actions: ["setPrevFocusedIndex", "clearFocusedValue"]
300
300
  }
301
301
  ],
302
302
  ENTER: {
@@ -317,13 +317,13 @@ function machine(userContext) {
317
317
  isValueEmpty: (_ctx, evt) => evt.value === "",
318
318
  hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
319
319
  isValueComplete: (ctx2) => ctx2.isValueComplete,
320
- isValidValue: (ctx2, evt) => {
320
+ isValidValue(ctx2, evt) {
321
321
  if (!ctx2.pattern)
322
322
  return isValidType(evt.value, ctx2.type);
323
323
  const regex = new RegExp(ctx2.pattern, "g");
324
324
  return regex.test(evt.value);
325
325
  },
326
- isFinalValue: (ctx2) => {
326
+ isFinalValue(ctx2) {
327
327
  return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
328
328
  },
329
329
  isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
@@ -331,21 +331,21 @@ function machine(userContext) {
331
331
  isDisabled: (ctx2) => !!ctx2.disabled
332
332
  },
333
333
  actions: {
334
- setupValue: (ctx2) => {
334
+ setupValue(ctx2) {
335
335
  if (ctx2.value.length)
336
336
  return;
337
- const inputs = dom.getElements(ctx2);
337
+ const inputs = dom.getInputEls(ctx2);
338
338
  const emptyValues = Array.from({ length: inputs.length }).fill("");
339
- assign(ctx2, emptyValues);
339
+ assignValue(ctx2, emptyValues);
340
340
  },
341
- focusInput: (ctx2) => {
341
+ focusInput(ctx2) {
342
342
  (0, import_dom_query3.raf)(() => {
343
343
  if (ctx2.focusedIndex === -1)
344
344
  return;
345
345
  dom.getFocusedInputEl(ctx2)?.focus();
346
346
  });
347
347
  },
348
- setInputSelection: (ctx2) => {
348
+ selectInputIfNeeded(ctx2) {
349
349
  (0, import_dom_query3.raf)(() => {
350
350
  if (ctx2.focusedIndex === -1)
351
351
  return;
@@ -355,76 +355,69 @@ function machine(userContext) {
355
355
  input.selectionEnd = length;
356
356
  });
357
357
  },
358
- invokeOnComplete: (ctx2) => {
358
+ invokeOnComplete(ctx2) {
359
359
  if (!ctx2.isValueComplete)
360
360
  return;
361
361
  ctx2.onComplete?.({ value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
362
362
  },
363
- invokeOnChange: (ctx2) => {
364
- ctx2.onChange?.({ value: Array.from(ctx2.value) });
365
- },
366
- dispatchInputEvent: (ctx2) => {
367
- const inputEl = dom.getHiddenInputEl(ctx2);
368
- (0, import_form_utils.dispatchInputValueEvent)(inputEl, { value: ctx2.valueAsString });
369
- },
370
- invokeOnInvalid: (ctx2, evt) => {
363
+ invokeOnInvalid(ctx2, evt) {
371
364
  ctx2.onInvalid?.({ value: evt.value, index: ctx2.focusedIndex });
372
365
  },
373
- clearFocusedIndex: (ctx2) => {
366
+ clearFocusedIndex(ctx2) {
374
367
  ctx2.focusedIndex = -1;
375
368
  },
376
- setValue: (ctx2, evt) => {
377
- assign(ctx2, evt.value);
378
- },
379
- setFocusedIndex: (ctx2, evt) => {
369
+ setFocusedIndex(ctx2, evt) {
380
370
  ctx2.focusedIndex = evt.index;
381
371
  },
382
- setFocusedValue: (ctx2, evt) => {
383
- ctx2.value[ctx2.focusedIndex] = getNextValue(ctx2.focusedValue, evt.value);
372
+ setValue(ctx2, evt) {
373
+ set.value(ctx2, evt.value);
374
+ },
375
+ setFocusedValue(ctx2, evt) {
376
+ const nextValue = getNextValue(ctx2.focusedValue, evt.value);
377
+ set.valueAtIndex(ctx2, ctx2.focusedIndex, nextValue);
378
+ },
379
+ revertInputValue(ctx2) {
380
+ const inputEl = dom.getFocusedInputEl(ctx2);
381
+ dom.setValue(inputEl, ctx2.focusedValue);
384
382
  },
385
383
  syncInputValue(ctx2, evt) {
386
- const input = dom.getInputEl(ctx2, evt.index.toString());
387
- if (!input)
388
- return;
389
- input.value = ctx2.value[evt.index];
384
+ const inputEl = dom.getInputEl(ctx2, evt.index.toString());
385
+ dom.setValue(inputEl, ctx2.value[evt.index]);
390
386
  },
391
387
  syncInputElements(ctx2) {
392
- const inputs = dom.getElements(ctx2);
393
- inputs.forEach((input, index) => {
394
- input.value = ctx2.value[index];
388
+ const inputEls = dom.getInputEls(ctx2);
389
+ inputEls.forEach((inputEl, index) => {
390
+ dom.setValue(inputEl, ctx2.value[index]);
395
391
  });
396
392
  },
397
393
  setPastedValue(ctx2, evt) {
398
394
  (0, import_dom_query3.raf)(() => {
399
395
  const startIndex = ctx2.focusedValue ? 1 : 0;
400
396
  const value = evt.value.substring(startIndex, startIndex + ctx2.valueLength);
401
- assign(ctx2, value);
397
+ set.value(ctx2, value);
402
398
  });
403
399
  },
404
- setValueAtIndex: (ctx2, evt) => {
405
- ctx2.value[evt.index] = getNextValue(ctx2.focusedValue, evt.value);
400
+ setValueAtIndex(ctx2, evt) {
401
+ const nextValue = getNextValue(ctx2.focusedValue, evt.value);
402
+ set.valueAtIndex(ctx2, evt.index, nextValue);
406
403
  },
407
- clearValue: (ctx2) => {
404
+ clearValue(ctx2) {
408
405
  const nextValue = Array.from({ length: ctx2.valueLength }).fill("");
409
- assign(ctx2, nextValue);
406
+ set.value(ctx2, nextValue);
410
407
  },
411
- clearFocusedValue: (ctx2) => {
412
- ctx2.value[ctx2.focusedIndex] = "";
408
+ clearFocusedValue(ctx2) {
409
+ set.valueAtIndex(ctx2, ctx2.focusedIndex, "");
413
410
  },
414
- resetFocusedValue: (ctx2) => {
415
- const input = dom.getFocusedInputEl(ctx2);
416
- input.value = ctx2.focusedValue;
417
- },
418
- setFocusIndexToFirst: (ctx2) => {
411
+ setFocusIndexToFirst(ctx2) {
419
412
  ctx2.focusedIndex = 0;
420
413
  },
421
- setNextFocusedIndex: (ctx2) => {
414
+ setNextFocusedIndex(ctx2) {
422
415
  ctx2.focusedIndex = Math.min(ctx2.focusedIndex + 1, ctx2.valueLength - 1);
423
416
  },
424
- setPrevFocusedIndex: (ctx2) => {
417
+ setPrevFocusedIndex(ctx2) {
425
418
  ctx2.focusedIndex = Math.max(ctx2.focusedIndex - 1, 0);
426
419
  },
427
- setLastValueFocusIndex: (ctx2) => {
420
+ setLastValueFocusIndex(ctx2) {
428
421
  (0, import_dom_query3.raf)(() => {
429
422
  ctx2.focusedIndex = Math.min(ctx2.filledValueLength, ctx2.valueLength - 1);
430
423
  });
@@ -442,8 +435,8 @@ function machine(userContext) {
442
435
  requestFormSubmit(ctx2) {
443
436
  if (!ctx2.name || !ctx2.isValueComplete)
444
437
  return;
445
- const input = dom.getHiddenInputEl(ctx2);
446
- input?.form?.requestSubmit();
438
+ const inputEl = dom.getHiddenInputEl(ctx2);
439
+ inputEl?.form?.requestSubmit();
447
440
  }
448
441
  }
449
442
  }
@@ -459,7 +452,7 @@ function isValidType(value, type) {
459
452
  return true;
460
453
  return !!REGEX[type]?.test(value);
461
454
  }
462
- function assign(ctx, value) {
455
+ function assignValue(ctx, value) {
463
456
  const arr = Array.isArray(value) ? value : value.split("").filter(Boolean);
464
457
  arr.forEach((value2, index) => {
465
458
  ctx.value[index] = value2;
@@ -473,6 +466,23 @@ function getNextValue(current, next) {
473
466
  nextValue = next[0];
474
467
  return nextValue;
475
468
  }
469
+ var invoke = {
470
+ change(ctx) {
471
+ ctx.onChange?.({ value: Array.from(ctx.value) });
472
+ const inputEl = dom.getHiddenInputEl(ctx);
473
+ (0, import_form_utils.dispatchInputValueEvent)(inputEl, { value: ctx.valueAsString });
474
+ }
475
+ };
476
+ var set = {
477
+ value(ctx, values) {
478
+ assignValue(ctx, values);
479
+ invoke.change(ctx);
480
+ },
481
+ valueAtIndex(ctx, index, value) {
482
+ ctx.value[index] = value;
483
+ invoke.change(ctx);
484
+ }
485
+ };
476
486
  // Annotate the CommonJS export names for ESM import in node:
477
487
  0 && (module.exports = {
478
488
  anatomy,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/pin-input.anatomy.ts","../src/pin-input.connect.ts","../src/pin-input.dom.ts","../src/pin-input.machine.ts"],"sourcesContent":["export { anatomy } from \"./pin-input.anatomy\"\nexport { connect } from \"./pin-input.connect\"\nexport { machine } from \"./pin-input.machine\"\nexport type { UserDefinedContext as Context, PublicApi } from \"./pin-input.types\"\n","import { createAnatomy } from \"@zag-js/anatomy\"\n\nexport const anatomy = createAnatomy(\"pinInput\").parts(\"root\", \"label\", \"input\", \"control\")\nexport const parts = anatomy.build()\n","import { type EventKeyMap, getEventKey, getNativeEvent, isModifiedEvent } from \"@zag-js/dom-event\"\nimport { ariaAttr, dataAttr } from \"@zag-js/dom-query\"\nimport type { NormalizeProps, PropTypes } from \"@zag-js/types\"\nimport { invariant } from \"@zag-js/utils\"\nimport { visuallyHiddenStyle } from \"@zag-js/visually-hidden\"\nimport { parts } from \"./pin-input.anatomy\"\nimport { dom } from \"./pin-input.dom\"\nimport type { PublicApi, Send, State } from \"./pin-input.types\"\n\nexport function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): PublicApi<T> {\n const isValueComplete = state.context.isValueComplete\n const isInvalid = state.context.invalid\n const focusedIndex = state.context.focusedIndex\n const translations = state.context.translations\n\n function focus() {\n dom.getFirstInputEl(state.context)?.focus()\n }\n\n return {\n value: state.context.value,\n valueAsString: state.context.valueAsString,\n isValueComplete: isValueComplete,\n\n setValue(value: string[]) {\n if (!Array.isArray(value)) {\n invariant(\"[pin-input/setValue] value must be an array\")\n }\n send({ type: \"SET_VALUE\", value })\n },\n\n clearValue() {\n send({ type: \"CLEAR_VALUE\" })\n },\n\n setValueAtIndex(index: number, value: string) {\n send({ type: \"SET_VALUE\", value, index })\n },\n\n focus,\n\n rootProps: normalize.element({\n dir: state.context.dir,\n ...parts.root.attrs,\n id: dom.getRootId(state.context),\n \"data-invalid\": dataAttr(isInvalid),\n \"data-disabled\": dataAttr(state.context.disabled),\n \"data-complete\": dataAttr(isValueComplete),\n }),\n\n labelProps: normalize.label({\n ...parts.label.attrs,\n htmlFor: dom.getHiddenInputId(state.context),\n id: dom.getLabelId(state.context),\n \"data-invalid\": dataAttr(isInvalid),\n \"data-disabled\": dataAttr(state.context.disabled),\n \"data-complete\": dataAttr(isValueComplete),\n onClick: (event) => {\n event.preventDefault()\n focus()\n },\n }),\n\n hiddenInputProps: normalize.input({\n \"aria-hidden\": true,\n type: \"text\",\n tabIndex: -1,\n id: dom.getHiddenInputId(state.context),\n name: state.context.name,\n form: state.context.form,\n style: visuallyHiddenStyle,\n maxLength: state.context.valueLength,\n defaultValue: state.context.valueAsString,\n }),\n\n controlProps: normalize.element({\n ...parts.control.attrs,\n id: dom.getControlId(state.context),\n }),\n\n getInputProps({ index }: { index: number }) {\n const inputType = state.context.type === \"numeric\" ? \"tel\" : \"text\"\n return normalize.input({\n ...parts.input.attrs,\n disabled: state.context.disabled,\n \"data-disabled\": dataAttr(state.context.disabled),\n \"data-complete\": dataAttr(isValueComplete),\n id: dom.getInputId(state.context, index.toString()),\n \"data-ownedby\": dom.getRootId(state.context),\n \"aria-label\": translations.inputLabel(index, state.context.valueLength),\n inputMode: state.context.otp || state.context.type === \"numeric\" ? \"numeric\" : \"text\",\n \"aria-invalid\": ariaAttr(isInvalid),\n \"data-invalid\": dataAttr(isInvalid),\n type: state.context.mask ? \"password\" : inputType,\n defaultValue: state.context.value[index] || \"\",\n autoCapitalize: \"none\",\n autoComplete: state.context.otp ? \"one-time-code\" : \"off\",\n placeholder: focusedIndex === index ? \"\" : state.context.placeholder,\n onChange(event) {\n const evt = getNativeEvent(event)\n const { value } = event.currentTarget\n if (evt.inputType === \"insertFromPaste\" || value.length > 2) {\n send({ type: \"PASTE\", value })\n event.preventDefault()\n return\n }\n\n if (evt.inputType === \"deleteContentBackward\") {\n send(\"BACKSPACE\")\n return\n }\n send({ type: \"INPUT\", value, index })\n },\n onKeyDown(event) {\n const evt = getNativeEvent(event)\n if (evt.isComposing || isModifiedEvent(evt)) return\n\n const keyMap: EventKeyMap = {\n Backspace() {\n send(\"BACKSPACE\")\n },\n Delete() {\n send(\"DELETE\")\n },\n ArrowLeft() {\n send(\"ARROW_LEFT\")\n },\n ArrowRight() {\n send(\"ARROW_RIGHT\")\n },\n Enter() {\n send(\"ENTER\")\n },\n }\n\n const key = getEventKey(event, { dir: state.context.dir })\n const exec = keyMap[key]\n\n if (exec) {\n exec(event)\n event.preventDefault()\n } else {\n if (key === \"Tab\") return\n send({ type: \"KEY_DOWN\", value: key, preventDefault: () => event.preventDefault() })\n }\n },\n onFocus() {\n send({ type: \"FOCUS\", index })\n },\n onBlur() {\n send({ type: \"BLUR\", index })\n },\n })\n },\n }\n}\n","import { createScope, queryAll } from \"@zag-js/dom-query\"\nimport type { MachineContext as Ctx } from \"./pin-input.types\"\n\nexport const dom = createScope({\n getRootId: (ctx: Ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`,\n getInputId: (ctx: Ctx, id: string) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`,\n getHiddenInputId: (ctx: Ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`,\n getLabelId: (ctx: Ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`,\n getControlId: (ctx: Ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`,\n\n getRootEl: (ctx: Ctx) => dom.getById(ctx, dom.getRootId(ctx)),\n getElements: (ctx: Ctx) => {\n const ownerId = CSS.escape(dom.getRootId(ctx))\n const selector = `input[data-ownedby=${ownerId}]`\n return queryAll<HTMLInputElement>(dom.getRootEl(ctx), selector)\n },\n getInputEl: (ctx: Ctx, id: string) => dom.getById<HTMLInputElement>(ctx, dom.getInputId(ctx, id)),\n getFocusedInputEl: (ctx: Ctx) => dom.getElements(ctx)[ctx.focusedIndex],\n getFirstInputEl: (ctx: Ctx) => dom.getElements(ctx)[0],\n getHiddenInputEl: (ctx: Ctx) => dom.getById<HTMLInputElement>(ctx, dom.getHiddenInputId(ctx)),\n})\n","import { createMachine, guards } from \"@zag-js/core\"\nimport { raf } from \"@zag-js/dom-query\"\nimport { dispatchInputValueEvent } from \"@zag-js/form-utils\"\nimport { compact } from \"@zag-js/utils\"\nimport { dom } from \"./pin-input.dom\"\nimport type { MachineContext, MachineState, UserDefinedContext } from \"./pin-input.types\"\n\nconst { and, not } = guards\n\nexport function machine(userContext: UserDefinedContext) {\n const ctx = compact(userContext)\n return createMachine<MachineContext, MachineState>(\n {\n id: \"pin-input\",\n initial: ctx.autoFocus ? \"focused\" : \"idle\",\n context: {\n value: [],\n focusedIndex: -1,\n placeholder: \"○\",\n otp: false,\n type: \"numeric\",\n ...ctx,\n translations: {\n inputLabel: (index, length) => `pin code ${index + 1} of ${length}`,\n ...ctx.translations,\n },\n },\n\n computed: {\n valueLength: (ctx) => ctx.value.length,\n filledValueLength: (ctx) => ctx.value.filter((v) => v?.trim() !== \"\").length,\n isValueComplete: (ctx) => ctx.valueLength === ctx.filledValueLength,\n valueAsString: (ctx) => ctx.value.join(\"\"),\n focusedValue: (ctx) => ctx.value[ctx.focusedIndex],\n },\n\n watch: {\n focusedIndex: [\"focusInput\", \"setInputSelection\"],\n value: [\"dispatchInputEvent\", \"syncInputElements\"],\n isValueComplete: [\"invokeOnComplete\", \"blurFocusedInputIfNeeded\"],\n },\n\n entry: ctx.autoFocus ? [\"setupValue\", \"setFocusIndexToFirst\"] : [\"setupValue\"],\n\n on: {\n SET_VALUE: [\n {\n guard: \"hasIndex\",\n actions: [\"setValueAtIndex\", \"invokeOnChange\"],\n },\n { actions: [\"setValue\", \"invokeOnChange\"] },\n ],\n CLEAR_VALUE: [\n {\n guard: \"isDisabled\",\n actions: [\"clearValue\", \"invokeOnChange\"],\n },\n {\n actions: [\"clearValue\", \"invokeOnChange\", \"setFocusIndexToFirst\"],\n },\n ],\n },\n\n states: {\n idle: {\n on: {\n FOCUS: {\n target: \"focused\",\n actions: \"setFocusedIndex\",\n },\n },\n },\n focused: {\n on: {\n INPUT: [\n {\n guard: and(\"isFinalValue\", \"isValidValue\"),\n actions: [\"setFocusedValue\", \"invokeOnChange\", \"syncInputValue\"],\n },\n {\n guard: \"isValidValue\",\n actions: [\"setFocusedValue\", \"invokeOnChange\", \"setNextFocusedIndex\", \"syncInputValue\"],\n },\n ],\n PASTE: [\n {\n guard: \"isValidValue\",\n actions: [\"setPastedValue\", \"invokeOnChange\", \"setLastValueFocusIndex\"],\n },\n { actions: [\"resetFocusedValue\", \"invokeOnChange\"] },\n ],\n BLUR: {\n target: \"idle\",\n actions: \"clearFocusedIndex\",\n },\n DELETE: {\n guard: \"hasValue\",\n actions: [\"clearFocusedValue\", \"invokeOnChange\"],\n },\n ARROW_LEFT: {\n actions: \"setPrevFocusedIndex\",\n },\n ARROW_RIGHT: {\n actions: \"setNextFocusedIndex\",\n },\n BACKSPACE: [\n {\n guard: \"hasValue\",\n actions: [\"clearFocusedValue\", \"invokeOnChange\"],\n },\n {\n actions: [\"setPrevFocusedIndex\", \"clearFocusedValue\", \"invokeOnChange\"],\n },\n ],\n ENTER: {\n guard: \"isValueComplete\",\n actions: \"requestFormSubmit\",\n },\n KEY_DOWN: {\n guard: not(\"isValidValue\"),\n actions: [\"preventDefault\", \"invokeOnInvalid\"],\n },\n },\n },\n },\n },\n {\n guards: {\n autoFocus: (ctx) => !!ctx.autoFocus,\n isValueEmpty: (_ctx, evt) => evt.value === \"\",\n hasValue: (ctx) => ctx.value[ctx.focusedIndex] !== \"\",\n isValueComplete: (ctx) => ctx.isValueComplete,\n isValidValue: (ctx, evt) => {\n if (!ctx.pattern) return isValidType(evt.value, ctx.type)\n const regex = new RegExp(ctx.pattern, \"g\")\n return regex.test(evt.value)\n },\n isFinalValue: (ctx) => {\n return (\n ctx.filledValueLength + 1 === ctx.valueLength &&\n ctx.value.findIndex((v) => v.trim() === \"\") === ctx.focusedIndex\n )\n },\n isLastInputFocused: (ctx) => ctx.focusedIndex === ctx.valueLength - 1,\n hasIndex: (_ctx, evt) => evt.index !== undefined,\n isDisabled: (ctx) => !!ctx.disabled,\n },\n actions: {\n setupValue: (ctx) => {\n if (ctx.value.length) return\n const inputs = dom.getElements(ctx)\n const emptyValues = Array.from<string>({ length: inputs.length }).fill(\"\")\n assign(ctx, emptyValues)\n },\n focusInput: (ctx) => {\n raf(() => {\n if (ctx.focusedIndex === -1) return\n dom.getFocusedInputEl(ctx)?.focus()\n })\n },\n setInputSelection: (ctx) => {\n raf(() => {\n if (ctx.focusedIndex === -1) return\n const input = dom.getFocusedInputEl(ctx)\n const length = input.value.length\n input.selectionStart = ctx.selectOnFocus ? 0 : length\n input.selectionEnd = length\n })\n },\n invokeOnComplete: (ctx) => {\n if (!ctx.isValueComplete) return\n ctx.onComplete?.({ value: Array.from(ctx.value), valueAsString: ctx.valueAsString })\n },\n invokeOnChange: (ctx) => {\n ctx.onChange?.({ value: Array.from(ctx.value) })\n },\n dispatchInputEvent: (ctx) => {\n const inputEl = dom.getHiddenInputEl(ctx)\n dispatchInputValueEvent(inputEl, { value: ctx.valueAsString })\n },\n invokeOnInvalid: (ctx, evt) => {\n ctx.onInvalid?.({ value: evt.value, index: ctx.focusedIndex })\n },\n clearFocusedIndex: (ctx) => {\n ctx.focusedIndex = -1\n },\n setValue: (ctx, evt) => {\n assign(ctx, evt.value)\n },\n setFocusedIndex: (ctx, evt) => {\n ctx.focusedIndex = evt.index\n },\n setFocusedValue: (ctx, evt) => {\n ctx.value[ctx.focusedIndex] = getNextValue(ctx.focusedValue, evt.value)\n },\n syncInputValue(ctx, evt) {\n const input = dom.getInputEl(ctx, evt.index.toString())\n if (!input) return\n input.value = ctx.value[evt.index]\n },\n syncInputElements(ctx) {\n const inputs = dom.getElements(ctx)\n inputs.forEach((input, index) => {\n input.value = ctx.value[index]\n })\n },\n setPastedValue(ctx, evt) {\n raf(() => {\n const startIndex = ctx.focusedValue ? 1 : 0\n const value = evt.value.substring(startIndex, startIndex + ctx.valueLength)\n assign(ctx, value)\n })\n },\n setValueAtIndex: (ctx, evt) => {\n ctx.value[evt.index] = getNextValue(ctx.focusedValue, evt.value)\n },\n clearValue: (ctx) => {\n const nextValue = Array.from<string>({ length: ctx.valueLength }).fill(\"\")\n assign(ctx, nextValue)\n },\n clearFocusedValue: (ctx) => {\n ctx.value[ctx.focusedIndex] = \"\"\n },\n resetFocusedValue: (ctx) => {\n const input = dom.getFocusedInputEl(ctx)\n input.value = ctx.focusedValue\n },\n setFocusIndexToFirst: (ctx) => {\n ctx.focusedIndex = 0\n },\n setNextFocusedIndex: (ctx) => {\n ctx.focusedIndex = Math.min(ctx.focusedIndex + 1, ctx.valueLength - 1)\n },\n setPrevFocusedIndex: (ctx) => {\n ctx.focusedIndex = Math.max(ctx.focusedIndex - 1, 0)\n },\n setLastValueFocusIndex: (ctx) => {\n raf(() => {\n ctx.focusedIndex = Math.min(ctx.filledValueLength, ctx.valueLength - 1)\n })\n },\n preventDefault(_, evt) {\n evt.preventDefault()\n },\n blurFocusedInputIfNeeded(ctx) {\n if (!ctx.blurOnComplete) return\n raf(() => {\n dom.getFocusedInputEl(ctx)?.blur()\n })\n },\n requestFormSubmit(ctx) {\n if (!ctx.name || !ctx.isValueComplete) return\n const input = dom.getHiddenInputEl(ctx)\n input?.form?.requestSubmit()\n },\n },\n },\n )\n}\n\nconst REGEX = {\n numeric: /^[0-9]+$/,\n alphabetic: /^[A-Za-z]+$/,\n alphanumeric: /^[a-zA-Z0-9]+$/i,\n}\n\nfunction isValidType(value: string, type: MachineContext[\"type\"]) {\n if (!type) return true\n return !!REGEX[type]?.test(value)\n}\n\nfunction assign(ctx: MachineContext, value: string | string[]) {\n const arr = Array.isArray(value) ? value : value.split(\"\").filter(Boolean)\n arr.forEach((value, index) => {\n ctx.value[index] = value\n })\n}\n\nfunction getNextValue(current: string, next: string) {\n let nextValue = next\n if (current[0] === next[0]) next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AAK,CAAC;AAAG,gBAAY,KAAK,CAAC;AAAA,WACrC,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAG,gBAAY,KAAK,CAAC;AACnD,SAAO;AACT;","names":["import_dom_query","import_dom_query","import_utils","ctx","value"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/pin-input.anatomy.ts","../src/pin-input.connect.ts","../src/pin-input.dom.ts","../src/pin-input.machine.ts"],"sourcesContent":["export { anatomy } from \"./pin-input.anatomy\"\nexport { connect } from \"./pin-input.connect\"\nexport { machine } from \"./pin-input.machine\"\nexport type { UserDefinedContext as Context, MachineApi as Api } from \"./pin-input.types\"\n","import { createAnatomy } from \"@zag-js/anatomy\"\n\nexport const anatomy = createAnatomy(\"pinInput\").parts(\"root\", \"label\", \"input\", \"control\")\nexport const parts = anatomy.build()\n","import { getEventKey, getNativeEvent, isModifiedEvent, type EventKeyMap } from \"@zag-js/dom-event\"\nimport { ariaAttr, dataAttr } from \"@zag-js/dom-query\"\nimport type { NormalizeProps, PropTypes } from \"@zag-js/types\"\nimport { invariant } from \"@zag-js/utils\"\nimport { visuallyHiddenStyle } from \"@zag-js/visually-hidden\"\nimport { parts } from \"./pin-input.anatomy\"\nimport { dom } from \"./pin-input.dom\"\nimport type { MachineApi, Send, State } from \"./pin-input.types\"\n\nexport function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T> {\n const isValueComplete = state.context.isValueComplete\n const isInvalid = state.context.invalid\n const focusedIndex = state.context.focusedIndex\n const translations = state.context.translations\n\n function focus() {\n dom.getFirstInputEl(state.context)?.focus()\n }\n\n return {\n value: state.context.value,\n valueAsString: state.context.valueAsString,\n isValueComplete: isValueComplete,\n\n setValue(value: string[]) {\n if (!Array.isArray(value)) {\n invariant(\"[pin-input/setValue] value must be an array\")\n }\n send({ type: \"SET_VALUE\", value })\n },\n\n clearValue() {\n send({ type: \"CLEAR_VALUE\" })\n },\n\n setValueAtIndex(index: number, value: string) {\n send({ type: \"SET_VALUE\", value, index })\n },\n\n focus,\n\n rootProps: normalize.element({\n dir: state.context.dir,\n ...parts.root.attrs,\n id: dom.getRootId(state.context),\n \"data-invalid\": dataAttr(isInvalid),\n \"data-disabled\": dataAttr(state.context.disabled),\n \"data-complete\": dataAttr(isValueComplete),\n }),\n\n labelProps: normalize.label({\n ...parts.label.attrs,\n htmlFor: dom.getHiddenInputId(state.context),\n id: dom.getLabelId(state.context),\n \"data-invalid\": dataAttr(isInvalid),\n \"data-disabled\": dataAttr(state.context.disabled),\n \"data-complete\": dataAttr(isValueComplete),\n onClick: (event) => {\n event.preventDefault()\n focus()\n },\n }),\n\n hiddenInputProps: normalize.input({\n \"aria-hidden\": true,\n type: \"text\",\n tabIndex: -1,\n id: dom.getHiddenInputId(state.context),\n name: state.context.name,\n form: state.context.form,\n style: visuallyHiddenStyle,\n maxLength: state.context.valueLength,\n defaultValue: state.context.valueAsString,\n }),\n\n controlProps: normalize.element({\n ...parts.control.attrs,\n id: dom.getControlId(state.context),\n }),\n\n getInputProps({ index }: { index: number }) {\n const inputType = state.context.type === \"numeric\" ? \"tel\" : \"text\"\n return normalize.input({\n ...parts.input.attrs,\n disabled: state.context.disabled,\n \"data-disabled\": dataAttr(state.context.disabled),\n \"data-complete\": dataAttr(isValueComplete),\n id: dom.getInputId(state.context, index.toString()),\n \"data-ownedby\": dom.getRootId(state.context),\n \"aria-label\": translations.inputLabel(index, state.context.valueLength),\n inputMode: state.context.otp || state.context.type === \"numeric\" ? \"numeric\" : \"text\",\n \"aria-invalid\": ariaAttr(isInvalid),\n \"data-invalid\": dataAttr(isInvalid),\n type: state.context.mask ? \"password\" : inputType,\n defaultValue: state.context.value[index] || \"\",\n autoCapitalize: \"none\",\n autoComplete: state.context.otp ? \"one-time-code\" : \"off\",\n placeholder: focusedIndex === index ? \"\" : state.context.placeholder,\n onChange(event) {\n const evt = getNativeEvent(event)\n const { value } = event.currentTarget\n if (evt.inputType === \"insertFromPaste\" || value.length > 2) {\n send({ type: \"PASTE\", value })\n event.preventDefault()\n return\n }\n\n if (evt.inputType === \"deleteContentBackward\") {\n send(\"BACKSPACE\")\n return\n }\n send({ type: \"INPUT\", value, index })\n },\n onKeyDown(event) {\n const evt = getNativeEvent(event)\n if (evt.isComposing || isModifiedEvent(evt)) return\n\n const keyMap: EventKeyMap = {\n Backspace() {\n send(\"BACKSPACE\")\n },\n Delete() {\n send(\"DELETE\")\n },\n ArrowLeft() {\n send(\"ARROW_LEFT\")\n },\n ArrowRight() {\n send(\"ARROW_RIGHT\")\n },\n Enter() {\n send(\"ENTER\")\n },\n }\n\n const key = getEventKey(event, { dir: state.context.dir })\n const exec = keyMap[key]\n\n if (exec) {\n exec(event)\n event.preventDefault()\n } else {\n if (key === \"Tab\") return\n send({ type: \"KEY_DOWN\", value: key, preventDefault: () => event.preventDefault() })\n }\n },\n onFocus() {\n send({ type: \"FOCUS\", index })\n },\n onBlur() {\n send({ type: \"BLUR\", index })\n },\n })\n },\n }\n}\n","import { createScope, queryAll } from \"@zag-js/dom-query\"\nimport type { MachineContext as Ctx } from \"./pin-input.types\"\n\nexport const dom = createScope({\n getRootId: (ctx: Ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`,\n getInputId: (ctx: Ctx, id: string) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`,\n getHiddenInputId: (ctx: Ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`,\n getLabelId: (ctx: Ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`,\n getControlId: (ctx: Ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`,\n\n getRootEl: (ctx: Ctx) => dom.getById(ctx, dom.getRootId(ctx)),\n getInputEls: (ctx: Ctx) => {\n const ownerId = CSS.escape(dom.getRootId(ctx))\n const selector = `input[data-ownedby=${ownerId}]`\n return queryAll<HTMLInputElement>(dom.getRootEl(ctx), selector)\n },\n getInputEl: (ctx: Ctx, id: string) => dom.getById<HTMLInputElement>(ctx, dom.getInputId(ctx, id)),\n getFocusedInputEl: (ctx: Ctx) => dom.getInputEls(ctx)[ctx.focusedIndex],\n getFirstInputEl: (ctx: Ctx) => dom.getInputEls(ctx)[0],\n getHiddenInputEl: (ctx: Ctx) => dom.getById<HTMLInputElement>(ctx, dom.getHiddenInputId(ctx)),\n})\n","import { createMachine, guards } from \"@zag-js/core\"\nimport { raf } from \"@zag-js/dom-query\"\nimport { dispatchInputValueEvent } from \"@zag-js/form-utils\"\nimport { compact } from \"@zag-js/utils\"\nimport { dom } from \"./pin-input.dom\"\nimport type { MachineContext, MachineState, UserDefinedContext } from \"./pin-input.types\"\n\nconst { and, not } = guards\n\nexport function machine(userContext: UserDefinedContext) {\n const ctx = compact(userContext)\n return createMachine<MachineContext, MachineState>(\n {\n id: \"pin-input\",\n initial: ctx.autoFocus ? \"focused\" : \"idle\",\n context: {\n value: [],\n focusedIndex: -1,\n placeholder: \"○\",\n otp: false,\n type: \"numeric\",\n ...ctx,\n translations: {\n inputLabel: (index, length) => `pin code ${index + 1} of ${length}`,\n ...ctx.translations,\n },\n },\n\n computed: {\n valueLength: (ctx) => ctx.value.length,\n filledValueLength: (ctx) => ctx.value.filter((v) => v?.trim() !== \"\").length,\n isValueComplete: (ctx) => ctx.valueLength === ctx.filledValueLength,\n valueAsString: (ctx) => ctx.value.join(\"\"),\n focusedValue: (ctx) => ctx.value[ctx.focusedIndex],\n },\n\n watch: {\n focusedIndex: [\"focusInput\", \"selectInputIfNeeded\"],\n value: [\"syncInputElements\"],\n isValueComplete: [\"invokeOnComplete\", \"blurFocusedInputIfNeeded\"],\n },\n\n entry: ctx.autoFocus ? [\"setupValue\", \"setFocusIndexToFirst\"] : [\"setupValue\"],\n\n on: {\n SET_VALUE: [\n {\n guard: \"hasIndex\",\n actions: [\"setValueAtIndex\"],\n },\n { actions: [\"setValue\"] },\n ],\n CLEAR_VALUE: [\n {\n guard: \"isDisabled\",\n actions: [\"clearValue\"],\n },\n {\n actions: [\"clearValue\", \"setFocusIndexToFirst\"],\n },\n ],\n },\n\n states: {\n idle: {\n on: {\n FOCUS: {\n target: \"focused\",\n actions: \"setFocusedIndex\",\n },\n },\n },\n focused: {\n on: {\n INPUT: [\n {\n guard: and(\"isFinalValue\", \"isValidValue\"),\n actions: [\"setFocusedValue\", \"syncInputValue\"],\n },\n {\n guard: \"isValidValue\",\n actions: [\"setFocusedValue\", \"setNextFocusedIndex\", \"syncInputValue\"],\n },\n ],\n PASTE: [\n {\n guard: \"isValidValue\",\n actions: [\"setPastedValue\", \"setLastValueFocusIndex\"],\n },\n { actions: [\"revertInputValue\"] },\n ],\n BLUR: {\n target: \"idle\",\n actions: \"clearFocusedIndex\",\n },\n DELETE: {\n guard: \"hasValue\",\n actions: [\"clearFocusedValue\"],\n },\n ARROW_LEFT: {\n actions: \"setPrevFocusedIndex\",\n },\n ARROW_RIGHT: {\n actions: \"setNextFocusedIndex\",\n },\n BACKSPACE: [\n {\n guard: \"hasValue\",\n actions: [\"clearFocusedValue\"],\n },\n {\n actions: [\"setPrevFocusedIndex\", \"clearFocusedValue\"],\n },\n ],\n ENTER: {\n guard: \"isValueComplete\",\n actions: \"requestFormSubmit\",\n },\n KEY_DOWN: {\n guard: not(\"isValidValue\"),\n actions: [\"preventDefault\", \"invokeOnInvalid\"],\n },\n },\n },\n },\n },\n {\n guards: {\n autoFocus: (ctx) => !!ctx.autoFocus,\n isValueEmpty: (_ctx, evt) => evt.value === \"\",\n hasValue: (ctx) => ctx.value[ctx.focusedIndex] !== \"\",\n isValueComplete: (ctx) => ctx.isValueComplete,\n isValidValue(ctx, evt) {\n if (!ctx.pattern) return isValidType(evt.value, ctx.type)\n const regex = new RegExp(ctx.pattern, \"g\")\n return regex.test(evt.value)\n },\n isFinalValue(ctx) {\n return (\n ctx.filledValueLength + 1 === ctx.valueLength &&\n ctx.value.findIndex((v) => v.trim() === \"\") === ctx.focusedIndex\n )\n },\n isLastInputFocused: (ctx) => ctx.focusedIndex === ctx.valueLength - 1,\n hasIndex: (_ctx, evt) => evt.index !== undefined,\n isDisabled: (ctx) => !!ctx.disabled,\n },\n actions: {\n setupValue(ctx) {\n if (ctx.value.length) return\n const inputs = dom.getInputEls(ctx)\n const emptyValues = Array.from<string>({ length: inputs.length }).fill(\"\")\n assignValue(ctx, emptyValues)\n },\n focusInput(ctx) {\n raf(() => {\n if (ctx.focusedIndex === -1) return\n dom.getFocusedInputEl(ctx)?.focus()\n })\n },\n selectInputIfNeeded(ctx) {\n raf(() => {\n if (ctx.focusedIndex === -1) return\n const input = dom.getFocusedInputEl(ctx)\n const length = input.value.length\n input.selectionStart = ctx.selectOnFocus ? 0 : length\n input.selectionEnd = length\n })\n },\n invokeOnComplete(ctx) {\n if (!ctx.isValueComplete) return\n ctx.onComplete?.({ value: Array.from(ctx.value), valueAsString: ctx.valueAsString })\n },\n invokeOnInvalid(ctx, evt) {\n ctx.onInvalid?.({ value: evt.value, index: ctx.focusedIndex })\n },\n clearFocusedIndex(ctx) {\n ctx.focusedIndex = -1\n },\n setFocusedIndex(ctx, evt) {\n ctx.focusedIndex = evt.index\n },\n setValue(ctx, evt) {\n set.value(ctx, evt.value)\n },\n setFocusedValue(ctx, evt) {\n const nextValue = getNextValue(ctx.focusedValue, evt.value)\n set.valueAtIndex(ctx, ctx.focusedIndex, nextValue)\n },\n revertInputValue(ctx) {\n const inputEl = dom.getFocusedInputEl(ctx)\n dom.setValue(inputEl, ctx.focusedValue)\n },\n syncInputValue(ctx, evt) {\n const inputEl = dom.getInputEl(ctx, evt.index.toString())\n dom.setValue(inputEl, ctx.value[evt.index])\n },\n syncInputElements(ctx) {\n const inputEls = dom.getInputEls(ctx)\n inputEls.forEach((inputEl, index) => {\n dom.setValue(inputEl, ctx.value[index])\n })\n },\n setPastedValue(ctx, evt) {\n raf(() => {\n const startIndex = ctx.focusedValue ? 1 : 0\n const value = evt.value.substring(startIndex, startIndex + ctx.valueLength)\n set.value(ctx, value)\n })\n },\n setValueAtIndex(ctx, evt) {\n const nextValue = getNextValue(ctx.focusedValue, evt.value)\n set.valueAtIndex(ctx, evt.index, nextValue)\n },\n clearValue(ctx) {\n const nextValue = Array.from<string>({ length: ctx.valueLength }).fill(\"\")\n set.value(ctx, nextValue)\n },\n clearFocusedValue(ctx) {\n set.valueAtIndex(ctx, ctx.focusedIndex, \"\")\n },\n setFocusIndexToFirst(ctx) {\n ctx.focusedIndex = 0\n },\n setNextFocusedIndex(ctx) {\n ctx.focusedIndex = Math.min(ctx.focusedIndex + 1, ctx.valueLength - 1)\n },\n setPrevFocusedIndex(ctx) {\n ctx.focusedIndex = Math.max(ctx.focusedIndex - 1, 0)\n },\n setLastValueFocusIndex(ctx) {\n raf(() => {\n ctx.focusedIndex = Math.min(ctx.filledValueLength, ctx.valueLength - 1)\n })\n },\n preventDefault(_, evt) {\n evt.preventDefault()\n },\n blurFocusedInputIfNeeded(ctx) {\n if (!ctx.blurOnComplete) return\n raf(() => {\n dom.getFocusedInputEl(ctx)?.blur()\n })\n },\n requestFormSubmit(ctx) {\n if (!ctx.name || !ctx.isValueComplete) return\n const inputEl = dom.getHiddenInputEl(ctx)\n inputEl?.form?.requestSubmit()\n },\n },\n },\n )\n}\n\nconst REGEX = {\n numeric: /^[0-9]+$/,\n alphabetic: /^[A-Za-z]+$/,\n alphanumeric: /^[a-zA-Z0-9]+$/i,\n}\n\nfunction isValidType(value: string, type: MachineContext[\"type\"]) {\n if (!type) return true\n return !!REGEX[type]?.test(value)\n}\n\nfunction assignValue(ctx: MachineContext, value: string | string[]) {\n const arr = Array.isArray(value) ? value : value.split(\"\").filter(Boolean)\n arr.forEach((value, index) => {\n ctx.value[index] = value\n })\n}\n\nfunction getNextValue(current: string, next: string) {\n let nextValue = next\n if (current[0] === next[0]) nextValue = next[1]\n else if (current[0] === next[1]) nextValue = next[0]\n return nextValue\n}\n\nconst invoke = {\n change(ctx: MachineContext) {\n // callback\n ctx.onChange?.({ value: Array.from(ctx.value) })\n\n // form event\n const inputEl = dom.getHiddenInputEl(ctx)\n dispatchInputValueEvent(inputEl, { value: ctx.valueAsString })\n },\n}\n\nconst set = {\n value(ctx: MachineContext, values: string[]) {\n assignValue(ctx, values)\n invoke.change(ctx)\n },\n valueAtIndex(ctx: MachineContext, index: number, value: string) {\n ctx.value[index] = value\n invoke.change(ctx)\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA8B;AAEvB,IAAM,cAAU,8BAAc,UAAU,EAAE,MAAM,QAAQ,SAAS,SAAS,SAAS;AACnF,IAAM,QAAQ,QAAQ,MAAM;;;ACHnC,uBAA+E;AAC/E,IAAAA,oBAAmC;AAEnC,mBAA0B;AAC1B,6BAAoC;;;ACJpC,uBAAsC;AAG/B,IAAM,UAAM,8BAAY;AAAA,EAC7B,WAAW,CAAC,QAAa,IAAI,KAAK,QAAQ,aAAa,IAAI,EAAE;AAAA,EAC7D,YAAY,CAAC,KAAU,OAAe,IAAI,KAAK,QAAQ,EAAE,KAAK,aAAa,IAAI,EAAE,IAAI,EAAE;AAAA,EACvF,kBAAkB,CAAC,QAAa,IAAI,KAAK,eAAe,aAAa,IAAI,EAAE;AAAA,EAC3E,YAAY,CAAC,QAAa,IAAI,KAAK,SAAS,aAAa,IAAI,EAAE;AAAA,EAC/D,cAAc,CAAC,QAAa,IAAI,KAAK,WAAW,aAAa,IAAI,EAAE;AAAA,EAEnE,WAAW,CAAC,QAAa,IAAI,QAAQ,KAAK,IAAI,UAAU,GAAG,CAAC;AAAA,EAC5D,aAAa,CAAC,QAAa;AACzB,UAAM,UAAU,IAAI,OAAO,IAAI,UAAU,GAAG,CAAC;AAC7C,UAAM,WAAW,sBAAsB,OAAO;AAC9C,eAAO,2BAA2B,IAAI,UAAU,GAAG,GAAG,QAAQ;AAAA,EAChE;AAAA,EACA,YAAY,CAAC,KAAU,OAAe,IAAI,QAA0B,KAAK,IAAI,WAAW,KAAK,EAAE,CAAC;AAAA,EAChG,mBAAmB,CAAC,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