function-call.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. closeNotify: () => closeNotify,
  27. resetNotifyDefaultOptions: () => resetNotifyDefaultOptions,
  28. setNotifyDefaultOptions: () => setNotifyDefaultOptions,
  29. showNotify: () => showNotify
  30. });
  31. module.exports = __toCommonJS(stdin_exports);
  32. var import_vue = require("vue");
  33. var import_utils = require("../utils");
  34. var import_mount_component = require("../utils/mount-component");
  35. var import_Notify = __toESM(require("./Notify"));
  36. let timer;
  37. let instance;
  38. const parseOptions = (message) => (0, import_utils.isObject)(message) ? message : {
  39. message
  40. };
  41. function initInstance() {
  42. ({
  43. instance
  44. } = (0, import_mount_component.mountComponent)({
  45. setup() {
  46. const {
  47. state,
  48. toggle
  49. } = (0, import_mount_component.usePopupState)();
  50. return () => (0, import_vue.createVNode)(import_Notify.default, (0, import_vue.mergeProps)(state, {
  51. "onUpdate:show": toggle
  52. }), null);
  53. }
  54. }));
  55. }
  56. const getDefaultOptions = () => ({
  57. type: "danger",
  58. color: void 0,
  59. message: "",
  60. onClose: void 0,
  61. onClick: void 0,
  62. onOpened: void 0,
  63. duration: 3e3,
  64. position: void 0,
  65. className: "",
  66. lockScroll: false,
  67. background: void 0
  68. });
  69. let currentOptions = getDefaultOptions();
  70. const closeNotify = () => {
  71. if (instance) {
  72. instance.toggle(false);
  73. }
  74. };
  75. function showNotify(options) {
  76. if (!import_utils.inBrowser) {
  77. return;
  78. }
  79. if (!instance) {
  80. initInstance();
  81. }
  82. options = (0, import_utils.extend)({}, currentOptions, parseOptions(options));
  83. instance.open(options);
  84. clearTimeout(timer);
  85. if (options.duration > 0) {
  86. timer = setTimeout(closeNotify, options.duration);
  87. }
  88. return instance;
  89. }
  90. const setNotifyDefaultOptions = (options) => (0, import_utils.extend)(currentOptions, options);
  91. const resetNotifyDefaultOptions = () => {
  92. currentOptions = getDefaultOptions();
  93. };