@zag-js/number-input 0.1.14 → 0.1.15

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.js CHANGED
@@ -52,11 +52,8 @@ function getPlatform() {
52
52
  }
53
53
  var pt = (v) => isDom() && v.test(getPlatform());
54
54
  var vn = (v) => isDom() && v.test(navigator.vendor);
55
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
56
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
57
55
  var isSafari = () => isApple() && vn(/apple/i);
58
56
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
59
- var isIos = () => isApple() && !isMac();
60
57
  function isDocument(el) {
61
58
  return el.nodeType === Node.DOCUMENT_NODE;
62
59
  }
@@ -473,7 +470,7 @@ function connect(state, send, normalize) {
473
470
  name: state.context.name,
474
471
  id: dom.getInputId(state.context),
475
472
  role: "spinbutton",
476
- value: state.context.formattedValue,
473
+ defaultValue: state.context.formattedValue,
477
474
  pattern: state.context.pattern,
478
475
  inputMode: state.context.inputMode,
479
476
  "aria-invalid": isInvalid || void 0,
@@ -485,7 +482,7 @@ function connect(state, send, normalize) {
485
482
  autoCorrect: "off",
486
483
  spellCheck: "false",
487
484
  type: "text",
488
- "aria-roledescription": !isIos() ? "number field" : void 0,
485
+ "aria-roledescription": "numberfield",
489
486
  "aria-valuemin": state.context.min,
490
487
  "aria-valuemax": state.context.max,
491
488
  "aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
@@ -611,6 +608,28 @@ var callAll2 = (...fns) => (...a) => {
611
608
  });
612
609
  };
613
610
 
611
+ // ../../utilities/form-utils/dist/index.mjs
612
+ function getWindow(el) {
613
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
614
+ }
615
+ function getDescriptor(el, options) {
616
+ const { type, property } = options;
617
+ const proto = getWindow(el)[type].prototype;
618
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
619
+ }
620
+ function dispatchInputValueEvent(el, value) {
621
+ var _a;
622
+ if (!el)
623
+ return;
624
+ const win = getWindow(el);
625
+ if (!(el instanceof win.HTMLInputElement))
626
+ return;
627
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
628
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
629
+ const event = new win.Event("input", { bubbles: true });
630
+ el.dispatchEvent(event);
631
+ }
632
+
614
633
  // src/number-input.machine.ts
615
634
  var { not, and } = import_core.guards;
616
635
  function machine(ctx) {
@@ -659,14 +678,20 @@ function machine(ctx) {
659
678
  }
660
679
  },
661
680
  watch: {
662
- value: ["invokeOnChange"],
681
+ value: ["invokeOnChange", "dispatchChangeEvent"],
663
682
  isOutOfRange: ["invokeOnInvalid"],
664
683
  scrubberCursorPoint: ["setVirtualCursorPosition"]
665
684
  },
666
685
  on: {
667
- SET_VALUE: {
668
- actions: ["setValue", "setHintToSet"]
669
- },
686
+ SET_VALUE: [
687
+ {
688
+ guard: "clampOnBlur",
689
+ actions: ["setValue", "clampValue", "setHintToSet"]
690
+ },
691
+ {
692
+ actions: ["setValue", "setHintToSet"]
693
+ }
694
+ ],
670
695
  CLEAR_VALUE: {
671
696
  actions: ["clearValue"]
672
697
  },
@@ -985,6 +1010,9 @@ function machine(ctx) {
985
1010
  return;
986
1011
  const { x, y } = ctx2.scrubberCursorPoint;
987
1012
  cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
1013
+ },
1014
+ dispatchChangeEvent(ctx2) {
1015
+ dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
988
1016
  }
989
1017
  },
990
1018
  hookSync: true
package/dist/index.mjs CHANGED
@@ -25,11 +25,8 @@ function getPlatform() {
25
25
  }
26
26
  var pt = (v) => isDom() && v.test(getPlatform());
27
27
  var vn = (v) => isDom() && v.test(navigator.vendor);
28
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
29
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
30
28
  var isSafari = () => isApple() && vn(/apple/i);
31
29
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
32
- var isIos = () => isApple() && !isMac();
33
30
  function isDocument(el) {
34
31
  return el.nodeType === Node.DOCUMENT_NODE;
35
32
  }
