@zag-js/pin-input 0.22.0 → 0.24.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.mjs CHANGED
@@ -5,7 +5,7 @@ var parts = anatomy.build();
5
5
 
6
6
  // src/pin-input.connect.ts
7
7
  import { getEventKey, getNativeEvent, isModifiedEvent } from "@zag-js/dom-event";
8
- import { ariaAttr, dataAttr } from "@zag-js/dom-query";
8
+ import { ariaAttr, dataAttr, getBeforeInputValue } from "@zag-js/dom-query";
9
9
  import { invariant } from "@zag-js/utils";
10
10
  import { visuallyHiddenStyle } from "@zag-js/visually-hidden";
11
11
 
@@ -29,6 +29,24 @@ var dom = createScope({
29
29
  getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
30
30
  });
31
31
 
32
+ // src/pin-input.utils.ts
33
+ var REGEX = {
34
+ numeric: /^[0-9]+$/,
35
+ alphabetic: /^[A-Za-z]+$/,
36
+ alphanumeric: /^[a-zA-Z0-9]+$/i
37
+ };
38
+ function isValidType(ctx, value) {
39
+ if (!ctx.type)
40
+ return true;
41
+ return !!REGEX[ctx.type]?.test(value);
42
+ }
43
+ function isValidValue(ctx, value) {
44
+ if (!ctx.pattern)
45
+ return isValidType(ctx, value);
46
+ const regex = new RegExp(ctx.pattern, "g");
47
+ return regex.test(value);
48
+ }
49
+
32
50
  // src/pin-input.connect.ts
