@react-stately/slider 3.5.1-nightly.4411 → 3.5.1-nightly.4420

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/import.mjs CHANGED
@@ -101,6 +101,7 @@ function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
101
101
  }
102
102
  function updateDragging(index, dragging) {
103
103
  if (isDisabled || !isThumbEditable(index)) return;
104
+ if (dragging) valuesRef.current = values;
104
105
  const wasDragging = isDraggingsRef.current[index];
105
106
  isDraggingsRef.current = $28f99e3e86e6ec45$var$replaceIndex(isDraggingsRef.current, index, dragging);
106
107
  setDraggings(isDraggingsRef.current);
package/dist/main.js CHANGED
@@ -107,6 +107,7 @@ function $e86753598efd0f02$export$e5fda3247f5d67f9(props) {
107
107
  }
108
108
  function updateDragging(index, dragging) {
109
109
  if (isDisabled || !isThumbEditable(index)) return;
110
+ if (dragging) valuesRef.current = values;
110
111
  const wasDragging = isDraggingsRef.current[index];
111
112
  isDraggingsRef.current = $e86753598efd0f02$var$replaceIndex(isDraggingsRef.current, index, dragging);
112
113
  setDraggings(isDraggingsRef.current);
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AAyID,MAAM,0CAAoB;AAC1B,MAAM,0CAAoB;AAC1B,MAAM,2CAAqB;AAYpB,SAAS,0CAA4C,KAA4B;IACtF,MAAM,cACJ,aAAa,iBACb,WAAW,mDACX,WAAW,yCACX,iBAAiB,SAAS,QAC1B,OAAO,uDACP,cAAc,cACf,GAAG;IAEJ,gFAAgF;IAChF,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE;QACrB,IAAI,eAAe,AAAC,CAAA,WAAW,QAAO,IAAK;QAC3C,eAAe,CAAA,GAAA,wCAAc,EAAE,cAAc,GAAG,eAAe,MAAM;QACrE,OAAO,KAAK,GAAG,CAAC,cAAc;IAChC,GAAG;QAAC;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,SAAS,MACX,OAAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ;IACnD,OAAO,CAAC;QACN,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,+BAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,+BAAA,SAAW;IAEf;AACF;;CDrUC","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, useControlledState} from '@react-stately/utils';\nimport {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useCallback, 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 restrictValues = useCallback((values: number[]) => values?.map((val, idx) => {\n let min = idx === 0 ? minValue : val[idx - 1];\n let max = idx === values.length - 1 ? maxValue : val[idx + 1];\n return snapValueToStep(val, min, max, step);\n }), [minValue, maxValue, step]);\n\n let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value]);\n let defaultValue = useMemo(() => restrictValues(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, setValuesState] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\n );\n const [isDraggings, setDraggingsState] = 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[]>(values);\n const isDraggingsRef = useRef<boolean[]>(isDraggings);\n let setValues = (values: number[]) => {\n valuesRef.current = values;\n setValuesState(values);\n };\n\n let setDraggings = (draggings: boolean[]) => {\n isDraggingsRef.current = draggings;\n setDraggingsState(draggings);\n };\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 let newValues = replaceIndex(valuesRef.current, index, value);\n setValues(newValues);\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;;AAyID,MAAM,0CAAoB;AAC1B,MAAM,0CAAoB;AAC1B,MAAM,2CAAqB;AAYpB,SAAS,0CAA4C,KAA4B;IACtF,MAAM,cACJ,aAAa,iBACb,WAAW,mDACX,WAAW,yCACX,iBAAiB,SAAS,QAC1B,OAAO,uDACP,cAAc,cACf,GAAG;IAEJ,gFAAgF;IAChF,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE;QACrB,IAAI,eAAe,AAAC,CAAA,WAAW,QAAO,IAAK;QAC3C,eAAe,CAAA,GAAA,wCAAc,EAAE,cAAc,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M,KAAK,CAAC,GAAG;QAAQ;WAAU,MAAM,KAAK,CAAC,QAAQ;KAAG;AACrE;AAEA,SAAS,mCAAa,KAAwB;IAC5C,IAAI,SAAS,MACX,OAAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ;IACnD,OAAO,CAAC;QACN,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,+BAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,+BAAA,SAAW;IAEf;AACF;;CDzUC","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, useControlledState} from '@react-stately/utils';\nimport {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useCallback, 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 restrictValues = useCallback((values: number[]) => values?.map((val, idx) => {\n let min = idx === 0 ? minValue : val[idx - 1];\n let max = idx === values.length - 1 ? maxValue : val[idx + 1];\n return snapValueToStep(val, min, max, step);\n }), [minValue, maxValue, step]);\n\n let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value]);\n let defaultValue = useMemo(() => restrictValues(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, setValuesState] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\n );\n const [isDraggings, setDraggingsState] = 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[]>(values);\n const isDraggingsRef = useRef<boolean[]>(isDraggings);\n\n let setValues = (values: number[]) => {\n valuesRef.current = values;\n setValuesState(values);\n };\n\n let setDraggings = (draggings: boolean[]) => {\n isDraggingsRef.current = draggings;\n setDraggingsState(draggings);\n };\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 let newValues = replaceIndex(valuesRef.current, index, value);\n setValues(newValues);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n if (dragging) {\n valuesRef.current = values;\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.js CHANGED
@@ -101,6 +101,7 @@ function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
101
101
  }
