"use strict";(self.webpackChunkemail_customizer_admin_ui=self.webpackChunkemail_customizer_admin_ui||[]).push([[920],{9114(e,t,n){n.d(t,{Ay:()=>f});var o,i,d=n(6540),r=n(961),s=n(5556),a=n(4848);"undefined"!=typeof document&&(o=document),"undefined"!=typeof window&&(i=window);var c=d.createContext({document:o,window:i}),{Provider:l,Consumer:h}=c,u=class extends d.Component{static propTypes={children:s.element.isRequired,contentDidMount:s.func.isRequired,contentDidUpdate:s.func.isRequired};componentDidMount(){this.props.contentDidMount()}componentDidUpdate(){this.props.contentDidUpdate()}render(){return d.Children.only(this.props.children)}},p=class extends d.Component{static propTypes={style:s.object,head:s.node,initialContent:s.string,mountTarget:s.string,dangerouslyUseDocWrite:s.bool,contentDidMount:s.func,contentDidUpdate:s.func,children:s.oneOfType([s.element,s.arrayOf(s.element)])};static defaultProps={style:{},head:null,children:void 0,mountTarget:void 0,dangerouslyUseDocWrite:!1,contentDidMount:()=>{},contentDidUpdate:()=>{},initialContent:'<!DOCTYPE html><html><head></head><body><div class="frame-root"></div></body></html>'};constructor(e,t){super(e,t),this._isMounted=!1,this.nodeRef=d.createRef(),this.state={iframeLoaded:!1}}componentDidMount(){this._isMounted=!0,this.getDoc()&&this.nodeRef.current.contentWindow.addEventListener("DOMContentLoaded",this.handleLoad),this.props.dangerouslyUseDocWrite&&this.handleLoad()}componentWillUnmount(){this._isMounted=!1,this.nodeRef.current.removeEventListener("DOMContentLoaded",this.handleLoad)}getDoc(){return this.nodeRef.current?this.nodeRef.current.contentDocument:null}getMountTarget(){const e=this.getDoc();return e&&e.body?this.props.mountTarget?e.querySelector(this.props.mountTarget):e.body.children[0]:null}setRef=e=>{this.nodeRef.current=e;const{forwardedRef:t}=this.props;"function"==typeof t?t(e):t&&(t.current=e)};handleLoad=()=>{clearInterval(this.loadCheck),this.state.iframeLoaded||this.setState({iframeLoaded:!0})};loadCheck=()=>setInterval(()=>{this.handleLoad()},500);renderFrameContents(){if(!this._isMounted)return null;const e=this.getDoc();if(!e)return null;const t=this.props.contentDidMount,n=this.props.contentDidUpdate,o=(0,a.jsx)(u,{contentDidMount:t,contentDidUpdate:n,children:(0,a.jsx)(l,{value:{document:e,window:e.defaultView||e.parentView},children:(0,a.jsx)("div",{className:"frame-content",children:this.props.children})})});this.props.dangerouslyUseDocWrite&&e.body.children.length<1&&(e.open("text/html","replace"),e.write(this.props.initialContent),e.close());const i=this.getMountTarget();return i?[r.createPortal(this.props.head,this.getDoc().head),r.createPortal(o,i)]:null}render(){const e={...this.props,children:void 0};return this.props.dangerouslyUseDocWrite||(e.srcDoc=this.props.initialContent),delete e.head,delete e.initialContent,delete e.mountTarget,delete e.dangerouslyUseDocWrite,delete e.contentDidMount,delete e.contentDidUpdate,delete e.forwardedRef,(0,a.jsx)("iframe",{...e,ref:this.setRef,onLoad:this.handleLoad,children:this.state.iframeLoaded&&this.renderFrameContents()})}},f=d.forwardRef((e,t)=>(0,a.jsx)(p,{...e,forwardedRef:t}))}}]);