UNPKG

@aplus-frontend/ui

Version:

122 lines (121 loc) 3.55 kB
import { render as h, defineComponent as k, createVNode as u, mergeProps as N, h as $ } from "vue"; import { Modal as E } from "@aplus-frontend/antdv"; import { globalConfigCached as p, ConfigProvider as F } from "../../config-provider/config-provider.mjs"; import { omit as L } from "lodash-unified"; import { isNumeric as C } from "@aplus-frontend/utils"; import { getContainerDom as g, getModalGlobalAppContext as M } from "./util.mjs"; import { getTopWindow as A } from "../../utils/index.mjs"; import H from "../style/index.mjs"; const j = (t) => { let n, r, i; const s = (e) => e ? `${p.value.namespace}-ap-modal-${e}` : `${p.value.namespace}-ap-modal`, { destroyOnClose: d = !0, wrapperOffset: o = !1, wrapperFullHeight: m = !1 } = t; function l() { n && n(!1), setTimeout(() => { h(null, a), a.parentElement?.removeChild(a); }, 500); } function v() { n && n(!0); } function c() { n && n(!1); } function x(e) { r && r(e); } const y = /* @__PURE__ */ k({ data() { return { open: d, props: t }; }, created() { n = (e) => { this.open = e; }, r = (e) => { this.props = { ...this.props, ...e }; }, i = H("ap-modal"); }, methods: { async handleCancel() { if (this.props?.onCancel) { const e = this.props?.content?.component?.exposed ?? void 0; await this.props?.onCancel(e); } d ? l() : c(); }, async handleOk() { try { if (r({ confirmLoading: !0 }), this.props?.onOk) { const e = this.props?.content?.component?.exposed ?? void 0; await this.props.onOk(e); } r({ confirmLoading: !1 }), d ? l() : c(); } catch { r({ confirmLoading: !1 }); } }, handleFooter(e) { return t?.footer !== void 0 ? typeof t.footer == "function" ? t.footer({ ...e, contentExposed: this.props?.content?.component?.exposed ?? void 0 }) : t.footer : e?.originNode; } }, render() { const e = L(this.props, ["onCancel", "onOk", "open", "onUpdate:open", "getContainer", "icon", "footer"]); return u(F, p.value, { default: () => [u(E, N({ class: { [s()]: !0, [s("wrapper")]: o, [i.value]: !0 }, centered: !0 }, e, { open: this.open, onCancel: this.handleCancel, onOk: this.handleOk, footer: this?.handleFooter }), { default: () => [u("div", { class: { [s("body-wrapper")]: o, [i.value]: !0 }, style: { maxHeight: o !== !1 ? `calc(100vh - ${(o === !0 ? 100 : C(o) ? Number(o) : 100) * 2}px)` : void 0, height: m === !0 ? `calc(100vh - ${(o === !0 ? 100 : C(o) ? Number(o) : 100) * 2}px)` : void 0, overflowY: o !== !1 || m === !0 ? "auto" : void 0 } }, [this.props?.content])] })] }); } }), O = g(p?.value?.getPopupContainer), w = g(t.getContainer), b = O || w || A().document.body, a = document.createElement("div"); b.appendChild(a); const f = $(y), P = M(); return f.appContext = t.appContext || P || f.appContext, h(f, a), { destroy: l, update: x, open: v, close: c }; }; export { j as createModal };