@react-stately/slider 3.0.5-nightly.3111 → 3.0.5
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 +23 -22
- package/dist/main.js.map +1 -1
- package/dist/module.js +23 -22
- package/dist/module.js.map +1 -1
- package/package.json +6 -6
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
1
|
+
var $m1uKO$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $m1uKO$reactstatelyutils = require("@react-stately/utils");
|
|
3
|
+
var $m1uKO$react = require("react");
|
|
4
4
|
|
|
5
5
|
function $parcel$exportWildcard(dest, source) {
|
|
6
6
|
Object.keys(source).forEach(function(key) {
|
|
@@ -21,26 +21,27 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
21
21
|
function $parcel$export(e, n, v, s) {
|
|
22
22
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
23
23
|
}
|
|
24
|
-
var $
|
|
24
|
+
var $37396301f90211cc$exports = {};
|
|
25
25
|
|
|
26
|
-
$parcel$export($
|
|
26
|
+
$parcel$export($37396301f90211cc$exports, "useSliderState", () => $37396301f90211cc$export$e5fda3247f5d67f9);
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
const $
|
|
31
|
-
const $
|
|
32
|
-
const $
|
|
33
|
-
function $
|
|
34
|
-
const { isDisabled: isDisabled , minValue: minValue = $
|
|
35
|
-
|
|
30
|
+
const $37396301f90211cc$var$DEFAULT_MIN_VALUE = 0;
|
|
31
|
+
const $37396301f90211cc$var$DEFAULT_MAX_VALUE = 100;
|
|
32
|
+
const $37396301f90211cc$var$DEFAULT_STEP_VALUE = 1;
|
|
33
|
+
function $37396301f90211cc$export$e5fda3247f5d67f9(props) {
|
|
34
|
+
const { isDisabled: isDisabled , minValue: minValue = $37396301f90211cc$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $37396301f90211cc$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $37396301f90211cc$var$DEFAULT_STEP_VALUE } = props;
|
|
35
|
+
var _defaultValue;
|
|
36
|
+
const [values, setValues] = $m1uKO$reactstatelyutils.useControlledState(props.value, (_defaultValue = props.defaultValue) !== null && _defaultValue !== void 0 ? _defaultValue : [
|
|
36
37
|
minValue
|
|
37
38
|
], props.onChange);
|
|
38
|
-
const [isDraggings, setDraggings] = $
|
|
39
|
-
const isEditablesRef = $
|
|
40
|
-
const [focusedIndex, setFocusedIndex] = $
|
|
41
|
-
const valuesRef = $
|
|
39
|
+
const [isDraggings, setDraggings] = $m1uKO$react.useState(new Array(values.length).fill(false));
|
|
40
|
+
const isEditablesRef = $m1uKO$react.useRef(new Array(values.length).fill(true));
|
|
41
|
+
const [focusedIndex, setFocusedIndex] = $m1uKO$react.useState(undefined);
|
|
42
|
+
const valuesRef = $m1uKO$react.useRef(null);
|
|
42
43
|
valuesRef.current = values;
|
|
43
|
-
const isDraggingsRef = $
|
|
44
|
+
const isDraggingsRef = $m1uKO$react.useRef(null);
|
|
44
45
|
isDraggingsRef.current = isDraggings;
|
|
45
46
|
function getValuePercent(value) {
|
|
46
47
|
return (value - minValue) / (maxValue - minValue);
|
|
@@ -62,14 +63,14 @@ function $16a7c389e53c069a$export$e5fda3247f5d67f9(props) {
|
|
|
62
63
|
const thisMin = getThumbMinValue(index);
|
|
63
64
|
const thisMax = getThumbMaxValue(index);
|
|
64
65
|
// Round value to multiple of step, clamp value between min and max
|
|
65
|
-
value = $
|
|
66
|
-
valuesRef.current = $
|
|
66
|
+
value = $m1uKO$reactariautils.snapValueToStep(value, thisMin, thisMax, step);
|
|
67
|
+
valuesRef.current = $37396301f90211cc$var$replaceIndex(valuesRef.current, index, value);
|
|
67
68
|
setValues(valuesRef.current);
|
|
68
69
|
}
|
|
69
70
|
function updateDragging(index, dragging) {
|
|
70
71
|
if (isDisabled || !isThumbEditable(index)) return;
|
|
71
72
|
const wasDragging = isDraggingsRef.current[index];
|
|
72
|
-
isDraggingsRef.current = $
|
|
73
|
+
isDraggingsRef.current = $37396301f90211cc$var$replaceIndex(isDraggingsRef.current, index, dragging);
|
|
73
74
|
setDraggings(isDraggingsRef.current);
|
|
74
75
|
// Call onChangeEnd if no handles are dragging.
|
|
75
76
|
if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) props.onChangeEnd(valuesRef.current);
|
|
@@ -85,7 +86,7 @@ function $16a7c389e53c069a$export$e5fda3247f5d67f9(props) {
|
|
|
85
86
|
}
|
|
86
87
|
function getPercentValue(percent) {
|
|
87
88
|
const val = percent * (maxValue - minValue) + minValue;
|
|
88
|
-
return $
|
|
89
|
+
return $m1uKO$reactariautils.clamp(getRoundedValue(val), minValue, maxValue);
|
|
89
90
|
}
|
|
90
91
|
return {
|
|
91
92
|
values: values,
|
|
@@ -112,7 +113,7 @@ function $16a7c389e53c069a$export$e5fda3247f5d67f9(props) {
|
|
|
112
113
|
step: step
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
|
-
function $
|
|
116
|
+
function $37396301f90211cc$var$replaceIndex(array, index, value) {
|
|
116
117
|
if (array[index] === value) return array;
|
|
117
118
|
return [
|
|
118
119
|
...array.slice(0, index),
|
|
@@ -122,7 +123,7 @@ function $16a7c389e53c069a$var$replaceIndex(array, index, value) {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
|
|
125
|
-
$parcel$exportWildcard(module.exports, $
|
|
126
|
+
$parcel$exportWildcard(module.exports, $37396301f90211cc$exports);
|
|
126
127
|
|
|
127
128
|
|
|
128
129
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC+HA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,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AAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, numberFormatter: formatter, step = DEFAULT_STEP_VALUE} = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n step\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC+HA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCAAkB,GAAG,CAAC;SAYZ,yCAAc,CAAC,KAAyB,EAAe,CAAC;IACtE,KAAK,CAAC,CAAC,aAAA,UAAU,aAAE,QAAQ,GAAG,uCAAiB,aAAE,QAAQ,GAAG,uCAAiB,GAAE,eAAe,EAAE,SAAS,SAAE,IAAI,GAAG,wCAAkB,EAAA,CAAC,GAAG,KAAK;QAI3I,aAAkB;IAFpB,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,2CAAkB,CAC5C,KAAK,CAAC,KAAK,GACX,aAAkB,GAAlB,KAAK,CAAC,YAAY,cAAlB,aAAkB,cAAlB,aAAkB,GAAI,CAAC;QAAA,QAAQ;IAAA,CAAC,EAChC,KAAK,CAAC,QAAQ;IAEhB,KAAK,EAAE,WAAW,EAAE,YAAY,IAAI,qBAAQ,CAAY,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK;IAC3F,KAAK,CAAC,cAAc,GAAG,mBAAM,CAAY,GAAG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QACd,aAAa,GAAG,KAAa,GAAK,MAAM,CAAC,KAAK;;QAC9C,aAAa,EAAE,WAAW;yBAC1B,eAAe;QACf,eAAe,GAAG,KAAa,GAAK,WAAW,CAAC,KAAK;;QACrD,gBAAgB,EAAE,cAAc;QAChC,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,eAAe;QAChC,eAAe,GAAG,KAAa,GAAK,eAAe,CAAC,MAAM,CAAC,KAAK;;yBAChE,eAAe;QACf,kBAAkB,GAAG,KAAa,GAAK,iBAAiB,CAAC,MAAM,CAAC,KAAK;;2BACrE,iBAAiB;0BACjB,gBAAgB;0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;cAChB,IAAI;IACN,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, numberFormatter: formatter, step = DEFAULT_STEP_VALUE} = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n step\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import {snapValueToStep as $
|
|
2
|
-
import {useControlledState as $
|
|
3
|
-
import {useState as $
|
|
1
|
+
import {snapValueToStep as $drHW0$snapValueToStep, clamp as $drHW0$clamp} from "@react-aria/utils";
|
|
2
|
+
import {useControlledState as $drHW0$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useState as $drHW0$useState, useRef as $drHW0$useRef} from "react";
|
|
4
4
|
|
|
5
5
|
function $parcel$export(e, n, v, s) {
|
|
6
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
7
|
}
|
|
8
|
-
var $
|
|
8
|
+
var $8f011f344c0ccbcc$exports = {};
|
|
9
9
|
|
|
10
|
-
$parcel$export($
|
|
10
|
+
$parcel$export($8f011f344c0ccbcc$exports, "useSliderState", () => $8f011f344c0ccbcc$export$e5fda3247f5d67f9);
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
const $
|
|
15
|
-
const $
|
|
16
|
-
const $
|
|
17
|
-
function $
|
|
18
|
-
const { isDisabled: isDisabled , minValue: minValue = $
|
|
19
|
-
|
|
14
|
+
const $8f011f344c0ccbcc$var$DEFAULT_MIN_VALUE = 0;
|
|
15
|
+
const $8f011f344c0ccbcc$var$DEFAULT_MAX_VALUE = 100;
|
|
16
|
+
const $8f011f344c0ccbcc$var$DEFAULT_STEP_VALUE = 1;
|
|
17
|
+
function $8f011f344c0ccbcc$export$e5fda3247f5d67f9(props) {
|
|
18
|
+
const { isDisabled: isDisabled , minValue: minValue = $8f011f344c0ccbcc$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $8f011f344c0ccbcc$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $8f011f344c0ccbcc$var$DEFAULT_STEP_VALUE } = props;
|
|
19
|
+
var _defaultValue;
|
|
20
|
+
const [values, setValues] = $drHW0$useControlledState(props.value, (_defaultValue = props.defaultValue) !== null && _defaultValue !== void 0 ? _defaultValue : [
|
|
20
21
|
minValue
|
|
21
22
|
], props.onChange);
|
|
22
|
-
const [isDraggings, setDraggings] = $
|
|
23
|
-
const isEditablesRef = $
|
|
24
|
-
const [focusedIndex, setFocusedIndex] = $
|
|
25
|
-
const valuesRef = $
|
|
23
|
+
const [isDraggings, setDraggings] = $drHW0$useState(new Array(values.length).fill(false));
|
|
24
|
+
const isEditablesRef = $drHW0$useRef(new Array(values.length).fill(true));
|
|
25
|
+
const [focusedIndex, setFocusedIndex] = $drHW0$useState(undefined);
|
|
26
|
+
const valuesRef = $drHW0$useRef(null);
|
|
26
27
|
valuesRef.current = values;
|
|
27
|
-
const isDraggingsRef = $
|
|
28
|
+
const isDraggingsRef = $drHW0$useRef(null);
|
|
28
29
|
isDraggingsRef.current = isDraggings;
|
|
29
30
|
function getValuePercent(value) {
|
|
30
31
|
return (value - minValue) / (maxValue - minValue);
|
|
@@ -46,14 +47,14 @@ function $41e91674a959b70c$export$e5fda3247f5d67f9(props) {
|
|
|
46
47
|
const thisMin = getThumbMinValue(index);
|
|
47
48
|
const thisMax = getThumbMaxValue(index);
|
|
48
49
|
// Round value to multiple of step, clamp value between min and max
|
|
49
|
-
value = $
|
|
50
|
-
valuesRef.current = $
|
|
50
|
+
value = $drHW0$snapValueToStep(value, thisMin, thisMax, step);
|
|
51
|
+
valuesRef.current = $8f011f344c0ccbcc$var$replaceIndex(valuesRef.current, index, value);
|
|
51
52
|
setValues(valuesRef.current);
|
|
52
53
|
}
|
|
53
54
|
function updateDragging(index, dragging) {
|
|
54
55
|
if (isDisabled || !isThumbEditable(index)) return;
|
|
55
56
|
const wasDragging = isDraggingsRef.current[index];
|
|
56
|
-
isDraggingsRef.current = $
|
|
57
|
+
isDraggingsRef.current = $8f011f344c0ccbcc$var$replaceIndex(isDraggingsRef.current, index, dragging);
|
|
57
58
|
setDraggings(isDraggingsRef.current);
|
|
58
59
|
// Call onChangeEnd if no handles are dragging.
|
|
59
60
|
if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) props.onChangeEnd(valuesRef.current);
|
|
@@ -69,7 +70,7 @@ function $41e91674a959b70c$export$e5fda3247f5d67f9(props) {
|
|
|
69
70
|
}
|
|
70
71
|
function getPercentValue(percent) {
|
|
71
72
|
const val = percent * (maxValue - minValue) + minValue;
|
|
72
|
-
return $
|
|
73
|
+
return $drHW0$clamp(getRoundedValue(val), minValue, maxValue);
|
|
73
74
|
}
|
|
74
75
|
return {
|
|
75
76
|
values: values,
|
|
@@ -96,7 +97,7 @@ function $41e91674a959b70c$export$e5fda3247f5d67f9(props) {
|
|
|
96
97
|
step: step
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
|
-
function $
|
|
100
|
+
function $8f011f344c0ccbcc$var$replaceIndex(array, index, value) {
|
|
100
101
|
if (array[index] === value) return array;
|
|
101
102
|
return [
|
|
102
103
|
...array.slice(0, index),
|
|
@@ -108,5 +109,5 @@ function $41e91674a959b70c$var$replaceIndex(array, index, value) {
|
|
|
108
109
|
|
|
109
110
|
|
|
110
111
|
|
|
111
|
-
export {$
|
|
112
|
+
export {$8f011f344c0ccbcc$export$e5fda3247f5d67f9 as useSliderState};
|
|
112
113
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AC+HA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCAAkB,GAAG,CAAC;SAYZ,yCAAc,CAAC,KAAyB,EAAe,CAAC;IACtE,KAAK,CAAC,CAAC,aAAA,UAAU,aAAE,QAAQ,GAAG,uCAAiB,aAAE,QAAQ,GAAG,uCAAiB,GAAE,eAAe,EAAE,SAAS,SAAE,IAAI,GAAG,wCAAkB,EAAA,CAAC,GAAG,KAAK;IAE7I,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,yBAAkB,CAC5C,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,YAAY,IAAI,CAAC;QAAA,QAAQ;IAAA,CAAC,EAChC,KAAK,CAAC,QAAQ;IAEhB,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GAAG,QAAQ,IAAI,QAAQ;QACtD,MAAM,CAAC,YAAK,CAAC,eAAe,CAAC,GAAG,GAAG,QAAQ,EAAE,QAAQ;IACvD,CAAC;IAED,MAAM,CAAC,CAAC;QACN,MAAM,EAAE,MAAM;QACd,aAAa,GAAG,KAAa,GAAK,MAAM,CAAC,KAAK;;QAC9C,aAAa,EAAE,WAAW;yBAC1B,eAAe;QACf,eAAe,GAAG,KAAa,GAAK,WAAW,CAAC,KAAK;;QACrD,gBAAgB,EAAE,cAAc;QAChC,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,eAAe;QAChC,eAAe,GAAG,KAAa,GAAK,eAAe,CAAC,MAAM,CAAC,KAAK;;yBAChE,eAAe;QACf,kBAAkB,GAAG,KAAa,GAAK,iBAAiB,CAAC,MAAM,CAAC,KAAK;;2BACrE,iBAAiB;0BACjB,gBAAgB;0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;cAChB,IAAI;IACN,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, numberFormatter: formatter, step = DEFAULT_STEP_VALUE} = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n step\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value,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B;cAChB,IAAI;IACN,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, numberFormatter: formatter, step = DEFAULT_STEP_VALUE} = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n step\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/slider",
|
|
3
|
-
"version": "3.0.5
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/i18n": "3.
|
|
22
|
-
"@react-aria/utils": "3.
|
|
23
|
-
"@react-stately/utils": "3.
|
|
24
|
-
"@react-types/slider": "3.0.4
|
|
21
|
+
"@react-aria/i18n": "^3.3.6",
|
|
22
|
+
"@react-aria/utils": "^3.11.2",
|
|
23
|
+
"@react-stately/utils": "^3.4.1",
|
|
24
|
+
"@react-types/slider": "^3.0.4"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937"
|
|
33
33
|
}
|