You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
4.8 KiB
174 lines
4.8 KiB
'use strict';
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
var vue = require('vue');
|
|
var core = require('@vueuse/core');
|
|
require('../hooks/index.js');
|
|
var dom = require('./dom.js');
|
|
var aria = require('./aria.js');
|
|
var index = require('../hooks/use-global-config/index.js');
|
|
|
|
const onTouchMove = (e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
};
|
|
const onModalClick = () => {
|
|
PopupManager == null ? void 0 : PopupManager.doOnModalClick();
|
|
};
|
|
let hasModal = false;
|
|
const getModal = function() {
|
|
if (!core.isClient)
|
|
return void 0;
|
|
let modalDom = PopupManager.modalDom;
|
|
if (modalDom) {
|
|
hasModal = true;
|
|
} else {
|
|
hasModal = false;
|
|
modalDom = document.createElement("div");
|
|
PopupManager.modalDom = modalDom;
|
|
dom.on(modalDom, "touchmove", onTouchMove);
|
|
dom.on(modalDom, "click", onModalClick);
|
|
}
|
|
return modalDom;
|
|
};
|
|
const instances = {};
|
|
const PopupManager = {
|
|
modalFade: true,
|
|
modalDom: void 0,
|
|
globalInitialZIndex: 2e3,
|
|
zIndex: 0,
|
|
getInitialZIndex() {
|
|
var _a;
|
|
if (!vue.getCurrentInstance())
|
|
return this.globalInitialZIndex;
|
|
return (_a = index.useGlobalConfig("zIndex").value) != null ? _a : this.globalInitialZIndex;
|
|
},
|
|
getInstance(id) {
|
|
return instances[id];
|
|
},
|
|
register(id, instance) {
|
|
if (id && instance) {
|
|
instances[id] = instance;
|
|
}
|
|
},
|
|
deregister(id) {
|
|
if (id) {
|
|
instances[id] = null;
|
|
delete instances[id];
|
|
}
|
|
},
|
|
nextZIndex() {
|
|
return this.getInitialZIndex() + ++this.zIndex;
|
|
},
|
|
modalStack: [],
|
|
doOnModalClick() {
|
|
const topItem = PopupManager.modalStack[PopupManager.modalStack.length - 1];
|
|
if (!topItem)
|
|
return;
|
|
const instance = PopupManager.getInstance(topItem.id);
|
|
if (instance && instance.closeOnClickModal.value) {
|
|
instance.close();
|
|
}
|
|
},
|
|
openModal(id, zIndex, dom$1, modalClass, modalFade) {
|
|
if (!core.isClient)
|
|
return;
|
|
if (!id || zIndex === void 0)
|
|
return;
|
|
this.modalFade = modalFade;
|
|
const modalStack = this.modalStack;
|
|
for (let i = 0, j = modalStack.length; i < j; i++) {
|
|
const item = modalStack[i];
|
|
if (item.id === id) {
|
|
return;
|
|
}
|
|
}
|
|
const modalDom = getModal();
|
|
dom.addClass(modalDom, "v-modal");
|
|
if (this.modalFade && !hasModal) {
|
|
dom.addClass(modalDom, "v-modal-enter");
|
|
}
|
|
if (modalClass) {
|
|
const classArr = modalClass.trim().split(/\s+/);
|
|
classArr.forEach((item) => dom.addClass(modalDom, item));
|
|
}
|
|
setTimeout(() => {
|
|
dom.removeClass(modalDom, "v-modal-enter");
|
|
}, 200);
|
|
if (dom$1 && dom$1.parentNode && dom$1.parentNode.nodeType !== 11) {
|
|
dom$1.parentNode.appendChild(modalDom);
|
|
} else {
|
|
document.body.appendChild(modalDom);
|
|
}
|
|
if (zIndex) {
|
|
modalDom.style.zIndex = String(zIndex);
|
|
}
|
|
modalDom.tabIndex = 0;
|
|
modalDom.style.display = "";
|
|
this.modalStack.push({ id, zIndex, modalClass });
|
|
},
|
|
closeModal(id) {
|
|
const modalStack = this.modalStack;
|
|
const modalDom = getModal();
|
|
if (modalStack.length > 0) {
|
|
const topItem = modalStack[modalStack.length - 1];
|
|
if (topItem.id === id) {
|
|
if (topItem.modalClass) {
|
|
const classArr = topItem.modalClass.trim().split(/\s+/);
|
|
classArr.forEach((item) => dom.removeClass(modalDom, item));
|
|
}
|
|
modalStack.pop();
|
|
if (modalStack.length > 0) {
|
|
modalDom.style.zIndex = `${modalStack[modalStack.length - 1].zIndex}`;
|
|
}
|
|
} else {
|
|
for (let i = modalStack.length - 1; i >= 0; i--) {
|
|
if (modalStack[i].id === id) {
|
|
modalStack.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (modalStack.length === 0) {
|
|
if (this.modalFade) {
|
|
dom.addClass(modalDom, "v-modal-leave");
|
|
}
|
|
setTimeout(() => {
|
|
if (modalStack.length === 0) {
|
|
if (modalDom.parentNode)
|
|
modalDom.parentNode.removeChild(modalDom);
|
|
modalDom.style.display = "none";
|
|
PopupManager.modalDom = void 0;
|
|
}
|
|
dom.removeClass(modalDom, "v-modal-leave");
|
|
}, 200);
|
|
}
|
|
}
|
|
};
|
|
const getTopPopup = function() {
|
|
if (!core.isClient)
|
|
return;
|
|
if (PopupManager.modalStack.length > 0) {
|
|
const topPopup = PopupManager.modalStack[PopupManager.modalStack.length - 1];
|
|
if (!topPopup)
|
|
return;
|
|
const instance = PopupManager.getInstance(topPopup.id);
|
|
return instance;
|
|
}
|
|
};
|
|
if (core.isClient) {
|
|
window.addEventListener("keydown", function(event) {
|
|
if (event.code === aria.EVENT_CODE.esc) {
|
|
const topPopup = getTopPopup();
|
|
if (topPopup && topPopup.closeOnPressEscape.value) {
|
|
topPopup.handleClose ? topPopup.handleClose() : topPopup.handleAction ? topPopup.handleAction("cancel") : topPopup.close();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
exports.PopupManager = PopupManager;
|
|
//# sourceMappingURL=popup-manager.js.map
|