import{r as C,w as I,l as J,B as b,z as v,y as L,G as M,F as h,O as p,u as m,D as R,K as H,P as q,I as O}from"./vue-BJk78QHK.js";import{j as F,_ as U,c as $,R as z}from"./CodemirrorEditor.vue_vue_type_style_index_0_scoped_4e88775a_lang-C38VhzFb.js";import{_ as A}from"./index-M_JNBppB.js";import{f as j,o as G,q as K}from"./element-3_pOinej.js";const P={class:"dialog-footer"},W={key:1},Q={key:0,class:"button-group"},X={__name:"CodemirrorEditor",props:{isShow:{type:Boolean,default:!1},mode:{type:String,default:"htmlmixed"},code:{type:String,default:""},height:{type:[Number,String],default:600},width:{type:[Number,String],default:"100%"},fontSize:{type:[Number,String],default:"16px"},useDialog:{type:Boolean,default:!0}},emits:["update:isShow","update:code"],setup(o,{emit:B}){const i=o,x=B;window.jsonlint=F,window.JSHINT=U.JSHINT,window.HTMLHint=$.HTMLHint;const g=C(i.isShow),u=C(i.code);I(()=>i.code,e=>{u.value=e}),I(()=>i.isShow,e=>{i.useDialog&&(g.value=e)});const y=J({mode:i.mode,theme:"dracula",lineNumbers:!0,lineWiseCopyCut:!0,gutters:["CodeMirror-lint-markers"],lint:{getAnnotations:(e,t,c,D)=>{let n=[];if(c.mode==="application/json")try{window.jsonlint.parse(e)}catch(f){const s=f.message.match(/line (\d+), col (\d+)/);if(s){const w=Number.parseInt(s[1],10)-1,r=Number.parseInt(s[2],10)-1;n.push({from:{line:w,ch:r},to:{line:w,ch:r+1},message:f.message,severity:"error"})}else n.push({from:{line:0,ch:0},to:{line:0,ch:1},message:`Invalid JSON: ${f.message}`,severity:"error"})}else{if(window.HTMLHint&&typeof window.HTMLHint.verify=="function"){const r=window.HTMLHint.verify(e,{"tag-pair":!0,"attr-value-double-quotes":!0});n=n.concat(r.map(a=>({from:D.posFromIndex(a.col-1),to:D.posFromIndex(a.col),message:a.message,severity:"error"})))}const f=/<script[^>]*>([\s\S]*?)<\/script>/gi;let s;for(;(s=f.exec(e))!==null;){const r=s[1];window.JSHINT(r,{asi:!1,curly:!0,esversion:11,laxbreak:!0,undef:!1,unused:!1,eqeqeq:!1,strict:!1},{document:!0,echarts:!0,$:!0,window:!0,setInterval:!0,console:!0,myChart:!0});const a=window.JSHINT.errors||[],d=e.substr(0,s.index).split(`
`).length-1;n=n.concat(a.map(l=>({from:{line:d+(l.line-1),ch:l.character-1},to:{line:d+(l.line-1),ch:l.character},message:l.reason,severity:"error"})))}const w=/<script[^>]*type="application\/json"[^>]*>([\s\S]*?)<\/script>/gi;for(;(s=w.exec(e))!==null;){const r=s[1];try{window.jsonlint.parse(r)}catch(a){const d=a.message.match(/line (\d+), col (\d+)/),l=e.substr(0,s.index).split(`
`).length-1;if(d){const E=l+Number.parseInt(d[1],10)-1,V=Number.parseInt(d[2],10)-1;n.push({from:{line:E,ch:V},to:{line:E,ch:V+1},message:a.message,severity:"error"})}else n.push({from:{line:l,ch:0},to:{line:l,ch:1},message:`Invalid JSON: ${a.message}`,severity:"error"})}}}t(n)},async:!0}}),S=C(null);function k(e){S.value=e,e.getValue()}function T(){u.value,x("update:code",u.value),i.useDialog&&(K({message:"保存成功",type:"success"}),N())}function N(){i.useDialog&&(g.value=!1,x("update:isShow",!1))}return I(()=>i.mode,e=>{y.mode=e,S.value&&S.value.setOption("mode",e)}),(e,t)=>(v(),b("div",null,[o.useDialog?(v(),L(m(G),{key:0,modelValue:g.value,"onUpdate:modelValue":t[1]||(t[1]=c=>g.value=c),draggable:"",title:"代码编辑器",width:"70%",onClose:N},{footer:h(()=>[R("span",P,[p(m(j),{onClick:N},{default:h(()=>t[3]||(t[3]=[H("取消")])),_:1}),p(m(j),{type:"primary",onClick:T},{default:h(()=>t[4]||(t[4]=[H("确认")])),_:1})])]),default:h(()=>[p(m(z),{value:u.value,"onUpdate:value":t[0]||(t[0]=c=>u.value=c),options:y,height:o.height,width:o.width,"font-size":o.fontSize,class:"cm-component",onReady:k},null,8,["value","options","height","width","font-size"])]),_:1},8,["modelValue"])):M((v(),b("div",W,[p(m(z),{value:u.value,"onUpdate:value":t[2]||(t[2]=c=>u.value=c),options:y,height:o.height,width:o.width,"font-size":o.fontSize,class:"cm-component",onReady:k},null,8,["value","options","height","width","font-size"]),o.isShow?(v(),b("div",Q,[p(m(j),{type:"primary",onClick:T},{default:h(()=>t[5]||(t[5]=[H(" 确定 ")])),_:1})])):O("",!0)],512)),[[q,o.isShow]])]))}},te=A(X,[["__scopeId","data-v-4e88775a"]]);export{te as C};
