import{l as z}from"./index-w6PwaWGP.js";import{d as E,aa as j,w as T,o as O,n as p,M as P,A as f,J as l,_ as h,P as y,O as v,H as C,i as D,C as J,j as N,an as W,r as _,c as b,g as i}from"./index-DOFLUERq.js";import{_ as q}from"./_plugin-vue_export-helper-DlAUqK2U.js";const Z={class:"field-label"},A={key:0,class:"required"},G={class:"code-editor"},I={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(n){const o=n,r=_(null);let g=null,e=null;const c=_(!1),d=j(),w=b(()=>o.df.label_layout||"vertical"),u=b(()=>!o.canEdit),x=()=>({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"})[o.df.options]||"text";async function S(){if(!r.value||u.value||(g||(g=await z.init()),e))return;const a=x(),t=String(o.record[o.df.fieldname]||"");e=g.editor.create(r.value,{value:t,language:a,automaticLayout:!0,folding:!0,minimap:{enabled:!1},readOnly:!1,wordWrap:o.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 s=()=>{if(!e||!r.value)return;const m=e.getLayoutInfo(),B=e.getScrollHeight()>m.height+1,L=e.getScrollWidth()>m.width+1;r.value.classList.toggle("no-scroll-y",!B),r.value.classList.toggle("no-scroll-x",!L)};s(),e.onDidContentSizeChange(()=>s()),e.onDidScrollChange(()=>s()),e.onDidLayoutChange(()=>s()),e.onDidChangeModelContent(()=>{e&&(o.record[o.df.fieldname]=e.getValue(),s())})}function V(){try{e?.dispose()}catch{}e=null}function k(){c.value=!c.value,p(()=>e?.layout())}function M(){const a=e?e.getValue():String(o.record[o.df.fieldname]||"");a?navigator.clipboard.writeText(a).then(()=>{d.success("代码已复制到剪贴板")}).catch(t=>{console.error("复制失败:",t),H(a)}):d.warning("没有内容可复制")}function H(a){const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.left="-999999px",t.style.top="-999999px",document.body.appendChild(t),t.focus(),t.select();try{document.execCommand("copy"),d.success("代码已复制到剪贴板")}catch(s){console.error("复制失败:",s),d.error("复制失败，请手动复制")}document.body.removeChild(t)}return T(()=>o.record[o.df.fieldname],a=>{e&&a!==e.getValue()&&e.setValue(String(a||""))}),O(async()=>{await p(),await S(),p(()=>e?.layout())}),P(V),(a,t)=>(i(),f("div",{class:C(["field-wrapper",`layout-${w.value}`])},[l("label",Z,[h(y(n.ctx.t(n.df.label||n.df.fieldname))+" ",1),n.df.reqd?(i(),f("span",A,"*")):v("",!0)]),l("div",G,[l("div",{class:C(["code-editor__monaco-wrap",{collapsed:!c.value,readonly:u.value}])},[u.value?(i(),f("div",I,[l("pre",null,[l("code",null,y(n.record[n.df.fieldname]||""),1)])])):(i(),f("div",{key:1,ref_key:"editorHost",ref:r,class:"code-editor__monaco-host"},null,512)),l("button",{class:"code-editor__copy-btn",type:"button",onClick:M,"aria-label":n.ctx.t("Copy")},[...t[0]||(t[0]=[l("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"},[l("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),l("div",U,[u.value?v("",!0):(i(),D(N(W),{key:0,size:"tiny",quaternary:"",onClick:k},{default:J(()=>[h(y(c.value?n.ctx.t("Collapse"):n.ctx.t("Expand")),1)]),_:1}))])])],2))}}),F=q($,[["__scopeId","data-v-646c435a"]]),Y=Object.freeze(Object.defineProperty({__proto__:null,default:F},Symbol.toStringTag,{value:"Module"}));export{F as C,Y as _};
