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