@zag-js/pin-input 0.2.0 → 0.2.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.
package/dist/index.d.ts CHANGED
@@ -142,6 +142,6 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
142
142
  }): T["input"];
143
143
  };
144
144
 
145
- declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
145
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
146
146
 
147
147
  export { UserDefinedContext as Context, connect, machine };
package/dist/index.js CHANGED
@@ -136,6 +136,15 @@ var visuallyHiddenStyle = {
136
136
  };
137
137
 
138
138
  // ../../utilities/core/dist/index.mjs
139
+ var isArray = (v) => Array.isArray(v);
140
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
141
+ function compact(obj) {
142
+ if (obj === void 0)
143
+ return obj;
144
+ return Object.fromEntries(
145
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
146
+ );
147
+ }
139
148
  function invariant(...a) {
140
149
  const m = a.length === 1 ? a[0] : a[1];
141
150
  const c = a.length === 2 ? a[0] : true;
@@ -315,7 +324,7 @@ function getWindow(el) {
315
324
  }
316
325
  function getDescriptor(el, options) {
317
326
  var _a;
318
- const { type, property } = options;
327
+ const { type, property = "value" } = options;
319
328
  const proto = getWindow(el)[type].prototype;
320
329
  return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
321
330
  }
@@ -334,7 +343,8 @@ function dispatchInputValueEvent(el, value) {
334
343
 
335
344
  // src/pin-input.machine.ts
336
345
  var { and, not } = import_core.guards;
337
- function machine(ctx) {
346
+ function machine(userContext) {
347
+ const ctx = compact(userContext);
338
348
  return (0, import_core.createMachine)(
339
349
  {
340
350
  id: "pin-input",
@@ -616,9 +626,8 @@ function isValidType(value, type) {
616
626
  return !!((_a = REGEX[type]) == null ? void 0 : _a.test(value));
617
627
  }
618
628
  function assign(ctx, value) {
619
- const valueArr = value.split("").filter(Boolean);
629
+ const valueArr = Array.isArray(value) ? value : value.split("").filter(Boolean);
620
630
  const valueObj = Object.assign({}, ctx.value, valueArr);
621
- console.log("valueObj :>> ", valueObj);
622
631
  ctx.value = Object.values(valueObj);
623
632
  }
624
633
  function lastChar(value) {
package/dist/index.mjs CHANGED
@@ -109,6 +109,15 @@ var visuallyHiddenStyle = {
109
109
  };
110
110
 
111
111
  // ../../utilities/core/dist/index.mjs
112
+ var isArray = (v) => Array.isArray(v);
113
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
114
+ function compact(obj) {
115
+ if (obj === void 0)
116
+ return obj;
117
+ return Object.fromEntries(
118
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
119
+ );
120
+ }
112
121
  function invariant(...a) {
113
122
  const m = a.length === 1 ? a[0] : a[1];
114
123
  const c = a.length === 2 ? a[0] : true;
@@ -288,7 +297,7 @@ function getWindow(el) {
288
297
  }
289
298
  function getDescriptor(el, options) {
290
299
  var _a;
291
- const { type, property } = options;
300
+ const { type, property = "value" } = options;
292
301
  const proto = getWindow(el)[type].prototype;
293
302
  return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
294
303
  }
@@ -307,7 +316,8 @@ function dispatchInputValueEvent(el, value) {
307
316
 
308
317
  // src/pin-input.machine.ts
309
318
  var { and, not } = guards;
310
- function machine(ctx) {
319
+ function machine(userContext) {
320
+ const ctx = compact(userContext);
311
321
  return createMachine(
312
322
  {
313
323
  id: "pin-input",
@@ -589,9 +599,8 @@ function isValidType(value, type) {
589
599
  return !!((_a = REGEX[type]) == null ? void 0 : _a.test(value));
590
600
  }
591
601
  function assign(ctx, value) {
592
- const valueArr = value.split("").filter(Boolean);
602
+ const valueArr = Array.isArray(value) ? value : value.split("").filter(Boolean);
593
603
  const valueObj = Object.assign({}, ctx.value, valueArr);
594
- console.log("valueObj :>> ", valueObj);
595
604
  ctx.value = Object.values(valueObj);
596
605
  }
597
606
  function lastChar(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/pin-input",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Core logic for the pin-input widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,13 +29,13 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.2.0",
33
- "@zag-js/types": "0.3.0"
32
+ "@zag-js/core": "0.2.2",
33
+ "@zag-js/types": "0.3.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.2.0",
37
- "@zag-js/form-utils": "0.2.0",
38
- "@zag-js/utils": "0.2.0"
36
+ "@zag-js/dom-utils": "0.2.1",
37
+ "@zag-js/form-utils": "0.2.1",
38
+ "@zag-js/utils": "0.3.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build-fast": "tsup src/index.ts --format=esm,cjs",