@zag-js/number-input 1.41.0 → 2.0.0-next.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/number-input.anatomy.d.mts +2 -2
- package/dist/number-input.anatomy.d.ts +2 -2
- package/dist/number-input.anatomy.js +2 -1
- package/dist/number-input.anatomy.mjs +2 -1
- package/dist/number-input.connect.js +40 -19
- package/dist/number-input.connect.mjs +42 -20
- package/dist/number-input.dom.d.mts +10 -8
- package/dist/number-input.dom.d.ts +10 -8
- package/dist/number-input.dom.js +60 -64
- package/dist/number-input.dom.mjs +57 -59
- package/dist/number-input.machine.js +72 -28
- package/dist/number-input.machine.mjs +75 -29
- package/dist/number-input.props.js +6 -0
- package/dist/number-input.props.mjs +6 -0
- package/dist/number-input.types.d.mts +50 -1
- package/dist/number-input.types.d.ts +50 -1
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
2
|
|
|
3
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber">;
|
|
4
|
-
declare const parts: Record<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber", _zag_js_anatomy.AnatomyPart>;
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber" | "scrubberCursor">;
|
|
4
|
+
declare const parts: Record<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber" | "scrubberCursor", _zag_js_anatomy.AnatomyPart>;
|
|
5
5
|
|
|
6
6
|
export { anatomy, parts };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
2
|
|
|
3
|
-
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber">;
|
|
4
|
-
declare const parts: Record<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber", _zag_js_anatomy.AnatomyPart>;
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber" | "scrubberCursor">;
|
|
4
|
+
declare const parts: Record<"root" | "label" | "input" | "control" | "valueText" | "incrementTrigger" | "decrementTrigger" | "scrubber" | "scrubberCursor", _zag_js_anatomy.AnatomyPart>;
|
|
5
5
|
|
|
6
6
|
export { anatomy, parts };
|
|
@@ -33,7 +33,8 @@ var anatomy = (0, import_anatomy.createAnatomy)("numberInput").parts(
|
|
|
33
33
|
"valueText",
|
|
34
34
|
"incrementTrigger",
|
|
35
35
|
"decrementTrigger",
|
|
36
|
-
"scrubber"
|
|
36
|
+
"scrubber",
|
|
37
|
+
"scrubberCursor"
|
|
37
38
|
);
|
|
38
39
|
var parts = anatomy.build();
|
|
39
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -39,7 +39,7 @@ var import_cursor = require("./cursor.js");
|
|
|
39
39
|
var import_number_input = require("./number-input.anatomy.js");
|
|
40
40
|
var dom = __toESM(require("./number-input.dom.js"));
|
|
41
41
|
function connect(service, normalize) {
|
|
42
|
-
const { state, send, prop, scope, computed } = service;
|
|
42
|
+
const { state, send, prop, scope, computed, context } = service;
|
|
43
43
|
const focused = state.hasTag("focus");
|
|
44
44
|
const disabled = computed("isDisabled");
|
|
45
45
|
const readOnly = !!prop("readOnly");
|
|
@@ -52,6 +52,7 @@ function connect(service, normalize) {
|
|
|
52
52
|
const translations = prop("translations");
|
|
53
53
|
return {
|
|
54
54
|
focused,
|
|
55
|
+
scrubbing,
|
|
55
56
|
invalid,
|
|
56
57
|
empty,
|
|
57
58
|
value: computed("formattedValue"),
|
|
@@ -79,8 +80,7 @@ function connect(service, normalize) {
|
|
|
79
80
|
},
|
|
80
81
|
getRootProps() {
|
|
81
82
|
return normalize.element({
|
|
82
|
-
|
|
83
|
-
...import_number_input.parts.root.attrs,
|
|
83
|
+
...import_number_input.parts.root.attrs(scope.id),
|
|
84
84
|
dir: prop("dir"),
|
|
85
85
|
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
86
86
|
"data-focus": (0, import_dom_query.dataAttr)(focused),
|
|
@@ -90,7 +90,7 @@ function connect(service, normalize) {
|
|
|
90
90
|
},
|
|
91
91
|
getLabelProps() {
|
|
92
92
|
return normalize.label({
|
|
93
|
-
...import_number_input.parts.label.attrs,
|
|
93
|
+
...import_number_input.parts.label.attrs(scope.id),
|
|
94
94
|
dir: prop("dir"),
|
|
95
95
|
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
96
96
|
"data-focus": (0, import_dom_query.dataAttr)(focused),
|
|
@@ -108,7 +108,7 @@ function connect(service, normalize) {
|
|
|
108
108
|
},
|
|
109
109
|
getControlProps() {
|
|
110
110
|
return normalize.element({
|
|
111
|
-
...import_number_input.parts.control.attrs,
|
|
111
|
+
...import_number_input.parts.control.attrs(scope.id),
|
|
112
112
|
dir: prop("dir"),
|
|
113
113
|
role: "group",
|
|
114
114
|
"aria-disabled": disabled,
|
|
@@ -121,7 +121,7 @@ function connect(service, normalize) {
|
|
|
121
121
|
},
|
|
122
122
|
getValueTextProps() {
|
|
123
123
|
return normalize.element({
|
|
124
|
-
...import_number_input.parts.valueText.attrs,
|
|
124
|
+
...import_number_input.parts.valueText.attrs(scope.id),
|
|
125
125
|
dir: prop("dir"),
|
|
126
126
|
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
127
127
|
"data-invalid": (0, import_dom_query.dataAttr)(invalid),
|
|
@@ -131,7 +131,7 @@ function connect(service, normalize) {
|
|
|
131
131
|
},
|
|
132
132
|
getInputProps() {
|
|
133
133
|
return normalize.input({
|
|
134
|
-
...import_number_input.parts.input.attrs,
|
|
134
|
+
...import_number_input.parts.input.attrs(scope.id),
|
|
135
135
|
dir: prop("dir"),
|
|
136
136
|
name: prop("name"),
|
|
137
137
|
form: prop("form"),
|
|
@@ -181,7 +181,11 @@ function connect(service, normalize) {
|
|
|
181
181
|
if (event.defaultPrevented) return;
|
|
182
182
|
if (readOnly) return;
|
|
183
183
|
if ((0, import_dom_query.isComposingEvent)(event)) return;
|
|
184
|
-
const step = (0, import_dom_query.getEventStep)(event
|
|
184
|
+
const step = (0, import_dom_query.getEventStep)(event, {
|
|
185
|
+
step: prop("step"),
|
|
186
|
+
largeStep: prop("largeStep"),
|
|
187
|
+
smallStep: prop("smallStep")
|
|
188
|
+
});
|
|
185
189
|
const keyMap = {
|
|
186
190
|
ArrowUp() {
|
|
187
191
|
send({ type: "INPUT.ARROW_UP", step });
|
|
@@ -213,9 +217,8 @@ function connect(service, normalize) {
|
|
|
213
217
|
},
|
|
214
218
|
getDecrementTriggerProps() {
|
|
215
219
|
return normalize.button({
|
|
216
|
-
...import_number_input.parts.decrementTrigger.attrs,
|
|
220
|
+
...import_number_input.parts.decrementTrigger.attrs(scope.id),
|
|
217
221
|
dir: prop("dir"),
|
|
218
|
-
id: dom.getDecrementTriggerId(scope),
|
|
219
222
|
disabled: isDecrementDisabled,
|
|
220
223
|
"data-disabled": (0, import_dom_query.dataAttr)(isDecrementDisabled),
|
|
221
224
|
"aria-label": translations.decrementLabel,
|
|
@@ -245,9 +248,8 @@ function connect(service, normalize) {
|
|
|
245
248
|
},
|
|
246
249
|
getIncrementTriggerProps() {
|
|
247
250
|
return normalize.button({
|
|
248
|
-
...import_number_input.parts.incrementTrigger.attrs,
|
|
251
|
+
...import_number_input.parts.incrementTrigger.attrs(scope.id),
|
|
249
252
|
dir: prop("dir"),
|
|
250
|
-
id: dom.getIncrementTriggerId(scope),
|
|
251
253
|
disabled: isIncrementDisabled,
|
|
252
254
|
"data-disabled": (0, import_dom_query.dataAttr)(isIncrementDisabled),
|
|
253
255
|
"aria-label": translations.incrementLabel,
|
|
@@ -274,29 +276,48 @@ function connect(service, normalize) {
|
|
|
274
276
|
});
|
|
275
277
|
},
|
|
276
278
|
getScrubberProps() {
|
|
279
|
+
const direction = prop("scrubberDirection");
|
|
280
|
+
const point = context.get("scrubberCursorPoint");
|
|
277
281
|
return normalize.element({
|
|
278
|
-
...import_number_input.parts.scrubber.attrs,
|
|
282
|
+
...import_number_input.parts.scrubber.attrs(scope.id),
|
|
279
283
|
dir: prop("dir"),
|
|
280
284
|
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
281
|
-
id: dom.getScrubberId(scope),
|
|
282
285
|
role: "presentation",
|
|
283
286
|
"data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
|
|
284
287
|
onMouseDown(event) {
|
|
285
288
|
if (disabled) return;
|
|
286
289
|
if (!(0, import_dom_query.isLeftClick)(event)) return;
|
|
287
|
-
const
|
|
290
|
+
const pt = (0, import_dom_query.getEventPoint)(event);
|
|
288
291
|
const win = (0, import_dom_query.getWindow)(event.currentTarget);
|
|
289
292
|
const dpr = win.devicePixelRatio;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
send({ type: "SCRUBBER.PRESS_DOWN", point });
|
|
293
|
+
pt.x = pt.x - (0, import_utils.roundToDpr)(7.5, dpr);
|
|
294
|
+
pt.y = pt.y - (0, import_utils.roundToDpr)(7.5, dpr);
|
|
295
|
+
send({ type: "SCRUBBER.PRESS_DOWN", point: pt });
|
|
293
296
|
event.preventDefault();
|
|
294
297
|
(0, import_dom_query.raf)(() => {
|
|
295
298
|
(0, import_dom_query.setCaretToEnd)(dom.getInputEl(scope));
|
|
296
299
|
});
|
|
297
300
|
},
|
|
298
301
|
style: {
|
|
299
|
-
cursor: disabled ? void 0 : "ew-resize"
|
|
302
|
+
cursor: disabled ? void 0 : direction === "vertical" ? "ns-resize" : "ew-resize",
|
|
303
|
+
"--scrubber-x": point ? (0, import_utils.toPx)(point.x) : void 0,
|
|
304
|
+
"--scrubber-y": point ? (0, import_utils.toPx)(point.y) : void 0,
|
|
305
|
+
"--scrubber-scale": `${1 / context.get("visualScale")}`
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
getScrubberCursorProps() {
|
|
310
|
+
return normalize.element({
|
|
311
|
+
...import_number_input.parts.scrubberCursor.attrs(scope.id),
|
|
312
|
+
hidden: !scrubbing || !context.get("isPointerLockSupported"),
|
|
313
|
+
style: {
|
|
314
|
+
position: "fixed",
|
|
315
|
+
pointerEvents: "none",
|
|
316
|
+
left: "0px",
|
|
317
|
+
top: "0px",
|
|
318
|
+
zIndex: import_dom_query.MAX_Z_INDEX,
|
|
319
|
+
transform: "translate3d(var(--scrubber-x, 0px), var(--scrubber-y, 0px), 0px) scale(var(--scrubber-scale, 1))",
|
|
320
|
+
willChange: "transform"
|
|
300
321
|
}
|
|
301
322
|
});
|
|
302
323
|
}
|
|
@@ -5,18 +5,19 @@ import {
|
|
|
5
5
|
getEventPoint,
|
|
6
6
|
getEventStep,
|
|
7
7
|
getWindow,
|
|
8
|
+
MAX_Z_INDEX,
|
|
8
9
|
isComposingEvent,
|
|
9
10
|
isLeftClick,
|
|
10
11
|
isModifierKey,
|
|
11
12
|
raf,
|
|
12
13
|
setCaretToEnd
|
|
13
14
|
} from "@zag-js/dom-query";
|
|
14
|
-
import { roundToDpr } from "@zag-js/utils";
|
|
15
|
+
import { roundToDpr, toPx } from "@zag-js/utils";
|
|
15
16
|
import { recordCursor } from "./cursor.mjs";
|
|
16
17
|
import { parts } from "./number-input.anatomy.mjs";
|
|
17
18
|
import * as dom from "./number-input.dom.mjs";
|
|
18
19
|
function connect(service, normalize) {
|
|
19
|
-
const { state, send, prop, scope, computed } = service;
|
|
20
|
+
const { state, send, prop, scope, computed, context } = service;
|
|
20
21
|
const focused = state.hasTag("focus");
|
|
21
22
|
const disabled = computed("isDisabled");
|
|
22
23
|
const readOnly = !!prop("readOnly");
|
|
@@ -29,6 +30,7 @@ function connect(service, normalize) {
|
|
|
29
30
|
const translations = prop("translations");
|
|
30
31
|
return {
|
|
31
32
|
focused,
|
|
33
|
+
scrubbing,
|
|
32
34
|
invalid,
|
|
33
35
|
empty,
|
|
34
36
|
value: computed("formattedValue"),
|
|
@@ -56,8 +58,7 @@ function connect(service, normalize) {
|
|
|
56
58
|
},
|
|
57
59
|
getRootProps() {
|
|
58
60
|
return normalize.element({
|
|
59
|
-
|
|
60
|
-
...parts.root.attrs,
|
|
61
|
+
...parts.root.attrs(scope.id),
|
|
61
62
|
dir: prop("dir"),
|
|
62
63
|
"data-disabled": dataAttr(disabled),
|
|
63
64
|
"data-focus": dataAttr(focused),
|
|
@@ -67,7 +68,7 @@ function connect(service, normalize) {
|
|
|
67
68
|
},
|
|
68
69
|
getLabelProps() {
|
|
69
70
|
return normalize.label({
|
|
70
|
-
...parts.label.attrs,
|
|
71
|
+
...parts.label.attrs(scope.id),
|
|
71
72
|
dir: prop("dir"),
|
|
72
73
|
"data-disabled": dataAttr(disabled),
|
|
73
74
|
"data-focus": dataAttr(focused),
|
|
@@ -85,7 +86,7 @@ function connect(service, normalize) {
|
|
|
85
86
|
},
|
|
86
87
|
getControlProps() {
|
|
87
88
|
return normalize.element({
|
|
88
|
-
...parts.control.attrs,
|
|
89
|
+
...parts.control.attrs(scope.id),
|
|
89
90
|
dir: prop("dir"),
|
|
90
91
|
role: "group",
|
|
91
92
|
"aria-disabled": disabled,
|
|
@@ -98,7 +99,7 @@ function connect(service, normalize) {
|
|
|
98
99
|
},
|
|
99
100
|
getValueTextProps() {
|
|
100
101
|
return normalize.element({
|
|
101
|
-
...parts.valueText.attrs,
|
|
102
|
+
...parts.valueText.attrs(scope.id),
|
|
102
103
|
dir: prop("dir"),
|
|
103
104
|
"data-disabled": dataAttr(disabled),
|
|
104
105
|
"data-invalid": dataAttr(invalid),
|
|
@@ -108,7 +109,7 @@ function connect(service, normalize) {
|
|
|
108
109
|
},
|
|
109
110
|
getInputProps() {
|
|
110
111
|
return normalize.input({
|
|
111
|
-
...parts.input.attrs,
|
|
112
|
+
...parts.input.attrs(scope.id),
|
|
112
113
|
dir: prop("dir"),
|
|
113
114
|
name: prop("name"),
|
|
114
115
|
form: prop("form"),
|
|
@@ -158,7 +159,11 @@ function connect(service, normalize) {
|
|
|
158
159
|
if (event.defaultPrevented) return;
|
|
159
160
|
if (readOnly) return;
|
|
160
161
|
if (isComposingEvent(event)) return;
|
|
161
|
-
const step = getEventStep(event
|
|
162
|
+
const step = getEventStep(event, {
|
|
163
|
+
step: prop("step"),
|
|
164
|
+
largeStep: prop("largeStep"),
|
|
165
|
+
smallStep: prop("smallStep")
|
|
166
|
+
});
|
|
162
167
|
const keyMap = {
|
|
163
168
|
ArrowUp() {
|
|
164
169
|
send({ type: "INPUT.ARROW_UP", step });
|
|
@@ -190,9 +195,8 @@ function connect(service, normalize) {
|
|
|
190
195
|
},
|
|
191
196
|
getDecrementTriggerProps() {
|
|
192
197
|
return normalize.button({
|
|
193
|
-
...parts.decrementTrigger.attrs,
|
|
198
|
+
...parts.decrementTrigger.attrs(scope.id),
|
|
194
199
|
dir: prop("dir"),
|
|
195
|
-
id: dom.getDecrementTriggerId(scope),
|
|
196
200
|
disabled: isDecrementDisabled,
|
|
197
201
|
"data-disabled": dataAttr(isDecrementDisabled),
|
|
198
202
|
"aria-label": translations.decrementLabel,
|
|
@@ -222,9 +226,8 @@ function connect(service, normalize) {
|
|
|
222
226
|
},
|
|
223
227
|
getIncrementTriggerProps() {
|
|
224
228
|
return normalize.button({
|
|
225
|
-
...parts.incrementTrigger.attrs,
|
|
229
|
+
...parts.incrementTrigger.attrs(scope.id),
|
|
226
230
|
dir: prop("dir"),
|
|
227
|
-
id: dom.getIncrementTriggerId(scope),
|
|
228
231
|
disabled: isIncrementDisabled,
|
|
229
232
|
"data-disabled": dataAttr(isIncrementDisabled),
|
|
230
233
|
"aria-label": translations.incrementLabel,
|
|
@@ -251,29 +254,48 @@ function connect(service, normalize) {
|
|
|
251
254
|
});
|
|
252
255
|
},
|
|
253
256
|
getScrubberProps() {
|
|
257
|
+
const direction = prop("scrubberDirection");
|
|
258
|
+
const point = context.get("scrubberCursorPoint");
|
|
254
259
|
return normalize.element({
|
|
255
|
-
...parts.scrubber.attrs,
|
|
260
|
+
...parts.scrubber.attrs(scope.id),
|
|
256
261
|
dir: prop("dir"),
|
|
257
262
|
"data-disabled": dataAttr(disabled),
|
|
258
|
-
id: dom.getScrubberId(scope),
|
|
259
263
|
role: "presentation",
|
|
260
264
|
"data-scrubbing": dataAttr(scrubbing),
|
|
261
265
|
onMouseDown(event) {
|
|
262
266
|
if (disabled) return;
|
|
263
267
|
if (!isLeftClick(event)) return;
|
|
264
|
-
const
|
|
268
|
+
const pt = getEventPoint(event);
|
|
265
269
|
const win = getWindow(event.currentTarget);
|
|
266
270
|
const dpr = win.devicePixelRatio;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
send({ type: "SCRUBBER.PRESS_DOWN", point });
|
|
271
|
+
pt.x = pt.x - roundToDpr(7.5, dpr);
|
|
272
|
+
pt.y = pt.y - roundToDpr(7.5, dpr);
|
|
273
|
+
send({ type: "SCRUBBER.PRESS_DOWN", point: pt });
|
|
270
274
|
event.preventDefault();
|
|
271
275
|
raf(() => {
|
|
272
276
|
setCaretToEnd(dom.getInputEl(scope));
|
|
273
277
|
});
|
|
274
278
|
},
|
|
275
279
|
style: {
|
|
276
|
-
cursor: disabled ? void 0 : "ew-resize"
|
|
280
|
+
cursor: disabled ? void 0 : direction === "vertical" ? "ns-resize" : "ew-resize",
|
|
281
|
+
"--scrubber-x": point ? toPx(point.x) : void 0,
|
|
282
|
+
"--scrubber-y": point ? toPx(point.y) : void 0,
|
|
283
|
+
"--scrubber-scale": `${1 / context.get("visualScale")}`
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
getScrubberCursorProps() {
|
|
288
|
+
return normalize.element({
|
|
289
|
+
...parts.scrubberCursor.attrs(scope.id),
|
|
290
|
+
hidden: !scrubbing || !context.get("isPointerLockSupported"),
|
|
291
|
+
style: {
|
|
292
|
+
position: "fixed",
|
|
293
|
+
pointerEvents: "none",
|
|
294
|
+
left: "0px",
|
|
295
|
+
top: "0px",
|
|
296
|
+
zIndex: MAX_Z_INDEX,
|
|
297
|
+
transform: "translate3d(var(--scrubber-x, 0px), var(--scrubber-y, 0px), 0px) scale(var(--scrubber-scale, 1))",
|
|
298
|
+
willChange: "transform"
|
|
277
299
|
}
|
|
278
300
|
});
|
|
279
301
|
}
|
|
@@ -8,27 +8,29 @@ declare const getInputId: (ctx: Scope) => any;
|
|
|
8
8
|
declare const getIncrementTriggerId: (ctx: Scope) => any;
|
|
9
9
|
declare const getDecrementTriggerId: (ctx: Scope) => any;
|
|
10
10
|
declare const getScrubberId: (ctx: Scope) => any;
|
|
11
|
-
declare const
|
|
11
|
+
declare const getScrubberCursorId: (ctx: Scope) => any;
|
|
12
12
|
declare const getLabelId: (ctx: Scope) => any;
|
|
13
13
|
declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
|
|
14
14
|
declare const getIncrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
|
|
15
15
|
declare const getDecrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
|
|
16
16
|
declare const getScrubberEl: (ctx: Scope) => HTMLElement | null;
|
|
17
|
-
declare const
|
|
17
|
+
declare const getScrubberCursorEl: (ctx: Scope) => HTMLElement | null;
|
|
18
18
|
declare const getPressedTriggerEl: (ctx: Scope, hint: HintValue | null) => HTMLButtonElement | null;
|
|
19
|
-
declare const
|
|
20
|
-
|
|
21
|
-
declare const getMousemoveValue: (ctx: Scope, opts: {
|
|
19
|
+
declare const preventTextSelection: (ctx: Scope, direction: "horizontal" | "vertical") => () => void;
|
|
20
|
+
interface MousemoveOpts {
|
|
22
21
|
point: Point | null;
|
|
23
22
|
isRtl: boolean;
|
|
24
23
|
event: MouseEvent;
|
|
25
|
-
|
|
24
|
+
direction: "horizontal" | "vertical";
|
|
25
|
+
teleportDistance?: number | undefined;
|
|
26
|
+
}
|
|
27
|
+
declare const getMousemoveValue: (ctx: Scope, opts: MousemoveOpts) => {
|
|
26
28
|
hint: string | null;
|
|
27
29
|
point: {
|
|
28
30
|
x: number;
|
|
29
31
|
y: number;
|
|
30
32
|
};
|
|
33
|
+
delta: number;
|
|
31
34
|
};
|
|
32
|
-
declare const createVirtualCursor: (ctx: Scope, point: Point | null) => void;
|
|
33
35
|
|
|
34
|
-
export {
|
|
36
|
+
export { getDecrementTriggerEl, getDecrementTriggerId, getIncrementTriggerEl, getIncrementTriggerId, getInputEl, getInputId, getLabelId, getMousemoveValue, getPressedTriggerEl, getRootId, getScrubberCursorEl, getScrubberCursorId, getScrubberEl, getScrubberId, preventTextSelection };
|
|
@@ -8,27 +8,29 @@ declare const getInputId: (ctx: Scope) => any;
|
|
|
8
8
|
declare const getIncrementTriggerId: (ctx: Scope) => any;
|
|
9
9
|
declare const getDecrementTriggerId: (ctx: Scope) => any;
|
|
10
10
|
declare const getScrubberId: (ctx: Scope) => any;
|
|
11
|
-
declare const
|
|
11
|
+
declare const getScrubberCursorId: (ctx: Scope) => any;
|
|
12
12
|
declare const getLabelId: (ctx: Scope) => any;
|
|
13
13
|
declare const getInputEl: (ctx: Scope) => HTMLInputElement | null;
|
|
14
14
|
declare const getIncrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
|
|
15
15
|
declare const getDecrementTriggerEl: (ctx: Scope) => HTMLButtonElement | null;
|
|
16
16
|
declare const getScrubberEl: (ctx: Scope) => HTMLElement | null;
|
|
17
|
-
declare const
|
|
17
|
+
declare const getScrubberCursorEl: (ctx: Scope) => HTMLElement | null;
|
|
18
18
|
declare const getPressedTriggerEl: (ctx: Scope, hint: HintValue | null) => HTMLButtonElement | null;
|
|
19
|
-
declare const
|
|
20
|
-
|
|
21
|
-
declare const getMousemoveValue: (ctx: Scope, opts: {
|
|
19
|
+
declare const preventTextSelection: (ctx: Scope, direction: "horizontal" | "vertical") => () => void;
|
|
20
|
+
interface MousemoveOpts {
|
|
22
21
|
point: Point | null;
|
|
23
22
|
isRtl: boolean;
|
|
24
23
|
event: MouseEvent;
|
|
25
|
-
|
|
24
|
+
direction: "horizontal" | "vertical";
|
|
25
|
+
teleportDistance?: number | undefined;
|
|
26
|
+
}
|
|
27
|
+
declare const getMousemoveValue: (ctx: Scope, opts: MousemoveOpts) => {
|
|
26
28
|
hint: string | null;
|
|
27
29
|
point: {
|
|
28
30
|
x: number;
|
|
29
31
|
y: number;
|
|
30
32
|
};
|
|
33
|
+
delta: number;
|
|
31
34
|
};
|
|
32
|
-
declare const createVirtualCursor: (ctx: Scope, point: Point | null) => void;
|
|
33
35
|
|
|
34
|
-
export {
|
|
36
|
+
export { getDecrementTriggerEl, getDecrementTriggerId, getIncrementTriggerEl, getIncrementTriggerId, getInputEl, getInputId, getLabelId, getMousemoveValue, getPressedTriggerEl, getRootId, getScrubberCursorEl, getScrubberCursorId, getScrubberEl, getScrubberId, preventTextSelection };
|
package/dist/number-input.dom.js
CHANGED
|
@@ -20,9 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/number-input.dom.ts
|
|
21
21
|
var number_input_dom_exports = {};
|
|
22
22
|
__export(number_input_dom_exports, {
|
|
23
|
-
createVirtualCursor: () => createVirtualCursor,
|
|
24
|
-
getCursorEl: () => getCursorEl,
|
|
25
|
-
getCursorId: () => getCursorId,
|
|
26
23
|
getDecrementTriggerEl: () => getDecrementTriggerEl,
|
|
27
24
|
getDecrementTriggerId: () => getDecrementTriggerId,
|
|
28
25
|
getIncrementTriggerEl: () => getIncrementTriggerEl,
|
|
@@ -33,26 +30,27 @@ __export(number_input_dom_exports, {
|
|
|
33
30
|
getMousemoveValue: () => getMousemoveValue,
|
|
34
31
|
getPressedTriggerEl: () => getPressedTriggerEl,
|
|
35
32
|
getRootId: () => getRootId,
|
|
33
|
+
getScrubberCursorEl: () => getScrubberCursorEl,
|
|
34
|
+
getScrubberCursorId: () => getScrubberCursorId,
|
|
36
35
|
getScrubberEl: () => getScrubberEl,
|
|
37
36
|
getScrubberId: () => getScrubberId,
|
|
38
|
-
preventTextSelection: () => preventTextSelection
|
|
39
|
-
setupVirtualCursor: () => setupVirtualCursor
|
|
37
|
+
preventTextSelection: () => preventTextSelection
|
|
40
38
|
});
|
|
41
39
|
module.exports = __toCommonJS(number_input_dom_exports);
|
|
42
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
43
40
|
var import_utils = require("@zag-js/utils");
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
41
|
+
var import_number_input = require("./number-input.anatomy.js");
|
|
42
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `${ctx.id}`;
|
|
43
|
+
var getInputId = (ctx) => ctx.ids?.input ?? `${ctx.id}:input`;
|
|
44
|
+
var getIncrementTriggerId = (ctx) => ctx.ids?.incrementTrigger ?? `${ctx.id}:inc`;
|
|
45
|
+
var getDecrementTriggerId = (ctx) => ctx.ids?.decrementTrigger ?? `${ctx.id}:dec`;
|
|
46
|
+
var getScrubberId = (ctx) => ctx.ids?.scrubber ?? `${ctx.id}:scrubber`;
|
|
47
|
+
var getScrubberCursorId = (ctx) => ctx.ids?.scrubberCursor ?? `${ctx.id}:scrubber-cursor`;
|
|
48
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `${ctx.id}:label`;
|
|
49
|
+
var getInputEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.input));
|
|
50
|
+
var getIncrementTriggerEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.incrementTrigger));
|
|
51
|
+
var getDecrementTriggerEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.decrementTrigger));
|
|
52
|
+
var getScrubberEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.scrubber));
|
|
53
|
+
var getScrubberCursorEl = (ctx) => ctx.query(ctx.selector(import_number_input.parts.scrubberCursor));
|
|
56
54
|
var getPressedTriggerEl = (ctx, hint) => {
|
|
57
55
|
let btnEl = null;
|
|
58
56
|
if (hint === "increment") {
|
|
@@ -63,20 +61,13 @@ var getPressedTriggerEl = (ctx, hint) => {
|
|
|
63
61
|
}
|
|
64
62
|
return btnEl;
|
|
65
63
|
};
|
|
66
|
-
var
|
|
67
|
-
if ((0, import_dom_query.isSafari)()) return;
|
|
68
|
-
createVirtualCursor(ctx, point);
|
|
69
|
-
return () => {
|
|
70
|
-
getCursorEl(ctx)?.remove();
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
var preventTextSelection = (ctx) => {
|
|
64
|
+
var preventTextSelection = (ctx, direction) => {
|
|
74
65
|
const doc = ctx.getDoc();
|
|
75
66
|
const html = doc.documentElement;
|
|
76
67
|
const body = doc.body;
|
|
77
68
|
body.style.pointerEvents = "none";
|
|
78
69
|
html.style.userSelect = "none";
|
|
79
|
-
html.style.cursor = "ew-resize";
|
|
70
|
+
html.style.cursor = direction === "vertical" ? "ns-resize" : "ew-resize";
|
|
80
71
|
return () => {
|
|
81
72
|
body.style.pointerEvents = "";
|
|
82
73
|
html.style.userSelect = "";
|
|
@@ -90,49 +81,53 @@ var preventTextSelection = (ctx) => {
|
|
|
90
81
|
};
|
|
91
82
|
};
|
|
92
83
|
var getMousemoveValue = (ctx, opts) => {
|
|
93
|
-
const { point, isRtl, event } = opts;
|
|
84
|
+
const { point, isRtl, event, direction, teleportDistance } = opts;
|
|
94
85
|
const win = ctx.getWin();
|
|
95
86
|
const x = (0, import_utils.roundToDpr)(event.movementX, win.devicePixelRatio);
|
|
96
87
|
const y = (0, import_utils.roundToDpr)(event.movementY, win.devicePixelRatio);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
const isVertical = direction === "vertical";
|
|
89
|
+
const delta = isVertical ? y : x;
|
|
90
|
+
let hint;
|
|
91
|
+
if (isVertical) {
|
|
92
|
+
hint = delta < 0 ? "increment" : delta > 0 ? "decrement" : null;
|
|
93
|
+
} else {
|
|
94
|
+
hint = delta > 0 ? "increment" : delta < 0 ? "decrement" : null;
|
|
95
|
+
}
|
|
96
|
+
if (!isVertical && isRtl) {
|
|
97
|
+
if (hint === "increment") hint = "decrement";
|
|
98
|
+
else if (hint === "decrement") hint = "increment";
|
|
99
|
+
}
|
|
100
100
|
const newPoint = { x: point.x + x, y: point.y + y };
|
|
101
|
-
const width = win.innerWidth;
|
|
102
101
|
const half = (0, import_utils.roundToDpr)(7.5, win.devicePixelRatio);
|
|
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
|
-
doc.body.appendChild(el);
|
|
102
|
+
if (teleportDistance != null) {
|
|
103
|
+
const scrubberEl = getScrubberEl(ctx);
|
|
104
|
+
if (scrubberEl) {
|
|
105
|
+
const rect = scrubberEl.getBoundingClientRect();
|
|
106
|
+
if (isVertical) {
|
|
107
|
+
const center = rect.top + rect.height / 2;
|
|
108
|
+
const min = center - teleportDistance / 2;
|
|
109
|
+
const max = center + teleportDistance / 2;
|
|
110
|
+
newPoint.y = (0, import_utils.wrap)(newPoint.y + half - min, max - min) + min - half;
|
|
111
|
+
} else {
|
|
112
|
+
const center = rect.left + rect.width / 2;
|
|
113
|
+
const min = center - teleportDistance / 2;
|
|
114
|
+
const max = center + teleportDistance / 2;
|
|
115
|
+
newPoint.x = (0, import_utils.wrap)(newPoint.x + half - min, max - min) + min - half;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
if (isVertical) {
|
|
120
|
+
const height = win.innerHeight;
|
|
121
|
+
newPoint.y = (0, import_utils.wrap)(newPoint.y + half, height) - half;
|
|
122
|
+
} else {
|
|
123
|
+
const width = win.innerWidth;
|
|
124
|
+
newPoint.x = (0, import_utils.wrap)(newPoint.x + half, width) - half;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { hint, point: newPoint, delta };
|
|
130
128
|
};
|
|
131
129
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
130
|
0 && (module.exports = {
|
|
133
|
-
createVirtualCursor,
|
|
134
|
-
getCursorEl,
|
|
135
|
-
getCursorId,
|
|
136
131
|
getDecrementTriggerEl,
|
|
137
132
|
getDecrementTriggerId,
|
|
138
133
|
getIncrementTriggerEl,
|
|
@@ -143,8 +138,9 @@ var createVirtualCursor = (ctx, point) => {
|
|
|
143
138
|
getMousemoveValue,
|
|
144
139
|
getPressedTriggerEl,
|
|
145
140
|
getRootId,
|
|
141
|
+
getScrubberCursorEl,
|
|
142
|
+
getScrubberCursorId,
|
|
146
143
|
getScrubberEl,
|
|
147
144
|
getScrubberId,
|
|
148
|
-
preventTextSelection
|
|
149
|
-
setupVirtualCursor
|
|
145
|
+
preventTextSelection
|
|
150
146
|
});
|