CodeEditor.8bfe03cf.js 1.3 KB

1
  1. import{a as f,w as h,V as m}from"./worker-json.743ca174.js";import{a as g,s as y,v,a7 as s,av as S,bp as w,o as b,j as O,i as u,cz as j,bk as k}from"./index.7e08ba81.js";const B=g({__name:"CodeEditor",props:{value:{type:[String,Object],default:""},readonly:{type:Boolean,default:!1},width:{type:String,default:"100%"},height:{type:String,default:"300px"},theme:{type:String,default:"chrome"}},emits:["update:value","format-error"],setup(d,{emit:p}){f.config.setModuleUrl("ace/mode/json_worker",h);const r=p;let e=y(""),n=d;const t=v({lang:"json",theme:"chrome",readOnly:!1,width:"100%",height:"300px",options:{enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0,tabSize:2,showPrintMargin:!1,fontSize:13,useWorker:"true"}});s(n,()=>{const{value:a,readonly:o,width:i,height:l}=n;if(S(a))try{e.value=JSON.stringify(JSON.parse(a),null,2)}catch(_){r("format-error",a),e.value=a}else w(a)&&(e.value=JSON.stringify(a,null,2));i&&(t.width=i),l&&(t.height=l),o&&(t.readOnly=o)}),s(e,()=>{r("update:value",e.value)});const c=()=>{};return(a,o)=>(b(),O(u(m),{value:u(e),"onUpdate:value":o[0]||(o[0]=i=>j(e)?e.value=i:e=i),onInit:c,lang:"json",theme:t.theme,options:t.options,readonly:t.readOnly,style:k({height:t.height,width:t.width}),class:"ace-editor"},null,8,["value","theme","options","readonly","style"]))}});export{B as default};