import{l as z}from"./index-2d2e8bf3.js";import{d as E,r as m,u as j,c as h,z as T,o as N,L as p,aW as W,e as u,f as n,s as _,g,k as v,B as C,J as D,w as J,j as O,n as r,q as P}from"./index-a0da86f0.js";import{_ as q}from"./_plugin-vue_export-helper-c27b6911.js";const Z={class:"field-label"},G={key:0,class:"required"},I={class:"code-editor"},A={key:0,class:"code-editor__preview"},R=["aria-label"],U={class:"code-editor__footer"},$=E({__name:"Code",props:{df:{},record:{},canEdit:{type:Boolean},ctx:{}},setup(b){const a=b,s=m(null);let f=null,e=null;const i=m(!1),c=j(),w=h(()=>a.df.label_layout||"vertical"),d=h(()=>!a.canEdit),S=()=>({Javascript:"javascript",JS:"javascript",Python:"python",Py:"python",PythonExpression:"python",HTML:"html",CSS:"css",Markdown:"markdown",SCSS:"scss",JSON:"json",Golang:"go",Go:"go",Jinja:"html"})[a.df.options]||"text";async function x(){if(!s.value||d.value||(f||(f=await z.init()),e))return;const o=S(),t=String(a.record[a.df.fieldname]||"");e=f.editor.create(s.value,{value:t,language:o,automaticLayout:!0,folding:!0,minimap:{enabled:!1},readOnly:!1,wordWrap:a.df.wrap?"on":"off",wordWrapColumn:120,wrappingStrategy:"advanced",scrollBeyondLastLine:!1,scrollBeyondLastColumn:0,scrollbar:{horizontal:"auto",vertical:"auto",horizontalScrollbarSize:6,verticalScrollbarSize:6,alwaysConsumeMouseWheel:!1},theme:"vs",showPrintMargin:!1,fontSize:14,lineNumbers:"on",renderWhitespace:"selection",tabSize:2,insertSpaces:!0});const l=()=>{if(!e||!s.value)return;const y=e.getLayoutInfo(),H=e.getScrollHeight()>y.height+1,L=e.getScrollWidth()>y.width+1;s.value.classList.toggle("no-scroll-y",!H),s.value.classList.toggle("no-scroll-x",!L)};l(),e.onDidContentSizeChange(()=>l()),e.onDidScrollChange(()=>l()),e.onDidLayoutChange(()=>l()),e.onDidChangeModelContent(()=>{e&&(a.record[a.df.fieldname]=e.getValue(),l())})}function V(){try{e==null||e.dispose()}catch{}e=null}function k(){i.value=!i.value,p(()=>e==null?void 0:e.layout())}function M(){const o=e?e.getValue():String(a.record[a.df.fieldname]||"");o?navigator.clipboard.writeText(o).then(()=>{c.success("代码已复制到剪贴板")}).catch(t=>{console.error("复制失败:",t),B(o)}):c.warning("没有内容可复制")}function B(o){const t=document.createElement("textarea");t.value=o,t.style.position="fixed",t.style.left="-999999px",t.style.top="-999999px",document.body.appendChild(t),t.focus(),t.select();try{document.execCommand("copy"),c.success("代码已复制到剪贴板")}catch(l){console.error("复制失败:",l),c.error("复制失败，请手动复制")}document.body.removeChild(t)}return T(()=>a.record[a.df.fieldname],o=>{e&&o!==e.getValue()&&e.setValue(String(o||""))}),N(async()=>{await p(),await x(),p(()=>e==null?void 0:e.layout())}),W(V),(o,t)=>(r(),u("div",{class:C(["field-wrapper",`layout-${w.value}`])},[n("label",Z,[_(g(o.ctx.t(o.df.label||o.df.fieldname))+" ",1),o.df.reqd?(r(),u("span",G,"*")):v("",!0)]),n("div",I,[n("div",{class:C(["code-editor__monaco-wrap",{collapsed:!i.value,readonly:d.value}])},[d.value?(r(),u("div",A,[n("pre",null,[n("code",null,g(o.record[o.df.fieldname]||""),1)])])):(r(),u("div",{key:1,ref_key:"editorHost",ref:s,class:"code-editor__monaco-host"},null,512)),n("button",{class:"code-editor__copy-btn",type:"button",onClick:M,"aria-label":o.ctx.t("Copy")},[...t[0]||(t[0]=[n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"},[n("path",{d:"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1ZM19 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H19C20.1 23 21 22.1 21 21V7C21 5.9 20.1 5 19 5ZM19 21H8V7H19V21Z",fill:"currentColor"})],-1)])],8,R)],2),n("div",U,[d.value?v("",!0):(r(),D(O(P),{key:0,size:"tiny",quaternary:"",onClick:k},{default:J(()=>[_(g(i.value?o.ctx.t("Collapse"):o.ctx.t("Expand")),1)]),_:1}))])])],2))}});const F=q($,[["__scopeId","data-v-928e00fb"]]),Y=Object.freeze(Object.defineProperty({__proto__:null,default:F},Symbol.toStringTag,{value:"Module"}));export{Y as _};
