@react-aria/slider 3.0.4-nightly.3038 → 3.0.4-nightly.3062

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/main.js CHANGED
@@ -1,424 +1,311 @@
1
- var {
2
- useFocusable
3
- } = require("@react-aria/focus");
4
-
5
- var {
6
- useLocale
7
- } = require("@react-aria/i18n");
8
-
9
- var {
10
- useLabel
11
- } = require("@react-aria/label");
12
-
13
- var {
14
- setInteractionModality,
15
- useMove
16
- } = require("@react-aria/interactions");
17
-
18
- var {
19
- useRef,
20
- useCallback,
21
- useEffect
22
- } = require("react");
23
-
24
- var {
25
- clamp,
26
- mergeProps,
27
- useGlobalListeners,
28
- focusWithoutScrolling
29
- } = require("@react-aria/utils");
1
+ var $3pmKZ$reactariautils = require("@react-aria/utils");
2
+ var $3pmKZ$react = require("react");
3
+ var $3pmKZ$reactariainteractions = require("@react-aria/interactions");
4
+ var $3pmKZ$reactarialabel = require("@react-aria/label");
5
+ var $3pmKZ$reactariai18n = require("@react-aria/i18n");
6
+ var $3pmKZ$reactariafocus = require("@react-aria/focus");
7
+
8
+ function $parcel$exportWildcard(dest, source) {
9
+ Object.keys(source).forEach(function(key) {
10
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
11
+ return;
12
+ }
30
13
 
31
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
14
+ Object.defineProperty(dest, key, {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return source[key];
18
+ }
19
+ });
20
+ });
32
21
 
33
- function $parcel$interopDefault(a) {
34
- return a && a.__esModule ? a.default : a;
22
+ return dest;
35
23
  }
