@react-stately/slider 3.2.4-nightly.3598 → 3.2.4-nightly.3600

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
@@ -7,45 +7,63 @@ function $parcel$export(e, n, v, s) {
7
7
  }
8
8
 
9
9
  $parcel$export(module.exports, "useSliderState", () => $e86753598efd0f02$export$e5fda3247f5d67f9);
10
-
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */ /*
21
+ * Copyright 2020 Adobe. All rights reserved.
22
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
23
+ * you may not use this file except in compliance with the License. You may obtain a copy
24
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
25
+ *
26
+ * Unless required by applicable law or agreed to in writing, software distributed under
27
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
28
+ * OF ANY KIND, either express or implied. See the License for the specific language
29
+ * governing permissions and limitations under the License.
30
+ */
11
31
 
12
32
 
13
33
  const $e86753598efd0f02$var$DEFAULT_MIN_VALUE = 0;
14
34
  const $e86753598efd0f02$var$DEFAULT_MAX_VALUE = 100;
15
35
  const $e86753598efd0f02$var$DEFAULT_STEP_VALUE = 1;
16
36
  function $e86753598efd0f02$export$e5fda3247f5d67f9(props) {
17
- const { isDisabled: isDisabled = false , minValue: minValue = $e86753598efd0f02$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $e86753598efd0f02$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $e86753598efd0f02$var$DEFAULT_STEP_VALUE , orientation: orientation = 'horizontal' } = props;
37
+ const { isDisabled: isDisabled = false , minValue: minValue = $e86753598efd0f02$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $e86753598efd0f02$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $e86753598efd0f02$var$DEFAULT_STEP_VALUE , orientation: orientation = "horizontal" } = props;
18
38
  // Page step should be at least equal to step and always a multiple of the step.
19
- let pageSize = $ltQvC$react.useMemo(()=>{
39
+ let pageSize = (0, $ltQvC$react.useMemo)(()=>{
20
40
  let calcPageSize = (maxValue - minValue) / 10;
21
- calcPageSize = $ltQvC$reactariautils.snapValueToStep(calcPageSize, 0, calcPageSize + step, step);
41
+ calcPageSize = (0, $ltQvC$reactariautils.snapValueToStep)(calcPageSize, 0, calcPageSize + step, step);
22
42
  return Math.max(calcPageSize, step);
23
43
  }, [
24
44
  step,
25
45
  maxValue,
26
46
  minValue
27
47
  ]);
28
- let value1 = $ltQvC$react.useMemo(()=>$e86753598efd0f02$var$convertValue(props.value)
29
- , [
48
+ let value = (0, $ltQvC$react.useMemo)(()=>$e86753598efd0f02$var$convertValue(props.value), [
30
49
  props.value
31
50
  ]);
32
51
  var ref;
33
- let defaultValue = $ltQvC$react.useMemo(()=>(ref = $e86753598efd0f02$var$convertValue(props.defaultValue)) !== null && ref !== void 0 ? ref : [
52
+ let defaultValue = (0, $ltQvC$react.useMemo)(()=>(ref = $e86753598efd0f02$var$convertValue(props.defaultValue)) !== null && ref !== void 0 ? ref : [
34
53
  minValue
35
- ]
36
- , [
54
+ ], [
37
55
  props.defaultValue,
38
56
  minValue
39
57
  ]);
40
58
  let onChange = $e86753598efd0f02$var$createOnChange(props.value, props.defaultValue, props.onChange);
41
59
  let onChangeEnd = $e86753598efd0f02$var$createOnChange(props.value, props.defaultValue, props.onChangeEnd);
42
- const [values, setValues] = $ltQvC$reactstatelyutils.useControlledState(value1, defaultValue, onChange);
43
- const [isDraggings, setDraggings] = $ltQvC$react.useState(new Array(values.length).fill(false));
44
- const isEditablesRef = $ltQvC$react.useRef(new Array(values.length).fill(true));
45
- const [focusedIndex, setFocusedIndex] = $ltQvC$react.useState(undefined);
46
- const valuesRef = $ltQvC$react.useRef(null);
60
+ const [values, setValues] = (0, $ltQvC$reactstatelyutils.useControlledState)(value, defaultValue, onChange);
61
+ const [isDraggings, setDraggings] = (0, $ltQvC$react.useState)(new Array(values.length).fill(false));
62
+ const isEditablesRef = (0, $ltQvC$react.useRef)(new Array(values.length).fill(true));
63
+ const [focusedIndex, setFocusedIndex] = (0, $ltQvC$react.useState)(undefined);
64
+ const valuesRef = (0, $ltQvC$react.useRef)(null);
47
65
  valuesRef.current = values;
48
- const isDraggingsRef = $ltQvC$react.useRef(null);
66
+ const isDraggingsRef = (0, $ltQvC$react.useRef)(null);
49
67
  isDraggingsRef.current = isDraggings;
50
68
  function getValuePercent(value) {
51
69
  return (value - minValue) / (maxValue - minValue);
@@ -67,7 +85,7 @@ function $e86753598efd0f02$export$e5fda3247f5d67f9(props) {
67
85
  const thisMin = getThumbMinValue(index);
68
86
  const thisMax = getThumbMaxValue(index);
69
87
  // Round value to multiple of step, clamp value between min and max
70
- value = $ltQvC$reactariautils.snapValueToStep(value, thisMin, thisMax, step);
88
+ value = (0, $ltQvC$reactariautils.snapValueToStep)(value, thisMin, thisMax, step);
71
89
  valuesRef.current = $e86753598efd0f02$var$replaceIndex(valuesRef.current, index, value);
72
90
  setValues(valuesRef.current);
73
91
  }
@@ -90,32 +108,28 @@ function $e86753598efd0f02$export$e5fda3247f5d67f9(props) {
90
108
  }
91
109
  function getPercentValue(percent) {
92
110
  const val = percent * (maxValue - minValue) + minValue;
93
- return $ltQvC$reactariautils.clamp(getRoundedValue(val), minValue, maxValue);
111
+ return (0, $ltQvC$reactariautils.clamp)(getRoundedValue(val), minValue, maxValue);
94
112
  }
95
113
  function incrementThumb(index, stepSize = 1) {
96
114
  let s = Math.max(stepSize, step);
97
- updateValue(index, $ltQvC$reactariautils.snapValueToStep(values[index] + s, minValue, maxValue, step));
115
+ updateValue(index, (0, $ltQvC$reactariautils.snapValueToStep)(values[index] + s, minValue, maxValue, step));
98
116
  }
99
117
  function decrementThumb(index, stepSize = 1) {
100
118
  let s = Math.max(stepSize, step);
101
- updateValue(index, $ltQvC$reactariautils.snapValueToStep(values[index] - s, minValue, maxValue, step));
119
+ updateValue(index, (0, $ltQvC$reactariautils.snapValueToStep)(values[index] - s, minValue, maxValue, step));
102
120
  }
103
121
  return {
104
122
  values: values,
105
- getThumbValue: (index)=>values[index]
106
- ,
123
+ getThumbValue: (index)=>values[index],
107
124
  setThumbValue: updateValue,
108
125
  setThumbPercent: setThumbPercent,
109
- isThumbDragging: (index)=>isDraggings[index]
110
- ,
126
+ isThumbDragging: (index)=>isDraggings[index],
111
127
  setThumbDragging: updateDragging,
112
128
  focusedThumb: focusedIndex,
113
129
  setFocusedThumb: setFocusedIndex,
114
- getThumbPercent: (index)=>getValuePercent(values[index])
115
- ,
130
+ getThumbPercent: (index)=>getValuePercent(values[index]),
116
131
  getValuePercent: getValuePercent,
117
- getThumbValueLabel: (index)=>getFormattedValue(values[index])
118
- ,
132
+ getThumbValueLabel: (index)=>getFormattedValue(values[index]),
119
133
  getFormattedValue: getFormattedValue,
120
134
  getThumbMinValue: getThumbMinValue,
121
135
  getThumbMaxValue: getThumbMaxValue,
@@ -146,7 +160,7 @@ function $e86753598efd0f02$var$convertValue(value) {
146
160
  }
147
161
  function $e86753598efd0f02$var$createOnChange(value, defaultValue, onChange) {
148
162
  return (newValue)=>{
149
- if (typeof value === 'number' || typeof defaultValue === 'number') onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
163
+ if (typeof value === "number" || typeof defaultValue === "number") onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
150
164
  else onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
151
165
  };
152
166
  }
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;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0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;wBAChB,cAAc;wBACd,cAAc;cACd,IAAI;kBACJ,QAAQ;qBACR,WAAW;oBACX,UAAU;IACZ,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;SAEQ,kCAAY,CAAC,KAAwB,EAAE,CAAC;IAC/C,EAAE,EAAE,KAAK,IAAI,IAAI,EACf,MAAM,CAAC,SAAS;IAGlB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC;QAAA,KAAK;IAAA,CAAC;AAC/C,CAAC;SAEQ,oCAAc,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;IACtD,MAAM,EAAE,QAAkB,GAAK,CAAC;QAC9B,EAAE,EAAE,MAAM,CAAC,KAAK,KAAK,CAAQ,WAAI,MAAM,CAAC,YAAY,KAAK,CAAQ,SAC/D,QAAQ,aAAR,QAAQ,KAAR,IAAI,CAAJ,CAAuB,GAAvB,IAAI,CAAJ,CAAuB,GAAvB,QAAQ,CAAG,QAAQ,CAAC,CAAC;aAErB,QAAQ,aAAR,QAAQ,KAAR,IAAI,CAAJ,CAAoB,GAApB,IAAI,CAAJ,CAAoB,GAApB,QAAQ,CAAG,QAAQ;IAEvB,CAAC;AACH,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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} 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 {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, 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 * Increments the value of the thumb by the step or page amount.\n */\n incrementThumb(index: number, stepSize?: number): void,\n /**\n * Decrements the value of the thumb by the step or page amount.\n */\n decrementThumb(index: number, stepSize?: number): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number,\n\n /**\n * The page size for the slider, used to do a bigger step.\n */\n readonly pageSize: number,\n\n /** The orientation of the slider. */\n readonly orientation: Orientation,\n\n /** Whether the slider is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\nexport interface SliderStateOptions<T> extends SliderProps<T> {\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<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {\n const {\n isDisabled = false,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n orientation = 'horizontal'\n } = props;\n\n // Page step should be at least equal to step and always a multiple of the step.\n let pageSize = useMemo(() => {\n let calcPageSize = (maxValue - minValue) / 10;\n calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);\n return Math.max(calcPageSize, step);\n }, [step, maxValue, minValue]);\n\n let value = useMemo(() => convertValue(props.value), [props.value]);\n let defaultValue = useMemo(() => convertValue(props.defaultValue) ?? [minValue], [props.defaultValue, minValue]);\n let onChange = createOnChange(props.value, props.defaultValue, props.onChange);\n let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);\n\n const [values, setValues] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\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 (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n 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 function incrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));\n }\n\n function decrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));\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 incrementThumb,\n decrementThumb,\n step,\n pageSize,\n orientation,\n isDisabled\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\nfunction convertValue(value: number | number[]) {\n if (value == null) {\n return undefined;\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nfunction createOnChange(value, defaultValue, onChange) {\n return (newValue: number[]) => {\n if (typeof value === 'number' || typeof defaultValue === 'number') {\n onChange?.(newValue[0]);\n } else {\n onChange?.(newValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AAwIA,MAAM,0CAAoB;AAC1B,MAAM,0CAAoB;AAC1B,MAAM,2CAAqB;AAYpB,SAAS,0CAA4C,KAA4B,EAAe;IACrG,MAAM,cACJ,aAAa,KAAK,aAClB,WAAW,oDACX,WAAW,0CACX,iBAAiB,UAAS,QAC1B,OAAO,wDACP,cAAc,eACf,GAAG;IAEJ,gFAAgF;IAChF,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE,IAAM;QAC3B,IAAI,eAAe,AAAC,CAAA,WAAW,QAAO,IAAK;QAC3C,eAAe,CAAA,GAAA,qCAAc,EAAE,cAAc,GAAG,eAAe,MAAM;QACrE,OAAO,KAAK,GAAG,CAAC,cAAc;IAChC,GAAG;QAAC;QAAM;QAAU;KAAS;IAE7B,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAM,mCAAa,MAAM,KAAK,GAAG;QAAC,MAAM,KAAK;KAAC;QACjC;IAAjC,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,CAAA,MAAA,mCAAa,MAAM,YAAY,eAA/B,iBAAA,MAAoC;YAAC;SAAS,EAAE;QAAC,MAAM,YAAY;QAAE;KAAS;IAC/G,IAAI,WAAW,qCAAe,MAAM,KAAK,EAAE,MAAM,YAAY,EAAE,MAAM,QAAQ;IAC7E,IAAI,cAAc,qCAAe,MAAM,KAAK,EAAE,MAAM,YAAY,EAAE,MAAM,WAAW;IAEnF,MAAM,CAAC,QAAQ,UAAU,GAAG,CAAA,GAAA,2CAAkB,AAAD,EAC3C,OACA,cACA;IAEF,MAAM,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,qB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AAM;yBACjE;QACA,oBAAoB,CAAC,QAAkB,kBAAkB,MAAM,CAAC,MAAM;2BACtE;0BACA;0BACA;yBACA;yBACA;0BACA;wBACA;wBACA;cACA;kBACA;qBACA;oBACA;IACF;AACF;AAEA,SAAS,mCAAgB,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE;IAC5D,IAAI,KAAK,CAAC,MAAM,KAAK,OACnB,OAAO;IAGT,OAAO;WAAI,MAAM,KAAK,CAAC,GAAG;QAAQ;WAAU,MAAM,KAAK,CAAC,QAAQ;KAAG;AACrE;AAEA,SAAS,mCAAa,KAAwB,EAAE;IAC9C,IAAI,SAAS,IAAI,EACf,OAAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE;IACrD,OAAO,CAAC,WAAuB;QAC7B,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,sBAAA,KAAA,IAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,sBAAA,KAAA,IAAA,SAAW;IAEf;AACF;;CDzTC,GAED","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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} 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 {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, 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 * Increments the value of the thumb by the step or page amount.\n */\n incrementThumb(index: number, stepSize?: number): void,\n /**\n * Decrements the value of the thumb by the step or page amount.\n */\n decrementThumb(index: number, stepSize?: number): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number,\n\n /**\n * The page size for the slider, used to do a bigger step.\n */\n readonly pageSize: number,\n\n /** The orientation of the slider. */\n readonly orientation: Orientation,\n\n /** Whether the slider is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\nexport interface SliderStateOptions<T> extends SliderProps<T> {\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<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {\n const {\n isDisabled = false,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n orientation = 'horizontal'\n } = props;\n\n // Page step should be at least equal to step and always a multiple of the step.\n let pageSize = useMemo(() => {\n let calcPageSize = (maxValue - minValue) / 10;\n calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);\n return Math.max(calcPageSize, step);\n }, [step, maxValue, minValue]);\n\n let value = useMemo(() => convertValue(props.value), [props.value]);\n let defaultValue = useMemo(() => convertValue(props.defaultValue) ?? [minValue], [props.defaultValue, minValue]);\n let onChange = createOnChange(props.value, props.defaultValue, props.onChange);\n let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);\n\n const [values, setValues] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\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 (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n 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 function incrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));\n }\n\n function decrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));\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 incrementThumb,\n decrementThumb,\n step,\n pageSize,\n orientation,\n isDisabled\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\nfunction convertValue(value: number | number[]) {\n if (value == null) {\n return undefined;\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nfunction createOnChange(value, defaultValue, onChange) {\n return (newValue: number[]) => {\n if (typeof value === 'number' || typeof defaultValue === 'number') {\n onChange?.(newValue[0]);\n } else {\n onChange?.(newValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.mjs CHANGED
@@ -2,45 +2,63 @@ import {snapValueToStep as $aTwux$snapValueToStep, clamp as $aTwux$clamp} from "
2
2
  import {useControlledState as $aTwux$useControlledState} from "@react-stately/utils";
3
3
  import {useMemo as $aTwux$useMemo, useState as $aTwux$useState, useRef as $aTwux$useRef} from "react";
4
4
 
5
-
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */ /*
16
+ * Copyright 2020 Adobe. All rights reserved.
17
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License. You may obtain a copy
19
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software distributed under
22
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
23
+ * OF ANY KIND, either express or implied. See the License for the specific language
24
+ * governing permissions and limitations under the License.
25
+ */
6
26
 
7
27
 
8
28
  const $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE = 0;
9
29
  const $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE = 100;
10
30
  const $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE = 1;
11
31
  function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
12
- const { isDisabled: isDisabled = false , minValue: minValue = $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE , orientation: orientation = 'horizontal' } = props;
32
+ const { isDisabled: isDisabled = false , minValue: minValue = $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE , orientation: orientation = "horizontal" } = props;
13
33
  // Page step should be at least equal to step and always a multiple of the step.
14
- let pageSize = $aTwux$useMemo(()=>{
34
+ let pageSize = (0, $aTwux$useMemo)(()=>{
15
35
  let calcPageSize = (maxValue - minValue) / 10;
16
- calcPageSize = $aTwux$snapValueToStep(calcPageSize, 0, calcPageSize + step, step);
36
+ calcPageSize = (0, $aTwux$snapValueToStep)(calcPageSize, 0, calcPageSize + step, step);
17
37
  return Math.max(calcPageSize, step);
18
38
  }, [
19
39
  step,
20
40
  maxValue,
21
41
  minValue
22
42
  ]);
23
- let value1 = $aTwux$useMemo(()=>$28f99e3e86e6ec45$var$convertValue(props.value)
24
- , [
43
+ let value = (0, $aTwux$useMemo)(()=>$28f99e3e86e6ec45$var$convertValue(props.value), [
25
44
  props.value
26
45
  ]);
27
46
  var ref;
28
- let defaultValue = $aTwux$useMemo(()=>(ref = $28f99e3e86e6ec45$var$convertValue(props.defaultValue)) !== null && ref !== void 0 ? ref : [
47
+ let defaultValue = (0, $aTwux$useMemo)(()=>(ref = $28f99e3e86e6ec45$var$convertValue(props.defaultValue)) !== null && ref !== void 0 ? ref : [
29
48
  minValue
30
- ]
31
- , [
49
+ ], [
32
50
  props.defaultValue,
33
51
  minValue
34
52
  ]);
35
53
  let onChange = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChange);
36
54
  let onChangeEnd = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChangeEnd);
37
- const [values, setValues] = $aTwux$useControlledState(value1, defaultValue, onChange);
38
- const [isDraggings, setDraggings] = $aTwux$useState(new Array(values.length).fill(false));
39
- const isEditablesRef = $aTwux$useRef(new Array(values.length).fill(true));
40
- const [focusedIndex, setFocusedIndex] = $aTwux$useState(undefined);
41
- const valuesRef = $aTwux$useRef(null);
55
+ const [values, setValues] = (0, $aTwux$useControlledState)(value, defaultValue, onChange);
56
+ const [isDraggings, setDraggings] = (0, $aTwux$useState)(new Array(values.length).fill(false));
57
+ const isEditablesRef = (0, $aTwux$useRef)(new Array(values.length).fill(true));
58
+ const [focusedIndex, setFocusedIndex] = (0, $aTwux$useState)(undefined);
59
+ const valuesRef = (0, $aTwux$useRef)(null);
42
60
  valuesRef.current = values;
43
- const isDraggingsRef = $aTwux$useRef(null);
61
+ const isDraggingsRef = (0, $aTwux$useRef)(null);
44
62
  isDraggingsRef.current = isDraggings;
45
63
  function getValuePercent(value) {
46
64
  return (value - minValue) / (maxValue - minValue);
@@ -62,7 +80,7 @@ function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
62
80
  const thisMin = getThumbMinValue(index);
63
81
  const thisMax = getThumbMaxValue(index);
64
82
  // Round value to multiple of step, clamp value between min and max
65
- value = $aTwux$snapValueToStep(value, thisMin, thisMax, step);
83
+ value = (0, $aTwux$snapValueToStep)(value, thisMin, thisMax, step);
66
84
  valuesRef.current = $28f99e3e86e6ec45$var$replaceIndex(valuesRef.current, index, value);
67
85
  setValues(valuesRef.current);
68
86
  }
@@ -85,32 +103,28 @@ function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
85
103
  }
86
104
  function getPercentValue(percent) {
87
105
  const val = percent * (maxValue - minValue) + minValue;
88
- return $aTwux$clamp(getRoundedValue(val), minValue, maxValue);
106
+ return (0, $aTwux$clamp)(getRoundedValue(val), minValue, maxValue);
89
107
  }
90
108
  function incrementThumb(index, stepSize = 1) {
91
109
  let s = Math.max(stepSize, step);
92
- updateValue(index, $aTwux$snapValueToStep(values[index] + s, minValue, maxValue, step));
110
+ updateValue(index, (0, $aTwux$snapValueToStep)(values[index] + s, minValue, maxValue, step));
93
111
  }
94
112
  function decrementThumb(index, stepSize = 1) {
95
113
  let s = Math.max(stepSize, step);
96
- updateValue(index, $aTwux$snapValueToStep(values[index] - s, minValue, maxValue, step));
114
+ updateValue(index, (0, $aTwux$snapValueToStep)(values[index] - s, minValue, maxValue, step));
97
115
  }
98
116
  return {
99
117
  values: values,
100
- getThumbValue: (index)=>values[index]
101
- ,
118
+ getThumbValue: (index)=>values[index],
102
119
  setThumbValue: updateValue,
103
120
  setThumbPercent: setThumbPercent,
104
- isThumbDragging: (index)=>isDraggings[index]
105
- ,
121
+ isThumbDragging: (index)=>isDraggings[index],
106
122
  setThumbDragging: updateDragging,
107
123
  focusedThumb: focusedIndex,
108
124
  setFocusedThumb: setFocusedIndex,
109
- getThumbPercent: (index)=>getValuePercent(values[index])
110
- ,
125
+ getThumbPercent: (index)=>getValuePercent(values[index]),
111
126
  getValuePercent: getValuePercent,
112
- getThumbValueLabel: (index)=>getFormattedValue(values[index])
113
- ,
127
+ getThumbValueLabel: (index)=>getFormattedValue(values[index]),
114
128
  getFormattedValue: getFormattedValue,
115
129
  getThumbMinValue: getThumbMinValue,
116
130
  getThumbMaxValue: getThumbMaxValue,
@@ -141,7 +155,7 @@ function $28f99e3e86e6ec45$var$convertValue(value) {
141
155
  }
142
156
  function $28f99e3e86e6ec45$var$createOnChange(value, defaultValue, onChange) {
143
157
  return (newValue)=>{
144
- if (typeof value === 'number' || typeof defaultValue === 'number') onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
158
+ if (typeof value === "number" || typeof defaultValue === "number") onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
145
159
  else onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
146
160
  };
147
161
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;ACoJA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCAAkB,GAAG,CAAC;SAYZ,yCAAc,CAA8B,KAA4B,EAAe,CAAC;IACtG,KAAK,CAAC,CAAC,aACL,UAAU,GAAG,KAAK,aAClB,QAAQ,GAAG,uCAAiB,aAC5B,QAAQ,GAAG,uCAAiB,GAC5B,eAAe,EAAE,SAAS,SAC1B,IAAI,GAAG,wCAAkB,gBACzB,WAAW,GAAG,CAAY,aAC5B,CAAC,GAAG,KAAK;IAET,E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K,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC;SAEQ,kCAAY,CAAC,KAAwB,EAAE,CAAC;IAC/C,EAAE,EAAE,KAAK,IAAI,IAAI,EACf,MAAM,CAAC,SAAS;IAGlB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC;QAAA,KAAK;IAAA,CAAC;AAC/C,CAAC;SAEQ,oCAAc,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;IACtD,MAAM,EAAE,QAAkB,GAAK,CAAC;QAC9B,EAAE,EAAE,MAAM,CAAC,KAAK,KAAK,CAAQ,WAAI,MAAM,CAAC,YAAY,KAAK,CAAQ,SAC/D,QAAQ,aAAR,QAAQ,KAAR,IAAI,CAAJ,CAAuB,GAAvB,IAAI,CAAJ,CAAuB,GAAvB,QAAQ,CAAG,QAAQ,CAAC,CAAC;aAErB,QAAQ,aAAR,QAAQ,KAAR,IAAI,CAAJ,CAAoB,GAApB,IAAI,CAAJ,CAAoB,GAApB,QAAQ,CAAG,QAAQ;IAEvB,CAAC;AACH,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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} 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 {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, 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 * Increments the value of the thumb by the step or page amount.\n */\n incrementThumb(index: number, stepSize?: number): void,\n /**\n * Decrements the value of the thumb by the step or page amount.\n */\n decrementThumb(index: number, stepSize?: number): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number,\n\n /**\n * The page size for the slider, used to do a bigger step.\n */\n readonly pageSize: number,\n\n /** The orientation of the slider. */\n readonly orientation: Orientation,\n\n /** Whether the slider is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\nexport interface SliderStateOptions<T> extends SliderProps<T> {\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<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {\n const {\n isDisabled = false,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n orientation = 'horizontal'\n } = props;\n\n // Page step should be at least equal to step and always a multiple of the step.\n let pageSize = useMemo(() => {\n let calcPageSize = (maxValue - minValue) / 10;\n calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);\n return Math.max(calcPageSize, step);\n }, [step, maxValue, minValue]);\n\n let value = useMemo(() => convertValue(props.value), [props.value]);\n let defaultValue = useMemo(() => convertValue(props.defaultValue) ?? [minValue], [props.defaultValue, minValue]);\n let onChange = createOnChange(props.value, props.defaultValue, props.onChange);\n let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);\n\n const [values, setValues] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\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 (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n 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 function incrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));\n }\n\n function decrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));\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 incrementThumb,\n decrementThumb,\n step,\n pageSize,\n orientation,\n isDisabled\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\nfunction convertValue(value: number | number[]) {\n if (value == null) {\n return undefined;\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nfunction createOnChange(value, defaultValue, onChange) {\n return (newValue: number[]) => {\n if (typeof value === 'number' || typeof defaultValue === 'number') {\n onChange?.(newValue[0]);\n } else {\n onChange?.(newValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AAwIA,MAAM,0CAAoB;AAC1B,MAAM,0CAAoB;AAC1B,MAAM,2CAAqB;AAYpB,SAAS,0CAA4C,KAA4B,EAAe;IACrG,MAAM,cACJ,aAAa,KAAK,aAClB,WAAW,oDACX,WAAW,0CACX,iBAAiB,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AAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE;IACrD,OAAO,CAAC,WAAuB;QAC7B,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,sBAAA,KAAA,IAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,sBAAA,KAAA,IAAA,SAAW;IAEf;AACF;;CDzTC,GAED","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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} 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 {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, 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 * Increments the value of the thumb by the step or page amount.\n */\n incrementThumb(index: number, stepSize?: number): void,\n /**\n * Decrements the value of the thumb by the step or page amount.\n */\n decrementThumb(index: number, stepSize?: number): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number,\n\n /**\n * The page size for the slider, used to do a bigger step.\n */\n readonly pageSize: number,\n\n /** The orientation of the slider. */\n readonly orientation: Orientation,\n\n /** Whether the slider is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\nexport interface SliderStateOptions<T> extends SliderProps<T> {\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<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {\n const {\n isDisabled = false,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n orientation = 'horizontal'\n } = props;\n\n // Page step should be at least equal to step and always a multiple of the step.\n let pageSize = useMemo(() => {\n let calcPageSize = (maxValue - minValue) / 10;\n calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);\n return Math.max(calcPageSize, step);\n }, [step, maxValue, minValue]);\n\n let value = useMemo(() => convertValue(props.value), [props.value]);\n let defaultValue = useMemo(() => convertValue(props.defaultValue) ?? [minValue], [props.defaultValue, minValue]);\n let onChange = createOnChange(props.value, props.defaultValue, props.onChange);\n let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);\n\n const [values, setValues] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\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 (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n 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 function incrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));\n }\n\n function decrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));\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 incrementThumb,\n decrementThumb,\n step,\n pageSize,\n orientation,\n isDisabled\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\nfunction convertValue(value: number | number[]) {\n if (value == null) {\n return undefined;\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nfunction createOnChange(value, defaultValue, onChange) {\n return (newValue: number[]) => {\n if (typeof value === 'number' || typeof defaultValue === 'number') {\n onChange?.(newValue[0]);\n } else {\n onChange?.(newValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/slider",
3
- "version": "3.2.4-nightly.3598+810579b67",
3
+ "version": "3.2.4-nightly.3600+bfce84fee",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,12 +22,12 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@babel/runtime": "^7.6.2",
26
- "@react-aria/i18n": "3.0.0-nightly.1898+810579b67",
27
- "@react-aria/utils": "3.0.0-nightly.1898+810579b67",
28
- "@react-stately/utils": "3.0.0-nightly.1898+810579b67",
29
- "@react-types/shared": "3.0.0-nightly.1898+810579b67",
30
- "@react-types/slider": "3.3.2-nightly.3598+810579b67"
25
+ "@react-aria/i18n": "3.0.0-nightly.1900+bfce84fee",
26
+ "@react-aria/utils": "3.0.0-nightly.1900+bfce84fee",
27
+ "@react-stately/utils": "3.0.0-nightly.1900+bfce84fee",
28
+ "@react-types/shared": "3.0.0-nightly.1900+bfce84fee",
29
+ "@react-types/slider": "3.3.2-nightly.3600+bfce84fee",
30
+ "@swc/helpers": "^0.4.14"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "810579b671791f1593108f62cdc1893de3a220e3"
38
+ "gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169"
39
39
  }