fix(api): use bcrypt directly instead of passlib for compatibility

This commit is contained in:
bwstudio
2026-05-21 22:18:36 +08:00
parent 7f51d200f1
commit 4651781bc3
23511 changed files with 2587254 additions and 8 deletions
@@ -0,0 +1,7 @@
import { Mark, useMarks } from "./use-marks.js";
import { useLifecycle } from "./use-lifecycle.js";
import { useSlide } from "./use-slide.js";
import { useSliderButton } from "./use-slider-button.js";
import { useStops } from "./use-stops.js";
import { useWatch } from "./use-watch.js";
export { Mark, useLifecycle, useMarks, useSlide, useSliderButton, useStops, useWatch };
@@ -0,0 +1,7 @@
import { useLifecycle } from "./use-lifecycle.mjs";
import { useMarks } from "./use-marks.mjs";
import { useSlide } from "./use-slide.mjs";
import { useSliderButton } from "./use-slider-button.mjs";
import { useStops } from "./use-stops.mjs";
import { useWatch } from "./use-watch.mjs";
export { useLifecycle, useMarks, useSlide, useSliderButton, useStops, useWatch };
@@ -0,0 +1,9 @@
import { SliderInitData, SliderProps } from "../slider.js";
import * as _$vue from "vue";
//#region ../../packages/components/slider/src/composables/use-lifecycle.d.ts
declare const useLifecycle: (props: SliderProps, initData: SliderInitData, resetSize: () => void) => {
sliderWrapper: _$vue.Ref<HTMLElement | undefined, HTMLElement | undefined>;
};
//#endregion
export { useLifecycle };
@@ -0,0 +1,31 @@
import { isArray, isNumber } from "../../../../utils/types.mjs";
import { useEventListener } from "@vueuse/core";
import { nextTick, onMounted, ref } from "vue";
//#region ../../packages/components/slider/src/composables/use-lifecycle.ts
const useLifecycle = (props, initData, resetSize) => {
const sliderWrapper = ref();
onMounted(async () => {
if (props.range) {
if (isArray(props.modelValue)) {
initData.firstValue = Math.max(props.min, props.modelValue[0]);
initData.secondValue = Math.min(props.max, props.modelValue[1]);
} else {
initData.firstValue = props.min;
initData.secondValue = props.max;
}
initData.oldValue = [initData.firstValue, initData.secondValue];
} else {
if (!isNumber(props.modelValue) || Number.isNaN(props.modelValue)) initData.firstValue = props.min;
else initData.firstValue = Math.min(props.max, Math.max(props.min, props.modelValue));
initData.oldValue = initData.firstValue;
}
useEventListener(window, "resize", resetSize);
await nextTick();
resetSize();
});
return { sliderWrapper };
};
//#endregion
export { useLifecycle };
//# sourceMappingURL=use-lifecycle.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"use-lifecycle.mjs","names":[],"sources":["../../../../../../../packages/components/slider/src/composables/use-lifecycle.ts"],"sourcesContent":["import { nextTick, onMounted, ref } from 'vue'\nimport { useEventListener } from '@vueuse/core'\nimport { isArray, isNumber } from '@element-plus/utils'\n\nimport type { SliderInitData, SliderProps } from '../slider'\n\nexport const useLifecycle = (\n props: SliderProps,\n initData: SliderInitData,\n resetSize: () => void\n) => {\n const sliderWrapper = ref<HTMLElement>()\n\n onMounted(async () => {\n if (props.range) {\n if (isArray(props.modelValue)) {\n initData.firstValue = Math.max(props.min, props.modelValue[0])\n initData.secondValue = Math.min(props.max, props.modelValue[1])\n } else {\n initData.firstValue = props.min\n initData.secondValue = props.max\n }\n initData.oldValue = [initData.firstValue, initData.secondValue]\n } else {\n if (!isNumber(props.modelValue) || Number.isNaN(props.modelValue)) {\n initData.firstValue = props.min\n } else {\n initData.firstValue = Math.min(\n props.max,\n Math.max(props.min, props.modelValue)\n )\n }\n initData.oldValue = initData.firstValue\n }\n\n useEventListener(window, 'resize', resetSize)\n\n await nextTick()\n resetSize()\n })\n\n return {\n sliderWrapper,\n }\n}\n"],"mappings":";;;;AAMA,MAAa,gBACX,OACA,UACA,cACG;CACH,MAAM,gBAAgB,KAAkB;CAExC,UAAU,YAAY;EACpB,IAAI,MAAM,OAAO;GACf,IAAI,QAAQ,MAAM,WAAW,EAAE;IAC7B,SAAS,aAAa,KAAK,IAAI,MAAM,KAAK,MAAM,WAAW,GAAG;IAC9D,SAAS,cAAc,KAAK,IAAI,MAAM,KAAK,MAAM,WAAW,GAAG;UAC1D;IACL,SAAS,aAAa,MAAM;IAC5B,SAAS,cAAc,MAAM;;GAE/B,SAAS,WAAW,CAAC,SAAS,YAAY,SAAS,YAAY;SAC1D;GACL,IAAI,CAAC,SAAS,MAAM,WAAW,IAAI,OAAO,MAAM,MAAM,WAAW,EAC/D,SAAS,aAAa,MAAM;QAE5B,SAAS,aAAa,KAAK,IACzB,MAAM,KACN,KAAK,IAAI,MAAM,KAAK,MAAM,WAAW,CACtC;GAEH,SAAS,WAAW,SAAS;;EAG/B,iBAAiB,QAAQ,UAAU,UAAU;EAE7C,MAAM,UAAU;EAChB,WAAW;GACX;CAEF,OAAO,EACL,eACD"}
@@ -0,0 +1,12 @@
import { SliderMarkerProps } from "../marker.js";
import { SliderProps } from "../slider.js";
import * as _$vue from "vue";
//#region ../../packages/components/slider/src/composables/use-marks.d.ts
interface Mark extends SliderMarkerProps {
point: number;
position: number;
}
declare const useMarks: (props: SliderProps) => _$vue.ComputedRef<Mark[]>;
//#endregion
export { Mark, useMarks };
@@ -0,0 +1,30 @@
import { debugWarn } from "../../../../utils/error.mjs";
import { computed, watchEffect } from "vue";
//#region ../../packages/components/slider/src/composables/use-marks.ts
const useMarks = (props) => {
const markList = computed(() => {
if (!props.marks) return [];
return Object.keys(props.marks).map(Number.parseFloat).sort((a, b) => a - b).filter((point) => point <= props.max && point >= props.min).map((point) => ({
point,
position: (point - props.min) * 100 / (props.max - props.min),
mark: props.marks[point]
}));
});
watchEffect(() => {
if (props.step === "mark" && !props.marks) debugWarn("ElSlider", "marks prop must be provided when step is mark");
if (props.marks) {
const keys = Object.keys(props.marks);
const validPoints = markList.value.map((m) => m.point);
const invalidKeys = keys.filter((key) => {
const parsed = Number.parseFloat(key);
return Number.isNaN(parsed) || !validPoints.includes(parsed);
});
if (invalidKeys.length > 0) debugWarn("ElSlider", `Some marks keys are invalid (not a number or out of [min, max]): [${invalidKeys.map((k) => `'${k}'`).join(", ")}] and will be ignored.`);
}
});
return markList;
};
//#endregion
export { useMarks };
//# sourceMappingURL=use-marks.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"use-marks.mjs","names":[],"sources":["../../../../../../../packages/components/slider/src/composables/use-marks.ts"],"sourcesContent":["import { computed, watchEffect } from 'vue'\nimport { debugWarn } from '@element-plus/utils'\n\nimport type { SliderProps } from '../slider'\nimport type { SliderMarkerProps } from '../marker'\n\nexport interface Mark extends SliderMarkerProps {\n point: number\n position: number\n}\n\nexport const useMarks = (props: SliderProps) => {\n const markList = computed(() => {\n if (!props.marks) {\n return []\n }\n const marksKeys = Object.keys(props.marks)\n return marksKeys\n .map(Number.parseFloat)\n .sort((a, b) => a - b)\n .filter((point) => point <= props.max && point >= props.min)\n .map(\n (point): Mark => ({\n point,\n position: ((point - props.min) * 100) / (props.max - props.min),\n mark: props.marks![point],\n })\n )\n })\n\n watchEffect(() => {\n if (props.step === 'mark' && !props.marks) {\n debugWarn('ElSlider', 'marks prop must be provided when step is mark')\n }\n if (props.marks) {\n const keys = Object.keys(props.marks)\n const validPoints = markList.value.map((m) => m.point)\n const invalidKeys = keys.filter((key) => {\n const parsed = Number.parseFloat(key)\n return Number.isNaN(parsed) || !validPoints.includes(parsed)\n })\n if (invalidKeys.length > 0) {\n debugWarn(\n 'ElSlider',\n `Some marks keys are invalid (not a number or out of [min, max]): [${invalidKeys.map((k) => `'${k}'`).join(', ')}] and will be ignored.`\n )\n }\n }\n })\n\n return markList\n}\n"],"mappings":";;;AAWA,MAAa,YAAY,UAAuB;CAC9C,MAAM,WAAW,eAAe;EAC9B,IAAI,CAAC,MAAM,OACT,OAAO,EAAE;EAGX,OADkB,OAAO,KAAK,MAAM,MACpB,CACb,IAAI,OAAO,WAAW,CACtB,MAAM,GAAG,MAAM,IAAI,EAAE,CACrB,QAAQ,UAAU,SAAS,MAAM,OAAO,SAAS,MAAM,IAAI,CAC3D,KACE,WAAiB;GAChB;GACA,WAAY,QAAQ,MAAM,OAAO,OAAQ,MAAM,MAAM,MAAM;GAC3D,MAAM,MAAM,MAAO;GACpB,EACF;GACH;CAEF,kBAAkB;EAChB,IAAI,MAAM,SAAS,UAAU,CAAC,MAAM,OAClC,UAAU,YAAY,gDAAgD;EAExE,IAAI,MAAM,OAAO;GACf,MAAM,OAAO,OAAO,KAAK,MAAM,MAAM;GACrC,MAAM,cAAc,SAAS,MAAM,KAAK,MAAM,EAAE,MAAM;GACtD,MAAM,cAAc,KAAK,QAAQ,QAAQ;IACvC,MAAM,SAAS,OAAO,WAAW,IAAI;IACrC,OAAO,OAAO,MAAM,OAAO,IAAI,CAAC,YAAY,SAAS,OAAO;KAC5D;GACF,IAAI,YAAY,SAAS,GACvB,UACE,YACA,qEAAqE,YAAY,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC,wBAClH;;GAGL;CAEF,OAAO"}
@@ -0,0 +1,29 @@
import { FormItemContext } from "../../../form/src/types.js";
import { SliderEmits, SliderInitData, SliderProps } from "../slider.js";
import { SliderButtonInstance } from "../button.js";
import * as _$vue from "vue";
import { CSSProperties, Ref, SetupContext } from "vue";
//#region ../../packages/components/slider/src/composables/use-slide.d.ts
declare const useSlide: (props: SliderProps, initData: SliderInitData, emit: SetupContext<SliderEmits>["emit"]) => {
elFormItem: FormItemContext | undefined;
slider: _$vue.ShallowRef<HTMLElement | undefined, HTMLElement | undefined>;
firstButton: Ref<SliderButtonInstance | undefined, SliderButtonInstance | undefined>;
secondButton: Ref<SliderButtonInstance | undefined, SliderButtonInstance | undefined>;
sliderDisabled: _$vue.ComputedRef<boolean>;
minValue: _$vue.ComputedRef<number>;
maxValue: _$vue.ComputedRef<number>;
runwayStyle: _$vue.ComputedRef<CSSProperties>;
barStyle: _$vue.ComputedRef<CSSProperties>;
resetSize: () => void;
setPosition: (percent: number) => Ref<SliderButtonInstance | undefined>;
emitChange: () => Promise<void>;
onSliderWrapperPrevent: (event: TouchEvent) => void;
onSliderClick: (event: MouseEvent | TouchEvent) => void;
onSliderDown: (event: MouseEvent | TouchEvent) => Promise<void>;
onSliderMarkerDown: (position: number) => void;
setFirstValue: (firstValue: number | undefined) => void;
setSecondValue: (secondValue: number) => void;
};
//#endregion
export { useSlide };
@@ -0,0 +1,124 @@
import { CHANGE_EVENT, INPUT_EVENT, UPDATE_MODEL_EVENT } from "../../../../constants/event.mjs";
import { useFormDisabled } from "../../../form/src/hooks/use-form-common-props.mjs";
import { useFormItem } from "../../../form/src/hooks/use-form-item.mjs";
import { computed, nextTick, ref, shallowRef } from "vue";
//#region ../../packages/components/slider/src/composables/use-slide.ts
const useSlide = (props, initData, emit) => {
const { formItem: elFormItem } = useFormItem();
const slider = shallowRef();
const firstButton = ref();
const secondButton = ref();
const buttonRefs = {
firstButton,
secondButton
};
const sliderDisabled = useFormDisabled();
const minValue = computed(() => {
return Math.min(initData.firstValue, initData.secondValue);
});
const maxValue = computed(() => {
return Math.max(initData.firstValue, initData.secondValue);
});
const barSize = computed(() => {
return props.range ? `${100 * (maxValue.value - minValue.value) / (props.max - props.min)}%` : `${100 * (initData.firstValue - props.min) / (props.max - props.min)}%`;
});
const barStart = computed(() => {
return props.range ? `${100 * (minValue.value - props.min) / (props.max - props.min)}%` : "0%";
});
const runwayStyle = computed(() => {
return props.vertical ? { height: props.height } : {};
});
const barStyle = computed(() => {
return props.vertical ? {
height: barSize.value,
bottom: barStart.value
} : {
width: barSize.value,
left: barStart.value
};
});
const resetSize = () => {
if (slider.value) initData.sliderSize = slider.value.getBoundingClientRect()[props.vertical ? "height" : "width"];
};
const getButtonRefByPercent = (percent) => {
const targetValue = props.min + percent * (props.max - props.min) / 100;
if (!props.range) return firstButton;
let buttonRefName;
if (Math.abs(minValue.value - targetValue) < Math.abs(maxValue.value - targetValue)) buttonRefName = initData.firstValue < initData.secondValue ? "firstButton" : "secondButton";
else buttonRefName = initData.firstValue > initData.secondValue ? "firstButton" : "secondButton";
return buttonRefs[buttonRefName];
};
const setPosition = (percent) => {
const buttonRef = getButtonRefByPercent(percent);
buttonRef.value.setPosition(percent);
return buttonRef;
};
const setFirstValue = (firstValue) => {
initData.firstValue = firstValue ?? props.min;
_emit(props.range ? [minValue.value, maxValue.value] : firstValue ?? props.min);
};
const setSecondValue = (secondValue) => {
initData.secondValue = secondValue;
if (props.range) _emit([minValue.value, maxValue.value]);
};
const _emit = (val) => {
emit(UPDATE_MODEL_EVENT, val);
emit(INPUT_EVENT, val);
};
const emitChange = async () => {
await nextTick();
emit(CHANGE_EVENT, props.range ? [minValue.value, maxValue.value] : props.modelValue);
};
const handleSliderPointerEvent = (event) => {
if (sliderDisabled.value || initData.dragging) return;
resetSize();
let newPercent = 0;
if (props.vertical) {
const clientY = event.touches?.item(0)?.clientY ?? event.clientY;
newPercent = (slider.value.getBoundingClientRect().bottom - clientY) / initData.sliderSize * 100;
} else newPercent = ((event.touches?.item(0)?.clientX ?? event.clientX) - slider.value.getBoundingClientRect().left) / initData.sliderSize * 100;
if (newPercent < 0 || newPercent > 100) return;
return setPosition(newPercent);
};
const onSliderWrapperPrevent = (event) => {
if (buttonRefs["firstButton"].value?.dragging || buttonRefs["secondButton"].value?.dragging) event.preventDefault();
};
const onSliderDown = async (event) => {
const buttonRef = handleSliderPointerEvent(event);
if (buttonRef) {
await nextTick();
buttonRef.value.onButtonDown(event);
}
};
const onSliderClick = (event) => {
if (handleSliderPointerEvent(event)) emitChange();
};
const onSliderMarkerDown = (position) => {
if (sliderDisabled.value || initData.dragging) return;
if (setPosition(position)) emitChange();
};
return {
elFormItem,
slider,
firstButton,
secondButton,
sliderDisabled,
minValue,
maxValue,
runwayStyle,
barStyle,
resetSize,
setPosition,
emitChange,
onSliderWrapperPrevent,
onSliderClick,
onSliderDown,
onSliderMarkerDown,
setFirstValue,
setSecondValue
};
};
//#endregion
export { useSlide };
//# sourceMappingURL=use-slide.mjs.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,23 @@
import { EpPropMergeType } from "../../../../utils/vue/props/types.js";
import { TooltipInstance } from "../../../tooltip/src/tooltip.js";
import { SliderButtonEmits, SliderButtonInitData, SliderButtonProps } from "../button.js";
import { CSSProperties, ComputedRef, Ref, SetupContext } from "vue";
//#region ../../packages/components/slider/src/composables/use-slider-button.d.ts
declare const useSliderButton: (props: SliderButtonProps, initData: SliderButtonInitData, emit: SetupContext<SliderButtonEmits>["emit"]) => {
disabled: ComputedRef<boolean>;
button: Ref<HTMLDivElement | undefined, HTMLDivElement | undefined>;
tooltip: Ref<TooltipInstance | undefined, TooltipInstance | undefined>;
tooltipVisible: Ref<boolean, boolean>;
showTooltip: Ref<EpPropMergeType<BooleanConstructor, unknown, unknown>, EpPropMergeType<BooleanConstructor, unknown, unknown>>;
persistent: Ref<EpPropMergeType<BooleanConstructor, unknown, unknown>, EpPropMergeType<BooleanConstructor, unknown, unknown>>;
wrapperStyle: ComputedRef<CSSProperties>;
formatValue: ComputedRef<string | number>;
handleMouseEnter: () => void;
handleMouseLeave: () => void;
onButtonDown: (event: MouseEvent | TouchEvent) => void;
onKeyDown: (event: KeyboardEvent) => void;
setPosition: (newPosition: number) => Promise<void>;
};
//#endregion
export { useSliderButton };
@@ -0,0 +1,258 @@
import { EVENT_CODE } from "../../../../constants/aria.mjs";
import { UPDATE_MODEL_EVENT } from "../../../../constants/event.mjs";
import { getEventCode } from "../../../../utils/dom/event.mjs";
import { isNumber } from "../../../../utils/types.mjs";
import { sliderContextKey } from "../constants.mjs";
import { useEventListener } from "@vueuse/core";
import { clamp as clamp$1, debounce } from "lodash-unified";
import { computed, inject, nextTick, ref, watch } from "vue";
//#region ../../packages/components/slider/src/composables/use-slider-button.ts
const useTooltip = (props, formatTooltip, showTooltip) => {
const tooltip = ref();
const tooltipVisible = ref(false);
const enableFormat = computed(() => {
return formatTooltip.value instanceof Function;
});
return {
tooltip,
tooltipVisible,
formatValue: computed(() => {
return enableFormat.value && formatTooltip.value(props.modelValue) || props.modelValue;
}),
displayTooltip: debounce(() => {
showTooltip.value && (tooltipVisible.value = true);
}, 50),
hideTooltip: debounce(() => {
showTooltip.value && (tooltipVisible.value = false);
}, 50)
};
};
const useSliderButton = (props, initData, emit) => {
const { disabled, min, max, step, showTooltip, persistent, precision, sliderSize, formatTooltip, emitChange, resetSize, updateDragging, markList } = inject(sliderContextKey);
const { tooltip, tooltipVisible, formatValue, displayTooltip, hideTooltip } = useTooltip(props, formatTooltip, showTooltip);
const button = ref();
const currentPosition = computed(() => {
return `${(props.modelValue - min.value) / (max.value - min.value) * 100}%`;
});
const wrapperStyle = computed(() => {
return props.vertical ? { bottom: currentPosition.value } : { left: currentPosition.value };
});
const shouldMoveToMark = computed(() => {
return step.value === "mark" && markList.value.length > 0;
});
const handleMouseEnter = () => {
initData.hovering = true;
displayTooltip();
};
const handleMouseLeave = () => {
initData.hovering = false;
if (!initData.dragging) hideTooltip();
};
const onButtonDown = (event) => {
if (disabled.value) return;
event.preventDefault();
onDragStart(event);
window.addEventListener("mousemove", onDragging);
window.addEventListener("touchmove", onDragging);
window.addEventListener("mouseup", onDragEnd);
window.addEventListener("touchend", onDragEnd);
window.addEventListener("contextmenu", onDragEnd);
button.value.focus();
};
const incrementPosition = (amount) => {
if (disabled.value) return;
initData.newPosition = Number.parseFloat(currentPosition.value) + amount / (max.value - min.value) * 100;
setPosition(initData.newPosition);
emitChange();
};
const moveToMark = (amount) => {
if (disabled.value || !markList.value.length) return;
const current = props.modelValue;
const epsilon = Number.EPSILON;
const stride = Math.abs(amount);
let target;
if (amount > 0) {
const startIndex = markList.value.findIndex((m) => m.point > current + epsilon);
if (startIndex !== -1) {
const targetIndex = Math.min(startIndex + stride - 1, markList.value.length - 1);
target = markList.value[targetIndex].point;
}
} else {
let startIndex = -1;
for (let i = markList.value.length - 1; i >= 0; i--) if (markList.value[i].point < current - epsilon) {
startIndex = i;
break;
}
if (startIndex !== -1) {
const targetIndex = Math.max(startIndex - (stride - 1), 0);
target = markList.value[targetIndex].point;
}
}
if (target !== void 0 && target !== current) {
setPosition((target - min.value) / (max.value - min.value) * 100);
emitChange();
}
};
const onLeftKeyDown = () => {
if (shouldMoveToMark.value) moveToMark(-1);
else if (isNumber(step.value)) incrementPosition(-step.value);
};
const onRightKeyDown = () => {
if (shouldMoveToMark.value) moveToMark(1);
else if (isNumber(step.value)) incrementPosition(step.value);
};
const onPageDownKeyDown = () => {
if (shouldMoveToMark.value) moveToMark(-4);
else if (isNumber(step.value)) incrementPosition(-step.value * 4);
};
const onPageUpKeyDown = () => {
if (shouldMoveToMark.value) moveToMark(4);
else if (isNumber(step.value)) incrementPosition(step.value * 4);
};
const onHomeKeyDown = () => {
if (disabled.value) return;
setPosition(0);
emitChange();
};
const onEndKeyDown = () => {
if (disabled.value) return;
setPosition(100);
emitChange();
};
const onKeyDown = (event) => {
const code = getEventCode(event);
let isPreventDefault = true;
switch (code) {
case EVENT_CODE.left:
case EVENT_CODE.down:
onLeftKeyDown();
break;
case EVENT_CODE.right:
case EVENT_CODE.up:
onRightKeyDown();
break;
case EVENT_CODE.home:
onHomeKeyDown();
break;
case EVENT_CODE.end:
onEndKeyDown();
break;
case EVENT_CODE.pageDown:
onPageDownKeyDown();
break;
case EVENT_CODE.pageUp:
onPageUpKeyDown();
break;
default:
isPreventDefault = false;
break;
}
isPreventDefault && event.preventDefault();
};
const getClientXY = (event) => {
let clientX;
let clientY;
if (event.type.startsWith("touch")) {
clientY = event.touches[0].clientY;
clientX = event.touches[0].clientX;
} else {
clientY = event.clientY;
clientX = event.clientX;
}
return {
clientX,
clientY
};
};
const onDragStart = (event) => {
initData.dragging = true;
initData.isClick = true;
const { clientX, clientY } = getClientXY(event);
if (props.vertical) initData.startY = clientY;
else initData.startX = clientX;
initData.startPosition = Number.parseFloat(currentPosition.value);
initData.newPosition = initData.startPosition;
};
const onDragging = (event) => {
if (initData.dragging) {
initData.isClick = false;
displayTooltip();
resetSize();
let diff;
const { clientX, clientY } = getClientXY(event);
if (props.vertical) {
initData.currentY = clientY;
diff = (initData.startY - initData.currentY) / sliderSize.value * 100;
} else {
initData.currentX = clientX;
diff = (initData.currentX - initData.startX) / sliderSize.value * 100;
}
initData.newPosition = initData.startPosition + diff;
setPosition(initData.newPosition);
}
};
const onDragEnd = () => {
if (initData.dragging) {
setTimeout(() => {
initData.dragging = false;
if (!initData.hovering) hideTooltip();
if (!initData.isClick) setPosition(initData.newPosition);
emitChange();
}, 0);
window.removeEventListener("mousemove", onDragging);
window.removeEventListener("touchmove", onDragging);
window.removeEventListener("mouseup", onDragEnd);
window.removeEventListener("touchend", onDragEnd);
window.removeEventListener("contextmenu", onDragEnd);
}
};
const setPosition = async (newPosition) => {
if (newPosition === null || Number.isNaN(+newPosition)) return;
newPosition = clamp$1(newPosition, 0, 100);
let value;
if (step.value === "mark") if (markList.value.length === 0) value = newPosition <= 50 ? min.value : max.value;
else value = markList.value.reduce((prev, curr) => {
return Math.abs(curr.position - newPosition) < Math.abs(prev.position - newPosition) ? curr : prev;
}).point;
else {
const fullSteps = Math.floor((max.value - min.value) / step.value);
const fullRangePercentage = fullSteps * step.value / (max.value - min.value) * 100;
const threshold = fullRangePercentage + (100 - fullRangePercentage) / 2;
if (newPosition < fullRangePercentage) {
const valueBetween = fullRangePercentage / fullSteps;
const steps = Math.round(newPosition / valueBetween);
value = min.value + steps * step.value;
} else if (newPosition < threshold) value = min.value + fullSteps * step.value;
else value = max.value;
value = Number.parseFloat(value.toFixed(precision.value));
}
if (value !== props.modelValue) emit(UPDATE_MODEL_EVENT, value);
if (!initData.dragging && props.modelValue !== initData.oldValue) initData.oldValue = props.modelValue;
await nextTick();
initData.dragging && displayTooltip();
tooltip.value.updatePopper();
};
watch(() => initData.dragging, (val) => {
updateDragging(val);
});
useEventListener(button, "touchstart", onButtonDown, { passive: false });
return {
disabled,
button,
tooltip,
tooltipVisible,
showTooltip,
persistent,
wrapperStyle,
formatValue,
handleMouseEnter,
handleMouseLeave,
onButtonDown,
onKeyDown,
setPosition
};
};
//#endregion
export { useSliderButton };
//# sourceMappingURL=use-slider-button.mjs.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
import { SliderInitData, SliderProps } from "../slider.js";
import { CSSProperties, ComputedRef } from "vue";
//#region ../../packages/components/slider/src/composables/use-stops.d.ts
type Stops = {
stops: ComputedRef<number[]>;
getStopStyle: (position: number) => CSSProperties;
};
declare const useStops: (props: SliderProps, initData: SliderInitData, minValue: ComputedRef<number>, maxValue: ComputedRef<number>) => Stops;
//#endregion
export { useStops };
@@ -0,0 +1,30 @@
import { debugWarn } from "../../../../utils/error.mjs";
import { computed } from "vue";
//#region ../../packages/components/slider/src/composables/use-stops.ts
const useStops = (props, initData, minValue, maxValue) => {
const stops = computed(() => {
if (!props.showStops || props.min > props.max) return [];
if (props.step === "mark" || props.step === 0) {
if (props.step === 0) debugWarn("ElSlider", "step should not be 0.");
return [];
}
const stopCount = Math.ceil((props.max - props.min) / props.step);
const stepWidth = 100 * props.step / (props.max - props.min);
const result = Array.from({ length: stopCount - 1 }).map((_, index) => (index + 1) * stepWidth);
if (props.range) return result.filter((step) => {
return step < 100 * (minValue.value - props.min) / (props.max - props.min) || step > 100 * (maxValue.value - props.min) / (props.max - props.min);
});
else return result.filter((step) => step > 100 * (initData.firstValue - props.min) / (props.max - props.min));
});
const getStopStyle = (position) => {
return props.vertical ? { bottom: `${position}%` } : { left: `${position}%` };
};
return {
stops,
getStopStyle
};
};
//#endregion
export { useStops };
//# sourceMappingURL=use-stops.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"use-stops.mjs","names":[],"sources":["../../../../../../../packages/components/slider/src/composables/use-stops.ts"],"sourcesContent":["import { computed } from 'vue'\nimport { debugWarn } from '@element-plus/utils'\n\nimport type { CSSProperties, ComputedRef } from 'vue'\nimport type { SliderInitData, SliderProps } from '../slider'\n\ntype Stops = {\n stops: ComputedRef<number[]>\n getStopStyle: (position: number) => CSSProperties\n}\n\nexport const useStops = (\n props: SliderProps,\n initData: SliderInitData,\n minValue: ComputedRef<number>,\n maxValue: ComputedRef<number>\n): Stops => {\n const stops = computed(() => {\n if (!props.showStops || props.min > props.max) return []\n if (props.step === 'mark' || props.step === 0) {\n if (props.step === 0) debugWarn('ElSlider', 'step should not be 0.')\n return []\n }\n\n const stopCount = Math.ceil((props.max - props.min) / props.step)\n const stepWidth = (100 * props.step) / (props.max - props.min)\n const result = Array.from<number>({ length: stopCount - 1 }).map(\n (_, index) => (index + 1) * stepWidth\n )\n\n if (props.range) {\n return result.filter((step) => {\n return (\n step <\n (100 * (minValue.value - props.min)) / (props.max - props.min) ||\n step > (100 * (maxValue.value - props.min)) / (props.max - props.min)\n )\n })\n } else {\n return result.filter(\n (step) =>\n step >\n (100 * (initData.firstValue - props.min)) / (props.max - props.min)\n )\n }\n })\n\n const getStopStyle = (position: number): CSSProperties => {\n return props.vertical\n ? { bottom: `${position}%` }\n : { left: `${position}%` }\n }\n\n return {\n stops,\n getStopStyle,\n }\n}\n"],"mappings":";;;AAWA,MAAa,YACX,OACA,UACA,UACA,aACU;CACV,MAAM,QAAQ,eAAe;EAC3B,IAAI,CAAC,MAAM,aAAa,MAAM,MAAM,MAAM,KAAK,OAAO,EAAE;EACxD,IAAI,MAAM,SAAS,UAAU,MAAM,SAAS,GAAG;GAC7C,IAAI,MAAM,SAAS,GAAG,UAAU,YAAY,wBAAwB;GACpE,OAAO,EAAE;;EAGX,MAAM,YAAY,KAAK,MAAM,MAAM,MAAM,MAAM,OAAO,MAAM,KAAK;EACjE,MAAM,YAAa,MAAM,MAAM,QAAS,MAAM,MAAM,MAAM;EAC1D,MAAM,SAAS,MAAM,KAAa,EAAE,QAAQ,YAAY,GAAG,CAAC,CAAC,KAC1D,GAAG,WAAW,QAAQ,KAAK,UAC7B;EAED,IAAI,MAAM,OACR,OAAO,OAAO,QAAQ,SAAS;GAC7B,OACE,OACG,OAAO,SAAS,QAAQ,MAAM,QAAS,MAAM,MAAM,MAAM,QAC5D,OAAQ,OAAO,SAAS,QAAQ,MAAM,QAAS,MAAM,MAAM,MAAM;IAEnE;OAEF,OAAO,OAAO,QACX,SACC,OACC,OAAO,SAAS,aAAa,MAAM,QAAS,MAAM,MAAM,MAAM,KAClE;GAEH;CAEF,MAAM,gBAAgB,aAAoC;EACxD,OAAO,MAAM,WACT,EAAE,QAAQ,GAAG,SAAS,IAAI,GAC1B,EAAE,MAAM,GAAG,SAAS,IAAI;;CAG9B,OAAO;EACL;EACA;EACD"}
@@ -0,0 +1,8 @@
import { FormItemContext } from "../../../form/src/types.js";
import { SliderEmits, SliderInitData, SliderProps } from "../slider.js";
import { ComputedRef, SetupContext } from "vue";
//#region ../../packages/components/slider/src/composables/use-watch.d.ts
declare const useWatch: (props: SliderProps, initData: SliderInitData, minValue: ComputedRef<number>, maxValue: ComputedRef<number>, emit: SetupContext<SliderEmits>["emit"], elFormItem: FormItemContext) => void;
//#endregion
export { useWatch };
@@ -0,0 +1,56 @@
import { INPUT_EVENT, UPDATE_MODEL_EVENT } from "../../../../constants/event.mjs";
import { isArray, isNumber } from "../../../../utils/types.mjs";
import { throwError } from "../../../../utils/error.mjs";
import { NOOP } from "../../../../utils/functions.mjs";
import { watch } from "vue";
//#region ../../packages/components/slider/src/composables/use-watch.ts
const useWatch = (props, initData, minValue, maxValue, emit, elFormItem) => {
const _emit = (val) => {
emit(UPDATE_MODEL_EVENT, val);
emit(INPUT_EVENT, val);
};
const valueChanged = () => {
if (props.range) return ![minValue.value, maxValue.value].every((item, index) => item === initData.oldValue[index]);
else return props.modelValue !== initData.oldValue;
};
const setValues = () => {
if (props.min > props.max) throwError("Slider", "min should not be greater than max.");
const val = props.modelValue;
if (props.range && isArray(val)) if (val[1] < props.min) _emit([props.min, props.min]);
else if (val[0] > props.max) _emit([props.max, props.max]);
else if (val[0] < props.min) _emit([props.min, val[1]]);
else if (val[1] > props.max) _emit([val[0], props.max]);
else {
initData.firstValue = val[0];
initData.secondValue = val[1];
if (valueChanged()) {
if (props.validateEvent) elFormItem?.validate?.("change").catch(NOOP);
initData.oldValue = val.slice();
}
}
else if (!props.range && isNumber(val) && !Number.isNaN(val)) if (val < props.min) _emit(props.min);
else if (val > props.max) _emit(props.max);
else {
initData.firstValue = val;
if (valueChanged()) {
if (props.validateEvent) elFormItem?.validate?.("change").catch(NOOP);
initData.oldValue = val;
}
}
};
setValues();
watch(() => initData.dragging, (val) => {
if (!val) setValues();
});
watch(() => props.modelValue, (val, oldVal) => {
if (initData.dragging || isArray(val) && isArray(oldVal) && val.every((item, index) => item === oldVal[index]) && initData.firstValue === val[0] && initData.secondValue === val[1]) return;
setValues();
}, { deep: true });
watch(() => [props.min, props.max], () => {
setValues();
});
};
//#endregion
export { useWatch };
//# sourceMappingURL=use-watch.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"use-watch.mjs","names":[],"sources":["../../../../../../../packages/components/slider/src/composables/use-watch.ts"],"sourcesContent":["import { watch } from 'vue'\nimport { INPUT_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { NOOP, isArray, isNumber, throwError } from '@element-plus/utils'\n\nimport type { ComputedRef, SetupContext } from 'vue'\nimport type { Arrayable } from '@element-plus/utils'\nimport type { FormItemContext } from '@element-plus/components/form'\nimport type { SliderEmits, SliderInitData, SliderProps } from '../slider'\n\nexport const useWatch = (\n props: SliderProps,\n initData: SliderInitData,\n minValue: ComputedRef<number>,\n maxValue: ComputedRef<number>,\n emit: SetupContext<SliderEmits>['emit'],\n elFormItem: FormItemContext\n) => {\n const _emit = (val: Arrayable<number>) => {\n emit(UPDATE_MODEL_EVENT, val)\n emit(INPUT_EVENT, val)\n }\n\n const valueChanged = () => {\n if (props.range) {\n return ![minValue.value, maxValue.value].every(\n (item, index) => item === (initData.oldValue as number[])[index]\n )\n } else {\n return props.modelValue !== initData.oldValue\n }\n }\n\n const setValues = () => {\n if (props.min > props.max) {\n throwError('Slider', 'min should not be greater than max.')\n }\n const val = props.modelValue\n if (props.range && isArray(val)) {\n if (val[1] < props.min) {\n _emit([props.min, props.min])\n } else if (val[0] > props.max) {\n _emit([props.max, props.max])\n } else if (val[0] < props.min) {\n _emit([props.min, val[1]])\n } else if (val[1] > props.max) {\n _emit([val[0], props.max])\n } else {\n initData.firstValue = val[0]\n initData.secondValue = val[1]\n if (valueChanged()) {\n if (props.validateEvent) {\n elFormItem?.validate?.('change').catch(NOOP)\n }\n initData.oldValue = val.slice()\n }\n }\n } else if (!props.range && isNumber(val) && !Number.isNaN(val)) {\n if (val < props.min) {\n _emit(props.min)\n } else if (val > props.max) {\n _emit(props.max)\n } else {\n initData.firstValue = val\n if (valueChanged()) {\n if (props.validateEvent) {\n elFormItem?.validate?.('change').catch(NOOP)\n }\n initData.oldValue = val\n }\n }\n }\n }\n\n setValues()\n\n watch(\n () => initData.dragging,\n (val) => {\n if (!val) {\n setValues()\n }\n }\n )\n\n watch(\n () => props.modelValue,\n (val, oldVal) => {\n if (\n initData.dragging ||\n (isArray(val) &&\n isArray(oldVal) &&\n val.every((item, index) => item === oldVal[index]) &&\n initData.firstValue === val[0] &&\n initData.secondValue === val[1])\n ) {\n return\n }\n setValues()\n },\n {\n deep: true,\n }\n )\n\n watch(\n () => [props.min, props.max],\n () => {\n setValues()\n }\n )\n}\n"],"mappings":";;;;;;AASA,MAAa,YACX,OACA,UACA,UACA,UACA,MACA,eACG;CACH,MAAM,SAAS,QAA2B;EACxC,KAAK,oBAAoB,IAAI;EAC7B,KAAK,aAAa,IAAI;;CAGxB,MAAM,qBAAqB;EACzB,IAAI,MAAM,OACR,OAAO,CAAC,CAAC,SAAS,OAAO,SAAS,MAAM,CAAC,OACtC,MAAM,UAAU,SAAU,SAAS,SAAsB,OAC3D;OAED,OAAO,MAAM,eAAe,SAAS;;CAIzC,MAAM,kBAAkB;EACtB,IAAI,MAAM,MAAM,MAAM,KACpB,WAAW,UAAU,sCAAsC;EAE7D,MAAM,MAAM,MAAM;EAClB,IAAI,MAAM,SAAS,QAAQ,IAAI,EAC7B,IAAI,IAAI,KAAK,MAAM,KACjB,MAAM,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC;OACxB,IAAI,IAAI,KAAK,MAAM,KACxB,MAAM,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC;OACxB,IAAI,IAAI,KAAK,MAAM,KACxB,MAAM,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC;OACrB,IAAI,IAAI,KAAK,MAAM,KACxB,MAAM,CAAC,IAAI,IAAI,MAAM,IAAI,CAAC;OACrB;GACL,SAAS,aAAa,IAAI;GAC1B,SAAS,cAAc,IAAI;GAC3B,IAAI,cAAc,EAAE;IAClB,IAAI,MAAM,eACR,YAAY,WAAW,SAAS,CAAC,MAAM,KAAK;IAE9C,SAAS,WAAW,IAAI,OAAO;;;OAG9B,IAAI,CAAC,MAAM,SAAS,SAAS,IAAI,IAAI,CAAC,OAAO,MAAM,IAAI,EAC5D,IAAI,MAAM,MAAM,KACd,MAAM,MAAM,IAAI;OACX,IAAI,MAAM,MAAM,KACrB,MAAM,MAAM,IAAI;OACX;GACL,SAAS,aAAa;GACtB,IAAI,cAAc,EAAE;IAClB,IAAI,MAAM,eACR,YAAY,WAAW,SAAS,CAAC,MAAM,KAAK;IAE9C,SAAS,WAAW;;;;CAM5B,WAAW;CAEX,YACQ,SAAS,WACd,QAAQ;EACP,IAAI,CAAC,KACH,WAAW;GAGhB;CAED,YACQ,MAAM,aACX,KAAK,WAAW;EACf,IACE,SAAS,YACR,QAAQ,IAAI,IACX,QAAQ,OAAO,IACf,IAAI,OAAO,MAAM,UAAU,SAAS,OAAO,OAAO,IAClD,SAAS,eAAe,IAAI,MAC5B,SAAS,gBAAgB,IAAI,IAE/B;EAEF,WAAW;IAEb,EACE,MAAM,MACP,CACF;CAED,YACQ,CAAC,MAAM,KAAK,MAAM,IAAI,QACtB;EACJ,WAAW;GAEd"}