This commit is contained in:
2025-09-24 20:35:15 +08:00
parent 39679f7330
commit 8a458ff0a4
12033 changed files with 1537546 additions and 13292 deletions

View File

@@ -0,0 +1,323 @@
import { defineComponent, inject, ref, computed, unref, onMounted, nextTick, watch, openBlock, createElementBlock, normalizeClass, Fragment, renderList, createBlock, withCtx, createTextVNode, toDisplayString, createCommentVNode, withDirectives, createVNode, createElementVNode } from 'vue';
import { debounce } from 'lodash-unified';
import { ElScrollbar } from '../../../scrollbar/index.mjs';
import { ElIcon } from '../../../icon/index.mjs';
import { ArrowUp, ArrowDown } from '@element-plus/icons-vue';
import { PICKER_BASE_INJECTION_KEY, timeUnits, DEFAULT_FORMATS_TIME } from '../constants.mjs';
import { buildTimeList } from '../utils.mjs';
import { basicTimeSpinnerProps } from '../props/basic-time-spinner.mjs';
import { getTimeLists } from '../composables/use-time-picker.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
import { vRepeatClick } from '../../../../directives/repeat-click/index.mjs';
import { CHANGE_EVENT } from '../../../../constants/event.mjs';
import { useNamespace } from '../../../../hooks/use-namespace/index.mjs';
import { getStyle } from '../../../../utils/dom/style.mjs';
import { isNumber } from '../../../../utils/types.mjs';
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "basic-time-spinner",
props: basicTimeSpinnerProps,
emits: [CHANGE_EVENT, "select-range", "set-option"],
setup(__props, { emit }) {
const props = __props;
const pickerBase = inject(PICKER_BASE_INJECTION_KEY);
const { isRange, format } = pickerBase.props;
const ns = useNamespace("time");
const { getHoursList, getMinutesList, getSecondsList } = getTimeLists(props.disabledHours, props.disabledMinutes, props.disabledSeconds);
let isScrolling = false;
const currentScrollbar = ref();
const listHoursRef = ref();
const listMinutesRef = ref();
const listSecondsRef = ref();
const listRefsMap = {
hours: listHoursRef,
minutes: listMinutesRef,
seconds: listSecondsRef
};
const spinnerItems = computed(() => {
return props.showSeconds ? timeUnits : timeUnits.slice(0, 2);
});
const timePartials = computed(() => {
const { spinnerDate } = props;
const hours = spinnerDate.hour();
const minutes = spinnerDate.minute();
const seconds = spinnerDate.second();
return { hours, minutes, seconds };
});
const timeList = computed(() => {
const { hours, minutes } = unref(timePartials);
const { role, spinnerDate } = props;
const compare = !isRange ? spinnerDate : void 0;
return {
hours: getHoursList(role, compare),
minutes: getMinutesList(hours, role, compare),
seconds: getSecondsList(hours, minutes, role, compare)
};
});
const arrowControlTimeList = computed(() => {
const { hours, minutes, seconds } = unref(timePartials);
return {
hours: buildTimeList(hours, 23),
minutes: buildTimeList(minutes, 59),
seconds: buildTimeList(seconds, 59)
};
});
const debouncedResetScroll = debounce((type) => {
isScrolling = false;
adjustCurrentSpinner(type);
}, 200);
const getAmPmFlag = (hour) => {
const shouldShowAmPm = !!props.amPmMode;
if (!shouldShowAmPm)
return "";
const isCapital = props.amPmMode === "A";
let content = hour < 12 ? " am" : " pm";
if (isCapital)
content = content.toUpperCase();
return content;
};
const emitSelectRange = (type) => {
let range = [0, 0];
const actualFormat = format || DEFAULT_FORMATS_TIME;
const hourIndex = actualFormat.indexOf("HH");
const minuteIndex = actualFormat.indexOf("mm");
const secondIndex = actualFormat.indexOf("ss");
switch (type) {
case "hours":
if (hourIndex !== -1) {
range = [hourIndex, hourIndex + 2];
}
break;
case "minutes":
if (minuteIndex !== -1) {
range = [minuteIndex, minuteIndex + 2];
}
break;
case "seconds":
if (secondIndex !== -1) {
range = [secondIndex, secondIndex + 2];
}
break;
}
const [left, right] = range;
emit("select-range", left, right);
currentScrollbar.value = type;
};
const adjustCurrentSpinner = (type) => {
adjustSpinner(type, unref(timePartials)[type]);
};
const adjustSpinners = () => {
adjustCurrentSpinner("hours");
adjustCurrentSpinner("minutes");
adjustCurrentSpinner("seconds");
};
const getScrollbarElement = (el) => el.querySelector(`.${ns.namespace.value}-scrollbar__wrap`);
const adjustSpinner = (type, value) => {
if (props.arrowControl)
return;
const scrollbar = unref(listRefsMap[type]);
if (scrollbar && scrollbar.$el) {
getScrollbarElement(scrollbar.$el).scrollTop = Math.max(0, value * typeItemHeight(type));
}
};
const typeItemHeight = (type) => {
const scrollbar = unref(listRefsMap[type]);
const listItem = scrollbar == null ? void 0 : scrollbar.$el.querySelector("li");
if (listItem) {
return Number.parseFloat(getStyle(listItem, "height")) || 0;
}
return 0;
};
const onIncrement = () => {
scrollDown(1);
};
const onDecrement = () => {
scrollDown(-1);
};
const scrollDown = (step) => {
if (!currentScrollbar.value) {
emitSelectRange("hours");
}
const label = currentScrollbar.value;
const now = unref(timePartials)[label];
const total = currentScrollbar.value === "hours" ? 24 : 60;
const next = findNextUnDisabled(label, now, step, total);
modifyDateField(label, next);
adjustSpinner(label, next);
nextTick(() => emitSelectRange(label));
};
const findNextUnDisabled = (type, now, step, total) => {
let next = (now + step + total) % total;
const list = unref(timeList)[type];
while (list[next] && next !== now) {
next = (next + step + total) % total;
}
return next;
};
const modifyDateField = (type, value) => {
const list = unref(timeList)[type];
const isDisabled = list[value];
if (isDisabled)
return;
const { hours, minutes, seconds } = unref(timePartials);
let changeTo;
switch (type) {
case "hours":
changeTo = props.spinnerDate.hour(value).minute(minutes).second(seconds);
break;
case "minutes":
changeTo = props.spinnerDate.hour(hours).minute(value).second(seconds);
break;
case "seconds":
changeTo = props.spinnerDate.hour(hours).minute(minutes).second(value);
break;
}
emit(CHANGE_EVENT, changeTo);
};
const handleClick = (type, { value, disabled }) => {
if (!disabled) {
modifyDateField(type, value);
emitSelectRange(type);
adjustSpinner(type, value);
}
};
const handleScroll = (type) => {
const scrollbar = unref(listRefsMap[type]);
if (!scrollbar)
return;
isScrolling = true;
debouncedResetScroll(type);
const value = Math.min(Math.round((getScrollbarElement(scrollbar.$el).scrollTop - (scrollBarHeight(type) * 0.5 - 10) / typeItemHeight(type) + 3) / typeItemHeight(type)), type === "hours" ? 23 : 59);
modifyDateField(type, value);
};
const scrollBarHeight = (type) => {
return unref(listRefsMap[type]).$el.offsetHeight;
};
const bindScrollEvent = () => {
const bindFunction = (type) => {
const scrollbar = unref(listRefsMap[type]);
if (scrollbar && scrollbar.$el) {
getScrollbarElement(scrollbar.$el).onscroll = () => {
handleScroll(type);
};
}
};
bindFunction("hours");
bindFunction("minutes");
bindFunction("seconds");
};
onMounted(() => {
nextTick(() => {
!props.arrowControl && bindScrollEvent();
adjustSpinners();
if (props.role === "start")
emitSelectRange("hours");
});
});
const setRef = (scrollbar, type) => {
listRefsMap[type].value = scrollbar != null ? scrollbar : void 0;
};
emit("set-option", [`${props.role}_scrollDown`, scrollDown]);
emit("set-option", [`${props.role}_emitSelectRange`, emitSelectRange]);
watch(() => props.spinnerDate, () => {
if (isScrolling)
return;
adjustSpinners();
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass([unref(ns).b("spinner"), { "has-seconds": _ctx.showSeconds }])
}, [
!_ctx.arrowControl ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(unref(spinnerItems), (item) => {
return openBlock(), createBlock(unref(ElScrollbar), {
key: item,
ref_for: true,
ref: (scrollbar) => setRef(scrollbar, item),
class: normalizeClass(unref(ns).be("spinner", "wrapper")),
"wrap-style": "max-height: inherit;",
"view-class": unref(ns).be("spinner", "list"),
noresize: "",
tag: "ul",
onMouseenter: ($event) => emitSelectRange(item),
onMousemove: ($event) => adjustCurrentSpinner(item)
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(timeList)[item], (disabled, key) => {
return openBlock(), createElementBlock("li", {
key,
class: normalizeClass([
unref(ns).be("spinner", "item"),
unref(ns).is("active", key === unref(timePartials)[item]),
unref(ns).is("disabled", disabled)
]),
onClick: ($event) => handleClick(item, { value: key, disabled })
}, [
item === "hours" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
createTextVNode(toDisplayString(("0" + (_ctx.amPmMode ? key % 12 || 12 : key)).slice(-2)) + toDisplayString(getAmPmFlag(key)), 1)
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
createTextVNode(toDisplayString(("0" + key).slice(-2)), 1)
], 64))
], 10, ["onClick"]);
}), 128))
]),
_: 2
}, 1032, ["class", "view-class", "onMouseenter", "onMousemove"]);
}), 128)) : createCommentVNode("v-if", true),
_ctx.arrowControl ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(spinnerItems), (item) => {
return openBlock(), createElementBlock("div", {
key: item,
class: normalizeClass([unref(ns).be("spinner", "wrapper"), unref(ns).is("arrow")]),
onMouseenter: ($event) => emitSelectRange(item)
}, [
withDirectives((openBlock(), createBlock(unref(ElIcon), {
class: normalizeClass(["arrow-up", unref(ns).be("spinner", "arrow")])
}, {
default: withCtx(() => [
createVNode(unref(ArrowUp))
]),
_: 1
}, 8, ["class"])), [
[unref(vRepeatClick), onDecrement]
]),
withDirectives((openBlock(), createBlock(unref(ElIcon), {
class: normalizeClass(["arrow-down", unref(ns).be("spinner", "arrow")])
}, {
default: withCtx(() => [
createVNode(unref(ArrowDown))
]),
_: 1
}, 8, ["class"])), [
[unref(vRepeatClick), onIncrement]
]),
createElementVNode("ul", {
class: normalizeClass(unref(ns).be("spinner", "list"))
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(arrowControlTimeList)[item], (time, key) => {
return openBlock(), createElementBlock("li", {
key,
class: normalizeClass([
unref(ns).be("spinner", "item"),
unref(ns).is("active", time === unref(timePartials)[item]),
unref(ns).is("disabled", unref(timeList)[item][time])
])
}, [
unref(isNumber)(time) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
item === "hours" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
createTextVNode(toDisplayString(("0" + (_ctx.amPmMode ? time % 12 || 12 : time)).slice(-2)) + toDisplayString(getAmPmFlag(time)), 1)
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
createTextVNode(toDisplayString(("0" + time).slice(-2)), 1)
], 64))
], 64)) : createCommentVNode("v-if", true)
], 2);
}), 128))
], 2)
], 42, ["onMouseenter"]);
}), 128)) : createCommentVNode("v-if", true)
], 2);
};
}
});
var TimeSpinner = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "basic-time-spinner.vue"]]);
export { TimeSpinner as default };
//# sourceMappingURL=basic-time-spinner.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,82 @@
declare const _default: import("vue").DefineComponent<{
readonly disabledHours: {
readonly type: import("vue").PropType<import("element-plus").GetDisabledHours>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly disabledMinutes: {
readonly type: import("vue").PropType<import("element-plus").GetDisabledMinutes>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly disabledSeconds: {
readonly type: import("vue").PropType<import("element-plus").GetDisabledSeconds>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly role: {
readonly type: import("vue").PropType<string>;
readonly required: true;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly spinnerDate: {
readonly type: import("vue").PropType<import("dayjs").Dayjs>;
readonly required: true;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly showSeconds: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, true, boolean>;
readonly arrowControl: BooleanConstructor;
readonly amPmMode: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "" | "a" | "A") | (() => "" | "a" | "A") | ((new (...args: any[]) => "" | "a" | "A") | (() => "" | "a" | "A"))[], unknown, unknown, "", boolean>;
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
change: (...args: any[]) => void;
"select-range": (...args: any[]) => void;
"set-option": (...args: any[]) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
readonly disabledHours: {
readonly type: import("vue").PropType<import("element-plus").GetDisabledHours>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly disabledMinutes: {
readonly type: import("vue").PropType<import("element-plus").GetDisabledMinutes>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly disabledSeconds: {
readonly type: import("vue").PropType<import("element-plus").GetDisabledSeconds>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly role: {
readonly type: import("vue").PropType<string>;
readonly required: true;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly spinnerDate: {
readonly type: import("vue").PropType<import("dayjs").Dayjs>;
readonly required: true;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly showSeconds: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, true, boolean>;
readonly arrowControl: BooleanConstructor;
readonly amPmMode: import("element-plus/es/utils").EpPropFinalized<(new (...args: any[]) => "" | "a" | "A") | (() => "" | "a" | "A") | ((new (...args: any[]) => "" | "a" | "A") | (() => "" | "a" | "A"))[], unknown, unknown, "", boolean>;
}>> & {
onChange?: ((...args: any[]) => any) | undefined;
"onSelect-range"?: ((...args: any[]) => any) | undefined;
"onSet-option"?: ((...args: any[]) => any) | undefined;
}, {
readonly arrowControl: boolean;
readonly showSeconds: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
readonly amPmMode: import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => "" | "a" | "A") | (() => "" | "a" | "A") | ((new (...args: any[]) => "" | "a" | "A") | (() => "" | "a" | "A"))[], unknown, unknown>;
}>;
export default _default;

View File

@@ -0,0 +1,185 @@
import { defineComponent, inject, ref, computed, openBlock, createBlock, Transition, unref, withCtx, createElementBlock, normalizeClass, createElementVNode, createVNode, toDisplayString, createCommentVNode } from 'vue';
import dayjs from 'dayjs';
import { PICKER_BASE_INJECTION_KEY } from '../constants.mjs';
import { panelTimePickerProps } from '../props/panel-time-picker.mjs';
import { useTimePanel } from '../composables/use-time-panel.mjs';
import { useOldValue, buildAvailableTimeSlotGetter } from '../composables/use-time-picker.mjs';
import TimeSpinner from './basic-time-spinner.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../../hooks/use-namespace/index.mjs';
import { useLocale } from '../../../../hooks/use-locale/index.mjs';
import { isUndefined } from '../../../../utils/types.mjs';
import { EVENT_CODE } from '../../../../constants/aria.mjs';
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "panel-time-pick",
props: panelTimePickerProps,
emits: ["pick", "select-range", "set-picker-option"],
setup(__props, { emit }) {
const props = __props;
const pickerBase = inject(PICKER_BASE_INJECTION_KEY);
const {
arrowControl,
disabledHours,
disabledMinutes,
disabledSeconds,
defaultValue
} = pickerBase.props;
const { getAvailableHours, getAvailableMinutes, getAvailableSeconds } = buildAvailableTimeSlotGetter(disabledHours, disabledMinutes, disabledSeconds);
const ns = useNamespace("time");
const { t, lang } = useLocale();
const selectionRange = ref([0, 2]);
const oldValue = useOldValue(props);
const transitionName = computed(() => {
return isUndefined(props.actualVisible) ? `${ns.namespace.value}-zoom-in-top` : "";
});
const showSeconds = computed(() => {
return props.format.includes("ss");
});
const amPmMode = computed(() => {
if (props.format.includes("A"))
return "A";
if (props.format.includes("a"))
return "a";
return "";
});
const isValidValue = (_date) => {
const parsedDate = dayjs(_date).locale(lang.value);
const result = getRangeAvailableTime(parsedDate);
return parsedDate.isSame(result);
};
const handleCancel = () => {
emit("pick", oldValue.value, false);
};
const handleConfirm = (visible = false, first = false) => {
if (first)
return;
emit("pick", props.parsedValue, visible);
};
const handleChange = (_date) => {
if (!props.visible) {
return;
}
const result = getRangeAvailableTime(_date).millisecond(0);
emit("pick", result, true);
};
const setSelectionRange = (start, end) => {
emit("select-range", start, end);
selectionRange.value = [start, end];
};
const changeSelectionRange = (step) => {
const actualFormat = props.format;
const hourIndex = actualFormat.indexOf("HH");
const minuteIndex = actualFormat.indexOf("mm");
const secondIndex = actualFormat.indexOf("ss");
const list = [];
const mapping = [];
if (hourIndex !== -1) {
list.push(hourIndex);
mapping.push("hours");
}
if (minuteIndex !== -1) {
list.push(minuteIndex);
mapping.push("minutes");
}
if (secondIndex !== -1 && showSeconds.value) {
list.push(secondIndex);
mapping.push("seconds");
}
const index = list.indexOf(selectionRange.value[0]);
const next = (index + step + list.length) % list.length;
timePickerOptions["start_emitSelectRange"](mapping[next]);
};
const handleKeydown = (event) => {
const code = event.code;
const { left, right, up, down } = EVENT_CODE;
if ([left, right].includes(code)) {
const step = code === left ? -1 : 1;
changeSelectionRange(step);
event.preventDefault();
return;
}
if ([up, down].includes(code)) {
const step = code === up ? -1 : 1;
timePickerOptions["start_scrollDown"](step);
event.preventDefault();
return;
}
};
const { timePickerOptions, onSetOption, getAvailableTime } = useTimePanel({
getAvailableHours,
getAvailableMinutes,
getAvailableSeconds
});
const getRangeAvailableTime = (date) => {
return getAvailableTime(date, props.datetimeRole || "", true);
};
const parseUserInput = (value) => {
if (!value)
return null;
return dayjs(value, props.format).locale(lang.value);
};
const formatToString = (value) => {
if (!value)
return null;
return value.format(props.format);
};
const getDefaultValue = () => {
return dayjs(defaultValue).locale(lang.value);
};
emit("set-picker-option", ["isValidValue", isValidValue]);
emit("set-picker-option", ["formatToString", formatToString]);
emit("set-picker-option", ["parseUserInput", parseUserInput]);
emit("set-picker-option", ["handleKeydownInput", handleKeydown]);
emit("set-picker-option", ["getRangeAvailableTime", getRangeAvailableTime]);
emit("set-picker-option", ["getDefaultValue", getDefaultValue]);
return (_ctx, _cache) => {
return openBlock(), createBlock(Transition, { name: unref(transitionName) }, {
default: withCtx(() => [
_ctx.actualVisible || _ctx.visible ? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass(unref(ns).b("panel"))
}, [
createElementVNode("div", {
class: normalizeClass([unref(ns).be("panel", "content"), { "has-seconds": unref(showSeconds) }])
}, [
createVNode(TimeSpinner, {
ref: "spinner",
role: _ctx.datetimeRole || "start",
"arrow-control": unref(arrowControl),
"show-seconds": unref(showSeconds),
"am-pm-mode": unref(amPmMode),
"spinner-date": _ctx.parsedValue,
"disabled-hours": unref(disabledHours),
"disabled-minutes": unref(disabledMinutes),
"disabled-seconds": unref(disabledSeconds),
onChange: handleChange,
onSetOption: unref(onSetOption),
onSelectRange: setSelectionRange
}, null, 8, ["role", "arrow-control", "show-seconds", "am-pm-mode", "spinner-date", "disabled-hours", "disabled-minutes", "disabled-seconds", "onSetOption"])
], 2),
createElementVNode("div", {
class: normalizeClass(unref(ns).be("panel", "footer"))
}, [
createElementVNode("button", {
type: "button",
class: normalizeClass([unref(ns).be("panel", "btn"), "cancel"]),
onClick: handleCancel
}, toDisplayString(unref(t)("el.datepicker.cancel")), 3),
createElementVNode("button", {
type: "button",
class: normalizeClass([unref(ns).be("panel", "btn"), "confirm"]),
onClick: ($event) => handleConfirm()
}, toDisplayString(unref(t)("el.datepicker.confirm")), 11, ["onClick"])
], 2)
], 2)) : createCommentVNode("v-if", true)
]),
_: 1
}, 8, ["name"]);
};
}
});
var TimePickPanel = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "panel-time-pick.vue"]]);
export { TimePickPanel as default };
//# sourceMappingURL=panel-time-pick.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,37 @@
import dayjs from 'dayjs';
declare const _default: import("vue").DefineComponent<{
readonly datetimeRole: StringConstructor;
readonly parsedValue: {
readonly type: import("vue").PropType<dayjs.Dayjs>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly visible: BooleanConstructor;
readonly actualVisible: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
readonly format: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
"select-range": (...args: any[]) => void;
pick: (...args: any[]) => void;
"set-picker-option": (...args: any[]) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
readonly datetimeRole: StringConstructor;
readonly parsedValue: {
readonly type: import("vue").PropType<dayjs.Dayjs>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly visible: BooleanConstructor;
readonly actualVisible: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
readonly format: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
}>> & {
onPick?: ((...args: any[]) => any) | undefined;
"onSelect-range"?: ((...args: any[]) => any) | undefined;
"onSet-picker-option"?: ((...args: any[]) => any) | undefined;
}, {
readonly visible: boolean;
readonly format: string;
readonly actualVisible: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
}>;
export default _default;

View File

@@ -0,0 +1,289 @@
import { defineComponent, inject, computed, ref, openBlock, createElementBlock, normalizeClass, unref, createElementVNode, toDisplayString, createVNode, createCommentVNode } from 'vue';
import dayjs from 'dayjs';
import { union } from 'lodash-unified';
import { PICKER_BASE_INJECTION_KEY } from '../constants.mjs';
import { panelTimeRangeProps } from '../props/panel-time-range.mjs';
import { useTimePanel } from '../composables/use-time-panel.mjs';
import { useOldValue, buildAvailableTimeSlotGetter } from '../composables/use-time-picker.mjs';
import TimeSpinner from './basic-time-spinner.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
import { useLocale } from '../../../../hooks/use-locale/index.mjs';
import { useNamespace } from '../../../../hooks/use-namespace/index.mjs';
import { isArray } from '@vue/shared';
import { EVENT_CODE } from '../../../../constants/aria.mjs';
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "panel-time-range",
props: panelTimeRangeProps,
emits: ["pick", "select-range", "set-picker-option"],
setup(__props, { emit }) {
const props = __props;
const makeSelectRange = (start, end) => {
const result = [];
for (let i = start; i <= end; i++) {
result.push(i);
}
return result;
};
const { t, lang } = useLocale();
const nsTime = useNamespace("time");
const nsPicker = useNamespace("picker");
const pickerBase = inject(PICKER_BASE_INJECTION_KEY);
const {
arrowControl,
disabledHours,
disabledMinutes,
disabledSeconds,
defaultValue
} = pickerBase.props;
const startContainerKls = computed(() => [
nsTime.be("range-picker", "body"),
nsTime.be("panel", "content"),
nsTime.is("arrow", arrowControl),
showSeconds.value ? "has-seconds" : ""
]);
const endContainerKls = computed(() => [
nsTime.be("range-picker", "body"),
nsTime.be("panel", "content"),
nsTime.is("arrow", arrowControl),
showSeconds.value ? "has-seconds" : ""
]);
const startTime = computed(() => props.parsedValue[0]);
const endTime = computed(() => props.parsedValue[1]);
const oldValue = useOldValue(props);
const handleCancel = () => {
emit("pick", oldValue.value, false);
};
const showSeconds = computed(() => {
return props.format.includes("ss");
});
const amPmMode = computed(() => {
if (props.format.includes("A"))
return "A";
if (props.format.includes("a"))
return "a";
return "";
});
const handleConfirm = (visible = false) => {
emit("pick", [startTime.value, endTime.value], visible);
};
const handleMinChange = (date) => {
handleChange(date.millisecond(0), endTime.value);
};
const handleMaxChange = (date) => {
handleChange(startTime.value, date.millisecond(0));
};
const isValidValue = (_date) => {
const parsedDate = _date.map((_) => dayjs(_).locale(lang.value));
const result = getRangeAvailableTime(parsedDate);
return parsedDate[0].isSame(result[0]) && parsedDate[1].isSame(result[1]);
};
const handleChange = (start, end) => {
if (!props.visible) {
return;
}
emit("pick", [start, end], true);
};
const btnConfirmDisabled = computed(() => {
return startTime.value > endTime.value;
});
const selectionRange = ref([0, 2]);
const setMinSelectionRange = (start, end) => {
emit("select-range", start, end, "min");
selectionRange.value = [start, end];
};
const offset = computed(() => showSeconds.value ? 11 : 8);
const setMaxSelectionRange = (start, end) => {
emit("select-range", start, end, "max");
const _offset = unref(offset);
selectionRange.value = [start + _offset, end + _offset];
};
const changeSelectionRange = (step) => {
const list = showSeconds.value ? [0, 3, 6, 11, 14, 17] : [0, 3, 8, 11];
const mapping = ["hours", "minutes"].concat(showSeconds.value ? ["seconds"] : []);
const index = list.indexOf(selectionRange.value[0]);
const next = (index + step + list.length) % list.length;
const half = list.length / 2;
if (next < half) {
timePickerOptions["start_emitSelectRange"](mapping[next]);
} else {
timePickerOptions["end_emitSelectRange"](mapping[next - half]);
}
};
const handleKeydown = (event) => {
const code = event.code;
const { left, right, up, down } = EVENT_CODE;
if ([left, right].includes(code)) {
const step = code === left ? -1 : 1;
changeSelectionRange(step);
event.preventDefault();
return;
}
if ([up, down].includes(code)) {
const step = code === up ? -1 : 1;
const role = selectionRange.value[0] < offset.value ? "start" : "end";
timePickerOptions[`${role}_scrollDown`](step);
event.preventDefault();
return;
}
};
const disabledHours_ = (role, compare) => {
const defaultDisable = disabledHours ? disabledHours(role) : [];
const isStart = role === "start";
const compareDate = compare || (isStart ? endTime.value : startTime.value);
const compareHour = compareDate.hour();
const nextDisable = isStart ? makeSelectRange(compareHour + 1, 23) : makeSelectRange(0, compareHour - 1);
return union(defaultDisable, nextDisable);
};
const disabledMinutes_ = (hour, role, compare) => {
const defaultDisable = disabledMinutes ? disabledMinutes(hour, role) : [];
const isStart = role === "start";
const compareDate = compare || (isStart ? endTime.value : startTime.value);
const compareHour = compareDate.hour();
if (hour !== compareHour) {
return defaultDisable;
}
const compareMinute = compareDate.minute();
const nextDisable = isStart ? makeSelectRange(compareMinute + 1, 59) : makeSelectRange(0, compareMinute - 1);
return union(defaultDisable, nextDisable);
};
const disabledSeconds_ = (hour, minute, role, compare) => {
const defaultDisable = disabledSeconds ? disabledSeconds(hour, minute, role) : [];
const isStart = role === "start";
const compareDate = compare || (isStart ? endTime.value : startTime.value);
const compareHour = compareDate.hour();
const compareMinute = compareDate.minute();
if (hour !== compareHour || minute !== compareMinute) {
return defaultDisable;
}
const compareSecond = compareDate.second();
const nextDisable = isStart ? makeSelectRange(compareSecond + 1, 59) : makeSelectRange(0, compareSecond - 1);
return union(defaultDisable, nextDisable);
};
const getRangeAvailableTime = ([start, end]) => {
return [
getAvailableTime(start, "start", true, end),
getAvailableTime(end, "end", false, start)
];
};
const { getAvailableHours, getAvailableMinutes, getAvailableSeconds } = buildAvailableTimeSlotGetter(disabledHours_, disabledMinutes_, disabledSeconds_);
const {
timePickerOptions,
getAvailableTime,
onSetOption
} = useTimePanel({
getAvailableHours,
getAvailableMinutes,
getAvailableSeconds
});
const parseUserInput = (days) => {
if (!days)
return null;
if (isArray(days)) {
return days.map((d) => dayjs(d, props.format).locale(lang.value));
}
return dayjs(days, props.format).locale(lang.value);
};
const formatToString = (days) => {
if (!days)
return null;
if (isArray(days)) {
return days.map((d) => d.format(props.format));
}
return days.format(props.format);
};
const getDefaultValue = () => {
if (isArray(defaultValue)) {
return defaultValue.map((d) => dayjs(d).locale(lang.value));
}
const defaultDay = dayjs(defaultValue).locale(lang.value);
return [defaultDay, defaultDay.add(60, "m")];
};
emit("set-picker-option", ["formatToString", formatToString]);
emit("set-picker-option", ["parseUserInput", parseUserInput]);
emit("set-picker-option", ["isValidValue", isValidValue]);
emit("set-picker-option", ["handleKeydownInput", handleKeydown]);
emit("set-picker-option", ["getDefaultValue", getDefaultValue]);
emit("set-picker-option", ["getRangeAvailableTime", getRangeAvailableTime]);
return (_ctx, _cache) => {
return _ctx.actualVisible ? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass([unref(nsTime).b("range-picker"), unref(nsPicker).b("panel")])
}, [
createElementVNode("div", {
class: normalizeClass(unref(nsTime).be("range-picker", "content"))
}, [
createElementVNode("div", {
class: normalizeClass(unref(nsTime).be("range-picker", "cell"))
}, [
createElementVNode("div", {
class: normalizeClass(unref(nsTime).be("range-picker", "header"))
}, toDisplayString(unref(t)("el.datepicker.startTime")), 3),
createElementVNode("div", {
class: normalizeClass(unref(startContainerKls))
}, [
createVNode(TimeSpinner, {
ref: "minSpinner",
role: "start",
"show-seconds": unref(showSeconds),
"am-pm-mode": unref(amPmMode),
"arrow-control": unref(arrowControl),
"spinner-date": unref(startTime),
"disabled-hours": disabledHours_,
"disabled-minutes": disabledMinutes_,
"disabled-seconds": disabledSeconds_,
onChange: handleMinChange,
onSetOption: unref(onSetOption),
onSelectRange: setMinSelectionRange
}, null, 8, ["show-seconds", "am-pm-mode", "arrow-control", "spinner-date", "onSetOption"])
], 2)
], 2),
createElementVNode("div", {
class: normalizeClass(unref(nsTime).be("range-picker", "cell"))
}, [
createElementVNode("div", {
class: normalizeClass(unref(nsTime).be("range-picker", "header"))
}, toDisplayString(unref(t)("el.datepicker.endTime")), 3),
createElementVNode("div", {
class: normalizeClass(unref(endContainerKls))
}, [
createVNode(TimeSpinner, {
ref: "maxSpinner",
role: "end",
"show-seconds": unref(showSeconds),
"am-pm-mode": unref(amPmMode),
"arrow-control": unref(arrowControl),
"spinner-date": unref(endTime),
"disabled-hours": disabledHours_,
"disabled-minutes": disabledMinutes_,
"disabled-seconds": disabledSeconds_,
onChange: handleMaxChange,
onSetOption: unref(onSetOption),
onSelectRange: setMaxSelectionRange
}, null, 8, ["show-seconds", "am-pm-mode", "arrow-control", "spinner-date", "onSetOption"])
], 2)
], 2)
], 2),
createElementVNode("div", {
class: normalizeClass(unref(nsTime).be("panel", "footer"))
}, [
createElementVNode("button", {
type: "button",
class: normalizeClass([unref(nsTime).be("panel", "btn"), "cancel"]),
onClick: ($event) => handleCancel()
}, toDisplayString(unref(t)("el.datepicker.cancel")), 11, ["onClick"]),
createElementVNode("button", {
type: "button",
class: normalizeClass([unref(nsTime).be("panel", "btn"), "confirm"]),
disabled: unref(btnConfirmDisabled),
onClick: ($event) => handleConfirm()
}, toDisplayString(unref(t)("el.datepicker.confirm")), 11, ["disabled", "onClick"])
], 2)
], 2)) : createCommentVNode("v-if", true);
};
}
});
var TimeRangePanel = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "panel-time-range.vue"]]);
export { TimeRangePanel as default };
//# sourceMappingURL=panel-time-range.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,35 @@
import dayjs from 'dayjs';
declare const _default: import("vue").DefineComponent<{
readonly parsedValue: {
readonly type: import("vue").PropType<[dayjs.Dayjs, dayjs.Dayjs]>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly visible: BooleanConstructor;
readonly actualVisible: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
readonly format: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
"select-range": (...args: any[]) => void;
pick: (...args: any[]) => void;
"set-picker-option": (...args: any[]) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
readonly parsedValue: {
readonly type: import("vue").PropType<[dayjs.Dayjs, dayjs.Dayjs]>;
readonly required: false;
readonly validator: ((val: unknown) => boolean) | undefined;
__epPropKey: true;
};
readonly visible: BooleanConstructor;
readonly actualVisible: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
readonly format: import("element-plus/es/utils").EpPropFinalized<StringConstructor, unknown, unknown, "", boolean>;
}>> & {
onPick?: ((...args: any[]) => any) | undefined;
"onSelect-range"?: ((...args: any[]) => any) | undefined;
"onSet-picker-option"?: ((...args: any[]) => any) | undefined;
}, {
readonly visible: boolean;
readonly format: string;
readonly actualVisible: import("element-plus/es/utils").EpPropMergeType<BooleanConstructor, unknown, unknown>;
}>;
export default _default;