/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{defineComponent as e,shallowRef as t,inject as n,computed as o,toRaw as r,onMounted as i,watch as a,onBeforeUnmount as u,h as s}from"vue";import{basicSetup as c}from"../../codemirror/dist/index.js";import{EditorState as l,Compartment as d,StateEffect as f}from"../../@codemirror/state/dist/index.js";import{EditorView as m,keymap as p,placeholder as v}from"../../@codemirror/view/dist/index.js";import{indentWithTab as g}from"../../@codemirror/commands/dist/index.js";import{indentUnit as b}from"../../@codemirror/language/dist/index.js";var h,y,O=Object.freeze({autofocus:!1,disabled:!1,indentWithTab:!0,tabSize:2,placeholder:"",autoDestroy:!0,extensions:[c]}),j=/* @__PURE__ */Symbol("vue-codemirror-global-config"),x=function(e){var t=new d;return{compartment:t,run:function(n){t.get(e.state)?e.dispatch({effects:t.reconfigure(n)}):e.dispatch({effects:f.appendConfig.of(t.of(n))})}}},S=function(e,t){var n=x(e),o=n.compartment,r=n.run;return function(n){var i=o.get(e.state);r((null!=n?n:i!==t)?t:[])}},C={type:Boolean,default:void 0},D={autofocus:C,disabled:C,indentWithTab:C,tabSize:Number,placeholder:String,style:Object,autoDestroy:C,phrases:Object,root:Object,extensions:Array,selection:Object},U={modelValue:{type:String,default:""}},F=Object.assign(Object.assign({},D),U);(y=h||(h={})).Change="change",y.Update="update",y.Focus="focus",y.Blur="blur",y.Ready="ready",y.ModelUpdate="update:modelValue";var w={};w[h.Change]=function(e,t){return!0},w[h.Update]=function(e){return!0},w[h.Focus]=function(e){return!0},w[h.Blur]=function(e){return!0},w[h.Ready]=function(e){return!0};var T={};T[h.ModelUpdate]=w[h.Change];var z=Object.assign(Object.assign({},w),T),B=e({name:"VueCodemirror",props:Object.assign({},F),emits:Object.assign({},z),setup:function(e,c){var d=t(),f=t(),y=t(),C=Object.assign(Object.assign({},O),n(j,{})),D=o(function(){var t={};return Object.keys(r(e)).forEach(function(n){var o;"modelValue"!==n&&(t[n]=null!==(o=e[n])&&void 0!==o?o:C[n])}),t});return i(function(){var t,n;f.value=function(e){var t=e.onUpdate,n=e.onChange,o=e.onFocus,r=e.onBlur,i=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}(e,["onUpdate","onChange","onFocus","onBlur"]);return l.create({doc:i.doc,selection:i.selection,extensions:(Array.isArray(i.extensions)?i.extensions:[i.extensions]).concat([m.updateListener.of(function(e){t(e),e.docChanged&&n(e.state.doc.toString(),e),e.focusChanged&&(e.view.hasFocus?o(e):r(e))})])})}({doc:e.modelValue,selection:D.value.selection,extensions:null!==(t=C.extensions)&&void 0!==t?t:[],onFocus:function(e){return c.emit(h.Focus,e)},onBlur:function(e){return c.emit(h.Blur,e)},onUpdate:function(e){return c.emit(h.Update,e)},onChange:function(t,n){t!==e.modelValue&&(c.emit(h.Change,t,n),c.emit(h.ModelUpdate,t,n))}}),y.value=(n={state:f.value,parent:d.value,root:D.value.root},new m(Object.assign({},n)));var o=function(e){var t=function(){return e.state.doc.toString()},n=x(e).run,o=S(e,[m.editable.of(!1),l.readOnly.of(!0)]),r=S(e,p.of([g])),i=x(e).run,a=x(e).run,u=x(e).run,s=x(e).run;return{focus:function(){return e.focus()},getDoc:t,setDoc:function(n){n!==t()&&e.dispatch({changes:{from:0,to:e.state.doc.length,insert:n}})},reExtensions:n,toggleDisabled:o,toggleIndentWithTab:r,setTabSize:function(e){i([l.tabSize.of(e),b.of(" ".repeat(e))])},setPhrases:function(e){a([l.phrases.of(e)])},setPlaceholder:function(e){u(v(e))},setStyle:function(e){void 0===e&&(e={}),s(m.theme({"&":Object.assign({},e)}))}}}(y.value);a(function(){return e.modelValue},function(e){e!==o.getDoc()&&o.setDoc(e)}),a(function(){return e.extensions},function(e){return o.reExtensions(e||[])},{immediate:!0}),a(function(){return D.value.disabled},function(e){return o.toggleDisabled(e)},{immediate:!0}),a(function(){return D.value.indentWithTab},function(e){return o.toggleIndentWithTab(e)},{immediate:!0}),a(function(){return D.value.tabSize},function(e){return o.setTabSize(e)},{immediate:!0}),a(function(){return D.value.phrases},function(e){return o.setPhrases(e||{})},{immediate:!0}),a(function(){return D.value.placeholder},function(e){return o.setPlaceholder(e)},{immediate:!0}),a(function(){return D.value.style},function(e){return o.setStyle(e)},{immediate:!0}),D.value.autofocus&&o.focus(),c.emit(h.Ready,{state:f.value,view:y.value,container:d.value})}),u(function(){D.value.autoDestroy&&y.value&&function(e){e.destroy()}(y.value)}),function(){return s("div",{class:"v-codemirror",style:{display:"contents"},ref:d})}}}),P=B;export{P as Codemirror,O as DEFAULT_CONFIG};