import{C as F,s as S,ad as M,aA as H,ab as g,aB as y,k as j,r as I,aC as P,aD as N}from"./index-4f532da6.js";var T=Object.defineProperty,A=Object.defineProperties,B=Object.getOwnPropertyDescriptors,V=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable,b=(e,t,a)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,h=(e,t)=>{for(var a in t||(t={}))W.call(t,a)&&b(e,a,t[a]);if(V)for(var a of V(t))z.call(t,a)&&b(e,a,t[a]);return e},q=(e,t)=>A(e,B(t));const _={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}};function G(e,t){const a=M(()=>{const{width:r,height:i}=e;return q(h({},_.wrapper),{width:r,height:i})}),l=M(()=>h(h({},_.fullWidth),!t.value&&_.hide));return{wrapperStyle:a,containerStyle:l}}function J(){const e=S(P.__getMonacoInstance()),t=I(!1);let a;return j(()=>{e.value||(a=P.init(),a.then(r=>e.value=r).catch(r=>{(r==null?void 0:r.type)!=="cancelation"&&(t.value=!0,console.error("Monaco initialization error:",r))}))}),{monacoRef:e,unload:()=>a==null?void 0:a.cancel(),isLoadFailed:t}}function $(e){return typeof e=="function"?e():e}function m(e){return e===void 0}function k(e,t,a,l){return K(e,l)||Q(e,t,a,l)}function K(e,t){return e.editor.getModel(L(e,t))}function Q(e,t,a,l){return e.editor.createModel(t,a,l?L(e,l):void 0)}function L(e,t){return e.Uri.parse(t)}var X=Object.defineProperty,C=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,E=(e,t,a)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,R=(e,t)=>{for(var a in t||(t={}))Y.call(t,a)&&E(e,a,t[a]);if(C)for(var a of C(t))Z.call(t,a)&&E(e,a,t[a]);return e};const ee={display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"};var ne=F({name:"VueMonacoEditor",model:{prop:"value",event:"update:value"},props:{defaultValue:String,defaultPath:String,defaultLanguage:String,value:String,language:String,path:String,theme:{type:String,default:"vs"},line:Number,options:{type:Object,default:()=>({})},overrideServices:{type:Object,default:()=>({})},saveViewState:{type:Boolean,default:!0},width:{type:[Number,String],default:"100%"},height:{type:[Number,String],default:"100%"},className:String},emits:["update:value","beforeMount","mount","change","validate"],setup(e,t){const a=new Map,l=S(null),{monacoRef:r,unload:i,isLoadFailed:o}=J(),{editorRef:n}=te(t,e,r,l),{disposeValidator:v}=ae(t,e,r,n),s=M(()=>!!r.value&&!!n.value),{wrapperStyle:d,containerStyle:O}=G(e,s);return H(()=>{var u,c;(u=v.value)==null||u.call(v),n.value?((c=n.value.getModel())==null||c.dispose(),n.value.dispose()):i()}),g([()=>e.path,()=>e.value,()=>e.language,()=>e.line],([u,c,p,f],[w,re,D,U])=>{if(s.value){if(u!==w){const x=k(r.value,c||e.defaultValue||"",p||e.defaultLanguage||"",u||e.defaultPath||"");e.saveViewState&&a.set(w,n.value.saveViewState()),n.value.setModel(x),e.saveViewState&&n.value.restoreViewState(a.get(u)),m(f)||n.value.revealLine(f);return}n.value.getValue()!==c&&n.value.setValue(c),p!==D&&r.value.editor.setModelLanguage(n.value.getModel(),p),!m(f)&&f!==U&&n.value.revealLine(f)}}),g(()=>e.options,u=>n.value&&n.value.updateOptions(u),{deep:!0}),g(()=>e.theme,u=>r.value&&r.value.editor.setTheme(u)),{containerRef:l,isEditorReady:s,isLoadFailed:o,wrapperStyle:d,containerStyle:O}},render(){const{$slots:e,isEditorReady:t,isLoadFailed:a,wrapperStyle:l,containerStyle:r,className:i}=this;return y("div",{style:l},[!t&&y("div",{style:ee},a?e.failure?$(e.failure):"load failed":e.default?$(e.default):"loading..."),y("div",{ref:"containerRef",key:"monaco_editor_container",style:r,class:i})])}});function te({emit:e},t,a,l){const r=S(null);j(()=>{const o=g(a,()=>{l.value&&a.value&&(N(()=>o()),i())},{immediate:!0})});function i(){var o;if(!l.value||!a.value||r.value)return;e("beforeMount",a.value);const n=t.path||t.defaultPath,v=k(a.value,t.value||t.defaultValue||"",t.language||t.defaultLanguage||"",n||"");r.value=a.value.editor.create(l.value,R({model:v,theme:t.theme,automaticLayout:!0,autoIndent:"brackets",formatOnPaste:!0,formatOnType:!0},t.options),t.overrideServices),(o=r.value)==null||o.onDidChangeModelContent(s=>{const d=r.value.getValue();d!==t.value&&(e("update:value",d),e("change",d,s))}),r.value&&!m(t.line)&&r.value.revealLine(t.line),e("mount",r.value,a.value)}return{editorRef:r}}function ae({emit:e},t,a,l){const r=I(null),i=g([a,l],()=>{if(a.value&&l.value){N(()=>i());const o=a.value.editor.onDidChangeMarkers(n=>{var v,s;const d=(s=(v=l.value)==null?void 0:v.getModel())==null?void 0:s.uri;if(d&&n.find(u=>u.path===d.path)){const u=a.value.editor.getModelMarkers({resource:d});e("validate",u)}});r.value=()=>o==null?void 0:o.dispose()}});return{disposeValidator:r}}export{ne as V};
