UNPKG

tdesign-vue-next

Version:
95 lines (91 loc) 2.74 kB
/** * tdesign v1.11.5 * (c) 2025 tdesign * @license MIT */ import _createClass from '@babel/runtime/helpers/createClass'; import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { ref, watch, onMounted, onBeforeUnmount, readonly } from 'vue'; var POPUP_BASE_Z_INDEX = 1e3; var MESSAGE_BASE_Z_INDEX = 5e3; var Z_INDEX_STEP = 1; var PopupManager = /*#__PURE__*/_createClass(function PopupManager() { var _this = this; _classCallCheck(this, PopupManager); _defineProperty(this, "popupStack", { popup: /* @__PURE__ */new Set(), dialog: /* @__PURE__ */new Set(), message: /* @__PURE__ */new Set() }); _defineProperty(this, "getNextZIndex", function (type) { var current = type === "message" ? Array.from(_this.popupStack.message).pop() || MESSAGE_BASE_Z_INDEX : Array.from(_this.popupStack.popup).pop() || POPUP_BASE_Z_INDEX; return current + Z_INDEX_STEP; }); _defineProperty(this, "add", function (type) { var zIndex = _this.getNextZIndex(type); _this.popupStack[type].add(zIndex); if (type === "dialog") { _this.popupStack.popup.add(zIndex); } return zIndex; }); _defineProperty(this, "delete", function (zIndex, type) { _this.popupStack[type]["delete"](zIndex); if (type === "dialog") { _this.popupStack.popup["delete"](zIndex); } }); _defineProperty(this, "isLastDialog", function (zIndex) { if (_this.popupStack.dialog.size > 1) { return zIndex === Array.from(_this.popupStack.dialog).pop(); } return true; }); }); var popupManager = new PopupManager(); function usePopupManager(type) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, visible = _ref.visible, runOnMounted = _ref.runOnMounted; var zIndex = ref(0); var open = function open() { zIndex.value = popupManager.add(type); }; var close = function close() { popupManager["delete"](zIndex.value, type); }; var isLastDialog = function isLastDialog() { if (type === "dialog") { return popupManager.isLastDialog(zIndex.value); } return false; }; watch(function () { return visible === null || visible === void 0 ? void 0 : visible.value; }, function (visible2) { if (visible2) { open(); } else { close(); } }, { immediate: true }); if (runOnMounted) { onMounted(function () { open(); }); onBeforeUnmount(function () { close(); }); } return { zIndex: readonly(zIndex), open: open, close: close, isLastDialog: isLastDialog }; } export { usePopupManager as default }; //# sourceMappingURL=usePopupManager.js.map