36
-
37
- const $dec1906781d9c7cb69245fc4d5344b$export$sliderIds = new WeakMap();
38
-
39
- function $dec1906781d9c7cb69245fc4d5344b$export$getSliderThumbId(state, index) {
40
- let id = $dec1906781d9c7cb69245fc4d5344b$export$sliderIds.get(state);
41
-
42
- if (!id) {
43
- throw new Error('Unknown slider state');
44
- }
45
-
46
- return id + "-" + index;
24
+ function $parcel$export(e, n, v, s) {
25
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
47
26
  }
27
+ var $c435846bb557c48e$exports = {};
48
28
 
49
- /**
50
- * Provides the behavior and accessibility implementation for a slider component representing one or more values.
51
- *
52
- * @param props Props for the slider.
53
- * @param state State for the slider, as returned by `useSliderState`.
54
- * @param trackRef Ref for the "track" element. The width of this element provides the "length"
55
- * of the track -- the span of one dimensional space that the slider thumb can be. It also
56
- * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
57
- * the track.
58
- */
59
- function useSlider(props, state, trackRef) {
60
- var _labelProps$id;
61
-
62
- let {
63
- labelProps,
64
- fieldProps
65
- } = useLabel(props);
66
- let isVertical = props.orientation === 'vertical'; // Attach id of the label to the state so it can be accessed by useSliderThumb.
67
-
68
- $dec1906781d9c7cb69245fc4d5344b$export$sliderIds.set(state, (_labelProps$id = labelProps.id) != null ? _labelProps$id : fieldProps.id);
69
- let {
70
- direction
71
- } = useLocale();
72
- let {
73
- addGlobalListener,
74
- removeGlobalListener
75
- } = useGlobalListeners(); // When the user clicks or drags the track, we want the motion to set and drag the
76
- // closest thumb. Hence we also need to install useMove() on the track element.
77
- // Here, we keep track of which index is the "closest" to the drag start point.
78
- // It is set onMouseDown/onTouchDown; see trackProps below.
79
-
80
- const realTimeTrackDraggingIndex = useRef(null);
81
- const stateRef = useRef(null);
82
- stateRef.current = state;
83
- const reverseX = direction === 'rtl';
84
- const currentPosition = useRef(null);
85
- const {
86
- moveProps
87
- } = useMove({
88
- onMoveStart() {
89
- currentPosition.current = null;
90
- },
91
-
92
- onMove(_ref) {
93
- let {
94
- deltaX,
95
- deltaY
96
- } = _ref;
97
- let size = isVertical ? trackRef.current.offsetHeight : trackRef.current.offsetWidth;
98
-
99
- if (currentPosition.current == null) {
100
- currentPosition.current = stateRef.current.getThumbPercent(realTimeTrackDraggingIndex.current) * size;
101
- }
102
-
103
- let delta = isVertical ? deltaY : deltaX;
104
-
105
- if (isVertical || reverseX) {
106
- delta = -delta;
107
- }
108
-
109
- currentPosition.current += delta;
29
+ $parcel$export($c435846bb557c48e$exports, "useSlider", () => $c435846bb557c48e$export$56b2c08e277f365);
110
30
 
111
- if (realTimeTrackDraggingIndex.current != null && trackRef.current) {
112
- const percent = clamp(currentPosition.current / size, 0, 1);
113
- stateRef.current.setThumbPercent(realTimeTrackDraggingIndex.current, percent);
114
- }
115
- },
116
-
117
- onMoveEnd() {
118
- if (realTimeTrackDraggingIndex.current != null) {
119
- stateRef.current.setThumbDragging(realTimeTrackDraggingIndex.current, false);
120
- realTimeTrackDraggingIndex.current = null;
121
- }
122
- }
123
-
124
- });
125
- let currentPointer = useRef(undefined);
126
-
127
- let onDownTrack = (e, id, clientX, clientY) => {
128
- // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.
129
- if (trackRef.current && !props.isDisabled && state.values.every((_, i) => !state.isThumbDragging(i))) {
130
- let size = isVertical ? trackRef.current.offsetHeight : trackRef.current.offsetWidth; // Find the closest thumb
31
+ const $8c52a6191bdb125d$export$7a8d2b02c9371cbf = new WeakMap();
32
+ function $8c52a6191bdb125d$export$68e648cbec363a18(state, index) {
33
+ let id = $8c52a6191bdb125d$export$7a8d2b02c9371cbf.get(state);
34
+ if (!id) throw new Error('Unknown slider state');
35
+ return `${id}-${index}`;
36
+ }
131
37
 
132
- const trackPosition = trackRef.current.getBoundingClientRect()[isVertical ? 'top' : 'left'];
133
- const clickPosition = isVertical ? clientY : clientX;
134
- const offset = clickPosition - trackPosition;
135
- let percent = offset / size;
136
38
 
137
- if (direction === 'rtl' || isVertical) {
138
- percent = 1 - percent;
139
- }
140
39
 
141
- let value = state.getPercentValue(percent); // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
142
40
 
143
- let closestThumb;
144
- let split = state.values.findIndex(v => value - v < 0);
145
41
 
146
- if (split === 0) {
147
- // If the index is zero then the closetThumb is the first one
148
- closestThumb = split;
149
- } else if (split === -1) {
150
- // If no index is found they've clicked past all the thumbs
151
- closestThumb = state.values.length - 1;
152
- } else {
153
- let lastLeft = state.values[split - 1];
154
- let firstRight = state.values[split]; // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one
155
42
 
156
- if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) {
157
- closestThumb = split - 1;
158
- } else {
159
- closestThumb = split;
43
+ function $c435846bb557c48e$export$56b2c08e277f365(props, state, trackRef) {
44
+ let { labelProps: labelProps , fieldProps: fieldProps } = $3pmKZ$reactarialabel.useLabel(props);
45
+ let isVertical = props.orientation === 'vertical';
46
+ // Attach id of the label to the state so it can be accessed by useSliderThumb.
47
+ $8c52a6191bdb125d$export$7a8d2b02c9371cbf.set(state, labelProps.id ?? fieldProps.id);
48
+ let { direction: direction } = $3pmKZ$reactariai18n.useLocale();
49
+ let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = $3pmKZ$reactariautils.useGlobalListeners();
50
+ // When the user clicks or drags the track, we want the motion to set and drag the
51
+ // closest thumb. Hence we also need to install useMove() on the track element.
52
+ // Here, we keep track of which index is the "closest" to the drag start point.
53
+ // It is set onMouseDown/onTouchDown; see trackProps below.
54
+ const realTimeTrackDraggingIndex = $3pmKZ$react.useRef(null);
55
+ const stateRef = $3pmKZ$react.useRef(null);
56
+ stateRef.current = state;
57
+ const reverseX = direction === 'rtl';
58
+ const currentPosition = $3pmKZ$react.useRef(null);
59
+ const { moveProps: moveProps } = $3pmKZ$reactariainteractions.useMove({
60
+ onMoveStart () {
61
+ currentPosition.current = null;
62
+ },
63
+ onMove ({ deltaX: deltaX , deltaY: deltaY }) {
64
+ let size = isVertical ? trackRef.current.offsetHeight : trackRef.current.offsetWidth;
65
+ if (currentPosition.current == null) currentPosition.current = stateRef.current.getThumbPercent(realTimeTrackDraggingIndex.current) * size;
66
+ let delta = isVertical ? deltaY : deltaX;
67
+ if (isVertical || reverseX) delta = -delta;
68
+ currentPosition.current += delta;
69
+ if (realTimeTrackDraggingIndex.current != null && trackRef.current) {
70
+ const percent = $3pmKZ$reactariautils.clamp(currentPosition.current / size, 0, 1);
71
+ stateRef.current.setThumbPercent(realTimeTrackDraggingIndex.current, percent);
72
+ }
73
+ },
74
+ onMoveEnd () {
75
+ if (realTimeTrackDraggingIndex.current != null) {
76
+ stateRef.current.setThumbDragging(realTimeTrackDraggingIndex.current, false);
77
+ realTimeTrackDraggingIndex.current = null;
78
+ }
160
79
  }
161
- } // Confirm that the found closest thumb is editable, not disabled, and move it
162
-
163
-
164
- if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {
165
- // Don't unfocus anything
166
- e.preventDefault();
167
- realTimeTrackDraggingIndex.current = closestThumb;
168
- state.setFocusedThumb(closestThumb);
169
- currentPointer.current = id;
170
- state.setThumbDragging(realTimeTrackDraggingIndex.current, true);
171
- state.setThumbValue(closestThumb, value);
172
- addGlobalListener(window, 'mouseup', onUpTrack, false);
173
- addGlobalListener(window, 'touchend', onUpTrack, false);
174
- addGlobalListener(window, 'pointerup', onUpTrack, false);
175
- } else {
176
- realTimeTrackDraggingIndex.current = null;
177
- }
178
- }
179
- };
180
-
181
- let onUpTrack = e => {
182
- var _e$pointerId, _e$changedTouches;
183
-
184
- let id = (_e$pointerId = e.pointerId) != null ? _e$pointerId : (_e$changedTouches = e.changedTouches) == null ? void 0 : _e$changedTouches[0].identifier;
185
-
186
- if (id === currentPointer.current) {
187
- if (realTimeTrackDraggingIndex.current != null) {
188
- state.setThumbDragging(realTimeTrackDraggingIndex.current, false);
189
- realTimeTrackDraggingIndex.current = null;
190
- }
191
-
192
- removeGlobalListener(window, 'mouseup', onUpTrack, false);
193
- removeGlobalListener(window, 'touchend', onUpTrack, false);
194
- removeGlobalListener(window, 'pointerup', onUpTrack, false);
195
- }
196
- };
197
-
198
- if (labelProps.htmlFor) {
199
- // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS
200
- // causes this to override the `aria-labelledby` on the thumb. This causes the first
201
- // thumb to only be announced as the slider label rather than its individual name as well.
202
- // See https://bugs.webkit.org/show_bug.cgi?id=172464.
203
- delete labelProps.htmlFor;
204
-
205
- labelProps.onClick = () => {
206
- var _document$getElementB;
207
-
208
- // Safari does not focus <input type="range"> elements when clicking on an associated <label>,
209
- // so do it manually. In addition, make sure we show the focus ring.
210
- (_document$getElementB = document.getElementById($dec1906781d9c7cb69245fc4d5344b$export$getSliderThumbId(state, 0))) == null ? void 0 : _document$getElementB.focus();
211
- setInteractionModality('keyboard');
212
- };
213
- }
214
-
215
- return {
216
- labelProps,
217
- // The root element of the Slider will have role="group" to group together
218
- // all the thumb inputs in the Slider. The label of the Slider will
219
- // be used to label the group.
220
- groupProps: _babelRuntimeHelpersExtends({
221
- role: 'group'
222
- }, fieldProps),
223
- trackProps: mergeProps({
224
- onMouseDown(e) {
225
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
226
- return;
80
+ });
81
+ let currentPointer = $3pmKZ$react.useRef(undefined);
82
+ let onDownTrack = (e, id, clientX, clientY)=>{
83
+ // We only trigger track-dragging if the user clicks on the track itself and nothing is currently being dragged.
84
+ if (trackRef.current && !props.isDisabled && state.values.every((_, i)=>!state.isThumbDragging(i)
85
+ )) {
86
+ let size = isVertical ? trackRef.current.offsetHeight : trackRef.current.offsetWidth;
87
+ // Find the closest thumb
88
+ const trackPosition = trackRef.current.getBoundingClientRect()[isVertical ? 'top' : 'left'];
89
+ const clickPosition = isVertical ? clientY : clientX;
90
+ const offset = clickPosition - trackPosition;
91
+ let percent = offset / size;
92
+ if (direction === 'rtl' || isVertical) percent = 1 - percent;
93
+ let value = state.getPercentValue(percent);
94
+ // to find the closet thumb we split the array based on the first thumb position to the "right/end" of the click.
95
+ let closestThumb;
96
+ let split = state.values.findIndex((v)=>value - v < 0
97
+ );
98
+ if (split === 0) closestThumb = split;
99
+ else if (split === -1) closestThumb = state.values.length - 1;
100
+ else {
101
+ let lastLeft = state.values[split - 1];
102
+ let firstRight = state.values[split];
103
+ // Pick the last left/start thumb, unless they are stacked on top of each other, then pick the right/end one
104
+ if (Math.abs(lastLeft - value) < Math.abs(firstRight - value)) closestThumb = split - 1;
105
+ else closestThumb = split;
106
+ }
107
+ // Confirm that the found closest thumb is editable, not disabled, and move it
108
+ if (closestThumb >= 0 && state.isThumbEditable(closestThumb)) {
109
+ // Don't unfocus anything
110
+ e.preventDefault();
111
+ realTimeTrackDraggingIndex.current = closestThumb;
112
+ state.setFocusedThumb(closestThumb);
113
+ currentPointer.current = id;
114
+ state.setThumbDragging(realTimeTrackDraggingIndex.current, true);
115
+ state.setThumbValue(closestThumb, value);
116
+ addGlobalListener(window, 'mouseup', onUpTrack, false);
117
+ addGlobalListener(window, 'touchend', onUpTrack, false);
118
+ addGlobalListener(window, 'pointerup', onUpTrack, false);
119
+ } else realTimeTrackDraggingIndex.current = null;
227
120
  }
228
-
229
- onDownTrack(e, undefined, e.clientX, e.clientY);
230
- },
231
-
232
- onPointerDown(e) {
233
- if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {
234
- return;
121
+ };
122
+ let onUpTrack = (e)=>{
123
+ let id = e.pointerId ?? e.changedTouches?.[0].identifier;
124
+ if (id === currentPointer.current) {
125
+ if (realTimeTrackDraggingIndex.current != null) {
126
+ state.setThumbDragging(realTimeTrackDraggingIndex.current, false);
127
+ realTimeTrackDraggingIndex.current = null;
128
+ }
129
+ removeGlobalListener(window, 'mouseup', onUpTrack, false);
130
+ removeGlobalListener(window, 'touchend', onUpTrack, false);
131
+ removeGlobalListener(window, 'pointerup', onUpTrack, false);
235
132
  }
236
-
237
- onDownTrack(e, e.pointerId, e.clientX, e.clientY);
238
- },
239
-
240
- onTouchStart(e) {
241
- onDownTrack(e, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
242
- }
243
-
244
- }, moveProps),
245
- outputProps: {
246
- htmlFor: state.values.map((_, index) => $dec1906781d9c7cb69245fc4d5344b$export$getSliderThumbId(state, index)).join(' '),
247
- 'aria-live': 'off'
133
+ };
134
+ if (labelProps.htmlFor) {
135
+ // Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS
136
+ // causes this to override the `aria-labelledby` on the thumb. This causes the first
137
+ // thumb to only be announced as the slider label rather than its individual name as well.
138
+ // See https://bugs.webkit.org/show_bug.cgi?id=172464.
139
+ delete labelProps.htmlFor;
140
+ labelProps.onClick = ()=>{
141
+ // Safari does not focus <input type="range"> elements when clicking on an associated <label>,
142
+ // so do it manually. In addition, make sure we show the focus ring.
143
+ document.getElementById($8c52a6191bdb125d$export$68e648cbec363a18(state, 0))?.focus();
144
+ $3pmKZ$reactariainteractions.setInteractionModality('keyboard');
145
+ };
248
146
  }
249
- };
147
+ return {
148
+ labelProps: labelProps,
149
+ // The root element of the Slider will have role="group" to group together
150
+ // all the thumb inputs in the Slider. The label of the Slider will
151
+ // be used to label the group.
152
+ groupProps: {
153
+ role: 'group',
154
+ ...fieldProps
155
+ },
156
+ trackProps: $3pmKZ$reactariautils.mergeProps({
157
+ onMouseDown (e) {
158
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
159
+ onDownTrack(e, undefined, e.clientX, e.clientY);
160
+ },
161
+ onPointerDown (e) {
162
+ if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) return;
163
+ onDownTrack(e, e.pointerId, e.clientX, e.clientY);
164
+ },
165
+ onTouchStart (e) {
166
+ onDownTrack(e, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
167
+ }
168
+ }, moveProps),
169
+ outputProps: {
170
+ htmlFor: state.values.map((_, index)=>$8c52a6191bdb125d$export$68e648cbec363a18(state, index)
171
+ ).join(' '),
172
+ 'aria-live': 'off'
173
+ }
174
+ };
250
175
  }
251
176
 
252
- exports.useSlider = useSlider;
253
-
254
- /**
255
- * Provides behavior and accessibility for a thumb of a slider component.
256
- *
257
- * @param opts Options for this Slider thumb.
258
- * @param state Slider state, created via `useSliderState`.
259
- */
260
- function useSliderThumb(opts, state) {
261
- var _opts$ariaLabelledby;
262
-
263
- let {
264
- index,
265
- isRequired,
266
- isDisabled,
267
- validationState,
268
- trackRef,
269
- inputRef
270
- } = opts;
271
- let isVertical = opts.orientation === 'vertical';
272
- let {
273
- direction
274
- } = useLocale();
275
- let {
276
- addGlobalListener,
277
- removeGlobalListener
278
- } = useGlobalListeners();
279
- let labelId = $dec1906781d9c7cb69245fc4d5344b$export$sliderIds.get(state);
280
- const {
281
- labelProps,
282
- fieldProps
283
- } = useLabel(_babelRuntimeHelpersExtends({}, opts, {
284
- id: $dec1906781d9c7cb69245fc4d5344b$export$getSliderThumbId(state, index),
285
- 'aria-labelledby': (labelId + " " + ((_opts$ariaLabelledby = opts['aria-labelledby']) != null ? _opts$ariaLabelledby : '')).trim()
286
- }));
287
- const value = state.values[index];
288
- const focusInput = useCallback(() => {
289
- if (inputRef.current) {
290
- focusWithoutScrolling(inputRef.current);
291
- }
292
- }, [inputRef]);
293
- const isFocused = state.focusedThumb === index;
294
- useEffect(() => {
295
- if (isFocused) {
296
- focusInput();
297
- }
298
- }, [isFocused, focusInput]);
299
- const stateRef = useRef(null);
300
- stateRef.current = state;
301
- let reverseX = direction === 'rtl';
302
- let currentPosition = useRef(null);
303
- let {
304
- moveProps
305
- } = useMove({
306
- onMoveStart() {
307
- currentPosition.current = null;
308
- state.setThumbDragging(index, true);
309
- },
310
177
 
311
- onMove(_ref) {
312
- let {
313
- deltaX,
314
- deltaY,
315
- pointerType
316
- } = _ref;
317
- let size = isVertical ? trackRef.current.offsetHeight : trackRef.current.offsetWidth;
318
-
319
- if (currentPosition.current == null) {
320
- currentPosition.current = stateRef.current.getThumbPercent(index) * size;
321
- }
322
-
323
- if (pointerType === 'keyboard') {
324
- // (invert left/right according to language direction) + (according to vertical)
325
- let delta = ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) * stateRef.current.step;
326
- currentPosition.current += delta * size;
327
- stateRef.current.setThumbValue(index, stateRef.current.getThumbValue(index) + delta);
328
- } else {
329
- let delta = isVertical ? deltaY : deltaX;
330
-
331
- if (isVertical || reverseX) {
332
- delta = -delta;
178
+ var $07aa5c3f60769fb0$exports = {};
179
+
180
+ $parcel$export($07aa5c3f60769fb0$exports, "useSliderThumb", () => $07aa5c3f60769fb0$export$8d15029008292ae);
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+ function $07aa5c3f60769fb0$export$8d15029008292ae(opts, state) {
189
+ let { index: index , isRequired: isRequired , isDisabled: isDisabled , validationState: validationState , trackRef: trackRef , inputRef: inputRef } = opts;
190
+ let isVertical = opts.orientation === 'vertical';
191
+ let { direction: direction } = $3pmKZ$reactariai18n.useLocale();
192
+ let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = $3pmKZ$reactariautils.useGlobalListeners();
193
+ let labelId = $8c52a6191bdb125d$export$7a8d2b02c9371cbf.get(state);
194
+ const { labelProps: labelProps , fieldProps: fieldProps } = $3pmKZ$reactarialabel.useLabel({
195
+ ...opts,
196
+ id: $8c52a6191bdb125d$export$68e648cbec363a18(state, index),
197
+ 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim()
198
+ });
199
+ const value = state.values[index];
200
+ const focusInput = $3pmKZ$react.useCallback(()=>{
201
+ if (inputRef.current) $3pmKZ$reactariautils.focusWithoutScrolling(inputRef.current);
202
+ }, [
203
+ inputRef
204
+ ]);
205
+ const isFocused = state.focusedThumb === index;
206
+ $3pmKZ$react.useEffect(()=>{
207
+ if (isFocused) focusInput();
208
+ }, [
209
+ isFocused,
210
+ focusInput
211
+ ]);
212
+ const stateRef = $3pmKZ$react.useRef(null);
213
+ stateRef.current = state;
214
+ let reverseX = direction === 'rtl';
215
+ let currentPosition = $3pmKZ$react.useRef(null);
216
+ let { moveProps: moveProps } = $3pmKZ$reactariainteractions.useMove({
217
+ onMoveStart () {
218
+ currentPosition.current = null;
219
+ state.setThumbDragging(index, true);
220
+ },
221
+ onMove ({ deltaX: deltaX , deltaY: deltaY , pointerType: pointerType }) {
222
+ let size = isVertical ? trackRef.current.offsetHeight : trackRef.current.offsetWidth;
223
+ if (currentPosition.current == null) currentPosition.current = stateRef.current.getThumbPercent(index) * size;
224
+ if (pointerType === 'keyboard') {
225
+ // (invert left/right according to language direction) + (according to vertical)
226
+ let delta = ((reverseX ? -deltaX : deltaX) + (isVertical ? -deltaY : -deltaY)) * stateRef.current.step;
227
+ currentPosition.current += delta * size;
228
+ stateRef.current.setThumbValue(index, stateRef.current.getThumbValue(index) + delta);
229
+ } else {
230
+ let delta = isVertical ? deltaY : deltaX;
231
+ if (isVertical || reverseX) delta = -delta;
232
+ currentPosition.current += delta;
233
+ stateRef.current.setThumbPercent(index, $3pmKZ$reactariautils.clamp(currentPosition.current / size, 0, 1));
234
+ }
235
+ },
236
+ onMoveEnd () {
237
+ state.setThumbDragging(index, false);
333
238
  }
334
-
335
- currentPosition.current += delta;
336
- stateRef.current.setThumbPercent(index, clamp(currentPosition.current / size, 0, 1));
337
- }
338
- },
339
-
340
- onMoveEnd() {
341
- state.setThumbDragging(index, false);
342
- }
343
-
344
- }); // Immediately register editability with the state
345
-
346
- state.setThumbEditable(index, !isDisabled);
347
- const {
348
- focusableProps
349
- } = useFocusable(mergeProps(opts, {
350
- onFocus: () => state.setFocusedThumb(index),
351
- onBlur: () => state.setFocusedThumb(undefined)
352
- }), inputRef);
353
- let currentPointer = useRef(undefined);
354
-
355
- let onDown = id => {
356
- focusInput();
357
- currentPointer.current = id;
358
- state.setThumbDragging(index, true);
359
- addGlobalListener(window, 'mouseup', onUp, false);
360
- addGlobalListener(window, 'touchend', onUp, false);
361
- addGlobalListener(window, 'pointerup', onUp, false);
362
- };
363
-
364
- let onUp = e => {
365
- var _e$pointerId, _e$changedTouches;
366
-
367
- let id = (_e$pointerId = e.pointerId) != null ? _e$pointerId : (_e$changedTouches = e.changedTouches) == null ? void 0 : _e$changedTouches[0].identifier;
368
-
369
- if (id === currentPointer.current) {
370
- focusInput();
371
- state.setThumbDragging(index, false);
372
- removeGlobalListener(window, 'mouseup', onUp, false);
373
- removeGlobalListener(window, 'touchend', onUp, false);
374
- removeGlobalListener(window, 'pointerup', onUp, false);
375
- }
376
- }; // We install mouse handlers for the drag motion on the thumb div, but
377
- // not the key handler for moving the thumb with the slider. Instead,
378
- // we focus the range input, and let the browser handle the keyboard
379
- // interactions; we then listen to input's onChange to update state.
380
-
381
-
382
- return {
383
- inputProps: mergeProps(focusableProps, fieldProps, {
384
- type: 'range',
385
- tabIndex: !isDisabled ? 0 : undefined,
386
- min: state.getThumbMinValue(index),
387
- max: state.getThumbMaxValue(index),
388
- step: state.step,
389
- value: value,
390
- disabled: isDisabled,
391
- 'aria-orientation': opts.orientation,
392
- 'aria-valuetext': state.getThumbValueLabel(index),
393
- 'aria-required': isRequired || undefined,
394
- 'aria-invalid': validationState === 'invalid' || undefined,
395
- 'aria-errormessage': opts['aria-errormessage'],
396
- onChange: e => {
397
- state.setThumbValue(index, parseFloat(e.target.value));
398
- }
399
- }),
400
- thumbProps: !isDisabled ? mergeProps(moveProps, {
401
- onMouseDown: e => {
402
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
403
- return;
239
+ });
240
+ // Immediately register editability with the state
241
+ state.setThumbEditable(index, !isDisabled);
242
+ const { focusableProps: focusableProps } = $3pmKZ$reactariafocus.useFocusable($3pmKZ$reactariautils.mergeProps(opts, {
243
+ onFocus: ()=>state.setFocusedThumb(index)
244
+ ,
245
+ onBlur: ()=>state.setFocusedThumb(undefined)
246
+ }), inputRef);
247
+ let currentPointer = $3pmKZ$react.useRef(undefined);
248
+ let onDown = (id)=>{
249
+ focusInput();
250
+ currentPointer.current = id;
251
+ state.setThumbDragging(index, true);
252
+ addGlobalListener(window, 'mouseup', onUp, false);
253
+ addGlobalListener(window, 'touchend', onUp, false);
254
+ addGlobalListener(window, 'pointerup', onUp, false);
255
+ };
256
+ let onUp = (e)=>{
257
+ let id = e.pointerId ?? e.changedTouches?.[0].identifier;
258
+ if (id === currentPointer.current) {
259
+ focusInput();
260
+ state.setThumbDragging(index, false);
261
+ removeGlobalListener(window, 'mouseup', onUp, false);
262
+ removeGlobalListener(window, 'touchend', onUp, false);
263
+ removeGlobalListener(window, 'pointerup', onUp, false);
404
264
  }
265
+ };
266
+ // We install mouse handlers for the drag motion on the thumb div, but
267
+ // not the key handler for moving the thumb with the slider. Instead,
268
+ // we focus the range input, and let the browser handle the keyboard
269
+ // interactions; we then listen to input's onChange to update state.
270
+ return {
271
+ inputProps: $3pmKZ$reactariautils.mergeProps(focusableProps, fieldProps, {
272
+ type: 'range',
273
+ tabIndex: !isDisabled ? 0 : undefined,
274
+ min: state.getThumbMinValue(index),
275
+ max: state.getThumbMaxValue(index),
276
+ step: state.step,
277
+ value: value,
278
+ disabled: isDisabled,
279
+ 'aria-orientation': opts.orientation,
280
+ 'aria-valuetext': state.getThumbValueLabel(index),
281
+ 'aria-required': isRequired || undefined,
282
+ 'aria-invalid': validationState === 'invalid' || undefined,
283
+ 'aria-errormessage': opts['aria-errormessage'],
284
+ onChange: (e)=>{
285
+ state.setThumbValue(index, parseFloat(e.target.value));
286
+ }
287
+ }),
288
+ thumbProps: !isDisabled ? $3pmKZ$reactariautils.mergeProps(moveProps, {
289
+ onMouseDown: (e)=>{
290
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
291
+ onDown();
292
+ },
293
+ onPointerDown: (e)=>{
294
+ if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) return;
295
+ onDown(e.pointerId);
296
+ },
297
+ onTouchStart: (e)=>{
298
+ onDown(e.changedTouches[0].identifier);
299
+ }
300
+ }) : {
301
+ },
302
+ labelProps: labelProps
303
+ };
304
+ }
405
305
 
406
- onDown();
407
- },
408
- onPointerDown: e => {
409
- if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {
410
- return;
411
- }
412
306
 
413
- onDown(e.pointerId);
414
- },
415
- onTouchStart: e => {
416
- onDown(e.changedTouches[0].identifier);
417
- }
418
- }) : {},
419
- labelProps
420
- };
421
- }
307
+ $parcel$exportWildcard(module.exports, $c435846bb557c48e$exports);
308
+ $parcel$exportWildcard(module.exports, $07aa5c3f60769fb0$exports);
309
+
422
310
 
423
- exports.useSliderThumb = useSliderThumb;
424
311
  //# sourceMappingURL=main.js.map