@zag-js/pin-input 0.1.13 → 0.1.14
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 +3 -1
- package/dist/index.js +24 -7
- package/dist/index.mjs +24 -7
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare type IntlMessages = {
|
|
|
8
8
|
declare type ElementIds = Partial<{
|
|
9
9
|
root: string;
|
|
10
10
|
hiddenInput: string;
|
|
11
|
+
label: string;
|
|
11
12
|
input(id: string): string;
|
|
12
13
|
}>;
|
|
13
14
|
declare type PublicContext = DirectionProperty & CommonProperties & {
|
|
@@ -123,8 +124,9 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
123
124
|
setValue(value: string[]): void;
|
|
124
125
|
clearValue(): void;
|
|
125
126
|
setValueAtIndex(index: number, value: string): void;
|
|
126
|
-
focus()
|
|
127
|
+
focus: () => void;
|
|
127
128
|
rootProps: T["element"];
|
|
129
|
+
labelProps: T["label"];
|
|
128
130
|
hiddenInputProps: T["input"];
|
|
129
131
|
getInputProps({ index }: {
|
|
130
132
|
index: number;
|
package/dist/index.js
CHANGED
|
@@ -67,9 +67,7 @@ function getNativeEvent(e) {
|
|
|
67
67
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
68
68
|
var rtlKeyMap = {
|
|
69
69
|
ArrowLeft: "ArrowRight",
|
|
70
|
-
ArrowRight: "ArrowLeft"
|
|
71
|
-
Home: "End",
|
|
72
|
-
End: "Home"
|
|
70
|
+
ArrowRight: "ArrowLeft"
|
|
73
71
|
};
|
|
74
72
|
var sameKeyMap = {
|
|
75
73
|
Up: "ArrowUp",
|
|
@@ -135,6 +133,10 @@ var dom = defineDomHelpers({
|
|
|
135
133
|
var _a;
|
|
136
134
|
return ((_a = ctx.ids) == null ? void 0 : _a.hiddenInput) ?? `pin-input:${ctx.id}:hidden`;
|
|
137
135
|
},
|
|
136
|
+
getLabelId: (ctx) => {
|
|
137
|
+
var _a;
|
|
138
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `pin-input:${ctx.id}:label`;
|
|
139
|
+
},
|
|
138
140
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
139
141
|
getElements: (ctx) => {
|
|
140
142
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
@@ -152,6 +154,10 @@ function connect(state, send, normalize) {
|
|
|
152
154
|
const isInvalid = state.context.invalid;
|
|
153
155
|
const focusedIndex = state.context.focusedIndex;
|
|
154
156
|
const messages = state.context.messages;
|
|
157
|
+
function focus() {
|
|
158
|
+
var _a;
|
|
159
|
+
(_a = dom.getFirstInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
160
|
+
}
|
|
155
161
|
return {
|
|
156
162
|
value: state.context.value,
|
|
157
163
|
valueAsString: state.context.valueAsString,
|
|
@@ -168,10 +174,7 @@ function connect(state, send, normalize) {
|
|
|
168
174
|
setValueAtIndex(index, value) {
|
|
169
175
|
send({ type: "SET_VALUE", value, index });
|
|
170
176
|
},
|
|
171
|
-
focus
|
|
172
|
-
var _a;
|
|
173
|
-
(_a = dom.getFirstInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
174
|
-
},
|
|
177
|
+
focus,
|
|
175
178
|
rootProps: normalize.element({
|
|
176
179
|
dir: state.context.dir,
|
|
177
180
|
"data-part": "root",
|
|
@@ -180,6 +183,18 @@ function connect(state, send, normalize) {
|
|
|
180
183
|
"data-disabled": dataAttr(state.context.disabled),
|
|
181
184
|
"data-complete": dataAttr(isValueComplete)
|
|
182
185
|
}),
|
|
186
|
+
labelProps: normalize.label({
|
|
187
|
+
"data-part": "label",
|
|
188
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
189
|
+
id: dom.getLabelId(state.context),
|
|
190
|
+
"data-invalid": dataAttr(isInvalid),
|
|
191
|
+
"data-disabled": dataAttr(state.context.disabled),
|
|
192
|
+
"data-complete": dataAttr(isValueComplete),
|
|
193
|
+
onClick: (event) => {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
focus();
|
|
196
|
+
}
|
|
197
|
+
}),
|
|
183
198
|
hiddenInputProps: normalize.input({
|
|
184
199
|
"aria-hidden": true,
|
|
185
200
|
type: "text",
|
|
@@ -249,6 +264,8 @@ function connect(state, send, normalize) {
|
|
|
249
264
|
exec(event);
|
|
250
265
|
event.preventDefault();
|
|
251
266
|
} else {
|
|
267
|
+
if (key === "Tab")
|
|
268
|
+
return;
|
|
252
269
|
send({ type: "KEY_DOWN", value: key, preventDefault: () => event.preventDefault() });
|
|
253
270
|
}
|
|
254
271
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -40,9 +40,7 @@ function getNativeEvent(e) {
|
|
|
40
40
|
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
41
41
|
var rtlKeyMap = {
|
|
42
42
|
ArrowLeft: "ArrowRight",
|
|
43
|
-
ArrowRight: "ArrowLeft"
|
|
44
|
-
Home: "End",
|
|
45
|
-
End: "Home"
|
|
43
|
+
ArrowRight: "ArrowLeft"
|
|
46
44
|
};
|
|
47
45
|
var sameKeyMap = {
|
|
48
46
|
Up: "ArrowUp",
|
|
@@ -108,6 +106,10 @@ var dom = defineDomHelpers({
|
|
|
108
106
|
var _a;
|
|
109
107
|
return ((_a = ctx.ids) == null ? void 0 : _a.hiddenInput) ?? `pin-input:${ctx.id}:hidden`;
|
|
110
108
|
},
|
|
109
|
+
getLabelId: (ctx) => {
|
|
110
|
+
var _a;
|
|
111
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `pin-input:${ctx.id}:label`;
|
|
112
|
+
},
|
|
111
113
|
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
112
114
|
getElements: (ctx) => {
|
|
113
115
|
const ownerId = CSS.escape(dom.getRootId(ctx));
|
|
@@ -125,6 +127,10 @@ function connect(state, send, normalize) {
|
|
|
125
127
|
const isInvalid = state.context.invalid;
|
|
126
128
|
const focusedIndex = state.context.focusedIndex;
|
|
127
129
|
const messages = state.context.messages;
|
|
130
|
+
function focus() {
|
|
131
|
+
var _a;
|
|
132
|
+
(_a = dom.getFirstInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
133
|
+
}
|
|
128
134
|
return {
|
|
129
135
|
value: state.context.value,
|
|
130
136
|
valueAsString: state.context.valueAsString,
|
|
@@ -141,10 +147,7 @@ function connect(state, send, normalize) {
|
|
|
141
147
|
setValueAtIndex(index, value) {
|
|
142
148
|
send({ type: "SET_VALUE", value, index });
|
|
143
149
|
},
|
|
144
|
-
focus
|
|
145
|
-
var _a;
|
|
146
|
-
(_a = dom.getFirstInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
147
|
-
},
|
|
150
|
+
focus,
|
|
148
151
|
rootProps: normalize.element({
|
|
149
152
|
dir: state.context.dir,
|
|
150
153
|
"data-part": "root",
|
|
@@ -153,6 +156,18 @@ function connect(state, send, normalize) {
|
|
|
153
156
|
"data-disabled": dataAttr(state.context.disabled),
|
|
154
157
|
"data-complete": dataAttr(isValueComplete)
|
|
155
158
|
}),
|
|
159
|
+
labelProps: normalize.label({
|
|
160
|
+
"data-part": "label",
|
|
161
|
+
htmlFor: dom.getHiddenInputId(state.context),
|
|
162
|
+
id: dom.getLabelId(state.context),
|
|
163
|
+
"data-invalid": dataAttr(isInvalid),
|
|
164
|
+
"data-disabled": dataAttr(state.context.disabled),
|
|
165
|
+
"data-complete": dataAttr(isValueComplete),
|
|
166
|
+
onClick: (event) => {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
focus();
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
156
171
|
hiddenInputProps: normalize.input({
|
|
157
172
|
"aria-hidden": true,
|
|
158
173
|
type: "text",
|
|
@@ -222,6 +237,8 @@ function connect(state, send, normalize) {
|
|
|
222
237
|
exec(event);
|
|
223
238
|
event.preventDefault();
|
|
224
239
|
} else {
|
|
240
|
+
if (key === "Tab")
|
|
241
|
+
return;
|
|
225
242
|
send({ type: "KEY_DOWN", value: key, preventDefault: () => event.preventDefault() });
|
|
226
243
|
}
|
|
227
244
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/pin-input",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Core logic for the pin-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/types": "0.2.
|
|
32
|
+
"@zag-js/core": "0.1.10",
|
|
33
|
+
"@zag-js/types": "0.2.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zag-js/dom-utils": "0.1.
|
|
37
|
-
"@zag-js/form-utils": "0.1.
|
|
38
|
-
"@zag-js/utils": "0.1.
|
|
36
|
+
"@zag-js/dom-utils": "0.1.11",
|
|
37
|
+
"@zag-js/form-utils": "0.1.1",
|
|
38
|
+
"@zag-js/utils": "0.1.4"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build-fast": "tsup src/index.ts --format=esm,cjs",
|