UNPKG

@opensig/opendesign

Version:

126 lines (125 loc) 4.88 kB
"use strict"; const vue = require("vue"); const core = require("@vueuse/core"); const index = require("../../popup/index.js"); const clientOnly = require("../../_components/client-only.js"); const index$1 = require("../../divider/index.js"); const vueUtils = require("../../_utils/vue-utils.js"); const provide = require("../provide.js"); const DateRangePanelContent_vue_vue_type_script_setup_true_lang = require("./DateRangePanelContent.vue.js"); const _hoisted_1 = { class: "o-date-panel-footer" }; const _hoisted_2 = { class: "o-date-panel-shortcut" }; const _sfc_main = /* @__PURE__ */ vue.defineComponent({ __name: "DateRangePanel", props: { target: {}, optionTitle: {} }, emits: ["change"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const visible = vue.ref(false); const currentView = vue.ref("date"); const datePickerCtx = vue.inject(provide.datePickerInjectKey); const { size, mode: effectiveMode, transition, popupPosition, popupWrapper } = datePickerCtx; const popupRef = vue.ref(); const contentRef = vue.ref(); const isMainPanel = vue.computed(() => { if (effectiveMode.value === "year") return currentView.value === "year"; if (effectiveMode.value === "month") return currentView.value === "month"; return currentView.value === "date"; }); const getValue = () => { var _a; return ((_a = contentRef.value) == null ? void 0 : _a.getValue()) ?? { start: void 0, end: void 0 }; }; const setValue = (start, end) => { var _a; (_a = contentRef.value) == null ? void 0 : _a.setValue(start, end); }; const open = async (start, end) => { var _a; if (visible.value) return; visible.value = true; await core.until(contentRef).toBeTruthy(); (_a = contentRef.value) == null ? void 0 : _a.init(start, end); }; const close = () => { visible.value = false; }; const handleContentChange = (start, end) => { emits("change", start, end); }; __expose({ getPopupEl: () => popupRef.value, getValue, setValue, open, close }); return (_ctx, _cache) => { return vue.openBlock(), vue.createBlock(vue.unref(clientOnly), null, { default: vue.withCtx(() => [ vue.createVNode(vue.unref(index.OPopup), { visible: visible.value, "onUpdate:visible": _cache[1] || (_cache[1] = ($event) => visible.value = $event), class: vue.normalizeClass(["o-date-panel", `o-date-panel-${vue.unref(size)}`, "o-date-range-panel"]), "hide-close": "", target: props.target, transition: vue.unref(transition), position: vue.unref(popupPosition), wrapper: vue.unref(popupWrapper), trigger: "none", offset: 4, "adjust-min-width": false, "adjust-width": false }, { default: vue.withCtx(() => [ vue.createElementVNode( "div", { ref_key: "popupRef", ref: popupRef }, [ vue.createVNode(DateRangePanelContent_vue_vue_type_script_setup_true_lang, { ref_key: "contentRef", ref: contentRef, "current-view": currentView.value, "onUpdate:currentView": _cache[0] || (_cache[0] = ($event) => currentView.value = $event), onChange: handleContentChange }, null, 8, ["current-view"]), !vue.unref(vueUtils.isEmptySlot)(_ctx.$slots.shortcut) && isMainPanel.value ? (vue.openBlock(), vue.createElementBlock( vue.Fragment, { key: 0 }, [ vue.createVNode(vue.unref(index$1.ODivider), { class: "o-date-panel-divider" }), vue.createElementVNode("div", _hoisted_1, [ vue.createElementVNode("span", _hoisted_2, [ vue.renderSlot(_ctx.$slots, "shortcut", { setValue, emitChange: () => emits("change", getValue().start, getValue().end) }) ]) ]) ], 64 /* STABLE_FRAGMENT */ )) : vue.createCommentVNode("v-if", true) ], 512 /* NEED_PATCH */ ) ]), _: 3 /* FORWARDED */ }, 8, ["visible", "class", "target", "transition", "position", "wrapper"]) ]), _: 3 /* FORWARDED */ }); }; } }); module.exports = _sfc_main;