ant-design-x-vue
Version:
Craft AI-driven interfaces effortlessly
59 lines (58 loc) • 1.98 kB
JavaScript
import { defineComponent as D, onMounted as C, watch as i, toValue as h, onWatcherCleanup as E, computed as L, createVNode as s, Teleport as A } from "vue";
import { c as x } from "./Attachments2.mjs";
import m from "../_util/hooks/use-state.mjs";
import { useAttachmentContextInject as w } from "./context.mjs";
const O = /* @__PURE__ */ D({
name: "AXAttachmentsDropArea",
__name: "DropArea",
props: {
prefixCls: null,
className: null,
getDropContainer: {
type: Function
},
children: null
},
setup(e) {
const v = w(), [n, l] = m(), [f, o] = m(null);
C(() => {
var t;
l((t = e.getDropContainer) == null ? void 0 : t.call(e));
}), i(() => h(e.getDropContainer), () => {
var a;
const t = (a = e.getDropContainer) == null ? void 0 : a.call(e);
n.value !== t && l(t);
}), i(() => !!n.value, () => {
if (n.value) {
const t = () => {
o(!0);
}, a = (r) => {
r.preventDefault();
}, c = (r) => {
r.relatedTarget || o(!1);
}, u = (r) => {
o(!1), r.preventDefault();
};
document.addEventListener("dragenter", t), document.addEventListener("dragover", a), document.addEventListener("dragleave", c), document.addEventListener("drop", u), E(() => {
document.removeEventListener("dragenter", t), document.removeEventListener("dragover", a), document.removeEventListener("dragleave", c), document.removeEventListener("drop", u);
});
}
});
const g = L(() => e.getDropContainer && n.value && !v.value.disabled), d = `${e.prefixCls}-drop-area`;
return () => g.value ? s(A, {
to: n.value
}, {
default: () => [s("div", {
class: x(d, e.className, {
[`${d}-on-body`]: n.value.tagName === "BODY"
}),
style: {
display: f.value ? "block" : "none"
}
}, [e.children])]
}) : null;
}
});
export {
O as default
};