@zag-js/slider 0.82.1 → 1.0.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 +53 -28
- package/dist/index.d.ts +53 -28
- package/dist/index.js +430 -425
- package/dist/index.mjs +432 -427
- package/package.json +15 -10
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { trackFormControl, trackPointerMove, setElementValue, raf, queryAll, getRelativePoint, dispatchInputValueEvent, dataAttr, ariaAttr, getEventStep, getEventKey, isLeftClick, isModifierKey, getEventPoint } from '@zag-js/dom-query';
|
|
3
|
+
import { compact, getValuePercent, setValueAtIndex, createSplitProps, getPercentValue, getValueRanges, snapValueToStep, clampValue, getPreviousStepValue, getNextStepValue, getClosestValueIndex, first, last, getValueTransformer } from '@zag-js/utils';
|
|
4
4
|
import { createMachine } from '@zag-js/core';
|
|
5
5
|
import { trackElementsSize } from '@zag-js/element-size';
|
|
6
6
|
import { createProps } from '@zag-js/types';
|
|
@@ -19,26 +19,65 @@ var anatomy = createAnatomy("slider").parts(
|
|
|
19
19
|
"draggingIndicator"
|
|
20
20
|
);
|
|
21
21
|
var parts = anatomy.build();
|
|
22
|
+
var getRootId = (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`;
|
|
23
|
+
var getThumbId = (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`;
|
|
24
|
+
var getHiddenInputId = (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`;
|
|
25
|
+
var getControlId = (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`;
|
|
26
|
+
var getTrackId = (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`;
|
|
27
|
+
var getRangeId = (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`;
|
|
28
|
+
var getLabelId = (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`;
|
|
29
|
+
var getValueTextId = (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`;
|
|
30
|
+
var getMarkerId = (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`;
|
|
31
|
+
var getRootEl = (ctx) => ctx.getById(getRootId(ctx));
|
|
32
|
+
var getThumbEl = (ctx, index) => ctx.getById(getThumbId(ctx, index));
|
|
33
|
+
var getHiddenInputEl = (ctx, index) => ctx.getById(getHiddenInputId(ctx, index));
|
|
34
|
+
var getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
35
|
+
var getElements = (ctx) => queryAll(getControlEl(ctx), "[role=slider]");
|
|
36
|
+
var getFirstEl = (ctx) => getElements(ctx)[0];
|
|
37
|
+
var getValueFromPoint = (params, point) => {
|
|
38
|
+
const { prop, scope } = params;
|
|
39
|
+
const controlEl = getControlEl(scope);
|
|
40
|
+
if (!controlEl) return;
|
|
41
|
+
const relativePoint = getRelativePoint(point, controlEl);
|
|
42
|
+
const percent = relativePoint.getPercentValue({
|
|
43
|
+
orientation: prop("orientation"),
|
|
44
|
+
dir: prop("dir"),
|
|
45
|
+
inverted: { y: true }
|
|
46
|
+
});
|
|
47
|
+
return getPercentValue(percent, prop("min"), prop("max"), prop("step"));
|
|
48
|
+
};
|
|
49
|
+
var dispatchChangeEvent = (ctx, value) => {
|
|
50
|
+
value.forEach((value2, index) => {
|
|
51
|
+
const inputEl = getHiddenInputEl(ctx, index);
|
|
52
|
+
if (!inputEl) return;
|
|
53
|
+
dispatchInputValueEvent(inputEl, { value: value2 });
|
|
54
|
+
});
|
|
55
|
+
};
|
|
22
56
|
function getBounds(value) {
|
|
23
57
|
const firstValue = value[0];
|
|
24
58
|
const lastThumb = value[value.length - 1];
|
|
25
59
|
return [firstValue, lastThumb];
|
|
26
60
|
}
|
|
27
|
-
function getRangeOffsets(
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
61
|
+
function getRangeOffsets(params) {
|
|
62
|
+
const { prop, computed } = params;
|
|
63
|
+
const valuePercent = computed("valuePercent");
|
|
64
|
+
const [firstPercent, lastPercent] = getBounds(valuePercent);
|
|
65
|
+
if (valuePercent.length === 1) {
|
|
66
|
+
if (prop("origin") === "center") {
|
|
67
|
+
const isNegative = valuePercent[0] < 50;
|
|
68
|
+
const start = isNegative ? `${valuePercent[0]}%` : "50%";
|
|
69
|
+
const end = isNegative ? "50%" : `${100 - valuePercent[0]}%`;
|
|
34
70
|
return { start, end };
|
|
35
71
|
}
|
|
36
72
|
return { start: "0%", end: `${100 - lastPercent}%` };
|
|
37
73
|
}
|
|
38
74
|
return { start: `${firstPercent}%`, end: `${100 - lastPercent}%` };
|
|
39
75
|
}
|
|
40
|
-
function getRangeStyle(
|
|
41
|
-
|
|
76
|
+
function getRangeStyle(params) {
|
|
77
|
+
const { computed } = params;
|
|
78
|
+
const isVertical = computed("isVertical");
|
|
79
|
+
const isRtl = computed("isRtl");
|
|
80
|
+
if (isVertical) {
|
|
42
81
|
return {
|
|
43
82
|
position: "absolute",
|
|
44
83
|
bottom: "var(--slider-range-start)",
|
|
@@ -47,44 +86,51 @@ function getRangeStyle(ctx) {
|
|
|
47
86
|
}
|
|
48
87
|
return {
|
|
49
88
|
position: "absolute",
|
|
50
|
-
[
|
|
51
|
-
[
|
|
89
|
+
[isRtl ? "right" : "left"]: "var(--slider-range-start)",
|
|
90
|
+
[isRtl ? "left" : "right"]: "var(--slider-range-end)"
|
|
52
91
|
};
|
|
53
92
|
}
|
|
54
|
-
function getVerticalThumbOffset(
|
|
55
|
-
const {
|
|
56
|
-
const
|
|
57
|
-
|
|
93
|
+
function getVerticalThumbOffset(params, value) {
|
|
94
|
+
const { context, prop } = params;
|
|
95
|
+
const { height = 0 } = context.get("thumbSize") ?? {};
|
|
96
|
+
const getValue = getValueTransformer([prop("min"), prop("max")], [-height / 2, height / 2]);
|
|
97
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
58
98
|
}
|
|
59
|
-
function getHorizontalThumbOffset(
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
99
|
+
function getHorizontalThumbOffset(params, value) {
|
|
100
|
+
const { computed, context, prop } = params;
|
|
101
|
+
const { width = 0 } = context.get("thumbSize") ?? {};
|
|
102
|
+
const isRtl = computed("isRtl");
|
|
103
|
+
if (isRtl) {
|
|
104
|
+
const getValue2 = getValueTransformer([prop("max"), prop("min")], [-width / 2, width / 2]);
|
|
105
|
+
return -1 * parseFloat(getValue2(value).toFixed(2));
|
|
64
106
|
}
|
|
65
|
-
const getValue = getValueTransformer([
|
|
66
|
-
return parseFloat(getValue(
|
|
107
|
+
const getValue = getValueTransformer([prop("min"), prop("max")], [-width / 2, width / 2]);
|
|
108
|
+
return parseFloat(getValue(value).toFixed(2));
|
|
67
109
|
}
|
|
68
|
-
function getOffset(
|
|
69
|
-
|
|
70
|
-
|
|
110
|
+
function getOffset(params, percent, value) {
|
|
111
|
+
const { computed, prop } = params;
|
|
112
|
+
if (prop("thumbAlignment") === "center") return `${percent}%`;
|
|
113
|
+
const offset = computed("isVertical") ? getVerticalThumbOffset(params, value) : getHorizontalThumbOffset(params, value);
|
|
71
114
|
return `calc(${percent}% - ${offset}px)`;
|
|
72
115
|
}
|
|
73
|
-
function getThumbOffset(
|
|
74
|
-
|
|
75
|
-
|
|
116
|
+
function getThumbOffset(params, value) {
|
|
117
|
+
const { prop } = params;
|
|
118
|
+
const percent = getValuePercent(value, prop("min"), prop("max")) * 100;
|
|
119
|
+
return getOffset(params, percent, value);
|
|
76
120
|
}
|
|
77
|
-
function getVisibility(
|
|
121
|
+
function getVisibility(params) {
|
|
122
|
+
const { computed, prop } = params;
|
|
78
123
|
let visibility = "visible";
|
|
79
|
-
if (
|
|
124
|
+
if (prop("thumbAlignment") === "contain" && !computed("hasMeasuredThumbSize")) {
|
|
80
125
|
visibility = "hidden";
|
|
81
126
|
}
|
|
82
127
|
return visibility;
|
|
83
128
|
}
|
|
84
|
-
function getThumbStyle(
|
|
85
|
-
const
|
|
129
|
+
function getThumbStyle(params, index) {
|
|
130
|
+
const { computed } = params;
|
|
131
|
+
const placementProp = computed("isVertical") ? "bottom" : "insetInlineStart";
|
|
86
132
|
return {
|
|
87
|
-
visibility: getVisibility(
|
|
133
|
+
visibility: getVisibility(params),
|
|
88
134
|
position: "absolute",
|
|
89
135
|
transform: "var(--slider-thumb-transform)",
|
|
90
136
|
[placementProp]: `var(--slider-thumb-offset-${index})`
|
|
@@ -98,30 +144,34 @@ function getControlStyle() {
|
|
|
98
144
|
position: "relative"
|
|
99
145
|
};
|
|
100
146
|
}
|
|
101
|
-
function getRootStyle(
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
147
|
+
function getRootStyle(params) {
|
|
148
|
+
const { context, computed } = params;
|
|
149
|
+
const isVertical = computed("isVertical");
|
|
150
|
+
const isRtl = computed("isRtl");
|
|
151
|
+
const range = getRangeOffsets(params);
|
|
152
|
+
const offsetStyles = context.get("value").reduce((styles, value, index) => {
|
|
153
|
+
const offset = getThumbOffset(params, value);
|
|
105
154
|
return { ...styles, [`--slider-thumb-offset-${index}`]: offset };
|
|
106
155
|
}, {});
|
|
107
156
|
return {
|
|
108
157
|
...offsetStyles,
|
|
109
|
-
"--slider-thumb-transform":
|
|
158
|
+
"--slider-thumb-transform": isVertical ? "translateY(50%)" : isRtl ? "translateX(50%)" : "translateX(-50%)",
|
|
110
159
|
"--slider-range-start": range.start,
|
|
111
160
|
"--slider-range-end": range.end
|
|
112
161
|
};
|
|
113
162
|
}
|
|
114
|
-
function getMarkerStyle(
|
|
163
|
+
function getMarkerStyle(params, value) {
|
|
164
|
+
const { computed } = params;
|
|
165
|
+
const isHorizontal = computed("isHorizontal");
|
|
166
|
+
const isRtl = computed("isRtl");
|
|
115
167
|
return {
|
|
116
|
-
|
|
117
|
-
visibility: getVisibility(ctx),
|
|
168
|
+
visibility: getVisibility(params),
|
|
118
169
|
position: "absolute",
|
|
119
170
|
pointerEvents: "none",
|
|
120
|
-
|
|
121
|
-
[ctx.isHorizontal ? "insetInlineStart" : "bottom"]: getThumbOffset({ ...ctx, value }),
|
|
171
|
+
[isHorizontal ? "insetInlineStart" : "bottom"]: getThumbOffset(params, value),
|
|
122
172
|
translate: "var(--tx) var(--ty)",
|
|
123
|
-
"--tx":
|
|
124
|
-
"--ty": !
|
|
173
|
+
"--tx": isHorizontal ? isRtl ? "50%" : "-50%" : "0%",
|
|
174
|
+
"--ty": !isHorizontal ? "50%" : "0%"
|
|
125
175
|
};
|
|
126
176
|
}
|
|
127
177
|
function getMarkerGroupStyle() {
|
|
@@ -132,119 +182,72 @@ function getMarkerGroupStyle() {
|
|
|
132
182
|
position: "relative"
|
|
133
183
|
};
|
|
134
184
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
getThumbStyle,
|
|
139
|
-
getRangeStyle,
|
|
140
|
-
getMarkerStyle,
|
|
141
|
-
getMarkerGroupStyle
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// src/slider.dom.ts
|
|
145
|
-
var dom = createScope({
|
|
146
|
-
...styleGetterFns,
|
|
147
|
-
getRootId: (ctx) => ctx.ids?.root ?? `slider:${ctx.id}`,
|
|
148
|
-
getThumbId: (ctx, index) => ctx.ids?.thumb?.(index) ?? `slider:${ctx.id}:thumb:${index}`,
|
|
149
|
-
getHiddenInputId: (ctx, index) => ctx.ids?.hiddenInput?.(index) ?? `slider:${ctx.id}:input:${index}`,
|
|
150
|
-
getControlId: (ctx) => ctx.ids?.control ?? `slider:${ctx.id}:control`,
|
|
151
|
-
getTrackId: (ctx) => ctx.ids?.track ?? `slider:${ctx.id}:track`,
|
|
152
|
-
getRangeId: (ctx) => ctx.ids?.range ?? `slider:${ctx.id}:range`,
|
|
153
|
-
getLabelId: (ctx) => ctx.ids?.label ?? `slider:${ctx.id}:label`,
|
|
154
|
-
getValueTextId: (ctx) => ctx.ids?.valueText ?? `slider:${ctx.id}:value-text`,
|
|
155
|
-
getMarkerId: (ctx, value) => ctx.ids?.marker?.(value) ?? `slider:${ctx.id}:marker:${value}`,
|
|
156
|
-
getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
|
|
157
|
-
getThumbEl: (ctx, index) => dom.getById(ctx, dom.getThumbId(ctx, index)),
|
|
158
|
-
getHiddenInputEl: (ctx, index) => dom.getById(ctx, dom.getHiddenInputId(ctx, index)),
|
|
159
|
-
getControlEl: (ctx) => dom.getById(ctx, dom.getControlId(ctx)),
|
|
160
|
-
getElements: (ctx) => queryAll(dom.getControlEl(ctx), "[role=slider]"),
|
|
161
|
-
getFirstEl: (ctx) => dom.getElements(ctx)[0],
|
|
162
|
-
getRangeEl: (ctx) => dom.getById(ctx, dom.getRangeId(ctx)),
|
|
163
|
-
getValueFromPoint(ctx, point) {
|
|
164
|
-
const controlEl = dom.getControlEl(ctx);
|
|
165
|
-
if (!controlEl) return;
|
|
166
|
-
const relativePoint = getRelativePoint(point, controlEl);
|
|
167
|
-
const percent = relativePoint.getPercentValue({
|
|
168
|
-
orientation: ctx.orientation,
|
|
169
|
-
dir: ctx.dir,
|
|
170
|
-
inverted: { y: true }
|
|
171
|
-
});
|
|
172
|
-
return getPercentValue(percent, ctx.min, ctx.max, ctx.step);
|
|
173
|
-
},
|
|
174
|
-
dispatchChangeEvent(ctx) {
|
|
175
|
-
const valueArray = Array.from(ctx.value);
|
|
176
|
-
valueArray.forEach((value, index) => {
|
|
177
|
-
const inputEl = dom.getHiddenInputEl(ctx, index);
|
|
178
|
-
if (!inputEl) return;
|
|
179
|
-
dispatchInputValueEvent(inputEl, { value });
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
function normalizeValues(ctx, nextValues) {
|
|
184
|
-
return nextValues.map((value, index, values) => {
|
|
185
|
-
return constrainValue({ ...ctx, value: values }, value, index);
|
|
185
|
+
function normalizeValues(params, nextValues) {
|
|
186
|
+
return nextValues.map((value, index) => {
|
|
187
|
+
return constrainValue(params, value, index);
|
|
186
188
|
});
|
|
187
189
|
}
|
|
188
|
-
function getRangeAtIndex(
|
|
189
|
-
|
|
190
|
+
function getRangeAtIndex(params, index) {
|
|
191
|
+
const { context, prop } = params;
|
|
192
|
+
return getValueRanges(context.get("value"), prop("min"), prop("max"), prop("minStepsBetweenThumbs"))[index];
|
|
190
193
|
}
|
|
191
|
-
function constrainValue(
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
+
function constrainValue(params, value, index) {
|
|
195
|
+
const { prop } = params;
|
|
196
|
+
const range = getRangeAtIndex(params, index);
|
|
197
|
+
const snapValue = snapValueToStep(value, prop("min"), prop("max"), prop("step"));
|
|
194
198
|
return clampValue(snapValue, range.min, range.max);
|
|
195
199
|
}
|
|
196
|
-
function decrement(
|
|
197
|
-
const
|
|
198
|
-
const
|
|
200
|
+
function decrement(params, index, step) {
|
|
201
|
+
const { context, prop } = params;
|
|
202
|
+
const idx = index ?? context.get("focusedIndex");
|
|
203
|
+
const range = getRangeAtIndex(params, idx);
|
|
199
204
|
const nextValues = getPreviousStepValue(idx, {
|
|
200
205
|
...range,
|
|
201
|
-
step: step ??
|
|
202
|
-
values:
|
|
206
|
+
step: step ?? prop("step"),
|
|
207
|
+
values: context.get("value")
|
|
203
208
|
});
|
|
204
209
|
nextValues[idx] = clampValue(nextValues[idx], range.min, range.max);
|
|
205
210
|
return nextValues;
|
|
206
211
|
}
|
|
207
|
-
function increment(
|
|
208
|
-
const
|
|
209
|
-
const
|
|
212
|
+
function increment(params, index, step) {
|
|
213
|
+
const { context, prop } = params;
|
|
214
|
+
const idx = index ?? context.get("focusedIndex");
|
|
215
|
+
const range = getRangeAtIndex(params, idx);
|
|
210
216
|
const nextValues = getNextStepValue(idx, {
|
|
211
217
|
...range,
|
|
212
|
-
step: step ??
|
|
213
|
-
values:
|
|
218
|
+
step: step ?? prop("step"),
|
|
219
|
+
values: context.get("value")
|
|
214
220
|
});
|
|
215
221
|
nextValues[idx] = clampValue(nextValues[idx], range.min, range.max);
|
|
216
222
|
return nextValues;
|
|
217
223
|
}
|
|
218
|
-
function getClosestIndex(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
function assignArray(current, next) {
|
|
222
|
-
for (let i = 0; i < next.length; i++) {
|
|
223
|
-
const value = next[i];
|
|
224
|
-
current[i] = value;
|
|
225
|
-
}
|
|
224
|
+
function getClosestIndex(params, pointValue) {
|
|
225
|
+
const { context } = params;
|
|
226
|
+
return getClosestValueIndex(context.get("value"), pointValue);
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
// src/slider.connect.ts
|
|
229
|
-
function connect(
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
const
|
|
230
|
+
function connect(service, normalize) {
|
|
231
|
+
const { state, send, context, prop, computed, scope } = service;
|
|
232
|
+
const ariaLabel = prop("aria-label");
|
|
233
|
+
const ariaLabelledBy = prop("aria-labelledby");
|
|
234
|
+
const sliderValue = context.get("value");
|
|
235
|
+
const focusedIndex = context.get("focusedIndex");
|
|
233
236
|
const focused = state.matches("focus");
|
|
234
237
|
const dragging = state.matches("dragging");
|
|
235
|
-
const disabled =
|
|
236
|
-
const invalid =
|
|
237
|
-
const interactive =
|
|
238
|
-
const isHorizontal =
|
|
239
|
-
const isVertical =
|
|
238
|
+
const disabled = computed("isDisabled");
|
|
239
|
+
const invalid = prop("invalid");
|
|
240
|
+
const interactive = computed("isInteractive");
|
|
241
|
+
const isHorizontal = prop("orientation") === "horizontal";
|
|
242
|
+
const isVertical = prop("orientation") === "vertical";
|
|
240
243
|
function getValuePercentFn(value) {
|
|
241
|
-
return getValuePercent(value,
|
|
244
|
+
return getValuePercent(value, prop("min"), prop("max"));
|
|
242
245
|
}
|
|
243
246
|
function getPercentValueFn(percent) {
|
|
244
|
-
return getPercentValue(percent,
|
|
247
|
+
return getPercentValue(percent, prop("min"), prop("max"), prop("step"));
|
|
245
248
|
}
|
|
246
249
|
return {
|
|
247
|
-
value:
|
|
250
|
+
value: sliderValue,
|
|
248
251
|
dragging,
|
|
249
252
|
focused,
|
|
250
253
|
setValue(value) {
|
|
@@ -266,10 +269,10 @@ function connect(state, send, normalize) {
|
|
|
266
269
|
send({ type: "SET_VALUE", index, value });
|
|
267
270
|
},
|
|
268
271
|
getThumbMin(index) {
|
|
269
|
-
return getRangeAtIndex(
|
|
272
|
+
return getRangeAtIndex(service, index).min;
|
|
270
273
|
},
|
|
271
274
|
getThumbMax(index) {
|
|
272
|
-
return getRangeAtIndex(
|
|
275
|
+
return getRangeAtIndex(service, index).max;
|
|
273
276
|
},
|
|
274
277
|
increment(index) {
|
|
275
278
|
send({ type: "INCREMENT", index });
|
|
@@ -284,18 +287,18 @@ function connect(state, send, normalize) {
|
|
|
284
287
|
getLabelProps() {
|
|
285
288
|
return normalize.label({
|
|
286
289
|
...parts.label.attrs,
|
|
287
|
-
dir:
|
|
290
|
+
dir: prop("dir"),
|
|
288
291
|
"data-disabled": dataAttr(disabled),
|
|
289
|
-
"data-orientation":
|
|
292
|
+
"data-orientation": prop("orientation"),
|
|
290
293
|
"data-invalid": dataAttr(invalid),
|
|
291
294
|
"data-dragging": dataAttr(dragging),
|
|
292
295
|
"data-focus": dataAttr(focused),
|
|
293
|
-
id:
|
|
294
|
-
htmlFor:
|
|
296
|
+
id: getLabelId(scope),
|
|
297
|
+
htmlFor: getHiddenInputId(scope, 0),
|
|
295
298
|
onClick(event) {
|
|
296
299
|
if (!interactive) return;
|
|
297
300
|
event.preventDefault();
|
|
298
|
-
|
|
301
|
+
getFirstEl(scope)?.focus();
|
|
299
302
|
},
|
|
300
303
|
style: {
|
|
301
304
|
userSelect: "none",
|
|
@@ -307,35 +310,35 @@ function connect(state, send, normalize) {
|
|
|
307
310
|
return normalize.element({
|
|
308
311
|
...parts.root.attrs,
|
|
309
312
|
"data-disabled": dataAttr(disabled),
|
|
310
|
-
"data-orientation":
|
|
313
|
+
"data-orientation": prop("orientation"),
|
|
311
314
|
"data-dragging": dataAttr(dragging),
|
|
312
315
|
"data-invalid": dataAttr(invalid),
|
|
313
316
|
"data-focus": dataAttr(focused),
|
|
314
|
-
id:
|
|
315
|
-
dir:
|
|
316
|
-
style:
|
|
317
|
+
id: getRootId(scope),
|
|
318
|
+
dir: prop("dir"),
|
|
319
|
+
style: getRootStyle(service)
|
|
317
320
|
});
|
|
318
321
|
},
|
|
319
322
|
getValueTextProps() {
|
|
320
323
|
return normalize.element({
|
|
321
324
|
...parts.valueText.attrs,
|
|
322
|
-
dir:
|
|
325
|
+
dir: prop("dir"),
|
|
323
326
|
"data-disabled": dataAttr(disabled),
|
|
324
|
-
"data-orientation":
|
|
327
|
+
"data-orientation": prop("orientation"),
|
|
325
328
|
"data-invalid": dataAttr(invalid),
|
|
326
329
|
"data-focus": dataAttr(focused),
|
|
327
|
-
id:
|
|
330
|
+
id: getValueTextId(scope)
|
|
328
331
|
});
|
|
329
332
|
},
|
|
330
333
|
getTrackProps() {
|
|
331
334
|
return normalize.element({
|
|
332
335
|
...parts.track.attrs,
|
|
333
|
-
dir:
|
|
334
|
-
id:
|
|
336
|
+
dir: prop("dir"),
|
|
337
|
+
id: getTrackId(scope),
|
|
335
338
|
"data-disabled": dataAttr(disabled),
|
|
336
339
|
"data-invalid": dataAttr(invalid),
|
|
337
340
|
"data-dragging": dataAttr(dragging),
|
|
338
|
-
"data-orientation":
|
|
341
|
+
"data-orientation": prop("orientation"),
|
|
339
342
|
"data-focus": dataAttr(focused),
|
|
340
343
|
style: { position: "relative" }
|
|
341
344
|
});
|
|
@@ -343,32 +346,32 @@ function connect(state, send, normalize) {
|
|
|
343
346
|
getThumbProps(props2) {
|
|
344
347
|
const { index = 0, name } = props2;
|
|
345
348
|
const value = sliderValue[index];
|
|
346
|
-
const range = getRangeAtIndex(
|
|
347
|
-
const valueText =
|
|
349
|
+
const range = getRangeAtIndex(service, index);
|
|
350
|
+
const valueText = prop("getAriaValueText")?.({ value, index });
|
|
348
351
|
const _ariaLabel = Array.isArray(ariaLabel) ? ariaLabel[index] : ariaLabel;
|
|
349
352
|
const _ariaLabelledBy = Array.isArray(ariaLabelledBy) ? ariaLabelledBy[index] : ariaLabelledBy;
|
|
350
353
|
return normalize.element({
|
|
351
354
|
...parts.thumb.attrs,
|
|
352
|
-
dir:
|
|
355
|
+
dir: prop("dir"),
|
|
353
356
|
"data-index": index,
|
|
354
357
|
"data-name": name,
|
|
355
|
-
id:
|
|
358
|
+
id: getThumbId(scope, index),
|
|
356
359
|
"data-disabled": dataAttr(disabled),
|
|
357
|
-
"data-orientation":
|
|
358
|
-
"data-focus": dataAttr(focused &&
|
|
359
|
-
"data-dragging": dataAttr(dragging &&
|
|
360
|
+
"data-orientation": prop("orientation"),
|
|
361
|
+
"data-focus": dataAttr(focused && focusedIndex === index),
|
|
362
|
+
"data-dragging": dataAttr(dragging && focusedIndex === index),
|
|
360
363
|
draggable: false,
|
|
361
364
|
"aria-disabled": ariaAttr(disabled),
|
|
362
365
|
"aria-label": _ariaLabel,
|
|
363
|
-
"aria-labelledby": _ariaLabelledBy ??
|
|
364
|
-
"aria-orientation":
|
|
366
|
+
"aria-labelledby": _ariaLabelledBy ?? getLabelId(scope),
|
|
367
|
+
"aria-orientation": prop("orientation"),
|
|
365
368
|
"aria-valuemax": range.max,
|
|
366
369
|
"aria-valuemin": range.min,
|
|
367
370
|
"aria-valuenow": sliderValue[index],
|
|
368
371
|
"aria-valuetext": valueText,
|
|
369
372
|
role: "slider",
|
|
370
373
|
tabIndex: disabled ? void 0 : 0,
|
|
371
|
-
style:
|
|
374
|
+
style: getThumbStyle(service, index),
|
|
372
375
|
onPointerDown(event) {
|
|
373
376
|
if (!interactive) return;
|
|
374
377
|
send({ type: "THUMB_POINTER_DOWN", index });
|
|
@@ -376,7 +379,7 @@ function connect(state, send, normalize) {
|
|
|
376
379
|
},
|
|
377
380
|
onBlur() {
|
|
378
381
|
if (!interactive) return;
|
|
379
|
-
send("BLUR");
|
|
382
|
+
send({ type: "BLUR" });
|
|
380
383
|
},
|
|
381
384
|
onFocus() {
|
|
382
385
|
if (!interactive) return;
|
|
@@ -385,7 +388,7 @@ function connect(state, send, normalize) {
|
|
|
385
388
|
onKeyDown(event) {
|
|
386
389
|
if (event.defaultPrevented) return;
|
|
387
390
|
if (!interactive) return;
|
|
388
|
-
const step = getEventStep(event) *
|
|
391
|
+
const step = getEventStep(event) * prop("step");
|
|
389
392
|
const keyMap = {
|
|
390
393
|
ArrowUp() {
|
|
391
394
|
if (isHorizontal) return;
|
|
@@ -410,13 +413,16 @@ function connect(state, send, normalize) {
|
|
|
410
413
|
send({ type: "ARROW_DEC", step, src: "PageDown" });
|
|
411
414
|
},
|
|
412
415
|
Home() {
|
|
413
|
-
send("HOME");
|
|
416
|
+
send({ type: "HOME" });
|
|
414
417
|
},
|
|
415
418
|
End() {
|
|
416
|
-
send("END");
|
|
419
|
+
send({ type: "END" });
|
|
417
420
|
}
|
|
418
421
|
};
|
|
419
|
-
const key = getEventKey(event,
|
|
422
|
+
const key = getEventKey(event, {
|
|
423
|
+
dir: prop("dir"),
|
|
424
|
+
orientation: prop("orientation")
|
|
425
|
+
});
|
|
420
426
|
const exec = keyMap[key];
|
|
421
427
|
if (exec) {
|
|
422
428
|
exec(event);
|
|
@@ -429,38 +435,38 @@ function connect(state, send, normalize) {
|
|
|
429
435
|
getHiddenInputProps(props2) {
|
|
430
436
|
const { index = 0, name } = props2;
|
|
431
437
|
return normalize.input({
|
|
432
|
-
name: name ?? (
|
|
433
|
-
form:
|
|
438
|
+
name: name ?? (prop("name") ? prop("name") + (sliderValue.length > 1 ? "[]" : "") : void 0),
|
|
439
|
+
form: prop("form"),
|
|
434
440
|
type: "text",
|
|
435
441
|
hidden: true,
|
|
436
|
-
defaultValue:
|
|
437
|
-
id:
|
|
442
|
+
defaultValue: sliderValue[index],
|
|
443
|
+
id: getHiddenInputId(scope, index)
|
|
438
444
|
});
|
|
439
445
|
},
|
|
440
446
|
getRangeProps() {
|
|
441
447
|
return normalize.element({
|
|
442
|
-
id:
|
|
448
|
+
id: getRangeId(scope),
|
|
443
449
|
...parts.range.attrs,
|
|
444
|
-
dir:
|
|
450
|
+
dir: prop("dir"),
|
|
445
451
|
"data-dragging": dataAttr(dragging),
|
|
446
452
|
"data-focus": dataAttr(focused),
|
|
447
453
|
"data-invalid": dataAttr(invalid),
|
|
448
454
|
"data-disabled": dataAttr(disabled),
|
|
449
|
-
"data-orientation":
|
|
450
|
-
style:
|
|
455
|
+
"data-orientation": prop("orientation"),
|
|
456
|
+
style: getRangeStyle(service)
|
|
451
457
|
});
|
|
452
458
|
},
|
|
453
459
|
getControlProps() {
|
|
454
460
|
return normalize.element({
|
|
455
461
|
...parts.control.attrs,
|
|
456
|
-
dir:
|
|
457
|
-
id:
|
|
462
|
+
dir: prop("dir"),
|
|
463
|
+
id: getControlId(scope),
|
|
458
464
|
"data-dragging": dataAttr(dragging),
|
|
459
465
|
"data-disabled": dataAttr(disabled),
|
|
460
|
-
"data-orientation":
|
|
466
|
+
"data-orientation": prop("orientation"),
|
|
461
467
|
"data-invalid": dataAttr(invalid),
|
|
462
468
|
"data-focus": dataAttr(focused),
|
|
463
|
-
style:
|
|
469
|
+
style: getControlStyle(),
|
|
464
470
|
onPointerDown(event) {
|
|
465
471
|
if (!interactive) return;
|
|
466
472
|
if (!isLeftClick(event)) return;
|
|
@@ -476,30 +482,28 @@ function connect(state, send, normalize) {
|
|
|
476
482
|
return normalize.element({
|
|
477
483
|
...parts.markerGroup.attrs,
|
|
478
484
|
role: "presentation",
|
|
479
|
-
dir:
|
|
485
|
+
dir: prop("dir"),
|
|
480
486
|
"aria-hidden": true,
|
|
481
|
-
"data-orientation":
|
|
482
|
-
style:
|
|
487
|
+
"data-orientation": prop("orientation"),
|
|
488
|
+
style: getMarkerGroupStyle()
|
|
483
489
|
});
|
|
484
490
|
},
|
|
485
491
|
getMarkerProps(props2) {
|
|
486
|
-
const style =
|
|
492
|
+
const style = getMarkerStyle(service, props2.value);
|
|
487
493
|
let markerState;
|
|
488
|
-
|
|
489
|
-
const last = state.context.value[state.context.value.length - 1];
|
|
490
|
-
if (props2.value < first) {
|
|
494
|
+
if (props2.value < first(sliderValue)) {
|
|
491
495
|
markerState = "under-value";
|
|
492
|
-
} else if (props2.value > last) {
|
|
496
|
+
} else if (props2.value > last(sliderValue)) {
|
|
493
497
|
markerState = "over-value";
|
|
494
498
|
} else {
|
|
495
499
|
markerState = "at-value";
|
|
496
500
|
}
|
|
497
501
|
return normalize.element({
|
|
498
502
|
...parts.marker.attrs,
|
|
499
|
-
id:
|
|
503
|
+
id: getMarkerId(scope, props2.value),
|
|
500
504
|
role: "presentation",
|
|
501
|
-
dir:
|
|
502
|
-
"data-orientation":
|
|
505
|
+
dir: prop("dir"),
|
|
506
|
+
"data-orientation": prop("orientation"),
|
|
503
507
|
"data-value": props2.value,
|
|
504
508
|
"data-disabled": dataAttr(disabled),
|
|
505
509
|
"data-state": markerState,
|
|
@@ -508,15 +512,15 @@ function connect(state, send, normalize) {
|
|
|
508
512
|
},
|
|
509
513
|
getDraggingIndicatorProps(props2) {
|
|
510
514
|
const { index = 0 } = props2;
|
|
511
|
-
const isDragging = index ===
|
|
515
|
+
const isDragging = index === focusedIndex && dragging;
|
|
512
516
|
return normalize.element({
|
|
513
517
|
...parts.draggingIndicator.attrs,
|
|
514
518
|
role: "presentation",
|
|
515
|
-
dir:
|
|
519
|
+
dir: prop("dir"),
|
|
516
520
|
hidden: !isDragging,
|
|
517
|
-
"data-orientation":
|
|
521
|
+
"data-orientation": prop("orientation"),
|
|
518
522
|
"data-state": isDragging ? "open" : "closed",
|
|
519
|
-
style:
|
|
523
|
+
style: getThumbStyle(service, index)
|
|
520
524
|
});
|
|
521
525
|
}
|
|
522
526
|
};
|
|
@@ -524,260 +528,260 @@ function connect(state, send, normalize) {
|
|
|
524
528
|
var isEqualSize = (a, b) => {
|
|
525
529
|
return a?.width === b?.width && a?.height === b?.height;
|
|
526
530
|
};
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
},
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize != null,
|
|
557
|
-
valuePercent(ctx2) {
|
|
558
|
-
return ctx2.value.map((value) => 100 * getValuePercent(value, ctx2.min, ctx2.max));
|
|
531
|
+
var machine = createMachine({
|
|
532
|
+
props({ props: props2 }) {
|
|
533
|
+
return {
|
|
534
|
+
dir: "ltr",
|
|
535
|
+
thumbAlignment: "contain",
|
|
536
|
+
min: 0,
|
|
537
|
+
max: 100,
|
|
538
|
+
step: 1,
|
|
539
|
+
defaultValue: [0],
|
|
540
|
+
origin: "start",
|
|
541
|
+
orientation: "horizontal",
|
|
542
|
+
minStepsBetweenThumbs: 0,
|
|
543
|
+
...compact(props2)
|
|
544
|
+
};
|
|
545
|
+
},
|
|
546
|
+
initialState() {
|
|
547
|
+
return "idle";
|
|
548
|
+
},
|
|
549
|
+
context({ prop, bindable, getContext, scope }) {
|
|
550
|
+
return {
|
|
551
|
+
thumbSize: bindable(() => ({
|
|
552
|
+
defaultValue: prop("thumbSize") || null
|
|
553
|
+
})),
|
|
554
|
+
value: bindable(() => ({
|
|
555
|
+
defaultValue: prop("defaultValue"),
|
|
556
|
+
value: prop("value"),
|
|
557
|
+
onChange(value) {
|
|
558
|
+
prop("onValueChange")?.({ value });
|
|
559
|
+
dispatchChangeEvent(scope, value);
|
|
559
560
|
}
|
|
560
|
-
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
on: {
|
|
567
|
-
SET_VALUE: [
|
|
568
|
-
{
|
|
569
|
-
guard: "hasIndex",
|
|
570
|
-
actions: "setValueAtIndex"
|
|
571
|
-
},
|
|
572
|
-
{ actions: "setValue" }
|
|
573
|
-
],
|
|
574
|
-
INCREMENT: {
|
|
575
|
-
actions: "incrementThumbAtIndex"
|
|
576
|
-
},
|
|
577
|
-
DECREMENT: {
|
|
578
|
-
actions: "decrementThumbAtIndex"
|
|
561
|
+
})),
|
|
562
|
+
focusedIndex: bindable(() => ({
|
|
563
|
+
defaultValue: -1,
|
|
564
|
+
onChange(value) {
|
|
565
|
+
const ctx = getContext();
|
|
566
|
+
prop("onFocusChange")?.({ focusedIndex: value, value: ctx.get("value") });
|
|
579
567
|
}
|
|
568
|
+
})),
|
|
569
|
+
fieldsetDisabled: bindable(() => ({
|
|
570
|
+
defaultValue: false
|
|
571
|
+
}))
|
|
572
|
+
};
|
|
573
|
+
},
|
|
574
|
+
computed: {
|
|
575
|
+
isHorizontal: ({ prop }) => prop("orientation") === "horizontal",
|
|
576
|
+
isVertical: ({ prop }) => prop("orientation") === "vertical",
|
|
577
|
+
isRtl: ({ prop }) => prop("orientation") === "horizontal" && prop("dir") === "rtl",
|
|
578
|
+
isDisabled: ({ context, prop }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
579
|
+
isInteractive: ({ prop, computed }) => !(prop("readOnly") || computed("isDisabled")),
|
|
580
|
+
hasMeasuredThumbSize: ({ context }) => context.get("thumbSize") != null,
|
|
581
|
+
valuePercent({ context, prop }) {
|
|
582
|
+
return context.get("value").map((value) => 100 * getValuePercent(value, prop("min"), prop("max")));
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
watch({ track, action, context }) {
|
|
586
|
+
track([() => context.get("value").join(",")], () => {
|
|
587
|
+
action(["syncInputElements"]);
|
|
588
|
+
});
|
|
589
|
+
},
|
|
590
|
+
entry: ["coarseValue"],
|
|
591
|
+
effects: ["trackFormControlState", "trackThumbsSize"],
|
|
592
|
+
on: {
|
|
593
|
+
SET_VALUE: [
|
|
594
|
+
{
|
|
595
|
+
guard: "hasIndex",
|
|
596
|
+
actions: ["setValueAtIndex"]
|
|
580
597
|
},
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
on: {
|
|
584
|
-
POINTER_DOWN: {
|
|
585
|
-
target: "dragging",
|
|
586
|
-
actions: ["setClosestThumbIndex", "setPointerValue", "focusActiveThumb"]
|
|
587
|
-
},
|
|
588
|
-
FOCUS: {
|
|
589
|
-
target: "focus",
|
|
590
|
-
actions: "setFocusedIndex"
|
|
591
|
-
},
|
|
592
|
-
THUMB_POINTER_DOWN: {
|
|
593
|
-
target: "dragging",
|
|
594
|
-
actions: ["setFocusedIndex", "focusActiveThumb"]
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
},
|
|
598
|
-
focus: {
|
|
599
|
-
entry: "focusActiveThumb",
|
|
600
|
-
on: {
|
|
601
|
-
POINTER_DOWN: {
|
|
602
|
-
target: "dragging",
|
|
603
|
-
actions: ["setClosestThumbIndex", "setPointerValue", "focusActiveThumb"]
|
|
604
|
-
},
|
|
605
|
-
THUMB_POINTER_DOWN: {
|
|
606
|
-
target: "dragging",
|
|
607
|
-
actions: ["setFocusedIndex", "focusActiveThumb"]
|
|
608
|
-
},
|
|
609
|
-
ARROW_DEC: {
|
|
610
|
-
actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"]
|
|
611
|
-
},
|
|
612
|
-
ARROW_INC: {
|
|
613
|
-
actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"]
|
|
614
|
-
},
|
|
615
|
-
HOME: {
|
|
616
|
-
actions: ["setFocusedThumbToMin", "invokeOnChangeEnd"]
|
|
617
|
-
},
|
|
618
|
-
END: {
|
|
619
|
-
actions: ["setFocusedThumbToMax", "invokeOnChangeEnd"]
|
|
620
|
-
},
|
|
621
|
-
BLUR: {
|
|
622
|
-
target: "idle",
|
|
623
|
-
actions: "clearFocusedIndex"
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
},
|
|
627
|
-
dragging: {
|
|
628
|
-
entry: "focusActiveThumb",
|
|
629
|
-
activities: "trackPointerMove",
|
|
630
|
-
on: {
|
|
631
|
-
POINTER_UP: {
|
|
632
|
-
target: "focus",
|
|
633
|
-
actions: "invokeOnChangeEnd"
|
|
634
|
-
},
|
|
635
|
-
POINTER_MOVE: {
|
|
636
|
-
actions: "setPointerValue"
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
598
|
+
{
|
|
599
|
+
actions: ["setValue"]
|
|
640
600
|
}
|
|
601
|
+
],
|
|
602
|
+
INCREMENT: {
|
|
603
|
+
actions: ["incrementThumbAtIndex"]
|
|
641
604
|
},
|
|
642
|
-
{
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
onFormReset() {
|
|
653
|
-
set.value(ctx2, initialContext.value);
|
|
654
|
-
}
|
|
655
|
-
});
|
|
605
|
+
DECREMENT: {
|
|
606
|
+
actions: ["decrementThumbAtIndex"]
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
states: {
|
|
610
|
+
idle: {
|
|
611
|
+
on: {
|
|
612
|
+
POINTER_DOWN: {
|
|
613
|
+
target: "dragging",
|
|
614
|
+
actions: ["setClosestThumbIndex", "setPointerValue", "focusActiveThumb"]
|
|
656
615
|
},
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
send({ type: "POINTER_MOVE", point: info.point });
|
|
661
|
-
},
|
|
662
|
-
onPointerUp() {
|
|
663
|
-
send("POINTER_UP");
|
|
664
|
-
}
|
|
665
|
-
});
|
|
616
|
+
FOCUS: {
|
|
617
|
+
target: "focus",
|
|
618
|
+
actions: ["setFocusedIndex"]
|
|
666
619
|
},
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
getNodes: () => dom.getElements(ctx2),
|
|
671
|
-
observeMutation: true,
|
|
672
|
-
callback(size) {
|
|
673
|
-
if (!size || isEqualSize(ctx2.thumbSize, size)) return;
|
|
674
|
-
ctx2.thumbSize = size;
|
|
675
|
-
}
|
|
676
|
-
});
|
|
620
|
+
THUMB_POINTER_DOWN: {
|
|
621
|
+
target: "dragging",
|
|
622
|
+
actions: ["setFocusedIndex", "focusActiveThumb"]
|
|
677
623
|
}
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
invokeOnChangeEnd(ctx2) {
|
|
687
|
-
invoke.valueChangeEnd(ctx2);
|
|
688
|
-
},
|
|
689
|
-
setClosestThumbIndex(ctx2, evt) {
|
|
690
|
-
const pointValue = dom.getValueFromPoint(ctx2, evt.point);
|
|
691
|
-
if (pointValue == null) return;
|
|
692
|
-
const focusedIndex = getClosestIndex(ctx2, pointValue);
|
|
693
|
-
set.focusedIndex(ctx2, focusedIndex);
|
|
694
|
-
},
|
|
695
|
-
setFocusedIndex(ctx2, evt) {
|
|
696
|
-
set.focusedIndex(ctx2, evt.index);
|
|
697
|
-
},
|
|
698
|
-
clearFocusedIndex(ctx2) {
|
|
699
|
-
set.focusedIndex(ctx2, -1);
|
|
700
|
-
},
|
|
701
|
-
setPointerValue(ctx2, evt) {
|
|
702
|
-
const pointerValue = dom.getValueFromPoint(ctx2, evt.point);
|
|
703
|
-
if (pointerValue == null) return;
|
|
704
|
-
const value = constrainValue(ctx2, pointerValue, ctx2.focusedIndex);
|
|
705
|
-
set.valueAtIndex(ctx2, ctx2.focusedIndex, value);
|
|
706
|
-
},
|
|
707
|
-
focusActiveThumb(ctx2) {
|
|
708
|
-
raf(() => {
|
|
709
|
-
const thumbEl = dom.getThumbEl(ctx2, ctx2.focusedIndex);
|
|
710
|
-
thumbEl?.focus({ preventScroll: true });
|
|
711
|
-
});
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
focus: {
|
|
627
|
+
entry: ["focusActiveThumb"],
|
|
628
|
+
on: {
|
|
629
|
+
POINTER_DOWN: {
|
|
630
|
+
target: "dragging",
|
|
631
|
+
actions: ["setClosestThumbIndex", "setPointerValue", "focusActiveThumb"]
|
|
712
632
|
},
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
633
|
+
THUMB_POINTER_DOWN: {
|
|
634
|
+
target: "dragging",
|
|
635
|
+
actions: ["setFocusedIndex", "focusActiveThumb"]
|
|
716
636
|
},
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
set.value(ctx2, value);
|
|
637
|
+
ARROW_DEC: {
|
|
638
|
+
actions: ["decrementThumbAtIndex", "invokeOnChangeEnd"]
|
|
720
639
|
},
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
set.valueAtIndex(ctx2, ctx2.focusedIndex, min);
|
|
640
|
+
ARROW_INC: {
|
|
641
|
+
actions: ["incrementThumbAtIndex", "invokeOnChangeEnd"]
|
|
724
642
|
},
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
set.valueAtIndex(ctx2, ctx2.focusedIndex, max);
|
|
643
|
+
HOME: {
|
|
644
|
+
actions: ["setFocusedThumbToMin", "invokeOnChangeEnd"]
|
|
728
645
|
},
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
set.value(ctx2, value);
|
|
646
|
+
END: {
|
|
647
|
+
actions: ["setFocusedThumbToMax", "invokeOnChangeEnd"]
|
|
732
648
|
},
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
649
|
+
BLUR: {
|
|
650
|
+
target: "idle",
|
|
651
|
+
actions: ["clearFocusedIndex"]
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
dragging: {
|
|
656
|
+
entry: ["focusActiveThumb"],
|
|
657
|
+
effects: ["trackPointerMove"],
|
|
658
|
+
on: {
|
|
659
|
+
POINTER_UP: {
|
|
660
|
+
target: "focus",
|
|
661
|
+
actions: ["invokeOnChangeEnd"]
|
|
736
662
|
},
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
set.value(ctx2, value);
|
|
663
|
+
POINTER_MOVE: {
|
|
664
|
+
actions: ["setPointerValue"]
|
|
740
665
|
}
|
|
741
666
|
}
|
|
742
667
|
}
|
|
743
|
-
);
|
|
744
|
-
}
|
|
745
|
-
var invoke = {
|
|
746
|
-
valueChange(ctx) {
|
|
747
|
-
ctx.onValueChange?.({
|
|
748
|
-
value: Array.from(ctx.value)
|
|
749
|
-
});
|
|
750
|
-
dom.dispatchChangeEvent(ctx);
|
|
751
|
-
},
|
|
752
|
-
valueChangeEnd(ctx) {
|
|
753
|
-
ctx.onValueChangeEnd?.({
|
|
754
|
-
value: Array.from(ctx.value)
|
|
755
|
-
});
|
|
756
|
-
},
|
|
757
|
-
focusChange(ctx) {
|
|
758
|
-
ctx.onFocusChange?.({
|
|
759
|
-
value: Array.from(ctx.value),
|
|
760
|
-
focusedIndex: ctx.focusedIndex
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
var set = {
|
|
765
|
-
valueAtIndex: (ctx, index, value) => {
|
|
766
|
-
if (isEqual(ctx.value[index], value)) return;
|
|
767
|
-
ctx.value[index] = value;
|
|
768
|
-
invoke.valueChange(ctx);
|
|
769
|
-
},
|
|
770
|
-
value: (ctx, value) => {
|
|
771
|
-
if (isEqual(ctx.value, value)) return;
|
|
772
|
-
assignArray(ctx.value, value);
|
|
773
|
-
invoke.valueChange(ctx);
|
|
774
668
|
},
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
669
|
+
implementations: {
|
|
670
|
+
guards: {
|
|
671
|
+
hasIndex: ({ event }) => event.index != null
|
|
672
|
+
},
|
|
673
|
+
effects: {
|
|
674
|
+
trackFormControlState({ context, scope }) {
|
|
675
|
+
return trackFormControl(getRootEl(scope), {
|
|
676
|
+
onFieldsetDisabledChange(disabled) {
|
|
677
|
+
context.set("fieldsetDisabled", disabled);
|
|
678
|
+
},
|
|
679
|
+
onFormReset() {
|
|
680
|
+
context.set("value", context.initial("value"));
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
},
|
|
684
|
+
trackPointerMove({ scope, send }) {
|
|
685
|
+
return trackPointerMove(scope.getDoc(), {
|
|
686
|
+
onPointerMove(info) {
|
|
687
|
+
send({ type: "POINTER_MOVE", point: info.point });
|
|
688
|
+
},
|
|
689
|
+
onPointerUp() {
|
|
690
|
+
send({ type: "POINTER_UP" });
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
trackThumbsSize({ context, scope, prop }) {
|
|
695
|
+
if (prop("thumbAlignment") !== "contain" || context.get("thumbSize")) return;
|
|
696
|
+
return trackElementsSize({
|
|
697
|
+
getNodes: () => getElements(scope),
|
|
698
|
+
observeMutation: true,
|
|
699
|
+
callback(size) {
|
|
700
|
+
if (!size || isEqualSize(context.get("thumbSize"), size)) return;
|
|
701
|
+
context.set("thumbSize", size);
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
actions: {
|
|
707
|
+
syncInputElements({ context, scope }) {
|
|
708
|
+
context.get("value").forEach((value, index) => {
|
|
709
|
+
const inputEl = getHiddenInputEl(scope, index);
|
|
710
|
+
setElementValue(inputEl, value.toString());
|
|
711
|
+
});
|
|
712
|
+
},
|
|
713
|
+
invokeOnChangeEnd({ prop, context }) {
|
|
714
|
+
prop("onValueChangeEnd")?.({ value: context.get("value") });
|
|
715
|
+
},
|
|
716
|
+
setClosestThumbIndex(params) {
|
|
717
|
+
const { context, event } = params;
|
|
718
|
+
const pointValue = getValueFromPoint(params, event.point);
|
|
719
|
+
if (pointValue == null) return;
|
|
720
|
+
const focusedIndex = getClosestIndex(params, pointValue);
|
|
721
|
+
context.set("focusedIndex", focusedIndex);
|
|
722
|
+
},
|
|
723
|
+
setFocusedIndex({ context, event }) {
|
|
724
|
+
context.set("focusedIndex", event.index);
|
|
725
|
+
},
|
|
726
|
+
clearFocusedIndex({ context }) {
|
|
727
|
+
context.set("focusedIndex", -1);
|
|
728
|
+
},
|
|
729
|
+
setPointerValue(params) {
|
|
730
|
+
queueMicrotask(() => {
|
|
731
|
+
const { context, event } = params;
|
|
732
|
+
const pointValue = getValueFromPoint(params, event.point);
|
|
733
|
+
if (pointValue == null) return;
|
|
734
|
+
const focusedIndex = context.get("focusedIndex");
|
|
735
|
+
const value = constrainValue(params, pointValue, focusedIndex);
|
|
736
|
+
context.set("value", (prev) => setValueAtIndex(prev, focusedIndex, value));
|
|
737
|
+
});
|
|
738
|
+
},
|
|
739
|
+
focusActiveThumb({ scope, context }) {
|
|
740
|
+
raf(() => {
|
|
741
|
+
const thumbEl = getThumbEl(scope, context.get("focusedIndex"));
|
|
742
|
+
thumbEl?.focus({ preventScroll: true });
|
|
743
|
+
});
|
|
744
|
+
},
|
|
745
|
+
decrementThumbAtIndex(params) {
|
|
746
|
+
const { context, event } = params;
|
|
747
|
+
const value = decrement(params, event.index, event.step);
|
|
748
|
+
context.set("value", value);
|
|
749
|
+
},
|
|
750
|
+
incrementThumbAtIndex(params) {
|
|
751
|
+
const { context, event } = params;
|
|
752
|
+
const value = increment(params, event.index, event.step);
|
|
753
|
+
context.set("value", value);
|
|
754
|
+
},
|
|
755
|
+
setFocusedThumbToMin(params) {
|
|
756
|
+
const { context } = params;
|
|
757
|
+
const index = context.get("focusedIndex");
|
|
758
|
+
const { min } = getRangeAtIndex(params, index);
|
|
759
|
+
context.set("value", (prev) => setValueAtIndex(prev, index, min));
|
|
760
|
+
},
|
|
761
|
+
setFocusedThumbToMax(params) {
|
|
762
|
+
const { context } = params;
|
|
763
|
+
const index = context.get("focusedIndex");
|
|
764
|
+
const { max } = getRangeAtIndex(params, index);
|
|
765
|
+
context.set("value", (prev) => setValueAtIndex(prev, index, max));
|
|
766
|
+
},
|
|
767
|
+
coarseValue(params) {
|
|
768
|
+
const { context } = params;
|
|
769
|
+
const value = normalizeValues(params, context.get("value"));
|
|
770
|
+
context.set("value", value);
|
|
771
|
+
},
|
|
772
|
+
setValueAtIndex(params) {
|
|
773
|
+
const { context, event } = params;
|
|
774
|
+
const value = constrainValue(params, event.value, event.index);
|
|
775
|
+
context.set("value", (prev) => setValueAtIndex(prev, event.index, value));
|
|
776
|
+
},
|
|
777
|
+
setValue(params) {
|
|
778
|
+
const { context, event } = params;
|
|
779
|
+
const value = normalizeValues(params, event.value);
|
|
780
|
+
context.set("value", value);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
779
783
|
}
|
|
780
|
-
};
|
|
784
|
+
});
|
|
781
785
|
var props = createProps()([
|
|
782
786
|
"aria-label",
|
|
783
787
|
"aria-labelledby",
|
|
@@ -803,7 +807,8 @@ var props = createProps()([
|
|
|
803
807
|
"thumbAlignment",
|
|
804
808
|
"thumbAlignment",
|
|
805
809
|
"thumbSize",
|
|
806
|
-
"value"
|
|
810
|
+
"value",
|
|
811
|
+
"defaultValue"
|
|
807
812
|
]);
|
|
808
813
|
var splitProps = createSplitProps(props);
|
|
809
814
|
var thumbProps = createProps()(["index", "name"]);
|