@zag-js/pin-input 1.41.0 → 1.41.2

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.
@@ -132,7 +132,7 @@ function connect(service, normalize) {
132
132
  tabIndex: index === tabbableIndex ? 0 : -1,
133
133
  "data-disabled": (0, import_dom_query.dataAttr)(disabled),
134
134
  "data-complete": (0, import_dom_query.dataAttr)(complete),
135
- "data-filled": (0, import_dom_query.dataAttr)(context.get("value")[index] !== ""),
135
+ "data-filled": (0, import_dom_query.dataAttr)(computed("_value")[index] !== ""),
136
136
  id: dom.getInputId(scope, index.toString()),
137
137
  "data-index": index,
138
138
  "data-ownedby": dom.getRootId(scope),
@@ -142,7 +142,7 @@ function connect(service, normalize) {
142
142
  "data-invalid": (0, import_dom_query.dataAttr)(invalid),
143
143
  enterKeyHint: index === valueLength - 1 ? "done" : "next",
144
144
  type: prop("mask") ? "password" : inputType,
145
- defaultValue: context.get("value")[index] || "",
145
+ defaultValue: computed("_value")[index] || "",
146
146
  readOnly,
147
147
  autoCapitalize: "none",
148
148
  autoComplete: prop("otp") ? "one-time-code" : "off",
@@ -108,7 +108,7 @@ function connect(service, normalize) {
108
108
  tabIndex: index === tabbableIndex ? 0 : -1,
109
109
  "data-disabled": dataAttr(disabled),
110
110
  "data-complete": dataAttr(complete),
111
- "data-filled": dataAttr(context.get("value")[index] !== ""),
111
+ "data-filled": dataAttr(computed("_value")[index] !== ""),
112
112
  id: dom.getInputId(scope, index.toString()),
113
113
  "data-index": index,
114
114
  "data-ownedby": dom.getRootId(scope),
@@ -118,7 +118,7 @@ function connect(service, normalize) {
118
118
  "data-invalid": dataAttr(invalid),
119
119
  enterKeyHint: index === valueLength - 1 ? "done" : "next",
120
120
  type: prop("mask") ? "password" : inputType,
121
- defaultValue: context.get("value")[index] || "",
121
+ defaultValue: computed("_value")[index] || "",
122
122
  readOnly,
123
123
  autoCapitalize: "none",
124
124
  autoComplete: prop("otp") ? "one-time-code" : "off",
@@ -58,8 +58,8 @@ var machine = createMachine({
58
58
  context({ prop, bindable }) {
59
59
  return {
60
60
  value: bindable(() => ({
61
- value: prop("value"),
62
- defaultValue: prop("defaultValue"),
61
+ value: prop("value") ? fill(prop("value"), prop("count")) : void 0,
62
+ defaultValue: fill(prop("defaultValue") ?? [], prop("count")),
63
63
  isEqual: import_utils.isEqual,
64
64
  onChange(value) {
65
65
  prop("onValueChange")?.({ value, valueAsString: value.join("") });
@@ -178,7 +178,7 @@ var machine = createMachine({
178
178
  implementations: {
179
179
  guards: {
180
180
  autoFocus: ({ prop }) => !!prop("autoFocus"),
181
- hasValue: ({ context }) => context.get("value")[context.get("focusedIndex")] !== "",
181
+ hasValue: ({ context, computed }) => computed("_value")[context.get("focusedIndex")] !== "",
182
182
  isValueComplete: ({ computed }) => computed("isValueComplete"),
183
183
  hasIndex: ({ event }) => event.index !== void 0
184
184
  },
@@ -340,7 +340,8 @@ function getNextValue(current, next) {
340
340
  return nextValue ?? "";
341
341
  }
342
342
  function fill(value, count) {
343
- return Array.from({ length: count }).fill("").map((v, i) => value[i] || v);
343
+ const length = count || value.length;
344
+ return Array.from({ length }).fill("").map((v, i) => value[i] || v);
344
345
  }
345
346
  // Annotate the CommonJS export names for ESM import in node:
346
347
  0 && (module.exports = {
@@ -24,8 +24,8 @@ var machine = createMachine({
24
24
  context({ prop, bindable }) {
25
25
  return {
26
26
  value: bindable(() => ({
27
- value: prop("value"),
28
- defaultValue: prop("defaultValue"),
27
+ value: prop("value") ? fill(prop("value"), prop("count")) : void 0,
28
+ defaultValue: fill(prop("defaultValue") ?? [], prop("count")),
29
29
  isEqual,
30
30
  onChange(value) {
31
31
  prop("onValueChange")?.({ value, valueAsString: value.join("") });
@@ -144,7 +144,7 @@ var machine = createMachine({
144
144
  implementations: {
145
145
  guards: {
146
146
  autoFocus: ({ prop }) => !!prop("autoFocus"),
147
- hasValue: ({ context }) => context.get("value")[context.get("focusedIndex")] !== "",
147
+ hasValue: ({ context, computed }) => computed("_value")[context.get("focusedIndex")] !== "",
148
148
  isValueComplete: ({ computed }) => computed("isValueComplete"),
149
149
  hasIndex: ({ event }) => event.index !== void 0
150
150
  },
@@ -306,7 +306,8 @@ function getNextValue(current, next) {
306
306
  return nextValue ?? "";
307
307
  }
308
308
  function fill(value, count) {
309
- return Array.from({ length: count }).fill("").map((v, i) => value[i] || v);
309
+ const length = count || value.length;
310
+ return Array.from({ length }).fill("").map((v, i) => value[i] || v);
310
311
  }
311
312
  export {
312
313
  machine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/pin-input",
3
- "version": "1.41.0",
3
+ "version": "1.41.2",
4
4
  "description": "Core logic for the pin-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,11 +26,11 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "1.41.0",
30
- "@zag-js/dom-query": "1.41.0",
31
- "@zag-js/utils": "1.41.0",
32
- "@zag-js/core": "1.41.0",
33
- "@zag-js/types": "1.41.0"
29
+ "@zag-js/anatomy": "1.41.2",
30
+ "@zag-js/dom-query": "1.41.2",
31
+ "@zag-js/utils": "1.41.2",
32
+ "@zag-js/core": "1.41.2",
33
+ "@zag-js/types": "1.41.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "clean-package": "2.2.0"