vue-codemirror6 1.2.2 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -3,9 +3,9 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.0
8
+ * @version 1.2.5
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
@@ -241,7 +241,7 @@ var oe = I({
241
241
  /** Emits */
242
242
  emits: {
243
243
  /** Model Update */
244
- "update:modelValue": (e) => !0,
244
+ "update:modelValue": (e = "") => !0,
245
245
  /** CodeMirror ViewUpdate */
246
246
  update: (e) => !0,
247
247
  /** CodeMirror onReady */
@@ -285,7 +285,7 @@ var oe = I({
285
285
  e.minimal && !e.basic ? K : void 0,
286
286
  // ViewUpdate event listener
287
287
  r.updateListener.of((i) => {
288
- o.emit("focus", t.value.hasFocus), p.value = t.value.state.doc.length, !(i.changes.empty || !i.docChanged) && (e.linter && (e.forceLinting && $(t.value), g.value = e.linter(t.value).length), o.emit("update", i));
288
+ o.emit("focus", t.value.hasFocus), p.value = t.value.state.doc?.length, !(i.changes.empty || !i.docChanged) && (e.linter && (e.forceLinting && $(t.value), g.value = e.linter(t.value).length), o.emit("update", i));
289
289
  }),
290
290
  // Toggle light/dark mode.
291
291
  r.theme(e.theme, { dark: e.dark }),
@@ -345,7 +345,7 @@ var oe = I({
345
345
  parent: n.value,
346
346
  state: s.create({ doc: a, extensions: h.value }),
347
347
  dispatch: (l) => {
348
- t.value.update([l]), !(l.changes.empty || !l.docChanged) && (o.emit("update:modelValue", l.state.doc.toString()), o.emit("change", l.state));
348
+ t.value.update([l]), !(l.changes.empty || !l.docChanged) && (o.emit("update:modelValue", l.state.doc.toString() ?? ""), o.emit("change", l.state));
349
349
  }
350
350
  }), await k(), o.emit("ready", {
351
351
  view: t.value,
@@ -385,6 +385,7 @@ var oe = I({
385
385
  selection: O.create(a, l)
386
386
  }), _ = (a) => t.value.dispatch({
387
387
  selection: O.create(
388
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
388
389
  f.value.ranges.map((l) => l.extend(a(l)))
389
390
  )
390
391
  }), S = {
@@ -436,8 +437,8 @@ var oe = I({
436
437
  }
437
438
  });
438
439
  const ie = {
439
- version: "1.2.0",
440
- date: "2024-01-08T15:53:56.825Z"
440
+ version: "1.2.5",
441
+ date: "2024-02-05T00:38:11.929Z"
441
442
  };
442
443
  var ve = ie;
443
444
  const me = (e) => e.component("CodeMirror", oe);
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.0
8
+ * @version 1.2.5
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror=function(u,n,y,r,i,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((c,[o,d])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...c,[o]:d}),{}):{};function p(e,c={},o){if(n.isVue2)return n.h(e,c,o);const{props:d,domProps:t,on:v,...g}=c,h=v?V(v):{};return n.h(e,{...g,...d,...t,...h},o)}const O=e=>typeof e=="function"?e():e;var b=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":e=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,c){const o=n.ref(),d=n.ref(e.modelValue),t=n.shallowRef(new r.EditorView),v=n.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),g=n.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=n.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=n.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),C=n.ref(0),m=n.ref(0),S=n.computed(()=>{const a=new i.Compartment,l=new i.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,r.EditorView.updateListener.of(s=>{c.emit("focus",t.value.hasFocus),C.value=t.value.state.doc.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),c.emit("update",s))}),r.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?r.EditorView.lineWrapping:void 0,e.tab?r.keymap.of([E.indentWithTab]):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?l.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),r.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?r.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});n.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),n.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),n.onMounted(async()=>{let a=d.value;o.value&&(o.value.childNodes[0]&&(d.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new r.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:l=>{t.value.update([l]),!(l.changes.empty||!l.docChanged)&&(c.emit("update:modelValue",l.state.doc.toString()),c.emit("change",l.state))}}),await n.nextTick(),c.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),n.onUnmounted(()=>{t.value.destroy(),c.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,l)=>t.value.state.sliceDoc(a,l),z=a=>t.value.state.doc.line(a+1).text,T=()=>t.value.state.doc.lines,R=()=>t.value.state.selection.main.head,_=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(l=>a.sliceDoc(l.from,l.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,l,s)=>t.value.dispatch({changes:{from:l,to:s,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),U=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,l)=>t.value.dispatch({selection:{anchor:a,head:l}}),G=(a,l)=>t.value.dispatch({selection:i.EditorSelection.create(a,l)}),I=a=>t.value.dispatch({selection:i.EditorSelection.create(g.value.ranges.map(l=>l.extend(a(l))))}),w={editor:o,view:t,cursor:h,selection:g,focus:v,length:C,json:B,diagnosticCount:m,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:N,getLine:z,lineCount:T,getCursor:R,listSelections:_,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:U,setSelection:W,setSelections:G,extendSelectionsBy:I};return c.expose(w),w},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.0",date:"2024-01-08T15:53:56.825Z"};const $=e=>e.component("CodeMirror",b);return u.Meta=M,u.default=b,u.install=$,Object.defineProperty(u,"__esModule",{value:!0}),u}({},VueDemi,codemirror,view,state,lint,commands);
12
+ var CodeMirror=function(u,n,y,r,i,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((c,[o,d])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...c,[o]:d}),{}):{};function p(e,c={},o){if(n.isVue2)return n.h(e,c,o);const{props:d,domProps:t,on:v,...g}=c,h=v?V(v):{};return n.h(e,{...g,...d,...t,...h},o)}const O=e=>typeof e=="function"?e():e;var b=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,c){const o=n.ref(),d=n.ref(e.modelValue),t=n.shallowRef(new r.EditorView),v=n.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),g=n.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=n.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=n.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),C=n.ref(0),m=n.ref(0),S=n.computed(()=>{const a=new i.Compartment,l=new i.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,r.EditorView.updateListener.of(s=>{c.emit("focus",t.value.hasFocus),C.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),c.emit("update",s))}),r.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?r.EditorView.lineWrapping:void 0,e.tab?r.keymap.of([E.indentWithTab]):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?l.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),r.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?r.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});n.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),n.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
+ `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),n.onMounted(async()=>{let a=d.value;o.value&&(o.value.childNodes[0]&&(d.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new r.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:l=>{t.value.update([l]),!(l.changes.empty||!l.docChanged)&&(c.emit("update:modelValue",l.state.doc.toString()??""),c.emit("change",l.state))}}),await n.nextTick(),c.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),n.onUnmounted(()=>{t.value.destroy(),c.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,l)=>t.value.state.sliceDoc(a,l),z=a=>t.value.state.doc.line(a+1).text,T=()=>t.value.state.doc.lines,R=()=>t.value.state.selection.main.head,_=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(l=>a.sliceDoc(l.from,l.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,l,s)=>t.value.dispatch({changes:{from:l,to:s,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),U=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,l)=>t.value.dispatch({selection:{anchor:a,head:l}}),G=(a,l)=>t.value.dispatch({selection:i.EditorSelection.create(a,l)}),I=a=>t.value.dispatch({selection:i.EditorSelection.create(g.value.ranges.map(l=>l.extend(a(l))))}),w={editor:o,view:t,cursor:h,selection:g,focus:v,length:C,json:B,diagnosticCount:m,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:N,getLine:z,lineCount:T,getCursor:R,listSelections:_,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:U,setSelection:W,setSelections:G,extendSelectionsBy:I};return c.expose(w),w},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.5",date:"2024-02-05T00:38:11.929Z"};const $=e=>e.component("CodeMirror",b);return u.Meta=M,u.default=b,u.install=$,Object.defineProperty(u,"__esModule",{value:!0}),u}({},VueDemi,codemirror,view,state,lint,commands);
package/dist/index.umd.js CHANGED
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.0
8
+ * @version 1.2.5
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- (function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue-demi"),require("codemirror"),require("@codemirror/view"),require("@codemirror/state"),require("@codemirror/lint"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","vue-demi","codemirror","@codemirror/view","@codemirror/state","@codemirror/lint","@codemirror/commands"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.CodeMirror={},l.VueDemi,l.codemirror,l.view,l.state,l.lint,l.commands))})(this,function(l,o,y,c,r,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((d,[i,u])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:u}),{}):{};function p(e,d={},i){if(o.isVue2)return o.h(e,d,i);const{props:u,domProps:t,on:v,...m}=d,h=v?V(v):{};return o.h(e,{...m,...u,...t,...h},i)}const O=e=>typeof e=="function"?e():e;var w=o.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":e=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const i=o.ref(),u=o.ref(e.modelValue),t=o.shallowRef(new c.EditorView),v=o.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=o.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=o.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=o.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),C=o.ref(0),g=o.ref(0),S=o.computed(()=>{const a=new r.Compartment,n=new r.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),C.value=t.value.state.doc.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),g.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});o.watch(S,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),o.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),o.onMounted(async()=>{let a=u.value;i.value&&(i.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=i.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:i.value,state:r.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()),d.emit("change",n.state))}}),await o.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:i.value}))}),o.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),g.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(S.value)})},T=(a,n)=>t.value.state.sliceDoc(a,n),q=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,z=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},R=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},_=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),U=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),W=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),G=a=>t.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))}),b={editor:i,view:t,cursor:h,selection:m,focus:v,length:C,json:B,diagnosticCount:g,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:T,getLine:q,lineCount:x,getCursor:N,listSelections:z,getSelection:R,getSelections:_,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:U,setSelections:W,extendSelectionsBy:G};return d.expose(b),b},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.0",date:"2024-01-08T15:53:56.825Z"};const $=e=>e.component("CodeMirror",w);l.Meta=M,l.default=w,l.install=$,Object.defineProperty(l,"__esModule",{value:!0})});
12
+ (function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue-demi"),require("codemirror"),require("@codemirror/view"),require("@codemirror/state"),require("@codemirror/lint"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","vue-demi","codemirror","@codemirror/view","@codemirror/state","@codemirror/lint","@codemirror/commands"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.CodeMirror={},l.VueDemi,l.codemirror,l.view,l.state,l.lint,l.commands))})(this,function(l,o,y,c,r,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((d,[i,u])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:u}),{}):{};function p(e,d={},i){if(o.isVue2)return o.h(e,d,i);const{props:u,domProps:t,on:v,...m}=d,h=v?V(v):{};return o.h(e,{...m,...u,...t,...h},i)}const O=e=>typeof e=="function"?e():e;var w=o.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const i=o.ref(),u=o.ref(e.modelValue),t=o.shallowRef(new c.EditorView),v=o.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=o.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=o.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=o.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),C=o.ref(0),g=o.ref(0),S=o.computed(()=>{const a=new r.Compartment,n=new r.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),C.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),g.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});o.watch(S,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),o.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
+ `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),o.onMounted(async()=>{let a=u.value;i.value&&(i.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=i.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:i.value,state:r.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()??""),d.emit("change",n.state))}}),await o.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:i.value}))}),o.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),g.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(S.value)})},T=(a,n)=>t.value.state.sliceDoc(a,n),q=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,z=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},R=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},_=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),U=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),W=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),G=a=>t.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))}),b={editor:i,view:t,cursor:h,selection:m,focus:v,length:C,json:B,diagnosticCount:g,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:T,getLine:q,lineCount:x,getCursor:N,listSelections:z,getSelection:R,getSelections:_,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:U,setSelections:W,extendSelectionsBy:G};return d.expose(b),b},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.5",date:"2024-02-05T00:38:11.929Z"};const $=e=>e.component("CodeMirror",w);l.Meta=M,l.default=w,l.install=$,Object.defineProperty(l,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "vue-codemirror6",
4
- "version": "1.2.2",
4
+ "version": "1.2.5",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -55,7 +55,7 @@
55
55
  "engines": {
56
56
  "yarn": ">=1.22.19"
57
57
  },
