@zag-js/pin-input 0.10.2 → 0.10.4
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.ts +4 -7
- package/dist/index.js +8 -498
- package/dist/index.mjs +3 -15
- package/dist/pin-input.anatomy.d.ts +3 -6
- package/dist/pin-input.anatomy.js +10 -33
- package/dist/pin-input.anatomy.mjs +6 -8
- package/dist/pin-input.connect.d.ts +3 -7
- package/dist/pin-input.connect.js +39 -86
- package/dist/pin-input.connect.mjs +165 -8
- package/dist/pin-input.dom.d.ts +13 -18
- package/dist/pin-input.dom.js +9 -31
- package/dist/pin-input.dom.mjs +21 -6
- package/dist/pin-input.machine.d.ts +3 -7
- package/dist/pin-input.machine.js +29 -72
- package/dist/pin-input.machine.mjs +282 -6
- package/dist/pin-input.types.d.ts +8 -10
- package/package.json +10 -15
- package/dist/chunk-BJXKBZJG.mjs +0 -9
- package/dist/chunk-CPXMEVTH.mjs +0 -23
- package/dist/chunk-KLVAQVBX.mjs +0 -172
- package/dist/chunk-RXPBAYJD.mjs +0 -288
- package/dist/pin-input.types.js +0 -18
- package/dist/pin-input.types.mjs +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export { anatomy } from
|
|
2
|
-
export { connect } from
|
|
3
|
-
export { machine } from
|
|
4
|
-
export { UserDefinedContext as Context } from
|
|
5
|
-
import '@zag-js/anatomy';
|
|
6
|
-
import '@zag-js/types';
|
|
7
|
-
import '@zag-js/core';
|
|
1
|
+
export { anatomy } from "./pin-input.anatomy";
|
|
2
|
+
export { connect } from "./pin-input.connect";
|
|
3
|
+
export { machine } from "./pin-input.machine";
|
|
4
|
+
export type { UserDefinedContext as Context } from "./pin-input.types";
|
package/dist/index.js
CHANGED
|
@@ -1,503 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
anatomy: () => anatomy,
|
|
24
|
-
connect: () => connect,
|
|
25
|
-
machine: () => machine
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var parts = anatomy.build();
|
|
5
|
+
const pinInput_anatomy = require('./pin-input.anatomy.js');
|
|
6
|
+
const pinInput_connect = require('./pin-input.connect.js');
|
|
7
|
+
const pinInput_machine = require('./pin-input.machine.js');
|
|
33
8
|
|
|
34
|
-
// src/pin-input.connect.ts
|
|
35
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
36
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
37
|
-
var import_utils = require("@zag-js/utils");
|
|
38
|
-
var import_visually_hidden = require("@zag-js/visually-hidden");
|
|
39
9
|
|
|
40
|
-
// src/pin-input.dom.ts
|
|
41
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
42
|
-
var dom = (0, import_dom_query.createScope)({
|
|
43
|
-
getRootId: (ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`,
|
|
44
|
-
getInputId: (ctx, id) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`,
|
|
45
|
-
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`,
|
|
46
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`,
|
|
47
|
-
getControlId: (ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`,
|
|
48
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
49
|
-
getElements: (ctx) => {
|
|
50
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
51
|
-
const selector = `input[data-ownedby=${ownerId}]`;
|
|
52
|
-
return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), selector);
|
|
53
|
-
},
|
|
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],
|
|
57
|
-
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
58
|
-
});
|
|
59
10
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const isInvalid = state.context.invalid;
|
|
64
|
-
const focusedIndex = state.context.focusedIndex;
|
|
65
|
-
const translations = state.context.translations;
|
|
66
|
-
function focus() {
|
|
67
|
-
dom.getFirstInputEl(state.context)?.focus();
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
/**
|
|
71
|
-
* The value of the input as an array of strings.
|
|
72
|
-
*/
|
|
73
|
-
value: state.context.value,
|
|
74
|
-
/**
|
|
75
|
-
* The value of the input as a string.
|
|
76
|
-
*/
|
|
77
|
-
valueAsString: state.context.valueAsString,
|
|
78
|
-
/**
|
|
79
|
-
* Whether all inputs are filled.
|
|
80
|
-
*/
|
|
81
|
-
isValueComplete,
|
|
82
|
-
/**
|
|
83
|
-
* Function to set the value of the inputs.
|
|
84
|
-
*/
|
|
85
|
-
setValue(value) {
|
|
86
|
-
if (!Array.isArray(value)) {
|
|
87
|
-
(0, import_utils.invariant)("[pin-input/setValue] value must be an array");
|
|
88
|
-
}
|
|
89
|
-
send({ type: "SET_VALUE", value });
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* Function to clear the value of the inputs.
|
|
93
|
-
*/
|
|
94
|
-
clearValue() {
|
|
95
|
-
send({ type: "CLEAR_VALUE" });
|
|
96
|
-
},
|
|
97
|
-
/**
|
|
98
|
-
* Function to set the value of the input at a specific index.
|
|
99
|
-
*/
|
|
100
|
-
setValueAtIndex(index, value) {
|
|
101
|
-
send({ type: "SET_VALUE", value, index });
|
|
102
|
-
},
|
|
103
|
-
/**
|
|
104
|
-
* Function to focus the pin-input. This will focus the first input.
|
|
105
|
-
*/
|
|
106
|
-
focus,
|
|
107
|
-
rootProps: normalize.element({
|
|
108
|
-
dir: state.context.dir,
|
|
109
|
-
...parts.root.attrs,
|
|
110
|
-
id: dom.getRootId(state.context),
|
|
111
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
112
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(state.context.disabled),
|
|
113
|
-
"data-complete": (0, import_dom_query2.dataAttr)(isValueComplete)
|
|
114
|
-
}),
|
|
115
|
-
labelProps: normalize.label({
|
|
116
|
-
...parts.label.attrs,
|
|
117
|
-
htmlFor: dom.getHiddenInputId(state.context),
|
|
118
|
-
id: dom.getLabelId(state.context),
|
|
119
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
120
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(state.context.disabled),
|
|
121
|
-
"data-complete": (0, import_dom_query2.dataAttr)(isValueComplete),
|
|
122
|
-
onClick: (event) => {
|
|
123
|
-
event.preventDefault();
|
|
124
|
-
focus();
|
|
125
|
-
}
|
|
126
|
-
}),
|
|
127
|
-
hiddenInputProps: normalize.input({
|
|
128
|
-
...parts.hiddenInput.attrs,
|
|
129
|
-
"aria-hidden": true,
|
|
130
|
-
type: "text",
|
|
131
|
-
tabIndex: -1,
|
|
132
|
-
id: dom.getHiddenInputId(state.context),
|
|
133
|
-
name: state.context.name,
|
|
134
|
-
form: state.context.form,
|
|
135
|
-
style: import_visually_hidden.visuallyHiddenStyle,
|
|
136
|
-
maxLength: state.context.valueLength,
|
|
137
|
-
defaultValue: state.context.valueAsString
|
|
138
|
-
}),
|
|
139
|
-
controlProps: normalize.element({
|
|
140
|
-
...parts.control.attrs,
|
|
141
|
-
id: dom.getControlId(state.context)
|
|
142
|
-
}),
|
|
143
|
-
getInputProps({ index }) {
|
|
144
|
-
const inputType = state.context.type === "numeric" ? "tel" : "text";
|
|
145
|
-
return normalize.input({
|
|
146
|
-
...parts.input.attrs,
|
|
147
|
-
disabled: state.context.disabled,
|
|
148
|
-
"data-disabled": (0, import_dom_query2.dataAttr)(state.context.disabled),
|
|
149
|
-
"data-complete": (0, import_dom_query2.dataAttr)(isValueComplete),
|
|
150
|
-
id: dom.getInputId(state.context, index.toString()),
|
|
151
|
-
"data-ownedby": dom.getRootId(state.context),
|
|
152
|
-
"aria-label": translations.inputLabel(index, state.context.valueLength),
|
|
153
|
-
inputMode: state.context.otp || state.context.type === "numeric" ? "numeric" : "text",
|
|
154
|
-
"aria-invalid": (0, import_dom_query2.ariaAttr)(isInvalid),
|
|
155
|
-
"data-invalid": (0, import_dom_query2.dataAttr)(isInvalid),
|
|
156
|
-
type: state.context.mask ? "password" : inputType,
|
|
157
|
-
defaultValue: state.context.value[index] || "",
|
|
158
|
-
autoCapitalize: "none",
|
|
159
|
-
autoComplete: state.context.otp ? "one-time-code" : "off",
|
|
160
|
-
placeholder: focusedIndex === index ? "" : state.context.placeholder,
|
|
161
|
-
onChange(event) {
|
|
162
|
-
const evt = (0, import_dom_event.getNativeEvent)(event);
|
|
163
|
-
const { value } = event.currentTarget;
|
|
164
|
-
if (evt.inputType === "insertFromPaste" || value.length > 2) {
|
|
165
|
-
send({ type: "PASTE", value });
|
|
166
|
-
event.preventDefault();
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (evt.inputType === "deleteContentBackward") {
|
|
170
|
-
send("BACKSPACE");
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
send({ type: "INPUT", value, index });
|
|
174
|
-
},
|
|
175
|
-
onKeyDown(event) {
|
|
176
|
-
const evt = (0, import_dom_event.getNativeEvent)(event);
|
|
177
|
-
if (evt.isComposing || (0, import_dom_event.isModifiedEvent)(evt))
|
|
178
|
-
return;
|
|
179
|
-
const keyMap = {
|
|
180
|
-
Backspace() {
|
|
181
|
-
send("BACKSPACE");
|
|
182
|
-
},
|
|
183
|
-
Delete() {
|
|
184
|
-
send("DELETE");
|
|
185
|
-
},
|
|
186
|
-
ArrowLeft() {
|
|
187
|
-
send("ARROW_LEFT");
|
|
188
|
-
},
|
|
189
|
-
ArrowRight() {
|
|
190
|
-
send("ARROW_RIGHT");
|
|
191
|
-
},
|
|
192
|
-
Enter() {
|
|
193
|
-
send("ENTER");
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const key = (0, import_dom_event.getEventKey)(event, { dir: state.context.dir });
|
|
197
|
-
const exec = keyMap[key];
|
|
198
|
-
if (exec) {
|
|
199
|
-
exec(event);
|
|
200
|
-
event.preventDefault();
|
|
201
|
-
} else {
|
|
202
|
-
if (key === "Tab")
|
|
203
|
-
return;
|
|
204
|
-
send({ type: "KEY_DOWN", value: key, preventDefault: () => event.preventDefault() });
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
onFocus() {
|
|
208
|
-
send({ type: "FOCUS", index });
|
|
209
|
-
},
|
|
210
|
-
onBlur() {
|
|
211
|
-
send({ type: "BLUR", index });
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/pin-input.machine.ts
|
|
219
|
-
var import_core = require("@zag-js/core");
|
|
220
|
-
var import_dom_query3 = require("@zag-js/dom-query");
|
|
221
|
-
var import_form_utils = require("@zag-js/form-utils");
|
|
222
|
-
var import_utils2 = require("@zag-js/utils");
|
|
223
|
-
var { and, not } = import_core.guards;
|
|
224
|
-
function machine(userContext) {
|
|
225
|
-
const ctx = (0, import_utils2.compact)(userContext);
|
|
226
|
-
return (0, import_core.createMachine)(
|
|
227
|
-
{
|
|
228
|
-
id: "pin-input",
|
|
229
|
-
initial: ctx.autoFocus ? "focused" : "idle",
|
|
230
|
-
context: {
|
|
231
|
-
value: [],
|
|
232
|
-
focusedIndex: -1,
|
|
233
|
-
placeholder: "\u25CB",
|
|
234
|
-
otp: false,
|
|
235
|
-
type: "numeric",
|
|
236
|
-
...ctx,
|
|
237
|
-
translations: {
|
|
238
|
-
inputLabel: (index, length) => `pin code ${index + 1} of ${length}`,
|
|
239
|
-
...ctx.translations
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
computed: {
|
|
243
|
-
valueLength: (ctx2) => ctx2.value.length,
|
|
244
|
-
filledValueLength: (ctx2) => ctx2.value.filter((v) => v?.trim() !== "").length,
|
|
245
|
-
isValueComplete: (ctx2) => ctx2.valueLength === ctx2.filledValueLength,
|
|
246
|
-
valueAsString: (ctx2) => ctx2.value.join(""),
|
|
247
|
-
focusedValue: (ctx2) => ctx2.value[ctx2.focusedIndex]
|
|
248
|
-
},
|
|
249
|
-
watch: {
|
|
250
|
-
focusedIndex: ["focusInput", "setInputSelection"],
|
|
251
|
-
value: ["dispatchInputEvent", "syncInputElements"],
|
|
252
|
-
isValueComplete: ["invokeOnComplete", "blurFocusedInputIfNeeded"]
|
|
253
|
-
},
|
|
254
|
-
entry: ctx.autoFocus ? ["setupValue", "setFocusIndexToFirst"] : ["setupValue"],
|
|
255
|
-
on: {
|
|
256
|
-
SET_VALUE: [
|
|
257
|
-
{
|
|
258
|
-
guard: "hasIndex",
|
|
259
|
-
actions: ["setValueAtIndex", "invokeOnChange"]
|
|
260
|
-
},
|
|
261
|
-
{ actions: ["setValue", "invokeOnChange"] }
|
|
262
|
-
],
|
|
263
|
-
CLEAR_VALUE: [
|
|
264
|
-
{
|
|
265
|
-
guard: "isDisabled",
|
|
266
|
-
actions: ["clearValue", "invokeOnChange"]
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
actions: ["clearValue", "invokeOnChange", "setFocusIndexToFirst"]
|
|
270
|
-
}
|
|
271
|
-
]
|
|
272
|
-
},
|
|
273
|
-
states: {
|
|
274
|
-
idle: {
|
|
275
|
-
on: {
|
|
276
|
-
FOCUS: {
|
|
277
|
-
target: "focused",
|
|
278
|
-
actions: "setFocusedIndex"
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
focused: {
|
|
283
|
-
on: {
|
|
284
|
-
INPUT: [
|
|
285
|
-
{
|
|
286
|
-
guard: and("isFinalValue", "isValidValue"),
|
|
287
|
-
actions: ["setFocusedValue", "invokeOnChange", "syncInputValue"]
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
guard: "isValidValue",
|
|
291
|
-
actions: ["setFocusedValue", "invokeOnChange", "setNextFocusedIndex", "syncInputValue"]
|
|
292
|
-
}
|
|
293
|
-
],
|
|
294
|
-
PASTE: [
|
|
295
|
-
{
|
|
296
|
-
guard: "isValidValue",
|
|
297
|
-
actions: ["setPastedValue", "invokeOnChange", "setLastValueFocusIndex"]
|
|
298
|
-
},
|
|
299
|
-
{ actions: ["resetFocusedValue", "invokeOnChange"] }
|
|
300
|
-
],
|
|
301
|
-
BLUR: {
|
|
302
|
-
target: "idle",
|
|
303
|
-
actions: "clearFocusedIndex"
|
|
304
|
-
},
|
|
305
|
-
DELETE: {
|
|
306
|
-
guard: "hasValue",
|
|
307
|
-
actions: ["clearFocusedValue", "invokeOnChange"]
|
|
308
|
-
},
|
|
309
|
-
ARROW_LEFT: {
|
|
310
|
-
actions: "setPrevFocusedIndex"
|
|
311
|
-
},
|
|
312
|
-
ARROW_RIGHT: {
|
|
313
|
-
actions: "setNextFocusedIndex"
|
|
314
|
-
},
|
|
315
|
-
BACKSPACE: [
|
|
316
|
-
{
|
|
317
|
-
guard: "hasValue",
|
|
318
|
-
actions: ["clearFocusedValue", "invokeOnChange"]
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
actions: ["setPrevFocusedIndex", "clearFocusedValue", "invokeOnChange"]
|
|
322
|
-
}
|
|
323
|
-
],
|
|
324
|
-
ENTER: {
|
|
325
|
-
guard: "isValueComplete",
|
|
326
|
-
actions: "requestFormSubmit"
|
|
327
|
-
},
|
|
328
|
-
KEY_DOWN: {
|
|
329
|
-
guard: not("isValidValue"),
|
|
330
|
-
actions: ["preventDefault", "invokeOnInvalid"]
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
guards: {
|
|
338
|
-
autoFocus: (ctx2) => !!ctx2.autoFocus,
|
|
339
|
-
isValueEmpty: (_ctx, evt) => evt.value === "",
|
|
340
|
-
hasValue: (ctx2) => ctx2.value[ctx2.focusedIndex] !== "",
|
|
341
|
-
isValueComplete: (ctx2) => ctx2.isValueComplete,
|
|
342
|
-
isValidValue: (ctx2, evt) => {
|
|
343
|
-
if (!ctx2.pattern)
|
|
344
|
-
return isValidType(evt.value, ctx2.type);
|
|
345
|
-
const regex = new RegExp(ctx2.pattern, "g");
|
|
346
|
-
return regex.test(evt.value);
|
|
347
|
-
},
|
|
348
|
-
isFinalValue: (ctx2) => {
|
|
349
|
-
return ctx2.filledValueLength + 1 === ctx2.valueLength && ctx2.value.findIndex((v) => v.trim() === "") === ctx2.focusedIndex;
|
|
350
|
-
},
|
|
351
|
-
isLastInputFocused: (ctx2) => ctx2.focusedIndex === ctx2.valueLength - 1,
|
|
352
|
-
hasIndex: (_ctx, evt) => evt.index !== void 0,
|
|
353
|
-
isDisabled: (ctx2) => !!ctx2.disabled
|
|
354
|
-
},
|
|
355
|
-
actions: {
|
|
356
|
-
setupValue: (ctx2) => {
|
|
357
|
-
if (ctx2.value.length)
|
|
358
|
-
return;
|
|
359
|
-
const inputs = dom.getElements(ctx2);
|
|
360
|
-
const emptyValues = Array.from({ length: inputs.length }).fill("");
|
|
361
|
-
assign(ctx2, emptyValues);
|
|
362
|
-
},
|
|
363
|
-
focusInput: (ctx2) => {
|
|
364
|
-
(0, import_dom_query3.raf)(() => {
|
|
365
|
-
if (ctx2.focusedIndex === -1)
|
|
366
|
-
return;
|
|
367
|
-
dom.getFocusedInputEl(ctx2)?.focus();
|
|
368
|
-
});
|
|
369
|
-
},
|
|
370
|
-
setInputSelection: (ctx2) => {
|
|
371
|
-
(0, import_dom_query3.raf)(() => {
|
|
372
|
-
if (ctx2.focusedIndex === -1)
|
|
373
|
-
return;
|
|
374
|
-
const input = dom.getFocusedInputEl(ctx2);
|
|
375
|
-
const length = input.value.length;
|
|
376
|
-
input.selectionStart = ctx2.selectOnFocus ? 0 : length;
|
|
377
|
-
input.selectionEnd = length;
|
|
378
|
-
});
|
|
379
|
-
},
|
|
380
|
-
invokeOnComplete: (ctx2) => {
|
|
381
|
-
if (!ctx2.isValueComplete)
|
|
382
|
-
return;
|
|
383
|
-
ctx2.onComplete?.({ value: Array.from(ctx2.value), valueAsString: ctx2.valueAsString });
|
|
384
|
-
},
|
|
385
|
-
invokeOnChange: (ctx2) => {
|
|
386
|
-
ctx2.onChange?.({ value: Array.from(ctx2.value) });
|
|
387
|
-
},
|
|
388
|
-
dispatchInputEvent: (ctx2) => {
|
|
389
|
-
const inputEl = dom.getHiddenInputEl(ctx2);
|
|
390
|
-
(0, import_form_utils.dispatchInputValueEvent)(inputEl, { value: ctx2.valueAsString });
|
|
391
|
-
},
|
|
392
|
-
invokeOnInvalid: (ctx2, evt) => {
|
|
393
|
-
ctx2.onInvalid?.({ value: evt.value, index: ctx2.focusedIndex });
|
|
394
|
-
},
|
|
395
|
-
clearFocusedIndex: (ctx2) => {
|
|
396
|
-
ctx2.focusedIndex = -1;
|
|
397
|
-
},
|
|
398
|
-
setValue: (ctx2, evt) => {
|
|
399
|
-
assign(ctx2, evt.value);
|
|
400
|
-
},
|
|
401
|
-
setFocusedIndex: (ctx2, evt) => {
|
|
402
|
-
ctx2.focusedIndex = evt.index;
|
|
403
|
-
},
|
|
404
|
-
setFocusedValue: (ctx2, evt) => {
|
|
405
|
-
ctx2.value[ctx2.focusedIndex] = getNextValue(ctx2.focusedValue, evt.value);
|
|
406
|
-
},
|
|
407
|
-
syncInputValue(ctx2, evt) {
|
|
408
|
-
const input = dom.getInputEl(ctx2, evt.index.toString());
|
|
409
|
-
if (!input)
|
|
410
|
-
return;
|
|
411
|
-
input.value = ctx2.value[evt.index];
|
|
412
|
-
},
|
|
413
|
-
syncInputElements(ctx2) {
|
|
414
|
-
const inputs = dom.getElements(ctx2);
|
|
415
|
-
inputs.forEach((input, index) => {
|
|
416
|
-
input.value = ctx2.value[index];
|
|
417
|
-
});
|
|
418
|
-
},
|
|
419
|
-
setPastedValue(ctx2, evt) {
|
|
420
|
-
(0, import_dom_query3.raf)(() => {
|
|
421
|
-
const startIndex = ctx2.focusedValue ? 1 : 0;
|
|
422
|
-
const value = evt.value.substring(startIndex, startIndex + ctx2.valueLength);
|
|
423
|
-
assign(ctx2, value);
|
|
424
|
-
});
|
|
425
|
-
},
|
|
426
|
-
setValueAtIndex: (ctx2, evt) => {
|
|
427
|
-
ctx2.value[evt.index] = getNextValue(ctx2.focusedValue, evt.value);
|
|
428
|
-
},
|
|
429
|
-
clearValue: (ctx2) => {
|
|
430
|
-
const nextValue = Array.from({ length: ctx2.valueLength }).fill("");
|
|
431
|
-
assign(ctx2, nextValue);
|
|
432
|
-
},
|
|
433
|
-
clearFocusedValue: (ctx2) => {
|
|
434
|
-
ctx2.value[ctx2.focusedIndex] = "";
|
|
435
|
-
},
|
|
436
|
-
resetFocusedValue: (ctx2) => {
|
|
437
|
-
const input = dom.getFocusedInputEl(ctx2);
|
|
438
|
-
input.value = ctx2.focusedValue;
|
|
439
|
-
},
|
|
440
|
-
setFocusIndexToFirst: (ctx2) => {
|
|
441
|
-
ctx2.focusedIndex = 0;
|
|
442
|
-
},
|
|
443
|
-
setNextFocusedIndex: (ctx2) => {
|
|
444
|
-
ctx2.focusedIndex = Math.min(ctx2.focusedIndex + 1, ctx2.valueLength - 1);
|
|
445
|
-
},
|
|
446
|
-
setPrevFocusedIndex: (ctx2) => {
|
|
447
|
-
ctx2.focusedIndex = Math.max(ctx2.focusedIndex - 1, 0);
|
|
448
|
-
},
|
|
449
|
-
setLastValueFocusIndex: (ctx2) => {
|
|
450
|
-
(0, import_dom_query3.raf)(() => {
|
|
451
|
-
ctx2.focusedIndex = Math.min(ctx2.filledValueLength, ctx2.valueLength - 1);
|
|
452
|
-
});
|
|
453
|
-
},
|
|
454
|
-
preventDefault(_, evt) {
|
|
455
|
-
evt.preventDefault();
|
|
456
|
-
},
|
|
457
|
-
blurFocusedInputIfNeeded(ctx2) {
|
|
458
|
-
if (!ctx2.blurOnComplete)
|
|
459
|
-
return;
|
|
460
|
-
(0, import_dom_query3.raf)(() => {
|
|
461
|
-
dom.getFocusedInputEl(ctx2)?.blur();
|
|
462
|
-
});
|
|
463
|
-
},
|
|
464
|
-
requestFormSubmit(ctx2) {
|
|
465
|
-
if (!ctx2.name || !ctx2.isValueComplete)
|
|
466
|
-
return;
|
|
467
|
-
const input = dom.getHiddenInputEl(ctx2);
|
|
468
|
-
input?.form?.requestSubmit();
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
var REGEX = {
|
|
475
|
-
numeric: /^[0-9]+$/,
|
|
476
|
-
alphabetic: /^[A-Za-z]+$/,
|
|
477
|
-
alphanumeric: /^[a-zA-Z0-9]+$/i
|
|
478
|
-
};
|
|
479
|
-
function isValidType(value, type) {
|
|
480
|
-
if (!type)
|
|
481
|
-
return true;
|
|
482
|
-
return !!REGEX[type]?.test(value);
|
|
483
|
-
}
|
|
484
|
-
function assign(ctx, value) {
|
|
485
|
-
const arr = Array.isArray(value) ? value : value.split("").filter(Boolean);
|
|
486
|
-
arr.forEach((value2, index) => {
|
|
487
|
-
ctx.value[index] = value2;
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
function getNextValue(current, next) {
|
|
491
|
-
let nextValue = next;
|
|
492
|
-
if (current[0] === next[0])
|
|
493
|
-
nextValue = next[1];
|
|
494
|
-
else if (current[0] === next[1])
|
|
495
|
-
nextValue = next[0];
|
|
496
|
-
return nextValue;
|
|
497
|
-
}
|
|
498
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
499
|
-
0 && (module.exports = {
|
|
500
|
-
anatomy,
|
|
501
|
-
connect,
|
|
502
|
-
machine
|
|
503
|
-
});
|
|
11
|
+
exports.anatomy = pinInput_anatomy.anatomy;
|
|
12
|
+
exports.connect = pinInput_connect.connect;
|
|
13
|
+
exports.machine = pinInput_machine.machine;
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
anatomy
|
|
6
|
-
} from "./chunk-BJXKBZJG.mjs";
|
|
7
|
-
import {
|
|
8
|
-
machine
|
|
9
|
-
} from "./chunk-RXPBAYJD.mjs";
|
|
10
|
-
import "./chunk-CPXMEVTH.mjs";
|
|
11
|
-
export {
|
|
12
|
-
anatomy,
|
|
13
|
-
connect,
|
|
14
|
-
machine
|
|
15
|
-
};
|
|
1
|
+
export { anatomy } from './pin-input.anatomy.mjs';
|
|
2
|
+
export { connect } from './pin-input.connect.mjs';
|
|
3
|
+
export { machine } from './pin-input.machine.mjs';
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
declare const parts: Record<"root" | "label" | "hiddenInput" | "input" | "control", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
-
|
|
6
|
-
export { anatomy, parts };
|
|
1
|
+
import { AnatomyInstance, AnatomyPart } from '@zag-js/anatomy';
|
|
2
|
+
export declare const anatomy: AnatomyInstance<"root" | "label" | "hiddenInput" | "input" | "control">;
|
|
3
|
+
export declare const parts: Record<"root" | "label" | "hiddenInput" | "input" | "control", AnatomyPart>;
|
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var parts = anatomy.build();
|
|
30
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
-
0 && (module.exports = {
|
|
32
|
-
anatomy,
|
|
33
|
-
parts
|
|
34
|
-
});
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const anatomy$1 = require('@zag-js/anatomy');
|
|
6
|
+
|
|
7
|
+
const anatomy = anatomy$1.createAnatomy("pinInput").parts("root", "label", "hiddenInput", "input", "control");
|
|
8
|
+
const parts = anatomy.build();
|
|
9
|
+
|
|
10
|
+
exports.anatomy = anatomy;
|
|
11
|
+
exports.parts = parts;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
parts
|
|
8
|
-
};
|
|
1
|
+
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
const anatomy = createAnatomy("pinInput").parts("root", "label", "hiddenInput", "input", "control");
|
|
4
|
+
const parts = anatomy.build();
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
1
|
+
import type { NormalizeProps, PropTypes } from "@zag-js/types";
|
|
2
|
+
import type { Send, State } from "./pin-input.types";
|
|
3
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
4
|
/**
|
|
7
5
|
* The value of the input as an array of strings.
|
|
8
6
|
*/
|
|
@@ -39,5 +37,3 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
39
37
|
index: number;
|
|
40
38
|
}): T["input"];
|
|
41
39
|
};
|
|
42
|
-
|
|
43
|
-
export { connect };
|