@zag-js/number-input 0.1.19 → 0.2.0
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 +72 -38
- package/dist/index.mjs +72 -38
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var ariaAttr = (guard) => {
|
|
|
35
35
|
var MAX_Z_INDEX = 2147483647;
|
|
36
36
|
var runIfFn = (v, ...a) => {
|
|
37
37
|
const res = typeof v === "function" ? v(...a) : v;
|
|
38
|
-
return res
|
|
38
|
+
return res != null ? res : void 0;
|
|
39
39
|
};
|
|
40
40
|
var callAll = (...fns) => (...a) => {
|
|
41
41
|
fns.forEach(function(fn) {
|
|
@@ -47,8 +47,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
47
47
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
48
48
|
var isDom = () => typeof window !== "undefined";
|
|
49
49
|
function getPlatform() {
|
|
50
|
+
var _a;
|
|
50
51
|
const agent = navigator.userAgentData;
|
|
51
|
-
return (agent == null ? void 0 : agent.platform)
|
|
52
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
52
53
|
}
|
|
53
54
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
54
55
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
@@ -61,22 +62,44 @@ function isWindow(value) {
|
|
|
61
62
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
62
63
|
}
|
|
63
64
|
function getDocument(el) {
|
|
65
|
+
var _a;
|
|
64
66
|
if (isWindow(el))
|
|
65
67
|
return el.document;
|
|
66
68
|
if (isDocument(el))
|
|
67
69
|
return el;
|
|
68
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
70
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
69
71
|
}
|
|
70
72
|
function defineDomHelpers(helpers) {
|
|
71
73
|
const dom2 = {
|
|
72
74
|
getRootNode: (ctx) => {
|
|
73
|
-
var _a;
|
|
74
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx))
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
75
77
|
},
|
|
76
78
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
77
|
-
getWin: (ctx) =>
|
|
79
|
+
getWin: (ctx) => {
|
|
80
|
+
var _a;
|
|
81
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
82
|
+
},
|
|
78
83
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
79
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
84
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
85
|
+
createEmitter: (ctx, target) => {
|
|
86
|
+
const win = dom2.getWin(ctx);
|
|
87
|
+
return function emit(evt, detail, options) {
|
|
88
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
89
|
+
const eventName = `zag:${evt}`;
|
|
90
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
91
|
+
const event = new win.CustomEvent(eventName, init);
|
|
92
|
+
target.dispatchEvent(event);
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
createListener: (target) => {
|
|
96
|
+
return function listen(evt, handler) {
|
|
97
|
+
const eventName = `zag:${evt}`;
|
|
98
|
+
const listener = (e) => handler(e);
|
|
99
|
+
target.addEventListener(eventName, listener);
|
|
100
|
+
return () => target.removeEventListener(eventName, listener);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
80
103
|
};
|
|
81
104
|
return {
|
|
82
105
|
...dom2,
|
|
@@ -84,7 +107,8 @@ function defineDomHelpers(helpers) {
|
|
|
84
107
|
};
|
|
85
108
|
}
|
|
86
109
|
function getNativeEvent(e) {
|
|
87
|
-
|
|
110
|
+
var _a;
|
|
111
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
88
112
|
}
|
|
89
113
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
90
114
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
@@ -97,7 +121,8 @@ var fallback = {
|
|
|
97
121
|
clientY: 0
|
|
98
122
|
};
|
|
99
123
|
function getEventPoint(event, type = "page") {
|
|
100
|
-
|
|
124
|
+
var _a, _b;
|
|
125
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
101
126
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
102
127
|
}
|
|
103
128
|
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
@@ -251,29 +276,29 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
|
|
|
251
276
|
// src/number-input.dom.ts
|
|
252
277
|
var dom = defineDomHelpers({
|
|
253
278
|
getRootId: (ctx) => {
|
|
254
|
-
var _a;
|
|
255
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.root)
|
|
279
|
+
var _a, _b;
|
|
280
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
|
|
256
281
|
},
|
|
257
282
|
getInputId: (ctx) => {
|
|
258
|
-
var _a;
|
|
259
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.input)
|
|
283
|
+
var _a, _b;
|
|
284
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
|
|
260
285
|
},
|
|
261
286
|
getIncButtonId: (ctx) => {
|
|
262
|
-
var _a;
|
|
263
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.incBtn)
|
|
287
|
+
var _a, _b;
|
|
288
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
|
|
264
289
|
},
|
|
265
290
|
getDecButtonId: (ctx) => {
|
|
266
|
-
var _a;
|
|
267
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.decBtn)
|
|
291
|
+
var _a, _b;
|
|
292
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
|
|
268
293
|
},
|
|
269
294
|
getScrubberId: (ctx) => {
|
|
270
|
-
var _a;
|
|
271
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.scrubber)
|
|
295
|
+
var _a, _b;
|
|
296
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
|
|
272
297
|
},
|
|
273
298
|
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
274
299
|
getLabelId: (ctx) => {
|
|
275
|
-
var _a;
|
|
276
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.label)
|
|
300
|
+
var _a, _b;
|
|
301
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
|
|
277
302
|
},
|
|
278
303
|
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
279
304
|
getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
|
|
@@ -366,38 +391,39 @@ var dom = defineDomHelpers({
|
|
|
366
391
|
// src/number-input.utils.ts
|
|
367
392
|
var utils = {
|
|
368
393
|
isValidNumericEvent: (ctx, event) => {
|
|
369
|
-
var _a;
|
|
394
|
+
var _a, _b;
|
|
370
395
|
if (event.key == null)
|
|
371
396
|
return true;
|
|
372
397
|
const isModifier = isModifiedEvent(event);
|
|
373
398
|
const isSingleKey = event.key.length === 1;
|
|
374
399
|
if (isModifier || !isSingleKey)
|
|
375
400
|
return true;
|
|
376
|
-
return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key))
|
|
401
|
+
return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
|
|
377
402
|
},
|
|
378
403
|
isFloatingPoint: (v) => /^[0-9+\-.]$/.test(v),
|
|
379
404
|
sanitize: (ctx, value) => {
|
|
380
|
-
|
|
405
|
+
var _a;
|
|
406
|
+
return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
|
|
381
407
|
},
|
|
382
408
|
increment: (ctx, step) => {
|
|
383
|
-
const value = increment(ctx.value, step
|
|
409
|
+
const value = increment(ctx.value, step != null ? step : ctx.step);
|
|
384
410
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
385
411
|
},
|
|
386
412
|
decrement: (ctx, step) => {
|
|
387
|
-
const value = decrement(ctx.value, step
|
|
413
|
+
const value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
388
414
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
389
415
|
},
|
|
390
416
|
clamp: (ctx) => {
|
|
391
417
|
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
392
418
|
},
|
|
393
419
|
parse: (ctx, value) => {
|
|
394
|
-
var _a;
|
|
395
|
-
return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value))
|
|
420
|
+
var _a, _b;
|
|
421
|
+
return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
|
|
396
422
|
},
|
|
397
423
|
format: (ctx, value) => {
|
|
398
|
-
var _a;
|
|
424
|
+
var _a, _b;
|
|
399
425
|
const _val = value.toString();
|
|
400
|
-
return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val))
|
|
426
|
+
return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
|
|
401
427
|
},
|
|
402
428
|
round: (ctx) => {
|
|
403
429
|
return formatDecimal(ctx.value, ctx);
|
|
@@ -610,12 +636,14 @@ var callAll2 = (...fns) => (...a) => {
|
|
|
610
636
|
|
|
611
637
|
// ../../utilities/form-utils/dist/index.mjs
|
|
612
638
|
function getWindow(el) {
|
|
613
|
-
|
|
639
|
+
var _a;
|
|
640
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
614
641
|
}
|
|
615
642
|
function getDescriptor(el, options) {
|
|
643
|
+
var _a;
|
|
616
644
|
const { type, property } = options;
|
|
617
645
|
const proto = getWindow(el)[type].prototype;
|
|
618
|
-
return Object.getOwnPropertyDescriptor(proto, property)
|
|
646
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
619
647
|
}
|
|
620
648
|
function dispatchInputValueEvent(el, value) {
|
|
621
649
|
var _a;
|
|
@@ -673,8 +701,8 @@ function machine(ctx) {
|
|
|
673
701
|
return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
674
702
|
},
|
|
675
703
|
formattedValue: (ctx2) => {
|
|
676
|
-
var _a;
|
|
677
|
-
return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString())
|
|
704
|
+
var _a, _b;
|
|
705
|
+
return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
|
|
678
706
|
}
|
|
679
707
|
},
|
|
680
708
|
watch: {
|
|
@@ -844,9 +872,15 @@ function machine(ctx) {
|
|
|
844
872
|
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
845
873
|
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
846
874
|
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
847
|
-
isDecrementHint: (ctx2, evt) =>
|
|
875
|
+
isDecrementHint: (ctx2, evt) => {
|
|
876
|
+
var _a;
|
|
877
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
878
|
+
},
|
|
848
879
|
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
849
|
-
isIncrementHint: (ctx2, evt) =>
|
|
880
|
+
isIncrementHint: (ctx2, evt) => {
|
|
881
|
+
var _a;
|
|
882
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
883
|
+
},
|
|
850
884
|
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
851
885
|
},
|
|
852
886
|
activities: {
|
|
@@ -928,8 +962,8 @@ function machine(ctx) {
|
|
|
928
962
|
}
|
|
929
963
|
},
|
|
930
964
|
setValue(ctx2, evt) {
|
|
931
|
-
var _a;
|
|
932
|
-
const value = ((_a = evt.target) == null ? void 0 : _a.value)
|
|
965
|
+
var _a, _b;
|
|
966
|
+
const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
|
|
933
967
|
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
934
968
|
},
|
|
935
969
|
clearValue(ctx2) {
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var ariaAttr = (guard) => {
|
|
|
8
8
|
var MAX_Z_INDEX = 2147483647;
|
|
9
9
|
var runIfFn = (v, ...a) => {
|
|
10
10
|
const res = typeof v === "function" ? v(...a) : v;
|
|
11
|
-
return res
|
|
11
|
+
return res != null ? res : void 0;
|
|
12
12
|
};
|
|
13
13
|
var callAll = (...fns) => (...a) => {
|
|
14
14
|
fns.forEach(function(fn) {
|
|
@@ -20,8 +20,9 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
20
20
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
21
21
|
var isDom = () => typeof window !== "undefined";
|
|
22
22
|
function getPlatform() {
|
|
23
|
+
var _a;
|
|
23
24
|
const agent = navigator.userAgentData;
|
|
24
|
-
return (agent == null ? void 0 : agent.platform)
|
|
25
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
25
26
|
}
|
|
26
27
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
27
28
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
@@ -34,22 +35,44 @@ function isWindow(value) {
|
|
|
34
35
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
35
36
|
}
|
|
36
37
|
function getDocument(el) {
|
|
38
|
+
var _a;
|
|
37
39
|
if (isWindow(el))
|
|
38
40
|
return el.document;
|
|
39
41
|
if (isDocument(el))
|
|
40
42
|
return el;
|
|
41
|
-
return (el == null ? void 0 : el.ownerDocument)
|
|
43
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
42
44
|
}
|
|
43
45
|
function defineDomHelpers(helpers) {
|
|
44
46
|
const dom2 = {
|
|
45
47
|
getRootNode: (ctx) => {
|
|
46
|
-
var _a;
|
|
47
|
-
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx))
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
48
50
|
},
|
|
49
51
|
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
50
|
-
getWin: (ctx) =>
|
|
52
|
+
getWin: (ctx) => {
|
|
53
|
+
var _a;
|
|
54
|
+
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
55
|
+
},
|
|
51
56
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
52
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
57
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
58
|
+
createEmitter: (ctx, target) => {
|
|
59
|
+
const win = dom2.getWin(ctx);
|
|
60
|
+
return function emit(evt, detail, options) {
|
|
61
|
+
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
62
|
+
const eventName = `zag:${evt}`;
|
|
63
|
+
const init = { bubbles, cancelable, composed, detail };
|
|
64
|
+
const event = new win.CustomEvent(eventName, init);
|
|
65
|
+
target.dispatchEvent(event);
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
createListener: (target) => {
|
|
69
|
+
return function listen(evt, handler) {
|
|
70
|
+
const eventName = `zag:${evt}`;
|
|
71
|
+
const listener = (e) => handler(e);
|
|
72
|
+
target.addEventListener(eventName, listener);
|
|
73
|
+
return () => target.removeEventListener(eventName, listener);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
53
76
|
};
|
|
54
77
|
return {
|
|
55
78
|
...dom2,
|
|
@@ -57,7 +80,8 @@ function defineDomHelpers(helpers) {
|
|
|
57
80
|
};
|
|
58
81
|
}
|
|
59
82
|
function getNativeEvent(e) {
|
|
60
|
-
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = e.nativeEvent) != null ? _a : e;
|
|
61
85
|
}
|
|
62
86
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
63
87
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
@@ -70,7 +94,8 @@ var fallback = {
|
|
|
70
94
|
clientY: 0
|
|
71
95
|
};
|
|
72
96
|
function getEventPoint(event, type = "page") {
|
|
73
|
-
|
|
97
|
+
var _a, _b;
|
|
98
|
+
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
74
99
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
75
100
|
}
|
|
76
101
|
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
@@ -224,29 +249,29 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
|
|
|
224
249
|
// src/number-input.dom.ts
|
|
225
250
|
var dom = defineDomHelpers({
|
|
226
251
|
getRootId: (ctx) => {
|
|
227
|
-
var _a;
|
|
228
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.root)
|
|
252
|
+
var _a, _b;
|
|
253
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `number-input:${ctx.id}`;
|
|
229
254
|
},
|
|
230
255
|
getInputId: (ctx) => {
|
|
231
|
-
var _a;
|
|
232
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.input)
|
|
256
|
+
var _a, _b;
|
|
257
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.input) != null ? _b : `number-input:${ctx.id}:input`;
|
|
233
258
|
},
|
|
234
259
|
getIncButtonId: (ctx) => {
|
|
235
|
-
var _a;
|
|
236
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.incBtn)
|
|
260
|
+
var _a, _b;
|
|
261
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.incBtn) != null ? _b : `number-input:${ctx.id}:inc-btn`;
|
|
237
262
|
},
|
|
238
263
|
getDecButtonId: (ctx) => {
|
|
239
|
-
var _a;
|
|
240
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.decBtn)
|
|
264
|
+
var _a, _b;
|
|
265
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.decBtn) != null ? _b : `number-input:${ctx.id}:dec-btn`;
|
|
241
266
|
},
|
|
242
267
|
getScrubberId: (ctx) => {
|
|
243
|
-
var _a;
|
|
244
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.scrubber)
|
|
268
|
+
var _a, _b;
|
|
269
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.scrubber) != null ? _b : `number-input:${ctx.id}:scrubber`;
|
|
245
270
|
},
|
|
246
271
|
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
247
272
|
getLabelId: (ctx) => {
|
|
248
|
-
var _a;
|
|
249
|
-
return ((_a = ctx.ids) == null ? void 0 : _a.label)
|
|
273
|
+
var _a, _b;
|
|
274
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.label) != null ? _b : `number-input:${ctx.id}:label`;
|
|
250
275
|
},
|
|
251
276
|
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
252
277
|
getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
|
|
@@ -339,38 +364,39 @@ var dom = defineDomHelpers({
|
|
|
339
364
|
// src/number-input.utils.ts
|
|
340
365
|
var utils = {
|
|
341
366
|
isValidNumericEvent: (ctx, event) => {
|
|
342
|
-
var _a;
|
|
367
|
+
var _a, _b;
|
|
343
368
|
if (event.key == null)
|
|
344
369
|
return true;
|
|
345
370
|
const isModifier = isModifiedEvent(event);
|
|
346
371
|
const isSingleKey = event.key.length === 1;
|
|
347
372
|
if (isModifier || !isSingleKey)
|
|
348
373
|
return true;
|
|
349
|
-
return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key))
|
|
374
|
+
return (_b = (_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) != null ? _b : utils.isFloatingPoint(event.key);
|
|
350
375
|
},
|
|
351
376
|
isFloatingPoint: (v) => /^[0-9+\-.]$/.test(v),
|
|
352
377
|
sanitize: (ctx, value) => {
|
|
353
|
-
|
|
378
|
+
var _a;
|
|
379
|
+
return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
|
|
354
380
|
},
|
|
355
381
|
increment: (ctx, step) => {
|
|
356
|
-
const value = increment(ctx.value, step
|
|
382
|
+
const value = increment(ctx.value, step != null ? step : ctx.step);
|
|
357
383
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
358
384
|
},
|
|
359
385
|
decrement: (ctx, step) => {
|
|
360
|
-
const value = decrement(ctx.value, step
|
|
386
|
+
const value = decrement(ctx.value, step != null ? step : ctx.step);
|
|
361
387
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
362
388
|
},
|
|
363
389
|
clamp: (ctx) => {
|
|
364
390
|
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
365
391
|
},
|
|
366
392
|
parse: (ctx, value) => {
|
|
367
|
-
var _a;
|
|
368
|
-
return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value))
|
|
393
|
+
var _a, _b;
|
|
394
|
+
return (_b = (_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) != null ? _b : value;
|
|
369
395
|
},
|
|
370
396
|
format: (ctx, value) => {
|
|
371
|
-
var _a;
|
|
397
|
+
var _a, _b;
|
|
372
398
|
const _val = value.toString();
|
|
373
|
-
return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val))
|
|
399
|
+
return (_b = (_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) != null ? _b : _val;
|
|
374
400
|
},
|
|
375
401
|
round: (ctx) => {
|
|
376
402
|
return formatDecimal(ctx.value, ctx);
|
|
@@ -583,12 +609,14 @@ var callAll2 = (...fns) => (...a) => {
|
|
|
583
609
|
|
|
584
610
|
// ../../utilities/form-utils/dist/index.mjs
|
|
585
611
|
function getWindow(el) {
|
|
586
|
-
|
|
612
|
+
var _a;
|
|
613
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
587
614
|
}
|
|
588
615
|
function getDescriptor(el, options) {
|
|
616
|
+
var _a;
|
|
589
617
|
const { type, property } = options;
|
|
590
618
|
const proto = getWindow(el)[type].prototype;
|
|
591
|
-
return Object.getOwnPropertyDescriptor(proto, property)
|
|
619
|
+
return (_a = Object.getOwnPropertyDescriptor(proto, property)) != null ? _a : {};
|
|
592
620
|
}
|
|
593
621
|
function dispatchInputValueEvent(el, value) {
|
|
594
622
|
var _a;
|
|
@@ -646,8 +674,8 @@ function machine(ctx) {
|
|
|
646
674
|
return (_b = (_a = ctx2.translations).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
647
675
|
},
|
|
648
676
|
formattedValue: (ctx2) => {
|
|
649
|
-
var _a;
|
|
650
|
-
return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString())
|
|
677
|
+
var _a, _b;
|
|
678
|
+
return (_b = (_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) != null ? _b : ctx2.value;
|
|
651
679
|
}
|
|
652
680
|
},
|
|
653
681
|
watch: {
|
|
@@ -817,9 +845,15 @@ function machine(ctx) {
|
|
|
817
845
|
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
818
846
|
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
819
847
|
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
820
|
-
isDecrementHint: (ctx2, evt) =>
|
|
848
|
+
isDecrementHint: (ctx2, evt) => {
|
|
849
|
+
var _a;
|
|
850
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
851
|
+
},
|
|
821
852
|
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
822
|
-
isIncrementHint: (ctx2, evt) =>
|
|
853
|
+
isIncrementHint: (ctx2, evt) => {
|
|
854
|
+
var _a;
|
|
855
|
+
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
856
|
+
},
|
|
823
857
|
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
824
858
|
},
|
|
825
859
|
activities: {
|
|
@@ -901,8 +935,8 @@ function machine(ctx) {
|
|
|
901
935
|
}
|
|
902
936
|
},
|
|
903
937
|
setValue(ctx2, evt) {
|
|
904
|
-
var _a;
|
|
905
|
-
const value = ((_a = evt.target) == null ? void 0 : _a.value)
|
|
938
|
+
var _a, _b;
|
|
939
|
+
const value = (_b = (_a = evt.target) == null ? void 0 : _a.value) != null ? _b : evt.value;
|
|
906
940
|
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
907
941
|
},
|
|
908
942
|
clearValue(ctx2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.
|
|
33
|
-
"@zag-js/types": "0.
|
|
32
|
+
"@zag-js/core": "0.2.0",
|
|
33
|
+
"@zag-js/types": "0.3.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zag-js/dom-utils": "0.
|
|
37
|
-
"@zag-js/form-utils": "0.
|
|
38
|
-
"@zag-js/number-utils": "0.
|
|
39
|
-
"@zag-js/utils": "0.
|
|
36
|
+
"@zag-js/dom-utils": "0.2.0",
|
|
37
|
+
"@zag-js/form-utils": "0.2.0",
|
|
38
|
+
"@zag-js/number-utils": "0.2.0",
|
|
39
|
+
"@zag-js/utils": "0.2.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build-fast": "tsup src/index.ts --format=esm,cjs",
|