@zag-js/slider 1.47.0 → 1.48.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/index.d.mts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +16 -38
- package/dist/index.mjs +2 -7
- package/dist/slider.anatomy.d.mts +2 -6
- package/dist/slider.anatomy.d.ts +2 -6
- package/dist/slider.anatomy.js +8 -44
- package/dist/slider.anatomy.mjs +4 -18
- package/dist/slider.connect.d.mts +3 -7
- package/dist/slider.connect.d.ts +3 -7
- package/dist/slider.connect.js +371 -351
- package/dist/slider.connect.mjs +366 -330
- package/dist/slider.dom.d.mts +27 -30
- package/dist/slider.dom.d.ts +27 -30
- package/dist/slider.dom.js +93 -137
- package/dist/slider.dom.mjs +70 -93
- package/dist/slider.machine.d.mts +2 -7
- package/dist/slider.machine.d.ts +2 -7
- package/dist/slider.machine.js +322 -367
- package/dist/slider.machine.mjs +318 -351
- package/dist/slider.props.d.mts +7 -12
- package/dist/slider.props.d.ts +7 -12
- package/dist/slider.props.js +45 -73
- package/dist/slider.props.mjs +36 -43
- package/dist/slider.style.d.mts +15 -17
- package/dist/slider.style.d.ts +15 -17
- package/dist/slider.style.js +126 -156
- package/dist/slider.style.mjs +114 -123
- package/dist/slider.types.d.mts +307 -309
- package/dist/slider.types.d.ts +307 -309
- package/dist/slider.types.js +4 -18
- package/dist/slider.types.mjs +1 -0
- package/dist/slider.utils.d.mts +18 -21
- package/dist/slider.utils.d.ts +18 -21
- package/dist/slider.utils.js +144 -168
- package/dist/slider.utils.mjs +132 -135
- package/package.json +8 -8
package/dist/slider.machine.mjs
CHANGED
|
@@ -1,355 +1,322 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { dispatchChangeEvent, getHiddenInputEl, getOffsetRect, getPointValue, getRootEl, getThumbEl, getThumbEls } from "./slider.dom.mjs";
|
|
2
|
+
import { constrainValue, decrement, getClosestIndex, getRangeAtIndex, increment, normalizeValues, resolveThumbCollision, selectMovableThumb } from "./slider.utils.mjs";
|
|
3
3
|
import { raf, resizeObserverBorderBox, setElementValue, trackFormControl, trackPointerMove } from "@zag-js/dom-query";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
isEqual,
|
|
10
|
-
isValueWithinRange,
|
|
11
|
-
pick,
|
|
12
|
-
setValueAtIndex,
|
|
13
|
-
snapValueToStep
|
|
14
|
-
} from "@zag-js/utils";
|
|
15
|
-
import * as dom from "./slider.dom.mjs";
|
|
16
|
-
import {
|
|
17
|
-
constrainValue,
|
|
18
|
-
decrement,
|
|
19
|
-
getClosestIndex,
|
|
20
|
-
getRangeAtIndex,
|
|
21
|
-
increment,
|
|
22
|
-
normalizeValues,
|
|
23
|
-
resolveThumbCollision,
|
|
24
|
-
selectMovableThumb
|
|
25
|
-
} from "./slider.utils.mjs";
|
|
26
|
-
var isEqualSize = (a, b) => {
|
|
27
|
-
return a?.width === b?.width && a?.height === b?.height;
|
|
4
|
+
import { callAll, clampValue, getValuePercent, getValueRanges, isEqual, isValueWithinRange, pick, setValueAtIndex, snapValueToStep } from "@zag-js/utils";
|
|
5
|
+
import { createMachine, memo } from "@zag-js/core";
|
|
6
|
+
// src/slider.machine.ts
|
|
7
|
+
const isEqualSize = (a, b) => {
|
|
8
|
+
return a?.width === b?.width && a?.height === b?.height;
|
|
28
9
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"[zag-js/slider] The configured `min`, `max`, `step` or `minStepsBetweenThumbs` values are invalid"
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return rangeValue;
|
|
40
|
-
});
|
|
10
|
+
const normalize = (value, min, max, step, minStepsBetweenThumbs) => {
|
|
11
|
+
return getValueRanges(value, min, max, minStepsBetweenThumbs * step).map((range) => {
|
|
12
|
+
const snapValue = snapValueToStep(range.value, range.min, range.max, step);
|
|
13
|
+
const rangeValue = clampValue(snapValue, range.min, range.max);
|
|
14
|
+
if (!isValueWithinRange(rangeValue, min, max)) throw new Error("[zag-js/slider] The configured `min`, `max`, `step` or `minStepsBetweenThumbs` values are invalid");
|
|
15
|
+
return rangeValue;
|
|
16
|
+
});
|
|
41
17
|
};
|
|
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
|
-
setValue(params) {
|
|
346
|
-
const { context, event } = params;
|
|
347
|
-
const value = normalizeValues(params, event.value);
|
|
348
|
-
context.set("value", value);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
18
|
+
const machine = createMachine({
|
|
19
|
+
props({ props }) {
|
|
20
|
+
const min = props.min ?? 0;
|
|
21
|
+
const max = props.max ?? 100;
|
|
22
|
+
const step = props.step ?? 1;
|
|
23
|
+
const defaultValue = props.defaultValue ?? [min];
|
|
24
|
+
const minStepsBetweenThumbs = props.minStepsBetweenThumbs ?? 0;
|
|
25
|
+
return {
|
|
26
|
+
dir: "ltr",
|
|
27
|
+
thumbAlignment: "contain",
|
|
28
|
+
origin: "start",
|
|
29
|
+
orientation: "horizontal",
|
|
30
|
+
thumbCollisionBehavior: "none",
|
|
31
|
+
minStepsBetweenThumbs,
|
|
32
|
+
...props,
|
|
33
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
34
|
+
defaultValue: normalize(defaultValue, min, max, step, minStepsBetweenThumbs),
|
|
35
|
+
value: props.value ? normalize(props.value, min, max, step, minStepsBetweenThumbs) : void 0,
|
|
36
|
+
max,
|
|
37
|
+
step,
|
|
38
|
+
min
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
initialState() {
|
|
42
|
+
return "idle";
|
|
43
|
+
},
|
|
44
|
+
context({ prop, bindable, getContext }) {
|
|
45
|
+
return {
|
|
46
|
+
thumbSize: bindable(() => ({ defaultValue: prop("thumbSize") || null })),
|
|
47
|
+
value: bindable(() => ({
|
|
48
|
+
defaultValue: prop("defaultValue"),
|
|
49
|
+
value: prop("value"),
|
|
50
|
+
isEqual,
|
|
51
|
+
hash(a) {
|
|
52
|
+
return a.join(",");
|
|
53
|
+
},
|
|
54
|
+
onChange(value) {
|
|
55
|
+
prop("onValueChange")?.({ value });
|
|
56
|
+
}
|
|
57
|
+
})),
|
|
58
|
+
focusedIndex: bindable(() => ({
|
|
59
|
+
defaultValue: -1,
|
|
60
|
+
onChange(value) {
|
|
61
|
+
const ctx = getContext();
|
|
62
|
+
prop("onFocusChange")?.({
|
|
63
|
+
focusedIndex: value,
|
|
64
|
+
value: ctx.get("value")
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
})),
|
|
68
|
+
fieldsetDisabled: bindable(() => ({ defaultValue: false }))
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
refs() {
|
|
72
|
+
return {
|
|
73
|
+
thumbDragOffset: null,
|
|
74
|
+
thumbDragStartValue: null
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
computed: {
|
|
78
|
+
isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
|
|
79
|
+
isVertical: ({ prop }) => prop("orientation") === "vertical",
|
|
80
|
+
isRtl: ({ prop }) => prop("orientation") === "horizontal" && prop("dir") === "rtl",
|
|
81
|
+
isDisabled: ({ context, prop }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
82
|
+
isInteractive: ({ prop, computed }) => !(prop("readOnly") || computed("isDisabled")),
|
|
83
|
+
hasMeasuredThumbSize: ({ context }) => context.get("thumbSize") != null,
|
|
84
|
+
valuePercent: memo(({ context, prop }) => [
|
|
85
|
+
context.get("value"),
|
|
86
|
+
prop("min"),
|
|
87
|
+
prop("max")
|
|
88
|
+
], ([value, min, max]) => value.map((value) => 100 * getValuePercent(value, min, max)))
|
|
89
|
+
},
|
|
90
|
+
watch({ track, action, context, computed, send }) {
|
|
91
|
+
track([() => context.hash("value")], () => {
|
|
92
|
+
action(["syncInputElements", "dispatchChangeEvent"]);
|
|
93
|
+
});
|
|
94
|
+
track([() => computed("isDisabled")], () => {
|
|
95
|
+
if (computed("isDisabled")) send({ type: "POINTER_CANCEL" });
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
effects: ["trackFormControlState", "trackThumbSize"],
|
|
99
|
+
on: {
|
|
100
|
+
SET_VALUE: [{
|
|
101
|
+
guard: "hasIndex",
|
|
102
|
+
actions: ["setValueAtIndex", "invokeOnChangeEnd"]
|
|
103
|
+
}, { actions: ["setValue", "invokeOnChangeEnd"] }],
|
|
104
|
+
INCREMENT: { actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"] },
|
|
105
|
+
DECREMENT: { actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"] }
|
|
106
|
+
},
|
|
107
|
+
states: {
|
|
108
|
+
idle: { on: {
|
|
109
|
+
POINTER_DOWN: {
|
|
110
|
+
target: "dragging",
|
|
111
|
+
actions: [
|
|
112
|
+
"setClosestThumbIndex",
|
|
113
|
+
"setThumbDragStartValue",
|
|
114
|
+
"setPointerValue",
|
|
115
|
+
"focusActiveThumb"
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
FOCUS: {
|
|
119
|
+
target: "focus",
|
|
120
|
+
actions: ["setFocusedIndex"]
|
|
121
|
+
},
|
|
122
|
+
THUMB_POINTER_DOWN: {
|
|
123
|
+
target: "dragging",
|
|
124
|
+
actions: [
|
|
125
|
+
"setFocusedIndex",
|
|
126
|
+
"setThumbDragOffset",
|
|
127
|
+
"setThumbDragStartValue",
|
|
128
|
+
"focusActiveThumb"
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
} },
|
|
132
|
+
focus: {
|
|
133
|
+
entry: ["focusActiveThumb"],
|
|
134
|
+
on: {
|
|
135
|
+
POINTER_DOWN: {
|
|
136
|
+
target: "dragging",
|
|
137
|
+
actions: [
|
|
138
|
+
"setClosestThumbIndex",
|
|
139
|
+
"setThumbDragStartValue",
|
|
140
|
+
"setPointerValue",
|
|
141
|
+
"focusActiveThumb"
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
THUMB_POINTER_DOWN: {
|
|
145
|
+
target: "dragging",
|
|
146
|
+
actions: [
|
|
147
|
+
"setFocusedIndex",
|
|
148
|
+
"setThumbDragOffset",
|
|
149
|
+
"setThumbDragStartValue",
|
|
150
|
+
"focusActiveThumb"
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
ARROW_DEC: { actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"] },
|
|
154
|
+
ARROW_INC: { actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"] },
|
|
155
|
+
HOME: { actions: ["setFocusedThumbToMin", "invokeOnChangeEnd"] },
|
|
156
|
+
END: { actions: ["setFocusedThumbToMax", "invokeOnChangeEnd"] },
|
|
157
|
+
BLUR: {
|
|
158
|
+
target: "idle",
|
|
159
|
+
actions: ["clearFocusedIndex"]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
dragging: {
|
|
164
|
+
entry: ["focusActiveThumb"],
|
|
165
|
+
effects: ["trackPointerMove"],
|
|
166
|
+
on: {
|
|
167
|
+
POINTER_UP: {
|
|
168
|
+
target: "focus",
|
|
169
|
+
actions: [
|
|
170
|
+
"invokeOnChangeEnd",
|
|
171
|
+
"clearThumbDragOffset",
|
|
172
|
+
"clearThumbDragStartValue"
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
POINTER_MOVE: { actions: ["setPointerValue"] },
|
|
176
|
+
POINTER_CANCEL: {
|
|
177
|
+
target: "idle",
|
|
178
|
+
actions: [
|
|
179
|
+
"clearFocusedIndex",
|
|
180
|
+
"clearThumbDragOffset",
|
|
181
|
+
"clearThumbDragStartValue"
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
implementations: {
|
|
188
|
+
guards: { hasIndex: ({ event }) => event.index != null },
|
|
189
|
+
effects: {
|
|
190
|
+
trackFormControlState({ context, scope }) {
|
|
191
|
+
return trackFormControl(getRootEl(scope), {
|
|
192
|
+
onFieldsetDisabledChange(disabled) {
|
|
193
|
+
context.set("fieldsetDisabled", disabled);
|
|
194
|
+
},
|
|
195
|
+
onFormReset() {
|
|
196
|
+
context.set("value", context.initial("value"));
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
trackPointerMove({ scope, send }) {
|
|
201
|
+
return trackPointerMove(scope.getDoc(), {
|
|
202
|
+
onPointerMove(info) {
|
|
203
|
+
send({
|
|
204
|
+
type: "POINTER_MOVE",
|
|
205
|
+
point: info.point
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
onPointerUp() {
|
|
209
|
+
send({ type: "POINTER_UP" });
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
trackThumbSize({ context, scope, prop }) {
|
|
214
|
+
if (prop("thumbAlignment") !== "contain" || prop("thumbSize")) return;
|
|
215
|
+
const exec = (el) => {
|
|
216
|
+
const rect = getOffsetRect(el);
|
|
217
|
+
const size = pick(rect, ["width", "height"]);
|
|
218
|
+
if (isEqualSize(context.get("thumbSize"), size)) return;
|
|
219
|
+
context.set("thumbSize", size);
|
|
220
|
+
};
|
|
221
|
+
const thumbEls = getThumbEls(scope);
|
|
222
|
+
thumbEls.forEach(exec);
|
|
223
|
+
const cleanups = thumbEls.map((el) => resizeObserverBorderBox.observe(el, () => exec(el)));
|
|
224
|
+
return callAll(...cleanups);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
actions: {
|
|
228
|
+
dispatchChangeEvent({ context, scope }) {
|
|
229
|
+
dispatchChangeEvent(scope, context.get("value"));
|
|
230
|
+
},
|
|
231
|
+
syncInputElements({ context, scope }) {
|
|
232
|
+
context.get("value").forEach((value, index) => {
|
|
233
|
+
const inputEl = getHiddenInputEl(scope, index);
|
|
234
|
+
setElementValue(inputEl, value.toString());
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
invokeOnChangeEnd({ prop, context }) {
|
|
238
|
+
queueMicrotask(() => {
|
|
239
|
+
prop("onValueChangeEnd")?.({ value: context.get("value") });
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
setClosestThumbIndex(params) {
|
|
243
|
+
const { context, event } = params;
|
|
244
|
+
const pointValue = getPointValue(params, event.point);
|
|
245
|
+
if (pointValue == null) return;
|
|
246
|
+
const focusedIndex = getClosestIndex(params, pointValue);
|
|
247
|
+
context.set("focusedIndex", focusedIndex);
|
|
248
|
+
},
|
|
249
|
+
setFocusedIndex(params) {
|
|
250
|
+
const { context, event } = params;
|
|
251
|
+
const movableIndex = selectMovableThumb(params, event.index);
|
|
252
|
+
context.set("focusedIndex", movableIndex);
|
|
253
|
+
},
|
|
254
|
+
clearFocusedIndex({ context }) {
|
|
255
|
+
context.set("focusedIndex", -1);
|
|
256
|
+
},
|
|
257
|
+
setThumbDragOffset(params) {
|
|
258
|
+
const { refs, event } = params;
|
|
259
|
+
refs.set("thumbDragOffset", event.offset ?? null);
|
|
260
|
+
},
|
|
261
|
+
clearThumbDragOffset({ refs }) {
|
|
262
|
+
refs.set("thumbDragOffset", null);
|
|
263
|
+
},
|
|
264
|
+
setThumbDragStartValue({ refs, context }) {
|
|
265
|
+
refs.set("thumbDragStartValue", context.get("value").slice());
|
|
266
|
+
},
|
|
267
|
+
clearThumbDragStartValue({ refs }) {
|
|
268
|
+
refs.set("thumbDragStartValue", null);
|
|
269
|
+
},
|
|
270
|
+
setPointerValue(params) {
|
|
271
|
+
queueMicrotask(() => {
|
|
272
|
+
const { context, event, prop, refs } = params;
|
|
273
|
+
const pointValue = getPointValue(params, event.point);
|
|
274
|
+
if (pointValue == null) return;
|
|
275
|
+
const focusedIndex = context.get("focusedIndex");
|
|
276
|
+
const startValues = refs.get("thumbDragStartValue");
|
|
277
|
+
const result = resolveThumbCollision(prop("thumbCollisionBehavior"), focusedIndex, pointValue, context.get("value"), prop("min"), prop("max"), prop("step"), prop("minStepsBetweenThumbs"), startValues?.[focusedIndex]);
|
|
278
|
+
if (result.swapped) context.set("focusedIndex", result.index);
|
|
279
|
+
context.set("value", result.values);
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
focusActiveThumb({ scope, context }) {
|
|
283
|
+
raf(() => {
|
|
284
|
+
getThumbEl(scope, context.get("focusedIndex"))?.focus({ preventScroll: true });
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
decrementThumbAtIndex(params) {
|
|
288
|
+
const { context, event } = params;
|
|
289
|
+
const value = decrement(params, event.index, event.step);
|
|
290
|
+
context.set("value", value);
|
|
291
|
+
},
|
|
292
|
+
incrementThumbAtIndex(params) {
|
|
293
|
+
const { context, event } = params;
|
|
294
|
+
const value = increment(params, event.index, event.step);
|
|
295
|
+
context.set("value", value);
|
|
296
|
+
},
|
|
297
|
+
setFocusedThumbToMin(params) {
|
|
298
|
+
const { context } = params;
|
|
299
|
+
const index = context.get("focusedIndex");
|
|
300
|
+
const { min } = getRangeAtIndex(params, index);
|
|
301
|
+
context.set("value", (prev) => setValueAtIndex(prev, index, min));
|
|
302
|
+
},
|
|
303
|
+
setFocusedThumbToMax(params) {
|
|
304
|
+
const { context } = params;
|
|
305
|
+
const index = context.get("focusedIndex");
|
|
306
|
+
const { max } = getRangeAtIndex(params, index);
|
|
307
|
+
context.set("value", (prev) => setValueAtIndex(prev, index, max));
|
|
308
|
+
},
|
|
309
|
+
setValueAtIndex(params) {
|
|
310
|
+
const { context, event } = params;
|
|
311
|
+
const value = constrainValue(params, event.value, event.index);
|
|
312
|
+
context.set("value", (prev) => setValueAtIndex(prev, event.index, value));
|
|
313
|
+
},
|
|
314
|
+
setValue(params) {
|
|
315
|
+
const { context, event } = params;
|
|
316
|
+
const value = normalizeValues(params, event.value);
|
|
317
|
+
context.set("value", value);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
352
321
|
});
|
|
353
|
-
export {
|
|
354
|
-
machine
|
|
355
|
-
};
|
|
322
|
+
export { machine };
|