| 1 |
import{h as i,v as g,j as h,e as d,o as u,b,d as s,x as _}from"./vue.esm-bundler.js?ver=1.3.25";import{u as E}from"./useElementor.js?ver=1.3.25";import"./ServerSidePreview.vue_vue_type_style_index_0_scoped_e73ce754_lang.js?ver=1.3.25";import{_ as k}from"./_plugin-vue_export-helper.js?ver=1.3.25";import{a as L}from"./add-query-args.js?ver=1.3.25";const S={style:{position:"relative",width:"100%",height:"600px"}},T={key:0,style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(255, 255, 255, 0.8)",display:"flex","align-items":"center","justify-content":"center","z-index":"20"}},x=["src"],P={__name:"ServerSidePreview",props:{block:{type:String,required:!0},attributes:{type:Object,required:!0}},setup(f){const n=f;E();const o=i(null),r=i(!1),p=i({...n.attributes}),l=(e=n.attributes)=>window.location.origin+L("",{"fluent-cart":"block-render",block:n.block,context:"edit",attributes:e}),m=async e=>{if(o.value&&o.value.contentWindow)try{o.value.contentWindow.postMessage({type:"UPDATE_ATTRIBUTES",attributes:e,block:n.block},window.location.origin)}catch(t){console.error("Failed to update iframe via postMessage:",t),await v()}},v=async()=>{if(!o.value)return;r.value=!0;const e=await w();o.value.src=l(),await new Promise(t=>{const a=()=>{o.value.removeEventListener("load",a),t()};o.value.addEventListener("load",a)}),e&&await y(e),r.value=!1},w=async()=>{var e;try{if((e=o.value)!=null&&e.contentWindow)return{scrollTop:o.value.contentDocument.documentElement.scrollTop,scrollLeft:o.value.contentDocument.documentElement.scrollLeft}}catch{return null}},y=async e=>{var t;try{await _(),(t=o.value)!=null&&t.contentWindow&&e&&o.value.contentWindow.scrollTo(e.scrollLeft,e.scrollTop)}catch{}};g(()=>n.attributes,async(e,t)=>{JSON.stringify(e)!==JSON.stringify(t)&&(p.value={...e},await m(e))},{deep:!0});const c=e=>{e.origin===window.location.origin&&(e.data.type==="IFRAME_READY"?console.log("Iframe ready"):e.data.type==="UPDATE_COMPLETE"&&(r.value=!1))};return typeof window<"u"&&window.addEventListener("message",c),h(()=>{typeof window<"u"&&window.removeEventListener("message",c)}),(e,t)=>(u(),d("div",S,[r.value?(u(),d("div",T,t[0]||(t[0]=[s("div",null,"Loading...",-1)]))):b("",!0),s("iframe",{class:"nuhel",ref_key:"iframeRef",ref:o,src:l(),style:{width:"100%",height:"100%",border:"none",transition:"opacity 0.3s ease"}},null,8,x),t[1]||(t[1]=s("div",{style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",cursor:"pointer",background:"transparent","z-index":"10"}},null,-1))]))}},B=k(P,[["__scopeId","data-v-e73ce754"]]);export{B as S}; |