UNPKG

@nextcloud/vue

Version:
34 lines (33 loc) 1.16 kB
import { createApp } from "vue"; function spawnDialog(dialog, props = {}, options = {}) { let { container } = options; if ("container" in props && typeof props.container === "string") { container ??= props.container; } const resolvedContainer = typeof container === "string" && document.querySelector(container) || document.body; const element = resolvedContainer.appendChild(document.createElement("div")); return new Promise((resolve, reject) => { const app = createApp(dialog, { ...props, // If dialog has no `container` prop passing a falsy value does nothing // Otherwise it is expected that `null` disables teleport and mounts dialog in place like NcDialog/NcModal container: null, onClose(...rest) { const payload = rest.length > 1 ? rest : rest[0]; app.unmount(); element.remove(); resolve(payload); }, "onVue:unmounted": () => { app.unmount(); element.remove(); reject(new Error("Dialog was unmounted without close event")); } }); app.mount(element); }); } export { spawnDialog }; //# sourceMappingURL=index.mjs.map