UNPKG

vuestic-ui

Version:
58 lines (57 loc) 1.67 kB
import { V as VaModal } from "./VaModal.js"; import { h, render, nextTick } from "vue"; const getNodeProps = (vNode) => { var _a; return ((_a = vNode.component) == null ? void 0 : _a.props) || {}; }; const destroy = (el, vNode) => { if (el) { render(null, el); el.remove(); } el = null; }; const mount = (component, { props, appContext } = {}) => { const el = document == null ? void 0 : document.createElement("div"); let vNode; const onClose = (event) => { var _a; (_a = props == null ? void 0 : props.onClose) == null ? void 0 : _a.call(props, event); destroy(el); }; const onUpdateModelValue = (value) => { var _a; (_a = props == null ? void 0 : props["onUpdate:modelValue"]) == null ? void 0 : _a.call(props, value); if ((props == null ? void 0 : props.withoutTransitions) && !value) { nextTick(() => { destroy(el); }); } }; vNode = h(component, { ...props, stateful: (props == null ? void 0 : props.stateful) ?? true, modelValue: true, onClose, "onUpdate:modelValue": onUpdateModelValue }); if (appContext) { vNode.appContext = appContext; } if (el) { render(vNode, el); } return { vNode, el }; }; const getModalOptions = (options) => typeof options === "string" ? { message: options } : options; const createModalInstance = (customProps, appContext) => { const { vNode, el } = mount(VaModal, { appContext, props: getModalOptions(customProps) }); if (el && vNode.el && getNodeProps(vNode)) { document.body.appendChild(el.childNodes[0]); } return vNode; }; export { createModalInstance as c }; //# sourceMappingURL=modal.js.map