1 |
- {"version":3,"file":"index.js","sources":["../../src/components/Common/Utils/utils.ts","../../src/components/Common/Modal/index.tsx"],"sourcesContent":["export function isBrowser() {\n return !(typeof window === undefined);\n}","import React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { createPortal } from \"react-dom\";\nimport { isBrowser } from \"../Utils/utils\";\n\nimport styles from \"./Modal.less\";\n\nexport interface ModalProps {\n visible: boolean;\n onCancel: (e: any) => void;\n container?: HTMLElement;\n}\n\nexport class Modal extends React.PureComponent<ModalProps> {\n static hasShowWarning = false;\n\n render() {\n if (!isBrowser()) return null; // 服务端无需渲染下列代码,渲染也会出错\n const DEFAULT_CONTAINER: HTMLElement | null = document.getElementById(\n \"container\"\n );\n const { children, visible, onCancel, container } = this.props;\n let finalMountContainer: HTMLElement;\n if (!container) {\n if (!DEFAULT_CONTAINER) {\n if (!Modal.hasShowWarning) {\n Modal.hasShowWarning = true;\n }\n finalMountContainer = document.body;\n } else {\n if (!Modal.hasShowWarning) {\n Modal.hasShowWarning = true;\n }\n finalMountContainer = DEFAULT_CONTAINER;\n }\n } else {\n finalMountContainer = container;\n }\n return (\n visible &&\n createPortal(\n <div className={styles.wrapper}>\n <div className={styles.overlay} onClick={onCancel} />\n <div className={styles.container}>{children}</div>\n </div>,\n finalMountContainer\n )\n );\n }\n}\n\nexport interface ModalCMDOptions {\n children: any;\n container?: HTMLElement;\n options?: {\n mask?: true;\n };\n}\n\nexport interface ModalCMDRecord {\n modalInstance: HTMLElement;\n}\n\nexport class ModalCMD {\n static currentModal: ModalCMDRecord[] = [];\n\n constructor() {\n ModalCMD.currentModal = [];\n }\n\n private static recordModal(record: ModalCMDRecord) {\n ModalCMD.currentModal.push(record);\n }\n\n private static delModal() {\n return ModalCMD.currentModal.pop();\n }\n\n static show({ children, container }: ModalCMDOptions) {\n const modalInstance = document.createElement(\"div\");\n let targetMountDom = container ? container : document.body;\n targetMountDom.appendChild(modalInstance);\n ReactDOM.render(\n <>\n <div\n style={{\n position: \"fixed\",\n top: 0,\n bottom: 0,\n left: 0,\n right: 0,\n zIndex: 1000\n }}\n >\n <div\n style={{\n position: \"absolute\",\n top: 0,\n bottom: 0,\n left: 0,\n right: 0,\n background: \"rgba(0,0,0,1)\",\n opacity: 0.6,\n zIndex: -1\n }}\n onClick={() => {\n ModalCMD.hide(ModalCMD.currentModal.length);\n }}\n />\n\n <div\n style={{\n position: \"absolute\",\n top: \"50%\",\n left: \"50%\",\n transform: \"translate(-50%, -50%)\"\n }}\n >\n {children}\n </div>\n </div>\n </>,\n modalInstance\n );\n this.recordModal({\n modalInstance\n });\n }\n\n static hide(targetId?: string | number) {\n const popModalRecord: ModalCMDRecord | undefined = this.delModal();\n if (popModalRecord && popModalRecord.modalInstance) {\n ReactDOM.unmountComponentAtNode(popModalRecord.modalInstance);\n const { parentNode } = popModalRecord.modalInstance;\n parentNode && parentNode.removeChild(popModalRecord.modalInstance);\n }\n }\n}\n\nexport default Modal;\n"],"names":["isBrowser","window","undefined","Modal","DEFAULT_CONTAINER","document","getElementById","props","children","visible","onCancel","container","finalMountContainer","hasShowWarning","body","createPortal","React","createElement","className","styles","wrapper","overlay","onClick","PureComponent","ModalCMD","currentModal","record","push","pop","modalInstance","targetMountDom","appendChild","ReactDOM","render","Fragment","style","position","top","bottom","left","right","zIndex","background","opacity","hide","length","transform","recordModal","targetId","popModalRecord","delModal","unmountComponentAtNode","parentNode","removeChild"],"mappings":";;;;;AAAM,SAAUA,SAAV,GAAmB;SAChB,EAAE,QAAOC,+CAAAA,OAAP,MAAkBC,SAApB;;;;;;;;;;;;ICYIC,KAAb;AAAA;AAAA,8BAAA;;;;;;;;;;;6BAGQ;UACA,CAACH,SAAS,IAAI,OAAO,IAAP;UACZI,iBAAiB,GAAuBC,QAAQ,CAACC,cAAT,CAC5C,WAD4C;wBAGK,KAAKC;UAAhDC,QALJ,eAKIA;UAAUC,OALd,eAKcA;UAASC,QALvB,eAKuBA;UAAUC,SALjC,eAKiCA;UACjCC;;UACA,CAACD,WAA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