@zag-js/number-input 0.0.0-dev-20220509202935 → 0.0.0-dev-20220509213421

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.mjs CHANGED
@@ -35,6 +35,12 @@ function nextTick(fn) {
35
35
  });
36
36
  };
37
37
  }
38
+ function raf(fn) {
39
+ const id = globalThis.requestAnimationFrame(fn);
40
+ return function cleanup() {
41
+ globalThis.cancelAnimationFrame(id);
42
+ };
43
+ }
38
44
  var noop = () => {
39
45
  };
40
46
  var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
@@ -501,10 +507,8 @@ function connect(state, send, normalize = normalizeProp) {
501
507
  send({ type: "SET_VALUE", value: state.context.min });
502
508
  },
503
509
  focus() {
504
- nextTick(() => {
505
- var _a;
506
- (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
507
- });
510
+ var _a;
511
+ (_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
508
512
  },
509
513
  rootProps: normalize.element({
510
514
  id: dom.getRootId(state.context),
@@ -755,7 +759,7 @@ function machine(ctx = {}) {
755
759
  actions: "setToMax"
756
760
  },
757
761
  CHANGE: {
758
- actions: ["setValue", "setSelectionRange", "setHint"]
762
+ actions: ["setValue", "setHint"]
759
763
  },
760
764
  BLUR: [
761
765
  {
@@ -790,7 +794,7 @@ function machine(ctx = {}) {
790
794
  on: {
791
795
  PRESS_UP: {
792
796
  target: "focused",
793
- actions: ["clearHint", "restoreSelection"]
797
+ actions: "clearHint"
794
798
  }
795
799
  }
796
800
  },
@@ -812,7 +816,7 @@ function machine(ctx = {}) {
812
816
  on: {
813
817
  PRESS_UP: {
814
818
  target: "focused",
815
- actions: ["clearHint", "restoreSelection"]
819
+ actions: "clearHint"
816
820
  }
817
821
  }
818
822
  },
@@ -924,7 +928,7 @@ function machine(ctx = {}) {
924
928
  if (!ctx2.focusInputOnChange)
925
929
  return;
926
930
  const input = dom.getInputEl(ctx2);
927
- nextTick(() => input == null ? void 0 : input.focus());
931
+ raf(() => input == null ? void 0 : input.focus());
928
932
  },
929
933
  increment(ctx2, evt) {
930
934
  ctx2.value = utils.increment(ctx2, evt.step);
@@ -961,20 +965,6 @@ function machine(ctx = {}) {
961
965
  setHintToSet(ctx2) {
962
966
  ctx2.hint = "set";
963
967
  },
964
- setSelectionRange(ctx2, evt) {
965
- ctx2.inputSelection = {
966
- start: evt.target.selectionStart,
967
- end: evt.target.selectionEnd
968
- };
969
- },
970
- restoreSelection(ctx2) {
971
- var _a, _b, _c;
972
- const input = dom.getInputEl(ctx2);
973
- if (!input || !ctx2.inputSelection)
974
- return;
975
- input.selectionStart = (_b = ctx2.inputSelection.start) != null ? _b : (_a = input.value) == null ? void 0 : _a.length;
976
- input.selectionEnd = (_c = ctx2.inputSelection.end) != null ? _c : input.selectionStart;
977
- },
978
968
  invokeOnChange(ctx2) {
979
969
  var _a;
980
970
  (_a = ctx2.onChange) == null ? void 0 : _a.call(ctx2, { value: ctx2.value, valueAsNumber: ctx2.valueAsNumber });