58
- "packageManager": "yarn@4.0.2",
58
+ "packageManager": "yarn@4.1.0",
59
59
  "sideEffects": false,
60
60
  "scripts": {
61
61
  "dev": "vite",
@@ -84,8 +84,8 @@
84
84
  "@codemirror/lang-markdown": "^6.2.4",
85
85
  "@codemirror/lang-vue": "0.1.2",
86
86
  "@tsconfig/node-lts": "^20.1.1",
87
- "@types/node": "^20.11.5",
88
- "@typescript-eslint/eslint-plugin": "^6.19.0",
87
+ "@types/node": "^20.11.16",
88
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
89
89
  "@vitejs/plugin-vue": "^5.0.3",
90
90
  "@vue/compiler-sfc": "^3.4.15",
91
91
  "@vue/eslint-config-prettier": "^9.0.0",
@@ -93,7 +93,7 @@
93
93
  "@vueuse/core": "^10.7.2",
94
94
  "bootstrap": "^5.3.2",
95
95
  "eslint": "^8.56.0",
96
- "eslint-config-standard-with-typescript": "^43.0.0",
96
+ "eslint-config-standard-with-typescript": "^43.0.1",
97
97
  "eslint-import-resolver-alias": "^1.1.2",
98
98
  "eslint-import-resolver-typescript": "^3.6.1",
99
99
  "eslint-linter-browserify": "^8.56.0",
@@ -105,20 +105,20 @@
105
105
  "eslint-plugin-vue": "latest",
106
106
  "eslint-plugin-vuejs-accessibility": "^2.2.1",
107
107
  "eslint-plugin-yaml": "^0.5.0",
108
- "husky": "^8.0.3",
109
- "lint-staged": "^15.2.0",
108
+ "husky": "^9.0.10",
109
+ "lint-staged": "^15.2.1",
110
110
  "npm-run-all": "^4.1.5",
111
- "prettier": "^3.2.4",
111
+ "prettier": "^3.2.5",
112
112
  "rimraf": "^5.0.5",
113
113
  "rollup-plugin-visualizer": "^5.12.0",
114
114
  "sass": "^1.70.0",
115
115
  "typescript": "^5.3.3",
116
116
  "vite": "^5.0.12",
117
117
  "vite-plugin-banner": "^0.7.1",
118
- "vite-plugin-checker": "^0.6.2",
119
- "vite-plugin-dts": "^3.7.1",
118
+ "vite-plugin-checker": "^0.6.4",
119
+ "vite-plugin-dts": "^3.7.2",
120
120
  "vue": "^3.4.15",
121
- "vue-eslint-parser": "^9.4.0",
121
+ "vue-eslint-parser": "^9.4.2",
122
122
  "vue-markdown-wasm": "^0.4.0",
123
123
  "vue-tsc": "^1.8.27"
124
124
  },
