@zag-js/number-input 1.47.0 → 1.49.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/cursor.d.mts +8 -10
- package/dist/cursor.d.ts +8 -10
- package/dist/cursor.js +65 -104
- package/dist/cursor.mjs +59 -77
- package/dist/index.d.mts +6 -9
- package/dist/index.d.ts +6 -9
- package/dist/index.js +12 -38
- package/dist/index.mjs +2 -7
- package/dist/number-input.anatomy.d.mts +2 -6
- package/dist/number-input.anatomy.d.ts +2 -6
- package/dist/number-input.anatomy.js +8 -42
- package/dist/number-input.anatomy.mjs +4 -16
- package/dist/number-input.connect.d.mts +3 -8
- package/dist/number-input.connect.d.ts +3 -8
- package/dist/number-input.connect.js +309 -310
- package/dist/number-input.connect.mjs +302 -283
- package/dist/number-input.dom.d.mts +28 -32
- package/dist/number-input.dom.d.ts +28 -32
- package/dist/number-input.dom.js +96 -137
- package/dist/number-input.dom.mjs +76 -96
- package/dist/number-input.machine.d.mts +2 -8
- package/dist/number-input.machine.d.ts +2 -8
- package/dist/number-input.machine.js +493 -460
- package/dist/number-input.machine.mjs +486 -439
- package/dist/number-input.props.d.mts +3 -9
- package/dist/number-input.props.d.ts +3 -9
- package/dist/number-input.props.js +41 -65
- package/dist/number-input.props.mjs +35 -38
- package/dist/number-input.translations.d.mts +3 -8
- package/dist/number-input.translations.d.ts +3 -8
- package/dist/number-input.translations.js +8 -31
- package/dist/number-input.translations.mjs +4 -6
- package/dist/number-input.types.d.mts +302 -300
- package/dist/number-input.types.d.ts +302 -300
- package/dist/number-input.types.js +4 -18
- package/dist/number-input.types.mjs +1 -0
- package/dist/number-input.utils.d.mts +9 -12
- package/dist/number-input.utils.d.ts +9 -12
- package/dist/number-input.utils.js +28 -57
- package/dist/number-input.utils.mjs +20 -28
- package/package.json +8 -8
|
@@ -1,462 +1,495 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/number-input.machine.ts
|
|
31
|
-
var number_input_machine_exports = {};
|
|
32
|
-
__export(number_input_machine_exports, {
|
|
33
|
-
machine: () => machine
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(number_input_machine_exports);
|
|
36
|
-
var import_core = require("@zag-js/core");
|
|
37
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
38
|
-
var import_utils = require("@zag-js/utils");
|
|
39
|
-
var import_cursor = require("./cursor.js");
|
|
40
|
-
var dom = __toESM(require("./number-input.dom.js"));
|
|
41
|
-
var import_number_input = require("./number-input.translations.js");
|
|
42
|
-
var import_number_input2 = require("./number-input.utils.js");
|
|
43
|
-
var { choose, guards, createMachine } = (0, import_core.setup)();
|
|
44
|
-
var { not, and } = guards;
|
|
45
|
-
var machine = createMachine({
|
|
46
|
-
props({ props }) {
|
|
47
|
-
const step = (0, import_number_input2.getDefaultStep)(props.step, props.formatOptions);
|
|
48
|
-
return {
|
|
49
|
-
dir: "ltr",
|
|
50
|
-
locale: "en-US",
|
|
51
|
-
focusInputOnChange: true,
|
|
52
|
-
clampValueOnBlur: !props.allowOverflow,
|
|
53
|
-
allowOverflow: false,
|
|
54
|
-
inputMode: "decimal",
|
|
55
|
-
pattern: "-?[0-9]*(.[0-9]+)?",
|
|
56
|
-
defaultValue: "",
|
|
57
|
-
step,
|
|
58
|
-
min: Number.MIN_SAFE_INTEGER,
|
|
59
|
-
max: Number.MAX_SAFE_INTEGER,
|
|
60
|
-
spinOnPress: true,
|
|
61
|
-
...props,
|
|
62
|
-
largeStep: props.largeStep ?? 10 * step,
|
|
63
|
-
smallStep: props.smallStep ?? step / 10
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
initialState() {
|
|
67
|
-
return "idle";
|
|
68
|
-
},
|
|
69
|
-
context({ prop, bindable, getComputed }) {
|
|
70
|
-
return {
|
|
71
|
-
value: bindable(() => ({
|
|
72
|
-
defaultValue: prop("defaultValue"),
|
|
73
|
-
value: prop("value"),
|
|
74
|
-
onChange(value) {
|
|
75
|
-
const computed = getComputed();
|
|
76
|
-
const valueAsNumber = (0, import_number_input2.parseValue)(value, { computed, prop });
|
|
77
|
-
prop("onValueChange")?.({ value, valueAsNumber });
|
|
78
|
-
}
|
|
79
|
-
})),
|
|
80
|
-
hint: bindable(() => ({ defaultValue: null })),
|
|
81
|
-
scrubberCursorPoint: bindable(() => ({
|
|
82
|
-
defaultValue: null,
|
|
83
|
-
hash(value) {
|
|
84
|
-
return value ? `x:${value.x}, y:${value.y}` : "";
|
|
85
|
-
}
|
|
86
|
-
})),
|
|
87
|
-
fieldsetDisabled: bindable(() => ({ defaultValue: false }))
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
computed: {
|
|
91
|
-
isRtl: ({ prop }) => prop("dir") === "rtl",
|
|
92
|
-
valueAsNumber: ({ context, computed, prop }) => (0, import_number_input2.parseValue)(context.get("value"), { computed, prop }),
|
|
93
|
-
formattedValue: ({ computed, prop }) => (0, import_number_input2.formatValue)(computed("valueAsNumber"), { computed, prop }),
|
|
94
|
-
isAtMin: ({ computed, prop }) => (0, import_utils.isValueAtMin)(computed("valueAsNumber"), prop("min")),
|
|
95
|
-
isAtMax: ({ computed, prop }) => (0, import_utils.isValueAtMax)(computed("valueAsNumber"), prop("max")),
|
|
96
|
-
isOutOfRange: ({ computed, prop }) => !(0, import_utils.isValueWithinRange)(computed("valueAsNumber"), prop("min"), prop("max")),
|
|
97
|
-
isValueEmpty: ({ context }) => context.get("value") === "",
|
|
98
|
-
isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
99
|
-
canIncrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMax"),
|
|
100
|
-
canDecrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMin"),
|
|
101
|
-
valueText: ({ prop, context }) => {
|
|
102
|
-
const translations = (0, import_utils.mergeWithDefault)(import_number_input.defaultTranslations, prop("translations"));
|
|
103
|
-
return translations.valueText?.(context.get("value"));
|
|
104
|
-
},
|
|
105
|
-
formatter: (0, import_core.memo)(
|
|
106
|
-
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
107
|
-
([locale, formatOptions]) => (0, import_number_input2.createFormatter)(locale, formatOptions)
|
|
108
|
-
),
|
|
109
|
-
parser: (0, import_core.memo)(
|
|
110
|
-
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
111
|
-
([locale, formatOptions]) => (0, import_number_input2.createParser)(locale, formatOptions)
|
|
112
|
-
)
|
|
113
|
-
},
|
|
114
|
-
watch({ track, action, context, computed, prop }) {
|
|
115
|
-
track([() => context.get("value"), () => prop("locale"), () => JSON.stringify(prop("formatOptions"))], () => {
|
|
116
|
-
action(["syncInputElement"]);
|
|
117
|
-
});
|
|
118
|
-
track([() => computed("isOutOfRange")], () => {
|
|
119
|
-
action(["invokeOnInvalid"]);
|
|
120
|
-
});
|
|
121
|
-
track([() => context.hash("scrubberCursorPoint")], () => {
|
|
122
|
-
action(["setVirtualCursorPosition"]);
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
effects: ["trackFormControl"],
|
|
126
|
-
on: {
|
|
127
|
-
"VALUE.SET": {
|
|
128
|
-
actions: ["setRawValue"]
|
|
129
|
-
},
|
|
130
|
-
"VALUE.CLEAR": {
|
|
131
|
-
actions: ["clearValue"]
|
|
132
|
-
},
|
|
133
|
-
"VALUE.INCREMENT": {
|
|
134
|
-
actions: ["increment"]
|
|
135
|
-
},
|
|
136
|
-
"VALUE.DECREMENT": {
|
|
137
|
-
actions: ["decrement"]
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
states: {
|
|
141
|
-
idle: {
|
|
142
|
-
on: {
|
|
143
|
-
"TRIGGER.PRESS_DOWN": [
|
|
144
|
-
{ guard: "isTouchPointer", target: "before:spin", actions: ["setHint"] },
|
|
145
|
-
{
|
|
146
|
-
target: "before:spin",
|
|
147
|
-
actions: ["focusInput", "invokeOnFocus", "setHint"]
|
|
148
|
-
}
|
|
149
|
-
],
|
|
150
|
-
"SCRUBBER.PRESS_DOWN": {
|
|
151
|
-
target: "scrubbing",
|
|
152
|
-
actions: ["focusInput", "invokeOnFocus", "setHint", "setCursorPoint"]
|
|
153
|
-
},
|
|
154
|
-
"INPUT.FOCUS": {
|
|
155
|
-
target: "focused",
|
|
156
|
-
actions: ["focusInput", "invokeOnFocus"]
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
focused: {
|
|
161
|
-
tags: ["focus"],
|
|
162
|
-
effects: ["attachWheelListener"],
|
|
163
|
-
on: {
|
|
164
|
-
"TRIGGER.PRESS_DOWN": [
|
|
165
|
-
{ guard: "isTouchPointer", target: "before:spin", actions: ["setHint"] },
|
|
166
|
-
{ target: "before:spin", actions: ["focusInput", "setHint"] }
|
|
167
|
-
],
|
|
168
|
-
"SCRUBBER.PRESS_DOWN": {
|
|
169
|
-
target: "scrubbing",
|
|
170
|
-
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
171
|
-
},
|
|
172
|
-
"INPUT.ARROW_UP": {
|
|
173
|
-
actions: ["increment"]
|
|
174
|
-
},
|
|
175
|
-
"INPUT.ARROW_DOWN": {
|
|
176
|
-
actions: ["decrement"]
|
|
177
|
-
},
|
|
178
|
-
"INPUT.HOME": {
|
|
179
|
-
actions: ["decrementToMin"]
|
|
180
|
-
},
|
|
181
|
-
"INPUT.END": {
|
|
182
|
-
actions: ["incrementToMax"]
|
|
183
|
-
},
|
|
184
|
-
"INPUT.CHANGE": {
|
|
185
|
-
actions: ["setValue", "setHint"]
|
|
186
|
-
},
|
|
187
|
-
"INPUT.BLUR": [
|
|
188
|
-
{
|
|
189
|
-
guard: and("clampValueOnBlur", not("isValueEmpty"), not("isInRange")),
|
|
190
|
-
target: "idle",
|
|
191
|
-
actions: ["setClampedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
guard: not("isInRange"),
|
|
195
|
-
target: "idle",
|
|
196
|
-
actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnInvalid", "invokeOnValueCommit"]
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
target: "idle",
|
|
200
|
-
actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
|
|
201
|
-
}
|
|
202
|
-
],
|
|
203
|
-
"INPUT.ENTER": {
|
|
204
|
-
actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
"before:spin": {
|
|
209
|
-
tags: ["focus"],
|
|
210
|
-
effects: ["trackButtonDisabled", "waitForChangeDelay"],
|
|
211
|
-
entry: choose([
|
|
212
|
-
{ guard: "isIncrementHint", actions: ["increment"] },
|
|
213
|
-
{ guard: "isDecrementHint", actions: ["decrement"] }
|
|
214
|
-
]),
|
|
215
|
-
on: {
|
|
216
|
-
CHANGE_DELAY: {
|
|
217
|
-
target: "spinning",
|
|
218
|
-
guard: and("isInRange", "spinOnPress")
|
|
219
|
-
},
|
|
220
|
-
"TRIGGER.PRESS_UP": [
|
|
221
|
-
{ guard: "isTouchPointer", target: "focused", actions: ["clearHint"] },
|
|
222
|
-
{ target: "focused", actions: ["focusInput", "clearHint"] }
|
|
223
|
-
]
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
spinning: {
|
|
227
|
-
tags: ["focus"],
|
|
228
|
-
effects: ["trackButtonDisabled", "spinValue"],
|
|
229
|
-
on: {
|
|
230
|
-
SPIN: [
|
|
231
|
-
{
|
|
232
|
-
guard: "isIncrementHint",
|
|
233
|
-
actions: ["increment"]
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
guard: "isDecrementHint",
|
|
237
|
-
actions: ["decrement"]
|
|
238
|
-
}
|
|
239
|
-
],
|
|
240
|
-
"TRIGGER.PRESS_UP": {
|
|
241
|
-
target: "focused",
|
|
242
|
-
actions: ["focusInput", "clearHint"]
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
scrubbing: {
|
|
247
|
-
tags: ["focus"],
|
|
248
|
-
effects: ["activatePointerLock", "trackMousemove", "setupVirtualCursor", "preventTextSelection"],
|
|
249
|
-
on: {
|
|
250
|
-
"SCRUBBER.POINTER_UP": {
|
|
251
|
-
target: "focused",
|
|
252
|
-
actions: ["focusInput", "clearCursorPoint"]
|
|
253
|
-
},
|
|
254
|
-
"SCRUBBER.POINTER_MOVE": [
|
|
255
|
-
{
|
|
256
|
-
guard: "isIncrementHint",
|
|
257
|
-
actions: ["increment", "setCursorPoint"]
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
guard: "isDecrementHint",
|
|
261
|
-
actions: ["decrement", "setCursorPoint"]
|
|
262
|
-
}
|
|
263
|
-
]
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
implementations: {
|
|
268
|
-
guards: {
|
|
269
|
-
clampValueOnBlur: ({ prop }) => prop("clampValueOnBlur"),
|
|
270
|
-
spinOnPress: ({ prop }) => !!prop("spinOnPress"),
|
|
271
|
-
isInRange: ({ computed }) => !computed("isOutOfRange"),
|
|
272
|
-
isValueEmpty: ({ computed }) => computed("isValueEmpty"),
|
|
273
|
-
isDecrementHint: ({ context, event }) => (event.hint ?? context.get("hint")) === "decrement",
|
|
274
|
-
isIncrementHint: ({ context, event }) => (event.hint ?? context.get("hint")) === "increment",
|
|
275
|
-
isTouchPointer: ({ event }) => event.pointerType === "touch"
|
|
276
|
-
},
|
|
277
|
-
effects: {
|
|
278
|
-
waitForChangeDelay({ send }) {
|
|
279
|
-
const id = setTimeout(() => {
|
|
280
|
-
send({ type: "CHANGE_DELAY" });
|
|
281
|
-
}, 300);
|
|
282
|
-
return () => clearTimeout(id);
|
|
283
|
-
},
|
|
284
|
-
spinValue({ send }) {
|
|
285
|
-
const id = setInterval(() => {
|
|
286
|
-
send({ type: "SPIN" });
|
|
287
|
-
}, 50);
|
|
288
|
-
return () => clearInterval(id);
|
|
289
|
-
},
|
|
290
|
-
trackFormControl({ context, scope }) {
|
|
291
|
-
const inputEl = dom.getInputEl(scope);
|
|
292
|
-
return (0, import_dom_query.trackFormControl)(inputEl, {
|
|
293
|
-
onFieldsetDisabledChange(disabled) {
|
|
294
|
-
context.set("fieldsetDisabled", disabled);
|
|
295
|
-
},
|
|
296
|
-
onFormReset() {
|
|
297
|
-
context.set("value", context.initial("value"));
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
},
|
|
301
|
-
setupVirtualCursor({ context, scope }) {
|
|
302
|
-
const point = context.get("scrubberCursorPoint");
|
|
303
|
-
return dom.setupVirtualCursor(scope, point);
|
|
304
|
-
},
|
|
305
|
-
preventTextSelection({ scope }) {
|
|
306
|
-
return dom.preventTextSelection(scope);
|
|
307
|
-
},
|
|
308
|
-
trackButtonDisabled({ context, scope, send }) {
|
|
309
|
-
const hint = context.get("hint");
|
|
310
|
-
const btn = dom.getPressedTriggerEl(scope, hint);
|
|
311
|
-
return (0, import_dom_query.observeAttributes)(btn, {
|
|
312
|
-
attributes: ["disabled"],
|
|
313
|
-
callback() {
|
|
314
|
-
send({ type: "TRIGGER.PRESS_UP", src: "attr" });
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
attachWheelListener({ scope, send, prop }) {
|
|
319
|
-
const inputEl = dom.getInputEl(scope);
|
|
320
|
-
if (!inputEl || !scope.isActiveElement(inputEl) || !prop("allowMouseWheel")) return;
|
|
321
|
-
function onWheel(event) {
|
|
322
|
-
event.preventDefault();
|
|
323
|
-
const dir = Math.sign(event.deltaY) * -1;
|
|
324
|
-
if (dir === 1) {
|
|
325
|
-
send({ type: "VALUE.INCREMENT" });
|
|
326
|
-
} else if (dir === -1) {
|
|
327
|
-
send({ type: "VALUE.DECREMENT" });
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return (0, import_dom_query.addDomEvent)(inputEl, "wheel", onWheel, { passive: false });
|
|
331
|
-
},
|
|
332
|
-
activatePointerLock({ scope }) {
|
|
333
|
-
if ((0, import_dom_query.isSafari)()) return;
|
|
334
|
-
return (0, import_dom_query.requestPointerLock)(scope.getDoc());
|
|
335
|
-
},
|
|
336
|
-
trackMousemove({ scope, send, context, computed }) {
|
|
337
|
-
const doc = scope.getDoc();
|
|
338
|
-
function onMousemove(event) {
|
|
339
|
-
const point = context.get("scrubberCursorPoint");
|
|
340
|
-
const isRtl = computed("isRtl");
|
|
341
|
-
const value = dom.getMousemoveValue(scope, { point, isRtl, event });
|
|
342
|
-
if (!value.hint) return;
|
|
343
|
-
send({
|
|
344
|
-
type: "SCRUBBER.POINTER_MOVE",
|
|
345
|
-
hint: value.hint,
|
|
346
|
-
point: value.point
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
function onMouseup() {
|
|
350
|
-
send({ type: "SCRUBBER.POINTER_UP" });
|
|
351
|
-
}
|
|
352
|
-
return (0, import_utils.callAll)((0, import_dom_query.addDomEvent)(doc, "mousemove", onMousemove, false), (0, import_dom_query.addDomEvent)(doc, "mouseup", onMouseup, false));
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
actions: {
|
|
356
|
-
focusInput({ scope, prop }) {
|
|
357
|
-
if (!prop("focusInputOnChange")) return;
|
|
358
|
-
const inputEl = dom.getInputEl(scope);
|
|
359
|
-
if (scope.isActiveElement(inputEl)) return;
|
|
360
|
-
(0, import_dom_query.raf)(() => inputEl?.focus({ preventScroll: true }));
|
|
361
|
-
},
|
|
362
|
-
increment({ context, event, prop, computed }) {
|
|
363
|
-
let nextValue = (0, import_utils.incrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
|
|
364
|
-
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
365
|
-
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
366
|
-
},
|
|
367
|
-
decrement({ context, event, prop, computed }) {
|
|
368
|
-
let nextValue = (0, import_utils.decrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
|
|
369
|
-
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
370
|
-
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
371
|
-
},
|
|
372
|
-
setClampedValue({ context, prop, computed }) {
|
|
373
|
-
const nextValue = (0, import_utils.clampValue)(computed("valueAsNumber"), prop("min"), prop("max"));
|
|
374
|
-
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
375
|
-
},
|
|
376
|
-
setRawValue({ context, event, prop, computed }) {
|
|
377
|
-
let nextValue = typeof event.value === "number" ? event.value : (0, import_number_input2.parseValue)(event.value, { computed, prop });
|
|
378
|
-
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
379
|
-
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
380
|
-
},
|
|
381
|
-
setValue({ context, event }) {
|
|
382
|
-
const value = event.target?.value ?? event.value;
|
|
383
|
-
context.set("value", value);
|
|
384
|
-
},
|
|
385
|
-
clearValue({ context }) {
|
|
386
|
-
context.set("value", "");
|
|
387
|
-
},
|
|
388
|
-
incrementToMax({ context, prop, computed }) {
|
|
389
|
-
const value = (0, import_number_input2.formatValue)(prop("max"), { computed, prop });
|
|
390
|
-
context.set("value", value);
|
|
391
|
-
},
|
|
392
|
-
decrementToMin({ context, prop, computed }) {
|
|
393
|
-
const value = (0, import_number_input2.formatValue)(prop("min"), { computed, prop });
|
|
394
|
-
context.set("value", value);
|
|
395
|
-
},
|
|
396
|
-
setHint({ context, event }) {
|
|
397
|
-
context.set("hint", event.hint);
|
|
398
|
-
},
|
|
399
|
-
clearHint({ context }) {
|
|
400
|
-
context.set("hint", null);
|
|
401
|
-
},
|
|
402
|
-
invokeOnFocus({ computed, prop }) {
|
|
403
|
-
prop("onFocusChange")?.({
|
|
404
|
-
focused: true,
|
|
405
|
-
value: computed("formattedValue"),
|
|
406
|
-
valueAsNumber: computed("valueAsNumber")
|
|
407
|
-
});
|
|
408
|
-
},
|
|
409
|
-
invokeOnBlur({ computed, prop }) {
|
|
410
|
-
prop("onFocusChange")?.({
|
|
411
|
-
focused: false,
|
|
412
|
-
value: computed("formattedValue"),
|
|
413
|
-
valueAsNumber: computed("valueAsNumber")
|
|
414
|
-
});
|
|
415
|
-
},
|
|
416
|
-
invokeOnInvalid({ computed, prop, event }) {
|
|
417
|
-
if (event.type === "INPUT.CHANGE") return;
|
|
418
|
-
const reason = computed("valueAsNumber") > prop("max") ? "rangeOverflow" : "rangeUnderflow";
|
|
419
|
-
prop("onValueInvalid")?.({
|
|
420
|
-
reason,
|
|
421
|
-
value: computed("formattedValue"),
|
|
422
|
-
valueAsNumber: computed("valueAsNumber")
|
|
423
|
-
});
|
|
424
|
-
},
|
|
425
|
-
invokeOnValueCommit({ computed, prop }) {
|
|
426
|
-
prop("onValueCommit")?.({
|
|
427
|
-
value: computed("formattedValue"),
|
|
428
|
-
valueAsNumber: computed("valueAsNumber")
|
|
429
|
-
});
|
|
430
|
-
},
|
|
431
|
-
syncInputElement({ context, event, computed, scope }) {
|
|
432
|
-
const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
|
|
433
|
-
const inputEl = dom.getInputEl(scope);
|
|
434
|
-
const sel = event.selection ?? (0, import_cursor.recordCursor)(inputEl, scope);
|
|
435
|
-
(0, import_dom_query.raf)(() => {
|
|
436
|
-
(0, import_dom_query.setElementValue)(inputEl, value);
|
|
437
|
-
(0, import_cursor.restoreCursor)(inputEl, sel, scope);
|
|
438
|
-
});
|
|
439
|
-
},
|
|
440
|
-
setFormattedValue({ context, computed, action }) {
|
|
441
|
-
context.set("value", computed("formattedValue"));
|
|
442
|
-
action(["syncInputElement"]);
|
|
443
|
-
},
|
|
444
|
-
setCursorPoint({ context, event }) {
|
|
445
|
-
context.set("scrubberCursorPoint", event.point);
|
|
446
|
-
},
|
|
447
|
-
clearCursorPoint({ context }) {
|
|
448
|
-
context.set("scrubberCursorPoint", null);
|
|
449
|
-
},
|
|
450
|
-
setVirtualCursorPosition({ context, scope }) {
|
|
451
|
-
const cursorEl = dom.getCursorEl(scope);
|
|
452
|
-
const point = context.get("scrubberCursorPoint");
|
|
453
|
-
if (!cursorEl || !point) return;
|
|
454
|
-
cursorEl.style.transform = `translate3d(${point.x}px, ${point.y}px, 0px)`;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
458
4
|
});
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
5
|
+
let _zag_js_core = require("@zag-js/core");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
8
|
+
const require_cursor = require("./cursor.js");
|
|
9
|
+
const require_number_input_dom = require("./number-input.dom.js");
|
|
10
|
+
const require_number_input_translations = require("./number-input.translations.js");
|
|
11
|
+
const require_number_input_utils = require("./number-input.utils.js");
|
|
12
|
+
// src/number-input.machine.ts
|
|
13
|
+
const { choose, guards, createMachine } = (0, _zag_js_core.setup)();
|
|
14
|
+
const { not, and } = guards;
|
|
15
|
+
const machine = createMachine({
|
|
16
|
+
props({ props }) {
|
|
17
|
+
const step = require_number_input_utils.getDefaultStep(props.step, props.formatOptions);
|
|
18
|
+
return {
|
|
19
|
+
dir: "ltr",
|
|
20
|
+
locale: "en-US",
|
|
21
|
+
focusInputOnChange: true,
|
|
22
|
+
clampValueOnBlur: !props.allowOverflow,
|
|
23
|
+
allowOverflow: false,
|
|
24
|
+
inputMode: "decimal",
|
|
25
|
+
pattern: "-?[0-9]*(.[0-9]+)?",
|
|
26
|
+
defaultValue: "",
|
|
27
|
+
step,
|
|
28
|
+
min: Number.MIN_SAFE_INTEGER,
|
|
29
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
30
|
+
spinOnPress: true,
|
|
31
|
+
...props,
|
|
32
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
33
|
+
smallStep: props.smallStep ?? step / 10
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
initialState() {
|
|
37
|
+
return "idle";
|
|
38
|
+
},
|
|
39
|
+
context({ prop, bindable, getComputed }) {
|
|
40
|
+
return {
|
|
41
|
+
value: bindable(() => ({
|
|
42
|
+
defaultValue: prop("defaultValue"),
|
|
43
|
+
value: prop("value"),
|
|
44
|
+
onChange(value) {
|
|
45
|
+
const computed = getComputed();
|
|
46
|
+
const valueAsNumber = require_number_input_utils.parseValue(value, {
|
|
47
|
+
computed,
|
|
48
|
+
prop
|
|
49
|
+
});
|
|
50
|
+
prop("onValueChange")?.({
|
|
51
|
+
value,
|
|
52
|
+
valueAsNumber
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
})),
|
|
56
|
+
hint: bindable(() => ({ defaultValue: null })),
|
|
57
|
+
scrubberCursorPoint: bindable(() => ({
|
|
58
|
+
defaultValue: null,
|
|
59
|
+
hash(value) {
|
|
60
|
+
return value ? `x:${value.x}, y:${value.y}` : "";
|
|
61
|
+
}
|
|
62
|
+
})),
|
|
63
|
+
fieldsetDisabled: bindable(() => ({ defaultValue: false }))
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
refs() {
|
|
67
|
+
return { syncFrame: _zag_js_dom_query.AnimationFrame.create() };
|
|
68
|
+
},
|
|
69
|
+
computed: {
|
|
70
|
+
isRtl: ({ prop }) => prop("dir") === "rtl",
|
|
71
|
+
valueAsNumber: ({ context, computed, prop }) => require_number_input_utils.parseValue(context.get("value"), {
|
|
72
|
+
computed,
|
|
73
|
+
prop
|
|
74
|
+
}),
|
|
75
|
+
formattedValue: ({ computed, prop }) => require_number_input_utils.formatValue(computed("valueAsNumber"), {
|
|
76
|
+
computed,
|
|
77
|
+
prop
|
|
78
|
+
}),
|
|
79
|
+
isAtMin: ({ computed, prop }) => (0, _zag_js_utils.isValueAtMin)(computed("valueAsNumber"), prop("min")),
|
|
80
|
+
isAtMax: ({ computed, prop }) => (0, _zag_js_utils.isValueAtMax)(computed("valueAsNumber"), prop("max")),
|
|
81
|
+
isOutOfRange: ({ computed, prop }) => !(0, _zag_js_utils.isValueWithinRange)(computed("valueAsNumber"), prop("min"), prop("max")),
|
|
82
|
+
isValueEmpty: ({ context }) => context.get("value") === "",
|
|
83
|
+
isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
84
|
+
canIncrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMax"),
|
|
85
|
+
canDecrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMin"),
|
|
86
|
+
valueText: ({ prop, context }) => {
|
|
87
|
+
return (0, _zag_js_utils.mergeWithDefault)(require_number_input_translations.defaultTranslations, prop("translations")).valueText?.(context.get("value"));
|
|
88
|
+
},
|
|
89
|
+
formatter: (0, _zag_js_core.memo)(({ prop }) => [prop("locale"), prop("formatOptions")], ([locale, formatOptions]) => require_number_input_utils.createFormatter(locale, formatOptions)),
|
|
90
|
+
parser: (0, _zag_js_core.memo)(({ prop }) => [prop("locale"), prop("formatOptions")], ([locale, formatOptions]) => require_number_input_utils.createParser(locale, formatOptions))
|
|
91
|
+
},
|
|
92
|
+
watch({ track, action, context, computed, prop }) {
|
|
93
|
+
track([
|
|
94
|
+
() => context.get("value"),
|
|
95
|
+
() => prop("locale"),
|
|
96
|
+
() => JSON.stringify(prop("formatOptions"))
|
|
97
|
+
], () => {
|
|
98
|
+
action(["syncInputElement"]);
|
|
99
|
+
});
|
|
100
|
+
track([() => computed("isOutOfRange")], () => {
|
|
101
|
+
action(["invokeOnInvalid"]);
|
|
102
|
+
});
|
|
103
|
+
track([() => context.hash("scrubberCursorPoint")], () => {
|
|
104
|
+
action(["setVirtualCursorPosition"]);
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
effects: ["trackFormControl"],
|
|
108
|
+
exit: ["cancelSyncFrame"],
|
|
109
|
+
on: {
|
|
110
|
+
"VALUE.SET": { actions: ["setRawValue"] },
|
|
111
|
+
"VALUE.CLEAR": { actions: ["clearValue"] },
|
|
112
|
+
"VALUE.INCREMENT": { actions: ["increment"] },
|
|
113
|
+
"VALUE.DECREMENT": { actions: ["decrement"] }
|
|
114
|
+
},
|
|
115
|
+
states: {
|
|
116
|
+
idle: { on: {
|
|
117
|
+
"TRIGGER.PRESS_DOWN": [{
|
|
118
|
+
guard: "isTouchPointer",
|
|
119
|
+
target: "before:spin",
|
|
120
|
+
actions: ["setHint"]
|
|
121
|
+
}, {
|
|
122
|
+
target: "before:spin",
|
|
123
|
+
actions: [
|
|
124
|
+
"focusInput",
|
|
125
|
+
"invokeOnFocus",
|
|
126
|
+
"setHint"
|
|
127
|
+
]
|
|
128
|
+
}],
|
|
129
|
+
"SCRUBBER.PRESS_DOWN": {
|
|
130
|
+
target: "scrubbing",
|
|
131
|
+
actions: [
|
|
132
|
+
"focusInput",
|
|
133
|
+
"invokeOnFocus",
|
|
134
|
+
"setHint",
|
|
135
|
+
"setCursorPoint"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"INPUT.FOCUS": {
|
|
139
|
+
target: "focused",
|
|
140
|
+
actions: ["focusInput", "invokeOnFocus"]
|
|
141
|
+
}
|
|
142
|
+
} },
|
|
143
|
+
focused: {
|
|
144
|
+
tags: ["focus"],
|
|
145
|
+
effects: ["attachWheelListener"],
|
|
146
|
+
on: {
|
|
147
|
+
"TRIGGER.PRESS_DOWN": [{
|
|
148
|
+
guard: "isTouchPointer",
|
|
149
|
+
target: "before:spin",
|
|
150
|
+
actions: ["setHint"]
|
|
151
|
+
}, {
|
|
152
|
+
target: "before:spin",
|
|
153
|
+
actions: ["focusInput", "setHint"]
|
|
154
|
+
}],
|
|
155
|
+
"SCRUBBER.PRESS_DOWN": {
|
|
156
|
+
target: "scrubbing",
|
|
157
|
+
actions: [
|
|
158
|
+
"focusInput",
|
|
159
|
+
"setHint",
|
|
160
|
+
"setCursorPoint"
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
"INPUT.ARROW_UP": { actions: ["increment"] },
|
|
164
|
+
"INPUT.ARROW_DOWN": { actions: ["decrement"] },
|
|
165
|
+
"INPUT.HOME": { actions: ["decrementToMin"] },
|
|
166
|
+
"INPUT.END": { actions: ["incrementToMax"] },
|
|
167
|
+
"INPUT.CHANGE": { actions: ["setValue", "setHint"] },
|
|
168
|
+
"INPUT.BLUR": [
|
|
169
|
+
{
|
|
170
|
+
guard: and("clampValueOnBlur", not("isValueEmpty"), not("isInRange")),
|
|
171
|
+
target: "idle",
|
|
172
|
+
actions: [
|
|
173
|
+
"setClampedValue",
|
|
174
|
+
"clearHint",
|
|
175
|
+
"invokeOnBlur",
|
|
176
|
+
"invokeOnValueCommit"
|
|
177
|
+
]
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
guard: not("isInRange"),
|
|
181
|
+
target: "idle",
|
|
182
|
+
actions: [
|
|
183
|
+
"setFormattedValue",
|
|
184
|
+
"clearHint",
|
|
185
|
+
"invokeOnBlur",
|
|
186
|
+
"invokeOnInvalid",
|
|
187
|
+
"invokeOnValueCommit"
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
target: "idle",
|
|
192
|
+
actions: [
|
|
193
|
+
"setFormattedValue",
|
|
194
|
+
"clearHint",
|
|
195
|
+
"invokeOnBlur",
|
|
196
|
+
"invokeOnValueCommit"
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"INPUT.ENTER": { actions: [
|
|
201
|
+
"setFormattedValue",
|
|
202
|
+
"clearHint",
|
|
203
|
+
"invokeOnBlur",
|
|
204
|
+
"invokeOnValueCommit"
|
|
205
|
+
] }
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
"before:spin": {
|
|
209
|
+
tags: ["focus"],
|
|
210
|
+
effects: ["trackButtonDisabled", "waitForChangeDelay"],
|
|
211
|
+
entry: choose([{
|
|
212
|
+
guard: "isIncrementHint",
|
|
213
|
+
actions: ["increment"]
|
|
214
|
+
}, {
|
|
215
|
+
guard: "isDecrementHint",
|
|
216
|
+
actions: ["decrement"]
|
|
217
|
+
}]),
|
|
218
|
+
on: {
|
|
219
|
+
CHANGE_DELAY: {
|
|
220
|
+
target: "spinning",
|
|
221
|
+
guard: and("isInRange", "spinOnPress")
|
|
222
|
+
},
|
|
223
|
+
"TRIGGER.PRESS_UP": [{
|
|
224
|
+
guard: "isTouchPointer",
|
|
225
|
+
target: "focused",
|
|
226
|
+
actions: ["clearHint"]
|
|
227
|
+
}, {
|
|
228
|
+
target: "focused",
|
|
229
|
+
actions: ["focusInput", "clearHint"]
|
|
230
|
+
}]
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
spinning: {
|
|
234
|
+
tags: ["focus"],
|
|
235
|
+
effects: ["trackButtonDisabled", "spinValue"],
|
|
236
|
+
on: {
|
|
237
|
+
SPIN: [{
|
|
238
|
+
guard: "isIncrementHint",
|
|
239
|
+
actions: ["increment"]
|
|
240
|
+
}, {
|
|
241
|
+
guard: "isDecrementHint",
|
|
242
|
+
actions: ["decrement"]
|
|
243
|
+
}],
|
|
244
|
+
"TRIGGER.PRESS_UP": {
|
|
245
|
+
target: "focused",
|
|
246
|
+
actions: ["focusInput", "clearHint"]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
scrubbing: {
|
|
251
|
+
tags: ["focus"],
|
|
252
|
+
effects: [
|
|
253
|
+
"activatePointerLock",
|
|
254
|
+
"trackMousemove",
|
|
255
|
+
"setupVirtualCursor",
|
|
256
|
+
"preventTextSelection"
|
|
257
|
+
],
|
|
258
|
+
on: {
|
|
259
|
+
"SCRUBBER.POINTER_UP": {
|
|
260
|
+
target: "focused",
|
|
261
|
+
actions: ["focusInput", "clearCursorPoint"]
|
|
262
|
+
},
|
|
263
|
+
"SCRUBBER.POINTER_MOVE": [{
|
|
264
|
+
guard: "isIncrementHint",
|
|
265
|
+
actions: ["increment", "setCursorPoint"]
|
|
266
|
+
}, {
|
|
267
|
+
guard: "isDecrementHint",
|
|
268
|
+
actions: ["decrement", "setCursorPoint"]
|
|
269
|
+
}]
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
implementations: {
|
|
274
|
+
guards: {
|
|
275
|
+
clampValueOnBlur: ({ prop }) => prop("clampValueOnBlur"),
|
|
276
|
+
spinOnPress: ({ prop }) => !!prop("spinOnPress"),
|
|
277
|
+
isInRange: ({ computed }) => !computed("isOutOfRange"),
|
|
278
|
+
isValueEmpty: ({ computed }) => computed("isValueEmpty"),
|
|
279
|
+
isDecrementHint: ({ context, event }) => (event.hint ?? context.get("hint")) === "decrement",
|
|
280
|
+
isIncrementHint: ({ context, event }) => (event.hint ?? context.get("hint")) === "increment",
|
|
281
|
+
isTouchPointer: ({ event }) => event.pointerType === "touch"
|
|
282
|
+
},
|
|
283
|
+
effects: {
|
|
284
|
+
waitForChangeDelay({ send }) {
|
|
285
|
+
const id = setTimeout(() => {
|
|
286
|
+
send({ type: "CHANGE_DELAY" });
|
|
287
|
+
}, 300);
|
|
288
|
+
return () => clearTimeout(id);
|
|
289
|
+
},
|
|
290
|
+
spinValue({ send }) {
|
|
291
|
+
const id = setInterval(() => {
|
|
292
|
+
send({ type: "SPIN" });
|
|
293
|
+
}, 50);
|
|
294
|
+
return () => clearInterval(id);
|
|
295
|
+
},
|
|
296
|
+
trackFormControl({ context, scope }) {
|
|
297
|
+
const inputEl = require_number_input_dom.getInputEl(scope);
|
|
298
|
+
return (0, _zag_js_dom_query.trackFormControl)(inputEl, {
|
|
299
|
+
onFieldsetDisabledChange(disabled) {
|
|
300
|
+
context.set("fieldsetDisabled", disabled);
|
|
301
|
+
},
|
|
302
|
+
onFormReset() {
|
|
303
|
+
context.set("value", context.initial("value"));
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
setupVirtualCursor({ context, scope }) {
|
|
308
|
+
const point = context.get("scrubberCursorPoint");
|
|
309
|
+
return require_number_input_dom.setupVirtualCursor(scope, point);
|
|
310
|
+
},
|
|
311
|
+
preventTextSelection({ scope }) {
|
|
312
|
+
return require_number_input_dom.preventTextSelection(scope);
|
|
313
|
+
},
|
|
314
|
+
trackButtonDisabled({ context, scope, send }) {
|
|
315
|
+
const hint = context.get("hint");
|
|
316
|
+
const btn = require_number_input_dom.getPressedTriggerEl(scope, hint);
|
|
317
|
+
return (0, _zag_js_dom_query.observeAttributes)(btn, {
|
|
318
|
+
attributes: ["disabled"],
|
|
319
|
+
callback() {
|
|
320
|
+
send({
|
|
321
|
+
type: "TRIGGER.PRESS_UP",
|
|
322
|
+
src: "attr"
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
attachWheelListener({ scope, send, prop }) {
|
|
328
|
+
const inputEl = require_number_input_dom.getInputEl(scope);
|
|
329
|
+
if (!inputEl || !scope.isActiveElement(inputEl) || !prop("allowMouseWheel")) return;
|
|
330
|
+
function onWheel(event) {
|
|
331
|
+
event.preventDefault();
|
|
332
|
+
const dir = Math.sign(event.deltaY) * -1;
|
|
333
|
+
if (dir === 1) send({ type: "VALUE.INCREMENT" });
|
|
334
|
+
else if (dir === -1) send({ type: "VALUE.DECREMENT" });
|
|
335
|
+
}
|
|
336
|
+
return (0, _zag_js_dom_query.addDomEvent)(inputEl, "wheel", onWheel, { passive: false });
|
|
337
|
+
},
|
|
338
|
+
activatePointerLock({ scope }) {
|
|
339
|
+
if ((0, _zag_js_dom_query.isSafari)()) return;
|
|
340
|
+
return (0, _zag_js_dom_query.requestPointerLock)(scope.getDoc());
|
|
341
|
+
},
|
|
342
|
+
trackMousemove({ scope, send, context, computed }) {
|
|
343
|
+
const doc = scope.getDoc();
|
|
344
|
+
function onMousemove(event) {
|
|
345
|
+
const point = context.get("scrubberCursorPoint");
|
|
346
|
+
const isRtl = computed("isRtl");
|
|
347
|
+
const value = require_number_input_dom.getMousemoveValue(scope, {
|
|
348
|
+
point,
|
|
349
|
+
isRtl,
|
|
350
|
+
event
|
|
351
|
+
});
|
|
352
|
+
if (!value.hint) return;
|
|
353
|
+
send({
|
|
354
|
+
type: "SCRUBBER.POINTER_MOVE",
|
|
355
|
+
hint: value.hint,
|
|
356
|
+
point: value.point
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function onMouseup() {
|
|
360
|
+
send({ type: "SCRUBBER.POINTER_UP" });
|
|
361
|
+
}
|
|
362
|
+
return (0, _zag_js_utils.callAll)((0, _zag_js_dom_query.addDomEvent)(doc, "mousemove", onMousemove, false), (0, _zag_js_dom_query.addDomEvent)(doc, "mouseup", onMouseup, false));
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
actions: {
|
|
366
|
+
focusInput({ scope, prop }) {
|
|
367
|
+
if (!prop("focusInputOnChange")) return;
|
|
368
|
+
const inputEl = require_number_input_dom.getInputEl(scope);
|
|
369
|
+
if (scope.isActiveElement(inputEl)) return;
|
|
370
|
+
(0, _zag_js_dom_query.raf)(() => inputEl?.focus({ preventScroll: true }));
|
|
371
|
+
},
|
|
372
|
+
increment({ context, event, prop, computed }) {
|
|
373
|
+
let nextValue = (0, _zag_js_utils.incrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
|
|
374
|
+
if (!prop("allowOverflow")) nextValue = (0, _zag_js_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
375
|
+
context.set("value", require_number_input_utils.formatValue(nextValue, {
|
|
376
|
+
computed,
|
|
377
|
+
prop
|
|
378
|
+
}));
|
|
379
|
+
},
|
|
380
|
+
decrement({ context, event, prop, computed }) {
|
|
381
|
+
let nextValue = (0, _zag_js_utils.decrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
|
|
382
|
+
if (!prop("allowOverflow")) nextValue = (0, _zag_js_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
383
|
+
context.set("value", require_number_input_utils.formatValue(nextValue, {
|
|
384
|
+
computed,
|
|
385
|
+
prop
|
|
386
|
+
}));
|
|
387
|
+
},
|
|
388
|
+
setClampedValue({ context, prop, computed }) {
|
|
389
|
+
const nextValue = (0, _zag_js_utils.clampValue)(computed("valueAsNumber"), prop("min"), prop("max"));
|
|
390
|
+
context.set("value", require_number_input_utils.formatValue(nextValue, {
|
|
391
|
+
computed,
|
|
392
|
+
prop
|
|
393
|
+
}));
|
|
394
|
+
},
|
|
395
|
+
setRawValue({ context, event, prop, computed }) {
|
|
396
|
+
let nextValue = typeof event.value === "number" ? event.value : require_number_input_utils.parseValue(event.value, {
|
|
397
|
+
computed,
|
|
398
|
+
prop
|
|
399
|
+
});
|
|
400
|
+
if (!prop("allowOverflow")) nextValue = (0, _zag_js_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
401
|
+
context.set("value", require_number_input_utils.formatValue(nextValue, {
|
|
402
|
+
computed,
|
|
403
|
+
prop
|
|
404
|
+
}));
|
|
405
|
+
},
|
|
406
|
+
setValue({ context, event }) {
|
|
407
|
+
const value = event.target?.value ?? event.value;
|
|
408
|
+
context.set("value", value);
|
|
409
|
+
},
|
|
410
|
+
clearValue({ context }) {
|
|
411
|
+
context.set("value", "");
|
|
412
|
+
},
|
|
413
|
+
incrementToMax({ context, prop, computed }) {
|
|
414
|
+
const value = require_number_input_utils.formatValue(prop("max"), {
|
|
415
|
+
computed,
|
|
416
|
+
prop
|
|
417
|
+
});
|
|
418
|
+
context.set("value", value);
|
|
419
|
+
},
|
|
420
|
+
decrementToMin({ context, prop, computed }) {
|
|
421
|
+
const value = require_number_input_utils.formatValue(prop("min"), {
|
|
422
|
+
computed,
|
|
423
|
+
prop
|
|
424
|
+
});
|
|
425
|
+
context.set("value", value);
|
|
426
|
+
},
|
|
427
|
+
setHint({ context, event }) {
|
|
428
|
+
context.set("hint", event.hint);
|
|
429
|
+
},
|
|
430
|
+
clearHint({ context }) {
|
|
431
|
+
context.set("hint", null);
|
|
432
|
+
},
|
|
433
|
+
invokeOnFocus({ computed, prop }) {
|
|
434
|
+
prop("onFocusChange")?.({
|
|
435
|
+
focused: true,
|
|
436
|
+
value: computed("formattedValue"),
|
|
437
|
+
valueAsNumber: computed("valueAsNumber")
|
|
438
|
+
});
|
|
439
|
+
},
|
|
440
|
+
invokeOnBlur({ computed, prop }) {
|
|
441
|
+
prop("onFocusChange")?.({
|
|
442
|
+
focused: false,
|
|
443
|
+
value: computed("formattedValue"),
|
|
444
|
+
valueAsNumber: computed("valueAsNumber")
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
invokeOnInvalid({ computed, prop, event }) {
|
|
448
|
+
if (event.type === "INPUT.CHANGE") return;
|
|
449
|
+
const reason = computed("valueAsNumber") > prop("max") ? "rangeOverflow" : "rangeUnderflow";
|
|
450
|
+
prop("onValueInvalid")?.({
|
|
451
|
+
reason,
|
|
452
|
+
value: computed("formattedValue"),
|
|
453
|
+
valueAsNumber: computed("valueAsNumber")
|
|
454
|
+
});
|
|
455
|
+
},
|
|
456
|
+
invokeOnValueCommit({ computed, prop }) {
|
|
457
|
+
prop("onValueCommit")?.({
|
|
458
|
+
value: computed("formattedValue"),
|
|
459
|
+
valueAsNumber: computed("valueAsNumber")
|
|
460
|
+
});
|
|
461
|
+
},
|
|
462
|
+
syncInputElement({ context, event, computed, scope, refs }) {
|
|
463
|
+
const value = event.type.endsWith("CHANGE") ? context.get("value") : computed("formattedValue");
|
|
464
|
+
const inputEl = require_number_input_dom.getInputEl(scope);
|
|
465
|
+
const sel = event.selection ?? require_cursor.recordCursor(inputEl, scope);
|
|
466
|
+
const scheduledText = inputEl?.value;
|
|
467
|
+
refs.get("syncFrame").request(() => {
|
|
468
|
+
if (inputEl && inputEl.value !== scheduledText) return;
|
|
469
|
+
(0, _zag_js_dom_query.setElementValue)(inputEl, value);
|
|
470
|
+
require_cursor.restoreCursor(inputEl, sel, scope);
|
|
471
|
+
});
|
|
472
|
+
},
|
|
473
|
+
cancelSyncFrame({ refs }) {
|
|
474
|
+
refs.get("syncFrame").cancel();
|
|
475
|
+
},
|
|
476
|
+
setFormattedValue({ context, computed, action }) {
|
|
477
|
+
context.set("value", computed("formattedValue"));
|
|
478
|
+
action(["syncInputElement"]);
|
|
479
|
+
},
|
|
480
|
+
setCursorPoint({ context, event }) {
|
|
481
|
+
context.set("scrubberCursorPoint", event.point);
|
|
482
|
+
},
|
|
483
|
+
clearCursorPoint({ context }) {
|
|
484
|
+
context.set("scrubberCursorPoint", null);
|
|
485
|
+
},
|
|
486
|
+
setVirtualCursorPosition({ context, scope }) {
|
|
487
|
+
const cursorEl = require_number_input_dom.getCursorEl(scope);
|
|
488
|
+
const point = context.get("scrubberCursorPoint");
|
|
489
|
+
if (!cursorEl || !point) return;
|
|
490
|
+
cursorEl.style.transform = `translate3d(${point.x}px, ${point.y}px, 0px)`;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
462
494
|
});
|
|
495
|
+
exports.machine = machine;
|