@@ -446,7 +443,7 @@ function connect(state, send, normalize) {
446
443
  name: state.context.name,
447
444
  id: dom.getInputId(state.context),
448
445
  role: "spinbutton",
449
- value: state.context.formattedValue,
446
+ defaultValue: state.context.formattedValue,
450
447
  pattern: state.context.pattern,
451
448
  inputMode: state.context.inputMode,
452
449
  "aria-invalid": isInvalid || void 0,
@@ -458,7 +455,7 @@ function connect(state, send, normalize) {
458
455
  autoCorrect: "off",
459
456
  spellCheck: "false",
460
457
  type: "text",
461
- "aria-roledescription": !isIos() ? "number field" : void 0,
458
+ "aria-roledescription": "numberfield",
462
459
  "aria-valuemin": state.context.min,
463
460
  "aria-valuemax": state.context.max,
464
461
  "aria-valuenow": isNaN(state.context.valueAsNumber) ? void 0 : state.context.valueAsNumber,
@@ -584,6 +581,28 @@ var callAll2 = (...fns) => (...a) => {
584
581
  });
585
582
  };
586
583
 
584
+ // ../../utilities/form-utils/dist/index.mjs
585
+ function getWindow(el) {
586
+ return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
587
+ }
588
+ function getDescriptor(el, options) {
589
+ const { type, property } = options;
590
+ const proto = getWindow(el)[type].prototype;
591
+ return Object.getOwnPropertyDescriptor(proto, property) ?? {};
592
+ }
593
+ function dispatchInputValueEvent(el, value) {
594
+ var _a;
595
+ if (!el)
596
+ return;
597
+ const win = getWindow(el);
598
+ if (!(el instanceof win.HTMLInputElement))
599
+ return;
600
+ const desc = getDescriptor(el, { type: "HTMLInputElement", property: "value" });
601
+ (_a = desc.set) == null ? void 0 : _a.call(el, value);
602
+ const event = new win.Event("input", { bubbles: true });
603
+ el.dispatchEvent(event);
604
+ }
605
+
587
606
  // src/number-input.machine.ts
588
607
  var { not, and } = guards;
589
608
  function machine(ctx) {
@@ -632,14 +651,20 @@ function machine(ctx) {
632
651
  }
633
652
  },
634
653
  watch: {
635
- value: ["invokeOnChange"],
654
+ value: ["invokeOnChange", "dispatchChangeEvent"],
636
655
  isOutOfRange: ["invokeOnInvalid"],
637
656
  scrubberCursorPoint: ["setVirtualCursorPosition"]
638
657
  },
639
658
  on: {
640
- SET_VALUE: {
641
- actions: ["setValue", "setHintToSet"]
642
- },
659
+ SET_VALUE: [
660
+ {
661
+ guard: "clampOnBlur",
662
+ actions: ["setValue", "clampValue", "setHintToSet"]
663
+ },
664
+ {
665
+ actions: ["setValue", "setHintToSet"]
666
+ }
667
+ ],
643
668
  CLEAR_VALUE: {
644
669
  actions: ["clearValue"]
645
670
  },
@@ -958,6 +983,9 @@ function machine(ctx) {
958
983
  return;
959
984
  const { x, y } = ctx2.scrubberCursorPoint;
960
985
  cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
986
+ },
987
+ dispatchChangeEvent(ctx2) {
988
+ dispatchInputValueEvent(dom.getInputEl(ctx2), ctx2.formattedValue);
961
989
  }
962
990
  },
963
991
  hookSync: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/number-input",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Core logic for the number-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -30,10 +30,11 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@zag-js/core": "0.1.9",
33
- "@zag-js/types": "0.2.3"
33
+ "@zag-js/types": "0.2.4"
34
34
  },
35
35
  "devDependencies": {
36
- "@zag-js/dom-utils": "0.1.9",
36
+ "@zag-js/dom-utils": "0.1.10",
37
+ "@zag-js/form-utils": "0.1.0",
37
38
  "@zag-js/number-utils": "0.1.3",
38
39
  "@zag-js/utils": "0.1.3"
39
40
  },