33
51
  function connect(state, send, normalize) {
34
52
  const isValueComplete = state.context.isValueComplete;
@@ -46,13 +64,13 @@ function connect(state, send, normalize) {
46
64
  if (!Array.isArray(value)) {
47
65
  invariant("[pin-input/setValue] value must be an array");
48
66
  }
49
- send({ type: "SET_VALUE", value });
67
+ send({ type: "VALUE.SET", value });
50
68
  },
51
69
  clearValue() {
52
- send({ type: "CLEAR_VALUE" });
70
+ send({ type: "VALUE.CLEAR" });
53
71
  },
54
72
  setValueAtIndex(index, value) {
55
- send({ type: "SET_VALUE", value, index });
73
+ send({ type: "VALUE.SET", value, index });
56
74
  },
57
75
  focus,
58
76
  rootProps: normalize.element({
@@ -71,7 +89,7 @@ function connect(state, send, normalize) {
71
89
  "data-invalid": dataAttr(isInvalid),
72
90
  "data-disabled": dataAttr(state.context.disabled),
73
91
  "data-complete": dataAttr(isValueComplete),
74
- onClick: (event) => {
92
+ onClick(event) {
75
93
  event.preventDefault();
76
94
  focus();
77
95
  }
@@ -92,7 +110,8 @@ function connect(state, send, normalize) {
92
110
  dir: state.context.dir,
93
111
  id: dom.getControlId(state.context)
94
112
  }),
95
- getInputProps({ index }) {
113
+ getInputProps(props) {
114
+ const { index } = props;
96
115
  const inputType = state.context.type === "numeric" ? "tel" : "text";
97
116
  return normalize.input({
98
117
  ...parts.input.attrs,
@@ -111,57 +130,63 @@ function connect(state, send, normalize) {
111
130
  autoCapitalize: "none",
112
131
  autoComplete: state.context.otp ? "one-time-code" : "off",
113
132
  placeholder: focusedIndex === index ? "" : state.context.placeholder,
133
+ onBeforeInput(event) {
134
+ try {
135
+ const value = getBeforeInputValue(event);
136
+ const isValid = isValidValue(state.context, value);
137
+ if (!isValid) {
138
+ send({ type: "VALUE.INVALID", value });
139
+ event.preventDefault();
140
+ }
141
+ } catch {
142
+ }
143
+ },
114
144
  onChange(event) {
115
145
  const evt = getNativeEvent(event);
116
146
  const { value } = event.currentTarget;
117
147
  if (evt.inputType === "insertFromPaste" || value.length > 2) {
118
- send({ type: "PASTE", value });
148
+ send({ type: "INPUT.PASTE", value });
119
149
  event.preventDefault();
120
150
  return;
121
151
  }
122
152
  if (evt.inputType === "deleteContentBackward") {
123
- send("BACKSPACE");
153
+ send("INPUT.BACKSPACE");
124
154
  return;
125
155
  }
126
- send({ type: "INPUT", value, index });
156
+ send({ type: "INPUT.CHANGE", value, index });
127
157
  },
128
158
  onKeyDown(event) {
129
159
  const evt = getNativeEvent(event);
130
- if (evt.isComposing || isModifiedEvent(evt))
160
+ if (isModifiedEvent(evt))
131
161
  return;
132
162
  const keyMap = {
133
163
  Backspace() {
134
- send("BACKSPACE");
164
+ send("INPUT.BACKSPACE");
135
165
  },
136
166
  Delete() {
137
- send("DELETE");
167
+ send("INPUT.DELETE");
138
168
  },
139
169
  ArrowLeft() {
140
- send("ARROW_LEFT");
170
+ send("INPUT.ARROW_LEFT");
141
171
  },
142
172
  ArrowRight() {
143
- send("ARROW_RIGHT");
173
+ send("INPUT.ARROW_RIGHT");
144
174
  },
145
175
  Enter() {
146
- send("ENTER");
176
+ send("INPUT.ENTER");
147
177
  }
148
178
  };
149
- const key = getEventKey(event, { dir: state.context.dir });
150
- const exec = keyMap[key];
179
+ const exec = keyMap[getEventKey(event, state.context)];
151
180
  if (exec) {
152
181
  exec(event);
153
182
  event.preventDefault();
154
- } else {
155
- if (key === "Tab")
156
- return;
157
- send({ type: "KEY_DOWN", value: key, preventDefault: () => event.preventDefault() });
158
183
  }
159
184
  },
160
185
  onFocus() {
161
- send({ type: "FOCUS", index });
186
+ send({ type: "INPUT.FOCUS", index });
162
187
  },
163
188
  onBlur() {
164
- send({ type: "BLUR", index });
189
+ send({ type: "INPUT.BLUR", index });
165
190
  }
166
191
  });
167
192
  }
@@ -169,17 +194,16 @@ function connect(state, send, normalize) {
169
194
  }
170
195
 
171
196
  // src/pin-input.machine.ts
172
- import { createMachine, guards } from "@zag-js/core";
197
+ import { choose, createMachine } from "@zag-js/core";
173
198
  import { raf } from "@zag-js/dom-query";
174
199
  import { dispatchInputValueEvent } from "@zag-js/form-utils";
175
200
  import { compact, isEqual } from "@zag-js/utils";
176
- var { and, not } = guards;
177
201
  function machine(userContext) {
178
202
  const ctx = compact(userContext);
179
203
  return createMachine(
180
204
  {
181
205
  id: "pin-input",
182
- initial: ctx.autoFocus ? "focused" : "idle",
206
+ initial: "idle",
183
207
  context: {
184
208
  value: [],
185
209
  focusedIndex: -1,
@@ -197,36 +221,36 @@ function machine(userContext) {
197
221
  filledValueLength: (ctx2) => ctx2.value.filter((v) => v?.trim() !== "").length,
198
222
  isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
199
223
  valueAsString: (ctx2) => ctx2.value.join(""),
200
- focusedValue: (ctx2) => ctx2.value[ctx2.focusedIndex]
224
+ focusedValue: (ctx2) => ctx2.value[ctx2.focusedIndex] || ""
201
225
  },
226
+ entry: choose([
227
+ {
228
+ guard: "autoFocus",
229
+ actions: ["setupValue", "setFocusIndexToFirst"]
230
+ },
231
+ { actions: ["setupValue"] }
232
+ ]),
202
233
  watch: {
203
234
  focusedIndex: ["focusInput", "selectInputIfNeeded"],
204
235
  value: ["syncInputElements"],
205
236
  isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
206
237
  },
207
- entry: ctx.autoFocus ? ["setupValue", "setFocusIndexToFirst"] : ["setupValue"],
208
238
  on: {
209
- SET_VALUE: [
239
+ "VALUE.SET": [
210
240
  {
211
241
  guard: "hasIndex",
212
242
  actions: ["setValueAtIndex"]
213
243
  },
214
244
  { actions: ["setValue"] }
215
245
  ],
216
- CLEAR_VALUE: [
217
- {
218
- guard: "isDisabled",
219
- actions: ["clearValue"]
220
- },
221
- {
222
- actions: ["clearValue", "setFocusIndexToFirst"]
223
- }
224
- ]
246
+ "VALUE.CLEAR": {
247
+ actions: ["clearValue", "setFocusIndexToFirst"]
248
+ }
225
249
  },
226
250
  states: {
227
251
  idle: {
228
252
  on: {
229
- FOCUS: {
253
+ "INPUT.FOCUS": {
230
254
  target: "focused",
231
255
  actions: "setFocusedIndex"
232
256
  }
@@ -234,38 +258,33 @@ function machine(userContext) {
234
258
  },
235
259
  focused: {
236
260
  on: {
237
- INPUT: [
261
+ "INPUT.CHANGE": [
238
262
  {
239
- guard: and("isFinalValue", "isValidValue"),
263
+ guard: "isFinalValue",
240
264
  actions: ["setFocusedValue", "syncInputValue"]
241
265
  },
242
266
  {
243
- guard: "isValidValue",
244
267
  actions: ["setFocusedValue", "setNextFocusedIndex", "syncInputValue"]
245
268
  }
246
269
  ],
247
- PASTE: [
248
- {
249
- guard: "isValidValue",
250
- actions: ["setPastedValue", "setLastValueFocusIndex"]
251
- },
252
- { actions: ["revertInputValue"] }
253
- ],
254
- BLUR: {
270
+ "INPUT.PASTE": {
271
+ actions: ["setPastedValue", "setLastValueFocusIndex"]
272
+ },
273
+ "INPUT.BLUR": {
255
274
  target: "idle",
256
275
  actions: "clearFocusedIndex"
257
276
  },
258
- DELETE: {
277
+ "INPUT.DELETE": {
259
278
  guard: "hasValue",
260
- actions: ["clearFocusedValue"]
279
+ actions: "clearFocusedValue"
261
280
  },
262
- ARROW_LEFT: {
281
+ "INPUT.ARROW_LEFT": {
263
282
  actions: "setPrevFocusedIndex"
264
283
  },
265
- ARROW_RIGHT: {
284
+ "INPUT.ARROW_RIGHT": {
266
285
  actions: "setNextFocusedIndex"
267
286
  },
268
- BACKSPACE: [
287
+ "INPUT.BACKSPACE": [
269
288
  {
270
289
  guard: "hasValue",
271
290
  actions: ["clearFocusedValue"]
@@ -274,13 +293,12 @@ function machine(userContext) {
274
293
  actions: ["setPrevFocusedIndex", "clearFocusedValue"]
275
294
  }
276
295
  ],
277
- ENTER: {
296
+ "INPUT.ENTER": {
278
297
  guard: "isValueComplete",
279
298
  actions: "requestFormSubmit"
280
299
  },
281
- KEY_DOWN: {
282
- guard: not("isValidValue"),
283
- actions: ["preventDefault", "invokeOnInvalid"]
300
+ "VALUE.INVALID": {
301
+ actions: "invokeOnInvalid"
284
302
  }
285
303
  }
286
304
  }
@@ -292,16 +310,7 @@ function machine(userContext) {
292
310
  isValueEmpty: (_ctx, evt) => evt.value === "",
293
311
  hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
294
312
  isValueComplete: (ctx2) => ctx2.isValueComplete,
295
- isValidValue(ctx2, evt) {
296
- if (!ctx2.pattern)
297
- return isValidType(evt.value, ctx2.type);
298
- const regex = new RegExp(ctx2.pattern, "g");
299
- return regex.test(evt.value);
300
- },
301
- isFinalValue(ctx2) {
302
- return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
303
- },
304
- isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
313
+ isFinalValue: (ctx2) => ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex,
305
314
  hasIndex: (_ctx, evt) => evt.index !== void 0,
306
315
  isDisabled: (ctx2) => !!ctx2.disabled
307
316
  },
@@ -309,25 +318,20 @@ function machine(userContext) {
309
318
  setupValue(ctx2) {
310
319
  if (ctx2.value.length)
311
320
  return;
312
- const inputs = dom.getInputEls(ctx2);
313
- const emptyValues = Array.from({ length: inputs.length }).fill("");
321
+ const inputEls = dom.getInputEls(ctx2);
322
+ const emptyValues = Array.from({ length: inputEls.length }).fill("");
314
323
  assignValue(ctx2, emptyValues);
315
324
  },
316
325
  focusInput(ctx2) {
317
- raf(() => {
318
- if (ctx2.focusedIndex === -1)
319
- return;
320
- dom.getFocusedInputEl(ctx2)?.focus();
321
- });
326
+ if (ctx2.focusedIndex === -1)
327
+ return;
328
+ dom.getFocusedInputEl(ctx2)?.focus({ preventScroll: true });
322
329
  },
323
330
  selectInputIfNeeded(ctx2) {
331
+ if (!ctx2.selectOnFocus || ctx2.focusedIndex === -1)
332
+ return;
324
333
  raf(() => {
325
- if (ctx2.focusedIndex === -1)
326
- return;
327
- const input = dom.getFocusedInputEl(ctx2);
328
- const length = input.value.length;
329
- input.selectionStart = ctx2.selectOnFocus ? 0 : length;
330
- input.selectionEnd = length;
334
+ dom.getFocusedInputEl(ctx2)?.select();
331
335
  });
332
336
  },
333
337
  invokeOnComplete(ctx2) {
@@ -403,9 +407,6 @@ function machine(userContext) {
403
407
  ctx2.focusedIndex = Math.min(ctx2.filledValueLength, ctx2.valueLength - 1);
404
408
  });
405
409
  },
406
- preventDefault(_, evt) {
407
- evt.preventDefault();
408
- },
409
410
  blurFocusedInputIfNeeded(ctx2) {
410
411
  if (!ctx2.blurOnComplete)
411
412
  return;
@@ -423,16 +424,6 @@ function machine(userContext) {
423
424
  }
424
425
  );
425
426
  }
426
- var REGEX = {
427
- numeric: /^[0-9]+$/,
428
- alphabetic: /^[A-Za-z]+$/,
429
- alphanumeric: /^[a-zA-Z0-9]+$/i
430
- };
431
- function isValidType(value, type) {
432
- if (!type)
433
- return true;
434
- return !!REGEX[type]?.test(value);
435
- }
436
427
  function assignValue(ctx, value) {
437
428
  const arr = Array.isArray(value) ? value : value.split("").filter(Boolean);
438
429
  arr.forEach((value2, index) => {
@@ -445,7 +436,7 @@ function getNextValue(current, next) {
445
436
  nextValue = next[1];
446
437
  else if (current[0] === next[1])
447
438
  nextValue = next[0];
448
- return nextValue;
439
+ return nextValue.split("")[nextValue.length - 1];
449
440
  }
450
441
  var invoke = {
451
442
  change(ctx) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/pin-input.anatomy.ts","../src/pin-input.connect.ts","../src/pin-input.dom.ts","../src/pin-input.machine.ts"],"sourcesContent":["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 dir: state.context.dir,\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 dir: state.context.dir,\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 dir: state.context.dir,\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, isEqual } 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.onValueComplete?.({\n value: Array.from(ctx.value),\n valueAsString: ctx.valueAsString,\n })\n },\n invokeOnInvalid(ctx, evt) {\n ctx.onValueInvalid?.({\n value: evt.value,\n index: ctx.focusedIndex,\n })\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.onValueChange?.({\n value: Array.from(ctx.value),\n valueAsString: ctx.valueAsString,\n })\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, value: string[]) {\n if (isEqual(ctx.value, value)) return\n assignValue(ctx, value)\n invoke.change(ctx)\n },\n valueAtIndex(ctx: MachineContext, index: number, value: string) {\n if (isEqual(ctx.value[index], value)) return\n ctx.value[index] = value\n invoke.change(ctx)\n },\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAEvB,IAAM,UAAU,cAAc,UAAU,EAAE,MAAM,QAAQ,SAAS,SAAS,SAAS;AACnF,IAAM,QAAQ,QAAQ,MAAM;;;ACHnC,SAAS,aAAa,gBAAgB,uBAAyC;AAC/E,SAAS,UAAU,gBAAgB;AAEnC,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;;;ACJpC,SAAS,aAAa,gBAAgB;AAG/B,IAAM,MAAM,YAAY;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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AAQ,CAACC,QAAO,UAAU;AAC5B,QAAI,MAAM,KAAK,IAAIA;AAAA,EACrB,CAAC;AACH;AAEA,SAAS,aAAa,SAAiB,MAAc;AACnD,MAAI,YAAY;AAChB,MAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAG,gBAAY,KAAK,CAAC;AAAA,WACrC,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAG,gBAAY,KAAK,CAAC;AACnD,SAAO;AACT;AAEA,IAAM,SAAS;AAAA,EACb,OAAO,KAAqB;AAE1B,QAAI,gBAAgB;AAAA,MAClB,OAAO,MAAM,KAAK,IAAI,KAAK;AAAA,MAC3B,eAAe,IAAI;AAAA,IACrB,CAAC;AAGD,UAAM,UAAU,IAAI,iBAAiB,GAAG;AACxC,4BAAwB,SAAS,EAAE,OAAO,IAAI,cAAc,CAAC;AAAA,EAC/D;AACF;AAEA,IAAM,MAAM;AAAA,EACV,MAAM,KAAqB,OAAiB;AAC1C,QAAI,QAAQ,IAAI,OAAO,KAAK;AAAG;AAC/B,gBAAY,KAAK,KAAK;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAAA,EACA,aAAa,KAAqB,OAAe,OAAe;AAC9D,QAAI,QAAQ,IAAI,MAAM,KAAK,GAAG,KAAK;AAAG;AACtC,QAAI,MAAM,KAAK,IAAI;AACnB,WAAO,OAAO,GAAG;AAAA,EACnB;AACF;","names":["ctx","value"]}
1
+ {"version":3,"sources":["../src/pin-input.anatomy.ts","../src/pin-input.connect.ts","../src/pin-input.dom.ts","../src/pin-input.utils.ts","../src/pin-input.machine.ts"],"sourcesContent":["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, getBeforeInputValue } 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\"\nimport { isValidValue } from \"./pin-input.utils\"\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) {\n if (!Array.isArray(value)) {\n invariant(\"[pin-input/setValue] value must be an array\")\n }\n send({ type: \"VALUE.SET\", value })\n },\n\n clearValue() {\n send({ type: \"VALUE.CLEAR\" })\n },\n\n setValueAtIndex(index, value) {\n send({ type: \"VALUE.SET\", 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 dir: state.context.dir,\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 dir: state.context.dir,\n id: dom.getControlId(state.context),\n }),\n\n getInputProps(props) {\n const { index } = props\n const inputType = state.context.type === \"numeric\" ? \"tel\" : \"text\"\n return normalize.input({\n ...parts.input.attrs,\n dir: state.context.dir,\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 onBeforeInput(event) {\n try {\n const value = getBeforeInputValue(event)\n const isValid = isValidValue(state.context, value)\n if (!isValid) {\n send({ type: \"VALUE.INVALID\", value })\n event.preventDefault()\n }\n } catch {\n // noop\n }\n },\n onChange(event) {\n const evt = getNativeEvent(event)\n const { value } = event.currentTarget\n\n if (evt.inputType === \"insertFromPaste\" || value.length > 2) {\n send({ type: \"INPUT.PASTE\", value })\n event.preventDefault()\n return\n }\n\n if (evt.inputType === \"deleteContentBackward\") {\n send(\"INPUT.BACKSPACE\")\n return\n }\n\n send({ type: \"INPUT.CHANGE\", value, index })\n },\n onKeyDown(event) {\n const evt = getNativeEvent(event)\n if (isModifiedEvent(evt)) return\n\n const keyMap: EventKeyMap = {\n Backspace() {\n send(\"INPUT.BACKSPACE\")\n },\n Delete() {\n send(\"INPUT.DELETE\")\n },\n ArrowLeft() {\n send(\"INPUT.ARROW_LEFT\")\n },\n ArrowRight() {\n send(\"INPUT.ARROW_RIGHT\")\n },\n Enter() {\n send(\"INPUT.ENTER\")\n },\n }\n\n const exec = keyMap[getEventKey(event, state.context)]\n\n if (exec) {\n exec(event)\n event.preventDefault()\n }\n },\n onFocus() {\n send({ type: \"INPUT.FOCUS\", index })\n },\n onBlur() {\n send({ type: \"INPUT.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 type { MachineContext } from \"./pin-input.types\"\n\nconst REGEX = {\n numeric: /^[0-9]+$/,\n alphabetic: /^[A-Za-z]+$/,\n alphanumeric: /^[a-zA-Z0-9]+$/i,\n}\n\nexport function isValidType(ctx: MachineContext, value: string) {\n if (!ctx.type) return true\n return !!REGEX[ctx.type]?.test(value)\n}\n\nexport function isValidValue(ctx: MachineContext, value: string) {\n if (!ctx.pattern) return isValidType(ctx, value)\n const regex = new RegExp(ctx.pattern, \"g\")\n return regex.test(value)\n}\n","import { choose, createMachine } from \"@zag-js/core\"\nimport { raf } from \"@zag-js/dom-query\"\nimport { dispatchInputValueEvent } from \"@zag-js/form-utils\"\nimport { compact, isEqual } from \"@zag-js/utils\"\nimport { dom } from \"./pin-input.dom\"\nimport type { MachineContext, MachineState, UserDefinedContext } from \"./pin-input.types\"\n\nexport function machine(userContext: UserDefinedContext) {\n const ctx = compact(userContext)\n return createMachine<MachineContext, MachineState>(\n {\n id: \"pin-input\",\n initial: \"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 entry: choose([\n {\n guard: \"autoFocus\",\n actions: [\"setupValue\", \"setFocusIndexToFirst\"],\n },\n { actions: [\"setupValue\"] },\n ]),\n\n watch: {\n focusedIndex: [\"focusInput\", \"selectInputIfNeeded\"],\n value: [\"syncInputElements\"],\n isValueComplete: [\"invokeOnComplete\", \"blurFocusedInputIfNeeded\"],\n },\n\n on: {\n \"VALUE.SET\": [\n {\n guard: \"hasIndex\",\n actions: [\"setValueAtIndex\"],\n },\n { actions: [\"setValue\"] },\n ],\n \"VALUE.CLEAR\": {\n actions: [\"clearValue\", \"setFocusIndexToFirst\"],\n },\n },\n\n states: {\n idle: {\n on: {\n \"INPUT.FOCUS\": {\n target: \"focused\",\n actions: \"setFocusedIndex\",\n },\n },\n },\n focused: {\n on: {\n \"INPUT.CHANGE\": [\n {\n guard: \"isFinalValue\",\n actions: [\"setFocusedValue\", \"syncInputValue\"],\n },\n {\n actions: [\"setFocusedValue\", \"setNextFocusedIndex\", \"syncInputValue\"],\n },\n ],\n \"INPUT.PASTE\": {\n actions: [\"setPastedValue\", \"setLastValueFocusIndex\"],\n },\n \"INPUT.BLUR\": {\n target: \"idle\",\n actions: \"clearFocusedIndex\",\n },\n \"INPUT.DELETE\": {\n guard: \"hasValue\",\n actions: \"clearFocusedValue\",\n },\n \"INPUT.ARROW_LEFT\": {\n actions: \"setPrevFocusedIndex\",\n },\n \"INPUT.ARROW_RIGHT\": {\n actions: \"setNextFocusedIndex\",\n },\n \"INPUT.BACKSPACE\": [\n {\n guard: \"hasValue\",\n actions: [\"clearFocusedValue\"],\n },\n {\n actions: [\"setPrevFocusedIndex\", \"clearFocusedValue\"],\n },\n ],\n \"INPUT.ENTER\": {\n guard: \"isValueComplete\",\n actions: \"requestFormSubmit\",\n },\n \"VALUE.INVALID\": {\n actions: \"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 isFinalValue: (ctx) =>\n ctx.filledValueLength + 1 === ctx.valueLength &&\n ctx.value.findIndex((v) => v.trim() === \"\") === ctx.focusedIndex,\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 inputEls = dom.getInputEls(ctx)\n const emptyValues = Array.from<string>({ length: inputEls.length }).fill(\"\")\n assignValue(ctx, emptyValues)\n },\n focusInput(ctx) {\n if (ctx.focusedIndex === -1) return\n dom.getFocusedInputEl(ctx)?.focus({ preventScroll: true })\n },\n selectInputIfNeeded(ctx) {\n if (!ctx.selectOnFocus || ctx.focusedIndex === -1) return\n raf(() => {\n dom.getFocusedInputEl(ctx)?.select()\n })\n },\n invokeOnComplete(ctx) {\n if (!ctx.isValueComplete) return\n ctx.onValueComplete?.({\n value: Array.from(ctx.value),\n valueAsString: ctx.valueAsString,\n })\n },\n invokeOnInvalid(ctx, evt) {\n ctx.onValueInvalid?.({\n value: evt.value,\n index: ctx.focusedIndex,\n })\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 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\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.split(\"\")[nextValue.length - 1]\n}\n\nconst invoke = {\n change(ctx: MachineContext) {\n // callback\n ctx.onValueChange?.({\n value: Array.from(ctx.value),\n valueAsString: ctx.valueAsString,\n })\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, value: string[]) {\n if (isEqual(ctx.value, value)) return\n assignValue(ctx, value)\n invoke.change(ctx)\n },\n valueAtIndex(ctx: MachineContext, index: number, value: string) {\n if (isEqual(ctx.value[index], value)) return\n ctx.value[index] = value\n invoke.change(ctx)\n },\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAEvB,IAAM,UAAU,cAAc,UAAU,EAAE,MAAM,QAAQ,SAAS,SAAS,SAAS;AACnF,IAAM,QAAQ,QAAQ,MAAM;;;ACHnC,SAAS,aAAa,gBAAgB,uBAAyC;AAC/E,SAAS,UAAU,UAAU,2BAA2B;AAExD,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;;;ACJpC,SAAS,aAAa,gBAAgB;AAG/B,IAAM,MAAM,YAAY;AAAA,EAC7B,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ACzE,MAAI,QAAQ,CAACC,QAAO,UAAU;AAC5B,QAAI,MAAM,KAAK,IAAIA;AAAA,EACrB,CAAC;AACH;AAEA,SAAS,aAAa,SAAiB,MAAc;AACnD,MAAI,YAAY;AAChB,MAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAG,gBAAY,KAAK,CAAC;AAAA,WACrC,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAG,gBAAY,KAAK,CAAC;AACnD,SAAO,UAAU,MAAM,EAAE,EAAE,UAAU,SAAS,CAAC;AACjD;AAEA,IAAM,SAAS;AAAA,EACb,OAAO,KAAqB;AAE1B,QAAI,gBAAgB;AAAA,MAClB,OAAO,MAAM,KAAK,IAAI,KAAK;AAAA,MAC3B,eAAe,IAAI;AAAA,IACrB,CAAC;AAGD,UAAM,UAAU,IAAI,iBAAiB,GAAG;AACxC,4BAAwB,SAAS,EAAE,OAAO,IAAI,cAAc,CAAC;AAAA,EAC/D;AACF;AAEA,IAAM,MAAM;AAAA,EACV,MAAM,KAAqB,OAAiB;AAC1C,QAAI,QAAQ,IAAI,OAAO,KAAK;AAAG;AAC/B,gBAAY,KAAK,KAAK;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAAA,EACA,aAAa,KAAqB,OAAe,OAAe;AAC9D,QAAI,QAAQ,IAAI,MAAM,KAAK,GAAG,KAAK;AAAG;AACtC,QAAI,MAAM,KAAK,IAAI;AACnB,WAAO,OAAO,GAAG;AAAA,EACnB;AACF;","names":["ctx","value"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/pin-input",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Core logic for the pin-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,14 +27,14 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "0.22.0",
31
- "@zag-js/dom-query": "0.22.0",
32
- "@zag-js/dom-event": "0.22.0",
33
- "@zag-js/form-utils": "0.22.0",
34
- "@zag-js/visually-hidden": "0.22.0",
35
- "@zag-js/utils": "0.22.0",
36
- "@zag-js/core": "0.22.0",
37
- "@zag-js/types": "0.22.0"
30
+ "@zag-js/anatomy": "0.24.0",
31
+ "@zag-js/dom-query": "0.24.0",
32
+ "@zag-js/dom-event": "0.24.0",
33
+ "@zag-js/form-utils": "0.24.0",
34
+ "@zag-js/visually-hidden": "0.24.0",
35
+ "@zag-js/utils": "0.24.0",
36
+ "@zag-js/core": "0.24.0",
37
+ "@zag-js/types": "0.24.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "clean-package": "2.2.0"