@zag-js/number-input 0.0.0-dev-20220704163406 → 0.0.0-dev-20220708193601
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 +60 -32
- package/dist/index.mjs +61 -33
- package/dist/number-input.connect.d.ts +1 -0
- package/dist/number-input.dom.d.ts +10 -3
- package/dist/number-input.machine.d.ts +1 -1
- package/dist/number-input.types.d.ts +8 -3
- package/package.json +4 -4
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 = {
|
|
@@ -376,12 +408,14 @@ function connect(state, send, normalize) {
|
|
|
376
408
|
const isFocused = state.hasTag("focus");
|
|
377
409
|
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
378
410
|
const isDisabled = !!state.context.disabled;
|
|
411
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
379
412
|
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
380
413
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
381
414
|
const messages = state.context.messages;
|
|
382
415
|
return {
|
|
383
416
|
isFocused,
|
|
384
417
|
isInvalid,
|
|
418
|
+
isValueEmpty,
|
|
385
419
|
value: state.context.formattedValue,
|
|
386
420
|
valueAsNumber: state.context.valueAsNumber,
|
|
387
421
|
setValue(value) {
|
|
@@ -571,12 +605,11 @@ var callAll2 = (...fns) => (...a) => {
|
|
|
571
605
|
|
|
572
606
|
// src/number-input.machine.ts
|
|
573
607
|
var { not, and } = import_core.guards;
|
|
574
|
-
function machine(ctx
|
|
608
|
+
function machine(ctx) {
|
|
575
609
|
return (0, import_core.createMachine)({
|
|
576
610
|
id: "number-input",
|
|
577
611
|
initial: "unknown",
|
|
578
612
|
context: __spreadProps(__spreadValues({
|
|
579
|
-
uid: "",
|
|
580
613
|
dir: "ltr",
|
|
581
614
|
focusInputOnChange: true,
|
|
582
615
|
clampValueOnBlur: true,
|
|
@@ -602,6 +635,7 @@ function machine(ctx = {}) {
|
|
|
602
635
|
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
603
636
|
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
604
637
|
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
638
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
605
639
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
606
640
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
607
641
|
valueText: (ctx2) => {
|
|
@@ -636,7 +670,7 @@ function machine(ctx = {}) {
|
|
|
636
670
|
on: {
|
|
637
671
|
SETUP: {
|
|
638
672
|
target: "idle",
|
|
639
|
-
actions:
|
|
673
|
+
actions: "syncInputValue"
|
|
640
674
|
}
|
|
641
675
|
}
|
|
642
676
|
},
|
|
@@ -688,7 +722,7 @@ function machine(ctx = {}) {
|
|
|
688
722
|
actions: ["clearValue", "clearHint"]
|
|
689
723
|
},
|
|
690
724
|
{
|
|
691
|
-
guard: and("clampOnBlur", not("isInRange")),
|
|
725
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
692
726
|
target: "idle",
|
|
693
727
|
actions: ["clampValue", "clearHint"]
|
|
694
728
|
},
|
|
@@ -778,6 +812,7 @@ function machine(ctx = {}) {
|
|
|
778
812
|
var _a;
|
|
779
813
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
780
814
|
},
|
|
815
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
781
816
|
isIncrementHint: (ctx2, evt) => {
|
|
782
817
|
var _a;
|
|
783
818
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
@@ -841,13 +876,6 @@ function machine(ctx = {}) {
|
|
|
841
876
|
}
|
|
842
877
|
},
|
|
843
878
|
actions: {
|
|
844
|
-
setupDocument: (ctx2, evt) => {
|
|
845
|
-
if (evt.doc)
|
|
846
|
-
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
847
|
-
if (evt.root)
|
|
848
|
-
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
849
|
-
ctx2.uid = evt.id;
|
|
850
|
-
},
|
|
851
879
|
focusInput(ctx2) {
|
|
852
880
|
if (!ctx2.focusInputOnChange)
|
|
853
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 = {
|
|
@@ -352,12 +384,14 @@ function connect(state, send, normalize) {
|
|
|
352
384
|
const isFocused = state.hasTag("focus");
|
|
353
385
|
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
354
386
|
const isDisabled = !!state.context.disabled;
|
|
387
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
355
388
|
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
356
389
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
357
390
|
const messages = state.context.messages;
|
|
358
391
|
return {
|
|
359
392
|
isFocused,
|
|
360
393
|
isInvalid,
|
|
394
|
+
isValueEmpty,
|
|
361
395
|
value: state.context.formattedValue,
|
|
362
396
|
valueAsNumber: state.context.valueAsNumber,
|
|
363
397
|
setValue(value) {
|
|
@@ -536,7 +570,7 @@ function connect(state, send, normalize) {
|
|
|
536
570
|
}
|
|
537
571
|
|
|
538
572
|
// src/number-input.machine.ts
|
|
539
|
-
import { choose, createMachine, guards
|
|
573
|
+
import { choose, createMachine, guards } from "@zag-js/core";
|
|
540
574
|
|
|
541
575
|
// ../../utilities/core/dist/index.mjs
|
|
542
576
|
var callAll2 = (...fns) => (...a) => {
|
|
@@ -547,12 +581,11 @@ var callAll2 = (...fns) => (...a) => {
|
|
|
547
581
|
|
|
548
582
|
// src/number-input.machine.ts
|
|
549
583
|
var { not, and } = guards;
|
|
550
|
-
function machine(ctx
|
|
584
|
+
function machine(ctx) {
|
|
551
585
|
return createMachine({
|
|
552
586
|
id: "number-input",
|
|
553
587
|
initial: "unknown",
|
|
554
588
|
context: __spreadProps(__spreadValues({
|
|
555
|
-
uid: "",
|
|
556
589
|
dir: "ltr",
|
|
557
590
|
focusInputOnChange: true,
|
|
558
591
|
clampValueOnBlur: true,
|
|
@@ -578,6 +611,7 @@ function machine(ctx = {}) {
|
|
|
578
611
|
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
579
612
|
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
580
613
|
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
614
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
581
615
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
582
616
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
583
617
|
valueText: (ctx2) => {
|
|
@@ -612,7 +646,7 @@ function machine(ctx = {}) {
|
|
|
612
646
|
on: {
|
|
613
647
|
SETUP: {
|
|
614
648
|
target: "idle",
|
|
615
|
-
actions:
|
|
649
|
+
actions: "syncInputValue"
|
|
616
650
|
}
|
|
617
651
|
}
|
|
618
652
|
},
|
|
@@ -664,7 +698,7 @@ function machine(ctx = {}) {
|
|
|
664
698
|
actions: ["clearValue", "clearHint"]
|
|
665
699
|
},
|
|
666
700
|
{
|
|
667
|
-
guard: and("clampOnBlur", not("isInRange")),
|
|
701
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
668
702
|
target: "idle",
|
|
669
703
|
actions: ["clampValue", "clearHint"]
|
|
670
704
|
},
|
|
@@ -754,6 +788,7 @@ function machine(ctx = {}) {
|
|
|
754
788
|
var _a;
|
|
755
789
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
756
790
|
},
|
|
791
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
757
792
|
isIncrementHint: (ctx2, evt) => {
|
|
758
793
|
var _a;
|
|
759
794
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
@@ -817,13 +852,6 @@ function machine(ctx = {}) {
|
|
|
817
852
|
}
|
|
818
853
|
},
|
|
819
854
|
actions: {
|
|
820
|
-
setupDocument: (ctx2, evt) => {
|
|
821
|
-
if (evt.doc)
|
|
822
|
-
ctx2.doc = ref(evt.doc);
|
|
823
|
-
if (evt.root)
|
|
824
|
-
ctx2.rootNode = ref(evt.root);
|
|
825
|
-
ctx2.uid = evt.id;
|
|
826
|
-
},
|
|
827
855
|
focusInput(ctx2) {
|
|
828
856
|
if (!ctx2.focusInputOnChange)
|
|
829
857
|
return;
|
|
@@ -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;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { MachineContext as Ctx } from "./number-input.types";
|
|
2
2
|
export declare const dom: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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 =
|
|
130
|
+
export declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
131
131
|
declare type ComputedContext = Readonly<{
|
|
132
132
|
/**
|
|
133
133
|
* @computed
|
|
@@ -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-20220708193601",
|
|
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.
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.1.7",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220708193601",
|
|
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-20220708193601",
|
|
36
36
|
"@zag-js/utils": "0.1.2"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|