UNPKG

@aplus-frontend/ui

Version:

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