@zag-js/number-input 0.0.0-dev-20220704151659 → 0.0.0-dev-20220707125149
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 +43 -37
- package/dist/index.mjs +43 -37
- package/dist/number-input.connect.d.ts +1 -0
- package/dist/number-input.types.d.ts +5 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -50,10 +50,39 @@ var ariaAttr = (guard) => {
|
|
|
50
50
|
return guard ? "true" : void 0;
|
|
51
51
|
};
|
|
52
52
|
var MAX_Z_INDEX = 2147483647;
|
|
53
|
+
var runIfFn = (v, ...a) => {
|
|
54
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
55
|
+
return res != null ? res : void 0;
|
|
56
|
+
};
|
|
57
|
+
var callAll = (...fns) => (...a) => {
|
|
58
|
+
fns.forEach(function(fn) {
|
|
59
|
+
fn == null ? void 0 : fn(...a);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
var isArray = (v) => Array.isArray(v);
|
|
63
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
64
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
65
|
+
var isDom = () => typeof window !== "undefined";
|
|
66
|
+
function getPlatform() {
|
|
67
|
+
var _a;
|
|
68
|
+
const agent = navigator.userAgentData;
|
|
69
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
70
|
+
}
|
|
71
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
72
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
73
|
+
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
74
|
+
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
75
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
76
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
77
|
+
var isIos = () => isApple() && !isMac();
|
|
53
78
|
function getNativeEvent(e) {
|
|
54
79
|
var _a;
|
|
55
80
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
56
81
|
}
|
|
82
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
83
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
84
|
+
var isLeftClick = (v) => v.button === 0;
|
|
85
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
57
86
|
function observeAttributes(node, attributes, fn) {
|
|
58
87
|
if (!node)
|
|
59
88
|
return;
|
|
@@ -69,19 +98,6 @@ function observeAttributes(node, attributes, fn) {
|
|
|
69
98
|
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
70
99
|
return () => obs.disconnect();
|
|
71
100
|
}
|
|
72
|
-
var isArray = (v) => Array.isArray(v);
|
|
73
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
74
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
75
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
76
|
-
var runIfFn = (v, ...a) => {
|
|
77
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
78
|
-
return res != null ? res : void 0;
|
|
79
|
-
};
|
|
80
|
-
var callAll = (...fns) => (...a) => {
|
|
81
|
-
fns.forEach(function(fn) {
|
|
82
|
-
fn == null ? void 0 : fn(...a);
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
101
|
var fallback = {
|
|
86
102
|
pageX: 0,
|
|
87
103
|
pageY: 0,
|
|
@@ -224,29 +240,6 @@ function decimalOperation(a, op, b) {
|
|
|
224
240
|
}
|
|
225
241
|
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
226
242
|
|
|
227
|
-
// ../../utilities/core/dist/index.mjs
|
|
228
|
-
var isDom = () => typeof window !== "undefined";
|
|
229
|
-
function getPlatform() {
|
|
230
|
-
var _a;
|
|
231
|
-
const agent = navigator.userAgentData;
|
|
232
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
233
|
-
}
|
|
234
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
235
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
236
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
237
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
238
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
239
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
240
|
-
var isIos = () => isApple() && !isMac();
|
|
241
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
242
|
-
var isLeftClick = (v) => v.button === 0;
|
|
243
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
244
|
-
var callAll2 = (...fns) => (...a) => {
|
|
245
|
-
fns.forEach(function(fn) {
|
|
246
|
-
fn == null ? void 0 : fn(...a);
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
|
|
250
243
|
// src/number-input.dom.ts
|
|
251
244
|
var dom = {
|
|
252
245
|
getDoc: (ctx) => {
|
|
@@ -383,12 +376,14 @@ function connect(state, send, normalize) {
|
|
|
383
376
|
const isFocused = state.hasTag("focus");
|
|
384
377
|
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
385
378
|
const isDisabled = !!state.context.disabled;
|
|
379
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
386
380
|
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
387
381
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
388
382
|
const messages = state.context.messages;
|
|
389
383
|
return {
|
|
390
384
|
isFocused,
|
|
391
385
|
isInvalid,
|
|
386
|
+
isValueEmpty,
|
|
392
387
|
value: state.context.formattedValue,
|
|
393
388
|
valueAsNumber: state.context.valueAsNumber,
|
|
394
389
|
setValue(value) {
|
|
@@ -568,6 +563,15 @@ function connect(state, send, normalize) {
|
|
|
568
563
|
|
|
569
564
|
// src/number-input.machine.ts
|
|
570
565
|
var import_core = require("@zag-js/core");
|
|
566
|
+
|
|
567
|
+
// ../../utilities/core/dist/index.mjs
|
|
568
|
+
var callAll2 = (...fns) => (...a) => {
|
|
569
|
+
fns.forEach(function(fn) {
|
|
570
|
+
fn == null ? void 0 : fn(...a);
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// src/number-input.machine.ts
|
|
571
575
|
var { not, and } = import_core.guards;
|
|
572
576
|
function machine(ctx = {}) {
|
|
573
577
|
return (0, import_core.createMachine)({
|
|
@@ -600,6 +604,7 @@ function machine(ctx = {}) {
|
|
|
600
604
|
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
601
605
|
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
602
606
|
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
607
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
603
608
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
604
609
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
605
610
|
valueText: (ctx2) => {
|
|
@@ -686,7 +691,7 @@ function machine(ctx = {}) {
|
|
|
686
691
|
actions: ["clearValue", "clearHint"]
|
|
687
692
|
},
|
|
688
693
|
{
|
|
689
|
-
guard: and("clampOnBlur", not("isInRange")),
|
|
694
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
690
695
|
target: "idle",
|
|
691
696
|
actions: ["clampValue", "clearHint"]
|
|
692
697
|
},
|
|
@@ -776,6 +781,7 @@ function machine(ctx = {}) {
|
|
|
776
781
|
var _a;
|
|
777
782
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
778
783
|
},
|
|
784
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
779
785
|
isIncrementHint: (ctx2, evt) => {
|
|
780
786
|
var _a;
|
|
781
787
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
package/dist/index.mjs
CHANGED
|
@@ -26,10 +26,39 @@ var ariaAttr = (guard) => {
|
|
|
26
26
|
return guard ? "true" : void 0;
|
|
27
27
|
};
|
|
28
28
|
var MAX_Z_INDEX = 2147483647;
|
|
29
|
+
var runIfFn = (v, ...a) => {
|
|
30
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
31
|
+
return res != null ? res : void 0;
|
|
32
|
+
};
|
|
33
|
+
var callAll = (...fns) => (...a) => {
|
|
34
|
+
fns.forEach(function(fn) {
|
|
35
|
+
fn == null ? void 0 : fn(...a);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var isArray = (v) => Array.isArray(v);
|
|
39
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
40
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
41
|
+
var isDom = () => typeof window !== "undefined";
|
|
42
|
+
function getPlatform() {
|
|
43
|
+
var _a;
|
|
44
|
+
const agent = navigator.userAgentData;
|
|
45
|
+
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
46
|
+
}
|
|
47
|
+
var pt = (v) => isDom() && v.test(getPlatform());
|
|
48
|
+
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
49
|
+
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
50
|
+
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
51
|
+
var isSafari = () => isApple() && vn(/apple/i);
|
|
52
|
+
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
53
|
+
var isIos = () => isApple() && !isMac();
|
|
29
54
|
function getNativeEvent(e) {
|
|
30
55
|
var _a;
|
|
31
56
|
return (_a = e.nativeEvent) != null ? _a : e;
|
|
32
57
|
}
|
|
58
|
+
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
59
|
+
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
60
|
+
var isLeftClick = (v) => v.button === 0;
|
|
61
|
+
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
33
62
|
function observeAttributes(node, attributes, fn) {
|
|
34
63
|
if (!node)
|
|
35
64
|
return;
|
|
@@ -45,19 +74,6 @@ function observeAttributes(node, attributes, fn) {
|
|
|
45
74
|
obs.observe(node, { attributes: true, attributeFilter: attrs });
|
|
46
75
|
return () => obs.disconnect();
|
|
47
76
|
}
|
|
48
|
-
var isArray = (v) => Array.isArray(v);
|
|
49
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
50
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
51
|
-
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
52
|
-
var runIfFn = (v, ...a) => {
|
|
53
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
54
|
-
return res != null ? res : void 0;
|
|
55
|
-
};
|
|
56
|
-
var callAll = (...fns) => (...a) => {
|
|
57
|
-
fns.forEach(function(fn) {
|
|
58
|
-
fn == null ? void 0 : fn(...a);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
77
|
var fallback = {
|
|
62
78
|
pageX: 0,
|
|
63
79
|
pageY: 0,
|
|
@@ -200,29 +216,6 @@ function decimalOperation(a, op, b) {
|
|
|
200
216
|
}
|
|
201
217
|
var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
|
|
202
218
|
|
|
203
|
-
// ../../utilities/core/dist/index.mjs
|
|
204
|
-
var isDom = () => typeof window !== "undefined";
|
|
205
|
-
function getPlatform() {
|
|
206
|
-
var _a;
|
|
207
|
-
const agent = navigator.userAgentData;
|
|
208
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
209
|
-
}
|
|
210
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
211
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
212
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
213
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
214
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
215
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
216
|
-
var isIos = () => isApple() && !isMac();
|
|
217
|
-
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
218
|
-
var isLeftClick = (v) => v.button === 0;
|
|
219
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
220
|
-
var callAll2 = (...fns) => (...a) => {
|
|
221
|
-
fns.forEach(function(fn) {
|
|
222
|
-
fn == null ? void 0 : fn(...a);
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
|
|
226
219
|
// src/number-input.dom.ts
|
|
227
220
|
var dom = {
|
|
228
221
|
getDoc: (ctx) => {
|
|
@@ -359,12 +352,14 @@ function connect(state, send, normalize) {
|
|
|
359
352
|
const isFocused = state.hasTag("focus");
|
|
360
353
|
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
361
354
|
const isDisabled = !!state.context.disabled;
|
|
355
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
362
356
|
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
363
357
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
364
358
|
const messages = state.context.messages;
|
|
365
359
|
return {
|
|
366
360
|
isFocused,
|
|
367
361
|
isInvalid,
|
|
362
|
+
isValueEmpty,
|
|
368
363
|
value: state.context.formattedValue,
|
|
369
364
|
valueAsNumber: state.context.valueAsNumber,
|
|
370
365
|
setValue(value) {
|
|
@@ -544,6 +539,15 @@ function connect(state, send, normalize) {
|
|
|
544
539
|
|
|
545
540
|
// src/number-input.machine.ts
|
|
546
541
|
import { choose, createMachine, guards, ref } from "@zag-js/core";
|
|
542
|
+
|
|
543
|
+
// ../../utilities/core/dist/index.mjs
|
|
544
|
+
var callAll2 = (...fns) => (...a) => {
|
|
545
|
+
fns.forEach(function(fn) {
|
|
546
|
+
fn == null ? void 0 : fn(...a);
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// src/number-input.machine.ts
|
|
547
551
|
var { not, and } = guards;
|
|
548
552
|
function machine(ctx = {}) {
|
|
549
553
|
return createMachine({
|
|
@@ -576,6 +580,7 @@ function machine(ctx = {}) {
|
|
|
576
580
|
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
577
581
|
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
578
582
|
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
583
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
579
584
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
580
585
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
581
586
|
valueText: (ctx2) => {
|
|
@@ -662,7 +667,7 @@ function machine(ctx = {}) {
|
|
|
662
667
|
actions: ["clearValue", "clearHint"]
|
|
663
668
|
},
|
|
664
669
|
{
|
|
665
|
-
guard: and("clampOnBlur", not("isInRange")),
|
|
670
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
666
671
|
target: "idle",
|
|
667
672
|
actions: ["clampValue", "clearHint"]
|
|
668
673
|
},
|
|
@@ -752,6 +757,7 @@ function machine(ctx = {}) {
|
|
|
752
757
|
var _a;
|
|
753
758
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
754
759
|
},
|
|
760
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
755
761
|
isIncrementHint: (ctx2, evt) => {
|
|
756
762
|
var _a;
|
|
757
763
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
@@ -3,6 +3,7 @@ import type { Send, State } from "./number-input.types";
|
|
|
3
3
|
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
4
|
isFocused: boolean;
|
|
5
5
|
isInvalid: boolean;
|
|
6
|
+
isValueEmpty: boolean;
|
|
6
7
|
value: string;
|
|
7
8
|
valueAsNumber: number;
|
|
8
9
|
setValue(value: string | number): void;
|
|
@@ -149,6 +149,11 @@ declare type ComputedContext = Readonly<{
|
|
|
149
149
|
* Whether the value is out of the min/max range
|
|
150
150
|
*/
|
|
151
151
|
isOutOfRange: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* @computed
|
|
154
|
+
* Whether the value is empty
|
|
155
|
+
*/
|
|
156
|
+
isValueEmpty: boolean;
|
|
152
157
|
/**
|
|
153
158
|
* @computed
|
|
154
159
|
* Whether the increment button is enabled
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220707125149",
|
|
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-
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.0.0-dev-20220707125149",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220707125149",
|
|
34
34
|
"@zag-js/number-utils": "0.1.2",
|
|
35
|
-
"@zag-js/types": "0.0.0-dev-
|
|
35
|
+
"@zag-js/types": "0.0.0-dev-20220707125149",
|
|
36
36
|
"@zag-js/utils": "0.1.2"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|