Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.174/page_editor/app/components/UnsafeHTML",["module","exports","require","@liferay/frontend-js-react-web","@liferay/layout-js-components-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../common/components/RawDOM"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=r("@liferay/frontend-js-react-web"),n=r("@liferay/layout-js-components-web"),a=(_interopRequireDefault(r("liferay!frontend-js-react-web$prop-types")),_interopRequireDefault(r("liferay!frontend-js-react-web$react"))),o=_interopRequireDefault(r("../../common/components/RawDOM"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class UnsafeHTML extends a.default.PureComponent{constructor(e){super(e),function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}(this,"_updateRef",(e=>{"function"==typeof this.props.contentRef?this.props.contentRef(e):this.props.contentRef&&(this.props.contentRef.current=e),this.setState((({ref:t})=>t!==e?{portals:[],ref:e}:null))})),this.state={portals:[],ref:null}}componentDidUpdate(e){this.state.ref&&(this._syncRefProps(),(!this.state.ref.childNodes.length&&this.props.markup||e.markup!==this.props.markup)&&this._syncRefContent())}_runRefScripts(){const e=this.props.globalContext.document,t=Array.from(this.state.ref.querySelectorAll("script")).filter((e=>!e.type||"module"===e.type||"text/javascript"===e.type)),runNextScript=()=>{if(t.length){const r=e.createElement("script"),s=t.shift();r.type=s.type,s.src?r.src=s.src:r.appendChild(e.createTextNode(s.innerHTML)),s.parentNode.replaceChild(r,s),requestAnimationFrame(runNextScript)}};runNextScript()}_syncRefContent(){const e=this.state.ref;e.innerHTML=this.props.markup;const t=this.props.getPortals(e);t.length||t.length!==this.state.portals.length?this.setState({portals:t},(()=>{this._runRefScripts(),this.props.onRender(e)})):(this._runRefScripts(),this.props.onRender(e))}_syncRefProps(){const e=this.state.ref;this.props.className?e.className=this.props.className:e.removeAttribute("class"),this.props.data&&Object.entries(this.props.data).forEach((([t,r])=>{e.dataset[t]=r})),this.props.id?e.id=this.props.id:e.removeAttribute("id"),this.props.hideFromAccessibilityTree?e.setAttribute("aria-hidden","true"):e.removeAttribute("aria-hidden"),e.removeAttribute("style"),Object.entries(this.props.style).forEach((([t,r])=>{(0,n.isNullOrUndefined)(r)||(!function isCSSVariable(e){return e.startsWith("--")}(t)?e.style[t]=r:e.style.setProperty(t,r))}))}render(){return a.default.createElement(a.default.Fragment,null,a.default.createElement(o.default,{TagName:this.props.TagName,elementRef:this._updateRef}),this.state.portals.map((({Component:e,element:t},r)=>a.default.createElement(s.ReactPortal,{container:t,key:r},a.default.createElement(e,null)))))}}t.default=UnsafeHTML,UnsafeHTML.defaultProps={TagName:"div",className:"",contentRef:null,getPortals:()=>[],globalContext:{document:document,window:window},hideFromAccessibilityTree:!0,id:"",markup:"",onRender:()=>{},style:{}}}}));
//# sourceMappingURL=UnsafeHTML.js.map