@zag-js/number-input 0.0.0-dev-20220714012600 → 0.0.0-dev-20220726220411
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/LICENSE +21 -0
- package/dist/index.d.ts +239 -3
- package/dist/index.js +145 -144
- package/dist/index.mjs +140 -147
- package/package.json +13 -12
- package/dist/number-input.connect.d.ts +0 -23
- package/dist/number-input.dom.d.ts +0 -39
- package/dist/number-input.machine.d.ts +0 -2
- package/dist/number-input.types.d.ts +0 -212
- package/dist/number-input.utils.d.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
6
|
var __export = (target, all) => {
|
|
24
7
|
for (var name in all)
|
|
25
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,22 +26,6 @@ __export(src_exports, {
|
|
|
43
26
|
module.exports = __toCommonJS(src_exports);
|
|
44
27
|
|
|
45
28
|
// ../../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
|
-
};
|
|
62
29
|
var dataAttr = (guard) => {
|
|
63
30
|
return guard ? "" : void 0;
|
|
64
31
|
};
|
|
@@ -68,7 +35,7 @@ var ariaAttr = (guard) => {
|
|
|
68
35
|
var MAX_Z_INDEX = 2147483647;
|
|
69
36
|
var runIfFn = (v, ...a) => {
|
|
70
37
|
const res = typeof v === "function" ? v(...a) : v;
|
|
71
|
-
return res
|
|
38
|
+
return res ?? void 0;
|
|
72
39
|
};
|
|
73
40
|
var callAll = (...fns) => (...a) => {
|
|
74
41
|
fns.forEach(function(fn) {
|
|
@@ -80,9 +47,8 @@ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
|
80
47
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
81
48
|
var isDom = () => typeof window !== "undefined";
|
|
82
49
|
function getPlatform() {
|
|
83
|
-
var _a;
|
|
84
50
|
const agent = navigator.userAgentData;
|
|
85
|
-
return (
|
|
51
|
+
return (agent == null ? void 0 : agent.platform) ?? navigator.platform;
|
|
86
52
|
}
|
|
87
53
|
var pt = (v) => isDom() && v.test(getPlatform());
|
|
88
54
|
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
@@ -98,32 +64,30 @@ function isWindow(value) {
|
|
|
98
64
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
99
65
|
}
|
|
100
66
|
function getDocument(el) {
|
|
101
|
-
var _a;
|
|
102
67
|
if (isWindow(el))
|
|
103
68
|
return el.document;
|
|
104
69
|
if (isDocument(el))
|
|
105
70
|
return el;
|
|
106
|
-
return (
|
|
71
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
107
72
|
}
|
|
108
73
|
function defineDomHelpers(helpers) {
|
|
109
74
|
const dom2 = {
|
|
110
75
|
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(dom2.getRootNode(ctx)),
|
|
115
|
-
getWin: (ctx) => {
|
|
116
76
|
var _a;
|
|
117
|
-
return (_a =
|
|
77
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
118
78
|
},
|
|
79
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
80
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
119
81
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
120
82
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
121
83
|
};
|
|
122
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
...dom2,
|
|
86
|
+
...helpers
|
|
87
|
+
};
|
|
123
88
|
}
|
|
124
89
|
function getNativeEvent(e) {
|
|
125
|
-
|
|
126
|
-
return (_a = e.nativeEvent) != null ? _a : e;
|
|
90
|
+
return e.nativeEvent ?? e;
|
|
127
91
|
}
|
|
128
92
|
var supportsPointerEvent = () => isDom() && window.onpointerdown === null;
|
|
129
93
|
var isTouchEvent = (v) => isObject(v) && hasProp(v, "touches");
|
|
@@ -151,8 +115,7 @@ var fallback = {
|
|
|
151
115
|
clientY: 0
|
|
152
116
|
};
|
|
153
117
|
function getEventPoint(event, type = "page") {
|
|
154
|
-
|
|
155
|
-
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event;
|
|
118
|
+
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event;
|
|
156
119
|
return { x: point[`${type}X`], y: point[`${type}Y`] };
|
|
157
120
|
}
|
|
158
121
|
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
|
|
@@ -222,7 +185,6 @@ function requestPointerLock(doc, handlers = {}) {
|
|
|
222
185
|
}
|
|
223
186
|
|
|
224
187
|
// ../../utilities/number/dist/index.mjs
|
|
225
|
-
var __pow = Math.pow;
|
|
226
188
|
function wrap(num, max) {
|
|
227
189
|
return (num % max + max) % max;
|
|
228
190
|
}
|
|
@@ -276,7 +238,7 @@ function isWithinRange(v, o) {
|
|
|
276
238
|
function decimalOperation(a, op, b) {
|
|
277
239
|
let result = op === "+" ? a + b : a - b;
|
|
278
240
|
if (a % 1 !== 0 || b % 1 !== 0) {
|
|
279
|
-
const multiplier =
|
|
241
|
+
const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
|
|
280
242
|
a = Math.round(a * multiplier);
|
|
281
243
|
b = Math.round(b * multiplier);
|
|
282
244
|
result = op === "+" ? a + b : a - b;
|
|
@@ -289,35 +251,73 @@ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigit
|
|
|
289
251
|
// src/number-input.dom.ts
|
|
290
252
|
var dom = defineDomHelpers({
|
|
291
253
|
getRootId: (ctx) => {
|
|
292
|
-
var _a
|
|
293
|
-
return (
|
|
254
|
+
var _a;
|
|
255
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.root) ?? `number-input:${ctx.id}`;
|
|
294
256
|
},
|
|
295
257
|
getInputId: (ctx) => {
|
|
296
|
-
var _a
|
|
297
|
-
return (
|
|
258
|
+
var _a;
|
|
259
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.input) ?? `number-input:${ctx.id}:input`;
|
|
298
260
|
},
|
|
299
261
|
getIncButtonId: (ctx) => {
|
|
300
|
-
var _a
|
|
301
|
-
return (
|
|
262
|
+
var _a;
|
|
263
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.incBtn) ?? `number-input:${ctx.id}:inc-btn`;
|
|
302
264
|
},
|
|
303
265
|
getDecButtonId: (ctx) => {
|
|
304
|
-
var _a
|
|
305
|
-
return (
|
|
266
|
+
var _a;
|
|
267
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.decBtn) ?? `number-input:${ctx.id}:dec-btn`;
|
|
306
268
|
},
|
|
307
269
|
getScrubberId: (ctx) => {
|
|
308
|
-
var _a
|
|
309
|
-
return (
|
|
270
|
+
var _a;
|
|
271
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.scrubber) ?? `number-input:${ctx.id}:scrubber`;
|
|
310
272
|
},
|
|
311
273
|
getCursorId: (ctx) => `number-input:${ctx.id}:cursor`,
|
|
312
274
|
getLabelId: (ctx) => {
|
|
313
|
-
var _a
|
|
314
|
-
return (
|
|
275
|
+
var _a;
|
|
276
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.label) ?? `number-input:${ctx.id}:label`;
|
|
315
277
|
},
|
|
316
278
|
getInputEl: (ctx) => dom.getById(ctx, dom.getInputId(ctx)),
|
|
317
279
|
getIncButtonEl: (ctx) => dom.getById(ctx, dom.getIncButtonId(ctx)),
|
|
318
280
|
getDecButtonEl: (ctx) => dom.getById(ctx, dom.getDecButtonId(ctx)),
|
|
319
281
|
getScrubberEl: (ctx) => dom.getById(ctx, dom.getScrubberId(ctx)),
|
|
320
282
|
getCursorEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getCursorId(ctx)),
|
|
283
|
+
getActiveButton: (ctx, hint = ctx.hint) => {
|
|
284
|
+
let btnEl = null;
|
|
285
|
+
if (hint === "increment") {
|
|
286
|
+
btnEl = dom.getIncButtonEl(ctx);
|
|
287
|
+
}
|
|
288
|
+
if (hint === "decrement") {
|
|
289
|
+
btnEl = dom.getDecButtonEl(ctx);
|
|
290
|
+
}
|
|
291
|
+
return btnEl;
|
|
292
|
+
},
|
|
293
|
+
setupVirtualCursor(ctx) {
|
|
294
|
+
if (isSafari() || !supportsPointerEvent())
|
|
295
|
+
return;
|
|
296
|
+
dom.createVirtualCursor(ctx);
|
|
297
|
+
return () => {
|
|
298
|
+
var _a;
|
|
299
|
+
(_a = dom.getCursorEl(ctx)) == null ? void 0 : _a.remove();
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
preventTextSelection(ctx) {
|
|
303
|
+
const doc = dom.getDoc(ctx);
|
|
304
|
+
const html = doc.documentElement;
|
|
305
|
+
const body = doc.body;
|
|
306
|
+
body.style.pointerEvents = "none";
|
|
307
|
+
html.style.userSelect = "none";
|
|
308
|
+
html.style.cursor = "ew-resize";
|
|
309
|
+
return () => {
|
|
310
|
+
body.style.pointerEvents = "";
|
|
311
|
+
html.style.userSelect = "";
|
|
312
|
+
html.style.cursor = "";
|
|
313
|
+
if (!html.style.length) {
|
|
314
|
+
html.removeAttribute("style");
|
|
315
|
+
}
|
|
316
|
+
if (!body.style.length) {
|
|
317
|
+
body.removeAttribute("style");
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
},
|
|
321
321
|
getMousementValue(ctx, event) {
|
|
322
322
|
const x = roundToDevicePixel(event.movementX);
|
|
323
323
|
const y = roundToDevicePixel(event.movementY);
|
|
@@ -366,39 +366,38 @@ var dom = defineDomHelpers({
|
|
|
366
366
|
// src/number-input.utils.ts
|
|
367
367
|
var utils = {
|
|
368
368
|
isValidNumericEvent: (ctx, event) => {
|
|
369
|
-
var _a
|
|
369
|
+
var _a;
|
|
370
370
|
if (event.key == null)
|
|
371
371
|
return true;
|
|
372
372
|
const isModifier = isModifiedEvent(event);
|
|
373
373
|
const isSingleKey = event.key.length === 1;
|
|
374
374
|
if (isModifier || !isSingleKey)
|
|
375
375
|
return true;
|
|
376
|
-
return (
|
|
376
|
+
return ((_a = ctx.validateCharacter) == null ? void 0 : _a.call(ctx, event.key)) ?? utils.isFloatingPoint(event.key);
|
|
377
377
|
},
|
|
378
378
|
isFloatingPoint: (v) => /^[Ee0-9+\-.]$/.test(v),
|
|
379
379
|
sanitize: (ctx, value) => {
|
|
380
|
-
|
|
381
|
-
return value.split("").filter((_a = ctx.validateCharacter) != null ? _a : utils.isFloatingPoint).join("");
|
|
380
|
+
return value.split("").filter(ctx.validateCharacter ?? utils.isFloatingPoint).join("");
|
|
382
381
|
},
|
|
383
382
|
increment: (ctx, step) => {
|
|
384
|
-
const value = increment(ctx.value, step
|
|
383
|
+
const value = increment(ctx.value, step ?? ctx.step);
|
|
385
384
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
386
385
|
},
|
|
387
386
|
decrement: (ctx, step) => {
|
|
388
|
-
const value = decrement(ctx.value, step
|
|
387
|
+
const value = decrement(ctx.value, step ?? ctx.step);
|
|
389
388
|
return formatDecimal(clamp(value, ctx), ctx);
|
|
390
389
|
},
|
|
391
390
|
clamp: (ctx) => {
|
|
392
391
|
return formatDecimal(clamp(ctx.value, ctx), ctx);
|
|
393
392
|
},
|
|
394
393
|
parse: (ctx, value) => {
|
|
395
|
-
var _a
|
|
396
|
-
return (
|
|
394
|
+
var _a;
|
|
395
|
+
return ((_a = ctx.parse) == null ? void 0 : _a.call(ctx, value)) ?? value;
|
|
397
396
|
},
|
|
398
397
|
format: (ctx, value) => {
|
|
399
|
-
var _a
|
|
398
|
+
var _a;
|
|
400
399
|
const _val = value.toString();
|
|
401
|
-
return (
|
|
400
|
+
return ((_a = ctx.format) == null ? void 0 : _a.call(ctx, _val)) ?? _val;
|
|
402
401
|
},
|
|
403
402
|
round: (ctx) => {
|
|
404
403
|
return formatDecimal(ctx.value, ctx);
|
|
@@ -442,6 +441,10 @@ function connect(state, send, normalize) {
|
|
|
442
441
|
var _a;
|
|
443
442
|
(_a = dom.getInputEl(state.context)) == null ? void 0 : _a.focus();
|
|
444
443
|
},
|
|
444
|
+
blur() {
|
|
445
|
+
var _a;
|
|
446
|
+
(_a = dom.getInputEl(state.context)) == null ? void 0 : _a.blur();
|
|
447
|
+
},
|
|
445
448
|
rootProps: normalize.element({
|
|
446
449
|
id: dom.getRootId(state.context),
|
|
447
450
|
"data-part": "root",
|
|
@@ -611,7 +614,7 @@ function machine(ctx) {
|
|
|
611
614
|
return (0, import_core.createMachine)({
|
|
612
615
|
id: "number-input",
|
|
613
616
|
initial: "unknown",
|
|
614
|
-
context:
|
|
617
|
+
context: {
|
|
615
618
|
dir: "ltr",
|
|
616
619
|
focusInputOnChange: true,
|
|
617
620
|
clampValueOnBlur: true,
|
|
@@ -624,13 +627,15 @@ function machine(ctx) {
|
|
|
624
627
|
min: Number.MIN_SAFE_INTEGER,
|
|
625
628
|
max: Number.MAX_SAFE_INTEGER,
|
|
626
629
|
scrubberCursorPoint: null,
|
|
627
|
-
invalid: false
|
|
628
|
-
|
|
629
|
-
|
|
630
|
+
invalid: false,
|
|
631
|
+
spinOnPress: true,
|
|
632
|
+
...ctx,
|
|
633
|
+
messages: {
|
|
630
634
|
incrementLabel: "increment value",
|
|
631
|
-
decrementLabel: "decrease value"
|
|
632
|
-
|
|
633
|
-
|
|
635
|
+
decrementLabel: "decrease value",
|
|
636
|
+
...ctx.messages
|
|
637
|
+
}
|
|
638
|
+
},
|
|
634
639
|
computed: {
|
|
635
640
|
isRtl: (ctx2) => ctx2.dir === "rtl",
|
|
636
641
|
valueAsNumber: (ctx2) => valueOf(ctx2.value),
|
|
@@ -645,13 +650,14 @@ function machine(ctx) {
|
|
|
645
650
|
return (_b = (_a = ctx2.messages).valueText) == null ? void 0 : _b.call(_a, ctx2.value);
|
|
646
651
|
},
|
|
647
652
|
formattedValue: (ctx2) => {
|
|
648
|
-
var _a
|
|
649
|
-
return (
|
|
653
|
+
var _a;
|
|
654
|
+
return ((_a = ctx2.format) == null ? void 0 : _a.call(ctx2, ctx2.value).toString()) ?? ctx2.value;
|
|
650
655
|
}
|
|
651
656
|
},
|
|
652
657
|
watch: {
|
|
653
658
|
value: ["invokeOnChange"],
|
|
654
|
-
isOutOfRange: ["invokeOnInvalid"]
|
|
659
|
+
isOutOfRange: ["invokeOnInvalid"],
|
|
660
|
+
scrubberCursorPoint: ["setVirtualCursorPosition"]
|
|
655
661
|
},
|
|
656
662
|
on: {
|
|
657
663
|
SET_VALUE: {
|
|
@@ -677,6 +683,7 @@ function machine(ctx) {
|
|
|
677
683
|
}
|
|
678
684
|
},
|
|
679
685
|
idle: {
|
|
686
|
+
exit: "invokeOnFocus",
|
|
680
687
|
on: {
|
|
681
688
|
PRESS_DOWN: {
|
|
682
689
|
target: "before:spin",
|
|
@@ -690,7 +697,7 @@ function machine(ctx) {
|
|
|
690
697
|
}
|
|
691
698
|
},
|
|
692
699
|
focused: {
|
|
693
|
-
tags:
|
|
700
|
+
tags: "focus",
|
|
694
701
|
entry: "focusInput",
|
|
695
702
|
activities: "attachWheelListener",
|
|
696
703
|
on: {
|
|
@@ -721,22 +728,22 @@ function machine(ctx) {
|
|
|
721
728
|
{
|
|
722
729
|
guard: "isInvalidExponential",
|
|
723
730
|
target: "idle",
|
|
724
|
-
actions: ["clearValue", "clearHint"]
|
|
731
|
+
actions: ["clearValue", "clearHint", "invokeOnBlur"]
|
|
725
732
|
},
|
|
726
733
|
{
|
|
727
734
|
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
728
735
|
target: "idle",
|
|
729
|
-
actions: ["clampValue", "clearHint"]
|
|
736
|
+
actions: ["clampValue", "clearHint", "invokeOnBlur"]
|
|
730
737
|
},
|
|
731
738
|
{
|
|
732
739
|
target: "idle",
|
|
733
|
-
actions: "roundValue"
|
|
740
|
+
actions: ["roundValue", "invokeOnBlur"]
|
|
734
741
|
}
|
|
735
742
|
]
|
|
736
743
|
}
|
|
737
744
|
},
|
|
738
745
|
"before:spin": {
|
|
739
|
-
tags:
|
|
746
|
+
tags: "focus",
|
|
740
747
|
activities: "trackButtonDisabled",
|
|
741
748
|
entry: (0, import_core.choose)([
|
|
742
749
|
{ guard: "isIncrementHint", actions: "increment" },
|
|
@@ -745,7 +752,7 @@ function machine(ctx) {
|
|
|
745
752
|
after: {
|
|
746
753
|
CHANGE_DELAY: {
|
|
747
754
|
target: "spinning",
|
|
748
|
-
guard: "isInRange"
|
|
755
|
+
guard: and("isInRange", "spinOnPress")
|
|
749
756
|
}
|
|
750
757
|
},
|
|
751
758
|
on: {
|
|
@@ -756,7 +763,7 @@ function machine(ctx) {
|
|
|
756
763
|
}
|
|
757
764
|
},
|
|
758
765
|
spinning: {
|
|
759
|
-
tags:
|
|
766
|
+
tags: "focus",
|
|
760
767
|
activities: "trackButtonDisabled",
|
|
761
768
|
every: [
|
|
762
769
|
{
|
|
@@ -778,23 +785,19 @@ function machine(ctx) {
|
|
|
778
785
|
}
|
|
779
786
|
},
|
|
780
787
|
scrubbing: {
|
|
781
|
-
tags:
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
activities: ["activatePointerLock", "trackMousemove"],
|
|
788
|
+
tags: "focus",
|
|
789
|
+
exit: "clearCursorPoint",
|
|
790
|
+
activities: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
|
|
785
791
|
on: {
|
|
786
|
-
POINTER_UP_SCRUBBER:
|
|
787
|
-
target: "focused",
|
|
788
|
-
actions: "clearCursorPoint"
|
|
789
|
-
},
|
|
792
|
+
POINTER_UP_SCRUBBER: "focused",
|
|
790
793
|
POINTER_MOVE_SCRUBBER: [
|
|
791
794
|
{
|
|
792
795
|
guard: "isIncrementHint",
|
|
793
|
-
actions: ["increment", "setCursorPoint"
|
|
796
|
+
actions: ["increment", "setCursorPoint"]
|
|
794
797
|
},
|
|
795
798
|
{
|
|
796
799
|
guard: "isDecrementHint",
|
|
797
|
-
actions: ["decrement", "setCursorPoint"
|
|
800
|
+
actions: ["decrement", "setCursorPoint"]
|
|
798
801
|
}
|
|
799
802
|
]
|
|
800
803
|
}
|
|
@@ -808,31 +811,24 @@ function machine(ctx) {
|
|
|
808
811
|
guards: {
|
|
809
812
|
clampOnBlur: (ctx2) => !!ctx2.clampValueOnBlur,
|
|
810
813
|
isAtMin: (ctx2) => ctx2.isAtMin,
|
|
814
|
+
spinOnPress: (ctx2) => !!ctx2.spinOnPress,
|
|
811
815
|
isAtMax: (ctx2) => ctx2.isAtMax,
|
|
812
816
|
isInRange: (ctx2) => !ctx2.isOutOfRange,
|
|
813
|
-
isDecrementHint: (ctx2, evt) =>
|
|
814
|
-
var _a;
|
|
815
|
-
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
816
|
-
},
|
|
817
|
+
isDecrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "decrement",
|
|
817
818
|
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
818
|
-
isIncrementHint: (ctx2, evt) =>
|
|
819
|
-
var _a;
|
|
820
|
-
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
821
|
-
},
|
|
819
|
+
isIncrementHint: (ctx2, evt) => (evt.hint ?? ctx2.hint) === "increment",
|
|
822
820
|
isInvalidExponential: (ctx2) => ctx2.value.toString().startsWith("e")
|
|
823
821
|
},
|
|
824
822
|
activities: {
|
|
823
|
+
setupVirtualCursor(ctx2) {
|
|
824
|
+
return dom.setupVirtualCursor(ctx2);
|
|
825
|
+
},
|
|
826
|
+
preventTextSelection(ctx2) {
|
|
827
|
+
return dom.preventTextSelection(ctx2);
|
|
828
|
+
},
|
|
825
829
|
trackButtonDisabled(ctx2, _evt, { send }) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
btnEl = dom.getIncButtonEl(ctx2);
|
|
829
|
-
}
|
|
830
|
-
if (ctx2.hint === "decrement") {
|
|
831
|
-
btnEl = dom.getDecButtonEl(ctx2);
|
|
832
|
-
}
|
|
833
|
-
return observeAttributes(btnEl, "disabled", function onDisable() {
|
|
834
|
-
send("PRESS_UP");
|
|
835
|
-
});
|
|
830
|
+
const btn = dom.getActiveButton(ctx2, ctx2.hint);
|
|
831
|
+
return observeAttributes(btn, "disabled", () => send("PRESS_UP"));
|
|
836
832
|
},
|
|
837
833
|
attachWheelListener(ctx2, _evt, { send }) {
|
|
838
834
|
const input = dom.getInputEl(ctx2);
|
|
@@ -899,8 +895,8 @@ function machine(ctx) {
|
|
|
899
895
|
}
|
|
900
896
|
},
|
|
901
897
|
setValue(ctx2, evt) {
|
|
902
|
-
var _a
|
|
903
|
-
const value = (
|
|
898
|
+
var _a;
|
|
899
|
+
const value = ((_a = evt.target) == null ? void 0 : _a.value) ?? evt.value;
|
|
904
900
|
ctx2.value = utils.sanitize(ctx2, utils.parse(ctx2, value.toString()));
|
|
905
901
|
},
|
|
906
902
|
clearValue(ctx2) {
|
|
@@ -928,6 +924,29 @@ function machine(ctx) {
|
|
|
928
924
|
valueAsNumber: ctx2.valueAsNumber
|
|
929
925
|
});
|
|
930
926
|
},
|
|
927
|
+
invokeOnFocus(ctx2, evt) {
|
|
928
|
+
var _a;
|
|
929
|
+
let srcElement = null;
|
|
930
|
+
if (evt.type === "PRESS_DOWN") {
|
|
931
|
+
srcElement = dom.getActiveButton(ctx2, evt.hint);
|
|
932
|
+
} else if (evt.type === "FOCUS") {
|
|
933
|
+
srcElement = dom.getInputEl(ctx2);
|
|
934
|
+
} else if (evt.type === "PRESS_DOWN_SCRUBBER") {
|
|
935
|
+
srcElement = dom.getScrubberEl(ctx2);
|
|
936
|
+
}
|
|
937
|
+
(_a = ctx2.onFocus) == null ? void 0 : _a.call(ctx2, {
|
|
938
|
+
value: ctx2.value,
|
|
939
|
+
valueAsNumber: ctx2.valueAsNumber,
|
|
940
|
+
srcElement
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
invokeOnBlur(ctx2) {
|
|
944
|
+
var _a;
|
|
945
|
+
(_a = ctx2.onBlur) == null ? void 0 : _a.call(ctx2, {
|
|
946
|
+
value: ctx2.value,
|
|
947
|
+
valueAsNumber: ctx2.valueAsNumber
|
|
948
|
+
});
|
|
949
|
+
},
|
|
931
950
|
invokeOnInvalid(ctx2) {
|
|
932
951
|
var _a;
|
|
933
952
|
if (!ctx2.isOutOfRange)
|
|
@@ -952,37 +971,19 @@ function machine(ctx) {
|
|
|
952
971
|
clearCursorPoint(ctx2) {
|
|
953
972
|
ctx2.scrubberCursorPoint = null;
|
|
954
973
|
},
|
|
955
|
-
|
|
974
|
+
setVirtualCursorPosition(ctx2) {
|
|
956
975
|
const cursor = dom.getCursorEl(ctx2);
|
|
957
976
|
if (!cursor || !ctx2.scrubberCursorPoint)
|
|
958
977
|
return;
|
|
959
978
|
const { x, y } = ctx2.scrubberCursorPoint;
|
|
960
979
|
cursor.style.transform = `translate3d(${x}px, ${y}px, 0px)`;
|
|
961
|
-
},
|
|
962
|
-
addCustomCursor(ctx2) {
|
|
963
|
-
if (isSafari() || !supportsPointerEvent())
|
|
964
|
-
return;
|
|
965
|
-
dom.createVirtualCursor(ctx2);
|
|
966
|
-
},
|
|
967
|
-
removeCustomCursor(ctx2) {
|
|
968
|
-
var _a;
|
|
969
|
-
if (isSafari() || !supportsPointerEvent())
|
|
970
|
-
return;
|
|
971
|
-
(_a = dom.getCursorEl(ctx2)) == null ? void 0 : _a.remove();
|
|
972
|
-
},
|
|
973
|
-
disableTextSelection(ctx2) {
|
|
974
|
-
const doc = dom.getDoc(ctx2);
|
|
975
|
-
doc.body.style.pointerEvents = "none";
|
|
976
|
-
doc.documentElement.style.userSelect = "none";
|
|
977
|
-
doc.documentElement.style.cursor = "ew-resize";
|
|
978
|
-
},
|
|
979
|
-
restoreTextSelection(ctx2) {
|
|
980
|
-
const doc = dom.getDoc(ctx2);
|
|
981
|
-
doc.body.style.pointerEvents = "";
|
|
982
|
-
doc.documentElement.style.userSelect = "";
|
|
983
|
-
doc.documentElement.style.cursor = "";
|
|
984
980
|
}
|
|
985
981
|
},
|
|
986
982
|
hookSync: true
|
|
987
983
|
});
|
|
988
984
|
}
|
|
985
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
986
|
+
0 && (module.exports = {
|
|
987
|
+
connect,
|
|
988
|
+
machine
|
|
989
|
+
});
|