UNPKG

carbon-react

Version:

A library of reusable React components for easily building user interfaces.

2 lines (1 loc) 1.56 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../dom/globals.js");function o(t,o,e){return o in t?Object.defineProperty(t,o,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[o]=e,t}class e{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 e=this.modalList.findIndex((({modal:o})=>o===t));if(-1===e)return;if(this.modalList.splice(e,1),this.callTopModalSetters(),!this.modalList.length)return;const{setTriggerRefocusFlag:s}=this.getTopModal();s&&o&&s(!0)}clearList(){const o=t.getWindow(),e=[];o&&(o.__CARBON_INTERNALS_MODAL_LIST=e),this.modalList=e,this.callTopModalSetters()}callTopModalSetters(){const o=t.getWindow();if(null==o?void 0:o.__CARBON_INTERNALS_MODAL_SETTER_LIST){var e;const t=(null===(e=this.getTopModal())||void 0===e?void 0:e.modal)||null;for(const e of o.__CARBON_INTERNALS_MODAL_SETTER_LIST)e(t)}}constructor(){o(this,"modalList",void 0),o(this,"addModal",((t,o,e)=>{if(!t)return;const{modal:s,setTriggerRefocusFlag:l,topModalOverride:i}=this.getTopModal();!i&&s&&l&&l(!1),this.modalList.push({modal:t,setTriggerRefocusFlag:o,topModalOverride:e}),this.callTopModalSetters()}));const e=t.getWindow();e?(e.__CARBON_INTERNALS_MODAL_LIST||(e.__CARBON_INTERNALS_MODAL_LIST=[]),this.modalList=e.__CARBON_INTERNALS_MODAL_LIST):this.modalList=[]}}const s=new e;exports.ModalManagerInstance=e,exports.default=s;