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