Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.169/page_editor/app/contexts/GlobalContext",["module","exports","require","@frontend-taglib-clay$clayui/loading-indicator","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../common/components/RawDOM","../config/index"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalContextFrame=function GlobalContextFrame({children:t,useIframe:n}){const[c,u]=(0,a.useState)(null),[d,f]=(0,a.useState)(null),[s,m]=(0,a.useState)(null),p=(0,r.useIsMounted)(),[g,w]=(0,a.useState)(!1),y=(0,a.useMemo)((()=>({document:document,window:window})),[]),[,b]=(0,a.useContext)(e);let _,x;(0,a.useEffect)((()=>{n&&!g&&w(!0)}),[n,g]),(0,a.useEffect)((()=>{let e=null;const handleIframeLoaded=()=>{if(!p()||!s)return;const t="".concat(i.config.portletNamespace,"pageEditorStylesLink");if(!s.contentDocument.getElementById(t)){const e=s.contentDocument.createElement("link");e.id=t,e.rel="stylesheet",e.href=i.config.getIframeContentCssURL,s.contentDocument.head.appendChild(e)}const n=s.contentDocument&&s.contentDocument.getElementById("content");n?(n.innerHTML="",s.contentWindow.requestAnimationFrame((()=>{u(n),f({document:s.contentDocument,iframe:s,window:s.contentWindow})}))):e=setTimeout(handleIframeLoaded,100)};return s&&(s.addEventListener("load",handleIframeLoaded),s.src=i.config.getIframeContentURL),()=>{clearTimeout(e),s&&s.removeEventListener("load",handleIframeLoaded),p()&&(u(null),f(null))}}),[s,p]),n&&c&&d?(x=a.default.createElement(r.ReactPortal,{container:c},t),_=d,s.classList.remove("page-editor__global-context-iframe--hidden","page-editor__global-context-iframe--loading")):n?(x=a.default.createElement(o.default,null),_=y):(x=a.default.createElement(a.default.Fragment,null,t),_=y,s&&s.classList.add("page-editor__global-context-iframe--hidden"));return(0,a.useEffect)((()=>{b(_)}),[_,b]),a.default.createElement(a.default.Fragment,null,x,g?a.default.createElement(l.default,{TagName:"iframe",elementRef:e=>{e&&e.classList.add("page-editor__global-context-iframe","page-editor__global-context-iframe--loading"),m(e)}}):null)},t.GlobalContextProvider=function GlobalContextProvider({children:t}){return a.default.createElement(e.Provider,{value:(0,a.useState)({document:document,window:window})},t)},t.useGlobalContext=function useGlobalContext(){const[t]=(0,a.useContext)(e);return t};var o=_interopRequireDefault(n("@frontend-taglib-clay$clayui/loading-indicator")),r=n("@liferay/frontend-js-react-web"),a=(_interopRequireDefault(n("liferay!frontend-js-react-web$prop-types")),function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var n={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var a=o?Object.getOwnPropertyDescriptor(e,r):null;a&&(a.get||a.set)?Object.defineProperty(n,r,a):n[r]=e[r]}n.default=e,t&&t.set(e,n);return n}(n("liferay!frontend-js-react-web$react"))),l=_interopRequireDefault(n("../../common/components/RawDOM")),i=n("../config/index");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const e=a.default.createContext([{document:document,window:window},()=>{}])}}));
//# sourceMappingURL=GlobalContext.js.map