UNPKG

tdesign-vue-next

Version:
105 lines (97 loc) 3.31 kB
/** * tdesign v1.11.5 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = require('@babel/runtime/helpers/createClass'); var _classCallCheck = require('@babel/runtime/helpers/classCallCheck'); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var Vue = require('vue'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck); var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var POPUP_BASE_Z_INDEX = 1e3; var MESSAGE_BASE_Z_INDEX = 5e3; var Z_INDEX_STEP = 1; var PopupManager = /*#__PURE__*/_createClass__default["default"](function PopupManager() { var _this = this; _classCallCheck__default["default"](this, PopupManager); _defineProperty__default["default"](this, "popupStack", { popup: /* @__PURE__ */new Set(), dialog: /* @__PURE__ */new Set(), message: /* @__PURE__ */new Set() }); _defineProperty__default["default"](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__default["default"](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__default["default"](this, "delete", function (zIndex, type) { _this.popupStack[type]["delete"](zIndex); if (type === "dialog") { _this.popupStack.popup["delete"](zIndex); } }); _defineProperty__default["default"](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 = Vue.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; }; Vue.watch(function () { return visible === null || visible === void 0 ? void 0 : visible.value; }, function (visible2) { if (visible2) { open(); } else { close(); } }, { immediate: true }); if (runOnMounted) { Vue.onMounted(function () { open(); }); Vue.onBeforeUnmount(function () { close(); }); } return { zIndex: Vue.readonly(zIndex), open: open, close: close, isLastDialog: isLastDialog }; } exports["default"] = usePopupManager; //# sourceMappingURL=usePopupManager.js.map