@zag-js/pin-input 1.34.1 → 1.35.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 +8 -199
- package/dist/index.d.ts +8 -199
- package/dist/index.js +35 -545
- package/dist/index.mjs +9 -542
- package/dist/pin-input.anatomy.d.mts +6 -0
- package/dist/pin-input.anatomy.d.ts +6 -0
- package/dist/pin-input.anatomy.js +34 -0
- package/dist/pin-input.anatomy.mjs +8 -0
- package/dist/pin-input.connect.d.mts +7 -0
- package/dist/pin-input.connect.d.ts +7 -0
- package/dist/pin-input.connect.js +235 -0
- package/dist/pin-input.connect.mjs +210 -0
- package/dist/pin-input.dom.d.mts +16 -0
- package/dist/pin-input.dom.d.ts +16 -0
- package/dist/pin-input.dom.js +71 -0
- package/dist/pin-input.dom.mjs +35 -0
- package/dist/pin-input.machine.d.mts +7 -0
- package/dist/pin-input.machine.d.ts +7 -0
- package/dist/pin-input.machine.js +320 -0
- package/dist/pin-input.machine.mjs +285 -0
- package/dist/pin-input.props.d.mts +8 -0
- package/dist/pin-input.props.d.ts +8 -0
- package/dist/pin-input.props.js +61 -0
- package/dist/pin-input.props.mjs +35 -0
- package/dist/pin-input.types.d.mts +188 -0
- package/dist/pin-input.types.d.ts +188 -0
- package/dist/pin-input.types.js +18 -0
- package/dist/pin-input.types.mjs +0 -0
- package/dist/pin-input.utils.d.mts +10 -0
- package/dist/pin-input.utils.d.ts +10 -0
- package/dist/pin-input.utils.js +45 -0
- package/dist/pin-input.utils.mjs +19 -0
- package/package.json +17 -7
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/pin-input.connect.ts
|
|
31
|
+
var pin_input_connect_exports = {};
|
|
32
|
+
__export(pin_input_connect_exports, {
|
|
33
|
+
connect: () => connect
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(pin_input_connect_exports);
|
|
36
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
37
|
+
var import_utils = require("@zag-js/utils");
|
|
38
|
+
var import_pin_input = require("./pin-input.anatomy.cjs");
|
|
39
|
+
var dom = __toESM(require("./pin-input.dom.cjs"));
|
|
40
|
+
var import_pin_input2 = require("./pin-input.utils.cjs");
|
|
41
|
+
function connect(service, normalize) {
|
|
42
|
+
const { send, context, computed, prop, scope } = service;
|
|
43
|
+
const complete = computed("isValueComplete");
|
|
44
|
+
const disabled = !!prop("disabled");
|
|
45
|
+
const readOnly = !!prop("readOnly");
|
|
46
|
+
const invalid = !!prop("invalid");
|
|
47
|
+
const required = !!prop("required");
|
|
48
|
+
const translations = prop("translations");
|
|
49
|
+
const focusedIndex = context.get("focusedIndex");
|
|
50
|
+
function focus() {
|
|
51
|
+
dom.getFirstInputEl(scope)?.focus();
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
focus,
|
|
55
|
+
count: context.get("count"),
|
|
56
|
+
items: Array.from({ length: context.get("count") }).map((_, i) => i),
|
|
57
|
+
value: context.get("value"),
|
|
58
|
+
valueAsString: computed("valueAsString"),
|
|
59
|
+
complete,
|
|
60
|
+
setValue(value) {
|
|
61
|
+
if (!Array.isArray(value)) {
|
|
62
|
+
(0, import_utils.invariant)("[pin-input/setValue] value must be an array");
|
|
63
|
+
}
|
|
64
|
+
send({ type: "VALUE.SET", value });
|
|
65
|
+
},
|
|
66
|
+
clearValue() {
|
|
67
|
+
send({ type: "VALUE.CLEAR" });
|
|
68
|
+
},
|
|
69
|
+
setValueAtIndex(index, value) {
|
|
70
|
+
send({ type: "VALUE.SET", value, index });
|
|
71
|
+
},
|
|
72
|
+
getRootProps() {
|
|
73
|
+
return normalize.element({
|
|
74
|
+
dir: prop("dir"),
|
|
75
|
+
...import_pin_input.parts.root.attrs,
|
|
76
|
+
id: dom.getRootId(scope),
|
|
77
|
+
"data-invalid": (0, import_dom_query.dataAttr)(invalid),
|
|
78
|
+
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
79
|
+
"data-complete": (0, import_dom_query.dataAttr)(complete),
|
|
80
|
+
"data-readonly": (0, import_dom_query.dataAttr)(readOnly)
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
getLabelProps() {
|
|
84
|
+
return normalize.label({
|
|
85
|
+
...import_pin_input.parts.label.attrs,
|
|
86
|
+
dir: prop("dir"),
|
|
87
|
+
htmlFor: dom.getHiddenInputId(scope),
|
|
88
|
+
id: dom.getLabelId(scope),
|
|
89
|
+
"data-invalid": (0, import_dom_query.dataAttr)(invalid),
|
|
90
|
+
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
91
|
+
"data-complete": (0, import_dom_query.dataAttr)(complete),
|
|
92
|
+
"data-required": (0, import_dom_query.dataAttr)(required),
|
|
93
|
+
"data-readonly": (0, import_dom_query.dataAttr)(readOnly),
|
|
94
|
+
onClick(event) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
focus();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
getHiddenInputProps() {
|
|
101
|
+
return normalize.input({
|
|
102
|
+
"aria-hidden": true,
|
|
103
|
+
type: "text",
|
|
104
|
+
tabIndex: -1,
|
|
105
|
+
id: dom.getHiddenInputId(scope),
|
|
106
|
+
readOnly,
|
|
107
|
+
disabled,
|
|
108
|
+
required,
|
|
109
|
+
name: prop("name"),
|
|
110
|
+
form: prop("form"),
|
|
111
|
+
style: import_dom_query.visuallyHiddenStyle,
|
|
112
|
+
maxLength: computed("valueLength"),
|
|
113
|
+
defaultValue: computed("valueAsString")
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
getControlProps() {
|
|
117
|
+
return normalize.element({
|
|
118
|
+
...import_pin_input.parts.control.attrs,
|
|
119
|
+
dir: prop("dir"),
|
|
120
|
+
id: dom.getControlId(scope)
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
getInputProps(props) {
|
|
124
|
+
const { index } = props;
|
|
125
|
+
const inputType = prop("type") === "numeric" ? "tel" : "text";
|
|
126
|
+
return normalize.input({
|
|
127
|
+
...import_pin_input.parts.input.attrs,
|
|
128
|
+
dir: prop("dir"),
|
|
129
|
+
disabled,
|
|
130
|
+
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
131
|
+
"data-complete": (0, import_dom_query.dataAttr)(complete),
|
|
132
|
+
id: dom.getInputId(scope, index.toString()),
|
|
133
|
+
"data-index": index,
|
|
134
|
+
"data-ownedby": dom.getRootId(scope),
|
|
135
|
+
"aria-label": translations?.inputLabel?.(index, computed("valueLength")),
|
|
136
|
+
inputMode: prop("otp") || prop("type") === "numeric" ? "numeric" : "text",
|
|
137
|
+
"aria-invalid": (0, import_dom_query.ariaAttr)(invalid),
|
|
138
|
+
"data-invalid": (0, import_dom_query.dataAttr)(invalid),
|
|
139
|
+
type: prop("mask") ? "password" : inputType,
|
|
140
|
+
defaultValue: context.get("value")[index] || "",
|
|
141
|
+
readOnly,
|
|
142
|
+
autoCapitalize: "none",
|
|
143
|
+
autoComplete: prop("otp") ? "one-time-code" : "off",
|
|
144
|
+
placeholder: focusedIndex === index ? "" : prop("placeholder"),
|
|
145
|
+
onPaste(event) {
|
|
146
|
+
const pastedValue = event.clipboardData?.getData("text/plain");
|
|
147
|
+
if (!pastedValue) return;
|
|
148
|
+
const isValid = (0, import_pin_input2.isValidValue)(pastedValue, prop("type"), prop("pattern"));
|
|
149
|
+
if (!isValid) {
|
|
150
|
+
send({ type: "VALUE.INVALID", value: pastedValue });
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
send({ type: "INPUT.PASTE", value: pastedValue });
|
|
156
|
+
},
|
|
157
|
+
onBeforeInput(event) {
|
|
158
|
+
try {
|
|
159
|
+
const value = (0, import_dom_query.getBeforeInputValue)(event);
|
|
160
|
+
const isValid = (0, import_pin_input2.isValidValue)(value, prop("type"), prop("pattern"));
|
|
161
|
+
if (!isValid) {
|
|
162
|
+
send({ type: "VALUE.INVALID", value });
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
}
|
|
165
|
+
if (value.length > 1) {
|
|
166
|
+
event.currentTarget.setSelectionRange(0, 1, "forward");
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
onChange(event) {
|
|
172
|
+
const evt = (0, import_dom_query.getNativeEvent)(event);
|
|
173
|
+
const { value } = event.currentTarget;
|
|
174
|
+
if (evt.inputType === "insertFromPaste") {
|
|
175
|
+
event.currentTarget.value = value[0] || "";
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (value.length > 2) {
|
|
179
|
+
send({ type: "INPUT.PASTE", value });
|
|
180
|
+
event.currentTarget.value = value[0];
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (evt.inputType === "deleteContentBackward") {
|
|
185
|
+
send({ type: "INPUT.BACKSPACE" });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
send({ type: "INPUT.CHANGE", value, index });
|
|
189
|
+
},
|
|
190
|
+
onKeyDown(event) {
|
|
191
|
+
if (event.defaultPrevented) return;
|
|
192
|
+
if ((0, import_dom_query.isComposingEvent)(event)) return;
|
|
193
|
+
if ((0, import_dom_query.isModifierKey)(event)) return;
|
|
194
|
+
const keyMap = {
|
|
195
|
+
Backspace() {
|
|
196
|
+
send({ type: "INPUT.BACKSPACE" });
|
|
197
|
+
},
|
|
198
|
+
Delete() {
|
|
199
|
+
send({ type: "INPUT.DELETE" });
|
|
200
|
+
},
|
|
201
|
+
ArrowLeft() {
|
|
202
|
+
send({ type: "INPUT.ARROW_LEFT" });
|
|
203
|
+
},
|
|
204
|
+
ArrowRight() {
|
|
205
|
+
send({ type: "INPUT.ARROW_RIGHT" });
|
|
206
|
+
},
|
|
207
|
+
Enter() {
|
|
208
|
+
send({ type: "INPUT.ENTER" });
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const exec = keyMap[(0, import_dom_query.getEventKey)(event, {
|
|
212
|
+
dir: prop("dir"),
|
|
213
|
+
orientation: "horizontal"
|
|
214
|
+
})];
|
|
215
|
+
if (exec) {
|
|
216
|
+
exec(event);
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
onFocus() {
|
|
221
|
+
send({ type: "INPUT.FOCUS", index });
|
|
222
|
+
},
|
|
223
|
+
onBlur(event) {
|
|
224
|
+
const target = event.relatedTarget;
|
|
225
|
+
if ((0, import_dom_query.isHTMLElement)(target) && target.dataset.ownedby === dom.getRootId(scope)) return;
|
|
226
|
+
send({ type: "INPUT.BLUR", index });
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
+
0 && (module.exports = {
|
|
234
|
+
connect
|
|
235
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// src/pin-input.connect.ts
|
|
2
|
+
import {
|
|
3
|
+
ariaAttr,
|
|
4
|
+
dataAttr,
|
|
5
|
+
getBeforeInputValue,
|
|
6
|
+
getEventKey,
|
|
7
|
+
getNativeEvent,
|
|
8
|
+
isComposingEvent,
|
|
9
|
+
isHTMLElement,
|
|
10
|
+
isModifierKey,
|
|
11
|
+
visuallyHiddenStyle
|
|
12
|
+
} from "@zag-js/dom-query";
|
|
13
|
+
import { invariant } from "@zag-js/utils";
|
|
14
|
+
import { parts } from "./pin-input.anatomy.mjs";
|
|
15
|
+
import * as dom from "./pin-input.dom.mjs";
|
|
16
|
+
import { isValidValue } from "./pin-input.utils.mjs";
|
|
17
|
+
function connect(service, normalize) {
|
|
18
|
+
const { send, context, computed, prop, scope } = service;
|
|
19
|
+
const complete = computed("isValueComplete");
|
|
20
|
+
const disabled = !!prop("disabled");
|
|
21
|
+
const readOnly = !!prop("readOnly");
|
|
22
|
+
const invalid = !!prop("invalid");
|
|
23
|
+
const required = !!prop("required");
|
|
24
|
+
const translations = prop("translations");
|
|
25
|
+
const focusedIndex = context.get("focusedIndex");
|
|
26
|
+
function focus() {
|
|
27
|
+
dom.getFirstInputEl(scope)?.focus();
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
focus,
|
|
31
|
+
count: context.get("count"),
|
|
32
|
+
items: Array.from({ length: context.get("count") }).map((_, i) => i),
|
|
33
|
+
value: context.get("value"),
|
|
34
|
+
valueAsString: computed("valueAsString"),
|
|
35
|
+
complete,
|
|
36
|
+
setValue(value) {
|
|
37
|
+
if (!Array.isArray(value)) {
|
|
38
|
+
invariant("[pin-input/setValue] value must be an array");
|
|
39
|
+
}
|
|
40
|
+
send({ type: "VALUE.SET", value });
|
|
41
|
+
},
|
|
42
|
+
clearValue() {
|
|
43
|
+
send({ type: "VALUE.CLEAR" });
|
|
44
|
+
},
|
|
45
|
+
setValueAtIndex(index, value) {
|
|
46
|
+
send({ type: "VALUE.SET", value, index });
|
|
47
|
+
},
|
|
48
|
+
getRootProps() {
|
|
49
|
+
return normalize.element({
|
|
50
|
+
dir: prop("dir"),
|
|
51
|
+
...parts.root.attrs,
|
|
52
|
+
id: dom.getRootId(scope),
|
|
53
|
+
"data-invalid": dataAttr(invalid),
|
|
54
|
+
"data-disabled": dataAttr(disabled),
|
|
55
|
+
"data-complete": dataAttr(complete),
|
|
56
|
+
"data-readonly": dataAttr(readOnly)
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
getLabelProps() {
|
|
60
|
+
return normalize.label({
|
|
61
|
+
...parts.label.attrs,
|
|
62
|
+
dir: prop("dir"),
|
|
63
|
+
htmlFor: dom.getHiddenInputId(scope),
|
|
64
|
+
id: dom.getLabelId(scope),
|
|
65
|
+
"data-invalid": dataAttr(invalid),
|
|
66
|
+
"data-disabled": dataAttr(disabled),
|
|
67
|
+
"data-complete": dataAttr(complete),
|
|
68
|
+
"data-required": dataAttr(required),
|
|
69
|
+
"data-readonly": dataAttr(readOnly),
|
|
70
|
+
onClick(event) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
focus();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
getHiddenInputProps() {
|
|
77
|
+
return normalize.input({
|
|
78
|
+
"aria-hidden": true,
|
|
79
|
+
type: "text",
|
|
80
|
+
tabIndex: -1,
|
|
81
|
+
id: dom.getHiddenInputId(scope),
|
|
82
|
+
readOnly,
|
|
83
|
+
disabled,
|
|
84
|
+
required,
|
|
85
|
+
name: prop("name"),
|
|
86
|
+
form: prop("form"),
|
|
87
|
+
style: visuallyHiddenStyle,
|
|
88
|
+
maxLength: computed("valueLength"),
|
|
89
|
+
defaultValue: computed("valueAsString")
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
getControlProps() {
|
|
93
|
+
return normalize.element({
|
|
94
|
+
...parts.control.attrs,
|
|
95
|
+
dir: prop("dir"),
|
|
96
|
+
id: dom.getControlId(scope)
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
getInputProps(props) {
|
|
100
|
+
const { index } = props;
|
|
101
|
+
const inputType = prop("type") === "numeric" ? "tel" : "text";
|
|
102
|
+
return normalize.input({
|
|
103
|
+
...parts.input.attrs,
|
|
104
|
+
dir: prop("dir"),
|
|
105
|
+
disabled,
|
|
106
|
+
"data-disabled": dataAttr(disabled),
|
|
107
|
+
"data-complete": dataAttr(complete),
|
|
108
|
+
id: dom.getInputId(scope, index.toString()),
|
|
109
|
+
"data-index": index,
|
|
110
|
+
"data-ownedby": dom.getRootId(scope),
|
|
111
|
+
"aria-label": translations?.inputLabel?.(index, computed("valueLength")),
|
|
112
|
+
inputMode: prop("otp") || prop("type") === "numeric" ? "numeric" : "text",
|
|
113
|
+
"aria-invalid": ariaAttr(invalid),
|
|
114
|
+
"data-invalid": dataAttr(invalid),
|
|
115
|
+
type: prop("mask") ? "password" : inputType,
|
|
116
|
+
defaultValue: context.get("value")[index] || "",
|
|
117
|
+
readOnly,
|
|
118
|
+
autoCapitalize: "none",
|
|
119
|
+
autoComplete: prop("otp") ? "one-time-code" : "off",
|
|
120
|
+
placeholder: focusedIndex === index ? "" : prop("placeholder"),
|
|
121
|
+
onPaste(event) {
|
|
122
|
+
const pastedValue = event.clipboardData?.getData("text/plain");
|
|
123
|
+
if (!pastedValue) return;
|
|
124
|
+
const isValid = isValidValue(pastedValue, prop("type"), prop("pattern"));
|
|
125
|
+
if (!isValid) {
|
|
126
|
+
send({ type: "VALUE.INVALID", value: pastedValue });
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
send({ type: "INPUT.PASTE", value: pastedValue });
|
|
132
|
+
},
|
|
133
|
+
onBeforeInput(event) {
|
|
134
|
+
try {
|
|
135
|
+
const value = getBeforeInputValue(event);
|
|
136
|
+
const isValid = isValidValue(value, prop("type"), prop("pattern"));
|
|
137
|
+
if (!isValid) {
|
|
138
|
+
send({ type: "VALUE.INVALID", value });
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
}
|
|
141
|
+
if (value.length > 1) {
|
|
142
|
+
event.currentTarget.setSelectionRange(0, 1, "forward");
|
|
143
|
+
}
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
onChange(event) {
|
|
148
|
+
const evt = getNativeEvent(event);
|
|
149
|
+
const { value } = event.currentTarget;
|
|
150
|
+
if (evt.inputType === "insertFromPaste") {
|
|
151
|
+
event.currentTarget.value = value[0] || "";
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (value.length > 2) {
|
|
155
|
+
send({ type: "INPUT.PASTE", value });
|
|
156
|
+
event.currentTarget.value = value[0];
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (evt.inputType === "deleteContentBackward") {
|
|
161
|
+
send({ type: "INPUT.BACKSPACE" });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
send({ type: "INPUT.CHANGE", value, index });
|
|
165
|
+
},
|
|
166
|
+
onKeyDown(event) {
|
|
167
|
+
if (event.defaultPrevented) return;
|
|
168
|
+
if (isComposingEvent(event)) return;
|
|
169
|
+
if (isModifierKey(event)) return;
|
|
170
|
+
const keyMap = {
|
|
171
|
+
Backspace() {
|
|
172
|
+
send({ type: "INPUT.BACKSPACE" });
|
|
173
|
+
},
|
|
174
|
+
Delete() {
|
|
175
|
+
send({ type: "INPUT.DELETE" });
|
|
176
|
+
},
|
|
177
|
+
ArrowLeft() {
|
|
178
|
+
send({ type: "INPUT.ARROW_LEFT" });
|
|
179
|
+
},
|
|
180
|
+
ArrowRight() {
|
|
181
|
+
send({ type: "INPUT.ARROW_RIGHT" });
|
|
182
|
+
},
|
|
183
|
+
Enter() {
|
|
184
|
+
send({ type: "INPUT.ENTER" });
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const exec = keyMap[getEventKey(event, {
|
|
188
|
+
dir: prop("dir"),
|
|
189
|
+
orientation: "horizontal"
|
|
190
|
+
})];
|
|
191
|
+
if (exec) {
|
|
192
|
+
exec(event);
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
onFocus() {
|
|
197
|
+
send({ type: "INPUT.FOCUS", index });
|
|
198
|
+
},
|
|
199
|
+
onBlur(event) {
|
|
200
|
+
const target = event.relatedTarget;
|
|
201
|
+
if (isHTMLElement(target) && target.dataset.ownedby === dom.getRootId(scope)) return;
|
|
202
|
+
send({ type: "INPUT.BLUR", index });
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
connect
|
|
210
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getInputId: (ctx: Scope, id: string) => any;
|
|
5
|
+
declare const getHiddenInputId: (ctx: Scope) => any;
|
|
6
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
7
|
+
declare const getControlId: (ctx: Scope) => any;
|
|
8
|
+
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
9
|
+
declare const getInputEls: (ctx: Scope) => HTMLInputElement[];
|
|
10
|
+
declare const getInputEl: (ctx: Scope, id: string) => HTMLInputElement | null;
|
|
11
|
+
declare const getInputElAtIndex: (ctx: Scope, index: number) => HTMLInputElement;
|
|
12
|
+
declare const getFirstInputEl: (ctx: Scope) => HTMLInputElement;
|
|
13
|
+
declare const getHiddenInputEl: (ctx: Scope) => HTMLInputElement | null;
|
|
14
|
+
declare const setInputValue: (inputEl: HTMLInputElement, value: string) => void;
|
|
15
|
+
|
|
16
|
+
export { getControlId, getFirstInputEl, getHiddenInputEl, getHiddenInputId, getInputEl, getInputElAtIndex, getInputEls, getInputId, getLabelId, getRootEl, getRootId, setInputValue };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Scope } from '@zag-js/core';
|
|
2
|
+
|
|
3
|
+
declare const getRootId: (ctx: Scope) => any;
|
|
4
|
+
declare const getInputId: (ctx: Scope, id: string) => any;
|
|
5
|
+
declare const getHiddenInputId: (ctx: Scope) => any;
|
|
6
|
+
declare const getLabelId: (ctx: Scope) => any;
|
|
7
|
+
declare const getControlId: (ctx: Scope) => any;
|
|
8
|
+
declare const getRootEl: (ctx: Scope) => HTMLElement | null;
|
|
9
|
+
declare const getInputEls: (ctx: Scope) => HTMLInputElement[];
|
|
10
|
+
declare const getInputEl: (ctx: Scope, id: string) => HTMLInputElement | null;
|
|
11
|
+
declare const getInputElAtIndex: (ctx: Scope, index: number) => HTMLInputElement;
|
|
12
|
+
declare const getFirstInputEl: (ctx: Scope) => HTMLInputElement;
|
|
13
|
+
declare const getHiddenInputEl: (ctx: Scope) => HTMLInputElement | null;
|
|
14
|
+
declare const setInputValue: (inputEl: HTMLInputElement, value: string) => void;
|
|
15
|
+
|
|
16
|
+
export { getControlId, getFirstInputEl, getHiddenInputEl, getHiddenInputId, getInputEl, getInputElAtIndex, getInputEls, getInputId, getLabelId, getRootEl, getRootId, setInputValue };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/pin-input.dom.ts
|
|
21
|
+
var pin_input_dom_exports = {};
|
|
22
|
+
__export(pin_input_dom_exports, {
|
|
23
|
+
getControlId: () => getControlId,
|
|
24
|
+
getFirstInputEl: () => getFirstInputEl,
|
|
25
|
+
getHiddenInputEl: () => getHiddenInputEl,
|
|
26
|
+
getHiddenInputId: () => getHiddenInputId,
|
|
27
|
+
getInputEl: () => getInputEl,
|
|
28
|
+
getInputElAtIndex: () => getInputElAtIndex,
|
|
29
|
+
getInputEls: () => getInputEls,
|
|
30
|
+
getInputId: () => getInputId,
|
|
31
|
+
getLabelId: () => getLabelId,
|
|
32
|
+
getRootEl: () => getRootEl,
|
|
33
|
+
getRootId: () => getRootId,
|
|
34
|
+
setInputValue: () => setInputValue
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(pin_input_dom_exports);
|
|
37
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
38
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`;
|
|
39
|
+
var getInputId = (ctx, id) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`;
|
|
40
|
+
var getHiddenInputId = (ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`;
|
|
41
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`;
|
|
42
|
+
var getControlId = (ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`;
|
|
43
|
+
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
44
|
+
var getInputEls = (ctx) => {
|
|
45
|
+
const ownerId = CSS.escape(getRootId(ctx));
|
|
46
|
+
const selector = `input[data-ownedby=${ownerId}]`;
|
|
47
|
+
return (0, import_dom_query.queryAll)(getRootEl(ctx), selector);
|
|
48
|
+
};
|
|
49
|
+
var getInputEl = (ctx, id) => ctx.getById(getInputId(ctx, id));
|
|
50
|
+
var getInputElAtIndex = (ctx, index) => getInputEls(ctx)[index];
|
|
51
|
+
var getFirstInputEl = (ctx) => getInputEls(ctx)[0];
|
|
52
|
+
var getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
53
|
+
var setInputValue = (inputEl, value) => {
|
|
54
|
+
inputEl.value = value;
|
|
55
|
+
inputEl.setAttribute("value", value);
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
getControlId,
|
|
60
|
+
getFirstInputEl,
|
|
61
|
+
getHiddenInputEl,
|
|
62
|
+
getHiddenInputId,
|
|
63
|
+
getInputEl,
|
|
64
|
+
getInputElAtIndex,
|
|
65
|
+
getInputEls,
|
|
66
|
+
getInputId,
|
|
67
|
+
getLabelId,
|
|
68
|
+
getRootEl,
|
|
69
|
+
getRootId,
|
|
70
|
+
setInputValue
|
|
71
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/pin-input.dom.ts
|
|
2
|
+
import { queryAll } from "@zag-js/dom-query";
|
|
3
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`;
|
|
4
|
+
var getInputId = (ctx, id) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`;
|
|
5
|
+
var getHiddenInputId = (ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`;
|
|
6
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`;
|
|
7
|
+
var getControlId = (ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`;
|
|
8
|
+
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
9
|
+
var getInputEls = (ctx) => {
|
|
10
|
+
const ownerId = CSS.escape(getRootId(ctx));
|
|
11
|
+
const selector = `input[data-ownedby=${ownerId}]`;
|
|
12
|
+
return queryAll(getRootEl(ctx), selector);
|
|
13
|
+
};
|
|
14
|
+
var getInputEl = (ctx, id) => ctx.getById(getInputId(ctx, id));
|
|
15
|
+
var getInputElAtIndex = (ctx, index) => getInputEls(ctx)[index];
|
|
16
|
+
var getFirstInputEl = (ctx) => getInputEls(ctx)[0];
|
|
17
|
+
var getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
18
|
+
var setInputValue = (inputEl, value) => {
|
|
19
|
+
inputEl.value = value;
|
|
20
|
+
inputEl.setAttribute("value", value);
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
getControlId,
|
|
24
|
+
getFirstInputEl,
|
|
25
|
+
getHiddenInputEl,
|
|
26
|
+
getHiddenInputId,
|
|
27
|
+
getInputEl,
|
|
28
|
+
getInputElAtIndex,
|
|
29
|
+
getInputEls,
|
|
30
|
+
getInputId,
|
|
31
|
+
getLabelId,
|
|
32
|
+
getRootEl,
|
|
33
|
+
getRootId,
|
|
34
|
+
setInputValue
|
|
35
|
+
};
|