tdesign-vue-next
Version:
TDesign Component for vue-next
569 lines (565 loc) • 23.9 kB
JavaScript
/**
* tdesign v1.19.2
* (c) 2026 tdesign
* @license MIT
*/
import { defineComponent, computed, watch, createVNode, mergeProps } from 'vue';
import dayjs from 'dayjs';
import { isDate, isArray, isFunction } from 'lodash-es';
import { CalendarIcon } from 'tdesign-icons-vue-next';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-c68ea098.js';
import { u as useTNodeJSX } from '../_chunks/dep-7bdccf65.js';
import { u as usePrefixClass } from '../_chunks/dep-e8dd47a9.js';
import { u as useDisabled } from '../_chunks/dep-2ba9b7d0.js';
import { u as useGlobalIcon } from '../_chunks/dep-52eae58a.js';
import '@babel/runtime/helpers/slicedToArray';
import '../_chunks/dep-91fc762d.js';
import { u as useReadonly } from '../_chunks/dep-8be9c790.js';
import '@babel/runtime/helpers/defineProperty';
import { u as useEventForward } from '../_chunks/dep-cd9622b1.js';
import { useSingle } from './hooks/useSingle.js';
import { g as getDefaultFormat, f as formatDate, p as parseToDayjs, a as formatTime } from '../_chunks/dep-dc276a19.js';
import { c as covertToDate, g as getRangeBounds, i as isSame, s as subtractMonth, a as addMonth, e as extractTimeObj } from '../_chunks/dep-43987ea8.js';
import datePickerProps from './props.js';
import { SelectInput } from '../select-input/index.js';
import TSinglePanel from './components/panel/SinglePanel.js';
import { triggerMap } from './utils/index.js';
import { useConfig } from '../config-provider/hooks/useConfig.js';
import '../_chunks/dep-f0f392fb.js';
import '../_chunks/dep-d518fdfb.js';
import '../_chunks/dep-8d4d971b.js';
import '../config-provider/utils/context.js';
import '../_chunks/dep-509ddbe3.js';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/classCallCheck';
import './hooks/useSingleValue.js';
import '../_chunks/dep-e332908e.js';
import '../_chunks/dep-4c859e6d.js';
import '../_chunks/dep-06660d60.js';
import '@babel/runtime/helpers/objectDestructuringEmpty';
import '@babel/runtime/helpers/extends';
import '../_chunks/dep-4d62a805.js';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../_chunks/dep-98d89c71.js';
import '../_chunks/dep-ef7a41ce.js';
import '../popup/container.js';
import '../popup/props.js';
import '../_chunks/dep-d5fc4caa.js';
import '../_chunks/dep-ae3e94b6.js';
import '../select-input/props.js';
import '../select-input/hooks/useMultiple.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../input/index.js';
import '../input/input.js';
import '../input/props.js';
import '../input/hooks/useInput.js';
import '../form/constants/index.js';
import '../input/hooks/useLengthLimit.js';
import '../_chunks/dep-fbf70ecb.js';
import '../input/hooks/useInputEventHandler.js';
import '../input/hooks/useInputWidth.js';
import '../input/input-group.js';
import '../input/input-group-props.js';
import '../tag-input/props.js';
import '../_chunks/dep-c3757953.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/hooks/useTagList.js';
import '../tag/index.js';
import '../tag/tag.js';
import 'tinycolor2';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../_chunks/dep-e9e05226.js';
import '../tag/check-tag-group.js';
import '../tag/check-tag-group-props.js';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../_chunks/dep-2a7145b5.js';
import '../loading/icon/gradient.js';
import '../loading/props.js';
import '../select-input/hooks/useOverlayInnerStyle.js';
import '../select-input/hooks/useSingle.js';
import './components/panel/PanelContent.js';
import './components/base/Header.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '../button/index.js';
import '../button/button.js';
import '../button/props.js';
import '../_chunks/dep-d67d6f8a.js';
import '../input-number/props.js';
import '../input-number/hooks/useInputNumber.js';
import '../_chunks/dep-ae97a686.js';
import '../_chunks/dep-e57ebe10.js';
import '../select/index.js';
import '../select/select.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../common-components/fake-arrow.js';
import '../select/components/select-panel.js';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants/index.js';
import '../checkbox/hooks/useCheckboxLazyLoad.js';
import '../_chunks/dep-6f148007.js';
import '../checkbox/hooks/useKeyboardEvent.js';
import '../checkbox/group.js';
import '../checkbox/checkbox-group-props.js';
import '../_chunks/dep-b36a4e94.js';
import '../select/utils/index.js';
import '../select/constants/index.js';
import '../select/option-group.js';
import '../select/option-group-props.js';
import '../select/props.js';
import '../select/hooks/usePanelVirtualScroll.js';
import '../select/hooks/useKeyboardControl.js';
import '../select/hooks/useSelectOptions.js';
import '../input-adornment/index.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../pagination/props.js';
import '../pagination/hooks/useMoreAction.js';
import '../pagination/hooks/usePaginationClasses.js';
import '../pagination/pagination-mini.js';
import '../pagination/pagination-mini-props.js';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import '../tooltip/props.js';
import '../tooltip/utils/index.js';
import './hooks/useSelectRange.js';
import './components/base/Table.js';
import './components/base/Cell.js';
import '../time-picker/index.js';
import '../time-picker/time-picker.js';
import '../time-picker/panel/time-picker-panel.js';
import '../_chunks/dep-32014f9a.js';
import '../time-picker/props.js';
import '../_chunks/dep-71ded012.js';
import '../time-picker/time-range-picker.js';
import '../range-input/index.js';
import '../range-input/range-input.js';
import '../range-input/props.js';
import '../range-input/range-input-popup.js';
import '../range-input/range-input-popup-props.js';
import '../time-picker/time-range-picker-props.js';
import './components/panel/ExtraContent.js';
import './components/base/Footer.js';
import './hooks/useDisableDate.js';
import './hooks/useTableData.js';
var _DatePicker = defineComponent({
name: "TDatePicker",
props: datePickerProps,
setup: function setup(props2, _ref) {
var slots = _ref.slots;
var COMPONENT_NAME = usePrefixClass("date-picker");
var _useSingle = useSingle(props2),
inputValue = _useSingle.inputValue,
popupVisible = _useSingle.popupVisible,
inputProps = _useSingle.inputProps,
popupProps = _useSingle.popupProps,
isHoverCell = _useSingle.isHoverCell,
cacheValue = _useSingle.cacheValue,
value = _useSingle.value,
year = _useSingle.year,
month = _useSingle.month,
time = _useSingle.time,
inputRef = _useSingle.inputRef,
onChange = _useSingle.onChange;
var isDisabled = useDisabled();
var renderTNodeJSX = useTNodeJSX();
var _useConfig = useConfig("datePicker"),
globalConfig = _useConfig.globalConfig;
var isReadOnly = useReadonly();
var _useGlobalIcon = useGlobalIcon({
CalendarIcon: CalendarIcon
}),
CalendarIcon$1 = _useGlobalIcon.CalendarIcon;
var formatRef = computed(function () {
return getDefaultFormat({
mode: props2.mode,
format: props2.format,
valueType: props2.valueType,
enableTimePicker: props2.multiple ? false : props2.enableTimePicker
});
});
var valueDisplayParams = computed(function () {
return {
value: value.value,
displayValue: inputValue.value
};
});
watch(popupVisible, function (visible) {
var _formatRef$value;
if (props2.multiple) return;
if (!props2.needConfirm && props2.enableTimePicker && !visible) {
var nextValue = formatDate(inputValue.value, {
format: formatRef.value.format
});
if (nextValue) {
onChange === null || onChange === void 0 || onChange(formatDate(inputValue.value, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType,
defaultTime: props2.defaultTime
}), {
dayjsValue: parseToDayjs(inputValue.value, formatRef.value.format, void 0, void 0, props2.defaultTime),
trigger: "confirm"
});
} else {
inputValue.value = formatDate(value.value, {
format: formatRef.value.format
});
}
}
var dateValue = value.value && !isDate(value.value) && !["week", "quarter"].includes(props2.mode) ? covertToDate(value.value, (_formatRef$value = formatRef.value) === null || _formatRef$value === void 0 ? void 0 : _formatRef$value.valueType) : value.value;
cacheValue.value = formatDate(dateValue, {
format: formatRef.value.valueType,
targetFormat: formatRef.value.format
});
inputValue.value = formatDate(dateValue, {
format: formatRef.value.valueType,
targetFormat: formatRef.value.format
});
if (visible) {
if ((props2.range && isArray(props2.range) || props2.panelActiveDate) && !value.value) {
var _rangeBounds$min$getF, _rangeBounds$min, _rangeBounds$max, _rangeBounds$min$getM, _rangeBounds$min2, _rangeBounds$max2, _props2$panelActiveDa, _props2$panelActiveDa2, _props2$panelActiveDa3, _props2$panelActiveDa4;
var rangeBounds = getRangeBounds(props2.range);
var yearFromRange = (_rangeBounds$min$getF = (_rangeBounds$min = rangeBounds.min) === null || _rangeBounds$min === void 0 ? void 0 : _rangeBounds$min.getFullYear()) !== null && _rangeBounds$min$getF !== void 0 ? _rangeBounds$min$getF : (_rangeBounds$max = rangeBounds.max) === null || _rangeBounds$max === void 0 ? void 0 : _rangeBounds$max.getFullYear();
var monthFromRange = (_rangeBounds$min$getM = (_rangeBounds$min2 = rangeBounds.min) === null || _rangeBounds$min2 === void 0 ? void 0 : _rangeBounds$min2.getMonth()) !== null && _rangeBounds$min$getM !== void 0 ? _rangeBounds$min$getM : (_rangeBounds$max2 = rangeBounds.max) === null || _rangeBounds$max2 === void 0 ? void 0 : _rangeBounds$max2.getMonth();
year.value = (_props2$panelActiveDa = (_props2$panelActiveDa2 = props2.panelActiveDate) === null || _props2$panelActiveDa2 === void 0 ? void 0 : _props2$panelActiveDa2.year) !== null && _props2$panelActiveDa !== void 0 ? _props2$panelActiveDa : yearFromRange;
month.value = (_props2$panelActiveDa3 = props2.panelActiveDate) !== null && _props2$panelActiveDa3 !== void 0 && _props2$panelActiveDa3.month ? Number((_props2$panelActiveDa4 = props2.panelActiveDate) === null || _props2$panelActiveDa4 === void 0 ? void 0 : _props2$panelActiveDa4.month) - 1 : monthFromRange;
} else {
year.value = parseToDayjs(value.value, formatRef.value.valueType).year();
month.value = parseToDayjs(value.value, formatRef.value.format).month();
}
time.value = formatTime(value.value, formatRef.value.format, formatRef.value.timeFormat, props2.defaultTime);
} else {
isHoverCell.value = false;
}
});
function onCellMouseEnter(date) {
if (props2.multiple) return;
isHoverCell.value = true;
inputValue.value = formatDate(date, {
format: formatRef.value.format
});
}
function onCellMouseLeave() {
if (props2.multiple) return;
isHoverCell.value = false;
inputValue.value = formatDate(cacheValue.value, {
format: formatRef.value.format
});
}
function onCellClick(date) {
var _props2$onPick;
isHoverCell.value = false;
if (props2.mode === "date") {
year.value = date.getFullYear();
month.value = date.getMonth();
}
if (props2.enableTimePicker) {
cacheValue.value = formatDate(date, {
format: formatRef.value.format
});
} else {
if (props2.multiple) {
var newDate = processDate(date, props2.defaultTime);
onChange(newDate, {
dayjsValue: parseToDayjs(date, formatRef.value.format, void 0, void 0, props2.defaultTime),
trigger: "pick"
});
return;
}
onChange === null || onChange === void 0 || onChange(formatDate(date, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType,
defaultTime: props2.defaultTime
}), {
dayjsValue: parseToDayjs(date, formatRef.value.format, void 0, void 0, props2.defaultTime),
trigger: "pick"
});
popupVisible.value = false;
}
(_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 || _props2$onPick.call(props2, date);
}
function processDate(date, defaultTime) {
var isSameDate;
var currentValue = value.value || [];
var dayjsLocale = globalConfig.value.dayjsLocale;
var currentDate;
if (props2.mode !== "week") isSameDate = currentValue.some(function (val) {
return isSame(parseToDayjs(val, formatRef.value.format).toDate(), date, props2.mode, dayjsLocale);
});else {
isSameDate = currentValue.some(function (val) {
return val === dayjs(date).locale(dayjsLocale).format(formatRef.value.format);
});
}
if (!isSameDate) {
currentDate = currentValue.concat(formatDate(date, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType,
defaultTime: defaultTime
}));
} else {
currentDate = currentValue.filter(function (val) {
return formatDate(val, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType,
defaultTime: defaultTime
}) !== formatDate(date, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType,
defaultTime: defaultTime
});
});
}
return currentDate;
}
function onTagRemoveClick(ctx) {
if (["week", "quarter"].includes(props2.mode)) {
onChange === null || onChange === void 0 || onChange(ctx.value, {
trigger: "tag-remove"
});
return;
}
var removeDate = dayjs(ctx.item).toDate();
var newDate = processDate(removeDate, props2.defaultTime);
onChange === null || onChange === void 0 || onChange(newDate, {
dayjsValue: parseToDayjs(removeDate, formatRef.value.format, void 0, void 0, props2.defaultTime),
trigger: "tag-remove"
});
}
function onTagClearClick(_ref2) {
var _props2$onClear;
var e = _ref2.e;
e.stopPropagation();
popupVisible.value = false;
onChange === null || onChange === void 0 || onChange(props2.multiple ? [] : "", {
dayjsValue: dayjs(),
trigger: "clear"
});
(_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 || _props2$onClear.call(props2, {
e: e
});
}
function onJumperClick(_ref3) {
var trigger = _ref3.trigger;
var monthCountMap = {
date: 1,
week: 1,
month: 12,
quarter: 12,
year: 120
};
var monthCount = monthCountMap[props2.mode] || 0;
var current = new Date(year.value, month.value);
var next = null;
if (trigger === "prev") {
next = subtractMonth(current, monthCount);
} else if (trigger === "current") {
next = new Date();
} else if (trigger === "next") {
next = addMonth(current, monthCount);
}
var nextYear = next.getFullYear();
var nextMonth = next.getMonth();
var yearChanged = year.value !== nextYear;
var monthChanged = month.value !== nextMonth;
year.value = nextYear;
month.value = nextMonth;
if (yearChanged) {
var _props2$onYearChange;
(_props2$onYearChange = props2.onYearChange) === null || _props2$onYearChange === void 0 || _props2$onYearChange.call(props2, {
year: nextYear,
date: new Date(nextYear, nextMonth),
trigger: trigger === "current" ? "today" : "year-".concat(triggerMap[trigger])
});
}
if (monthChanged) {
var _props2$onMonthChange;
(_props2$onMonthChange = props2.onMonthChange) === null || _props2$onMonthChange === void 0 || _props2$onMonthChange.call(props2, {
month: nextMonth,
date: new Date(nextYear, nextMonth),
trigger: trigger === "current" ? "today" : "month-".concat(triggerMap[trigger])
});
}
}
function onTimePickerChange(val) {
var _props2$onPick2;
time.value = val;
var _extractTimeObj = extractTimeObj(val),
hours = _extractTimeObj.hours,
minutes = _extractTimeObj.minutes,
seconds = _extractTimeObj.seconds,
milliseconds = _extractTimeObj.milliseconds,
meridiem = _extractTimeObj.meridiem;
var nextHours = hours;
if (/am/i.test(meridiem) && nextHours === 12) nextHours -= 12;
if (/pm/i.test(meridiem) && nextHours < 12) nextHours += 12;
var currentDate = !dayjs(inputValue.value, formatRef.value.format).isValid() ? dayjs() : dayjs(inputValue.value, formatRef.value.format);
var nextDate = currentDate.hour(nextHours).minute(minutes).second(seconds).millisecond(milliseconds).toDate();
inputValue.value = formatDate(nextDate, {
format: formatRef.value.format
});
cacheValue.value = formatDate(nextDate, {
format: formatRef.value.format
});
(_props2$onPick2 = props2.onPick) === null || _props2$onPick2 === void 0 || _props2$onPick2.call(props2, nextDate);
}
function onConfirmClick(_ref4) {
var e = _ref4.e;
var nextValue = formatDate(inputValue.value, {
format: formatRef.value.format
});
if (nextValue) {
var _props2$onConfirm;
props2 === null || props2 === void 0 || (_props2$onConfirm = props2.onConfirm) === null || _props2$onConfirm === void 0 || _props2$onConfirm.call(props2, {
date: dayjs(nextValue).toDate(),
e: e
});
onChange === null || onChange === void 0 || onChange(formatDate(inputValue.value, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType,
defaultTime: props2.defaultTime
}), {
dayjsValue: parseToDayjs(inputValue.value, formatRef.value.format, void 0, void 0, props2.defaultTime),
trigger: "confirm"
});
} else {
inputValue.value = formatDate(value.value, {
format: formatRef.value.format
});
}
popupVisible.value = false;
}
function onPresetClick(presetValue, context) {
var _props2$onPresetClick;
var presetVal = isFunction(presetValue) ? presetValue() : presetValue;
onChange === null || onChange === void 0 || onChange(formatDate(presetVal, {
format: formatRef.value.format,
targetFormat: formatRef.value.valueType
}), {
dayjsValue: parseToDayjs(presetVal, formatRef.value.format, void 0, void 0, props2.defaultTime),
trigger: "preset"
});
inputValue.value = formatDate(presetVal, {
format: formatRef.value.format
});
popupVisible.value = false;
(_props2$onPresetClick = props2.onPresetClick) === null || _props2$onPresetClick === void 0 || _props2$onPresetClick.call(props2, context);
}
function onYearChange(nextYear) {
var _props2$onYearChange2;
year.value = nextYear;
(_props2$onYearChange2 = props2.onYearChange) === null || _props2$onYearChange2 === void 0 || _props2$onYearChange2.call(props2, {
year: nextYear,
date: dayjs(value.value).toDate(),
trigger: "year-select"
});
}
function onMonthChange(nextMonth) {
var _props2$onMonthChange2;
month.value = nextMonth;
(_props2$onMonthChange2 = props2.onMonthChange) === null || _props2$onMonthChange2 === void 0 || _props2$onMonthChange2.call(props2, {
month: nextMonth,
date: dayjs(value.value).toDate(),
trigger: "month-select"
});
}
var panelProps = computed(function () {
return {
value: cacheValue.value,
year: year.value,
month: month.value,
format: formatRef.value.format,
mode: props2.mode,
presets: props2.presets,
multiple: props2.multiple,
time: props2.multiple ? "" : time.value,
disableDate: props2.disableDate,
firstDayOfWeek: props2.firstDayOfWeek,
timePickerProps: props2.timePickerProps,
enableTimePicker: props2.multiple ? false : props2.enableTimePicker,
presetsPlacement: props2.presetsPlacement,
popupVisible: popupVisible.value,
needConfirm: props2.needConfirm,
disableTime: props2.disableTime,
range: props2.range,
cell: props2.cell,
onCellClick: onCellClick,
onCellMouseEnter: onCellMouseEnter,
onCellMouseLeave: onCellMouseLeave,
onJumperClick: onJumperClick,
onConfirmClick: onConfirmClick,
onPresetClick: onPresetClick,
onYearChange: onYearChange,
onMonthChange: onMonthChange,
onTimePickerChange: onTimePickerChange,
onPanelClick: function onPanelClick() {
var _inputRef$value, _inputRef$value$focus;
return (_inputRef$value = inputRef.value) === null || _inputRef$value === void 0 || (_inputRef$value$focus = _inputRef$value.focus) === null || _inputRef$value$focus === void 0 ? void 0 : _inputRef$value$focus.call(_inputRef$value);
}
};
});
var selectInputEvents = useEventForward(props2.selectInputProps, {
onClear: onTagClearClick
});
return function () {
return createVNode("div", {
"class": COMPONENT_NAME.value
}, [createVNode(SelectInput, mergeProps({
"borderless": props2.borderless,
"disabled": isDisabled.value,
"value": inputValue.value,
"label": function label() {
return renderTNodeJSX("label");
},
"status": props2.status,
"tips": props2.tips,
"clearable": props2.clearable,
"readonly": isReadOnly.value,
"multiple": props2.multiple,
"popupProps": popupProps.value,
"inputProps": inputProps.value,
"placeholder": props2.placeholder || globalConfig.value.placeholder[props2.mode],
"popupVisible": !isReadOnly.value && popupVisible.value,
"valueDisplay": function valueDisplay() {
return renderTNodeJSX("valueDisplay", {
params: valueDisplayParams.value
});
}
}, props2.selectInputProps, {
"panel": function panel() {
return createVNode(TSinglePanel, panelProps.value, slots);
},
"tagInputProps": {
onRemove: onTagRemoveClick
},
"prefixIcon": function prefixIcon() {
return renderTNodeJSX("prefixIcon");
},
"suffixIcon": function suffixIcon() {
return renderTNodeJSX("suffixIcon") || createVNode(CalendarIcon$1, null, null);
}
}, selectInputEvents.value), null)]);
};
}
});
export { _DatePicker as default };
//# sourceMappingURL=DatePicker.js.map