UNPKG

@aplus-frontend/ui

Version:

104 lines (103 loc) 2.58 kB
import { isValid as _ } from "@aplus-frontend/utils"; import { createModal as I } from "./createModal.mjs"; import { Modal as S } from "@aplus-frontend/antdv"; import { ModalMessage as y } from "../enums/modalMessage.mjs"; const A = (M, g) => { const E = g ?? (Array.isArray(M) ? M[0]?.modalId : void 0), n = /* @__PURE__ */ new Map(); let x, u, c = 1e3; const m = async ({ modalId: r, params: d, handleCurrentModal: f, handleModal: O } = {}) => { if (!_(r)) { l(); return; } x = d; const s = M.find((t) => t.modalId === r); let i = !1; if (u) { const t = n.get(u), a = { ...t, destroy: () => { t?.destroy?.(), n.delete(u); }, open: () => { i = !0; } }; await f?.(a), await O?.({ getModal: n.get.bind(n) }); } return s && setTimeout(() => { C(s); }), i; }, l = () => { for (const [r, d] of n) d?.destroy?.(); }, C = async (r) => { const { modalId: d, modalType: f = "createModal", props: O } = r; u = d; const s = n.get(d), i = await O?.(x, async (e) => (a = !0, await m(e))); c = Math.max(i?.zIndex ?? 0, c), c += 1; let t, a = !1; if (f === "createModal") { const e = i, p = async (o) => (a = !0, await m(o)); t = { ...e, destroyOnClose: !1, zIndex: c, onOk: async (o) => { const w = await e?.onOk?.(o, p); if (a || l(), w) throw new Error(y.NOT_NEED_CLOSE); }, onCancel: async (o) => { const w = await e?.onCancel?.(o, p); if (a || l(), w) throw new Error(y.NOT_NEED_CLOSE); } }; } else { const e = i, p = async (o) => (a = !0, await m(o)); t = { ...e, zIndex: c, onOk: async () => { const o = await e?.onOk?.(p); if (a || l(), o) throw new Error(y.NOT_NEED_CLOSE); }, onCancel: async () => { const o = await e?.onCancel?.(p); if (a || l(), o) throw new Error(y.NOT_NEED_CLOSE); } }; } if (s) { s?.update(t), s?.open?.(); return; } else if (f === "createModal") { const e = I(t); e?.open?.(), n.set(d, e); } else S?.[f]?.(t); }, N = M.find((r) => _(E) && r.modalId === E); if (N !== void 0) return C(N), { getModal: n.get.bind(n), clearAllModal: l, next: m }; }; export { A as createModalStream };