carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 1.47 kB
JavaScript
import{getWindow as t}from"../dom/globals.js";function o(t,o,s){return o in t?Object.defineProperty(t,o,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[o]=s,t}class s{getTopModal(){return this.modalList.length?this.modalList.slice().reverse().find((t=>t.topModalOverride))||this.modalList[this.modalList.length-1]:{}}isTopmost(t){const{modal:o}=this.getTopModal();return!(!t||!o)&&t===o}removeModal(t,o=!0){const s=this.modalList.findIndex((({modal:o})=>o===t));if(-1===s)return;if(this.modalList.splice(s,1),this.callTopModalSetters(),!this.modalList.length)return;const{setTriggerRefocusFlag:l}=this.getTopModal();l&&o&&l(!0)}clearList(){const o=t(),s=[];o&&(o.__CARBON_INTERNALS_MODAL_LIST=s),this.modalList=s,this.callTopModalSetters()}callTopModalSetters(){const o=t();if(null==o?void 0:o.__CARBON_INTERNALS_MODAL_SETTER_LIST){var s;const t=(null===(s=this.getTopModal())||void 0===s?void 0:s.modal)||null;for(const s of o.__CARBON_INTERNALS_MODAL_SETTER_LIST)s(t)}}constructor(){o(this,"modalList",void 0),o(this,"addModal",((t,o,s)=>{if(!t)return;const{modal:l,setTriggerRefocusFlag:e,topModalOverride:i}=this.getTopModal();!i&&l&&e&&e(!1),this.modalList.push({modal:t,setTriggerRefocusFlag:o,topModalOverride:s}),this.callTopModalSetters()}));const s=t();s?(s.__CARBON_INTERNALS_MODAL_LIST||(s.__CARBON_INTERNALS_MODAL_LIST=[]),this.modalList=s.__CARBON_INTERNALS_MODAL_LIST):this.modalList=[]}}const l=new s;export{s as ModalManagerInstance,l as default};