@zag-js/number-input 0.0.0-dev-20220707125149 → 0.0.0-dev-20220709094318

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
@@ -43,6 +43,22 @@ __export(src_exports, {
43
43
  module.exports = __toCommonJS(src_exports);
44
44
 
45
45
  // ../../utilities/dom/dist/index.mjs
46
+ var __defProp2 = Object.defineProperty;
47
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
48
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
49
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
50
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
51
+ var __spreadValues2 = (a, b) => {
52
+ for (var prop in b || (b = {}))
53
+ if (__hasOwnProp2.call(b, prop))
54
+ __defNormalProp2(a, prop, b[prop]);
55
+ if (__getOwnPropSymbols2)
56
+ for (var prop of __getOwnPropSymbols2(b)) {
57
+ if (__propIsEnum2.call(b, prop))
58
+ __defNormalProp2(a, prop, b[prop]);
59
+ }
60
+ return a;
61
+ };
46
62
  var dataAttr = (guard) => {
47
63
  return guard ? "" : void 0;
48
64
  };
@@ -75,6 +91,34 @@ var isMac = () => pt(/^Mac/) && !isTouchDevice;
75
91
  var isSafari = () => isApple() && vn(/apple/i);
76
92
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
77
93
  var isIos = () => isApple() && !isMac();
94
+ function isDocument(el) {
95
+ return el.nodeType === Node.DOCUMENT_NODE;
96
+ }
97
+ function isWindow(value) {
98
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
99
+ }
100
+ function getDocument(el) {
101
+ var _a;
102
+ if (isWindow(el))
103
+ return el.document;
104
+ if (isDocument(el))
105
+ return el;
106
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
107
+ }
108
+ function withRootHelpers(domUtils) {
109
+ const roots = {
110
+ getRootNode: (ctx) => {
111
+ var _a, _b;
112
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
113
+ },
114
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
115
+ getWin: (ctx) => {
116
+ var _a;
117
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
118
+ }
119
+ };
120
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
121
+ }
78
122
  function getNativeEvent(e) {
79
123
  var _a;
80
124
  return (_a = e.nativeEvent) != null ? _a : e;
@@ -241,43 +285,31 @@ function decimalOperation(a, op, b) {
241
285
  var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
242
286
 
243
287
  // src/number-input.dom.ts
244
- var dom = {
245
- getDoc: (ctx) => {
246
- var _a;
247
- return (_a = ctx.doc) != null ? _a : document;
248
- },
249
- getWin: (ctx) => {
250
- var _a;
251
- return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
252
- },
253
- getRootNode: (ctx) => {
254
- var _a;
255
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
256
- },
288
+ var dom = withRootHelpers({
257
289
  getRootId: (ctx) => {
258
290
  var _a, _b;
259
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.uid}`;
291
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
260
292
  },
261
293
  getInputId: (ctx) => {
262
294
  var _a, _b;
263
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.uid}:input`;
295
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
264
296
  },
265
297
  getIncButtonId: (ctx) => {
266
298
  var _a, _b;
267
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.uid}:inc-btn`;
299
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
268
300
  },
269
301
  getDecButtonId: (ctx) => {
270
302
  var _a, _b;
271
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.uid}:dec-btn`;
303
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
272
304
  },
273
305
  getScrubberId: (ctx) => {
274
306
  var _a, _b;
275
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.uid}:scrubber`;
307
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
276
308
  },
277
- getCursorId: (ctx) => `number-input:${ctx.uid}:cursor`,
309
+ getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
278
310
  getLabelId: (ctx) => {
279
311
  var _a, _b;
280
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.uid}:label`;
312
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
281
313
  },
282
314
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
283
315
  getIncButtonEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getIncButtonId(ctx)),
@@ -327,7 +359,7 @@ var dom = {
327
359
  </svg>`;
328
360
  doc.body.appendChild(el);
329
361
  }
330
- };
362
+ });
331
363
 
332
364
  // src/number-input.utils.ts
333
365
  var utils = {
@@ -573,12 +605,11 @@ var callAll2 = (...fns) => (...a) => {
573
605
 
574
606
  // src/number-input.machine.ts
575
607
  var { not, and } = import_core.guards;
576
- function machine(ctx = {}) {
608
+ function machine(ctx) {
577
609
  return (0, import_core.createMachine)({
578
610
  id: "number-input",
579
611
  initial: "unknown",
580
612
  context: __spreadProps(__spreadValues({
581
- uid: "",
582
613
  dir: "ltr",
583
614
  focusInputOnChange: true,
584
615
  clampValueOnBlur: true,
@@ -639,7 +670,7 @@ function machine(ctx = {}) {
639
670
  on: {
640
671
  SETUP: {
641
672
  target: "idle",
642
- actions: ["setupDocument", "syncInputValue"]
673
+ actions: "syncInputValue"
643
674
  }
644
675
  }
645
676
  },
@@ -845,13 +876,6 @@ function machine(ctx = {}) {
845
876
  }
846
877
  },
847
878
  actions: {
848
- setupDocument: (ctx2, evt) => {
849
- if (evt.doc)
850
- ctx2.doc = (0, import_core.ref)(evt.doc);
851
- if (evt.root)
852
- ctx2.rootNode = (0, import_core.ref)(evt.root);
853
- ctx2.uid = evt.id;
854
- },
855
879
  focusInput(ctx2) {
856
880
  if (!ctx2.focusInputOnChange)
857
881
  return;
package/dist/index.mjs CHANGED
@@ -19,6 +19,22 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
21
  // ../../utilities/dom/dist/index.mjs
22
+ var __defProp2 = Object.defineProperty;
23
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
24
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
25
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
26
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
27
+ var __spreadValues2 = (a, b) => {
28
+ for (var prop in b || (b = {}))
29
+ if (__hasOwnProp2.call(b, prop))
30
+ __defNormalProp2(a, prop, b[prop]);
31
+ if (__getOwnPropSymbols2)
32
+ for (var prop of __getOwnPropSymbols2(b)) {
33
+ if (__propIsEnum2.call(b, prop))
34
+ __defNormalProp2(a, prop, b[prop]);
35
+ }
36
+ return a;
37
+ };
22
38
  var dataAttr = (guard) => {
23
39
  return guard ? "" : void 0;
24
40
  };
@@ -51,6 +67,34 @@ var isMac = () => pt(/^Mac/) && !isTouchDevice;
51
67
  var isSafari = () => isApple() && vn(/apple/i);
52
68
  var isApple = () => pt(/mac|iphone|ipad|ipod/i);
53
69
  var isIos = () => isApple() && !isMac();
70
+ function isDocument(el) {
71
+ return el.nodeType === Node.DOCUMENT_NODE;
72
+ }
73
+ function isWindow(value) {
74
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
75
+ }
76
+ function getDocument(el) {
77
+ var _a;
78
+ if (isWindow(el))
79
+ return el.document;
80
+ if (isDocument(el))
81
+ return el;
82
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
83
+ }
84
+ function withRootHelpers(domUtils) {
85
+ const roots = {
86
+ getRootNode: (ctx) => {
87
+ var _a, _b;
88
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
89
+ },
90
+ getDoc: (ctx) => getDocument(roots.getRootNode(ctx)),
91
+ getWin: (ctx) => {
92
+ var _a;
93
+ return (_a = roots.getDoc(ctx).defaultView) != null ? _a : window;
94
+ }
95
+ };
96
+ return __spreadValues2(__spreadValues2({}, roots), domUtils);
97
+ }
54
98
  function getNativeEvent(e) {
55
99
  var _a;
56
100
  return (_a = e.nativeEvent) != null ? _a : e;
@@ -217,43 +261,31 @@ function decimalOperation(a, op, b) {
217
261
  var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
218
262
 
219
263
  // src/number-input.dom.ts
220
- var dom = {
221
- getDoc: (ctx) => {
222
- var _a;
223
- return (_a = ctx.doc) != null ? _a : document;
224
- },
225
- getWin: (ctx) => {
226
- var _a;
227
- return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
228
- },
229
- getRootNode: (ctx) => {
230
- var _a;
231
- return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
232
- },
264
+ var dom = withRootHelpers({
233
265
  getRootId: (ctx) => {
234
266
  var _a, _b;
235
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.uid}`;
267
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
236
268
  },
237
269
  getInputId: (ctx) => {
238
270
  var _a, _b;
239
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.uid}:input`;
271
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
240
272
  },
241
273
  getIncButtonId: (ctx) => {
242
274
  var _a, _b;
243
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.uid}:inc-btn`;
275
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
244
276
  },
245
277
  getDecButtonId: (ctx) => {
246
278
  var _a, _b;
247
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.uid}:dec-btn`;
279
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
248
280
  },
249
281
  getScrubberId: (ctx) => {
250
282
  var _a, _b;
251
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.uid}:scrubber`;
283
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
252
284
  },
253
- getCursorId: (ctx) => `number-input:${ctx.uid}:cursor`,
285
+ getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
254
286
  getLabelId: (ctx) => {
255
287
  var _a, _b;
256
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.uid}:label`;
288
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
257
289
  },
258
290
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
259
291
  getIncButtonEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getIncButtonId(ctx)),
@@ -303,7 +335,7 @@ var dom = {
303
335
  </svg>`;
304
336
  doc.body.appendChild(el);
305
337
  }
