| 1 |
import{a as c,d as f}from"./element-plus.js?ver=2.10.01";import"./dayjs.js?ver=2.10.01";import{af as p,D as r,F as s,K as o,Q as n,S as F,I as g,P as _,O as l,J as E,E as T,L as D,R as y}from"./vue.js?ver=2.10.01";import{_ as S}from"./emoji-picker.js?ver=2.10.01";const w={name:"FullEditorFrame",emits:["update:modelValue","titleUpdated","featuredMediaUpdated","metaUpdated","manageDocuments","useAlternateEditor"],props:{editorPath:{type:String,default:"/editor"},modelValue:{type:String,default:""},editorParams:{type:Object,default:()=>({})},frameHeight:{type:String,default:"500px"},documentTitle:{type:String,default:""},featured_image_id:{type:[String,Number],default:""},metaSettings:{type:Object,default:()=>null}},data(){return{editorData:{content:""},editorFrame:null,editorOrigin:null,lastUpdate:"No updates yet",dataSent:!1,isFailing:!1,loadTimer:null,readyTimer:null}},computed:{hasFailed(){return!this.dataSent&&this.isFailing}},mounted(){this.loadTimer=setTimeout(this.markEditorFailed,3e4),this.editorData.content=this.modelValue,this.editorData.title=this.documentTitle,this.editorData.featured_image_id=this.featured_image_id,this.metaSettings&&(this.editorData.metaSettings=this.metaSettings),this.createEditorIframe(),window.addEventListener("message",this.handleEditorMessage)},beforeUnmount(){window.removeEventListener("message",this.handleEditorMessage),this.clearFailureTimers(),this.editorFrame&&(this.editorFrame.onload=null,this.$refs.iframeContainer.removeChild(this.editorFrame),this.editorFrame=null)},methods:{createEditorIframe(){const t=new URL(this.editorPath,window.location.origin);this.editorOrigin=t.origin,this.editorFrame=document.createElement("iframe");let e=this.appVars.wp_lesson_editor_frame;if(this.editorParams){const i=new URLSearchParams(this.editorParams);e+="&"+i.toString()}this.editorFrame.onload=()=>{clearTimeout(this.loadTimer),this.loadTimer=null,!(this.dataSent||this.readyTimer)&&(this.readyTimer=setTimeout(this.markEditorFailed,15e3))},this.editorFrame.onerror=this.markEditorFailed,this.editorFrame.src=e,this.editorFrame.style.width="100%",this.editorFrame.style.height=this.frameHeight,this.$refs.iframeContainer.appendChild(this.editorFrame)},editorFailed(){this.$emit("useAlternateEditor")},markEditorFailed(){this.clearFailureTimers(),this.dataSent||(this.isFailing=!0)},clearFailureTimers(){clearTimeout(this.loadTimer),clearTimeout(this.readyTimer),this.loadTimer=null,this.readyTimer=null},sendDataToEditor(){if(this.editorFrame&&this.editorFrame.contentWindow){const t=JSON.parse(JSON.stringify(this.editorData));this.editorFrame.contentWindow.postMessage({type:"UPDATE_EDITOR",data:t},"*"),this.dataSent=!0}else alert("Editor frame is not loaded or contentWindow is not accessible.")},syncMetaToEditor(t){this.editorFrame&&this.editorFrame.contentWindow&&this.editorFrame.contentWindow.postMessage({type:"SYNC_META",data:JSON.parse(JSON.stringify(t))},"*")},handleEditorMessage(t){const{action:e,content:i}=t.data;e==="EDITOR_UPDATED"?this.dataSent&&(this.editorData.content=i,this.$emit("update:modelValue",i)):e==="TITLE_UPDATED"?(this.editorData.title=i,this.$emit("titleUpdated",i)):e==="FEATURED_MEDIA_UPDATED"?this.$emit("featuredMediaUpdated",i):e==="META_UPDATED"?this.$emit("metaUpdated",i):e==="MANAGE_DOCUMENTS"?this.$emit("manageDocuments"):e==="EDITOR_READY"&&(this.clearFailureTimers(),this.isFailing=!1,this.sendDataToEditor())}}},U={key:0,style:{display:"flex","justify-content":"center","align-items":"center","column-gap":"10px"}},v=["element-loading-text"];function A(t,e,i,P,d,a){const m=c,h=f,u=p("loading");return r(),s(y,null,[a.hasFailed?(r(),s("div",U,[o("p",null,n(t.$t("Problem with loading the editor?")),1),F(m,{onClick:e[0]||(e[0]=M=>a.editorFailed())},{default:g(()=>[_(n(t.$t("Use Alternative Editor")),1)]),_:1})])):l("",!0),E((r(),s("div",{"element-loading-text":t.$t("Loading editor. Please wait..."),class:"editor-container"},[!d.dataSent&&!a.hasFailed?(r(),T(h,{key:0,style:{margin:"50px"},animated:!0,rows:2})):l("",!0),o("div",{ref:"iframeContainer",class:D(["iframe-container",{"is-hidden":a.hasFailed}])},null,2)],8,v)),[[u,!d.dataSent&&!a.hasFailed]])],64)}const x=S(w,[["render",A],["__scopeId","data-v-1796445f"]]);export{x as F}; |