@zag-js/number-input 0.1.5 → 0.1.8

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
@@ -131,17 +131,6 @@ function getNativeEvent(event) {
131
131
  var _a;
132
132
  return (_a = event.nativeEvent) != null ? _a : event;
133
133
  }
134
- var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
135
- var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
136
- function getEventStep(event) {
137
- if (event.ctrlKey || event.metaKey) {
138
- return 0.1;
139
- } else {
140
- const isPageKey = PAGE_KEYS.has(event.key);
141
- const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
142
- return isSkipKey ? 10 : 1;
143
- }
144
- }
145
134
  function observeAttributes(node, attributes, fn) {
146
135
  if (!node)
147
136
  return noop;
@@ -157,6 +146,17 @@ function observeAttributes(node, attributes, fn) {
157
146
  obs.observe(node, { attributes: true, attributeFilter: attrs });
158
147
  return () => obs.disconnect();
159
148
  }
149
+ var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
150
+ var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
151
+ function getEventStep(event) {
152
+ if (event.ctrlKey || event.metaKey) {
153
+ return 0.1;
154
+ } else {
155
+ const isPageKey = PAGE_KEYS.has(event.key);
156
+ const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
157
+ return isSkipKey ? 10 : 1;
158
+ }
159
+ }
160
160
  function itemById(v, id) {
161
161
  return v.find((node) => node.id === id);
162
162
  }
@@ -327,7 +327,11 @@ function getEventPoint(e, t2 = "page") {
327
327
 
328
328
  // ../../types/dist/index.mjs
329
329
  function createNormalizer(fn) {
330
- return { button: fn, label: fn, input: fn, output: fn, element: fn };
330
+ return new Proxy({}, {
331
+ get() {
332
+ return fn;
333
+ }
334
+ });
331
335
  }
332
336
  var normalizeProp = createNormalizer((v) => v);
333
337
 
@@ -342,6 +346,7 @@ var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
342
346
  var isIos = () => isIPhone() || isIPad();
343
347
  var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
344
348
  var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
349
+ var isLeftClick = (v) => v.button === 0;
345
350
  var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
346
351
 
347
352
  // src/number-input.dom.ts
@@ -606,7 +611,7 @@ function connect(state, send, normalize = normalizeProp) {
606
611
  onPointerDown(event) {
607
612
  if (isDecrementDisabled)
608
613
  return;
609
- send({ type: "PRESS_DOWN", hint: "decrement" });
614
+ send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "decrement" } : { type: "FOCUS" });
610
615
  event.preventDefault();
611
616
  },
612
617
  onPointerUp() {
@@ -629,10 +634,10 @@ function connect(state, send, normalize = normalizeProp) {
629
634
  tabIndex: -1,
630
635
  "aria-controls": dom.getInputId(state.context),
631
636
  onPointerDown(event) {
632
- event.preventDefault();
633
637
  if (isIncrementDisabled)
634
638
  return;
635
- send({ type: "PRESS_DOWN", hint: "increment" });
639
+ send(isLeftClick(event) ? { type: "PRESS_DOWN", hint: "increment" } : { type: "FOCUS" });
640
+ event.preventDefault();
636
641
  },
637
642
  onPointerUp() {
638
643
  send({ type: "PRESS_UP", hint: "increment" });
@@ -750,6 +755,7 @@ function machine(ctx = {}) {
750
755
  },
751
756
  focused: {
752
757
  tags: ["focus"],
758
+ entry: "focusInput",
753
759
  activities: "attachWheelListener",
754
760
  on: {
755
761
  PRESS_DOWN: {
@@ -788,13 +794,14 @@ function machine(ctx = {}) {
788
794
  },
789
795
  {
790
796
  target: "idle",
791
- actions: ["roundValue"]
797
+ actions: "roundValue"
792
798
  }
793
799
  ]
794
800
  }
795
801
  },
796
802
  "before:spin": {
797
803
  tags: ["focus"],
804
+ activities: "trackButtonDisabled",
798
805
  entry: (0, import_core.choose)([
799
806
  { guard: "isIncrementHint", actions: "increment" },
800
807
  { guard: "isDecrementHint", actions: "decrement" }
@@ -842,7 +849,7 @@ function machine(ctx = {}) {
842
849
  on: {
843
850
  POINTER_UP_SCRUBBER: {
844
851
  target: "focused",
845
- actions: ["clearCursorPoint"]
852
+ actions: "clearCursorPoint"
846
853
  },
847
854
  POINTER_MOVE_SCRUBBER: [
848
855
  {