Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.132/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({children:t,useIframe:n}){const[i,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 t=()=>{if(!p()||!s)return;const n="".concat(c.config.portletNamespace,"pageEditorStylesLink");if(!s.contentDocument.getElementById(n)){const e=s.contentDocument.createElement("link");e.id=n,e.rel="stylesheet",e.href=c.config.getIframeContentCssURL,s.contentDocument.head.appendChild(e)}const o=s.contentDocument&&(s.contentDocument.getElementById("content")||s.contentDocument.getElementById("main-content"));o?(o.innerHTML="",s.contentWindow.requestAnimationFrame((()=>{u(o),f({document:s.contentDocument,iframe:s,window:s.contentWindow})}))):e=setTimeout(t,100)};return s&&(s.addEventListener("load",t),s.src=c.config.getIframeContentURL),()=>{clearTimeout(e),s&&s.removeEventListener("load",t),p()&&(u(null),f(null))}}),[s,p]),n&&i&&d?(x=a.default.createElement(r.ReactPortal,{container:i},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({children:t}){return a.default.createElement(e.Provider,{value:(0,a.useState)({document:document,window:window})},t)},t.useGlobalContext=function(){const[t]=(0,a.useContext)(e);return t};var o=u(n("@frontend-taglib-clay$clayui/loading-indicator")),r=n("@liferay/frontend-js-react-web"),a=(u(n("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=i();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=u(n("../../common/components/RawDOM")),c=n("../config/index");function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function u(e){return e&&e.__esModule?e:{default:e}}const e=a.default.createContext([{document:document,window:window},()=>{}])}}));
//# sourceMappingURL=GlobalContext.js.map