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 +15 -3
- package/README.md +58 -0
- package/dist/index.cjs.js +3 -3
- package/dist/index.d.ts +646 -1
- package/dist/index.es.js +139 -122
- package/dist/index.iife.js +3 -3
- package/dist/index.umd.js +3 -3
- package/package.json +47 -38
- package/dist/components/CodeMirror.d.ts +0 -633
- package/src/components/CodeMirror.ts +0 -816
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.
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
13
|
-
`)===a)return;const i=!
|
|
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;
|