UNPKG

ingenious-flow-designer

Version:

[演示地址](http://antd-vben5-pro.madong.tech/)

343 lines (342 loc) 13.1 kB
import { onMounted, watchEffect, onBeforeUnmount, defineComponent, inject, computed, openBlock, createElementBlock, unref, normalizeClass, normalizeStyle, createElementVNode, renderSlot, toDisplayString, createVNode, withCtx, createBlock, resolveDynamicComponent, createCommentVNode, useSlots, ref, provide, Transition, withDirectives, mergeProps, createSlots, vShow } from "vue"; import { b as dialogContentProps, c as dialogContentEmits, d as dialogProps, a as dialogEmits, u as useDialog, E as ElOverlay, e as useSameTarget } from "./use-dialog-B0t0S0Y_.js"; import { F as FOCUS_TRAP_INJECTION_KEY, E as ElTeleport, a as ElFocusTrap } from "./index-C4X_r6uW.js"; import { E as ElIcon, C as CloseComponents } from "./icon-BjcUSrq3.js"; import { g as isFunction, _ as _export_sfc, u as useNamespace, w as withInstall } from "./install-DW2-zxb6.js"; import { a as addUnit } from "./index-Bg0OtIyq.js"; import { u as useLocale } from "./index-Ckp3g-8T.js"; import { u as useDeprecated } from "./index-BAOcmYcy.js"; const dialogInjectionKey = Symbol("dialogInjectionKey"); const useDraggable = (targetRef, dragRef, draggable, overflow) => { let transform = { offsetX: 0, offsetY: 0 }; const onMousedown = (e) => { const downX = e.clientX; const downY = e.clientY; const { offsetX, offsetY } = transform; const targetRect = targetRef.value.getBoundingClientRect(); const targetLeft = targetRect.left; const targetTop = targetRect.top; const targetWidth = targetRect.width; const targetHeight = targetRect.height; const clientWidth = document.documentElement.clientWidth; const clientHeight = document.documentElement.clientHeight; const minLeft = -targetLeft + offsetX; const minTop = -targetTop + offsetY; const maxLeft = clientWidth - targetLeft - targetWidth + offsetX; const maxTop = clientHeight - targetTop - targetHeight + offsetY; const onMousemove = (e2) => { let moveX = offsetX + e2.clientX - downX; let moveY = offsetY + e2.clientY - downY; if (!(overflow == null ? void 0 : overflow.value)) { moveX = Math.min(Math.max(moveX, minLeft), maxLeft); moveY = Math.min(Math.max(moveY, minTop), maxTop); } transform = { offsetX: moveX, offsetY: moveY }; if (targetRef.value) { targetRef.value.style.transform = `translate(${addUnit(moveX)}, ${addUnit(moveY)})`; } }; const onMouseup = () => { document.removeEventListener("mousemove", onMousemove); document.removeEventListener("mouseup", onMouseup); }; document.addEventListener("mousemove", onMousemove); document.addEventListener("mouseup", onMouseup); }; const onDraggable = () => { if (dragRef.value && targetRef.value) { dragRef.value.addEventListener("mousedown", onMousedown); } }; const offDraggable = () => { if (dragRef.value && targetRef.value) { dragRef.value.removeEventListener("mousedown", onMousedown); } }; const resetPosition = () => { transform = { offsetX: 0, offsetY: 0 }; if (targetRef.value) { targetRef.value.style.transform = "none"; } }; onMounted(() => { watchEffect(() => { if (draggable.value) { onDraggable(); } else { offDraggable(); } }); }); onBeforeUnmount(() => { offDraggable(); }); return { resetPosition }; }; const composeRefs = (...refs) => { return (el) => { refs.forEach((ref2) => { if (isFunction(ref2)) { ref2(el); } else { ref2.value = el; } }); }; }; const __default__$1 = defineComponent({ name: "ElDialogContent" }); const _sfc_main$1 = /* @__PURE__ */ defineComponent({ ...__default__$1, props: dialogContentProps, emits: dialogContentEmits, setup(__props, { expose }) { const props = __props; const { t } = useLocale(); const { Close } = CloseComponents; const { dialogRef, headerRef, bodyId, ns, style } = inject(dialogInjectionKey); const { focusTrapRef } = inject(FOCUS_TRAP_INJECTION_KEY); const dialogKls = computed(() => [ ns.b(), ns.is("fullscreen", props.fullscreen), ns.is("draggable", props.draggable), ns.is("align-center", props.alignCenter), { [ns.m("center")]: props.center } ]); const composedDialogRef = composeRefs(focusTrapRef, dialogRef); const draggable = computed(() => props.draggable); const overflow = computed(() => props.overflow); const { resetPosition } = useDraggable(dialogRef, headerRef, draggable, overflow); expose({ resetPosition }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { ref: unref(composedDialogRef), class: normalizeClass(unref(dialogKls)), style: normalizeStyle(unref(style)), tabindex: "-1" }, [ createElementVNode("header", { ref_key: "headerRef", ref: headerRef, class: normalizeClass([unref(ns).e("header"), { "show-close": _ctx.showClose }]) }, [ renderSlot(_ctx.$slots, "header", {}, () => [ createElementVNode("span", { role: "heading", "aria-level": _ctx.ariaLevel, class: normalizeClass(unref(ns).e("title")) }, toDisplayString(_ctx.title), 11, ["aria-level"]) ]), _ctx.showClose ? (openBlock(), createElementBlock("button", { key: 0, "aria-label": unref(t)("el.dialog.close"), class: normalizeClass(unref(ns).e("headerbtn")), type: "button", onClick: ($event) => _ctx.$emit("close") }, [ createVNode(unref(ElIcon), { class: normalizeClass(unref(ns).e("close")) }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(_ctx.closeIcon || unref(Close)))) ]), _: 1 }, 8, ["class"]) ], 10, ["aria-label", "onClick"])) : createCommentVNode("v-if", true) ], 2), createElementVNode("div", { id: unref(bodyId), class: normalizeClass(unref(ns).e("body")) }, [ renderSlot(_ctx.$slots, "default") ], 10, ["id"]), _ctx.$slots.footer ? (openBlock(), createElementBlock("footer", { key: 0, class: normalizeClass(unref(ns).e("footer")) }, [ renderSlot(_ctx.$slots, "footer") ], 2)) : createCommentVNode("v-if", true) ], 6); }; } }); var ElDialogContent = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__file", "dialog-content.vue"]]); const __default__ = defineComponent({ name: "ElDialog", inheritAttrs: false }); const _sfc_main = /* @__PURE__ */ defineComponent({ ...__default__, props: dialogProps, emits: dialogEmits, setup(__props, { expose }) { const props = __props; const slots = useSlots(); useDeprecated({ scope: "el-dialog", from: "the title slot", replacement: "the header slot", version: "3.0.0", ref: "https://element-plus.org/en-US/component/dialog.html#slots" }, computed(() => !!slots.title)); const ns = useNamespace("dialog"); const dialogRef = ref(); const headerRef = ref(); const dialogContentRef = ref(); const { visible, titleId, bodyId, style, overlayDialogStyle, rendered, zIndex, afterEnter, afterLeave, beforeLeave, handleClose, onModalClick, onOpenAutoFocus, onCloseAutoFocus, onCloseRequested, onFocusoutPrevented } = useDialog(props, dialogRef); provide(dialogInjectionKey, { dialogRef, headerRef, bodyId, ns, rendered, style }); const overlayEvent = useSameTarget(onModalClick); const draggable = computed(() => props.draggable && !props.fullscreen); const resetPosition = () => { var _a; (_a = dialogContentRef.value) == null ? void 0 : _a.resetPosition(); }; expose({ visible, dialogContentRef, resetPosition }); return (_ctx, _cache) => { return openBlock(), createBlock(unref(ElTeleport), { to: _ctx.appendTo, disabled: _ctx.appendTo !== "body" ? false : !_ctx.appendToBody }, { default: withCtx(() => [ createVNode(Transition, { name: "dialog-fade", onAfterEnter: unref(afterEnter), onAfterLeave: unref(afterLeave), onBeforeLeave: unref(beforeLeave), persisted: "" }, { default: withCtx(() => [ withDirectives(createVNode(unref(ElOverlay), { "custom-mask-event": "", mask: _ctx.modal, "overlay-class": _ctx.modalClass, "z-index": unref(zIndex) }, { default: withCtx(() => [ createElementVNode("div", { role: "dialog", "aria-modal": "true", "aria-label": _ctx.title || void 0, "aria-labelledby": !_ctx.title ? unref(titleId) : void 0, "aria-describedby": unref(bodyId), class: normalizeClass(`${unref(ns).namespace.value}-overlay-dialog`), style: normalizeStyle(unref(overlayDialogStyle)), onClick: unref(overlayEvent).onClick, onMousedown: unref(overlayEvent).onMousedown, onMouseup: unref(overlayEvent).onMouseup }, [ createVNode(unref(ElFocusTrap), { loop: "", trapped: unref(visible), "focus-start-el": "container", onFocusAfterTrapped: unref(onOpenAutoFocus), onFocusAfterReleased: unref(onCloseAutoFocus), onFocusoutPrevented: unref(onFocusoutPrevented), onReleaseRequested: unref(onCloseRequested) }, { default: withCtx(() => [ unref(rendered) ? (openBlock(), createBlock(ElDialogContent, mergeProps({ key: 0, ref_key: "dialogContentRef", ref: dialogContentRef }, _ctx.$attrs, { center: _ctx.center, "align-center": _ctx.alignCenter, "close-icon": _ctx.closeIcon, draggable: unref(draggable), overflow: _ctx.overflow, fullscreen: _ctx.fullscreen, "show-close": _ctx.showClose, title: _ctx.title, "aria-level": _ctx.headerAriaLevel, onClose: unref(handleClose) }), createSlots({ header: withCtx(() => [ !_ctx.$slots.title ? renderSlot(_ctx.$slots, "header", { key: 0, close: unref(handleClose), titleId: unref(titleId), titleClass: unref(ns).e("title") }) : renderSlot(_ctx.$slots, "title", { key: 1 }) ]), default: withCtx(() => [ renderSlot(_ctx.$slots, "default") ]), _: 2 }, [ _ctx.$slots.footer ? { name: "footer", fn: withCtx(() => [ renderSlot(_ctx.$slots, "footer") ]) } : void 0 ]), 1040, ["center", "align-center", "close-icon", "draggable", "overflow", "fullscreen", "show-close", "title", "aria-level", "onClose"])) : createCommentVNode("v-if", true) ]), _: 3 }, 8, ["trapped", "onFocusAfterTrapped", "onFocusAfterReleased", "onFocusoutPrevented", "onReleaseRequested"]) ], 46, ["aria-label", "aria-labelledby", "aria-describedby", "onClick", "onMousedown", "onMouseup"]) ]), _: 3 }, 8, ["mask", "overlay-class", "z-index"]), [ [vShow, unref(visible)] ]) ]), _: 3 }, 8, ["onAfterEnter", "onAfterLeave", "onBeforeLeave"]) ]), _: 3 }, 8, ["to", "disabled"]); }; } }); var Dialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "dialog.vue"]]); const ElDialog = withInstall(Dialog); export { ElDialog, ElDialog as default, dialogEmits, dialogInjectionKey, dialogProps, useDialog }; //# sourceMappingURL=index-c_WSQBtH.js.map