UNPKG

armisa-models

Version:
84 lines (83 loc) 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PopupFactory = exports.MouseLocationOfPopup = void 0; const ToolStripButtonFactory_1 = require("./ToolStrip/ToolStripButtonFactory"); class MouseLocationOfPopup { constructor(X, Y) { this.X = X; this.Y = Y; } static buildNew(e) { return new MouseLocationOfPopup(e.clientX, e.clientY); } } exports.MouseLocationOfPopup = MouseLocationOfPopup; class PopupFactory { constructor(mainStateFactory, children, mouseLocation, onClosePopup) { this.mainStateFactory = mainStateFactory; this.children = children; this.mouseLocation = mouseLocation; this.onClosePopup = onClosePopup; this.forceUpdate = () => { }; this.mainStateManager = this.mainStateFactory.mainStateManager; this.id = Math.random().toString() + '-' + new Date().getMilliseconds().toString(); this.mainStateFactory.elementsOfForm.popup = this; let tempPopupRoot = document.getElementById('popup__container'); if (!tempPopupRoot) { tempPopupRoot = document.createElement('div'); tempPopupRoot.className = "popup__container"; tempPopupRoot.id = "popup__container"; const root = document.getElementById('root'); root.insertAdjacentElement('beforebegin', tempPopupRoot); } this.popupRoot = tempPopupRoot; const popupCount = this.mainStateManager.popups.length; this.backdropDivElement = document.createElement('div'); this.backdropDivElement.classList.add('backdrop-popup'); this.backdropDivElement.style.zIndex = `${4000 + popupCount}`; this.backdropDivElement.style.opacity = '0'; this.backdropDivElement.onclick = (e) => this.closeByClick(this); this.mainDivElement = document.createElement('div'); this.mainDivElement.classList.add('popup'); const setMainDivElementByElement = (element) => { var rect = element.getBoundingClientRect(); this.mainDivElement.style.left = `${rect.left + (rect.width / 2)}px`; this.mainDivElement.style.top = `${rect.bottom - 10}px`; this.mainDivElement.classList.add('arrow'); this.mainDivElement.classList.add('bottom'); }; if (mouseLocation instanceof MouseLocationOfPopup) { this.mainDivElement.style.left = `${mouseLocation.X}px`; this.mainDivElement.style.top = `${mouseLocation.Y}px`; } else if (mouseLocation instanceof ToolStripButtonFactory_1.ToolStripButtonFactory) { if (mouseLocation.refOfElemetn && mouseLocation.refOfElemetn.current) { setMainDivElementByElement(mouseLocation.refOfElemetn.current); } } else if (typeof mouseLocation === 'object') { if ('element' in mouseLocation && 'getBoundingClientRect' in mouseLocation['element']) { setMainDivElementByElement(mouseLocation.element); } else { this.mainDivElement.style.left = `${mouseLocation.clientX}px`; this.mainDivElement.style.top = `${mouseLocation.clientY}px`; } } else { this.backdropDivElement.classList.add('back-drop'); } // this.mainDivElement.style.zIndex = `${4000 + this.mainStateManager.Modaling.modals.length}`; this.popupRoot.appendChild(this.backdropDivElement); this.popupRoot.appendChild(this.mainDivElement); } closeByClick(e) { e.close(); } close() { this.mainStateManager.closePopup(this); this.mainStateFactory.elementsOfForm.popup = undefined; this.onClosePopup && this.onClosePopup(); } } exports.PopupFactory = PopupFactory;