UNPKG

ant-design-x-vue

Version:
73 lines (72 loc) 2.36 kB
import { defineComponent as C, onMounted as h, watch as c, toValue as p, onWatcherCleanup as x, computed as E, createVNode as l, Teleport as A } from "vue"; import { b as L } from "../chunks/module-chunk.mjs"; import m from "../_util/hooks/use-state.mjs"; import { useAttachmentContextInject as w } from "./context.mjs"; import { _ as y } from "../chunks/helper-chunk.mjs"; const b = /* @__PURE__ */ C({ name: "AXAttachmentsDropArea", __name: "DropArea", props: { prefixCls: { type: String, required: !0 }, className: { type: String, required: !0 }, getDropContainer: { type: Function, skipCheck: !0, required: !1 }, children: { required: !1 } }, setup(e, { expose: v }) { v(); const f = w(), [n, u] = m(), [g, o] = m(null); h(() => { var t; u((t = e.getDropContainer) == null ? void 0 : t.call(e)); }), c(() => p(e.getDropContainer), () => { var r; const t = (r = e.getDropContainer) == null ? void 0 : r.call(e); n.value !== t && u(t); }), c(() => !!n.value, () => { if (n.value) { const t = () => { o(!0); }, r = (a) => { a.preventDefault(); }, i = (a) => { a.relatedTarget || o(!1); }, s = (a) => { o(!1), a.preventDefault(); }; document.addEventListener("dragenter", t), document.addEventListener("dragover", r), document.addEventListener("dragleave", i), document.addEventListener("drop", s), x(() => { document.removeEventListener("dragenter", t), document.removeEventListener("dragover", r), document.removeEventListener("dragleave", i), document.removeEventListener("drop", s); }); } }); const D = E(() => e.getDropContainer && n.value && !f.value.disabled), d = `${e.prefixCls}-drop-area`; return () => D.value ? l(A, { to: n.value }, { default: () => [l("div", { class: L(d, e.className, { [`${d}-on-body`]: n.value.tagName === "BODY" }), style: { display: g.value ? "block" : "none" } }, [e.children])] }) : null; } }), T = /* @__PURE__ */ y(b, [["__file", "/Users/wangzhichao/办公/code/github/ant-design-x-vue-pure/ant-design-x-vue/src/attachments/DropArea.vue"]]); export { T as default };