import{u as e,l as a,bj as t,bk as l,d as o}from"./utils-lib.js?v=20260328163632";import"./ace.js?v=20260328163632";import{k as s,a9 as u,r as i,x as n,w as r,o as d,n as c,O as v,s as m,a8 as f}from"./base-lib.js?v=20260328163632";const{load:g,request:h}=o(),p=s({name:"BtAceEditor",props:{modelValue:{type:String,default:""},isZoom:{type:Boolean,default:!1},isScrollBottom:{type:Boolean,default:!1},filePath:{type:String,default:""},request:{type:Object,default:!1},encoding:{type:String,default:"utf-8"},autoSave:{type:Boolean,default:!1},editorOption:{type:Object,default:()=>({})}},emits:["update:modelValue","save"],setup(s,{attrs:g,emit:p}){const{isDark:y}=e(),{modelValue:V,editorOption:w}=u(s),S=i("file"),q=i(),b=n(),P=i(!1),B={theme:y.value?"ace/theme/monokai":"ace/theme/chrome",mode:"ace/mode/nginx",wrap:!0,showInvisibles:!1,showFoldWidgets:!1,useSoftTabs:!0,tabSize:2,showPrintMargin:!1,readOnly:!1,fontSize:"12px"},C=i(!1),O=o();r((()=>V.value),(e=>{if(b.value){if(P.value)return void(P.value=!1);b.value.getValue()!==V.value&&(b.value.setValue(e),b.value.moveCursorTo(0,0)),s.isScrollBottom&&b.value.renderer.scrollBar.scrollHeight&&setTimeout((()=>{b.value.getSession().setScrollTop(b.value.renderer.scrollBar.scrollHeight)}),50)}}));const j=async({filePath:e,request:t,encoding:o})=>{const s=O.load(a("正在保存文件，请稍后..."));try{if("file"===S.value){const a=await l({filename:e,data:b.value.getValue()});O.request(a)}else if("request"===S.value){await t.set({data:b.value.getValue(),encoding:o})}else p("save",b.value.getValue())}catch(u){}finally{s.close()}},T=()=>{C.value=!C.value};return d((async()=>{var e,a;await c(),""!==s.filePath?S.value="file":(null==(e=null==s?void 0:s.request)?void 0:e.get)&&(null==(a=null==s?void 0:s.request)?void 0:a.set)?S.value="request":S.value="model",(()=>{try{window.ace.config.set("basePath","/static/editor/");const e=window.ace.edit(q.value,{...f(B),...w.value});e.commands.addCommand({name:"保存文件",bindKey:{win:"Ctrl-S",mac:"Command-S"},exec:()=>{p("save",e.getValue()),s.autoSave&&j({filePath:s.filePath,request:s.request,encoding:s.encoding})},readOnly:!1}),e.getSession().on("change",(()=>{p("update:modelValue",e.getValue())})),b.value=e}catch(e){}})(),"model"!==S.value?(async({filePath:e,request:a})=>{try{if("file"===S.value){const a=await t({filename:e});if(a.status){const{data:e}=a;b.value.setValue(e?e.data:"")}else h(a)}else if("request"===S.value){const{data:e}=await a.get();b.value.setValue(e)}else P.value=!0,p("update:modelValue",b.value.getValue());c((()=>{b.value.focus(),b.value.moveCursorTo(0,0)}))}catch(l){}})({filePath:s.filePath,request:s.request}):(b.value.setValue(V.value),c((()=>{b.value.focus(),b.value.moveCursorTo(0,0)})))})),()=>v("div",{class:"ace-editor-content h-full relative"},[v("div",m({class:"ace-editor "+(s.isZoom,""),style:"height:100%",ref:q},g),null),s.isZoom?v("div",{class:"absolute right-0 top-0 icon-zoom",title:s.isZoom?a("全屏显示"):a("退出全屏"),onClick:T},null):null])}});export{p as B};
