rc-slider
Advanced tools
Comparing version 10.1.0 to 10.1.1
@@ -13,27 +13,24 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
var _classNames, _getIndex; | ||
var prefixCls = props.prefixCls, | ||
value = props.value, | ||
valueIndex = props.valueIndex, | ||
onStartMove = props.onStartMove, | ||
style = props.style, | ||
render = props.render, | ||
dragging = props.dragging, | ||
onOffsetChange = props.onOffsetChange, | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
value = props.value, | ||
valueIndex = props.valueIndex, | ||
onStartMove = props.onStartMove, | ||
style = props.style, | ||
render = props.render, | ||
dragging = props.dragging, | ||
onOffsetChange = props.onOffsetChange, | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
var _React$useContext = React.useContext(SliderContext), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
disabled = _React$useContext.disabled, | ||
keyboard = _React$useContext.keyboard, | ||
range = _React$useContext.range, | ||
tabIndex = _React$useContext.tabIndex, | ||
ariaLabelForHandle = _React$useContext.ariaLabelForHandle, | ||
ariaLabelledByForHandle = _React$useContext.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = _React$useContext.ariaValueTextFormatterForHandle; | ||
var handlePrefixCls = "".concat(prefixCls, "-handle"); // ============================ Events ============================ | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
disabled = _React$useContext.disabled, | ||
keyboard = _React$useContext.keyboard, | ||
range = _React$useContext.range, | ||
tabIndex = _React$useContext.tabIndex, | ||
ariaLabelForHandle = _React$useContext.ariaLabelForHandle, | ||
ariaLabelledByForHandle = _React$useContext.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = _React$useContext.ariaValueTextFormatterForHandle; | ||
var handlePrefixCls = "".concat(prefixCls, "-handle"); | ||
// ============================ Events ============================ | ||
var onInternalStartMove = function onInternalStartMove(e) { | ||
@@ -43,9 +40,8 @@ if (!disabled) { | ||
} | ||
}; // =========================== Keyboard =========================== | ||
}; | ||
// =========================== Keyboard =========================== | ||
var onKeyDown = function onKeyDown(e) { | ||
if (!disabled && keyboard) { | ||
var offset = null; // Change the value | ||
var offset = null; | ||
// Change the value | ||
switch (e.which || e.keyCode) { | ||
@@ -55,3 +51,2 @@ case KeyCode.LEFT: | ||
break; | ||
case KeyCode.RIGHT: | ||
@@ -61,3 +56,2 @@ offset = direction === 'ltr' || direction === 'btt' ? 1 : -1; | ||
// Up is plus | ||
case KeyCode.UP: | ||
@@ -67,19 +61,14 @@ offset = direction !== 'ttb' ? 1 : -1; | ||
// Down is minus | ||
case KeyCode.DOWN: | ||
offset = direction !== 'ttb' ? -1 : 1; | ||
break; | ||
case KeyCode.HOME: | ||
offset = 'min'; | ||
break; | ||
case KeyCode.END: | ||
offset = 'max'; | ||
break; | ||
case KeyCode.PAGE_UP: | ||
offset = 2; | ||
break; | ||
case KeyCode.PAGE_DOWN: | ||
@@ -89,3 +78,2 @@ offset = -2; | ||
} | ||
if (offset !== null) { | ||
@@ -96,7 +84,6 @@ e.preventDefault(); | ||
} | ||
}; // ============================ Offset ============================ | ||
var positionStyle = getDirectionStyle(direction, value, min, max); // ============================ Render ============================ | ||
}; | ||
// ============================ Offset ============================ | ||
var positionStyle = getDirectionStyle(direction, value, min, max); | ||
// ============================ Render ============================ | ||
var handleNode = /*#__PURE__*/React.createElement("div", _extends({ | ||
@@ -118,4 +105,4 @@ ref: ref, | ||
"aria-valuetext": (_getIndex = getIndex(ariaValueTextFormatterForHandle, valueIndex)) === null || _getIndex === void 0 ? void 0 : _getIndex(value) | ||
}, restProps)); // Customize | ||
}, restProps)); | ||
// Customize | ||
if (render) { | ||
@@ -129,10 +116,7 @@ handleNode = render(handleNode, { | ||
} | ||
return handleNode; | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Handle.displayName = 'Handle'; | ||
} | ||
export default Handle; |
@@ -9,10 +9,9 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
onStartMove = props.onStartMove, | ||
onOffsetChange = props.onOffsetChange, | ||
values = props.values, | ||
handleRender = props.handleRender, | ||
draggingIndex = props.draggingIndex, | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
style = props.style, | ||
onStartMove = props.onStartMove, | ||
onOffsetChange = props.onOffsetChange, | ||
values = props.values, | ||
handleRender = props.handleRender, | ||
draggingIndex = props.draggingIndex, | ||
restProps = _objectWithoutProperties(props, _excluded); | ||
var handlesRef = React.useRef({}); | ||
@@ -23,3 +22,2 @@ React.useImperativeHandle(ref, function () { | ||
var _handlesRef$current$i; | ||
(_handlesRef$current$i = handlesRef.current[index]) === null || _handlesRef$current$i === void 0 ? void 0 : _handlesRef$current$i.focus(); | ||
@@ -50,7 +48,5 @@ } | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Handles.displayName = 'Handles'; | ||
} | ||
export default Handles; |
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import * as React from 'react'; | ||
function getPosition(e) { | ||
@@ -12,24 +11,19 @@ var obj = 'touches' in e ? e.touches[0] : e; | ||
} | ||
export default function useDrag(containerRef, direction, rawValues, min, max, formatValue, triggerChange, finishChange, offsetValues) { | ||
var _React$useState = React.useState(null), | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
draggingValue = _React$useState2[0], | ||
setDraggingValue = _React$useState2[1]; | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
draggingValue = _React$useState2[0], | ||
setDraggingValue = _React$useState2[1]; | ||
var _React$useState3 = React.useState(-1), | ||
_React$useState4 = _slicedToArray(_React$useState3, 2), | ||
draggingIndex = _React$useState4[0], | ||
setDraggingIndex = _React$useState4[1]; | ||
_React$useState4 = _slicedToArray(_React$useState3, 2), | ||
draggingIndex = _React$useState4[0], | ||
setDraggingIndex = _React$useState4[1]; | ||
var _React$useState5 = React.useState(rawValues), | ||
_React$useState6 = _slicedToArray(_React$useState5, 2), | ||
cacheValues = _React$useState6[0], | ||
setCacheValues = _React$useState6[1]; | ||
_React$useState6 = _slicedToArray(_React$useState5, 2), | ||
cacheValues = _React$useState6[0], | ||
setCacheValues = _React$useState6[1]; | ||
var _React$useState7 = React.useState(rawValues), | ||
_React$useState8 = _slicedToArray(_React$useState7, 2), | ||
originValues = _React$useState8[0], | ||
setOriginValues = _React$useState8[1]; | ||
_React$useState8 = _slicedToArray(_React$useState7, 2), | ||
originValues = _React$useState8[0], | ||
setOriginValues = _React$useState8[1]; | ||
var mouseMoveEventRef = React.useRef(null); | ||
@@ -41,4 +35,4 @@ var mouseUpEventRef = React.useRef(null); | ||
} | ||
}, [rawValues, draggingIndex]); // Clean up event | ||
}, [rawValues, draggingIndex]); | ||
// Clean up event | ||
React.useEffect(function () { | ||
@@ -52,3 +46,2 @@ return function () { | ||
}, []); | ||
var flushValues = function flushValues(nextValues, nextValue) { | ||
@@ -62,3 +55,2 @@ // Perf: Only update state when value changed | ||
} | ||
setCacheValues(nextValues); | ||
@@ -68,3 +60,2 @@ triggerChange(nextValues); | ||
}; | ||
var updateCacheValue = function updateCacheValue(valueIndex, offsetPercent) { | ||
@@ -77,8 +68,8 @@ // Basic point offset | ||
var maxStartOffset = min - startValue; | ||
var maxEndOffset = max - endValue; // Get valid offset | ||
var maxEndOffset = max - endValue; | ||
// Get valid offset | ||
var offset = offsetPercent * (max - min); | ||
offset = Math.max(offset, maxStartOffset); | ||
offset = Math.min(offset, maxEndOffset); // Use first value to revert back of valid offset (like steps marks) | ||
offset = Math.min(offset, maxEndOffset); | ||
// Use first value to revert back of valid offset (like steps marks) | ||
var formatStartValue = formatValue(startValue + offset); | ||
@@ -92,6 +83,5 @@ offset = formatStartValue - startValue; | ||
// >>>> Dragging on the handle | ||
var offsetDist = (max - min) * offsetPercent; // Always start with the valueIndex origin value | ||
var offsetDist = (max - min) * offsetPercent; | ||
// Always start with the valueIndex origin value | ||
var cloneValues = _toConsumableArray(cacheValues); | ||
cloneValues[valueIndex] = originValues[valueIndex]; | ||
@@ -101,8 +91,6 @@ var next = offsetValues(cloneValues, offsetDist, valueIndex, 'dist'); | ||
} | ||
}; // Resolve closure | ||
}; | ||
// Resolve closure | ||
var updateCacheValueRef = React.useRef(updateCacheValue); | ||
updateCacheValueRef.current = updateCacheValue; | ||
var onStartMove = function onStartMove(e, valueIndex) { | ||
@@ -114,24 +102,17 @@ e.stopPropagation(); | ||
setOriginValues(rawValues); | ||
var _getPosition = getPosition(e), | ||
startX = _getPosition.pageX, | ||
startY = _getPosition.pageY; // Moving | ||
startX = _getPosition.pageX, | ||
startY = _getPosition.pageY; | ||
// Moving | ||
var onMouseMove = function onMouseMove(event) { | ||
event.preventDefault(); | ||
var _getPosition2 = getPosition(event), | ||
moveX = _getPosition2.pageX, | ||
moveY = _getPosition2.pageY; | ||
moveX = _getPosition2.pageX, | ||
moveY = _getPosition2.pageY; | ||
var offsetX = moveX - startX; | ||
var offsetY = moveY - startY; | ||
var _containerRef$current = containerRef.current.getBoundingClientRect(), | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height; | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height; | ||
var offSetPercent; | ||
switch (direction) { | ||
@@ -141,19 +122,14 @@ case 'btt': | ||
break; | ||
case 'ttb': | ||
offSetPercent = offsetY / height; | ||
break; | ||
case 'rtl': | ||
offSetPercent = -offsetX / width; | ||
break; | ||
default: | ||
offSetPercent = offsetX / width; | ||
} | ||
updateCacheValueRef.current(valueIndex, offSetPercent); | ||
}; // End | ||
}; | ||
// End | ||
var onMouseUp = function onMouseUp(event) { | ||
@@ -170,3 +146,2 @@ event.preventDefault(); | ||
}; | ||
document.addEventListener('mouseup', onMouseUp); | ||
@@ -178,5 +153,4 @@ document.addEventListener('mousemove', onMouseMove); | ||
mouseUpEventRef.current = onMouseUp; | ||
}; // Only return cache value when it mapping with rawValues | ||
}; | ||
// Only return cache value when it mapping with rawValues | ||
var returnValues = React.useMemo(function () { | ||
@@ -186,7 +160,5 @@ var sourceValues = _toConsumableArray(rawValues).sort(function (a, b) { | ||
}); | ||
var targetValues = _toConsumableArray(cacheValues).sort(function (a, b) { | ||
return a - b; | ||
}); | ||
return sourceValues.every(function (val, index) { | ||
@@ -193,0 +165,0 @@ return val === targetValues[index]; |
import type { InternalMarkObj } from '../Marks'; | ||
/** Format value align with step & marks */ | ||
declare type FormatValue = (value: number) => number; | ||
declare type OffsetMode = 'unit' | 'dist'; | ||
export declare type OffsetValues = (values: number[], offset: number | 'min' | 'max', valueIndex: number, mode?: OffsetMode) => { | ||
type FormatValue = (value: number) => number; | ||
type OffsetMode = 'unit' | 'dist'; | ||
export type OffsetValues = (values: number[], offset: number | 'min' | 'max', valueIndex: number, mode?: OffsetMode) => { | ||
value: number; | ||
@@ -7,0 +7,0 @@ values: number[]; |
@@ -12,8 +12,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
if (step !== null) { | ||
var stepValue = min + Math.round((formatRangeValue(val) - min) / step) * step; // Cut number in case to be like 0.30000000000000004 | ||
var stepValue = min + Math.round((formatRangeValue(val) - min) / step) * step; | ||
// Cut number in case to be like 0.30000000000000004 | ||
var getDecimal = function getDecimal(num) { | ||
return (String(num).split('.')[1] || '').length; | ||
}; | ||
var maxDecimal = Math.max(getDecimal(step), getDecimal(max), getDecimal(min)); | ||
@@ -23,19 +22,16 @@ var fixedValue = Number(stepValue.toFixed(maxDecimal)); | ||
} | ||
return null; | ||
}, [step, min, max, formatRangeValue]); | ||
var formatValue = React.useCallback(function (val) { | ||
var formatNextValue = formatRangeValue(val); // List align values | ||
var formatNextValue = formatRangeValue(val); | ||
// List align values | ||
var alignValues = markList.map(function (mark) { | ||
return mark.value; | ||
}); | ||
if (step !== null) { | ||
alignValues.push(formatStepValue(val)); | ||
} // min & max | ||
alignValues.push(min, max); // Align with marks | ||
} | ||
// min & max | ||
alignValues.push(min, max); | ||
// Align with marks | ||
var closeValue = alignValues[0]; | ||
@@ -45,3 +41,2 @@ var closeDist = max - min; | ||
var dist = Math.abs(formatNextValue - alignValue); | ||
if (dist <= closeDist) { | ||
@@ -53,25 +48,23 @@ closeValue = alignValue; | ||
return closeValue; | ||
}, [min, max, markList, step, formatRangeValue, formatStepValue]); // ========================== Offset ========================== | ||
}, [min, max, markList, step, formatRangeValue, formatStepValue]); | ||
// ========================== Offset ========================== | ||
// Single Value | ||
var offsetValue = function offsetValue(values, offset, valueIndex) { | ||
var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unit'; | ||
if (typeof offset === 'number') { | ||
var nextValue; | ||
var originValue = values[valueIndex]; // Only used for `dist` mode | ||
var targetDistValue = originValue + offset; // Compare next step value & mark value which is best match | ||
var originValue = values[valueIndex]; | ||
// Only used for `dist` mode | ||
var targetDistValue = originValue + offset; | ||
// Compare next step value & mark value which is best match | ||
var potentialValues = []; | ||
markList.forEach(function (mark) { | ||
potentialValues.push(mark.value); | ||
}); // Min & Max | ||
potentialValues.push(min, max); // In case origin value is align with mark but not with step | ||
potentialValues.push(formatStepValue(originValue)); // Put offset step value also | ||
}); | ||
// Min & Max | ||
potentialValues.push(min, max); | ||
// In case origin value is align with mark but not with step | ||
potentialValues.push(formatStepValue(originValue)); | ||
// Put offset step value also | ||
var sign = offset > 0 ? 1 : -1; | ||
if (mode === 'unit') { | ||
@@ -81,12 +74,11 @@ potentialValues.push(formatStepValue(originValue + sign * step)); | ||
potentialValues.push(formatStepValue(targetDistValue)); | ||
} // Find close one | ||
} | ||
// Find close one | ||
potentialValues = potentialValues.filter(function (val) { | ||
return val !== null; | ||
}) // Remove reverse value | ||
}) | ||
// Remove reverse value | ||
.filter(function (val) { | ||
return offset < 0 ? val <= originValue : val >= originValue; | ||
}); | ||
if (mode === 'unit') { | ||
@@ -98,3 +90,2 @@ // `unit` mode can not contain itself | ||
} | ||
var compareValue = mode === 'unit' ? originValue : targetDistValue; | ||
@@ -105,3 +96,2 @@ nextValue = potentialValues[0]; | ||
var dist = Math.abs(potentialValue - compareValue); | ||
if (dist < valueDist) { | ||
@@ -111,21 +101,17 @@ nextValue = potentialValue; | ||
} | ||
}); // Out of range will back to range | ||
}); | ||
// Out of range will back to range | ||
if (nextValue === undefined) { | ||
return offset < 0 ? min : max; | ||
} // `dist` mode | ||
} | ||
// `dist` mode | ||
if (mode === 'dist') { | ||
return nextValue; | ||
} // `unit` mode may need another round | ||
} | ||
// `unit` mode may need another round | ||
if (Math.abs(offset) > 1) { | ||
var cloneValues = _toConsumableArray(values); | ||
cloneValues[valueIndex] = nextValue; | ||
return offsetValue(cloneValues, offset - sign, valueIndex, mode); | ||
} | ||
return nextValue; | ||
@@ -139,4 +125,2 @@ } else if (offset === 'min') { | ||
/** Same as `offsetValue` but return `changed` mark to tell value changed */ | ||
var offsetChangedValue = function offsetChangedValue(values, offset, valueIndex) { | ||
@@ -151,8 +135,6 @@ var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unit'; | ||
}; | ||
var needPush = function needPush(dist) { | ||
return pushable === null && dist === 0 || typeof pushable === 'number' && dist < pushable; | ||
}; // Values | ||
}; | ||
// Values | ||
var offsetValues = function offsetValues(values, offset, valueIndex) { | ||
@@ -164,11 +146,9 @@ var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unit'; | ||
nextValues[valueIndex] = nextValue; | ||
if (allowCross === false) { | ||
// >>>>> Allow Cross | ||
var pushNum = pushable || 0; // ============ AllowCross =============== | ||
var pushNum = pushable || 0; | ||
// ============ AllowCross =============== | ||
if (valueIndex > 0 && nextValues[valueIndex - 1] !== originValue) { | ||
nextValues[valueIndex] = Math.max(nextValues[valueIndex], nextValues[valueIndex - 1] + pushNum); | ||
} | ||
if (valueIndex < nextValues.length - 1 && nextValues[valueIndex + 1] !== originValue) { | ||
@@ -184,43 +164,32 @@ nextValues[valueIndex] = Math.min(nextValues[valueIndex], nextValues[valueIndex + 1] - pushNum); | ||
var changed = true; | ||
while (needPush(nextValues[i] - nextValues[i - 1]) && changed) { | ||
var _offsetChangedValue = offsetChangedValue(nextValues, 1, i); | ||
nextValues[i] = _offsetChangedValue.value; | ||
changed = _offsetChangedValue.changed; | ||
} | ||
} // Start values | ||
} | ||
// Start values | ||
for (var _i = valueIndex; _i > 0; _i -= 1) { | ||
var _changed = true; | ||
while (needPush(nextValues[_i] - nextValues[_i - 1]) && _changed) { | ||
var _offsetChangedValue2 = offsetChangedValue(nextValues, -1, _i - 1); | ||
nextValues[_i - 1] = _offsetChangedValue2.value; | ||
_changed = _offsetChangedValue2.changed; | ||
} | ||
} // >>>>> Revert back to safe push range | ||
} | ||
// >>>>> Revert back to safe push range | ||
// End to Start | ||
for (var _i2 = nextValues.length - 1; _i2 > 0; _i2 -= 1) { | ||
var _changed2 = true; | ||
while (needPush(nextValues[_i2] - nextValues[_i2 - 1]) && _changed2) { | ||
var _offsetChangedValue3 = offsetChangedValue(nextValues, -1, _i2 - 1); | ||
nextValues[_i2 - 1] = _offsetChangedValue3.value; | ||
_changed2 = _offsetChangedValue3.changed; | ||
} | ||
} // Start to End | ||
} | ||
// Start to End | ||
for (var _i3 = 0; _i3 < nextValues.length - 1; _i3 += 1) { | ||
var _changed3 = true; | ||
while (needPush(nextValues[_i3 + 1] - nextValues[_i3]) && _changed3) { | ||
var _offsetChangedValue4 = offsetChangedValue(nextValues, 1, _i3 + 1); | ||
nextValues[_i3 + 1] = _offsetChangedValue4.value; | ||
@@ -231,3 +200,2 @@ _changed3 = _offsetChangedValue4.changed; | ||
} | ||
return { | ||
@@ -238,4 +206,3 @@ value: nextValues[valueIndex], | ||
}; | ||
return [formatValue, offsetValues]; | ||
} |
import type React from 'react'; | ||
export declare type Direction = 'rtl' | 'ltr' | 'ttb' | 'btt'; | ||
export declare type OnStartMove = (e: React.MouseEvent | React.TouchEvent, valueIndex: number) => void; | ||
export declare type AriaValueFormat = (value: number) => string; | ||
export type Direction = 'rtl' | 'ltr' | 'ttb' | 'btt'; | ||
export type OnStartMove = (e: React.MouseEvent | React.TouchEvent, valueIndex: number) => void; | ||
export type AriaValueFormat = (value: number) => string; |
@@ -5,10 +5,9 @@ import * as React from 'react'; | ||
var prefixCls = props.prefixCls, | ||
marks = props.marks, | ||
onClick = props.onClick; | ||
var markPrefixCls = "".concat(prefixCls, "-mark"); // Not render mark if empty | ||
marks = props.marks, | ||
onClick = props.onClick; | ||
var markPrefixCls = "".concat(prefixCls, "-mark"); | ||
// Not render mark if empty | ||
if (!marks.length) { | ||
return null; | ||
} | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -18,4 +17,4 @@ className: markPrefixCls | ||
var value = _ref.value, | ||
style = _ref.style, | ||
label = _ref.label; | ||
style = _ref.style, | ||
label = _ref.label; | ||
return /*#__PURE__*/React.createElement(Mark, { | ||
@@ -22,0 +21,0 @@ key: value, |
@@ -9,17 +9,15 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
children = props.children, | ||
value = props.value, | ||
_onClick = props.onClick; | ||
style = props.style, | ||
children = props.children, | ||
value = props.value, | ||
_onClick = props.onClick; | ||
var _React$useContext = React.useContext(SliderContext), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd, | ||
included = _React$useContext.included; | ||
var textCls = "".concat(prefixCls, "-text"); // ============================ Offset ============================ | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd, | ||
included = _React$useContext.included; | ||
var textCls = "".concat(prefixCls, "-text"); | ||
// ============================ Offset ============================ | ||
var positionStyle = getDirectionStyle(direction, value, min, max); | ||
@@ -26,0 +24,0 @@ return /*#__PURE__*/React.createElement("span", { |
304
es/Slider.js
@@ -7,3 +7,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import classNames from 'classnames'; | ||
import shallowEqual from 'shallowequal'; | ||
import isEqual from "rc-util/es/isEqual"; | ||
import useMergedState from "rc-util/es/hooks/useMergedState"; | ||
@@ -20,50 +20,49 @@ import Handles from './Handles'; | ||
var _classNames; | ||
var _props$prefixCls = props.prefixCls, | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-slider' : _props$prefixCls, | ||
className = props.className, | ||
style = props.style, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$keyboard = props.keyboard, | ||
keyboard = _props$keyboard === void 0 ? true : _props$keyboard, | ||
autoFocus = props.autoFocus, | ||
onFocus = props.onFocus, | ||
onBlur = props.onBlur, | ||
_props$min = props.min, | ||
min = _props$min === void 0 ? 0 : _props$min, | ||
_props$max = props.max, | ||
max = _props$max === void 0 ? 100 : _props$max, | ||
_props$step = props.step, | ||
step = _props$step === void 0 ? 1 : _props$step, | ||
value = props.value, | ||
defaultValue = props.defaultValue, | ||
range = props.range, | ||
count = props.count, | ||
onChange = props.onChange, | ||
onBeforeChange = props.onBeforeChange, | ||
onAfterChange = props.onAfterChange, | ||
_props$allowCross = props.allowCross, | ||
allowCross = _props$allowCross === void 0 ? true : _props$allowCross, | ||
_props$pushable = props.pushable, | ||
pushable = _props$pushable === void 0 ? false : _props$pushable, | ||
draggableTrack = props.draggableTrack, | ||
reverse = props.reverse, | ||
vertical = props.vertical, | ||
_props$included = props.included, | ||
included = _props$included === void 0 ? true : _props$included, | ||
startPoint = props.startPoint, | ||
trackStyle = props.trackStyle, | ||
handleStyle = props.handleStyle, | ||
railStyle = props.railStyle, | ||
dotStyle = props.dotStyle, | ||
activeDotStyle = props.activeDotStyle, | ||
marks = props.marks, | ||
dots = props.dots, | ||
handleRender = props.handleRender, | ||
_props$tabIndex = props.tabIndex, | ||
tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex, | ||
ariaLabelForHandle = props.ariaLabelForHandle, | ||
ariaLabelledByForHandle = props.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = props.ariaValueTextFormatterForHandle; | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-slider' : _props$prefixCls, | ||
className = props.className, | ||
style = props.style, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$keyboard = props.keyboard, | ||
keyboard = _props$keyboard === void 0 ? true : _props$keyboard, | ||
autoFocus = props.autoFocus, | ||
onFocus = props.onFocus, | ||
onBlur = props.onBlur, | ||
_props$min = props.min, | ||
min = _props$min === void 0 ? 0 : _props$min, | ||
_props$max = props.max, | ||
max = _props$max === void 0 ? 100 : _props$max, | ||
_props$step = props.step, | ||
step = _props$step === void 0 ? 1 : _props$step, | ||
value = props.value, | ||
defaultValue = props.defaultValue, | ||
range = props.range, | ||
count = props.count, | ||
onChange = props.onChange, | ||
onBeforeChange = props.onBeforeChange, | ||
onAfterChange = props.onAfterChange, | ||
_props$allowCross = props.allowCross, | ||
allowCross = _props$allowCross === void 0 ? true : _props$allowCross, | ||
_props$pushable = props.pushable, | ||
pushable = _props$pushable === void 0 ? false : _props$pushable, | ||
draggableTrack = props.draggableTrack, | ||
reverse = props.reverse, | ||
vertical = props.vertical, | ||
_props$included = props.included, | ||
included = _props$included === void 0 ? true : _props$included, | ||
startPoint = props.startPoint, | ||
trackStyle = props.trackStyle, | ||
handleStyle = props.handleStyle, | ||
railStyle = props.railStyle, | ||
dotStyle = props.dotStyle, | ||
activeDotStyle = props.activeDotStyle, | ||
marks = props.marks, | ||
dots = props.dots, | ||
handleRender = props.handleRender, | ||
_props$tabIndex = props.tabIndex, | ||
tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex, | ||
ariaLabelForHandle = props.ariaLabelForHandle, | ||
ariaLabelledByForHandle = props.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = props.ariaValueTextFormatterForHandle; | ||
var handlesRef = React.useRef(); | ||
@@ -75,6 +74,5 @@ var containerRef = React.useRef(); | ||
} | ||
return reverse ? 'rtl' : 'ltr'; | ||
}, [reverse, vertical]); // ============================ Range ============================= | ||
}, [reverse, vertical]); | ||
// ============================ Range ============================= | ||
var mergedMin = React.useMemo(function () { | ||
@@ -85,8 +83,8 @@ return isFinite(min) ? min : 0; | ||
return isFinite(max) ? max : 100; | ||
}, [max]); // ============================= Step ============================= | ||
}, [max]); | ||
// ============================= Step ============================= | ||
var mergedStep = React.useMemo(function () { | ||
return step !== null && step <= 0 ? 1 : step; | ||
}, [step]); // ============================= Push ============================= | ||
}, [step]); | ||
// ============================= Push ============================= | ||
var mergedPush = React.useMemo(function () { | ||
@@ -96,6 +94,5 @@ if (pushable === true) { | ||
} | ||
return pushable >= 0 ? pushable : false; | ||
}, [pushable, mergedStep]); // ============================ Marks ============================= | ||
}, [pushable, mergedStep]); | ||
// ============================ Marks ============================= | ||
var markList = React.useMemo(function () { | ||
@@ -108,3 +105,2 @@ var keys = Object.keys(marks || {}); | ||
}; | ||
if (mark && _typeof(mark) === 'object' && ! /*#__PURE__*/React.isValidElement(mark) && ('label' in mark || 'style' in mark)) { | ||
@@ -116,3 +112,2 @@ markObj.style = mark.style; | ||
} | ||
return markObj; | ||
@@ -125,46 +120,39 @@ }).filter(function (_ref) { | ||
}); | ||
}, [marks]); // ============================ Format ============================ | ||
}, [marks]); | ||
// ============================ Format ============================ | ||
var _useOffset = useOffset(mergedMin, mergedMax, mergedStep, markList, allowCross, mergedPush), | ||
_useOffset2 = _slicedToArray(_useOffset, 2), | ||
formatValue = _useOffset2[0], | ||
offsetValues = _useOffset2[1]; // ============================ Values ============================ | ||
_useOffset2 = _slicedToArray(_useOffset, 2), | ||
formatValue = _useOffset2[0], | ||
offsetValues = _useOffset2[1]; | ||
// ============================ Values ============================ | ||
var _useMergedState = useMergedState(defaultValue, { | ||
value: value | ||
}), | ||
_useMergedState2 = _slicedToArray(_useMergedState, 2), | ||
mergedValue = _useMergedState2[0], | ||
setValue = _useMergedState2[1]; | ||
value: value | ||
}), | ||
_useMergedState2 = _slicedToArray(_useMergedState, 2), | ||
mergedValue = _useMergedState2[0], | ||
setValue = _useMergedState2[1]; | ||
var rawValues = React.useMemo(function () { | ||
var valueList = mergedValue === null || mergedValue === undefined ? [] : Array.isArray(mergedValue) ? mergedValue : [mergedValue]; | ||
var _valueList = _slicedToArray(valueList, 1), | ||
_valueList$ = _valueList[0], | ||
val0 = _valueList$ === void 0 ? mergedMin : _valueList$; | ||
var returnValues = mergedValue === null ? [] : [val0]; // Format as range | ||
_valueList$ = _valueList[0], | ||
val0 = _valueList$ === void 0 ? mergedMin : _valueList$; | ||
var returnValues = mergedValue === null ? [] : [val0]; | ||
// Format as range | ||
if (range) { | ||
returnValues = _toConsumableArray(valueList); // When count provided or value is `undefined`, we fill values | ||
returnValues = _toConsumableArray(valueList); | ||
// When count provided or value is `undefined`, we fill values | ||
if (count || mergedValue === undefined) { | ||
var pointCount = count >= 0 ? count + 1 : 2; | ||
returnValues = returnValues.slice(0, pointCount); // Fill with count | ||
returnValues = returnValues.slice(0, pointCount); | ||
// Fill with count | ||
while (returnValues.length < pointCount) { | ||
var _returnValues; | ||
returnValues.push((_returnValues = returnValues[returnValues.length - 1]) !== null && _returnValues !== void 0 ? _returnValues : mergedMin); | ||
} | ||
} | ||
returnValues.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
} // Align in range | ||
} | ||
// Align in range | ||
returnValues.forEach(function (val, index) { | ||
@@ -174,11 +162,9 @@ returnValues[index] = formatValue(val); | ||
return returnValues; | ||
}, [mergedValue, range, mergedMin, count, formatValue]); // =========================== onChange =========================== | ||
}, [mergedValue, range, mergedMin, count, formatValue]); | ||
// =========================== onChange =========================== | ||
var rawValuesRef = React.useRef(rawValues); | ||
rawValuesRef.current = rawValues; | ||
var getTriggerValue = function getTriggerValue(triggerValues) { | ||
return range ? triggerValues : triggerValues[0]; | ||
}; | ||
var triggerChange = function triggerChange(nextValues) { | ||
@@ -188,13 +174,10 @@ // Order first | ||
return a - b; | ||
}); // Trigger event if needed | ||
if (onChange && !shallowEqual(cloneNextValues, rawValuesRef.current)) { | ||
}); | ||
// Trigger event if needed | ||
if (onChange && !isEqual(cloneNextValues, rawValuesRef.current, true)) { | ||
onChange(getTriggerValue(cloneNextValues)); | ||
} // We set this later since it will re-render component immediately | ||
} | ||
// We set this later since it will re-render component immediately | ||
setValue(cloneNextValues); | ||
}; | ||
var changeToCloseValue = function changeToCloseValue(newValue) { | ||
@@ -206,3 +189,2 @@ if (!disabled) { | ||
var dist = Math.abs(newValue - val); | ||
if (dist <= valueDist) { | ||
@@ -212,12 +194,10 @@ valueDist = dist; | ||
} | ||
}); // Create new values | ||
}); | ||
// Create new values | ||
var cloneNextValues = _toConsumableArray(rawValues); | ||
cloneNextValues[valueIndex] = newValue; // Fill value to match default 2 | ||
cloneNextValues[valueIndex] = newValue; | ||
// Fill value to match default 2 | ||
if (range && !rawValues.length && count === undefined) { | ||
cloneNextValues.push(newValue); | ||
} | ||
onBeforeChange === null || onBeforeChange === void 0 ? void 0 : onBeforeChange(getTriggerValue(cloneNextValues)); | ||
@@ -227,20 +207,16 @@ triggerChange(cloneNextValues); | ||
} | ||
}; // ============================ Click ============================= | ||
}; | ||
// ============================ Click ============================= | ||
var onSliderMouseDown = function onSliderMouseDown(e) { | ||
e.preventDefault(); | ||
var _containerRef$current = containerRef.current.getBoundingClientRect(), | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height, | ||
left = _containerRef$current.left, | ||
top = _containerRef$current.top, | ||
bottom = _containerRef$current.bottom, | ||
right = _containerRef$current.right; | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height, | ||
left = _containerRef$current.left, | ||
top = _containerRef$current.top, | ||
bottom = _containerRef$current.bottom, | ||
right = _containerRef$current.right; | ||
var clientX = e.clientX, | ||
clientY = e.clientY; | ||
clientY = e.clientY; | ||
var percent; | ||
switch (direction) { | ||
@@ -250,25 +226,19 @@ case 'btt': | ||
break; | ||
case 'ttb': | ||
percent = (clientY - top) / height; | ||
break; | ||
case 'rtl': | ||
percent = (right - clientX) / width; | ||
break; | ||
default: | ||
percent = (clientX - left) / width; | ||
} | ||
var nextValue = mergedMin + percent * (mergedMax - mergedMin); | ||
changeToCloseValue(formatValue(nextValue)); | ||
}; // =========================== Keyboard =========================== | ||
}; | ||
// =========================== Keyboard =========================== | ||
var _React$useState = React.useState(null), | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
keyboardValue = _React$useState2[0], | ||
setKeyboardValue = _React$useState2[1]; | ||
_React$useState2 = _slicedToArray(_React$useState, 2), | ||
keyboardValue = _React$useState2[0], | ||
setKeyboardValue = _React$useState2[1]; | ||
var onHandleOffsetChange = function onHandleOffsetChange(offset, valueIndex) { | ||
@@ -283,7 +253,5 @@ if (!disabled) { | ||
}; | ||
React.useEffect(function () { | ||
if (keyboardValue !== null) { | ||
var valueIndex = rawValues.indexOf(keyboardValue); | ||
if (valueIndex >= 0) { | ||
@@ -293,6 +261,5 @@ handlesRef.current.focus(valueIndex); | ||
} | ||
setKeyboardValue(null); | ||
}, [keyboardValue]); // ============================= Drag ============================= | ||
}, [keyboardValue]); | ||
// ============================= Drag ============================= | ||
var mergedDraggableTrack = React.useMemo(function () { | ||
@@ -303,26 +270,20 @@ if (draggableTrack && mergedStep === null) { | ||
} | ||
return false; | ||
} | ||
return draggableTrack; | ||
}, [draggableTrack, mergedStep]); | ||
var finishChange = function finishChange() { | ||
onAfterChange === null || onAfterChange === void 0 ? void 0 : onAfterChange(getTriggerValue(rawValuesRef.current)); | ||
}; | ||
var _useDrag = useDrag(containerRef, direction, rawValues, mergedMin, mergedMax, formatValue, triggerChange, finishChange, offsetValues), | ||
_useDrag2 = _slicedToArray(_useDrag, 4), | ||
draggingIndex = _useDrag2[0], | ||
draggingValue = _useDrag2[1], | ||
cacheValues = _useDrag2[2], | ||
onStartDrag = _useDrag2[3]; | ||
_useDrag2 = _slicedToArray(_useDrag, 4), | ||
draggingIndex = _useDrag2[0], | ||
draggingValue = _useDrag2[1], | ||
cacheValues = _useDrag2[2], | ||
onStartDrag = _useDrag2[3]; | ||
var onStartMove = function onStartMove(e, valueIndex) { | ||
onStartDrag(e, valueIndex); | ||
onBeforeChange === null || onBeforeChange === void 0 ? void 0 : onBeforeChange(getTriggerValue(rawValuesRef.current)); | ||
}; // Auto focus for updated handle | ||
}; | ||
// Auto focus for updated handle | ||
var dragging = draggingIndex !== -1; | ||
@@ -334,4 +295,4 @@ React.useEffect(function () { | ||
} | ||
}, [dragging]); // =========================== Included =========================== | ||
}, [dragging]); | ||
// =========================== Included =========================== | ||
var sortedCacheValues = React.useMemo(function () { | ||
@@ -341,17 +302,15 @@ return _toConsumableArray(cacheValues).sort(function (a, b) { | ||
}); | ||
}, [cacheValues]); // Provide a range values with included [min, max] | ||
}, [cacheValues]); | ||
// Provide a range values with included [min, max] | ||
// Used for Track, Mark & Dot | ||
var _React$useMemo = React.useMemo(function () { | ||
if (!range) { | ||
return [mergedMin, sortedCacheValues[0]]; | ||
} | ||
return [sortedCacheValues[0], sortedCacheValues[sortedCacheValues.length - 1]]; | ||
}, [sortedCacheValues, range, mergedMin]), | ||
_React$useMemo2 = _slicedToArray(_React$useMemo, 2), | ||
includedStart = _React$useMemo2[0], | ||
includedEnd = _React$useMemo2[1]; // ============================= Refs ============================= | ||
if (!range) { | ||
return [mergedMin, sortedCacheValues[0]]; | ||
} | ||
return [sortedCacheValues[0], sortedCacheValues[sortedCacheValues.length - 1]]; | ||
}, [sortedCacheValues, range, mergedMin]), | ||
_React$useMemo2 = _slicedToArray(_React$useMemo, 2), | ||
includedStart = _React$useMemo2[0], | ||
includedEnd = _React$useMemo2[1]; | ||
// ============================= Refs ============================= | ||
React.useImperativeHandle(ref, function () { | ||
@@ -364,4 +323,3 @@ return { | ||
var _document = document, | ||
activeElement = _document.activeElement; | ||
activeElement = _document.activeElement; | ||
if (containerRef.current.contains(activeElement)) { | ||
@@ -372,4 +330,4 @@ activeElement === null || activeElement === void 0 ? void 0 : activeElement.blur(); | ||
}; | ||
}); // ========================== Auto Focus ========================== | ||
}); | ||
// ========================== Auto Focus ========================== | ||
React.useEffect(function () { | ||
@@ -379,4 +337,4 @@ if (autoFocus) { | ||
} | ||
}, []); // =========================== Context ============================ | ||
}, []); | ||
// =========================== Context ============================ | ||
var context = React.useMemo(function () { | ||
@@ -399,4 +357,4 @@ return { | ||
}; | ||
}, [mergedMin, mergedMax, direction, disabled, keyboard, mergedStep, included, includedStart, includedEnd, range, tabIndex, ariaLabelForHandle, ariaLabelledByForHandle, ariaValueTextFormatterForHandle]); // ============================ Render ============================ | ||
}, [mergedMin, mergedMax, direction, disabled, keyboard, mergedStep, included, includedStart, includedEnd, range, tabIndex, ariaLabelForHandle, ariaLabelledByForHandle, ariaValueTextFormatterForHandle]); | ||
// ============================ Render ============================ | ||
return /*#__PURE__*/React.createElement(SliderContext.Provider, { | ||
@@ -441,7 +399,5 @@ value: context | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Slider.displayName = 'Slider'; | ||
} | ||
export default Slider; |
@@ -9,23 +9,19 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
var prefixCls = props.prefixCls, | ||
value = props.value, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
value = props.value, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
var _React$useContext = React.useContext(SliderContext), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
included = _React$useContext.included, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd; | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
included = _React$useContext.included, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd; | ||
var dotClassName = "".concat(prefixCls, "-dot"); | ||
var active = included && includedStart <= value && value <= includedEnd; // ============================ Offset ============================ | ||
var active = included && includedStart <= value && value <= includedEnd; | ||
// ============================ Offset ============================ | ||
var mergedStyle = _objectSpread(_objectSpread({}, getDirectionStyle(direction, value, min, max)), typeof style === 'function' ? style(value) : style); | ||
if (active) { | ||
mergedStyle = _objectSpread(_objectSpread({}, mergedStyle), typeof activeStyle === 'function' ? activeStyle(value) : activeStyle); | ||
} | ||
return /*#__PURE__*/React.createElement("span", { | ||
@@ -32,0 +28,0 @@ className: classNames(dotClassName, _defineProperty({}, "".concat(dotClassName, "-active"), active)), |
@@ -6,22 +6,19 @@ import * as React from 'react'; | ||
var prefixCls = props.prefixCls, | ||
marks = props.marks, | ||
dots = props.dots, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
marks = props.marks, | ||
dots = props.dots, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
var _React$useContext = React.useContext(SliderContext), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
step = _React$useContext.step; | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
step = _React$useContext.step; | ||
var stepDots = React.useMemo(function () { | ||
var dotSet = new Set(); // Add marks | ||
var dotSet = new Set(); | ||
// Add marks | ||
marks.forEach(function (mark) { | ||
dotSet.add(mark.value); | ||
}); // Fill dots | ||
}); | ||
// Fill dots | ||
if (dots && step !== null) { | ||
var current = min; | ||
while (current <= max) { | ||
@@ -32,3 +29,2 @@ dotSet.add(current); | ||
} | ||
return Array.from(dotSet); | ||
@@ -35,0 +31,0 @@ }, [min, max, step, dots, marks]); |
@@ -7,12 +7,10 @@ import * as React from 'react'; | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
values = props.values, | ||
startPoint = props.startPoint, | ||
onStartMove = props.onStartMove; | ||
style = props.style, | ||
values = props.values, | ||
startPoint = props.startPoint, | ||
onStartMove = props.onStartMove; | ||
var _React$useContext = React.useContext(SliderContext), | ||
included = _React$useContext.included, | ||
range = _React$useContext.range, | ||
min = _React$useContext.min; | ||
included = _React$useContext.included, | ||
range = _React$useContext.range, | ||
min = _React$useContext.min; | ||
var trackList = React.useMemo(function () { | ||
@@ -24,3 +22,2 @@ if (!range) { | ||
} | ||
var startValue = startPoint !== null && startPoint !== void 0 ? startPoint : min; | ||
@@ -32,7 +29,5 @@ var endValue = values[0]; | ||
}]; | ||
} // Multiple | ||
} | ||
// Multiple | ||
var list = []; | ||
for (var i = 0; i < values.length - 1; i += 1) { | ||
@@ -44,3 +39,2 @@ list.push({ | ||
} | ||
return list; | ||
@@ -50,3 +44,3 @@ }, [values, range, startPoint, min]); | ||
var start = _ref.start, | ||
end = _ref.end; | ||
end = _ref.end; | ||
return /*#__PURE__*/React.createElement(Track, { | ||
@@ -53,0 +47,0 @@ index: index, |
@@ -8,19 +8,17 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
start = props.start, | ||
end = props.end, | ||
index = props.index, | ||
onStartMove = props.onStartMove; | ||
style = props.style, | ||
start = props.start, | ||
end = props.end, | ||
index = props.index, | ||
onStartMove = props.onStartMove; | ||
var _React$useContext = React.useContext(SliderContext), | ||
direction = _React$useContext.direction, | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
disabled = _React$useContext.disabled, | ||
range = _React$useContext.range; | ||
direction = _React$useContext.direction, | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
disabled = _React$useContext.disabled, | ||
range = _React$useContext.range; | ||
var trackPrefixCls = "".concat(prefixCls, "-track"); | ||
var offsetStart = getOffset(start, min, max); | ||
var offsetEnd = getOffset(end, min, max); // ============================ Events ============================ | ||
var offsetEnd = getOffset(end, min, max); | ||
// ============================ Events ============================ | ||
var onInternalStartMove = function onInternalStartMove(e) { | ||
@@ -30,7 +28,5 @@ if (!disabled && onStartMove) { | ||
} | ||
}; // ============================ Render ============================ | ||
}; | ||
// ============================ Render ============================ | ||
var positionStyle = {}; | ||
switch (direction) { | ||
@@ -41,3 +37,2 @@ case 'rtl': | ||
break; | ||
case 'btt': | ||
@@ -47,3 +42,2 @@ positionStyle.bottom = "".concat(offsetStart * 100, "%"); | ||
break; | ||
case 'ttb': | ||
@@ -53,3 +47,2 @@ positionStyle.top = "".concat(offsetStart * 100, "%"); | ||
break; | ||
default: | ||
@@ -59,3 +52,2 @@ positionStyle.left = "".concat(offsetStart * 100, "%"); | ||
} | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -62,0 +54,0 @@ className: classNames(trackPrefixCls, range && "".concat(trackPrefixCls, "-").concat(index + 1)), |
@@ -7,3 +7,2 @@ export function getOffset(value, min, max) { | ||
var positionStyle = {}; | ||
switch (direction) { | ||
@@ -14,3 +13,2 @@ case 'rtl': | ||
break; | ||
case 'btt': | ||
@@ -20,3 +18,2 @@ positionStyle.bottom = "".concat(offset * 100, "%"); | ||
break; | ||
case 'ttb': | ||
@@ -26,3 +23,2 @@ positionStyle.top = "".concat(offset * 100, "%"); | ||
break; | ||
default: | ||
@@ -33,9 +29,7 @@ positionStyle.left = "".concat(offset * 100, "%"); | ||
} | ||
return positionStyle; | ||
} | ||
/** Return index value if is list or return value directly */ | ||
export function getIndex(value, index) { | ||
return Array.isArray(value) ? value[index] : value; | ||
} |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,5 +8,5 @@ value: true | ||
exports.default = void 0; | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var SliderContext = /*#__PURE__*/React.createContext({ | ||
@@ -14,0 +13,0 @@ min: 0, |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,49 +9,38 @@ value: true | ||
exports.default = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _KeyCode = _interopRequireDefault(require("rc-util/lib/KeyCode")); | ||
var _context = _interopRequireDefault(require("../context")); | ||
var _util = require("../util"); | ||
var _excluded = ["prefixCls", "value", "valueIndex", "onStartMove", "style", "render", "dragging", "onOffsetChange"]; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var Handle = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
var _classNames, _getIndex; | ||
var prefixCls = props.prefixCls, | ||
value = props.value, | ||
valueIndex = props.valueIndex, | ||
onStartMove = props.onStartMove, | ||
style = props.style, | ||
render = props.render, | ||
dragging = props.dragging, | ||
onOffsetChange = props.onOffsetChange, | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
value = props.value, | ||
valueIndex = props.valueIndex, | ||
onStartMove = props.onStartMove, | ||
style = props.style, | ||
render = props.render, | ||
dragging = props.dragging, | ||
onOffsetChange = props.onOffsetChange, | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
var _React$useContext = React.useContext(_context.default), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
disabled = _React$useContext.disabled, | ||
keyboard = _React$useContext.keyboard, | ||
range = _React$useContext.range, | ||
tabIndex = _React$useContext.tabIndex, | ||
ariaLabelForHandle = _React$useContext.ariaLabelForHandle, | ||
ariaLabelledByForHandle = _React$useContext.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = _React$useContext.ariaValueTextFormatterForHandle; | ||
var handlePrefixCls = "".concat(prefixCls, "-handle"); // ============================ Events ============================ | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
disabled = _React$useContext.disabled, | ||
keyboard = _React$useContext.keyboard, | ||
range = _React$useContext.range, | ||
tabIndex = _React$useContext.tabIndex, | ||
ariaLabelForHandle = _React$useContext.ariaLabelForHandle, | ||
ariaLabelledByForHandle = _React$useContext.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = _React$useContext.ariaValueTextFormatterForHandle; | ||
var handlePrefixCls = "".concat(prefixCls, "-handle"); | ||
// ============================ Events ============================ | ||
var onInternalStartMove = function onInternalStartMove(e) { | ||
@@ -63,9 +50,8 @@ if (!disabled) { | ||
} | ||
}; // =========================== Keyboard =========================== | ||
}; | ||
// =========================== Keyboard =========================== | ||
var onKeyDown = function onKeyDown(e) { | ||
if (!disabled && keyboard) { | ||
var offset = null; // Change the value | ||
var offset = null; | ||
// Change the value | ||
switch (e.which || e.keyCode) { | ||
@@ -75,3 +61,2 @@ case _KeyCode.default.LEFT: | ||
break; | ||
case _KeyCode.default.RIGHT: | ||
@@ -81,3 +66,2 @@ offset = direction === 'ltr' || direction === 'btt' ? 1 : -1; | ||
// Up is plus | ||
case _KeyCode.default.UP: | ||
@@ -87,19 +71,14 @@ offset = direction !== 'ttb' ? 1 : -1; | ||
// Down is minus | ||
case _KeyCode.default.DOWN: | ||
offset = direction !== 'ttb' ? -1 : 1; | ||
break; | ||
case _KeyCode.default.HOME: | ||
offset = 'min'; | ||
break; | ||
case _KeyCode.default.END: | ||
offset = 'max'; | ||
break; | ||
case _KeyCode.default.PAGE_UP: | ||
offset = 2; | ||
break; | ||
case _KeyCode.default.PAGE_DOWN: | ||
@@ -109,3 +88,2 @@ offset = -2; | ||
} | ||
if (offset !== null) { | ||
@@ -116,7 +94,6 @@ e.preventDefault(); | ||
} | ||
}; // ============================ Offset ============================ | ||
var positionStyle = (0, _util.getDirectionStyle)(direction, value, min, max); // ============================ Render ============================ | ||
}; | ||
// ============================ Offset ============================ | ||
var positionStyle = (0, _util.getDirectionStyle)(direction, value, min, max); | ||
// ============================ Render ============================ | ||
var handleNode = /*#__PURE__*/React.createElement("div", (0, _extends2.default)({ | ||
@@ -138,4 +115,4 @@ ref: ref, | ||
"aria-valuetext": (_getIndex = (0, _util.getIndex)(ariaValueTextFormatterForHandle, valueIndex)) === null || _getIndex === void 0 ? void 0 : _getIndex(value) | ||
}, restProps)); // Customize | ||
}, restProps)); | ||
// Customize | ||
if (render) { | ||
@@ -149,11 +126,8 @@ handleNode = render(handleNode, { | ||
} | ||
return handleNode; | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Handle.displayName = 'Handle'; | ||
} | ||
var _default = Handle; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,23 +9,19 @@ value: true | ||
exports.default = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _Handle = _interopRequireDefault(require("./Handle")); | ||
var _util = require("../util"); | ||
var _excluded = ["prefixCls", "style", "onStartMove", "onOffsetChange", "values", "handleRender", "draggingIndex"]; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var Handles = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
onStartMove = props.onStartMove, | ||
onOffsetChange = props.onOffsetChange, | ||
values = props.values, | ||
handleRender = props.handleRender, | ||
draggingIndex = props.draggingIndex, | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
style = props.style, | ||
onStartMove = props.onStartMove, | ||
onOffsetChange = props.onOffsetChange, | ||
values = props.values, | ||
handleRender = props.handleRender, | ||
draggingIndex = props.draggingIndex, | ||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded); | ||
var handlesRef = React.useRef({}); | ||
@@ -38,3 +32,2 @@ React.useImperativeHandle(ref, function () { | ||
var _handlesRef$current$i; | ||
(_handlesRef$current$i = handlesRef.current[index]) === null || _handlesRef$current$i === void 0 ? void 0 : _handlesRef$current$i.focus(); | ||
@@ -65,8 +58,6 @@ } | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Handles.displayName = 'Handles'; | ||
} | ||
var _default = Handles; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,9 +9,7 @@ value: true | ||
exports.default = useDrag; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function getPosition(e) { | ||
@@ -26,24 +22,19 @@ var obj = 'touches' in e ? e.touches[0] : e; | ||
} | ||
function useDrag(containerRef, direction, rawValues, min, max, formatValue, triggerChange, finishChange, offsetValues) { | ||
var _React$useState = React.useState(null), | ||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2), | ||
draggingValue = _React$useState2[0], | ||
setDraggingValue = _React$useState2[1]; | ||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2), | ||
draggingValue = _React$useState2[0], | ||
setDraggingValue = _React$useState2[1]; | ||
var _React$useState3 = React.useState(-1), | ||
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2), | ||
draggingIndex = _React$useState4[0], | ||
setDraggingIndex = _React$useState4[1]; | ||
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2), | ||
draggingIndex = _React$useState4[0], | ||
setDraggingIndex = _React$useState4[1]; | ||
var _React$useState5 = React.useState(rawValues), | ||
_React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2), | ||
cacheValues = _React$useState6[0], | ||
setCacheValues = _React$useState6[1]; | ||
_React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2), | ||
cacheValues = _React$useState6[0], | ||
setCacheValues = _React$useState6[1]; | ||
var _React$useState7 = React.useState(rawValues), | ||
_React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2), | ||
originValues = _React$useState8[0], | ||
setOriginValues = _React$useState8[1]; | ||
_React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2), | ||
originValues = _React$useState8[0], | ||
setOriginValues = _React$useState8[1]; | ||
var mouseMoveEventRef = React.useRef(null); | ||
@@ -55,4 +46,4 @@ var mouseUpEventRef = React.useRef(null); | ||
} | ||
}, [rawValues, draggingIndex]); // Clean up event | ||
}, [rawValues, draggingIndex]); | ||
// Clean up event | ||
React.useEffect(function () { | ||
@@ -66,3 +57,2 @@ return function () { | ||
}, []); | ||
var flushValues = function flushValues(nextValues, nextValue) { | ||
@@ -76,3 +66,2 @@ // Perf: Only update state when value changed | ||
} | ||
setCacheValues(nextValues); | ||
@@ -82,3 +71,2 @@ triggerChange(nextValues); | ||
}; | ||
var updateCacheValue = function updateCacheValue(valueIndex, offsetPercent) { | ||
@@ -91,8 +79,8 @@ // Basic point offset | ||
var maxStartOffset = min - startValue; | ||
var maxEndOffset = max - endValue; // Get valid offset | ||
var maxEndOffset = max - endValue; | ||
// Get valid offset | ||
var offset = offsetPercent * (max - min); | ||
offset = Math.max(offset, maxStartOffset); | ||
offset = Math.min(offset, maxEndOffset); // Use first value to revert back of valid offset (like steps marks) | ||
offset = Math.min(offset, maxEndOffset); | ||
// Use first value to revert back of valid offset (like steps marks) | ||
var formatStartValue = formatValue(startValue + offset); | ||
@@ -106,4 +94,4 @@ offset = formatStartValue - startValue; | ||
// >>>> Dragging on the handle | ||
var offsetDist = (max - min) * offsetPercent; // Always start with the valueIndex origin value | ||
var offsetDist = (max - min) * offsetPercent; | ||
// Always start with the valueIndex origin value | ||
var cloneValues = (0, _toConsumableArray2.default)(cacheValues); | ||
@@ -114,8 +102,6 @@ cloneValues[valueIndex] = originValues[valueIndex]; | ||
} | ||
}; // Resolve closure | ||
}; | ||
// Resolve closure | ||
var updateCacheValueRef = React.useRef(updateCacheValue); | ||
updateCacheValueRef.current = updateCacheValue; | ||
var onStartMove = function onStartMove(e, valueIndex) { | ||
@@ -127,24 +113,17 @@ e.stopPropagation(); | ||
setOriginValues(rawValues); | ||
var _getPosition = getPosition(e), | ||
startX = _getPosition.pageX, | ||
startY = _getPosition.pageY; // Moving | ||
startX = _getPosition.pageX, | ||
startY = _getPosition.pageY; | ||
// Moving | ||
var onMouseMove = function onMouseMove(event) { | ||
event.preventDefault(); | ||
var _getPosition2 = getPosition(event), | ||
moveX = _getPosition2.pageX, | ||
moveY = _getPosition2.pageY; | ||
moveX = _getPosition2.pageX, | ||
moveY = _getPosition2.pageY; | ||
var offsetX = moveX - startX; | ||
var offsetY = moveY - startY; | ||
var _containerRef$current = containerRef.current.getBoundingClientRect(), | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height; | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height; | ||
var offSetPercent; | ||
switch (direction) { | ||
@@ -154,19 +133,14 @@ case 'btt': | ||
break; | ||
case 'ttb': | ||
offSetPercent = offsetY / height; | ||
break; | ||
case 'rtl': | ||
offSetPercent = -offsetX / width; | ||
break; | ||
default: | ||
offSetPercent = offsetX / width; | ||
} | ||
updateCacheValueRef.current(valueIndex, offSetPercent); | ||
}; // End | ||
}; | ||
// End | ||
var onMouseUp = function onMouseUp(event) { | ||
@@ -183,3 +157,2 @@ event.preventDefault(); | ||
}; | ||
document.addEventListener('mouseup', onMouseUp); | ||
@@ -191,5 +164,4 @@ document.addEventListener('mousemove', onMouseMove); | ||
mouseUpEventRef.current = onMouseUp; | ||
}; // Only return cache value when it mapping with rawValues | ||
}; | ||
// Only return cache value when it mapping with rawValues | ||
var returnValues = React.useMemo(function () { | ||
@@ -196,0 +168,0 @@ var sourceValues = (0, _toConsumableArray2.default)(rawValues).sort(function (a, b) { |
import type { InternalMarkObj } from '../Marks'; | ||
/** Format value align with step & marks */ | ||
declare type FormatValue = (value: number) => number; | ||
declare type OffsetMode = 'unit' | 'dist'; | ||
export declare type OffsetValues = (values: number[], offset: number | 'min' | 'max', valueIndex: number, mode?: OffsetMode) => { | ||
type FormatValue = (value: number) => number; | ||
type OffsetMode = 'unit' | 'dist'; | ||
export type OffsetValues = (values: number[], offset: number | 'min' | 'max', valueIndex: number, mode?: OffsetMode) => { | ||
value: number; | ||
@@ -7,0 +7,0 @@ values: number[]; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,7 +9,6 @@ value: true | ||
exports.default = useOffset; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var React = _interopRequireWildcard(require("react")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function useOffset(min, max, step, markList, allowCross, pushable) { | ||
@@ -26,8 +23,7 @@ var formatRangeValue = React.useCallback(function (val) { | ||
if (step !== null) { | ||
var stepValue = min + Math.round((formatRangeValue(val) - min) / step) * step; // Cut number in case to be like 0.30000000000000004 | ||
var stepValue = min + Math.round((formatRangeValue(val) - min) / step) * step; | ||
// Cut number in case to be like 0.30000000000000004 | ||
var getDecimal = function getDecimal(num) { | ||
return (String(num).split('.')[1] || '').length; | ||
}; | ||
var maxDecimal = Math.max(getDecimal(step), getDecimal(max), getDecimal(min)); | ||
@@ -37,19 +33,16 @@ var fixedValue = Number(stepValue.toFixed(maxDecimal)); | ||
} | ||
return null; | ||
}, [step, min, max, formatRangeValue]); | ||
var formatValue = React.useCallback(function (val) { | ||
var formatNextValue = formatRangeValue(val); // List align values | ||
var formatNextValue = formatRangeValue(val); | ||
// List align values | ||
var alignValues = markList.map(function (mark) { | ||
return mark.value; | ||
}); | ||
if (step !== null) { | ||
alignValues.push(formatStepValue(val)); | ||
} // min & max | ||
alignValues.push(min, max); // Align with marks | ||
} | ||
// min & max | ||
alignValues.push(min, max); | ||
// Align with marks | ||
var closeValue = alignValues[0]; | ||
@@ -59,3 +52,2 @@ var closeDist = max - min; | ||
var dist = Math.abs(formatNextValue - alignValue); | ||
if (dist <= closeDist) { | ||
@@ -67,25 +59,23 @@ closeValue = alignValue; | ||
return closeValue; | ||
}, [min, max, markList, step, formatRangeValue, formatStepValue]); // ========================== Offset ========================== | ||
}, [min, max, markList, step, formatRangeValue, formatStepValue]); | ||
// ========================== Offset ========================== | ||
// Single Value | ||
var offsetValue = function offsetValue(values, offset, valueIndex) { | ||
var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unit'; | ||
if (typeof offset === 'number') { | ||
var nextValue; | ||
var originValue = values[valueIndex]; // Only used for `dist` mode | ||
var targetDistValue = originValue + offset; // Compare next step value & mark value which is best match | ||
var originValue = values[valueIndex]; | ||
// Only used for `dist` mode | ||
var targetDistValue = originValue + offset; | ||
// Compare next step value & mark value which is best match | ||
var potentialValues = []; | ||
markList.forEach(function (mark) { | ||
potentialValues.push(mark.value); | ||
}); // Min & Max | ||
potentialValues.push(min, max); // In case origin value is align with mark but not with step | ||
potentialValues.push(formatStepValue(originValue)); // Put offset step value also | ||
}); | ||
// Min & Max | ||
potentialValues.push(min, max); | ||
// In case origin value is align with mark but not with step | ||
potentialValues.push(formatStepValue(originValue)); | ||
// Put offset step value also | ||
var sign = offset > 0 ? 1 : -1; | ||
if (mode === 'unit') { | ||
@@ -95,12 +85,11 @@ potentialValues.push(formatStepValue(originValue + sign * step)); | ||
potentialValues.push(formatStepValue(targetDistValue)); | ||
} // Find close one | ||
} | ||
// Find close one | ||
potentialValues = potentialValues.filter(function (val) { | ||
return val !== null; | ||
}) // Remove reverse value | ||
}) | ||
// Remove reverse value | ||
.filter(function (val) { | ||
return offset < 0 ? val <= originValue : val >= originValue; | ||
}); | ||
if (mode === 'unit') { | ||
@@ -112,3 +101,2 @@ // `unit` mode can not contain itself | ||
} | ||
var compareValue = mode === 'unit' ? originValue : targetDistValue; | ||
@@ -119,3 +107,2 @@ nextValue = potentialValues[0]; | ||
var dist = Math.abs(potentialValue - compareValue); | ||
if (dist < valueDist) { | ||
@@ -125,14 +112,12 @@ nextValue = potentialValue; | ||
} | ||
}); // Out of range will back to range | ||
}); | ||
// Out of range will back to range | ||
if (nextValue === undefined) { | ||
return offset < 0 ? min : max; | ||
} // `dist` mode | ||
} | ||
// `dist` mode | ||
if (mode === 'dist') { | ||
return nextValue; | ||
} // `unit` mode may need another round | ||
} | ||
// `unit` mode may need another round | ||
if (Math.abs(offset) > 1) { | ||
@@ -143,3 +128,2 @@ var cloneValues = (0, _toConsumableArray2.default)(values); | ||
} | ||
return nextValue; | ||
@@ -153,4 +137,2 @@ } else if (offset === 'min') { | ||
/** Same as `offsetValue` but return `changed` mark to tell value changed */ | ||
var offsetChangedValue = function offsetChangedValue(values, offset, valueIndex) { | ||
@@ -165,8 +147,6 @@ var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unit'; | ||
}; | ||
var needPush = function needPush(dist) { | ||
return pushable === null && dist === 0 || typeof pushable === 'number' && dist < pushable; | ||
}; // Values | ||
}; | ||
// Values | ||
var offsetValues = function offsetValues(values, offset, valueIndex) { | ||
@@ -178,11 +158,9 @@ var mode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'unit'; | ||
nextValues[valueIndex] = nextValue; | ||
if (allowCross === false) { | ||
// >>>>> Allow Cross | ||
var pushNum = pushable || 0; // ============ AllowCross =============== | ||
var pushNum = pushable || 0; | ||
// ============ AllowCross =============== | ||
if (valueIndex > 0 && nextValues[valueIndex - 1] !== originValue) { | ||
nextValues[valueIndex] = Math.max(nextValues[valueIndex], nextValues[valueIndex - 1] + pushNum); | ||
} | ||
if (valueIndex < nextValues.length - 1 && nextValues[valueIndex + 1] !== originValue) { | ||
@@ -198,43 +176,32 @@ nextValues[valueIndex] = Math.min(nextValues[valueIndex], nextValues[valueIndex + 1] - pushNum); | ||
var changed = true; | ||
while (needPush(nextValues[i] - nextValues[i - 1]) && changed) { | ||
var _offsetChangedValue = offsetChangedValue(nextValues, 1, i); | ||
nextValues[i] = _offsetChangedValue.value; | ||
changed = _offsetChangedValue.changed; | ||
} | ||
} // Start values | ||
} | ||
// Start values | ||
for (var _i = valueIndex; _i > 0; _i -= 1) { | ||
var _changed = true; | ||
while (needPush(nextValues[_i] - nextValues[_i - 1]) && _changed) { | ||
var _offsetChangedValue2 = offsetChangedValue(nextValues, -1, _i - 1); | ||
nextValues[_i - 1] = _offsetChangedValue2.value; | ||
_changed = _offsetChangedValue2.changed; | ||
} | ||
} // >>>>> Revert back to safe push range | ||
} | ||
// >>>>> Revert back to safe push range | ||
// End to Start | ||
for (var _i2 = nextValues.length - 1; _i2 > 0; _i2 -= 1) { | ||
var _changed2 = true; | ||
while (needPush(nextValues[_i2] - nextValues[_i2 - 1]) && _changed2) { | ||
var _offsetChangedValue3 = offsetChangedValue(nextValues, -1, _i2 - 1); | ||
nextValues[_i2 - 1] = _offsetChangedValue3.value; | ||
_changed2 = _offsetChangedValue3.changed; | ||
} | ||
} // Start to End | ||
} | ||
// Start to End | ||
for (var _i3 = 0; _i3 < nextValues.length - 1; _i3 += 1) { | ||
var _changed3 = true; | ||
while (needPush(nextValues[_i3 + 1] - nextValues[_i3]) && _changed3) { | ||
var _offsetChangedValue4 = offsetChangedValue(nextValues, 1, _i3 + 1); | ||
nextValues[_i3 + 1] = _offsetChangedValue4.value; | ||
@@ -245,3 +212,2 @@ _changed3 = _offsetChangedValue4.changed; | ||
} | ||
return { | ||
@@ -252,4 +218,3 @@ value: nextValues[valueIndex], | ||
}; | ||
return [formatValue, offsetValues]; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,6 +8,4 @@ value: true | ||
exports.default = void 0; | ||
var _Slider = _interopRequireDefault(require("./Slider")); | ||
var _default = _Slider.default; | ||
exports.default = _default; |
import type React from 'react'; | ||
export declare type Direction = 'rtl' | 'ltr' | 'ttb' | 'btt'; | ||
export declare type OnStartMove = (e: React.MouseEvent | React.TouchEvent, valueIndex: number) => void; | ||
export declare type AriaValueFormat = (value: number) => string; | ||
export type Direction = 'rtl' | 'ltr' | 'ttb' | 'btt'; | ||
export type OnStartMove = (e: React.MouseEvent | React.TouchEvent, valueIndex: number) => void; | ||
export type AriaValueFormat = (value: number) => string; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,17 +9,15 @@ value: true | ||
exports.default = Marks; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _Mark = _interopRequireDefault(require("./Mark")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Marks(props) { | ||
var prefixCls = props.prefixCls, | ||
marks = props.marks, | ||
onClick = props.onClick; | ||
var markPrefixCls = "".concat(prefixCls, "-mark"); // Not render mark if empty | ||
marks = props.marks, | ||
onClick = props.onClick; | ||
var markPrefixCls = "".concat(prefixCls, "-mark"); | ||
// Not render mark if empty | ||
if (!marks.length) { | ||
return null; | ||
} | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -31,4 +27,4 @@ className: markPrefixCls | ||
var value = _ref.value, | ||
style = _ref.style, | ||
label = _ref.label; | ||
style = _ref.style, | ||
label = _ref.label; | ||
return /*#__PURE__*/React.createElement(_Mark.default, { | ||
@@ -35,0 +31,0 @@ key: value, |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,32 +9,25 @@ value: true | ||
exports.default = Mark; | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _util = require("../util"); | ||
var _context = _interopRequireDefault(require("../context")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Mark(props) { | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
children = props.children, | ||
value = props.value, | ||
_onClick = props.onClick; | ||
style = props.style, | ||
children = props.children, | ||
value = props.value, | ||
_onClick = props.onClick; | ||
var _React$useContext = React.useContext(_context.default), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd, | ||
included = _React$useContext.included; | ||
var textCls = "".concat(prefixCls, "-text"); // ============================ Offset ============================ | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd, | ||
included = _React$useContext.included; | ||
var textCls = "".concat(prefixCls, "-text"); | ||
// ============================ Offset ============================ | ||
var positionStyle = (0, _util.getDirectionStyle)(direction, value, min, max); | ||
@@ -43,0 +34,0 @@ return /*#__PURE__*/React.createElement("span", { |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof3 = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,85 +9,69 @@ value: true | ||
exports.default = void 0; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _shallowequal = _interopRequireDefault(require("shallowequal")); | ||
var _isEqual = _interopRequireDefault(require("rc-util/lib/isEqual")); | ||
var _useMergedState3 = _interopRequireDefault(require("rc-util/lib/hooks/useMergedState")); | ||
var _Handles = _interopRequireDefault(require("./Handles")); | ||
var _useDrag3 = _interopRequireDefault(require("./hooks/useDrag")); | ||
var _context = _interopRequireDefault(require("./context")); | ||
var _Tracks = _interopRequireDefault(require("./Tracks")); | ||
var _Marks = _interopRequireDefault(require("./Marks")); | ||
var _Steps = _interopRequireDefault(require("./Steps")); | ||
var _useOffset3 = _interopRequireDefault(require("./hooks/useOffset")); | ||
var _warning = _interopRequireDefault(require("rc-util/lib/warning")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var Slider = /*#__PURE__*/React.forwardRef(function (props, ref) { | ||
var _classNames; | ||
var _props$prefixCls = props.prefixCls, | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-slider' : _props$prefixCls, | ||
className = props.className, | ||
style = props.style, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$keyboard = props.keyboard, | ||
keyboard = _props$keyboard === void 0 ? true : _props$keyboard, | ||
autoFocus = props.autoFocus, | ||
onFocus = props.onFocus, | ||
onBlur = props.onBlur, | ||
_props$min = props.min, | ||
min = _props$min === void 0 ? 0 : _props$min, | ||
_props$max = props.max, | ||
max = _props$max === void 0 ? 100 : _props$max, | ||
_props$step = props.step, | ||
step = _props$step === void 0 ? 1 : _props$step, | ||
value = props.value, | ||
defaultValue = props.defaultValue, | ||
range = props.range, | ||
count = props.count, | ||
onChange = props.onChange, | ||
onBeforeChange = props.onBeforeChange, | ||
onAfterChange = props.onAfterChange, | ||
_props$allowCross = props.allowCross, | ||
allowCross = _props$allowCross === void 0 ? true : _props$allowCross, | ||
_props$pushable = props.pushable, | ||
pushable = _props$pushable === void 0 ? false : _props$pushable, | ||
draggableTrack = props.draggableTrack, | ||
reverse = props.reverse, | ||
vertical = props.vertical, | ||
_props$included = props.included, | ||
included = _props$included === void 0 ? true : _props$included, | ||
startPoint = props.startPoint, | ||
trackStyle = props.trackStyle, | ||
handleStyle = props.handleStyle, | ||
railStyle = props.railStyle, | ||
dotStyle = props.dotStyle, | ||
activeDotStyle = props.activeDotStyle, | ||
marks = props.marks, | ||
dots = props.dots, | ||
handleRender = props.handleRender, | ||
_props$tabIndex = props.tabIndex, | ||
tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex, | ||
ariaLabelForHandle = props.ariaLabelForHandle, | ||
ariaLabelledByForHandle = props.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = props.ariaValueTextFormatterForHandle; | ||
prefixCls = _props$prefixCls === void 0 ? 'rc-slider' : _props$prefixCls, | ||
className = props.className, | ||
style = props.style, | ||
_props$disabled = props.disabled, | ||
disabled = _props$disabled === void 0 ? false : _props$disabled, | ||
_props$keyboard = props.keyboard, | ||
keyboard = _props$keyboard === void 0 ? true : _props$keyboard, | ||
autoFocus = props.autoFocus, | ||
onFocus = props.onFocus, | ||
onBlur = props.onBlur, | ||
_props$min = props.min, | ||
min = _props$min === void 0 ? 0 : _props$min, | ||
_props$max = props.max, | ||
max = _props$max === void 0 ? 100 : _props$max, | ||
_props$step = props.step, | ||
step = _props$step === void 0 ? 1 : _props$step, | ||
value = props.value, | ||
defaultValue = props.defaultValue, | ||
range = props.range, | ||
count = props.count, | ||
onChange = props.onChange, | ||
onBeforeChange = props.onBeforeChange, | ||
onAfterChange = props.onAfterChange, | ||
_props$allowCross = props.allowCross, | ||
allowCross = _props$allowCross === void 0 ? true : _props$allowCross, | ||
_props$pushable = props.pushable, | ||
pushable = _props$pushable === void 0 ? false : _props$pushable, | ||
draggableTrack = props.draggableTrack, | ||
reverse = props.reverse, | ||
vertical = props.vertical, | ||
_props$included = props.included, | ||
included = _props$included === void 0 ? true : _props$included, | ||
startPoint = props.startPoint, | ||
trackStyle = props.trackStyle, | ||
handleStyle = props.handleStyle, | ||
railStyle = props.railStyle, | ||
dotStyle = props.dotStyle, | ||
activeDotStyle = props.activeDotStyle, | ||
marks = props.marks, | ||
dots = props.dots, | ||
handleRender = props.handleRender, | ||
_props$tabIndex = props.tabIndex, | ||
tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex, | ||
ariaLabelForHandle = props.ariaLabelForHandle, | ||
ariaLabelledByForHandle = props.ariaLabelledByForHandle, | ||
ariaValueTextFormatterForHandle = props.ariaValueTextFormatterForHandle; | ||
var handlesRef = React.useRef(); | ||
@@ -101,6 +83,5 @@ var containerRef = React.useRef(); | ||
} | ||
return reverse ? 'rtl' : 'ltr'; | ||
}, [reverse, vertical]); // ============================ Range ============================= | ||
}, [reverse, vertical]); | ||
// ============================ Range ============================= | ||
var mergedMin = React.useMemo(function () { | ||
@@ -111,8 +92,8 @@ return isFinite(min) ? min : 0; | ||
return isFinite(max) ? max : 100; | ||
}, [max]); // ============================= Step ============================= | ||
}, [max]); | ||
// ============================= Step ============================= | ||
var mergedStep = React.useMemo(function () { | ||
return step !== null && step <= 0 ? 1 : step; | ||
}, [step]); // ============================= Push ============================= | ||
}, [step]); | ||
// ============================= Push ============================= | ||
var mergedPush = React.useMemo(function () { | ||
@@ -122,6 +103,5 @@ if (pushable === true) { | ||
} | ||
return pushable >= 0 ? pushable : false; | ||
}, [pushable, mergedStep]); // ============================ Marks ============================= | ||
}, [pushable, mergedStep]); | ||
// ============================ Marks ============================= | ||
var markList = React.useMemo(function () { | ||
@@ -134,3 +114,2 @@ var keys = Object.keys(marks || {}); | ||
}; | ||
if (mark && (0, _typeof2.default)(mark) === 'object' && ! /*#__PURE__*/React.isValidElement(mark) && ('label' in mark || 'style' in mark)) { | ||
@@ -142,3 +121,2 @@ markObj.style = mark.style; | ||
} | ||
return markObj; | ||
@@ -151,46 +129,39 @@ }).filter(function (_ref) { | ||
}); | ||
}, [marks]); // ============================ Format ============================ | ||
}, [marks]); | ||
// ============================ Format ============================ | ||
var _useOffset = (0, _useOffset3.default)(mergedMin, mergedMax, mergedStep, markList, allowCross, mergedPush), | ||
_useOffset2 = (0, _slicedToArray2.default)(_useOffset, 2), | ||
formatValue = _useOffset2[0], | ||
offsetValues = _useOffset2[1]; // ============================ Values ============================ | ||
_useOffset2 = (0, _slicedToArray2.default)(_useOffset, 2), | ||
formatValue = _useOffset2[0], | ||
offsetValues = _useOffset2[1]; | ||
// ============================ Values ============================ | ||
var _useMergedState = (0, _useMergedState3.default)(defaultValue, { | ||
value: value | ||
}), | ||
_useMergedState2 = (0, _slicedToArray2.default)(_useMergedState, 2), | ||
mergedValue = _useMergedState2[0], | ||
setValue = _useMergedState2[1]; | ||
value: value | ||
}), | ||
_useMergedState2 = (0, _slicedToArray2.default)(_useMergedState, 2), | ||
mergedValue = _useMergedState2[0], | ||
setValue = _useMergedState2[1]; | ||
var rawValues = React.useMemo(function () { | ||
var valueList = mergedValue === null || mergedValue === undefined ? [] : Array.isArray(mergedValue) ? mergedValue : [mergedValue]; | ||
var _valueList = (0, _slicedToArray2.default)(valueList, 1), | ||
_valueList$ = _valueList[0], | ||
val0 = _valueList$ === void 0 ? mergedMin : _valueList$; | ||
var returnValues = mergedValue === null ? [] : [val0]; // Format as range | ||
_valueList$ = _valueList[0], | ||
val0 = _valueList$ === void 0 ? mergedMin : _valueList$; | ||
var returnValues = mergedValue === null ? [] : [val0]; | ||
// Format as range | ||
if (range) { | ||
returnValues = (0, _toConsumableArray2.default)(valueList); // When count provided or value is `undefined`, we fill values | ||
returnValues = (0, _toConsumableArray2.default)(valueList); | ||
// When count provided or value is `undefined`, we fill values | ||
if (count || mergedValue === undefined) { | ||
var pointCount = count >= 0 ? count + 1 : 2; | ||
returnValues = returnValues.slice(0, pointCount); // Fill with count | ||
returnValues = returnValues.slice(0, pointCount); | ||
// Fill with count | ||
while (returnValues.length < pointCount) { | ||
var _returnValues; | ||
returnValues.push((_returnValues = returnValues[returnValues.length - 1]) !== null && _returnValues !== void 0 ? _returnValues : mergedMin); | ||
} | ||
} | ||
returnValues.sort(function (a, b) { | ||
return a - b; | ||
}); | ||
} // Align in range | ||
} | ||
// Align in range | ||
returnValues.forEach(function (val, index) { | ||
@@ -200,11 +171,9 @@ returnValues[index] = formatValue(val); | ||
return returnValues; | ||
}, [mergedValue, range, mergedMin, count, formatValue]); // =========================== onChange =========================== | ||
}, [mergedValue, range, mergedMin, count, formatValue]); | ||
// =========================== onChange =========================== | ||
var rawValuesRef = React.useRef(rawValues); | ||
rawValuesRef.current = rawValues; | ||
var getTriggerValue = function getTriggerValue(triggerValues) { | ||
return range ? triggerValues : triggerValues[0]; | ||
}; | ||
var triggerChange = function triggerChange(nextValues) { | ||
@@ -214,12 +183,10 @@ // Order first | ||
return a - b; | ||
}); // Trigger event if needed | ||
if (onChange && !(0, _shallowequal.default)(cloneNextValues, rawValuesRef.current)) { | ||
}); | ||
// Trigger event if needed | ||
if (onChange && !(0, _isEqual.default)(cloneNextValues, rawValuesRef.current, true)) { | ||
onChange(getTriggerValue(cloneNextValues)); | ||
} // We set this later since it will re-render component immediately | ||
} | ||
// We set this later since it will re-render component immediately | ||
setValue(cloneNextValues); | ||
}; | ||
var changeToCloseValue = function changeToCloseValue(newValue) { | ||
@@ -231,3 +198,2 @@ if (!disabled) { | ||
var dist = Math.abs(newValue - val); | ||
if (dist <= valueDist) { | ||
@@ -237,11 +203,10 @@ valueDist = dist; | ||
} | ||
}); // Create new values | ||
}); | ||
// Create new values | ||
var cloneNextValues = (0, _toConsumableArray2.default)(rawValues); | ||
cloneNextValues[valueIndex] = newValue; // Fill value to match default 2 | ||
cloneNextValues[valueIndex] = newValue; | ||
// Fill value to match default 2 | ||
if (range && !rawValues.length && count === undefined) { | ||
cloneNextValues.push(newValue); | ||
} | ||
onBeforeChange === null || onBeforeChange === void 0 ? void 0 : onBeforeChange(getTriggerValue(cloneNextValues)); | ||
@@ -251,20 +216,16 @@ triggerChange(cloneNextValues); | ||
} | ||
}; // ============================ Click ============================= | ||
}; | ||
// ============================ Click ============================= | ||
var onSliderMouseDown = function onSliderMouseDown(e) { | ||
e.preventDefault(); | ||
var _containerRef$current = containerRef.current.getBoundingClientRect(), | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height, | ||
left = _containerRef$current.left, | ||
top = _containerRef$current.top, | ||
bottom = _containerRef$current.bottom, | ||
right = _containerRef$current.right; | ||
width = _containerRef$current.width, | ||
height = _containerRef$current.height, | ||
left = _containerRef$current.left, | ||
top = _containerRef$current.top, | ||
bottom = _containerRef$current.bottom, | ||
right = _containerRef$current.right; | ||
var clientX = e.clientX, | ||
clientY = e.clientY; | ||
clientY = e.clientY; | ||
var percent; | ||
switch (direction) { | ||
@@ -274,25 +235,19 @@ case 'btt': | ||
break; | ||
case 'ttb': | ||
percent = (clientY - top) / height; | ||
break; | ||
case 'rtl': | ||
percent = (right - clientX) / width; | ||
break; | ||
default: | ||
percent = (clientX - left) / width; | ||
} | ||
var nextValue = mergedMin + percent * (mergedMax - mergedMin); | ||
changeToCloseValue(formatValue(nextValue)); | ||
}; // =========================== Keyboard =========================== | ||
}; | ||
// =========================== Keyboard =========================== | ||
var _React$useState = React.useState(null), | ||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2), | ||
keyboardValue = _React$useState2[0], | ||
setKeyboardValue = _React$useState2[1]; | ||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2), | ||
keyboardValue = _React$useState2[0], | ||
setKeyboardValue = _React$useState2[1]; | ||
var onHandleOffsetChange = function onHandleOffsetChange(offset, valueIndex) { | ||
@@ -307,7 +262,5 @@ if (!disabled) { | ||
}; | ||
React.useEffect(function () { | ||
if (keyboardValue !== null) { | ||
var valueIndex = rawValues.indexOf(keyboardValue); | ||
if (valueIndex >= 0) { | ||
@@ -317,6 +270,5 @@ handlesRef.current.focus(valueIndex); | ||
} | ||
setKeyboardValue(null); | ||
}, [keyboardValue]); // ============================= Drag ============================= | ||
}, [keyboardValue]); | ||
// ============================= Drag ============================= | ||
var mergedDraggableTrack = React.useMemo(function () { | ||
@@ -327,26 +279,20 @@ if (draggableTrack && mergedStep === null) { | ||
} | ||
return false; | ||
} | ||
return draggableTrack; | ||
}, [draggableTrack, mergedStep]); | ||
var finishChange = function finishChange() { | ||
onAfterChange === null || onAfterChange === void 0 ? void 0 : onAfterChange(getTriggerValue(rawValuesRef.current)); | ||
}; | ||
var _useDrag = (0, _useDrag3.default)(containerRef, direction, rawValues, mergedMin, mergedMax, formatValue, triggerChange, finishChange, offsetValues), | ||
_useDrag2 = (0, _slicedToArray2.default)(_useDrag, 4), | ||
draggingIndex = _useDrag2[0], | ||
draggingValue = _useDrag2[1], | ||
cacheValues = _useDrag2[2], | ||
onStartDrag = _useDrag2[3]; | ||
_useDrag2 = (0, _slicedToArray2.default)(_useDrag, 4), | ||
draggingIndex = _useDrag2[0], | ||
draggingValue = _useDrag2[1], | ||
cacheValues = _useDrag2[2], | ||
onStartDrag = _useDrag2[3]; | ||
var onStartMove = function onStartMove(e, valueIndex) { | ||
onStartDrag(e, valueIndex); | ||
onBeforeChange === null || onBeforeChange === void 0 ? void 0 : onBeforeChange(getTriggerValue(rawValuesRef.current)); | ||
}; // Auto focus for updated handle | ||
}; | ||
// Auto focus for updated handle | ||
var dragging = draggingIndex !== -1; | ||
@@ -358,4 +304,4 @@ React.useEffect(function () { | ||
} | ||
}, [dragging]); // =========================== Included =========================== | ||
}, [dragging]); | ||
// =========================== Included =========================== | ||
var sortedCacheValues = React.useMemo(function () { | ||
@@ -365,17 +311,15 @@ return (0, _toConsumableArray2.default)(cacheValues).sort(function (a, b) { | ||
}); | ||
}, [cacheValues]); // Provide a range values with included [min, max] | ||
}, [cacheValues]); | ||
// Provide a range values with included [min, max] | ||
// Used for Track, Mark & Dot | ||
var _React$useMemo = React.useMemo(function () { | ||
if (!range) { | ||
return [mergedMin, sortedCacheValues[0]]; | ||
} | ||
return [sortedCacheValues[0], sortedCacheValues[sortedCacheValues.length - 1]]; | ||
}, [sortedCacheValues, range, mergedMin]), | ||
_React$useMemo2 = (0, _slicedToArray2.default)(_React$useMemo, 2), | ||
includedStart = _React$useMemo2[0], | ||
includedEnd = _React$useMemo2[1]; // ============================= Refs ============================= | ||
if (!range) { | ||
return [mergedMin, sortedCacheValues[0]]; | ||
} | ||
return [sortedCacheValues[0], sortedCacheValues[sortedCacheValues.length - 1]]; | ||
}, [sortedCacheValues, range, mergedMin]), | ||
_React$useMemo2 = (0, _slicedToArray2.default)(_React$useMemo, 2), | ||
includedStart = _React$useMemo2[0], | ||
includedEnd = _React$useMemo2[1]; | ||
// ============================= Refs ============================= | ||
React.useImperativeHandle(ref, function () { | ||
@@ -388,4 +332,3 @@ return { | ||
var _document = document, | ||
activeElement = _document.activeElement; | ||
activeElement = _document.activeElement; | ||
if (containerRef.current.contains(activeElement)) { | ||
@@ -396,4 +339,4 @@ activeElement === null || activeElement === void 0 ? void 0 : activeElement.blur(); | ||
}; | ||
}); // ========================== Auto Focus ========================== | ||
}); | ||
// ========================== Auto Focus ========================== | ||
React.useEffect(function () { | ||
@@ -403,4 +346,4 @@ if (autoFocus) { | ||
} | ||
}, []); // =========================== Context ============================ | ||
}, []); | ||
// =========================== Context ============================ | ||
var context = React.useMemo(function () { | ||
@@ -423,4 +366,4 @@ return { | ||
}; | ||
}, [mergedMin, mergedMax, direction, disabled, keyboard, mergedStep, included, includedStart, includedEnd, range, tabIndex, ariaLabelForHandle, ariaLabelledByForHandle, ariaValueTextFormatterForHandle]); // ============================ Render ============================ | ||
}, [mergedMin, mergedMax, direction, disabled, keyboard, mergedStep, included, includedStart, includedEnd, range, tabIndex, ariaLabelForHandle, ariaLabelledByForHandle, ariaValueTextFormatterForHandle]); | ||
// ============================ Render ============================ | ||
return /*#__PURE__*/React.createElement(_context.default.Provider, { | ||
@@ -465,8 +408,6 @@ value: context | ||
}); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Slider.displayName = 'Slider'; | ||
} | ||
var _default = Slider; | ||
exports.default = _default; |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,38 +9,29 @@ value: true | ||
exports.default = Dot; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _util = require("../util"); | ||
var _context = _interopRequireDefault(require("../context")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Dot(props) { | ||
var prefixCls = props.prefixCls, | ||
value = props.value, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
value = props.value, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
var _React$useContext = React.useContext(_context.default), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
included = _React$useContext.included, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd; | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
direction = _React$useContext.direction, | ||
included = _React$useContext.included, | ||
includedStart = _React$useContext.includedStart, | ||
includedEnd = _React$useContext.includedEnd; | ||
var dotClassName = "".concat(prefixCls, "-dot"); | ||
var active = included && includedStart <= value && value <= includedEnd; // ============================ Offset ============================ | ||
var active = included && includedStart <= value && value <= includedEnd; | ||
// ============================ Offset ============================ | ||
var mergedStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _util.getDirectionStyle)(direction, value, min, max)), typeof style === 'function' ? style(value) : style); | ||
if (active) { | ||
mergedStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, mergedStyle), typeof activeStyle === 'function' ? activeStyle(value) : activeStyle); | ||
} | ||
return /*#__PURE__*/React.createElement("span", { | ||
@@ -49,0 +38,0 @@ className: (0, _classnames.default)(dotClassName, (0, _defineProperty2.default)({}, "".concat(dotClassName, "-active"), active)), |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,31 +9,26 @@ value: true | ||
exports.default = Steps; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _context = _interopRequireDefault(require("../context")); | ||
var _Dot = _interopRequireDefault(require("./Dot")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Steps(props) { | ||
var prefixCls = props.prefixCls, | ||
marks = props.marks, | ||
dots = props.dots, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
marks = props.marks, | ||
dots = props.dots, | ||
style = props.style, | ||
activeStyle = props.activeStyle; | ||
var _React$useContext = React.useContext(_context.default), | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
step = _React$useContext.step; | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
step = _React$useContext.step; | ||
var stepDots = React.useMemo(function () { | ||
var dotSet = new Set(); // Add marks | ||
var dotSet = new Set(); | ||
// Add marks | ||
marks.forEach(function (mark) { | ||
dotSet.add(mark.value); | ||
}); // Fill dots | ||
}); | ||
// Fill dots | ||
if (dots && step !== null) { | ||
var current = min; | ||
while (current <= max) { | ||
@@ -46,3 +39,2 @@ dotSet.add(current); | ||
} | ||
return Array.from(dotSet); | ||
@@ -49,0 +41,0 @@ }, [min, max, step, dots, marks]); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,23 +9,18 @@ value: true | ||
exports.default = Tracks; | ||
var React = _interopRequireWildcard(require("react")); | ||
var _context = _interopRequireDefault(require("../context")); | ||
var _Track = _interopRequireDefault(require("./Track")); | ||
var _util = require("../util"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Tracks(props) { | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
values = props.values, | ||
startPoint = props.startPoint, | ||
onStartMove = props.onStartMove; | ||
style = props.style, | ||
values = props.values, | ||
startPoint = props.startPoint, | ||
onStartMove = props.onStartMove; | ||
var _React$useContext = React.useContext(_context.default), | ||
included = _React$useContext.included, | ||
range = _React$useContext.range, | ||
min = _React$useContext.min; | ||
included = _React$useContext.included, | ||
range = _React$useContext.range, | ||
min = _React$useContext.min; | ||
var trackList = React.useMemo(function () { | ||
@@ -39,3 +32,2 @@ if (!range) { | ||
} | ||
var startValue = startPoint !== null && startPoint !== void 0 ? startPoint : min; | ||
@@ -47,7 +39,5 @@ var endValue = values[0]; | ||
}]; | ||
} // Multiple | ||
} | ||
// Multiple | ||
var list = []; | ||
for (var i = 0; i < values.length - 1; i += 1) { | ||
@@ -59,3 +49,2 @@ list.push({ | ||
} | ||
return list; | ||
@@ -65,3 +54,3 @@ }, [values, range, startPoint, min]); | ||
var start = _ref.start, | ||
end = _ref.end; | ||
end = _ref.end; | ||
return /*#__PURE__*/React.createElement(_Track.default, { | ||
@@ -68,0 +57,0 @@ index: index, |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -11,32 +9,26 @@ value: true | ||
exports.default = Track; | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")); | ||
var React = _interopRequireWildcard(require("react")); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _context = _interopRequireDefault(require("../context")); | ||
var _util = require("../util"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function Track(props) { | ||
var prefixCls = props.prefixCls, | ||
style = props.style, | ||
start = props.start, | ||
end = props.end, | ||
index = props.index, | ||
onStartMove = props.onStartMove; | ||
style = props.style, | ||
start = props.start, | ||
end = props.end, | ||
index = props.index, | ||
onStartMove = props.onStartMove; | ||
var _React$useContext = React.useContext(_context.default), | ||
direction = _React$useContext.direction, | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
disabled = _React$useContext.disabled, | ||
range = _React$useContext.range; | ||
direction = _React$useContext.direction, | ||
min = _React$useContext.min, | ||
max = _React$useContext.max, | ||
disabled = _React$useContext.disabled, | ||
range = _React$useContext.range; | ||
var trackPrefixCls = "".concat(prefixCls, "-track"); | ||
var offsetStart = (0, _util.getOffset)(start, min, max); | ||
var offsetEnd = (0, _util.getOffset)(end, min, max); // ============================ Events ============================ | ||
var offsetEnd = (0, _util.getOffset)(end, min, max); | ||
// ============================ Events ============================ | ||
var onInternalStartMove = function onInternalStartMove(e) { | ||
@@ -46,7 +38,5 @@ if (!disabled && onStartMove) { | ||
} | ||
}; // ============================ Render ============================ | ||
}; | ||
// ============================ Render ============================ | ||
var positionStyle = {}; | ||
switch (direction) { | ||
@@ -57,3 +47,2 @@ case 'rtl': | ||
break; | ||
case 'btt': | ||
@@ -63,3 +52,2 @@ positionStyle.bottom = "".concat(offsetStart * 100, "%"); | ||
break; | ||
case 'ttb': | ||
@@ -69,3 +57,2 @@ positionStyle.top = "".concat(offsetStart * 100, "%"); | ||
break; | ||
default: | ||
@@ -75,3 +62,2 @@ positionStyle.left = "".concat(offsetStart * 100, "%"); | ||
} | ||
return /*#__PURE__*/React.createElement("div", { | ||
@@ -78,0 +64,0 @@ className: (0, _classnames.default)(trackPrefixCls, range && "".concat(trackPrefixCls, "-").concat(index + 1)), |
@@ -9,11 +9,8 @@ "use strict"; | ||
exports.getOffset = getOffset; | ||
function getOffset(value, min, max) { | ||
return (value - min) / (max - min); | ||
} | ||
function getDirectionStyle(direction, value, min, max) { | ||
var offset = getOffset(value, min, max); | ||
var positionStyle = {}; | ||
switch (direction) { | ||
@@ -24,3 +21,2 @@ case 'rtl': | ||
break; | ||
case 'btt': | ||
@@ -30,3 +26,2 @@ positionStyle.bottom = "".concat(offset * 100, "%"); | ||
break; | ||
case 'ttb': | ||
@@ -36,3 +31,2 @@ positionStyle.top = "".concat(offset * 100, "%"); | ||
break; | ||
default: | ||
@@ -43,10 +37,7 @@ positionStyle.left = "".concat(offset * 100, "%"); | ||
} | ||
return positionStyle; | ||
} | ||
/** Return index value if is list or return value directly */ | ||
function getIndex(value, index) { | ||
return Array.isArray(value) ? value[index] : value; | ||
} |
{ | ||
"name": "rc-slider", | ||
"version": "10.1.0", | ||
"version": "10.1.1", | ||
"description": "Slider UI component for React", | ||
@@ -54,4 +54,3 @@ "engines": { | ||
"classnames": "^2.2.5", | ||
"rc-util": "^5.18.1", | ||
"shallowequal": "^1.1.0" | ||
"rc-util": "^5.27.0" | ||
}, | ||
@@ -65,3 +64,2 @@ "devDependencies": { | ||
"@types/react-dom": "^16.9.0", | ||
"@types/shallowequal": "^1.1.1", | ||
"@umijs/fabric": "^2.0.0", | ||
@@ -68,0 +66,0 @@ "cross-env": "^7.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145421
5
25
3164
- Removedshallowequal@^1.1.0
- Removedshallowequal@1.1.0(transitive)
Updatedrc-util@^5.27.0