import{l as H}from"./index-w6PwaWGP.js";import{d as M,w as v,o as V,M as T,A as d,J as c,_ as u,P as f,O,i as x,C as g,j as h,an as _,H as S,B as q,c as b,r as p,g as i,n as w}from"./index-DOFLUERq.js";import{_ as D}from"./_plugin-vue_export-helper-DlAUqK2U.js";const N={class:"field-label"},P={key:0,class:"required"},W={class:"html-editor"},j={class:"html-editor__toolbar"},$=["innerHTML"],I={class:"html-editor__actions"},A=M({__name:"HTMLEditor",props:{df:{},record:{},canEdit:{type:Boolean},ctx:{}},setup(o){const a=o,k=b(()=>a.df.label_layout||"vertical"),n=p(null);let m=null,e=null;const s=p(!1),r=p("preview"),L=b(()=>String(a.record[a.df.fieldname]||""));async function B(){if(!n.value||(m||(m=await H.init()),e))return;e=m.editor.create(n.value,{value:String(a.record[a.df.fieldname]||""),language:"html",automaticLayout:!0,folding:!0,minimap:{enabled:!1},readOnly:!a.canEdit,wordWrap:"on",wordWrapColumn:120,wrappingStrategy:"advanced",scrollBeyondLastLine:!1,scrollBeyondLastColumn:0,scrollbar:{horizontal:"hidden",vertical:"auto",horizontalScrollbarSize:6,verticalScrollbarSize:6,alwaysConsumeMouseWheel:!1}});const t=()=>{if(!e||!n.value)return;const l=e.getLayoutInfo(),y=e.getScrollHeight()>l.height+1,z=e.getScrollWidth()>l.width+1;n.value.classList.toggle("no-scroll-y",!y),n.value.classList.toggle("no-scroll-x",!z)};t(),e.onDidContentSizeChange(()=>t()),e.onDidScrollChange(()=>t()),e.onDidLayoutChange(()=>t()),e.onDidChangeModelContent(()=>{e&&(a.record[a.df.fieldname]=e.getValue(),t())})}function C(){try{e?.dispose()}catch{}e=null}function E(){s.value=!s.value,w(()=>e?.layout())}return v(()=>a.canEdit,t=>{e?.updateOptions({readOnly:!t})}),v(()=>a.record[a.df.fieldname],t=>{e&&t!==e.getValue()&&e.setValue(String(t||""))}),V(async()=>{}),v(r,async t=>{t==="edit"?(await w(),await B(),w(()=>e?.layout())):C()}),T(C),(t,l)=>(i(),d("div",{class:S(["field-wrapper",`layout-${k.value}`])},[c("label",N,[u(f(o.ctx.t(o.df.label||o.df.fieldname))+" ",1),o.df.reqd?(i(),d("span",P,"*")):O("",!0)]),c("div",W,[c("div",j,[r.value==="edit"?(i(),x(h(_),{key:0,size:"tiny",quaternary:"",type:"default",onClick:l[0]||(l[0]=y=>r.value="preview")},{default:g(()=>[u(f(o.ctx.t("Preview")),1)]),_:1})):(i(),x(h(_),{key:1,size:"tiny",quaternary:"",type:"default",onClick:l[1]||(l[1]=y=>r.value="edit")},{default:g(()=>[u(f(o.ctx.t("Edit")),1)]),_:1}))]),r.value==="preview"?(i(),d("div",{key:0,class:"html-editor__preview",innerHTML:L.value},null,8,$)):(i(),d("div",{key:1,ref_key:"editorHost",ref:n,class:S(["html-editor__monaco",{collapsed:!s.value}])},null,2)),c("div",I,[q(h(_),{size:"tiny",quaternary:"",onClick:E},{default:g(()=>[u(f(s.value?o.ctx.t("Collapse"):o.ctx.t("Expand")),1)]),_:1})])])],2))}}),J=D(A,[["__scopeId","data-v-4ffe6731"]]),K=Object.freeze(Object.defineProperty({__proto__:null,default:J},Symbol.toStringTag,{value:"Module"}));export{K as _};
