UNPKG

@opensig/opendesign

Version:

54 lines (53 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const dayjs = require("dayjs"); const useFormField = require("../../_composables/use-form-field.js"); const provide = require("../provide.js"); const utils = require("../utils.js"); const is = require("../../_utils/is.js"); const END_UNIT_MAP = { year: "year", month: "month", date: "day", datetime: null }; function toTimestamp(value) { var _a; if (is.isNil(value)) return void 0; return (_a = utils.parseValue(value)) == null ? void 0 : _a.valueOf(); } function formatOut(ts, valueFormat) { return valueFormat === "x" ? ts : dayjs(ts).format(valueFormat); } function useRangePickerBase(opts) { const { props, mode, start, end, emit } = opts; const propsRefs = vue.toRefs(props); const formField = useFormField.useFormField(props, emit); const modeRef = vue.computed(() => mode); const startTimestamp = vue.computed({ get: () => toTimestamp(start.value), set: (ts) => { start.value = is.isNil(ts) ? void 0 : formatOut(ts, props.valueFormat); } }); const endTimestamp = vue.computed({ get: () => toTimestamp(end.value), set: (ts) => { if (is.isNil(ts)) { end.value = void 0; return; } const unit = END_UNIT_MAP[mode]; const finalTs = unit ? dayjs(ts).endOf(unit).valueOf() : ts; end.value = formatOut(finalTs, props.valueFormat); } }); vue.provide(provide.datePickerInjectKey, { ...propsRefs, mode: modeRef, color: formField.effectiveColor }); return { startTimestamp, endTimestamp, ...formField }; } exports.useRangePickerBase = useRangePickerBase;