maz-ui
Version:
A standalone components library for Vue.Js 3 & Nuxt.Js 3
52 lines (51 loc) • 1.57 kB
JavaScript
import { _ as _sfc_main, u as useMazDialogConfirm } from "../chunks/MazDialogConfirm.vue_vue_type_script_setup_true_lang.DuEcluOw.js";
import { useMountComponent } from "../composables/useMountComponent.js";
const DEFAULT_OPTIONS = {
identifier: "main-dialog"
};
class DialogHandler {
constructor(app, globalOptions = DEFAULT_OPTIONS) {
this.app = app, this.globalOptions = globalOptions;
}
open(options) {
const props = {
...DEFAULT_OPTIONS,
...this.globalOptions,
...options
}, { destroy, vNode } = useMountComponent(_sfc_main, {
props,
app: this.app
}), { showDialogAndWaitChoice } = useMazDialogConfirm();
function close() {
vNode.component?.exposed?.isActive?.value && (vNode.component?.exposed?.close(), props.onClose?.(), setTimeout(() => {
destroy();
}, 700));
}
async function runDialog() {
try {
const response = await showDialogAndWaitChoice(props.identifier);
props.onAccept && props.onAccept(response);
} catch (error) {
const response = error;
props.onReject && props.onReject(response);
}
}
return runDialog(), {
destroy,
close
};
}
}
const DialogPlugin = {
install(app, options) {
const dialogHandler = new DialogHandler(app, options);
app.provide("mazDialog", dialogHandler), app.config.globalProperties.$mazDialog = {
open: dialogHandler.open.bind(dialogHandler),
globalOptions: dialogHandler.globalOptions
};
}
};
export {
DialogHandler,
DialogPlugin
};