@zag-js/number-input 2.0.0-next.3 → 2.0.0-next.4
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.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 -43
- package/dist/number-input.anatomy.mjs +4 -17
- package/dist/number-input.connect.d.mts +3 -8
- package/dist/number-input.connect.d.ts +3 -8
- package/dist/number-input.connect.js +483 -377
- package/dist/number-input.connect.mjs +478 -353
- package/dist/number-input.dom.d.mts +33 -33
- package/dist/number-input.dom.d.ts +33 -33
- package/dist/number-input.dom.js +99 -142
- package/dist/number-input.dom.mjs +78 -103
- package/dist/number-input.machine.d.mts +2 -8
- package/dist/number-input.machine.d.ts +2 -8
- package/dist/number-input.machine.js +600 -528
- package/dist/number-input.machine.mjs +596 -512
- package/dist/number-input.props.d.mts +3 -9
- package/dist/number-input.props.d.ts +3 -9
- package/dist/number-input.props.js +43 -69
- package/dist/number-input.props.mjs +39 -43
- package/dist/number-input.translations.d.mts +3 -8
- package/dist/number-input.translations.d.ts +3 -8
- package/dist/number-input.translations.js +9 -31
- package/dist/number-input.translations.mjs +5 -6
- package/dist/number-input.types.d.mts +418 -408
- package/dist/number-input.types.d.ts +418 -408
- package/dist/number-input.types.js +4 -18
- package/dist/number-input.types.mjs +1 -0
- package/dist/number-input.utils.d.mts +16 -12
- package/dist/number-input.utils.d.ts +16 -12
- package/dist/number-input.utils.js +51 -57
- package/dist/number-input.utils.mjs +39 -27
- package/package.json +8 -8
- package/dist/cursor.d.mts +0 -12
- package/dist/cursor.d.ts +0 -12
- package/dist/cursor.js +0 -111
- package/dist/cursor.mjs +0 -84
|
@@ -1,357 +1,482 @@
|
|
|
1
|
-
// src/number-input.connect.ts
|
|
2
|
-
import {
|
|
3
|
-
ariaAttr,
|
|
4
|
-
dataAttr,
|
|
5
|
-
getEventPoint,
|
|
6
|
-
getEventStepValue,
|
|
7
|
-
getWindow,
|
|
8
|
-
MAX_Z_INDEX,
|
|
9
|
-
isComposingEvent,
|
|
10
|
-
isLeftClick,
|
|
11
|
-
isModifierKey,
|
|
12
|
-
raf,
|
|
13
|
-
setCaretToEnd
|
|
14
|
-
} from "@zag-js/dom-query";
|
|
15
|
-
import { mergeWithDefault, roundToDpr, toPx } from "@zag-js/utils";
|
|
16
|
-
import { recordCursor } from "./cursor.mjs";
|
|
17
1
|
import { parts } from "./number-input.anatomy.mjs";
|
|
18
|
-
import
|
|
2
|
+
import { getHiddenInputId, getInputEl, getInputId, getLabelId } from "./number-input.dom.mjs";
|
|
19
3
|
import { defaultTranslations } from "./number-input.translations.mjs";
|
|
4
|
+
import { normalizeNumberText } from "./number-input.utils.mjs";
|
|
5
|
+
import { MAX_Z_INDEX, ariaAttr, dataAttr, getEventPoint, getEventStepValue, getNativeEvent, getWindow, isComposingEvent, isInternalChangeEvent, isLeftClick, isModifierKey, raf, recordCursor, setCaretToEnd, visuallyHiddenStyle } from "@zag-js/dom-query";
|
|
6
|
+
import { mergeWithDefault, roundToDpr, toPx } from "@zag-js/utils";
|
|
7
|
+
// src/number-input.connect.ts
|
|
20
8
|
function connect(service, normalize) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
9
|
+
const { state, send, prop, scope, computed, context } = service;
|
|
10
|
+
const focused = state.hasTag("focus");
|
|
11
|
+
const disabled = computed("isDisabled");
|
|
12
|
+
const readOnly = !!prop("readOnly");
|
|
13
|
+
const required = !!prop("required");
|
|
14
|
+
const scrubbing = state.matches("scrubbing");
|
|
15
|
+
const empty = computed("isValueEmpty");
|
|
16
|
+
const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
|
|
17
|
+
const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
|
|
18
|
+
const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
|
|
19
|
+
const translations = mergeWithDefault(defaultTranslations, prop("translations"));
|
|
20
|
+
const min = prop("min");
|
|
21
|
+
const max = prop("max");
|
|
22
|
+
const allowsNegative = min == null || min < 0;
|
|
23
|
+
const inputMode = prop("inputMode") ?? (context.get("platform").iPhone && allowsNegative ? "text" : "decimal");
|
|
24
|
+
function getRootState() {
|
|
25
|
+
return {
|
|
26
|
+
disabled,
|
|
27
|
+
focused,
|
|
28
|
+
invalid,
|
|
29
|
+
scrubbing
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getInputState() {
|
|
33
|
+
return {
|
|
34
|
+
disabled,
|
|
35
|
+
invalid,
|
|
36
|
+
readOnly,
|
|
37
|
+
scrubbing
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function getIncrementTriggerState() {
|
|
41
|
+
return { disabled: isIncrementDisabled };
|
|
42
|
+
}
|
|
43
|
+
function getDecrementTriggerState() {
|
|
44
|
+
return { disabled: isDecrementDisabled };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
focused,
|
|
48
|
+
scrubbing,
|
|
49
|
+
invalid,
|
|
50
|
+
empty,
|
|
51
|
+
value: context.get("value"),
|
|
52
|
+
formattedValue: computed("formattedValue"),
|
|
53
|
+
setValue(value) {
|
|
54
|
+
send({
|
|
55
|
+
type: "VALUE.SET",
|
|
56
|
+
value,
|
|
57
|
+
src: "script"
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
clearValue() {
|
|
61
|
+
send({
|
|
62
|
+
type: "VALUE.CLEAR",
|
|
63
|
+
src: "script"
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
increment() {
|
|
67
|
+
send({
|
|
68
|
+
type: "VALUE.INCREMENT",
|
|
69
|
+
src: "script"
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
decrement() {
|
|
73
|
+
send({
|
|
74
|
+
type: "VALUE.DECREMENT",
|
|
75
|
+
src: "script"
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
setToMax() {
|
|
79
|
+
if (max == null) return;
|
|
80
|
+
send({
|
|
81
|
+
type: "VALUE.SET",
|
|
82
|
+
value: max,
|
|
83
|
+
src: "script"
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
setToMin() {
|
|
87
|
+
if (min == null) return;
|
|
88
|
+
send({
|
|
89
|
+
type: "VALUE.SET",
|
|
90
|
+
value: min,
|
|
91
|
+
src: "script"
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
focus() {
|
|
95
|
+
getInputEl(scope)?.focus();
|
|
96
|
+
},
|
|
97
|
+
getRootState,
|
|
98
|
+
getRootProps() {
|
|
99
|
+
const rootState = getRootState();
|
|
100
|
+
return normalize.element({
|
|
101
|
+
...parts.root.attrs(scope.id),
|
|
102
|
+
dir: prop("dir"),
|
|
103
|
+
"data-disabled": dataAttr(rootState.disabled),
|
|
104
|
+
"data-focus": dataAttr(rootState.focused),
|
|
105
|
+
"data-invalid": dataAttr(rootState.invalid),
|
|
106
|
+
"data-scrubbing": dataAttr(rootState.scrubbing)
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
getLabelProps() {
|
|
110
|
+
return normalize.label({
|
|
111
|
+
...parts.label.attrs(scope.id),
|
|
112
|
+
dir: prop("dir"),
|
|
113
|
+
"data-disabled": dataAttr(disabled),
|
|
114
|
+
"data-focus": dataAttr(focused),
|
|
115
|
+
"data-invalid": dataAttr(invalid),
|
|
116
|
+
"data-required": dataAttr(required),
|
|
117
|
+
"data-scrubbing": dataAttr(scrubbing),
|
|
118
|
+
id: getLabelId(scope),
|
|
119
|
+
htmlFor: getInputId(scope),
|
|
120
|
+
onClick() {
|
|
121
|
+
raf(() => {
|
|
122
|
+
setCaretToEnd(getInputEl(scope));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
getControlProps() {
|
|
128
|
+
return normalize.element({
|
|
129
|
+
...parts.control.attrs(scope.id),
|
|
130
|
+
dir: prop("dir"),
|
|
131
|
+
role: "group",
|
|
132
|
+
"aria-disabled": disabled,
|
|
133
|
+
"data-focus": dataAttr(focused),
|
|
134
|
+
"data-disabled": dataAttr(disabled),
|
|
135
|
+
"data-invalid": dataAttr(invalid),
|
|
136
|
+
"data-scrubbing": dataAttr(scrubbing),
|
|
137
|
+
"aria-invalid": ariaAttr(invalid)
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
getValueTextProps() {
|
|
141
|
+
return normalize.element({
|
|
142
|
+
...parts.valueText.attrs(scope.id),
|
|
143
|
+
dir: prop("dir"),
|
|
144
|
+
"data-disabled": dataAttr(disabled),
|
|
145
|
+
"data-invalid": dataAttr(invalid),
|
|
146
|
+
"data-focus": dataAttr(focused),
|
|
147
|
+
"data-scrubbing": dataAttr(scrubbing)
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
getInputState,
|
|
151
|
+
getInputProps() {
|
|
152
|
+
const inputState = getInputState();
|
|
153
|
+
return normalize.input({
|
|
154
|
+
...parts.input.attrs(scope.id),
|
|
155
|
+
dir: prop("dir"),
|
|
156
|
+
id: getInputId(scope),
|
|
157
|
+
defaultValue: context.get("inputValue"),
|
|
158
|
+
pattern: prop("formatOptions") ? void 0 : prop("pattern"),
|
|
159
|
+
inputMode,
|
|
160
|
+
"aria-invalid": ariaAttr(inputState.invalid),
|
|
161
|
+
"data-invalid": dataAttr(inputState.invalid),
|
|
162
|
+
disabled: inputState.disabled,
|
|
163
|
+
"data-disabled": dataAttr(inputState.disabled),
|
|
164
|
+
readOnly: inputState.readOnly,
|
|
165
|
+
required: prop("required"),
|
|
166
|
+
autoComplete: "off",
|
|
167
|
+
autoCorrect: "off",
|
|
168
|
+
spellCheck: "false",
|
|
169
|
+
type: "text",
|
|
170
|
+
"aria-roledescription": context.get("platform").ios ? void 0 : translations.roleDescription,
|
|
171
|
+
"data-scrubbing": dataAttr(inputState.scrubbing),
|
|
172
|
+
onFocus() {
|
|
173
|
+
send({ type: "INPUT.FOCUS" });
|
|
174
|
+
},
|
|
175
|
+
onBlur() {
|
|
176
|
+
send({
|
|
177
|
+
type: "INPUT.BLUR",
|
|
178
|
+
src: "input-blur"
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
onInput(event) {
|
|
182
|
+
const selection = recordCursor(event.currentTarget);
|
|
183
|
+
send({
|
|
184
|
+
type: "INPUT.CHANGE",
|
|
185
|
+
value: event.currentTarget.value,
|
|
186
|
+
selection,
|
|
187
|
+
src: "input-change"
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
onBeforeInput(event) {
|
|
191
|
+
try {
|
|
192
|
+
const { selectionStart, selectionEnd, value } = event.currentTarget;
|
|
193
|
+
const nextValue = value.slice(0, selectionStart) + (event.data ?? "") + value.slice(selectionEnd);
|
|
194
|
+
const allowOutOfRange = prop("allowOutOfRange");
|
|
195
|
+
if (!computed("parser").isValidPartialNumber(normalizeNumberText(nextValue), allowOutOfRange ? void 0 : min, allowOutOfRange ? void 0 : max)) event.preventDefault();
|
|
196
|
+
} catch {}
|
|
197
|
+
},
|
|
198
|
+
onKeyDown(event) {
|
|
199
|
+
if (event.defaultPrevented) return;
|
|
200
|
+
if (readOnly) return;
|
|
201
|
+
if (isComposingEvent(event)) return;
|
|
202
|
+
const step = getEventStepValue(event, {
|
|
203
|
+
step: prop("step"),
|
|
204
|
+
largeStep: prop("largeStep"),
|
|
205
|
+
smallStep: prop("smallStep")
|
|
206
|
+
});
|
|
207
|
+
const exec = {
|
|
208
|
+
ArrowUp() {
|
|
209
|
+
send({
|
|
210
|
+
type: "INPUT.ARROW_UP",
|
|
211
|
+
step,
|
|
212
|
+
src: "keyboard"
|
|
213
|
+
});
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
event.stopPropagation();
|
|
216
|
+
},
|
|
217
|
+
ArrowDown() {
|
|
218
|
+
send({
|
|
219
|
+
type: "INPUT.ARROW_DOWN",
|
|
220
|
+
step,
|
|
221
|
+
src: "keyboard"
|
|
222
|
+
});
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
event.stopPropagation();
|
|
225
|
+
},
|
|
226
|
+
PageUp() {
|
|
227
|
+
send({
|
|
228
|
+
type: "INPUT.ARROW_UP",
|
|
229
|
+
step,
|
|
230
|
+
src: "keyboard"
|
|
231
|
+
});
|
|
232
|
+
event.preventDefault();
|
|
233
|
+
event.stopPropagation();
|
|
234
|
+
},
|
|
235
|
+
PageDown() {
|
|
236
|
+
send({
|
|
237
|
+
type: "INPUT.ARROW_DOWN",
|
|
238
|
+
step,
|
|
239
|
+
src: "keyboard"
|
|
240
|
+
});
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
event.stopPropagation();
|
|
243
|
+
},
|
|
244
|
+
Home() {
|
|
245
|
+
if (isModifierKey(event) || min == null) return;
|
|
246
|
+
send({
|
|
247
|
+
type: "INPUT.HOME",
|
|
248
|
+
src: "keyboard"
|
|
249
|
+
});
|
|
250
|
+
event.preventDefault();
|
|
251
|
+
event.stopPropagation();
|
|
252
|
+
},
|
|
253
|
+
End() {
|
|
254
|
+
if (isModifierKey(event) || max == null) return;
|
|
255
|
+
send({
|
|
256
|
+
type: "INPUT.END",
|
|
257
|
+
src: "keyboard"
|
|
258
|
+
});
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
event.stopPropagation();
|
|
261
|
+
},
|
|
262
|
+
Enter(event) {
|
|
263
|
+
const selection = recordCursor(event.currentTarget);
|
|
264
|
+
send({
|
|
265
|
+
type: "INPUT.ENTER",
|
|
266
|
+
selection,
|
|
267
|
+
src: "keyboard"
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}[event.key];
|
|
271
|
+
exec?.(event);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
getHiddenInputProps() {
|
|
276
|
+
const value = context.get("value");
|
|
277
|
+
const handleChange = (e) => {
|
|
278
|
+
if (isInternalChangeEvent(getNativeEvent(e)) || disabled || readOnly) return;
|
|
279
|
+
const next = e.currentTarget.valueAsNumber;
|
|
280
|
+
if (Number.isNaN(next)) send({
|
|
281
|
+
type: "VALUE.CLEAR",
|
|
282
|
+
src: "autofill"
|
|
283
|
+
});
|
|
284
|
+
else send({
|
|
285
|
+
type: "VALUE.SET",
|
|
286
|
+
value: next,
|
|
287
|
+
src: "autofill"
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
return normalize.input({
|
|
291
|
+
type: "number",
|
|
292
|
+
id: getHiddenInputId(scope),
|
|
293
|
+
name: prop("name"),
|
|
294
|
+
form: prop("form"),
|
|
295
|
+
min,
|
|
296
|
+
max,
|
|
297
|
+
step: "any",
|
|
298
|
+
disabled,
|
|
299
|
+
readOnly,
|
|
300
|
+
required,
|
|
301
|
+
defaultValue: value == null ? "" : String(value),
|
|
302
|
+
"aria-hidden": true,
|
|
303
|
+
tabIndex: -1,
|
|
304
|
+
style: visuallyHiddenStyle,
|
|
305
|
+
onChange: handleChange,
|
|
306
|
+
onInput: handleChange,
|
|
307
|
+
onFocus() {
|
|
308
|
+
getInputEl(scope)?.focus({ preventScroll: true });
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
getDecrementTriggerState,
|
|
313
|
+
getDecrementTriggerProps() {
|
|
314
|
+
const decrementTriggerState = getDecrementTriggerState();
|
|
315
|
+
return normalize.button({
|
|
316
|
+
...parts.decrementTrigger.attrs(scope.id),
|
|
317
|
+
dir: prop("dir"),
|
|
318
|
+
disabled: decrementTriggerState.disabled,
|
|
319
|
+
"data-disabled": dataAttr(decrementTriggerState.disabled),
|
|
320
|
+
"aria-label": translations.decrementLabel,
|
|
321
|
+
type: "button",
|
|
322
|
+
tabIndex: -1,
|
|
323
|
+
"aria-controls": getInputId(scope),
|
|
324
|
+
"data-scrubbing": dataAttr(scrubbing),
|
|
325
|
+
onClick(event) {
|
|
326
|
+
if (decrementTriggerState.disabled || event.detail !== 0) return;
|
|
327
|
+
send({
|
|
328
|
+
type: "VALUE.DECREMENT",
|
|
329
|
+
src: "decrement-trigger"
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
onPointerDown(event) {
|
|
333
|
+
if (decrementTriggerState.disabled) return;
|
|
334
|
+
if (!isLeftClick(event)) return;
|
|
335
|
+
send({
|
|
336
|
+
type: "TRIGGER.PRESS_DOWN",
|
|
337
|
+
direction: -1,
|
|
338
|
+
pointerType: event.pointerType,
|
|
339
|
+
src: "decrement-trigger"
|
|
340
|
+
});
|
|
341
|
+
if (event.pointerType === "mouse") event.preventDefault();
|
|
342
|
+
if (event.pointerType === "touch") event.currentTarget?.focus({ preventScroll: true });
|
|
343
|
+
},
|
|
344
|
+
onPointerUp(event) {
|
|
345
|
+
send({
|
|
346
|
+
type: "TRIGGER.PRESS_UP",
|
|
347
|
+
direction: -1,
|
|
348
|
+
pointerType: event.pointerType,
|
|
349
|
+
src: "decrement-trigger"
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
onPointerLeave(event) {
|
|
353
|
+
if (decrementTriggerState.disabled) return;
|
|
354
|
+
send({
|
|
355
|
+
type: "TRIGGER.PRESS_UP",
|
|
356
|
+
direction: -1,
|
|
357
|
+
pointerType: event.pointerType,
|
|
358
|
+
cancelled: true,
|
|
359
|
+
src: "decrement-trigger"
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
onPointerCancel(event) {
|
|
363
|
+
send({
|
|
364
|
+
type: "TRIGGER.PRESS_UP",
|
|
365
|
+
direction: -1,
|
|
366
|
+
pointerType: event.pointerType,
|
|
367
|
+
cancelled: true,
|
|
368
|
+
src: "decrement-trigger"
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
},
|
|
373
|
+
getIncrementTriggerState,
|
|
374
|
+
getIncrementTriggerProps() {
|
|
375
|
+
const incrementTriggerState = getIncrementTriggerState();
|
|
376
|
+
return normalize.button({
|
|
377
|
+
...parts.incrementTrigger.attrs(scope.id),
|
|
378
|
+
dir: prop("dir"),
|
|
379
|
+
disabled: incrementTriggerState.disabled,
|
|
380
|
+
"data-disabled": dataAttr(incrementTriggerState.disabled),
|
|
381
|
+
"aria-label": translations.incrementLabel,
|
|
382
|
+
type: "button",
|
|
383
|
+
tabIndex: -1,
|
|
384
|
+
"aria-controls": getInputId(scope),
|
|
385
|
+
"data-scrubbing": dataAttr(scrubbing),
|
|
386
|
+
onClick(event) {
|
|
387
|
+
if (incrementTriggerState.disabled || event.detail !== 0) return;
|
|
388
|
+
send({
|
|
389
|
+
type: "VALUE.INCREMENT",
|
|
390
|
+
src: "increment-trigger"
|
|
391
|
+
});
|
|
392
|
+
},
|
|
393
|
+
onPointerDown(event) {
|
|
394
|
+
if (incrementTriggerState.disabled || !isLeftClick(event)) return;
|
|
395
|
+
send({
|
|
396
|
+
type: "TRIGGER.PRESS_DOWN",
|
|
397
|
+
direction: 1,
|
|
398
|
+
pointerType: event.pointerType,
|
|
399
|
+
src: "increment-trigger"
|
|
400
|
+
});
|
|
401
|
+
if (event.pointerType === "mouse") event.preventDefault();
|
|
402
|
+
if (event.pointerType === "touch") event.currentTarget?.focus({ preventScroll: true });
|
|
403
|
+
},
|
|
404
|
+
onPointerUp(event) {
|
|
405
|
+
send({
|
|
406
|
+
type: "TRIGGER.PRESS_UP",
|
|
407
|
+
direction: 1,
|
|
408
|
+
pointerType: event.pointerType,
|
|
409
|
+
src: "increment-trigger"
|
|
410
|
+
});
|
|
411
|
+
},
|
|
412
|
+
onPointerLeave(event) {
|
|
413
|
+
send({
|
|
414
|
+
type: "TRIGGER.PRESS_UP",
|
|
415
|
+
direction: 1,
|
|
416
|
+
pointerType: event.pointerType,
|
|
417
|
+
cancelled: true,
|
|
418
|
+
src: "increment-trigger"
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
onPointerCancel(event) {
|
|
422
|
+
send({
|
|
423
|
+
type: "TRIGGER.PRESS_UP",
|
|
424
|
+
direction: 1,
|
|
425
|
+
pointerType: event.pointerType,
|
|
426
|
+
cancelled: true,
|
|
427
|
+
src: "increment-trigger"
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
getScrubberProps() {
|
|
433
|
+
const direction = prop("scrubberDirection");
|
|
434
|
+
const point = context.get("scrubberCursorPoint");
|
|
435
|
+
return normalize.element({
|
|
436
|
+
...parts.scrubber.attrs(scope.id),
|
|
437
|
+
dir: prop("dir"),
|
|
438
|
+
"data-disabled": dataAttr(disabled),
|
|
439
|
+
role: "presentation",
|
|
440
|
+
"data-scrubbing": dataAttr(scrubbing),
|
|
441
|
+
onMouseDown(event) {
|
|
442
|
+
if (disabled || readOnly) return;
|
|
443
|
+
if (!isLeftClick(event)) return;
|
|
444
|
+
const pt = getEventPoint(event);
|
|
445
|
+
const dpr = getWindow(event.currentTarget).devicePixelRatio;
|
|
446
|
+
pt.x = pt.x - roundToDpr(7.5, dpr);
|
|
447
|
+
pt.y = pt.y - roundToDpr(7.5, dpr);
|
|
448
|
+
send({
|
|
449
|
+
type: "SCRUBBER.PRESS_DOWN",
|
|
450
|
+
point: pt
|
|
451
|
+
});
|
|
452
|
+
event.preventDefault();
|
|
453
|
+
raf(() => {
|
|
454
|
+
setCaretToEnd(getInputEl(scope));
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
style: {
|
|
458
|
+
cursor: disabled ? void 0 : direction === "vertical" ? "ns-resize" : "ew-resize",
|
|
459
|
+
"--scrubber-x": point ? toPx(point.x) : void 0,
|
|
460
|
+
"--scrubber-y": point ? toPx(point.y) : void 0,
|
|
461
|
+
"--scrubber-scale": `${1 / context.get("visualScale")}`
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
},
|
|
465
|
+
getScrubberCursorProps() {
|
|
466
|
+
return normalize.element({
|
|
467
|
+
...parts.scrubberCursor.attrs(scope.id),
|
|
468
|
+
hidden: !scrubbing || !context.get("platform").supportsPointerLock,
|
|
469
|
+
style: {
|
|
470
|
+
position: "fixed",
|
|
471
|
+
pointerEvents: "none",
|
|
472
|
+
left: "0px",
|
|
473
|
+
top: "0px",
|
|
474
|
+
zIndex: MAX_Z_INDEX,
|
|
475
|
+
transform: "translate3d(var(--scrubber-x, 0px), var(--scrubber-y, 0px), 0px) scale(var(--scrubber-scale, 1))",
|
|
476
|
+
willChange: "transform"
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
};
|
|
354
481
|
}
|
|
355
|
-
export {
|
|
356
|
-
connect
|
|
357
|
-
};
|
|
482
|
+
export { connect };
|