102
102
  function updateDragging(index, dragging) {
103
103
  if (isDisabled || !isThumbEditable(index)) return;
104
+ if (dragging) valuesRef.current = values;
104
105
  const wasDragging = isDraggingsRef.current[index];
105
106
  isDraggingsRef.current = $28f99e3e86e6ec45$var$replaceIndex(isDraggingsRef.current, index, dragging);
106
107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AiB,CAAC,QAAkB,WAAW,CAAC,MAAM;QACtD,kBAAkB;QAClB,cAAc;QACd,iBAAiB;QACjB,iBAAiB,CAAC,QAAkB,gBAAgB,MAAM,CAAC,MAAM;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;IAC1D,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;IAC5C,IAAI,SAAS,MACX,OAAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ;IACnD,OAAO,CAAC;QACN,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,+BAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,+BAAA,SAAW;IAEf;AACF;;CDrUC","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, useControlledState} from '@react-stately/utils';\nimport {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useCallback, 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 restrictValues = useCallback((values: number[]) => values?.map((val, idx) => {\n let min = idx === 0 ? minValue : val[idx - 1];\n let max = idx === values.length - 1 ? maxValue : val[idx + 1];\n return snapValueToStep(val, min, max, step);\n }), [minValue, maxValue, step]);\n\n let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value]);\n let defaultValue = useMemo(() => restrictValues(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, setValuesState] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\n );\n const [isDraggings, setDraggingsState] = 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[]>(values);\n const isDraggingsRef = useRef<boolean[]>(isDraggings);\n let setValues = (values: number[]) => {\n valuesRef.current = values;\n setValuesState(values);\n };\n\n let setDraggings = (draggings: boolean[]) => {\n isDraggingsRef.current = draggings;\n setDraggingsState(draggings);\n };\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 let newValues = replaceIndex(valuesRef.current, index, value);\n setValues(newValues);\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 defa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EA,OAAO;QACL,QAAQ;QACR,eAAe,CAAC,QAAkB,MAAM,CAAC,MAAM;QAC/C,eAAe;yBACf;QACA,iBAAiB,CAAC,QAAkB,WAAW,CAAC,MAAM;QACtD,kBAAkB;QAClB,cAAc;QACd,iBAAiB;QACjB,iBAAiB,CAAC,QAAkB,gBAAgB,MAAM,CAAC,MAAM;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;IAC1D,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;IAC5C,IAAI,SAAS,MACX,OAAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ;IACnD,OAAO,CAAC;QACN,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,+BAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,+BAAA,SAAW;IAEf;AACF;;CDzUC","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, useControlledState} from '@react-stately/utils';\nimport {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useCallback, 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 restrictValues = useCallback((values: number[]) => values?.map((val, idx) => {\n let min = idx === 0 ? minValue : val[idx - 1];\n let max = idx === values.length - 1 ? maxValue : val[idx + 1];\n return snapValueToStep(val, min, max, step);\n }), [minValue, maxValue, step]);\n\n let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value]);\n let defaultValue = useMemo(() => restrictValues(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, setValuesState] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\n );\n const [isDraggings, setDraggingsState] = 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[]>(values);\n const isDraggingsRef = useRef<boolean[]>(isDraggings);\n\n let setValues = (values: number[]) => {\n valuesRef.current = values;\n setValuesState(values);\n };\n\n let setDraggings = (draggings: boolean[]) => {\n isDraggingsRef.current = draggings;\n setDraggingsState(draggings);\n };\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 let newValues = replaceIndex(valuesRef.current, index, value);\n setValues(newValues);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n if (dragging) {\n valuesRef.current = values;\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.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;AAiBA;IACE;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAErC;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAElD;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAEjD;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvC;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvC;;;OAGG;IACH,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1C;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAExC;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAExC;;;OAGG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAExC;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,qCAAqC;IACrC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAElC,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC7B;AAMD,oCAAoC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC;IAC3D,eAAe,EAAE,KAAK,YAAY,CAAA;CACnC;AAED;;;;;GAKG;AACH,+BAA+B,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,GAAG,WAAW,CAoJrG","sources":["packages/@react-stately/slider/src/packages/@react-stately/slider/src/useSliderState.ts","packages/@react-stately/slider/src/packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/index.ts"],"sourcesContent":[null,null,"/*\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"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAiBA;IACE;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAErC;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAElD;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAEjD;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvC;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvC;;;OAGG;IACH,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1C;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAExC;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAExC;;;OAGG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAExC;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,qCAAqC;IACrC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAElC,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC7B;AAMD,oCAAoC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC;IAC3D,eAAe,EAAE,KAAK,YAAY,CAAA;CACnC;AAED;;;;;GAKG;AACH,+BAA+B,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,GAAG,WAAW,CAwJrG","sources":["packages/@react-stately/slider/src/packages/@react-stately/slider/src/useSliderState.ts","packages/@react-stately/slider/src/packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/index.ts"],"sourcesContent":[null,null,"/*\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"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/slider",
3
- "version": "3.5.1-nightly.4411+ee51290b9",
3
+ "version": "3.5.1-nightly.4420+46ae3314a",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,9 +22,9 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/utils": "3.0.0-nightly.2699+ee51290b9",
26
- "@react-types/shared": "3.0.0-nightly.2699+ee51290b9",
27
- "@react-types/slider": "3.7.1-nightly.4411+ee51290b9",
25
+ "@react-stately/utils": "3.0.0-nightly.2708+46ae3314a",
26
+ "@react-types/shared": "3.0.0-nightly.2708+46ae3314a",
27
+ "@react-types/slider": "3.7.1-nightly.4420+46ae3314a",
28
28
  "@swc/helpers": "^0.5.0"
29
29
  },
30
30
  "peerDependencies": {
@@ -33,5 +33,5 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "ee51290b98fdc7cad31957ed2dd0a486eb0c1427"
36
+ "gitHead": "46ae3314a2e2c1ab856c82c8d9dc941e8c70016e"
37
37
  }
@@ -198,6 +198,7 @@ export function useSliderState<T extends number | number[]>(props: SliderStateOp
198
198
 
199
199
  const valuesRef = useRef<number[]>(values);
200
200
  const isDraggingsRef = useRef<boolean[]>(isDraggings);
201
+
201
202
  let setValues = (values: number[]) => {
202
203
  valuesRef.current = values;
203
204
  setValuesState(values);
@@ -244,6 +245,9 @@ export function useSliderState<T extends number | number[]>(props: SliderStateOp
244
245
  if (isDisabled || !isThumbEditable(index)) {
245
246
  return;
246
247
  }
248
+ if (dragging) {
249
+ valuesRef.current = values;
250
+ }
247
251
 
248
252
  const wasDragging = isDraggingsRef.current[index];
249
253
  isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);