@zag-js/pin-input 0.2.10 → 0.2.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/dist/{chunk-QVOI2QEW.mjs → chunk-IGE2OJGQ.mjs} +2 -2
- package/dist/{chunk-53K4IC6M.mjs → chunk-VZQYAAIE.mjs} +19 -25
- package/dist/{chunk-T5OKDF74.mjs → chunk-Y7IZ6OAH.mjs} +2 -1
- package/dist/index.js +21 -26
- package/dist/index.mjs +3 -3
- package/dist/pin-input.connect.js +3 -2
- package/dist/pin-input.connect.mjs +2 -2
- package/dist/pin-input.dom.d.ts +2 -1
- package/dist/pin-input.dom.js +2 -1
- package/dist/pin-input.dom.mjs +1 -1
- package/dist/pin-input.machine.js +20 -25
- package/dist/pin-input.machine.mjs +2 -2
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-BJXKBZJG.mjs";
|
|
4
4
|
import {
|
|
5
5
|
dom
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Y7IZ6OAH.mjs";
|
|
7
7
|
|
|
8
8
|
// ../../utilities/dom/src/attrs.ts
|
|
9
9
|
var dataAttr = (guard) => {
|
|
@@ -159,7 +159,7 @@ function connect(state, send, normalize) {
|
|
|
159
159
|
send("BACKSPACE");
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
|
-
send({ type: "INPUT", value });
|
|
162
|
+
send({ type: "INPUT", value, index });
|
|
163
163
|
},
|
|
164
164
|
onKeyDown(event) {
|
|
165
165
|
const evt = getNativeEvent(event);
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
dom,
|
|
6
6
|
getWindow
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-Y7IZ6OAH.mjs";
|
|
8
8
|
|
|
9
9
|
// src/pin-input.machine.ts
|
|
10
10
|
import { createMachine, guards } from "@zag-js/core";
|
|
@@ -54,7 +54,7 @@ function machine(userContext) {
|
|
|
54
54
|
initial: ctx.autoFocus ? "focused" : "idle",
|
|
55
55
|
context: {
|
|
56
56
|
value: [],
|
|
57
|
-
focusedIndex:
|
|
57
|
+
focusedIndex: -1,
|
|
58
58
|
placeholder: "\u25CB",
|
|
59
59
|
otp: false,
|
|
60
60
|
type: "numeric",
|
|
@@ -73,10 +73,10 @@ function machine(userContext) {
|
|
|
73
73
|
},
|
|
74
74
|
watch: {
|
|
75
75
|
focusedIndex: ["focusInput", "setInputSelection"],
|
|
76
|
-
value: ["dispatchInputEvent"],
|
|
76
|
+
value: ["dispatchInputEvent", "syncInputElements"],
|
|
77
77
|
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
78
78
|
},
|
|
79
|
-
entry: ["setupValue"],
|
|
79
|
+
entry: ctx.autoFocus ? ["setupValue", "setFocusIndexToFirst"] : ["setupValue"],
|
|
80
80
|
on: {
|
|
81
81
|
SET_VALUE: [
|
|
82
82
|
{
|
|
@@ -187,14 +187,14 @@ function machine(userContext) {
|
|
|
187
187
|
raf(() => {
|
|
188
188
|
if (ctx2.focusedIndex === -1)
|
|
189
189
|
return;
|
|
190
|
-
dom.
|
|
190
|
+
dom.getFocusedInputEl(ctx2)?.focus();
|
|
191
191
|
});
|
|
192
192
|
},
|
|
193
193
|
setInputSelection: (ctx2) => {
|
|
194
194
|
raf(() => {
|
|
195
195
|
if (ctx2.focusedIndex === -1)
|
|
196
196
|
return;
|
|
197
|
-
const input = dom.
|
|
197
|
+
const input = dom.getFocusedInputEl(ctx2);
|
|
198
198
|
const length = input.value.length;
|
|
199
199
|
input.selectionStart = ctx2.selectOnFocus ? 0 : length;
|
|
200
200
|
input.selectionEnd = length;
|
|
@@ -205,20 +205,11 @@ function machine(userContext) {
|
|
|
205
205
|
return;
|
|
206
206
|
ctx2.onComplete?.({ value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
207
207
|
},
|
|
208
|
-
invokeOnChange: (ctx2
|
|
209
|
-
if (evt.type === "SETUP")
|
|
210
|
-
return;
|
|
208
|
+
invokeOnChange: (ctx2) => {
|
|
211
209
|
ctx2.onChange?.({ value: Array.from(ctx2.value) });
|
|
212
210
|
},
|
|
213
|
-
dispatchInputEvent: (ctx2
|
|
214
|
-
if (evt.type === "SETUP")
|
|
215
|
-
return;
|
|
211
|
+
dispatchInputEvent: (ctx2) => {
|
|
216
212
|
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
217
|
-
const inputs = dom.getElements(ctx2);
|
|
218
|
-
ctx2.value.forEach((val, index) => {
|
|
219
|
-
const input = inputs[index];
|
|
220
|
-
input.value = val || "";
|
|
221
|
-
});
|
|
222
213
|
},
|
|
223
214
|
invokeOnInvalid: (ctx2, evt) => {
|
|
224
215
|
ctx2.onInvalid?.({ value: evt.value, index: ctx2.focusedIndex });
|
|
@@ -235,14 +226,17 @@ function machine(userContext) {
|
|
|
235
226
|
setFocusedValue: (ctx2, evt) => {
|
|
236
227
|
ctx2.value[ctx2.focusedIndex] = getNextValue(ctx2.focusedValue, evt.value);
|
|
237
228
|
},
|
|
238
|
-
syncInputValue
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
if (evt.value.length <= 1 || changed)
|
|
229
|
+
syncInputValue(ctx2, evt) {
|
|
230
|
+
const input = dom.getInputEl(ctx2, evt.index.toString());
|
|
231
|
+
if (!input)
|
|
242
232
|
return;
|
|
233
|
+
input.value = ctx2.value[evt.index];
|
|
234
|
+
},
|
|
235
|
+
syncInputElements(ctx2) {
|
|
243
236
|
const inputs = dom.getElements(ctx2);
|
|
244
|
-
|
|
245
|
-
|
|
237
|
+
inputs.forEach((input, index) => {
|
|
238
|
+
input.value = ctx2.value[index];
|
|
239
|
+
});
|
|
246
240
|
},
|
|
247
241
|
setPastedValue(ctx2, evt) {
|
|
248
242
|
raf(() => {
|
|
@@ -262,7 +256,7 @@ function machine(userContext) {
|
|
|
262
256
|
ctx2.value[ctx2.focusedIndex] = "";
|
|
263
257
|
},
|
|
264
258
|
resetFocusedValue: (ctx2) => {
|
|
265
|
-
const input = dom.
|
|
259
|
+
const input = dom.getFocusedInputEl(ctx2);
|
|
266
260
|
input.value = ctx2.focusedValue;
|
|
267
261
|
},
|
|
268
262
|
setFocusIndexToFirst: (ctx2) => {
|
|
@@ -286,7 +280,7 @@ function machine(userContext) {
|
|
|
286
280
|
if (!ctx2.blurOnComplete)
|
|
287
281
|
return;
|
|
288
282
|
raf(() => {
|
|
289
|
-
dom.
|
|
283
|
+
dom.getFocusedInputEl(ctx2)?.blur();
|
|
290
284
|
});
|
|
291
285
|
},
|
|
292
286
|
requestFormSubmit(ctx2) {
|
|
@@ -47,7 +47,8 @@ var dom = defineDomHelpers({
|
|
|
47
47
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
48
48
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
51
|
+
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
51
52
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
52
53
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
53
54
|
});
|
package/dist/index.js
CHANGED
|
@@ -163,7 +163,8 @@ var dom = defineDomHelpers({
|
|
|
163
163
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
164
164
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
165
165
|
},
|
|
166
|
-
|
|
166
|
+
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
167
|
+
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
167
168
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
168
169
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
169
170
|
});
|
|
@@ -260,7 +261,7 @@ function connect(state, send, normalize) {
|
|
|
260
261
|
send("BACKSPACE");
|
|
261
262
|
return;
|
|
262
263
|
}
|
|
263
|
-
send({ type: "INPUT", value });
|
|
264
|
+
send({ type: "INPUT", value, index });
|
|
264
265
|
},
|
|
265
266
|
onKeyDown(event) {
|
|
266
267
|
const evt = getNativeEvent(event);
|
|
@@ -336,7 +337,7 @@ function machine(userContext) {
|
|
|
336
337
|
initial: ctx.autoFocus ? "focused" : "idle",
|
|
337
338
|
context: {
|
|
338
339
|
value: [],
|
|
339
|
-
focusedIndex:
|
|
340
|
+
focusedIndex: -1,
|
|
340
341
|
placeholder: "\u25CB",
|
|
341
342
|
otp: false,
|
|
342
343
|
type: "numeric",
|
|
@@ -355,10 +356,10 @@ function machine(userContext) {
|
|
|
355
356
|
},
|
|
356
357
|
watch: {
|
|
357
358
|
focusedIndex: ["focusInput", "setInputSelection"],
|
|
358
|
-
value: ["dispatchInputEvent"],
|
|
359
|
+
value: ["dispatchInputEvent", "syncInputElements"],
|
|
359
360
|
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
360
361
|
},
|
|
361
|
-
entry: ["setupValue"],
|
|
362
|
+
entry: ctx.autoFocus ? ["setupValue", "setFocusIndexToFirst"] : ["setupValue"],
|
|
362
363
|
on: {
|
|
363
364
|
SET_VALUE: [
|
|
364
365
|
{
|
|
@@ -469,14 +470,14 @@ function machine(userContext) {
|
|
|
469
470
|
raf(() => {
|
|
470
471
|
if (ctx2.focusedIndex === -1)
|
|
471
472
|
return;
|
|
472
|
-
dom.
|
|
473
|
+
dom.getFocusedInputEl(ctx2)?.focus();
|
|
473
474
|
});
|
|
474
475
|
},
|
|
475
476
|
setInputSelection: (ctx2) => {
|
|
476
477
|
raf(() => {
|
|
477
478
|
if (ctx2.focusedIndex === -1)
|
|
478
479
|
return;
|
|
479
|
-
const input = dom.
|
|
480
|
+
const input = dom.getFocusedInputEl(ctx2);
|
|
480
481
|
const length = input.value.length;
|
|
481
482
|
input.selectionStart = ctx2.selectOnFocus ? 0 : length;
|
|
482
483
|
input.selectionEnd = length;
|
|
@@ -487,20 +488,11 @@ function machine(userContext) {
|
|
|
487
488
|
return;
|
|
488
489
|
ctx2.onComplete?.({ value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
489
490
|
},
|
|
490
|
-
invokeOnChange: (ctx2
|
|
491
|
-
if (evt.type === "SETUP")
|
|
492
|
-
return;
|
|
491
|
+
invokeOnChange: (ctx2) => {
|
|
493
492
|
ctx2.onChange?.({ value: Array.from(ctx2.value) });
|
|
494
493
|
},
|
|
495
|
-
dispatchInputEvent: (ctx2
|
|
496
|
-
if (evt.type === "SETUP")
|
|
497
|
-
return;
|
|
494
|
+
dispatchInputEvent: (ctx2) => {
|
|
498
495
|
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
499
|
-
const inputs = dom.getElements(ctx2);
|
|
500
|
-
ctx2.value.forEach((val, index) => {
|
|
501
|
-
const input = inputs[index];
|
|
502
|
-
input.value = val || "";
|
|
503
|
-
});
|
|
504
496
|
},
|
|
505
497
|
invokeOnInvalid: (ctx2, evt) => {
|
|
506
498
|
ctx2.onInvalid?.({ value: evt.value, index: ctx2.focusedIndex });
|
|
@@ -517,14 +509,17 @@ function machine(userContext) {
|
|
|
517
509
|
setFocusedValue: (ctx2, evt) => {
|
|
518
510
|
ctx2.value[ctx2.focusedIndex] = getNextValue(ctx2.focusedValue, evt.value);
|
|
519
511
|
},
|
|
520
|
-
syncInputValue
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
if (evt.value.length <= 1 || changed)
|
|
512
|
+
syncInputValue(ctx2, evt) {
|
|
513
|
+
const input = dom.getInputEl(ctx2, evt.index.toString());
|
|
514
|
+
if (!input)
|
|
524
515
|
return;
|
|
516
|
+
input.value = ctx2.value[evt.index];
|
|
517
|
+
},
|
|
518
|
+
syncInputElements(ctx2) {
|
|
525
519
|
const inputs = dom.getElements(ctx2);
|
|
526
|
-
|
|
527
|
-
|
|
520
|
+
inputs.forEach((input, index) => {
|
|
521
|
+
input.value = ctx2.value[index];
|
|
522
|
+
});
|
|
528
523
|
},
|
|
529
524
|
setPastedValue(ctx2, evt) {
|
|
530
525
|
raf(() => {
|
|
@@ -544,7 +539,7 @@ function machine(userContext) {
|
|
|
544
539
|
ctx2.value[ctx2.focusedIndex] = "";
|
|
545
540
|
},
|
|
546
541
|
resetFocusedValue: (ctx2) => {
|
|
547
|
-
const input = dom.
|
|
542
|
+
const input = dom.getFocusedInputEl(ctx2);
|
|
548
543
|
input.value = ctx2.focusedValue;
|
|
549
544
|
},
|
|
550
545
|
setFocusIndexToFirst: (ctx2) => {
|
|
@@ -568,7 +563,7 @@ function machine(userContext) {
|
|
|
568
563
|
if (!ctx2.blurOnComplete)
|
|
569
564
|
return;
|
|
570
565
|
raf(() => {
|
|
571
|
-
dom.
|
|
566
|
+
dom.getFocusedInputEl(ctx2)?.blur();
|
|
572
567
|
});
|
|
573
568
|
},
|
|
574
569
|
requestFormSubmit(ctx2) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IGE2OJGQ.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-BJXKBZJG.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VZQYAAIE.mjs";
|
|
10
10
|
import "./chunk-NT4W6JYX.mjs";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-Y7IZ6OAH.mjs";
|
|
12
12
|
export {
|
|
13
13
|
anatomy,
|
|
14
14
|
connect,
|
|
@@ -137,7 +137,8 @@ var dom = defineDomHelpers({
|
|
|
137
137
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
138
138
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
139
139
|
},
|
|
140
|
-
|
|
140
|
+
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
141
|
+
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
141
142
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
142
143
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
143
144
|
});
|
|
@@ -234,7 +235,7 @@ function connect(state, send, normalize) {
|
|
|
234
235
|
send("BACKSPACE");
|
|
235
236
|
return;
|
|
236
237
|
}
|
|
237
|
-
send({ type: "INPUT", value });
|
|
238
|
+
send({ type: "INPUT", value, index });
|
|
238
239
|
},
|
|
239
240
|
onKeyDown(event) {
|
|
240
241
|
const evt = getNativeEvent(event);
|
package/dist/pin-input.dom.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ declare const dom: {
|
|
|
26
26
|
getControlId: (ctx: MachineContext) => string;
|
|
27
27
|
getRootEl: (ctx: MachineContext) => HTMLElement | null;
|
|
28
28
|
getElements: (ctx: MachineContext) => HTMLInputElement[];
|
|
29
|
-
|
|
29
|
+
getInputEl: (ctx: MachineContext, id: string) => HTMLInputElement | null;
|
|
30
|
+
getFocusedInputEl: (ctx: MachineContext) => HTMLInputElement;
|
|
30
31
|
getFirstInputEl: (ctx: MachineContext) => HTMLInputElement;
|
|
31
32
|
getHiddenInputEl: (ctx: MachineContext) => HTMLInputElement | null;
|
|
32
33
|
};
|
package/dist/pin-input.dom.js
CHANGED
|
@@ -70,7 +70,8 @@ var dom = defineDomHelpers({
|
|
|
70
70
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
71
71
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
72
72
|
},
|
|
73
|
-
|
|
73
|
+
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
74
|
+
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
74
75
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
75
76
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
76
77
|
});
|
package/dist/pin-input.dom.mjs
CHANGED
|
@@ -113,7 +113,8 @@ var dom = defineDomHelpers({
|
|
|
113
113
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
114
114
|
return queryAll(dom.getRootEl(ctx), selector);
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
117
|
+
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
117
118
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
118
119
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
119
120
|
});
|
|
@@ -128,7 +129,7 @@ function machine(userContext) {
|
|
|
128
129
|
initial: ctx.autoFocus ? "focused" : "idle",
|
|
129
130
|
context: {
|
|
130
131
|
value: [],
|
|
131
|
-
focusedIndex:
|
|
132
|
+
focusedIndex: -1,
|
|
132
133
|
placeholder: "\u25CB",
|
|
133
134
|
otp: false,
|
|
134
135
|
type: "numeric",
|
|
@@ -147,10 +148,10 @@ function machine(userContext) {
|
|
|
147
148
|
},
|
|
148
149
|
watch: {
|
|
149
150
|
focusedIndex: ["focusInput", "setInputSelection"],
|
|
150
|
-
value: ["dispatchInputEvent"],
|
|
151
|
+
value: ["dispatchInputEvent", "syncInputElements"],
|
|
151
152
|
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
152
153
|
},
|
|
153
|
-
entry: ["setupValue"],
|
|
154
|
+
entry: ctx.autoFocus ? ["setupValue", "setFocusIndexToFirst"] : ["setupValue"],
|
|
154
155
|
on: {
|
|
155
156
|
SET_VALUE: [
|
|
156
157
|
{
|
|
@@ -261,14 +262,14 @@ function machine(userContext) {
|
|
|
261
262
|
raf(() => {
|
|
262
263
|
if (ctx2.focusedIndex === -1)
|
|
263
264
|
return;
|
|
264
|
-
dom.
|
|
265
|
+
dom.getFocusedInputEl(ctx2)?.focus();
|
|
265
266
|
});
|
|
266
267
|
},
|
|
267
268
|
setInputSelection: (ctx2) => {
|
|
268
269
|
raf(() => {
|
|
269
270
|
if (ctx2.focusedIndex === -1)
|
|
270
271
|
return;
|
|
271
|
-
const input = dom.
|
|
272
|
+
const input = dom.getFocusedInputEl(ctx2);
|
|
272
273
|
const length = input.value.length;
|
|
273
274
|
input.selectionStart = ctx2.selectOnFocus ? 0 : length;
|
|
274
275
|
input.selectionEnd = length;
|
|
@@ -279,20 +280,11 @@ function machine(userContext) {
|
|
|
279
280
|
return;
|
|
280
281
|
ctx2.onComplete?.({ value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
281
282
|
},
|
|
282
|
-
invokeOnChange: (ctx2
|
|
283
|
-
if (evt.type === "SETUP")
|
|
284
|
-
return;
|
|
283
|
+
invokeOnChange: (ctx2) => {
|
|
285
284
|
ctx2.onChange?.({ value: Array.from(ctx2.value) });
|
|
286
285
|
},
|
|
287
|
-
dispatchInputEvent: (ctx2
|
|
288
|
-
if (evt.type === "SETUP")
|
|
289
|
-
return;
|
|
286
|
+
dispatchInputEvent: (ctx2) => {
|
|
290
287
|
dispatchInputValueEvent(dom.getHiddenInputEl(ctx2), ctx2.valueAsString);
|
|
291
|
-
const inputs = dom.getElements(ctx2);
|
|
292
|
-
ctx2.value.forEach((val, index) => {
|
|
293
|
-
const input = inputs[index];
|
|
294
|
-
input.value = val || "";
|
|
295
|
-
});
|
|
296
288
|
},
|
|
297
289
|
invokeOnInvalid: (ctx2, evt) => {
|
|
298
290
|
ctx2.onInvalid?.({ value: evt.value, index: ctx2.focusedIndex });
|
|
@@ -309,14 +301,17 @@ function machine(userContext) {
|
|
|
309
301
|
setFocusedValue: (ctx2, evt) => {
|
|
310
302
|
ctx2.value[ctx2.focusedIndex] = getNextValue(ctx2.focusedValue, evt.value);
|
|
311
303
|
},
|
|
312
|
-
syncInputValue
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
if (evt.value.length <= 1 || changed)
|
|
304
|
+
syncInputValue(ctx2, evt) {
|
|
305
|
+
const input = dom.getInputEl(ctx2, evt.index.toString());
|
|
306
|
+
if (!input)
|
|
316
307
|
return;
|
|
308
|
+
input.value = ctx2.value[evt.index];
|
|
309
|
+
},
|
|
310
|
+
syncInputElements(ctx2) {
|
|
317
311
|
const inputs = dom.getElements(ctx2);
|
|
318
|
-
|
|
319
|
-
|
|
312
|
+
inputs.forEach((input, index) => {
|
|
313
|
+
input.value = ctx2.value[index];
|
|
314
|
+
});
|
|
320
315
|
},
|
|
321
316
|
setPastedValue(ctx2, evt) {
|
|
322
317
|
raf(() => {
|
|
@@ -336,7 +331,7 @@ function machine(userContext) {
|
|
|
336
331
|
ctx2.value[ctx2.focusedIndex] = "";
|
|
337
332
|
},
|
|
338
333
|
resetFocusedValue: (ctx2) => {
|
|
339
|
-
const input = dom.
|
|
334
|
+
const input = dom.getFocusedInputEl(ctx2);
|
|
340
335
|
input.value = ctx2.focusedValue;
|
|
341
336
|
},
|
|
342
337
|
setFocusIndexToFirst: (ctx2) => {
|
|
@@ -360,7 +355,7 @@ function machine(userContext) {
|
|
|
360
355
|
if (!ctx2.blurOnComplete)
|
|
361
356
|
return;
|
|
362
357
|
raf(() => {
|
|
363
|
-
dom.
|
|
358
|
+
dom.getFocusedInputEl(ctx2)?.blur();
|
|
364
359
|
});
|
|
365
360
|
},
|
|
366
361
|
requestFormSubmit(ctx2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/pin-input",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Core logic for the pin-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@zag-js/anatomy": "0.1.4",
|
|
30
|
-
"@zag-js/core": "0.2.
|
|
30
|
+
"@zag-js/core": "0.2.9",
|
|
31
31
|
"@zag-js/types": "0.3.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|