306
- };
338
+ });
307
339
 
308
340
  // src/number-input.utils.ts
309
341
  var utils = {
@@ -538,7 +570,7 @@ function connect(state, send, normalize) {
538
570
  }
539
571
 
540
572
  // src/number-input.machine.ts
541
- import { choose, createMachine, guards, ref } from "@zag-js/core";
573
+ import { choose, createMachine, guards } from "@zag-js/core";
542
574
 
543
575
  // ../../utilities/core/dist/index.mjs
544
576
  var callAll2 = (...fns) => (...a) => {
@@ -549,12 +581,11 @@ var callAll2 = (...fns) => (...a) => {
549
581
 
550
582
  // src/number-input.machine.ts
551
583
  var { not, and } = guards;
552
- function machine(ctx = {}) {
584
+ function machine(ctx) {
553
585
  return createMachine({
554
586
  id: "number-input",
555
587
  initial: "unknown",
556
588
  context: __spreadProps(__spreadValues({
557
- uid: "",
558
589
  dir: "ltr",
559
590
  focusInputOnChange: true,
560
591
  clampValueOnBlur: true,
@@ -615,7 +646,7 @@ function machine(ctx = {}) {
615
646
  on: {
616
647
  SETUP: {
617
648
  target: "idle",
618
- actions: ["setupDocument", "syncInputValue"]
649
+ actions: "syncInputValue"
619
650
  }
620
651
  }
621
652
  },
@@ -821,13 +852,6 @@ function machine(ctx = {}) {
821
852
  }
822
853
  },
823
854
  actions: {
824
- setupDocument: (ctx2, evt) => {
825
- if (evt.doc)
826
- ctx2.doc = ref(evt.doc);
827
- if (evt.root)
828
- ctx2.rootNode = ref(evt.root);
829
- ctx2.uid = evt.id;
830
- },
831
855
  focusInput(ctx2) {
832
856
  if (!ctx2.focusInputOnChange)
833
857
  return;
@@ -1,8 +1,15 @@
1
1
  import type { MachineContext as Ctx } from "./number-input.types";
2
2
  export declare const dom: {
3
- getDoc: (ctx: Ctx) => Document;
4
- getWin: (ctx: Ctx) => Window & typeof globalThis;
5
- getRootNode: (ctx: Ctx) => Document | ShadowRoot;
3
+ getRootNode: (ctx: {
4
+ getRootNode?: () => Node | Document | ShadowRoot;
5
+ }) => Document | ShadowRoot;
6
+ getDoc: (ctx: {
7
+ getRootNode?: () => Node | Document | ShadowRoot;
8
+ }) => Document;
9
+ getWin: (ctx: {
10
+ getRootNode?: () => Node | Document | ShadowRoot;
11
+ }) => Window & typeof globalThis;
12
+ } & {
6
13
  getRootId: (ctx: Ctx) => string;
7
14
  getInputId: (ctx: Ctx) => string;
8
15
  getIncButtonId: (ctx: Ctx) => string;
@@ -1,2 +1,2 @@
1
1
  import type { MachineContext, MachineState, UserDefinedContext } from "./number-input.types";
2
- export declare function machine(ctx?: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
2
+ export declare function machine(ctx: UserDefinedContext): import("@zag-js/core").Machine<MachineContext, MachineState, import("@zag-js/core").StateMachine.AnyEventObject>;
@@ -1,6 +1,6 @@
1
1
  import type { StateMachine as S } from "@zag-js/core";
2
2
  import type { FormatDecimalOptions } from "@zag-js/number-utils";
3
- import type { Context, DirectionProperty } from "@zag-js/types";
3
+ import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
4
4
  declare type ValidityState = "rangeUnderflow" | "rangeOverflow";
5
5
  declare type ElementIds = Partial<{
6
6
  root: string;
@@ -25,7 +25,7 @@ declare type IntlMessages = {
25
25
  */
26
26
  decrementLabel: string;
27
27
  };
28
- declare type PublicContext = DirectionProperty & FormatDecimalOptions & {
28
+ declare type PublicContext = DirectionProperty & CommonProperties & FormatDecimalOptions & {
29
29
  /**
30
30
  * The ids of the elements in the number input. Useful for composition.
31
31
  */
@@ -127,7 +127,7 @@ declare type PublicContext = DirectionProperty & FormatDecimalOptions & {
127
127
  valueAsNumber: number;
128
128
  }) => void;
129
129
  };
130
- export declare type UserDefinedContext = Partial<PublicContext>;
130
+ export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
131
131
  declare type ComputedContext = Readonly<{
132
132
  /**
133
133
  * @computed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/number-input",
3
- "version": "0.0.0-dev-20220707125149",
3
+ "version": "0.0.0-dev-20220709094318",
4
4
  "description": "Core logic for the number-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,10 +29,10 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/core": "0.0.0-dev-20220707125149",
33
- "@zag-js/dom-utils": "0.0.0-dev-20220707125149",
32
+ "@zag-js/core": "0.1.7",
33
+ "@zag-js/dom-utils": "0.0.0-dev-20220709094318",
34
34
  "@zag-js/number-utils": "0.1.2",
35
- "@zag-js/types": "0.0.0-dev-20220707125149",
35
+ "@zag-js/types": "0.0.0-dev-20220709094318",
36
36
  "@zag-js/utils": "0.1.2"
37
37
  },
38
38
  "scripts": {