UNPKG

3.76 kBJavaScriptView Raw
1var __create = Object.create;
2var __defProp = Object.defineProperty;
3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4var __getOwnPropNames = Object.getOwnPropertyNames;
5var __getProtoOf = Object.getPrototypeOf;
6var __hasOwnProp = Object.prototype.hasOwnProperty;
7var __export = (target, all) => {
8 for (var name in all)
9 __defProp(target, name, { get: all[name], enumerable: true });
10};
11var __copyProps = (to, from, except, desc) => {
12 if (from && typeof from === "object" || typeof from === "function") {
13 for (let key of __getOwnPropNames(from))
14 if (!__hasOwnProp.call(to, key) && key !== except)
15 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16 }
17 return to;
18};
19var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20 // If the importer is in node compatibility mode or this is not an ESM
21 // file that has been converted to a CommonJS file using a Babel-
22 // compatible transform (i.e. "__esModule" has not been set), then set
23 // "default" to the CommonJS "module.exports" for node compatibility.
24 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25 mod
26));
27var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28var stdin_exports = {};
29__export(stdin_exports, {
30 closeDialog: () => closeDialog,
31 resetDialogDefaultOptions: () => resetDialogDefaultOptions,
32 setDialogDefaultOptions: () => setDialogDefaultOptions,
33 showConfirmDialog: () => showConfirmDialog,
34 showDialog: () => showDialog
35});
36module.exports = __toCommonJS(stdin_exports);
37var import_vue = require("vue");
38var import_utils = require("../utils");
39var import_mount_component = require("../utils/mount-component");
40var import_Dialog = __toESM(require("./Dialog"));
41let instance;
42const DEFAULT_OPTIONS = {
43 title: "",
44 width: "",
45 theme: null,
46 message: "",
47 overlay: true,
48 callback: null,
49 teleport: "body",
50 className: "",
51 allowHtml: false,
52 lockScroll: true,
53 transition: void 0,
54 beforeClose: null,
55 overlayClass: "",
56 overlayStyle: void 0,
57 messageAlign: "",
58 cancelButtonText: "",
59 cancelButtonColor: null,
60 cancelButtonDisabled: false,
61 confirmButtonText: "",
62 confirmButtonColor: null,
63 confirmButtonDisabled: false,
64 showConfirmButton: true,
65 showCancelButton: false,
66 closeOnPopstate: true,
67 closeOnClickOverlay: false
68};
69let currentOptions = (0, import_utils.extend)({}, DEFAULT_OPTIONS);
70function initInstance() {
71 const Wrapper = {
72 setup() {
73 const {
74 state,
75 toggle
76 } = (0, import_mount_component.usePopupState)();
77 return () => (0, import_vue.createVNode)(import_Dialog.default, (0, import_vue.mergeProps)(state, {
78 "onUpdate:show": toggle
79 }), null);
80 }
81 };
82 ({
83 instance
84 } = (0, import_mount_component.mountComponent)(Wrapper));
85}
86function showDialog(options) {
87 if (!import_utils.inBrowser) {
88 return Promise.resolve(void 0);
89 }
90 return new Promise((resolve, reject) => {
91 if (!instance) {
92 initInstance();
93 }
94 instance.open((0, import_utils.extend)({}, currentOptions, options, {
95 callback: (action) => {
96 (action === "confirm" ? resolve : reject)(action);
97 }
98 }));
99 });
100}
101const setDialogDefaultOptions = (options) => {
102 (0, import_utils.extend)(currentOptions, options);
103};
104const resetDialogDefaultOptions = () => {
105 currentOptions = (0, import_utils.extend)({}, DEFAULT_OPTIONS);
106};
107const showConfirmDialog = (options) => showDialog((0, import_utils.extend)({
108 showCancelButton: true
109}, options));
110const closeDialog = () => {
111 if (instance) {
112 instance.toggle(false);
113 }
114};