Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.130/page_editor/app/components/UnsafeHTML",["module","exports","require","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../common/components/RawDOM","../utils/isNullOrUndefined"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=r("@liferay/frontend-js-react-web"),n=(i(r("liferay!frontend-js-react-web$prop-types")),i(r("liferay!frontend-js-react-web$react"))),a=i(r("../../common/components/RawDOM")),o=i(r("../utils/isNullOrUndefined"));function i(e){return e&&e.__esModule?e:{default:e}}class e extends n.default.PureComponent{constructor(e){var t,r,s;super(e),s=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))},(r="_updateRef")in(t=this)?Object.defineProperty(t,r,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[r]=s,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)),r=()=>{if(t.length){const s=e.createElement("script"),n=t.shift();s.type=n.type,n.src?s.src=n.src:s.appendChild(e.createTextNode(n.innerHTML)),n.parentNode.replaceChild(s,n),requestAnimationFrame(r)}};r()}_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"),e.removeAttribute("style"),Object.entries(this.props.style).forEach((([t,r])=>{(0,o.default)(r)||(t.startsWith("--")?e.style.setProperty(t,r):e.style[t]=r)}))}render(){return n.default.createElement(n.default.Fragment,null,n.default.createElement(a.default,{TagName:this.props.TagName,elementRef:this._updateRef}),this.state.portals.map((({Component:e,element:t},r)=>n.default.createElement(s.ReactPortal,{container:t,key:r},n.default.createElement(e,null)))))}}t.default=e,e.defaultProps={TagName:"div",className:"",contentRef:null,getPortals:()=>[],globalContext:{document:document,window:window},id:"",markup:"",onRender:()=>{},style:{}}}}));
//# sourceMappingURL=UnsafeHTML.js.map