@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
|
@@ -1,66 +1,21 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/pin-input.connect.ts
|
|
21
|
-
var pin_input_connect_exports = {};
|
|
22
|
-
__export(pin_input_connect_exports, {
|
|
23
|
-
connect: () => connect
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(pin_input_connect_exports);
|
|
26
|
-
var import_dom_event = require("@zag-js/dom-event");
|
|
27
|
-
var import_dom_query2 = require("@zag-js/dom-query");
|
|
28
|
-
var import_utils = require("@zag-js/utils");
|
|
29
|
-
var import_visually_hidden = require("@zag-js/visually-hidden");
|
|
1
|
+
'use strict';
|
|
30
2
|
|
|
31
|
-
|
|
32
|
-
var import_anatomy = require("@zag-js/anatomy");
|
|
33
|
-
var anatomy = (0, import_anatomy.createAnatomy)("pinInput").parts("root", "label", "hiddenInput", "input", "control");
|
|
34
|
-
var parts = anatomy.build();
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
35
4
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`,
|
|
43
|
-
getControlId: (ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`,
|
|
44
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
45
|
-
getElements: (ctx) => {
|
|
46
|
-
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
47
|
-
const selector = `input[data-ownedby=${ownerId}]`;
|
|
48
|
-
return (0, import_dom_query.queryAll)(dom.getRootEl(ctx), selector);
|
|
49
|
-
},
|
|
50
|
-
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
51
|
-
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
52
|
-
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
53
|
-
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
54
|
-
});
|
|
5
|
+
const domEvent = require('@zag-js/dom-event');
|
|
6
|
+
const domQuery = require('@zag-js/dom-query');
|
|
7
|
+
const utils = require('@zag-js/utils');
|
|
8
|
+
const visuallyHidden = require('@zag-js/visually-hidden');
|
|
9
|
+
const pinInput_anatomy = require('./pin-input.anatomy.js');
|
|
10
|
+
const pinInput_dom = require('./pin-input.dom.js');
|
|
55
11
|
|
|
56
|
-
// src/pin-input.connect.ts
|
|
57
12
|
function connect(state, send, normalize) {
|
|
58
13
|
const isValueComplete = state.context.isValueComplete;
|
|
59
14
|
const isInvalid = state.context.invalid;
|
|
60
15
|
const focusedIndex = state.context.focusedIndex;
|
|
61
16
|
const translations = state.context.translations;
|
|
62
17
|
function focus() {
|
|
63
|
-
dom.getFirstInputEl(state.context)?.focus();
|
|
18
|
+
pinInput_dom.dom.getFirstInputEl(state.context)?.focus();
|
|
64
19
|
}
|
|
65
20
|
return {
|
|
66
21
|
/**
|
|
@@ -80,7 +35,7 @@ function connect(state, send, normalize) {
|
|
|
80
35
|
*/
|
|
81
36
|
setValue(value) {
|
|
82
37
|
if (!Array.isArray(value)) {
|
|
83
|
-
|
|
38
|
+
utils.invariant("[pin-input/setValue] value must be an array");
|
|
84
39
|
}
|
|
85
40
|
send({ type: "SET_VALUE", value });
|
|
86
41
|
},
|
|
@@ -102,60 +57,60 @@ function connect(state, send, normalize) {
|
|
|
102
57
|
focus,
|
|
103
58
|
rootProps: normalize.element({
|
|
104
59
|
dir: state.context.dir,
|
|
105
|
-
...parts.root.attrs,
|
|
106
|
-
id: dom.getRootId(state.context),
|
|
107
|
-
"data-invalid":
|
|
108
|
-
"data-disabled":
|
|
109
|
-
"data-complete":
|
|
60
|
+
...pinInput_anatomy.parts.root.attrs,
|
|
61
|
+
id: pinInput_dom.dom.getRootId(state.context),
|
|
62
|
+
"data-invalid": domQuery.dataAttr(isInvalid),
|
|
63
|
+
"data-disabled": domQuery.dataAttr(state.context.disabled),
|
|
64
|
+
"data-complete": domQuery.dataAttr(isValueComplete)
|
|
110
65
|
}),
|
|
111
66
|
labelProps: normalize.label({
|
|
112
|
-
...parts.label.attrs,
|
|
113
|
-
htmlFor: dom.getHiddenInputId(state.context),
|
|
114
|
-
id: dom.getLabelId(state.context),
|
|
115
|
-
"data-invalid":
|
|
116
|
-
"data-disabled":
|
|
117
|
-
"data-complete":
|
|
67
|
+
...pinInput_anatomy.parts.label.attrs,
|
|
68
|
+
htmlFor: pinInput_dom.dom.getHiddenInputId(state.context),
|
|
69
|
+
id: pinInput_dom.dom.getLabelId(state.context),
|
|
70
|
+
"data-invalid": domQuery.dataAttr(isInvalid),
|
|
71
|
+
"data-disabled": domQuery.dataAttr(state.context.disabled),
|
|
72
|
+
"data-complete": domQuery.dataAttr(isValueComplete),
|
|
118
73
|
onClick: (event) => {
|
|
119
74
|
event.preventDefault();
|
|
120
75
|
focus();
|
|
121
76
|
}
|
|
122
77
|
}),
|
|
123
78
|
hiddenInputProps: normalize.input({
|
|
124
|
-
...parts.hiddenInput.attrs,
|
|
79
|
+
...pinInput_anatomy.parts.hiddenInput.attrs,
|
|
125
80
|
"aria-hidden": true,
|
|
126
81
|
type: "text",
|
|
127
82
|
tabIndex: -1,
|
|
128
|
-
id: dom.getHiddenInputId(state.context),
|
|
83
|
+
id: pinInput_dom.dom.getHiddenInputId(state.context),
|
|
129
84
|
name: state.context.name,
|
|
130
85
|
form: state.context.form,
|
|
131
|
-
style:
|
|
86
|
+
style: visuallyHidden.visuallyHiddenStyle,
|
|
132
87
|
maxLength: state.context.valueLength,
|
|
133
88
|
defaultValue: state.context.valueAsString
|
|
134
89
|
}),
|
|
135
90
|
controlProps: normalize.element({
|
|
136
|
-
...parts.control.attrs,
|
|
137
|
-
id: dom.getControlId(state.context)
|
|
91
|
+
...pinInput_anatomy.parts.control.attrs,
|
|
92
|
+
id: pinInput_dom.dom.getControlId(state.context)
|
|
138
93
|
}),
|
|
139
94
|
getInputProps({ index }) {
|
|
140
95
|
const inputType = state.context.type === "numeric" ? "tel" : "text";
|
|
141
96
|
return normalize.input({
|
|
142
|
-
...parts.input.attrs,
|
|
97
|
+
...pinInput_anatomy.parts.input.attrs,
|
|
143
98
|
disabled: state.context.disabled,
|
|
144
|
-
"data-disabled":
|
|
145
|
-
"data-complete":
|
|
146
|
-
id: dom.getInputId(state.context, index.toString()),
|
|
147
|
-
"data-ownedby": dom.getRootId(state.context),
|
|
99
|
+
"data-disabled": domQuery.dataAttr(state.context.disabled),
|
|
100
|
+
"data-complete": domQuery.dataAttr(isValueComplete),
|
|
101
|
+
id: pinInput_dom.dom.getInputId(state.context, index.toString()),
|
|
102
|
+
"data-ownedby": pinInput_dom.dom.getRootId(state.context),
|
|
148
103
|
"aria-label": translations.inputLabel(index, state.context.valueLength),
|
|
149
104
|
inputMode: state.context.otp || state.context.type === "numeric" ? "numeric" : "text",
|
|
150
|
-
"aria-invalid":
|
|
151
|
-
"data-invalid":
|
|
105
|
+
"aria-invalid": domQuery.ariaAttr(isInvalid),
|
|
106
|
+
"data-invalid": domQuery.dataAttr(isInvalid),
|
|
152
107
|
type: state.context.mask ? "password" : inputType,
|
|
153
108
|
defaultValue: state.context.value[index] || "",
|
|
154
109
|
autoCapitalize: "none",
|
|
155
110
|
autoComplete: state.context.otp ? "one-time-code" : "off",
|
|
156
111
|
placeholder: focusedIndex === index ? "" : state.context.placeholder,
|
|
157
112
|
onChange(event) {
|
|
158
|
-
const evt =
|
|
113
|
+
const evt = domEvent.getNativeEvent(event);
|
|
159
114
|
const { value } = event.currentTarget;
|
|
160
115
|
if (evt.inputType === "insertFromPaste" || value.length > 2) {
|
|
161
116
|
send({ type: "PASTE", value });
|
|
@@ -169,8 +124,8 @@ function connect(state, send, normalize) {
|
|
|
169
124
|
send({ type: "INPUT", value, index });
|
|
170
125
|
},
|
|
171
126
|
onKeyDown(event) {
|
|
172
|
-
const evt =
|
|
173
|
-
if (evt.isComposing ||
|
|
127
|
+
const evt = domEvent.getNativeEvent(event);
|
|
128
|
+
if (evt.isComposing || domEvent.isModifiedEvent(evt))
|
|
174
129
|
return;
|
|
175
130
|
const keyMap = {
|
|
176
131
|
Backspace() {
|
|
@@ -189,7 +144,7 @@ function connect(state, send, normalize) {
|
|
|
189
144
|
send("ENTER");
|
|
190
145
|
}
|
|
191
146
|
};
|
|
192
|
-
const key =
|
|
147
|
+
const key = domEvent.getEventKey(event, { dir: state.context.dir });
|
|
193
148
|
const exec = keyMap[key];
|
|
194
149
|
if (exec) {
|
|
195
150
|
exec(event);
|
|
@@ -210,7 +165,5 @@ function connect(state, send, normalize) {
|
|
|
210
165
|
}
|
|
211
166
|
};
|
|
212
167
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
connect
|
|
216
|
-
});
|
|
168
|
+
|
|
169
|
+
exports.connect = connect;
|
|
@@ -1,8 +1,165 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getNativeEvent, isModifiedEvent, getEventKey } from '@zag-js/dom-event';
|
|
2
|
+
import { dataAttr, ariaAttr } from '@zag-js/dom-query';
|
|
3
|
+
import { invariant } from '@zag-js/utils';
|
|
4
|
+
import { visuallyHiddenStyle } from '@zag-js/visually-hidden';
|
|
5
|
+
import { parts } from './pin-input.anatomy.mjs';
|
|
6
|
+
import { dom } from './pin-input.dom.mjs';
|
|
7
|
+
|
|
8
|
+
function connect(state, send, normalize) {
|
|
9
|
+
const isValueComplete = state.context.isValueComplete;
|
|
10
|
+
const isInvalid = state.context.invalid;
|
|
11
|
+
const focusedIndex = state.context.focusedIndex;
|
|
12
|
+
const translations = state.context.translations;
|
|
13
|
+
function focus() {
|
|
14
|
+
dom.getFirstInputEl(state.context)?.focus();
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
/**
|
|
18
|
+
* The value of the input as an array of strings.
|
|
19
|
+
*/
|
|
20
|
+
value: state.context.value,
|
|
21
|
+
/**
|
|
22
|
+
* The value of the input as a string.
|
|
23
|
+
*/
|
|
24
|
+
valueAsString: state.context.valueAsString,
|
|
25
|
+
/**
|
|
26
|
+
* Whether all inputs are filled.
|
|
27
|
+
*/
|
|
28
|
+
isValueComplete,
|
|
29
|
+
/**
|
|
30
|
+
* Function to set the value of the inputs.
|
|
31
|
+
*/
|
|
32
|
+
setValue(value) {
|
|
33
|
+
if (!Array.isArray(value)) {
|
|
34
|
+
invariant("[pin-input/setValue] value must be an array");
|
|
35
|
+
}
|
|
36
|
+
send({ type: "SET_VALUE", value });
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Function to clear the value of the inputs.
|
|
40
|
+
*/
|
|
41
|
+
clearValue() {
|
|
42
|
+
send({ type: "CLEAR_VALUE" });
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Function to set the value of the input at a specific index.
|
|
46
|
+
*/
|
|
47
|
+
setValueAtIndex(index, value) {
|
|
48
|
+
send({ type: "SET_VALUE", value, index });
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Function to focus the pin-input. This will focus the first input.
|
|
52
|
+
*/
|
|
53
|
+
focus,
|
|
54
|
+
rootProps: normalize.element({
|
|
55
|
+
dir: state.context.dir,
|
|
56
|
+
...parts.root.attrs,
|
|
57
|
+
id: dom.getRootId(state.context),
|
|
58
|
+
"data-invalid": dataAttr(isInvalid),
|
|
59
|
+
"data-disabled": dataAttr(state.context.disabled),
|
|
60
|
+
"data-complete": dataAttr(isValueComplete)
|
|
61
|
+
}),
|
|
62
|
+
labelProps: normalize.label({
|
|
63
|
+
...parts.label.attrs,
|
|
64
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
65
|
+
id: dom.getLabelId(state.context),
|
|
66
|
+
"data-invalid": dataAttr(isInvalid),
|
|
67
|
+
"data-disabled": dataAttr(state.context.disabled),
|
|
68
|
+
"data-complete": dataAttr(isValueComplete),
|
|
69
|
+
onClick: (event) => {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
focus();
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
hiddenInputProps: normalize.input({
|
|
75
|
+
...parts.hiddenInput.attrs,
|
|
76
|
+
"aria-hidden": true,
|
|
77
|
+
type: "text",
|
|
78
|
+
tabIndex: -1,
|
|
79
|
+
id: dom.getHiddenInputId(state.context),
|
|
80
|
+
name: state.context.name,
|
|
81
|
+
form: state.context.form,
|
|
82
|
+
style: visuallyHiddenStyle,
|
|
83
|
+
maxLength: state.context.valueLength,
|
|
84
|
+
defaultValue: state.context.valueAsString
|
|
85
|
+
}),
|
|
86
|
+
controlProps: normalize.element({
|
|
87
|
+
...parts.control.attrs,
|
|
88
|
+
id: dom.getControlId(state.context)
|
|
89
|
+
}),
|
|
90
|
+
getInputProps({ index }) {
|
|
91
|
+
const inputType = state.context.type === "numeric" ? "tel" : "text";
|
|
92
|
+
return normalize.input({
|
|
93
|
+
...parts.input.attrs,
|
|
94
|
+
disabled: state.context.disabled,
|
|
95
|
+
"data-disabled": dataAttr(state.context.disabled),
|
|
96
|
+
"data-complete": dataAttr(isValueComplete),
|
|
97
|
+
id: dom.getInputId(state.context, index.toString()),
|
|
98
|
+
"data-ownedby": dom.getRootId(state.context),
|
|
99
|
+
"aria-label": translations.inputLabel(index, state.context.valueLength),
|
|
100
|
+
inputMode: state.context.otp || state.context.type === "numeric" ? "numeric" : "text",
|
|
101
|
+
"aria-invalid": ariaAttr(isInvalid),
|
|
102
|
+
"data-invalid": dataAttr(isInvalid),
|
|
103
|
+
type: state.context.mask ? "password" : inputType,
|
|
104
|
+
defaultValue: state.context.value[index] || "",
|
|
105
|
+
autoCapitalize: "none",
|
|
106
|
+
autoComplete: state.context.otp ? "one-time-code" : "off",
|
|
107
|
+
placeholder: focusedIndex === index ? "" : state.context.placeholder,
|
|
108
|
+
onChange(event) {
|
|
109
|
+
const evt = getNativeEvent(event);
|
|
110
|
+
const { value } = event.currentTarget;
|
|
111
|
+
if (evt.inputType === "insertFromPaste" || value.length > 2) {
|
|
112
|
+
send({ type: "PASTE", value });
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (evt.inputType === "deleteContentBackward") {
|
|
117
|
+
send("BACKSPACE");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
send({ type: "INPUT", value, index });
|
|
121
|
+
},
|
|
122
|
+
onKeyDown(event) {
|
|
123
|
+
const evt = getNativeEvent(event);
|
|
124
|
+
if (evt.isComposing || isModifiedEvent(evt))
|
|
125
|
+
return;
|
|
126
|
+
const keyMap = {
|
|
127
|
+
Backspace() {
|
|
128
|
+
send("BACKSPACE");
|
|
129
|
+
},
|
|
130
|
+
Delete() {
|
|
131
|
+
send("DELETE");
|
|
132
|
+
},
|
|
133
|
+
ArrowLeft() {
|
|
134
|
+
send("ARROW_LEFT");
|
|
135
|
+
},
|
|
136
|
+
ArrowRight() {
|
|
137
|
+
send("ARROW_RIGHT");
|
|
138
|
+
},
|
|
139
|
+
Enter() {
|
|
140
|
+
send("ENTER");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const key = getEventKey(event, { dir: state.context.dir });
|
|
144
|
+
const exec = keyMap[key];
|
|
145
|
+
if (exec) {
|
|
146
|
+
exec(event);
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
} else {
|
|
149
|
+
if (key === "Tab")
|
|
150
|
+
return;
|
|
151
|
+
send({ type: "KEY_DOWN", value: key, preventDefault: () => event.preventDefault() });
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
onFocus() {
|
|
155
|
+
send({ type: "FOCUS", index });
|
|
156
|
+
},
|
|
157
|
+
onBlur() {
|
|
158
|
+
send({ type: "BLUR", index });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { connect };
|
package/dist/pin-input.dom.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { MachineContext } from
|
|
2
|
-
|
|
3
|
-
import '@zag-js/types';
|
|
4
|
-
|
|
5
|
-
declare const dom: {
|
|
1
|
+
import type { MachineContext as Ctx } from "./pin-input.types";
|
|
2
|
+
export declare const dom: {
|
|
6
3
|
getRootNode: (ctx: {
|
|
7
4
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
8
5
|
}) => Document | ShadowRoot;
|
|
@@ -22,17 +19,15 @@ declare const dom: {
|
|
|
22
19
|
getRootNode?: (() => Document | Node | ShadowRoot) | undefined;
|
|
23
20
|
}, id: string) => T_1;
|
|
24
21
|
} & {
|
|
25
|
-
getRootId: (ctx:
|
|
26
|
-
getInputId: (ctx:
|
|
27
|
-
getHiddenInputId: (ctx:
|
|
28
|
-
getLabelId: (ctx:
|
|
29
|
-
getControlId: (ctx:
|
|
30
|
-
getRootEl: (ctx:
|
|
31
|
-
getElements: (ctx:
|
|
32
|
-
getInputEl: (ctx:
|
|
33
|
-
getFocusedInputEl: (ctx:
|
|
34
|
-
getFirstInputEl: (ctx:
|
|
35
|
-
getHiddenInputEl: (ctx:
|
|
22
|
+
getRootId: (ctx: Ctx) => string;
|
|
23
|
+
getInputId: (ctx: Ctx, id: string) => string;
|
|
24
|
+
getHiddenInputId: (ctx: Ctx) => string;
|
|
25
|
+
getLabelId: (ctx: Ctx) => string;
|
|
26
|
+
getControlId: (ctx: Ctx) => string;
|
|
27
|
+
getRootEl: (ctx: Ctx) => HTMLElement | null;
|
|
28
|
+
getElements: (ctx: Ctx) => HTMLInputElement[];
|
|
29
|
+
getInputEl: (ctx: Ctx, id: string) => HTMLInputElement | null;
|
|
30
|
+
getFocusedInputEl: (ctx: Ctx) => HTMLInputElement;
|
|
31
|
+
getFirstInputEl: (ctx: Ctx) => HTMLInputElement;
|
|
32
|
+
getHiddenInputEl: (ctx: Ctx) => HTMLInputElement | null;
|
|
36
33
|
};
|
|
37
|
-
|
|
38
|
-
export { dom };
|
package/dist/pin-input.dom.js
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
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
|
-
module.exports = __toCommonJS(pin_input_dom_exports);
|
|
26
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
-
var dom = (0, import_dom_query.createScope)({
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const domQuery = require('@zag-js/dom-query');
|
|
6
|
+
|
|
7
|
+
const dom = domQuery.createScope({
|
|
28
8
|
getRootId: (ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`,
|
|
29
9
|
getInputId: (ctx, id) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`,
|
|
30
10
|
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`,
|
|
@@ -34,14 +14,12 @@ var dom = (0, import_dom_query.createScope)({
|
|
|
34
14
|
getElements: (ctx) => {
|
|
35
15
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
36
16
|
const selector = `input[data-ownedby=${ownerId}]`;
|
|
37
|
-
return
|
|
17
|
+
return domQuery.queryAll(dom.getRootEl(ctx), selector);
|
|
38
18
|
},
|
|
39
19
|
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
40
20
|
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
41
21
|
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
42
22
|
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
43
23
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
dom
|
|
47
|
-
});
|
|
24
|
+
|
|
25
|
+
exports.dom = dom;
|
package/dist/pin-input.dom.mjs
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { createScope, queryAll } from '@zag-js/dom-query';
|
|
2
|
+
|
|
3
|
+
const dom = createScope({
|
|
4
|
+
getRootId: (ctx) => ctx.ids?.root ?? `pin-input:${ctx.id}`,
|
|
5
|
+
getInputId: (ctx, id) => ctx.ids?.input?.(id) ?? `pin-input:${ctx.id}:${id}`,
|
|
6
|
+
getHiddenInputId: (ctx) => ctx.ids?.hiddenInput ?? `pin-input:${ctx.id}:hidden`,
|
|
7
|
+
getLabelId: (ctx) => ctx.ids?.label ?? `pin-input:${ctx.id}:label`,
|
|
8
|
+
getControlId: (ctx) => ctx.ids?.control ?? `pin-input:${ctx.id}:control`,
|
|
9
|
+
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
10
|
+
getElements: (ctx) => {
|
|
11
|
+
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
12
|
+
const selector = `input[data-ownedby=${ownerId}]`;
|
|
13
|
+
return queryAll(dom.getRootEl(ctx), selector);
|
|
14
|
+
},
|
|
15
|
+
getInputEl: (ctx, id) => dom.getById(ctx, dom.getInputId(ctx, id)),
|
|
16
|
+
getFocusedInputEl: (ctx) => dom.getElements(ctx)[ctx.focusedIndex],
|
|
17
|
+
getFirstInputEl: (ctx) => dom.getElements(ctx)[0],
|
|
18
|
+
getHiddenInputEl: (ctx) => dom.getById(ctx, dom.getHiddenInputId(ctx))
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { dom };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
6
|
-
|
|
7
|
-
export { machine };
|
|
1
|
+
import { Machine, StateMachine } from '@zag-js/core';
|
|
2
|
+
import type { MachineContext, MachineState, UserDefinedContext } from "./pin-input.types";
|
|
3
|
+
export declare function machine(userContext: UserDefinedContext): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
|