vue-codemirror6 1.3.22 → 1.4.1

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/CHANGELOG.md CHANGED
@@ -4,7 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- #### [1.3.21](https://github.com/logue/vue-codemirror6/compare/1.3.21...1.3.21)
7
+ #### [1.4.1](https://github.com/logue/vue-codemirror6/compare/1.4.0...1.4.1)
8
+
9
+ - Move the contents of Codemirror.ts to index.ts. [`d9a624b`](https://github.com/logue/vue-codemirror6/commit/d9a624bbe61034b2a5abe553b0e362818ea8e91b)
10
+ - Delete unnecessary specifications. [`0eec4b1`](https://github.com/logue/vue-codemirror6/commit/0eec4b1510e3dbb16cf7927b673e109f7be9e68a)
11
+ - Fixed type check error. [`7e80246`](https://github.com/logue/vue-codemirror6/commit/7e802465e3fde974a9c797d8512e20639fb2edbe)
12
+
13
+ #### [1.4.0](https://github.com/logue/vue-codemirror6/compare/1.3.21...1.4.0)
14
+
15
+ > 17 October 2025
16
+
17
+ - Update CHANGELOG.md. [`0d97dff`](https://github.com/logue/vue-codemirror6/commit/0d97dff0e60abc577cf4dd2ff67218cbbde5f6c0)
18
+ - Add support for SSR (Nuxt, VitePress、Quasar SSR etc) [`98b5f28`](https://github.com/logue/vue-codemirror6/commit/98b5f28e505bab4b9bb55e1e989d507011e19208)
19
+ - Add Test program. [`9fd5409`](https://github.com/logue/vue-codemirror6/commit/9fd5409e37751fe2a54de9e8a221aaf707b84731)
8
20
 
9
21
  #### [1.3.21](https://github.com/logue/vue-codemirror6/compare/1.3.13...1.3.21)
10
22
 
@@ -27,7 +39,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
27
39
 
28
40
  > 22 November 2024
29
41
 
30
- - Fix sample code syntax error [`#47`](https://github.com/logue/vue-codemirror6/pull/47)
42
+ - Fix sample code syntax error [`#47`](https://github.com/logue/vue-codemirror6/pull/47)
31
43
  - chore: demo docs [`#43`](https://github.com/logue/vue-codemirror6/pull/43)
32
44
  - fix: editor not update content when `modelValue` change and selection is out of range [`#44`](https://github.com/logue/vue-codemirror6/pull/44)
33
45
  - chore: props and readme doc [`#31`](https://github.com/logue/vue-codemirror6/pull/31)
@@ -59,7 +71,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
59
71
 
60
72
  - chore(CODEOWNERS): CODEOWNERS.com Bot, at your service! [`#14`](https://github.com/logue/vue-codemirror6/pull/14)
61
73
  - Update demo code. (Replaced @codemirror/html to @codemirror/vue.) [`8da1a8a`](https://github.com/logue/vue-codemirror6/commit/8da1a8a4e37d713cc78281ce9c304c42a06940dc)
62
- - Changed implementation to generate *.d.ts with vite-plugin-dts. [`1caaa20`](https://github.com/logue/vue-codemirror6/commit/1caaa20b1423a3d252a6c770a630fb60e2e3440d)
74
+ - Changed implementation to generate \*.d.ts with vite-plugin-dts. [`1caaa20`](https://github.com/logue/vue-codemirror6/commit/1caaa20b1423a3d252a6c770a630fb60e2e3440d)
63
75
  - Update README.md. [`f8dd493`](https://github.com/logue/vue-codemirror6/commit/f8dd4934a7b9cc089cd830473db5250d28b3389b)
64
76
 
65
77
  #### [1.1.11](https://github.com/logue/vue-codemirror6/compare/1.1.3...1.1.11)
package/README.md CHANGED
@@ -202,6 +202,37 @@ export default defineComponent({
202
202
  </script>
203
203
  ```
204
204
 
205
+ ### Using with SSR (Nuxt.js, etc.)
206
+
207
+ This component is now SSR-compatible. CodeMirror will only be initialized on the client side, and the component will safely render without errors during server-side rendering.
208
+
209
+ If you're using Nuxt 3, you can use the component directly:
210
+
211
+ ```vue
212
+ <template>
213
+ <code-mirror v-model="value" :lang="lang" />
214
+ </template>
215
+
216
+ <script setup lang="ts">
217
+ import { ref } from 'vue';
218
+ import CodeMirror from 'vue-codemirror6';
219
+ import { javascript } from '@codemirror/lang-javascript';
220
+
221
+ const value = ref('console.log("Hello, World!");');
222
+ const lang = javascript();
223
+ </script>
224
+ ```
225
+
226
+ For Nuxt 2 or if you encounter any issues, you can wrap the component with `<ClientOnly>`:
227
+
228
+ ```vue
229
+ <template>
230
+ <client-only>
231
+ <code-mirror v-model="value" :lang="lang" />
232
+ </client-only>
233
+ </template>
234
+ ```
235
+
205
236
  ### Full Example
206
237
 
207
238
  When using as a Markdown editor on [vite-vue3-ts-starter](https://github.com/logue/vite-vue3-ts-starter).
@@ -378,6 +409,33 @@ const config: UserConfig = {
378
409
  };
379
410
  ```
380
411
 
412
+ ## Development
413
+
414
+ ### Testing
415
+
416
+ This project uses [Vitest](https://vitest.dev/) for unit testing.
417
+
418
+ ```bash
419
+ # Run tests
420
+ pnpm test
421
+
422
+ # Run tests in watch mode
423
+ pnpm test:watch
424
+
425
+ # Run tests with UI
426
+ pnpm test:ui
427
+
428
+ # Run tests with coverage
429
+ pnpm test:coverage
430
+ ```
431
+
432
+ The test suite includes:
433
+
434
+ - **Component Tests**: Testing basic rendering, props, events, and v-model binding
435
+ - **SSR Tests**: Ensuring proper server-side rendering compatibility for Nuxt.js and other SSR frameworks
436
+ - **Method Tests**: Verifying all exposed methods work correctly
437
+ - **Edge Cases**: Testing error handling and unusual scenarios
438
+
381
439
  ## LICENSE
382
440
 
383
441
  ©2022-2025 by Logue.
package/dist/index.cjs.js CHANGED
@@ -5,9 +5,9 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2025 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.3.22
8
+ * @version 1.4.1
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var T=require("@codemirror/commands"),A=require("@codemirror/language"),f=require("@codemirror/lint"),o=require("@codemirror/state"),s=require("@codemirror/view"),b=require("codemirror"),n=require("vue-demi");const F={version:"1.3.22",date:"2025-07-12T05:13:58.540Z"},I=e=>e?Object.entries(e).reduce((r,[l,c])=>(l=l.charAt(0).toUpperCase()+l.slice(1),l=`on${l}`,{...r,[l]:c}),{}):{};function p(e,r={},l){if(n.isVue2)return n.h(e,r,l);const{props:c,domProps:t,on:v,...m}=r,h=v?I(v):{};return n.h(e,{...m,...c,...t,...h},l)}const J=e=>typeof e=="function"?e():e;var C=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},indentUnit:{type:String,default:void 0},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:void 0},lang:{type:Object,default:void 0},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:void 0},tag:{type:String,default:"div"},scrollIntoView:{type:Boolean,default:!0},keymap:{type:Array,default:()=>[]}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,r){const l=n.ref(),c=n.ref(e.modelValue),t=n.shallowRef(new s.EditorView),v=n.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=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}})}),E=n.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(o.EditorState.fromJSON(a))}),S=n.ref(0),g=n.ref(0),y=n.computed(()=>{const a=new o.Compartment,i=new o.Compartment;if(e.basic&&e.minimal)throw new Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");let u=[];return e.keymap&&e.keymap.length>0&&(u=e.keymap),e.tab&&u.push(T.indentWithTab),[e.basic&&!e.minimal?b.basicSetup:void 0,e.minimal&&!e.basic?b.minimalSetup:void 0,s.EditorView.updateListener.of(d=>{r.emit("focus",t.value.hasFocus),S.value=t.value.state.doc?.length,!(d.changes.empty||!d.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),g.value=e.linter(t.value).length),r.emit("update",d))}),s.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?s.EditorView.lineWrapping:void 0,e.indentUnit?A.indentUnit.of(e.indentUnit):void 0,o.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?i.of(o.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?o.EditorState.phrases.of(e.phrases):void 0,o.EditorState.readOnly.of(e.readonly),s.EditorView.editable.of(!e.disabled),e.lineSeparator?o.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?s.placeholder(e.placeholder):void 0,u.length!==0?s.keymap.of(u):void 0,...e.extensions].filter(d=>!!d)});n.watch(y,a=>t.value?.dispatch({effects:o.StateEffect.reconfigure.of(a)}),{immediate:!0}),n.watch(()=>e.modelValue,async a=>{if(t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a)return;const i=!t.value.state.selection.ranges.every(u=>u.anchor<a.length&&u.head<a.length);t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:i?{anchor:0,head:0}:t.value.state.selection,scrollIntoView:e.scrollIntoView})},{immediate:!0}),n.onMounted(async()=>{let a=c.value;l.value&&(l.value.childNodes[0]&&(c.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=l.value.childNodes[0].innerText.trim()),t.value=new s.EditorView({parent:l.value,state:o.EditorState.create({doc:a,extensions:y.value}),dispatch:i=>{t.value.update([i]),!(i.changes.empty||!i.docChanged)&&(r.emit("update:modelValue",i.state.doc.toString()),r.emit("change",i.state))}}),await n.nextTick(),r.emit("ready",{view:t.value,state:t.value.state,container:l.value}))}),n.onUnmounted(()=>{t.value.destroy(),r.emit("destroy")});const V=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),g.value=f.diagnosticCount(t.value.state))},O=()=>{t.value?.dispatch({effects:o.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:o.StateEffect.appendConfig.of(y.value)})},B=(a,i)=>t.value.state.sliceDoc(a,i),M=a=>t.value.state.doc.line(a+1).text,$=()=>t.value.state.doc.lines,j=()=>t.value.state.selection.main.head,_=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},q=()=>{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:""},L=()=>{const a=t.value.state;return a?a.selection.ranges.map(i=>a.sliceDoc(i.from,i.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),N=(a,i,u)=>t.value.dispatch({changes:{from:i,to:u,insert:a}}),U=a=>t.value.dispatch(t.value.state.replaceSelection(a)),k=a=>t.value.dispatch({selection:{anchor:a}}),z=(a,i)=>t.value.dispatch({selection:{anchor:a,head:i}}),D=(a,i)=>t.value.dispatch({selection:o.EditorSelection.create(a,i)}),R=a=>t.value.dispatch({selection:o.EditorSelection.create(m.value.ranges.map(i=>i.extend(a(i))))}),w={editor:l,view:t,cursor:h,selection:m,focus:v,length:S,json:E,diagnosticCount:g,dom:t.value.contentDOM,lint:V,forceReconfigure:O,getRange:B,getLine:M,lineCount:$,getCursor:j,listSelections:_,getSelection:q,getSelections:L,somethingSelected:x,replaceRange:N,replaceSelection:U,setCursor:k,setSelection:z,setSelections:D,extendSelectionsBy:R};return r.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"},J(this.$slots.default)):void 0)}});const P=e=>e.component("CodeMirror",C);exports.Meta=F;exports.default=C;exports.install=P;
12
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var R=require("@codemirror/commands"),A=require("@codemirror/language"),v=require("@codemirror/lint"),o=require("@codemirror/state"),s=require("@codemirror/view"),b=require("codemirror"),n=require("vue-demi");const F={version:"1.4.1",date:"2025-10-17T22:30:13.688Z"},I=t=>t?Object.entries(t).reduce((u,[l,c])=>(l=l.charAt(0).toUpperCase()+l.slice(1),l=`on${l}`,{...u,[l]:c}),{}):{};function p(t,u={},l){if(n.isVue2)return n.h(t,u,l);const{props:c,domProps:e,on:m,...d}=u,h=m?I(m):{};return n.h(t,{...d,...c,...e,...h},l)}const J=t=>typeof t=="function"?t():t,C=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},indentUnit:{type:String,default:void 0},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:void 0},lang:{type:Object,default:void 0},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:void 0},tag:{type:String,default:"div"},scrollIntoView:{type:Boolean,default:!0},keymap:{type:Array,default:()=>[]}},emits:{"update:modelValue":(t="")=>!0,update:t=>!0,ready:t=>!0,focus:t=>!0,change:t=>!0,destroy:()=>!0},setup(t,u){const l=n.ref(),c=n.ref(t.modelValue),e=n.shallowRef(void 0),m=n.computed({get:()=>e.value?.hasFocus??!1,set:a=>{a&&e.value&&e.value.focus()}}),d=n.computed({get:()=>e.value?.state.selection,set:a=>{e.value&&a&&e.value.dispatch({selection:a})}}),h=n.computed({get:()=>e.value?.state.selection.main.head??0,set:a=>{e.value&&e.value.dispatch({selection:{anchor:a}})}}),E=n.computed({get:()=>e.value?.state.toJSON(),set:a=>{e.value&&a&&e.value.setState(o.EditorState.fromJSON(a))}}),S=n.ref(0),g=n.ref(0),y=n.computed(()=>{const a=new o.Compartment,i=new o.Compartment;if(t.basic&&t.minimal)throw new Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");let r=[];return t.keymap&&t.keymap.length>0&&(r=t.keymap),t.tab&&r.push(R.indentWithTab),[t.basic&&!t.minimal?b.basicSetup:void 0,t.minimal&&!t.basic?b.minimalSetup:void 0,s.EditorView.updateListener.of(f=>{e.value&&(u.emit("focus",e.value.hasFocus),S.value=e.value.state.doc?.length,!(f.changes.empty||!f.docChanged)&&(t.linter&&(t.forceLinting&&v.forceLinting(e.value),g.value=t.linter(e.value).length),u.emit("update",f)))}),s.EditorView.theme(t.theme,{dark:t.dark}),t.wrap?s.EditorView.lineWrapping:void 0,t.indentUnit?A.indentUnit.of(t.indentUnit):void 0,o.EditorState.allowMultipleSelections.of(t.allowMultipleSelections),t.tabSize?i.of(o.EditorState.tabSize.of(t.tabSize)):void 0,t.phrases?o.EditorState.phrases.of(t.phrases):void 0,o.EditorState.readOnly.of(t.readonly),s.EditorView.editable.of(!t.disabled),t.lineSeparator?o.EditorState.lineSeparator.of(t.lineSeparator):void 0,t.lang?a.of(t.lang):void 0,t.linter?v.linter(t.linter,t.linterConfig):void 0,t.linter&&t.gutter?v.lintGutter(t.gutterConfig):void 0,t.placeholder?s.placeholder(t.placeholder):void 0,r.length>0?s.keymap.of(r):void 0,...t.extensions].filter(f=>!!f)});n.watch(y,a=>e.value?.dispatch({effects:o.StateEffect.reconfigure.of(a)}),{immediate:!0}),n.watch(()=>t.modelValue,async a=>{if(!e.value||e.value.composing||e.value.state.doc.toJSON().join(t.lineSeparator??`
13
+ `)===a)return;const i=!e.value.state.selection.ranges.every(r=>r.anchor<a.length&&r.head<a.length);e.value.dispatch({changes:{from:0,to:e.value.state.doc.length,insert:a},selection:i?{anchor:0,head:0}:e.value.state.selection,scrollIntoView:t.scrollIntoView})},{immediate:!0}),n.onMounted(async()=>{if(globalThis.window===void 0||!l.value)return;let a=c.value;l.value.childNodes[0]&&(c.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=l.value.childNodes[0].innerText.trim()),e.value=new s.EditorView({parent:l.value,state:o.EditorState.create({doc:a,extensions:y.value}),dispatch:i=>{e.value&&(e.value.update([i]),!(i.changes.empty||!i.docChanged)&&(u.emit("update:modelValue",i.state.doc.toString()),u.emit("change",i.state)))}}),await n.nextTick(),u.emit("ready",{view:e.value,state:e.value.state,container:l.value})}),n.onUnmounted(()=>{e.value&&(e.value.destroy(),u.emit("destroy"))});const V=()=>{!t.linter||!e.value||(t.forceLinting&&v.forceLinting(e.value),g.value=v.diagnosticCount(e.value.state))},O=()=>{e.value?.dispatch({effects:o.StateEffect.reconfigure.of([])}),e.value?.dispatch({effects:o.StateEffect.appendConfig.of(y.value)})},B=(a,i)=>e.value?.state.sliceDoc(a,i),M=a=>e.value?.state.doc.line(a+1).text,j=()=>e.value?.state.doc.lines??0,q=()=>e.value?.state.selection.main.head??0,L=()=>e.value?.state.selection.ranges??[],_=()=>e.value?e.value.state.sliceDoc(e.value.state.selection.main.from,e.value.state.selection.main.to):"",$=()=>{const a=e.value?.state;return a?a.selection.ranges.map(i=>a.sliceDoc(i.from,i.to)):[]},x=()=>e.value?.state.selection.ranges.some(a=>!a.empty)??!1,N=(a,i,r)=>{e.value&&e.value.dispatch({changes:{from:i,to:r,insert:a}})},T=a=>{e.value&&e.value.dispatch(e.value.state.replaceSelection(a))},U=a=>{e.value&&e.value.dispatch({selection:{anchor:a}})},k=(a,i)=>{e.value&&e.value.dispatch({selection:{anchor:a,head:i}})},z=(a,i)=>{e.value&&e.value.dispatch({selection:o.EditorSelection.create(a,i)})},D=a=>{e.value&&d.value&&e.value.dispatch({selection:o.EditorSelection.create(d.value.ranges.map(i=>i.extend(a(i))))})},w={editor:l,view:e,cursor:h,selection:d,focus:m,length:S,json:E,diagnosticCount:g,dom:e.value?.contentDOM,lint:V,forceReconfigure:O,getRange:B,getLine:M,lineCount:j,getCursor:q,listSelections:L,getSelection:_,getSelections:$,somethingSelected:x,replaceRange:N,replaceSelection:T,setCursor:U,setSelection:k,setSelections:z,extendSelectionsBy:D};return u.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"},J(this.$slots.default)):void 0)}}),P=t=>t.component("CodeMirror",C);exports.Meta=F;exports.default=C;exports.install=P;