1 | var __create = Object.create;
|
2 | var __defProp = Object.defineProperty;
|
3 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
5 | var __getProtoOf = Object.getPrototypeOf;
|
6 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7 | var __export = (target, all) => {
|
8 | for (var name in all)
|
9 | __defProp(target, name, { get: all[name], enumerable: true });
|
10 | };
|
11 | var __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 | };
|
19 | var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25 | mod
|
26 | ));
|
27 | var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28 | var stdin_exports = {};
|
29 | __export(stdin_exports, {
|
30 | closeDialog: () => closeDialog,
|
31 | resetDialogDefaultOptions: () => resetDialogDefaultOptions,
|
32 | setDialogDefaultOptions: () => setDialogDefaultOptions,
|
33 | showConfirmDialog: () => showConfirmDialog,
|
34 | showDialog: () => showDialog
|
35 | });
|
36 | module.exports = __toCommonJS(stdin_exports);
|
37 | var import_vue = require("vue");
|
38 | var import_utils = require("../utils");
|
39 | var import_mount_component = require("../utils/mount-component");
|
40 | var import_Dialog = __toESM(require("./Dialog"));
|
41 | let instance;
|
42 | const 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 | };
|
69 | let currentOptions = (0, import_utils.extend)({}, DEFAULT_OPTIONS);
|
70 | function 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 | }
|
86 | function 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 | }
|
101 | const setDialogDefaultOptions = (options) => {
|
102 | (0, import_utils.extend)(currentOptions, options);
|
103 | };
|
104 | const resetDialogDefaultOptions = () => {
|
105 | currentOptions = (0, import_utils.extend)({}, DEFAULT_OPTIONS);
|
106 | };
|
107 | const showConfirmDialog = (options) => showDialog((0, import_utils.extend)({
|
108 | showCancelButton: true
|
109 | }, options));
|
110 | const closeDialog = () => {
|
111 | if (instance) {
|
112 | instance.toggle(false);
|
113 | }
|
114 | };
|