@@ -138,4 +138,4 @@
138
138
  "yaml": "^2.3.2",
139
139
  "vite": ">5.0.5"
140
140
  }
141
- }
141
+ }
@@ -263,7 +263,7 @@ export default defineComponent({
263
263
  /** Emits */
264
264
  emits: {
265
265
  /** Model Update */
266
- 'update:modelValue': (value: string | Text) => true,
266
+ 'update:modelValue': (value: string | Text = '') => true,
267
267
  /** CodeMirror ViewUpdate */
268
268
  update: (value: ViewUpdate) => true,
269
269
  /** CodeMirror onReady */
@@ -364,8 +364,9 @@ export default defineComponent({
364
364
  EditorView.updateListener.of((update: ViewUpdate): void => {
365
365
  // Emit focus status
366
366
  context.emit('focus', view.value.hasFocus);
367
+
367
368
  // Update count
368
- length.value = view.value.state.doc.length;
369
+ length.value = view.value.state.doc?.length;
369
370
 
370
371
  if (update.changes.empty || !update.docChanged) {
371
372
  // Suppress event firing if no change
@@ -478,7 +479,6 @@ export default defineComponent({
478
479
  state: EditorState.create({ doc: value, extensions: extensions.value }),
479
480
  dispatch: (tr: Transaction) => {
480
481
  view.value.update([tr]);
481
-
482
482
  if (tr.changes.empty || !tr.docChanged) {
483
483
  // if not change value, no fire emit event
484
484
  return;
@@ -486,7 +486,7 @@ export default defineComponent({
486
486
 
487
487
  // console.log(view.state.doc.toString(), tr);
488
488
  // state.toString() is not defined, so use toJSON and toText function to convert string.
489
- context.emit('update:modelValue', tr.state.doc);
489
+ context.emit('update:modelValue', tr.state.doc.toString() ?? '');
490
490
  // Emit EditorState
491
491
  context.emit('change', tr.state);
492
492
  },