function-call.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  21. mod
  22. ));
  23. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  24. var stdin_exports = {};
  25. __export(stdin_exports, {
  26. closeDialog: () => closeDialog,
  27. resetDialogDefaultOptions: () => resetDialogDefaultOptions,
  28. setDialogDefaultOptions: () => setDialogDefaultOptions,
  29. showConfirmDialog: () => showConfirmDialog,
  30. showDialog: () => showDialog
  31. });
  32. module.exports = __toCommonJS(stdin_exports);
  33. var import_vue = require("vue");
  34. var import_utils = require("../utils");
  35. var import_mount_component = require("../utils/mount-component");
  36. var import_Dialog = __toESM(require("./Dialog"));
  37. let instance;
  38. const DEFAULT_OPTIONS = {
  39. title: "",
  40. width: "",
  41. theme: null,
  42. message: "",
  43. overlay: true,
  44. callback: null,
  45. teleport: "body",
  46. className: "",
  47. allowHtml: false,
  48. lockScroll: true,
  49. transition: void 0,
  50. beforeClose: null,
  51. overlayClass: "",
  52. overlayStyle: void 0,
  53. messageAlign: "",
  54. cancelButtonText: "",
  55. cancelButtonColor: null,
  56. cancelButtonDisabled: false,
  57. confirmButtonText: "",
  58. confirmButtonColor: null,
  59. confirmButtonDisabled: false,
  60. showConfirmButton: true,
  61. showCancelButton: false,
  62. closeOnPopstate: true,
  63. closeOnClickOverlay: false
  64. };
  65. let currentOptions = (0, import_utils.extend)({}, DEFAULT_OPTIONS);
  66. function initInstance() {
  67. const Wrapper = {
  68. setup() {
  69. const {
  70. state,
  71. toggle
  72. } = (0, import_mount_component.usePopupState)();
  73. return () => (0, import_vue.createVNode)(import_Dialog.default, (0, import_vue.mergeProps)(state, {
  74. "onUpdate:show": toggle
  75. }), null);
  76. }
  77. };
  78. ({
  79. instance
  80. } = (0, import_mount_component.mountComponent)(Wrapper));
  81. }
  82. function showDialog(options) {
  83. if (!import_utils.inBrowser) {
  84. return Promise.resolve();
  85. }
  86. return new Promise((resolve, reject) => {
  87. if (!instance) {
  88. initInstance();
  89. }
  90. instance.open((0, import_utils.extend)({}, currentOptions, options, {
  91. callback: (action) => {
  92. (action === "confirm" ? resolve : reject)(action);
  93. }
  94. }));
  95. });
  96. }
  97. const setDialogDefaultOptions = (options) => {
  98. (0, import_utils.extend)(currentOptions, options);
  99. };
  100. const resetDialogDefaultOptions = () => {
  101. currentOptions = (0, import_utils.extend)({}, DEFAULT_OPTIONS);
  102. };
  103. const showConfirmDialog = (options) => showDialog((0, import_utils.extend)({
  104. showCancelButton: true
  105. }, options));
  106. const closeDialog = () => {
  107. if (instance) {
  108. instance.toggle(false);
  109. }
  110. };