vue-codemirror6 1.3.22 → 1.4.0
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 +3 -3
- package/README.md +58 -0
- package/dist/components/CodeMirror.d.ts +5 -5
- package/dist/index.cjs.js +2 -2
- package/dist/index.es.js +134 -122
- package/dist/index.iife.js +2 -2
- package/dist/index.umd.js +2 -2
- package/package.json +34 -27
- package/src/components/CodeMirror.ts +107 -59
package/CHANGELOG.md
CHANGED
|
@@ -4,11 +4,11 @@ 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.0](https://github.com/logue/vue-codemirror6/compare/1.4.0...1.4.0)
|
|
8
8
|
|
|
9
|
-
#### [1.
|
|
9
|
+
#### [1.4.0](https://github.com/logue/vue-codemirror6/compare/1.3.13...1.4.0)
|
|
10
10
|
|
|
11
|
-
>
|
|
11
|
+
> 17 October 2025
|
|
12
12
|
|
|
13
13
|
- fix: full example link [`#58`](https://github.com/logue/vue-codemirror6/pull/58)
|
|
14
14
|
- Update dependencies. [`985f36f`](https://github.com/logue/vue-codemirror6/commit/985f36f23c4fc1b562b53b664deb7ff1eec79989)
|
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.
|
|
@@ -279,18 +279,18 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
279
279
|
};
|
|
280
280
|
}>, {
|
|
281
281
|
editor: Ref<HTMLElement | undefined, HTMLElement | undefined>;
|
|
282
|
-
view: ShallowRef<EditorView>;
|
|
282
|
+
view: ShallowRef<EditorView | undefined>;
|
|
283
283
|
cursor: WritableComputedRef<number, number>;
|
|
284
|
-
selection: WritableComputedRef<EditorSelection, EditorSelection>;
|
|
284
|
+
selection: WritableComputedRef<EditorSelection | undefined, EditorSelection | undefined>;
|
|
285
285
|
focus: WritableComputedRef<boolean, boolean>;
|
|
286
286
|
length: Ref<number, number>;
|
|
287
|
-
json: WritableComputedRef<Record<string, StateField<any
|
|
287
|
+
json: WritableComputedRef<Record<string, StateField<any>> | undefined, Record<string, StateField<any>> | undefined>;
|
|
288
288
|
diagnosticCount: Ref<number, number>;
|
|
289
|
-
dom: HTMLElement;
|
|
289
|
+
dom: HTMLElement | undefined;
|
|
290
290
|
lint: () => void;
|
|
291
291
|
forceReconfigure: () => void;
|
|
292
292
|
getRange: (from?: number, to?: number) => string | undefined;
|
|
293
|
-
getLine: (number: number) => string;
|
|
293
|
+
getLine: (number: number) => string | undefined;
|
|
294
294
|
lineCount: () => number;
|
|
295
295
|
getCursor: () => number;
|
|
296
296
|
listSelections: () => readonly SelectionRange[];
|
package/dist/index.cjs.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
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"),
|
|
13
|
-
`)===a)return;const i=!
|
|
12
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var T=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.3.22",date:"2025-10-17T01:01:41.290Z"},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;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":(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(T.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(typeof window>"u"||!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}})},U=a=>{e.value&&e.value.dispatch(e.value.state.replaceSelection(a))},k=a=>{e.value&&e.value.dispatch({selection:{anchor:a}})},z=(a,i)=>{e.value&&e.value.dispatch({selection:{anchor:a,head:i}})},D=(a,i)=>{e.value&&e.value.dispatch({selection:o.EditorSelection.create(a,i)})},R=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:U,setCursor:k,setSelection:z,setSelections:D,extendSelectionsBy:R};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)}});const P=t=>t.component("CodeMirror",C);exports.Meta=F;exports.default=C;exports.install=P;
|
package/dist/index.es.js
CHANGED
|
@@ -12,26 +12,26 @@
|
|
|
12
12
|
import { indentWithTab as W } from "@codemirror/commands";
|
|
13
13
|
import { indentUnit as G } from "@codemirror/language";
|
|
14
14
|
import { linter as P, lintGutter as Z, forceLinting as w, diagnosticCount as q } from "@codemirror/lint";
|
|
15
|
-
import { EditorState as
|
|
16
|
-
import { EditorView as
|
|
15
|
+
import { EditorState as u, Compartment as C, StateEffect as S, EditorSelection as O } from "@codemirror/state";
|
|
16
|
+
import { EditorView as d, placeholder as H, keymap as K } from "@codemirror/view";
|
|
17
17
|
import { basicSetup as Q, minimalSetup as X } from "codemirror";
|
|
18
|
-
import { isVue2 as Y, h as V, defineComponent as ee, ref as m, shallowRef as te, computed as
|
|
18
|
+
import { isVue2 as Y, h as V, defineComponent as ee, ref as m, shallowRef as te, computed as f, watch as B, onMounted as ae, nextTick as ne, onUnmounted as ie } from "vue-demi";
|
|
19
19
|
const he = {
|
|
20
20
|
version: "1.3.22",
|
|
21
|
-
date: "2025-
|
|
22
|
-
},
|
|
23
|
-
function M(
|
|
21
|
+
date: "2025-10-17T01:01:41.290Z"
|
|
22
|
+
}, le = (t) => t ? Object.entries(t).reduce((l, [i, s]) => (i = i.charAt(0).toUpperCase() + i.slice(1), i = `on${i}`, { ...l, [i]: s }), {}) : {};
|
|
23
|
+
function M(t, l = {}, i) {
|
|
24
24
|
if (Y)
|
|
25
|
-
return V(
|
|
26
|
-
const { props:
|
|
25
|
+
return V(t, l, i);
|
|
26
|
+
const { props: s, domProps: e, on: v, ...r } = l, h = v ? le(v) : {};
|
|
27
27
|
return V(
|
|
28
|
-
|
|
29
|
-
{ ...
|
|
30
|
-
|
|
28
|
+
t,
|
|
29
|
+
{ ...r, ...s, ...e, ...h },
|
|
30
|
+
i
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
const oe = (
|
|
34
|
-
var
|
|
33
|
+
const oe = (t) => typeof t == "function" ? t() : t;
|
|
34
|
+
var ue = ee({
|
|
35
35
|
/** Component Name */
|
|
36
36
|
name: "CodeMirror",
|
|
37
37
|
/** Model Definition */
|
|
@@ -316,15 +316,15 @@ var se = ee({
|
|
|
316
316
|
/** Emits */
|
|
317
317
|
emits: {
|
|
318
318
|
/** Model Update */
|
|
319
|
-
"update:modelValue": (
|
|
319
|
+
"update:modelValue": (t = "") => !0,
|
|
320
320
|
/** CodeMirror ViewUpdate */
|
|
321
|
-
update: (
|
|
321
|
+
update: (t) => !0,
|
|
322
322
|
/** CodeMirror onReady */
|
|
323
|
-
ready: (
|
|
323
|
+
ready: (t) => !0,
|
|
324
324
|
/** CodeMirror onFocus */
|
|
325
|
-
focus: (
|
|
325
|
+
focus: (t) => !0,
|
|
326
326
|
/** State Changed */
|
|
327
|
-
change: (
|
|
327
|
+
change: (t) => !0,
|
|
328
328
|
/** CodeMirror onDestroy */
|
|
329
329
|
destroy: () => !0
|
|
330
330
|
},
|
|
@@ -334,171 +334,183 @@ var se = ee({
|
|
|
334
334
|
* @param props - Props
|
|
335
335
|
* @param context - Context
|
|
336
336
|
*/
|
|
337
|
-
setup(
|
|
338
|
-
const
|
|
339
|
-
get: () =>
|
|
337
|
+
setup(t, l) {
|
|
338
|
+
const i = m(), s = m(t.modelValue), e = te(void 0), v = f({
|
|
339
|
+
get: () => e.value?.hasFocus ?? !1,
|
|
340
340
|
set: (a) => {
|
|
341
|
-
a &&
|
|
341
|
+
a && e.value && e.value.focus();
|
|
342
342
|
}
|
|
343
|
-
}),
|
|
344
|
-
get: () =>
|
|
345
|
-
set: (a) =>
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
|
|
352
|
-
|
|
343
|
+
}), r = f({
|
|
344
|
+
get: () => e.value?.state.selection,
|
|
345
|
+
set: (a) => {
|
|
346
|
+
e.value && a && e.value.dispatch({ selection: a });
|
|
347
|
+
}
|
|
348
|
+
}), h = f({
|
|
349
|
+
get: () => e.value?.state.selection.main.head ?? 0,
|
|
350
|
+
set: (a) => {
|
|
351
|
+
e.value && e.value.dispatch({ selection: { anchor: a } });
|
|
352
|
+
}
|
|
353
|
+
}), j = f({
|
|
354
|
+
get: () => e.value?.state.toJSON(),
|
|
355
|
+
set: (a) => {
|
|
356
|
+
e.value && a && e.value.setState(u.fromJSON(a));
|
|
353
357
|
}
|
|
354
|
-
), p = m(0), g = m(0), y =
|
|
358
|
+
}), p = m(0), g = m(0), y = f(() => {
|
|
355
359
|
const a = new C(), n = new C();
|
|
356
|
-
if (
|
|
360
|
+
if (t.basic && t.minimal)
|
|
357
361
|
throw new Error(
|
|
358
362
|
"[Vue CodeMirror] Both basic and minimal cannot be specified."
|
|
359
363
|
);
|
|
360
364
|
let o = [];
|
|
361
|
-
return
|
|
365
|
+
return t.keymap && t.keymap.length > 0 && (o = t.keymap), t.tab && o.push(W), [
|
|
362
366
|
// Toggle basic setup
|
|
363
|
-
|
|
367
|
+
t.basic && !t.minimal ? Q : void 0,
|
|
364
368
|
// Toggle minimal setup
|
|
365
|
-
|
|
369
|
+
t.minimal && !t.basic ? X : void 0,
|
|
366
370
|
// ViewUpdate event listener
|
|
367
|
-
|
|
368
|
-
|
|
371
|
+
d.updateListener.of((c) => {
|
|
372
|
+
e.value && (l.emit("focus", e.value.hasFocus), p.value = e.value.state.doc?.length, !(c.changes.empty || !c.docChanged) && (t.linter && (t.forceLinting && w(e.value), g.value = t.linter(e.value).length), l.emit("update", c)));
|
|
369
373
|
}),
|
|
370
374
|
// Toggle light/dark mode.
|
|
371
|
-
|
|
375
|
+
d.theme(t.theme, { dark: t.dark }),
|
|
372
376
|
// Toggle line wrapping
|
|
373
|
-
|
|
377
|
+
t.wrap ? d.lineWrapping : void 0,
|
|
374
378
|
// Tab character
|
|
375
|
-
|
|
379
|
+
t.indentUnit ? G.of(t.indentUnit) : void 0,
|
|
376
380
|
// Allow Multiple Selections
|
|
377
|
-
|
|
381
|
+
u.allowMultipleSelections.of(t.allowMultipleSelections),
|
|
378
382
|
// Indent tab size
|
|
379
|
-
|
|
383
|
+
t.tabSize ? n.of(u.tabSize.of(t.tabSize)) : void 0,
|
|
380
384
|
// locale settings
|
|
381
|
-
|
|
385
|
+
t.phrases ? u.phrases.of(t.phrases) : void 0,
|
|
382
386
|
// Readonly option
|
|
383
|
-
|
|
387
|
+
u.readOnly.of(t.readonly),
|
|
384
388
|
// Editable option
|
|
385
|
-
|
|
389
|
+
d.editable.of(!t.disabled),
|
|
386
390
|
// Set Line break char
|
|
387
|
-
|
|
391
|
+
t.lineSeparator ? u.lineSeparator.of(t.lineSeparator) : void 0,
|
|
388
392
|
// Lang
|
|
389
|
-
|
|
393
|
+
t.lang ? a.of(t.lang) : void 0,
|
|
390
394
|
// Append Linter settings
|
|
391
|
-
|
|
395
|
+
t.linter ? P(t.linter, t.linterConfig) : void 0,
|
|
392
396
|
// Show 🔴 to error line when linter enabled.
|
|
393
|
-
|
|
397
|
+
t.linter && t.gutter ? Z(t.gutterConfig) : void 0,
|
|
394
398
|
// Placeholder
|
|
395
|
-
|
|
399
|
+
t.placeholder ? H(t.placeholder) : void 0,
|
|
396
400
|
// Keymap and Indent with Tab
|
|
397
401
|
o.length !== 0 ? K.of(o) : void 0,
|
|
398
402
|
// Append Extensions
|
|
399
|
-
...
|
|
400
|
-
].filter((
|
|
403
|
+
...t.extensions
|
|
404
|
+
].filter((c) => !!c);
|
|
401
405
|
});
|
|
402
406
|
B(
|
|
403
407
|
y,
|
|
404
|
-
(a) =>
|
|
408
|
+
(a) => e.value?.dispatch({ effects: S.reconfigure.of(a) }),
|
|
405
409
|
{ immediate: !0 }
|
|
406
410
|
), B(
|
|
407
|
-
() =>
|
|
411
|
+
() => t.modelValue,
|
|
408
412
|
async (a) => {
|
|
409
|
-
if (
|
|
410
|
-
|
|
413
|
+
if (!e.value || e.value.composing || // IME fix
|
|
414
|
+
e.value.state.doc.toJSON().join(t.lineSeparator ?? `
|
|
411
415
|
`) === a)
|
|
412
416
|
return;
|
|
413
|
-
const n = !
|
|
417
|
+
const n = !e.value.state.selection.ranges.every(
|
|
414
418
|
(o) => o.anchor < a.length && o.head < a.length
|
|
415
419
|
);
|
|
416
|
-
|
|
417
|
-
changes: { from: 0, to:
|
|
418
|
-
selection: n ? { anchor: 0, head: 0 } :
|
|
419
|
-
scrollIntoView:
|
|
420
|
+
e.value.dispatch({
|
|
421
|
+
changes: { from: 0, to: e.value.state.doc.length, insert: a },
|
|
422
|
+
selection: n ? { anchor: 0, head: 0 } : e.value.state.selection,
|
|
423
|
+
scrollIntoView: t.scrollIntoView
|
|
420
424
|
});
|
|
421
425
|
},
|
|
422
426
|
{ immediate: !0 }
|
|
423
427
|
), ae(async () => {
|
|
424
|
-
|
|
425
|
-
|
|
428
|
+
if (typeof window > "u" || !i.value)
|
|
429
|
+
return;
|
|
430
|
+
let a = s.value;
|
|
431
|
+
i.value.childNodes[0] && (s.value !== "" && console.warn(
|
|
426
432
|
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
427
|
-
), a =
|
|
428
|
-
parent:
|
|
429
|
-
state:
|
|
433
|
+
), a = i.value.childNodes[0].innerText.trim()), e.value = new d({
|
|
434
|
+
parent: i.value,
|
|
435
|
+
state: u.create({ doc: a, extensions: y.value }),
|
|
430
436
|
dispatch: (n) => {
|
|
431
|
-
|
|
437
|
+
e.value && (e.value.update([n]), !(n.changes.empty || !n.docChanged) && (l.emit("update:modelValue", n.state.doc.toString()), l.emit("change", n.state)));
|
|
432
438
|
}
|
|
433
|
-
}), await ne(),
|
|
434
|
-
view:
|
|
435
|
-
state:
|
|
436
|
-
container:
|
|
437
|
-
})
|
|
438
|
-
}),
|
|
439
|
-
|
|
439
|
+
}), await ne(), l.emit("ready", {
|
|
440
|
+
view: e.value,
|
|
441
|
+
state: e.value.state,
|
|
442
|
+
container: i.value
|
|
443
|
+
});
|
|
444
|
+
}), ie(() => {
|
|
445
|
+
e.value && (e.value.destroy(), l.emit("destroy"));
|
|
440
446
|
});
|
|
441
|
-
const
|
|
442
|
-
!
|
|
443
|
-
},
|
|
444
|
-
|
|
447
|
+
const x = () => {
|
|
448
|
+
!t.linter || !e.value || (t.forceLinting && w(e.value), g.value = q(e.value.state));
|
|
449
|
+
}, L = () => {
|
|
450
|
+
e.value?.dispatch({
|
|
445
451
|
effects: S.reconfigure.of([])
|
|
446
|
-
}),
|
|
452
|
+
}), e.value?.dispatch({
|
|
447
453
|
effects: S.appendConfig.of(y.value)
|
|
448
454
|
});
|
|
449
|
-
},
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return (a = t.value.state.sliceDoc(
|
|
455
|
-
t.value.state.selection.main.from,
|
|
456
|
-
t.value.state.selection.main.to
|
|
457
|
-
)) !== null && a !== void 0 ? a : "";
|
|
458
|
-
}, E = () => {
|
|
459
|
-
const a = t.value.state;
|
|
455
|
+
}, N = (a, n) => e.value?.state.sliceDoc(a, n), U = (a) => e.value?.state.doc.line(a + 1).text, $ = () => e.value?.state.doc.lines ?? 0, k = () => e.value?.state.selection.main.head ?? 0, z = () => e.value?.state.selection.ranges ?? [], E = () => e.value ? e.value.state.sliceDoc(
|
|
456
|
+
e.value.state.selection.main.from,
|
|
457
|
+
e.value.state.selection.main.to
|
|
458
|
+
) : "", R = () => {
|
|
459
|
+
const a = e.value?.state;
|
|
460
460
|
return a ? a.selection.ranges.map(
|
|
461
461
|
(n) => a.sliceDoc(n.from, n.to)
|
|
462
462
|
) : [];
|
|
463
|
-
},
|
|
463
|
+
}, T = () => e.value?.state.selection.ranges.some(
|
|
464
464
|
(a) => !a.empty
|
|
465
|
-
),
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
465
|
+
) ?? !1, _ = (a, n, o) => {
|
|
466
|
+
e.value && e.value.dispatch({
|
|
467
|
+
changes: { from: n, to: o, insert: a }
|
|
468
|
+
});
|
|
469
|
+
}, D = (a) => {
|
|
470
|
+
e.value && e.value.dispatch(e.value.state.replaceSelection(a));
|
|
471
|
+
}, A = (a) => {
|
|
472
|
+
e.value && e.value.dispatch({ selection: { anchor: a } });
|
|
473
|
+
}, F = (a, n) => {
|
|
474
|
+
e.value && e.value.dispatch({ selection: { anchor: a, head: n } });
|
|
475
|
+
}, I = (a, n) => {
|
|
476
|
+
e.value && e.value.dispatch({
|
|
477
|
+
selection: O.create(a, n)
|
|
478
|
+
});
|
|
479
|
+
}, J = (a) => {
|
|
480
|
+
e.value && r.value && e.value.dispatch({
|
|
481
|
+
selection: O.create(
|
|
482
|
+
r.value.ranges.map((n) => n.extend(a(n)))
|
|
483
|
+
)
|
|
484
|
+
});
|
|
485
|
+
}, b = {
|
|
486
|
+
editor: i,
|
|
487
|
+
view: e,
|
|
476
488
|
cursor: h,
|
|
477
|
-
selection:
|
|
478
|
-
focus:
|
|
489
|
+
selection: r,
|
|
490
|
+
focus: v,
|
|
479
491
|
length: p,
|
|
480
|
-
json:
|
|
492
|
+
json: j,
|
|
481
493
|
diagnosticCount: g,
|
|
482
|
-
dom:
|
|
483
|
-
lint:
|
|
484
|
-
forceReconfigure:
|
|
494
|
+
dom: e.value?.contentDOM,
|
|
495
|
+
lint: x,
|
|
496
|
+
forceReconfigure: L,
|
|
485
497
|
// Bellow is CodeMirror5's function
|
|
486
|
-
getRange:
|
|
487
|
-
getLine:
|
|
488
|
-
lineCount:
|
|
489
|
-
getCursor:
|
|
490
|
-
listSelections:
|
|
491
|
-
getSelection:
|
|
492
|
-
getSelections:
|
|
493
|
-
somethingSelected:
|
|
494
|
-
replaceRange:
|
|
498
|
+
getRange: N,
|
|
499
|
+
getLine: U,
|
|
500
|
+
lineCount: $,
|
|
501
|
+
getCursor: k,
|
|
502
|
+
listSelections: z,
|
|
503
|
+
getSelection: E,
|
|
504
|
+
getSelections: R,
|
|
505
|
+
somethingSelected: T,
|
|
506
|
+
replaceRange: _,
|
|
495
507
|
replaceSelection: D,
|
|
496
508
|
setCursor: A,
|
|
497
509
|
setSelection: F,
|
|
498
510
|
setSelections: I,
|
|
499
511
|
extendSelectionsBy: J
|
|
500
512
|
};
|
|
501
|
-
return
|
|
513
|
+
return l.expose(b), b;
|
|
502
514
|
},
|
|
503
515
|
render() {
|
|
504
516
|
return M(
|
|
@@ -518,9 +530,9 @@ var se = ee({
|
|
|
518
530
|
);
|
|
519
531
|
}
|
|
520
532
|
});
|
|
521
|
-
const ge = (
|
|
533
|
+
const ge = (t) => t.component("CodeMirror", ue);
|
|
522
534
|
export {
|
|
523
535
|
he as Meta,
|
|
524
|
-
|
|
536
|
+
ue as default,
|
|
525
537
|
ge as install
|
|
526
538
|
};
|
package/dist/index.iife.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var CodeMirror=function(
|
|
13
|
-
`)===a)return;const n=!
|
|
12
|
+
var CodeMirror=(function(s,E,O,f,o,c,b,l){"use strict";const M={version:"1.3.22",date:"2025-10-17T01:01:41.290Z"},B=t=>t?Object.entries(t).reduce((r,[i,d])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...r,[i]:d}),{}):{};function w(t,r={},i){if(l.isVue2)return l.h(t,r,i);const{props:d,domProps:e,on:g,...v}=r,m=g?B(g):{};return l.h(t,{...v,...d,...e,...m},i)}const j=t=>typeof t=="function"?t():t;var C=l.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,r){const i=l.ref(),d=l.ref(t.modelValue),e=l.shallowRef(void 0),g=l.computed({get:()=>e.value?.hasFocus??!1,set:a=>{a&&e.value&&e.value.focus()}}),v=l.computed({get:()=>e.value?.state.selection,set:a=>{e.value&&a&&e.value.dispatch({selection:a})}}),m=l.computed({get:()=>e.value?.state.selection.main.head??0,set:a=>{e.value&&e.value.dispatch({selection:{anchor:a}})}}),_=l.computed({get:()=>e.value?.state.toJSON(),set:a=>{e.value&&a&&e.value.setState(o.EditorState.fromJSON(a))}}),p=l.ref(0),y=l.ref(0),S=l.computed(()=>{const a=new o.Compartment,n=new o.Compartment;if(t.basic&&t.minimal)throw new Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");let u=[];return t.keymap&&t.keymap.length>0&&(u=t.keymap),t.tab&&u.push(E.indentWithTab),[t.basic&&!t.minimal?b.basicSetup:void 0,t.minimal&&!t.basic?b.minimalSetup:void 0,c.EditorView.updateListener.of(h=>{e.value&&(r.emit("focus",e.value.hasFocus),p.value=e.value.state.doc?.length,!(h.changes.empty||!h.docChanged)&&(t.linter&&(t.forceLinting&&f.forceLinting(e.value),y.value=t.linter(e.value).length),r.emit("update",h)))}),c.EditorView.theme(t.theme,{dark:t.dark}),t.wrap?c.EditorView.lineWrapping:void 0,t.indentUnit?O.indentUnit.of(t.indentUnit):void 0,o.EditorState.allowMultipleSelections.of(t.allowMultipleSelections),t.tabSize?n.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),c.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?f.linter(t.linter,t.linterConfig):void 0,t.linter&&t.gutter?f.lintGutter(t.gutterConfig):void 0,t.placeholder?c.placeholder(t.placeholder):void 0,u.length!==0?c.keymap.of(u):void 0,...t.extensions].filter(h=>!!h)});l.watch(S,a=>e.value?.dispatch({effects:o.StateEffect.reconfigure.of(a)}),{immediate:!0}),l.watch(()=>t.modelValue,async a=>{if(!e.value||e.value.composing||e.value.state.doc.toJSON().join(t.lineSeparator??`
|
|
13
|
+
`)===a)return;const n=!e.value.state.selection.ranges.every(u=>u.anchor<a.length&&u.head<a.length);e.value.dispatch({changes:{from:0,to:e.value.state.doc.length,insert:a},selection:n?{anchor:0,head:0}:e.value.state.selection,scrollIntoView:t.scrollIntoView})},{immediate:!0}),l.onMounted(async()=>{if(typeof window>"u"||!i.value)return;let a=d.value;i.value.childNodes[0]&&(d.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()),e.value=new c.EditorView({parent:i.value,state:o.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{e.value&&(e.value.update([n]),!(n.changes.empty||!n.docChanged)&&(r.emit("update:modelValue",n.state.doc.toString()),r.emit("change",n.state)))}}),await l.nextTick(),r.emit("ready",{view:e.value,state:e.value.state,container:i.value})}),l.onUnmounted(()=>{e.value&&(e.value.destroy(),r.emit("destroy"))});const $=()=>{!t.linter||!e.value||(t.forceLinting&&f.forceLinting(e.value),y.value=f.diagnosticCount(e.value.state))},N=()=>{e.value?.dispatch({effects:o.StateEffect.reconfigure.of([])}),e.value?.dispatch({effects:o.StateEffect.appendConfig.of(S.value)})},U=(a,n)=>e.value?.state.sliceDoc(a,n),k=a=>e.value?.state.doc.line(a+1).text,z=()=>e.value?.state.doc.lines??0,R=()=>e.value?.state.selection.main.head??0,T=()=>e.value?.state.selection.ranges??[],A=()=>e.value?e.value.state.sliceDoc(e.value.state.selection.main.from,e.value.state.selection.main.to):"",F=()=>{const a=e.value?.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},I=()=>e.value?.state.selection.ranges.some(a=>!a.empty)??!1,J=(a,n,u)=>{e.value&&e.value.dispatch({changes:{from:n,to:u,insert:a}})},x=a=>{e.value&&e.value.dispatch(e.value.state.replaceSelection(a))},P=a=>{e.value&&e.value.dispatch({selection:{anchor:a}})},W=(a,n)=>{e.value&&e.value.dispatch({selection:{anchor:a,head:n}})},G=(a,n)=>{e.value&&e.value.dispatch({selection:o.EditorSelection.create(a,n)})},Z=a=>{e.value&&v.value&&e.value.dispatch({selection:o.EditorSelection.create(v.value.ranges.map(n=>n.extend(a(n))))})},V={editor:i,view:e,cursor:m,selection:v,focus:g,length:p,json:_,diagnosticCount:y,dom:e.value?.contentDOM,lint:$,forceReconfigure:N,getRange:U,getLine:k,lineCount:z,getCursor:R,listSelections:T,getSelection:A,getSelections:F,somethingSelected:I,replaceRange:J,replaceSelection:x,setCursor:P,setSelection:W,setSelections:G,extendSelectionsBy:Z};return r.expose(V),V},render(){return w(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?w("aside",{style:"display: none;","aria-hidden":"true"},j(this.$slots.default)):void 0)}});const L=t=>t.component("CodeMirror",C);return s.Meta=M,s.default=C,s.install=L,Object.defineProperty(s,"__esModule",{value:!0}),s})({},commands,language,lint,state,view,codemirror,VueDemi);
|
package/dist/index.umd.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,function(l,f,O,v,r,
|
|
13
|
-
`)===a)return;const n=!
|
|
12
|
+
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,(function(l,f,O,v,r,c,w,i){"use strict";const M={version:"1.3.22",date:"2025-10-17T01:01:41.290Z"},B=t=>t?Object.entries(t).reduce((d,[o,s])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...d,[o]:s}),{}):{};function C(t,d={},o){if(i.isVue2)return i.h(t,d,o);const{props:s,domProps:e,on:g,...m}=d,y=g?B(g):{};return i.h(t,{...m,...s,...e,...y},o)}const j=t=>typeof t=="function"?t():t;var b=i.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,d){const o=i.ref(),s=i.ref(t.modelValue),e=i.shallowRef(void 0),g=i.computed({get:()=>e.value?.hasFocus??!1,set:a=>{a&&e.value&&e.value.focus()}}),m=i.computed({get:()=>e.value?.state.selection,set:a=>{e.value&&a&&e.value.dispatch({selection:a})}}),y=i.computed({get:()=>e.value?.state.selection.main.head??0,set:a=>{e.value&&e.value.dispatch({selection:{anchor:a}})}}),L=i.computed({get:()=>e.value?.state.toJSON(),set:a=>{e.value&&a&&e.value.setState(r.EditorState.fromJSON(a))}}),V=i.ref(0),S=i.ref(0),p=i.computed(()=>{const a=new r.Compartment,n=new r.Compartment;if(t.basic&&t.minimal)throw new Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");let u=[];return t.keymap&&t.keymap.length>0&&(u=t.keymap),t.tab&&u.push(f.indentWithTab),[t.basic&&!t.minimal?w.basicSetup:void 0,t.minimal&&!t.basic?w.minimalSetup:void 0,c.EditorView.updateListener.of(h=>{e.value&&(d.emit("focus",e.value.hasFocus),V.value=e.value.state.doc?.length,!(h.changes.empty||!h.docChanged)&&(t.linter&&(t.forceLinting&&v.forceLinting(e.value),S.value=t.linter(e.value).length),d.emit("update",h)))}),c.EditorView.theme(t.theme,{dark:t.dark}),t.wrap?c.EditorView.lineWrapping:void 0,t.indentUnit?O.indentUnit.of(t.indentUnit):void 0,r.EditorState.allowMultipleSelections.of(t.allowMultipleSelections),t.tabSize?n.of(r.EditorState.tabSize.of(t.tabSize)):void 0,t.phrases?r.EditorState.phrases.of(t.phrases):void 0,r.EditorState.readOnly.of(t.readonly),c.EditorView.editable.of(!t.disabled),t.lineSeparator?r.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?c.placeholder(t.placeholder):void 0,u.length!==0?c.keymap.of(u):void 0,...t.extensions].filter(h=>!!h)});i.watch(p,a=>e.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)}),{immediate:!0}),i.watch(()=>t.modelValue,async a=>{if(!e.value||e.value.composing||e.value.state.doc.toJSON().join(t.lineSeparator??`
|
|
13
|
+
`)===a)return;const n=!e.value.state.selection.ranges.every(u=>u.anchor<a.length&&u.head<a.length);e.value.dispatch({changes:{from:0,to:e.value.state.doc.length,insert:a},selection:n?{anchor:0,head:0}:e.value.state.selection,scrollIntoView:t.scrollIntoView})},{immediate:!0}),i.onMounted(async()=>{if(typeof window>"u"||!o.value)return;let a=s.value;o.value.childNodes[0]&&(s.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()),e.value=new c.EditorView({parent:o.value,state:r.EditorState.create({doc:a,extensions:p.value}),dispatch:n=>{e.value&&(e.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()),d.emit("change",n.state)))}}),await i.nextTick(),d.emit("ready",{view:e.value,state:e.value.state,container:o.value})}),i.onUnmounted(()=>{e.value&&(e.value.destroy(),d.emit("destroy"))});const T=()=>{!t.linter||!e.value||(t.forceLinting&&v.forceLinting(e.value),S.value=v.diagnosticCount(e.value.state))},_=()=>{e.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),e.value?.dispatch({effects:r.StateEffect.appendConfig.of(p.value)})},$=(a,n)=>e.value?.state.sliceDoc(a,n),x=a=>e.value?.state.doc.line(a+1).text,N=()=>e.value?.state.doc.lines??0,U=()=>e.value?.state.selection.main.head??0,k=()=>e.value?.state.selection.ranges??[],z=()=>e.value?e.value.state.sliceDoc(e.value.state.selection.main.from,e.value.state.selection.main.to):"",R=()=>{const a=e.value?.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},A=()=>e.value?.state.selection.ranges.some(a=>!a.empty)??!1,F=(a,n,u)=>{e.value&&e.value.dispatch({changes:{from:n,to:u,insert:a}})},I=a=>{e.value&&e.value.dispatch(e.value.state.replaceSelection(a))},J=a=>{e.value&&e.value.dispatch({selection:{anchor:a}})},P=(a,n)=>{e.value&&e.value.dispatch({selection:{anchor:a,head:n}})},W=(a,n)=>{e.value&&e.value.dispatch({selection:r.EditorSelection.create(a,n)})},G=a=>{e.value&&m.value&&e.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))})},E={editor:o,view:e,cursor:y,selection:m,focus:g,length:V,json:L,diagnosticCount:S,dom:e.value?.contentDOM,lint:T,forceReconfigure:_,getRange:$,getLine:x,lineCount:N,getCursor:U,listSelections:k,getSelection:z,getSelections:R,somethingSelected:A,replaceRange:F,replaceSelection:I,setCursor:J,setSelection:P,setSelections:W,extendSelectionsBy:G};return d.expose(E),E},render(){return C(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?C("aside",{style:"display: none;","aria-hidden":"true"},j(this.$slots.default)):void 0)}});const q=t=>t.component("CodeMirror",b);l.Meta=M,l.default=b,l.install=q,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.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "CodeMirror6 Component for vue2 and vue3.",
|
|
7
7
|
"keywords": [
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"node": ">=18",
|
|
68
68
|
"pnpm": ">=10.3.0"
|
|
69
69
|
},
|
|
70
|
-
"packageManager": "pnpm@10.
|
|
70
|
+
"packageManager": "pnpm@10.18.3",
|
|
71
71
|
"scripts": {
|
|
72
72
|
"dev": "vite",
|
|
73
73
|
"clean": "rimraf node_modules/.vite",
|
|
@@ -79,6 +79,10 @@
|
|
|
79
79
|
"preview": "vite preview --mode=docs",
|
|
80
80
|
"build-only": "vite build",
|
|
81
81
|
"type-check": "vue-tsc --declaration --emitDeclarationOnly",
|
|
82
|
+
"test": "vitest",
|
|
83
|
+
"test:ui": "vitest --ui",
|
|
84
|
+
"test:run": "vitest run",
|
|
85
|
+
"test:coverage": "vitest run --coverage",
|
|
82
86
|
"prepare": "husky",
|
|
83
87
|
"version": "auto-changelog -p && git add CHANGELOG.md"
|
|
84
88
|
},
|
|
@@ -86,7 +90,6 @@
|
|
|
86
90
|
"vue-demi": "latest"
|
|
87
91
|
},
|
|
88
92
|
"peerDependencies": {
|
|
89
|
-
"vue": "^2.7.14 || ^3.3.4",
|
|
90
93
|
"@codemirror/autocomplete": "^6.0.0",
|
|
91
94
|
"@codemirror/commands": "^6.0.0",
|
|
92
95
|
"@codemirror/language": "^6.0.0",
|
|
@@ -94,51 +97,55 @@
|
|
|
94
97
|
"@codemirror/search": "^6.0.0",
|
|
95
98
|
"@codemirror/state": "^6.0.0",
|
|
96
99
|
"@codemirror/view": "^6.0.0",
|
|
100
|
+
"codemirror": "^6.0.0",
|
|
97
101
|
"style-mod": "^4.0.0",
|
|
98
|
-
"
|
|
102
|
+
"vue": "^2.7.14 || ^3.3.4"
|
|
99
103
|
},
|
|
100
104
|
"devDependencies": {
|
|
101
105
|
"@codemirror/lang-javascript": "^6.2.4",
|
|
102
106
|
"@codemirror/lang-json": "^6.0.2",
|
|
103
|
-
"@codemirror/lang-markdown": "^6.
|
|
107
|
+
"@codemirror/lang-markdown": "^6.4.0",
|
|
104
108
|
"@codemirror/lang-vue": "^0.1.3",
|
|
105
109
|
"@tsconfig/node-lts": "^22.0.2",
|
|
106
|
-
"@types/node": "^24.0
|
|
107
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
108
|
-
"@
|
|
110
|
+
"@types/node": "^24.8.0",
|
|
111
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
112
|
+
"@vitest/ui": "^3.2.4",
|
|
113
|
+
"@vue/compiler-sfc": "^3.5.22",
|
|
109
114
|
"@vue/eslint-config-prettier": "^10.2.0",
|
|
110
115
|
"@vue/eslint-config-typescript": "^14.6.0",
|
|
111
116
|
"@vue/test-utils": "^2.4.6",
|
|
112
|
-
"@vue/tsconfig": "^0.
|
|
113
|
-
"@vueuse/core": "^13.
|
|
114
|
-
"bootstrap": "^5.3.
|
|
115
|
-
"eslint": "^9.
|
|
117
|
+
"@vue/tsconfig": "^0.8.1",
|
|
118
|
+
"@vueuse/core": "^13.9.0",
|
|
119
|
+
"bootstrap": "^5.3.8",
|
|
120
|
+
"eslint": "^9.37.0",
|
|
116
121
|
"eslint-import-resolver-custom-alias": "^1.3.2",
|
|
117
122
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
118
|
-
"eslint-linter-browserify": "^9.
|
|
123
|
+
"eslint-linter-browserify": "^9.37.0",
|
|
119
124
|
"eslint-plugin-import": "^2.32.0",
|
|
120
|
-
"eslint-plugin-playwright": "^2.2.
|
|
121
|
-
"eslint-plugin-vue": "^10.
|
|
125
|
+
"eslint-plugin-playwright": "^2.2.2",
|
|
126
|
+
"eslint-plugin-vue": "^10.5.1",
|
|
122
127
|
"eslint-plugin-vuejs-accessibility": "^2.4.1",
|
|
128
|
+
"happy-dom": "^20.0.4",
|
|
123
129
|
"husky": "^9.1.7",
|
|
124
|
-
"jiti": "^2.
|
|
125
|
-
"lint-staged": "^16.
|
|
130
|
+
"jiti": "^2.6.1",
|
|
131
|
+
"lint-staged": "^16.2.4",
|
|
126
132
|
"npm-run-all2": "^8.0.4",
|
|
127
133
|
"prettier": "^3.6.2",
|
|
128
134
|
"rimraf": "^6.0.1",
|
|
129
|
-
"rollup-plugin-visualizer": "^6.0.
|
|
130
|
-
"sass-embedded": "^1.
|
|
131
|
-
"supports-color": "^10.
|
|
132
|
-
"typescript": "^5.
|
|
133
|
-
"typescript-eslint": "^8.
|
|
134
|
-
"vite": "^7.
|
|
135
|
+
"rollup-plugin-visualizer": "^6.0.5",
|
|
136
|
+
"sass-embedded": "^1.93.2",
|
|
137
|
+
"supports-color": "^10.2.2",
|
|
138
|
+
"typescript": "^5.9.3",
|
|
139
|
+
"typescript-eslint": "^8.46.1",
|
|
140
|
+
"vite": "^7.1.10",
|
|
135
141
|
"vite-plugin-banner": "^0.8.1",
|
|
136
|
-
"vite-plugin-checker": "^0.
|
|
142
|
+
"vite-plugin-checker": "^0.11.0",
|
|
137
143
|
"vite-plugin-dts": "^4.5.4",
|
|
138
|
-
"
|
|
144
|
+
"vitest": "^3.2.4",
|
|
145
|
+
"vue": "^3.5.22",
|
|
139
146
|
"vue-eslint-parser": "^10.2.0",
|
|
140
|
-
"vue-markdown-wasm": "^0.5.
|
|
141
|
-
"vue-tsc": "^3.
|
|
147
|
+
"vue-markdown-wasm": "^0.5.2",
|
|
148
|
+
"vue-tsc": "^3.1.1"
|
|
142
149
|
},
|
|
143
150
|
"husky": {
|
|
144
151
|
"hooks": {
|
|
@@ -82,6 +82,8 @@ export default defineComponent({
|
|
|
82
82
|
/**
|
|
83
83
|
* Use Basic Setup
|
|
84
84
|
*
|
|
85
|
+
* This will enable the basic setup for the editor.
|
|
86
|
+
*
|
|
85
87
|
* @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
|
|
86
88
|
*/
|
|
87
89
|
basic: {
|
|
@@ -120,6 +122,8 @@ export default defineComponent({
|
|
|
120
122
|
/**
|
|
121
123
|
* Allow tab key indent.
|
|
122
124
|
*
|
|
125
|
+
* This will enable the tab key to indent the current line or selection.
|
|
126
|
+
*
|
|
123
127
|
* @see {@link https://codemirror.net/examples/tab/}
|
|
124
128
|
*/
|
|
125
129
|
tab: {
|
|
@@ -128,6 +132,7 @@ export default defineComponent({
|
|
|
128
132
|
},
|
|
129
133
|
/**
|
|
130
134
|
* Tab character
|
|
135
|
+
*
|
|
131
136
|
* This is the unit of indentation used when the editor is configured to indent with tabs.
|
|
132
137
|
* It is also used to determine the size of the tab character when the editor is configured to use tabs for indentation..
|
|
133
138
|
*
|
|
@@ -139,6 +144,7 @@ export default defineComponent({
|
|
|
139
144
|
},
|
|
140
145
|
/**
|
|
141
146
|
* Allow Multiple Selection.
|
|
147
|
+
*
|
|
142
148
|
* This allows the editor to have multiple selections at the same time.
|
|
143
149
|
* This is useful for editing multiple parts of the document at once.
|
|
144
150
|
* If this is set to true, the editor will allow multiple selections.
|
|
@@ -152,6 +158,7 @@ export default defineComponent({
|
|
|
152
158
|
},
|
|
153
159
|
/**
|
|
154
160
|
* Tab size
|
|
161
|
+
*
|
|
155
162
|
* This is the number of spaces that a tab character represents in the editor.
|
|
156
163
|
* It is used to determine the size of the tab character when the editor is configured to use tabs for indentation.
|
|
157
164
|
* If this is set to a number, the editor will use that number of spaces for each tab character.
|
|
@@ -373,7 +380,7 @@ export default defineComponent({
|
|
|
373
380
|
*
|
|
374
381
|
* @see {@link https://codemirror.net/docs/ref/#view.EditorView}
|
|
375
382
|
*/
|
|
376
|
-
const view: ShallowRef<EditorView> = shallowRef(
|
|
383
|
+
const view: ShallowRef<EditorView | undefined> = shallowRef(undefined);
|
|
377
384
|
|
|
378
385
|
/**
|
|
379
386
|
* Focus
|
|
@@ -381,9 +388,9 @@ export default defineComponent({
|
|
|
381
388
|
* @see {@link https://codemirror.net/docs/ref/#view.EditorView.hasFocus}
|
|
382
389
|
*/
|
|
383
390
|
const focus: WritableComputedRef<boolean> = computed({
|
|
384
|
-
get: () => view.value
|
|
391
|
+
get: () => view.value?.hasFocus ?? false,
|
|
385
392
|
set: f => {
|
|
386
|
-
if (f) {
|
|
393
|
+
if (f && view.value) {
|
|
387
394
|
view.value.focus();
|
|
388
395
|
}
|
|
389
396
|
},
|
|
@@ -394,24 +401,37 @@ export default defineComponent({
|
|
|
394
401
|
*
|
|
395
402
|
* @see {@link https://codemirror.net/docs/ref/#state.EditorSelection}
|
|
396
403
|
*/
|
|
397
|
-
const selection: WritableComputedRef<EditorSelection> =
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
404
|
+
const selection: WritableComputedRef<EditorSelection | undefined> =
|
|
405
|
+
computed({
|
|
406
|
+
get: () => view.value?.state.selection,
|
|
407
|
+
set: s => {
|
|
408
|
+
if (view.value && s) {
|
|
409
|
+
view.value.dispatch({ selection: s });
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
});
|
|
401
413
|
|
|
402
414
|
/** Cursor Position */
|
|
403
415
|
const cursor: WritableComputedRef<number> = computed({
|
|
404
|
-
get: () => view.value
|
|
405
|
-
set: a =>
|
|
416
|
+
get: () => view.value?.state.selection.main.head ?? 0,
|
|
417
|
+
set: a => {
|
|
418
|
+
if (view.value) {
|
|
419
|
+
view.value.dispatch({ selection: { anchor: a } });
|
|
420
|
+
}
|
|
421
|
+
},
|
|
406
422
|
});
|
|
407
423
|
|
|
408
424
|
/** JSON */
|
|
409
|
-
const json: WritableComputedRef<
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
425
|
+
const json: WritableComputedRef<
|
|
426
|
+
Record<string, StateField<any>> | undefined
|
|
427
|
+
> = computed({
|
|
428
|
+
get: () => view.value?.state.toJSON(),
|
|
429
|
+
set: j => {
|
|
430
|
+
if (view.value && j) {
|
|
431
|
+
view.value.setState(EditorState.fromJSON(j));
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
});
|
|
415
435
|
|
|
416
436
|
/** Text length */
|
|
417
437
|
const length: Ref<number> = ref(0);
|
|
@@ -453,6 +473,9 @@ export default defineComponent({
|
|
|
453
473
|
props.minimal && !props.basic ? minimalSetup : undefined,
|
|
454
474
|
// ViewUpdate event listener
|
|
455
475
|
EditorView.updateListener.of((update: ViewUpdate): void => {
|
|
476
|
+
if (!view.value) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
456
479
|
// Emit focus status
|
|
457
480
|
context.emit('focus', view.value.hasFocus);
|
|
458
481
|
|
|
@@ -527,6 +550,9 @@ export default defineComponent({
|
|
|
527
550
|
watch(
|
|
528
551
|
() => props.modelValue,
|
|
529
552
|
async value => {
|
|
553
|
+
if (!view.value) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
530
556
|
if (
|
|
531
557
|
view.value.composing || // IME fix
|
|
532
558
|
view.value.state.doc.toJSON().join(props.lineSeparator ?? '\n') ===
|
|
@@ -556,11 +582,14 @@ export default defineComponent({
|
|
|
556
582
|
|
|
557
583
|
/** When loaded */
|
|
558
584
|
onMounted(async () => {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
if (!editor.value) {
|
|
585
|
+
// Skip initialization in SSR environment
|
|
586
|
+
if (typeof window === 'undefined' || !editor.value) {
|
|
562
587
|
return;
|
|
563
588
|
}
|
|
589
|
+
|
|
590
|
+
/** Initial value */
|
|
591
|
+
let value: string | Text = doc.value;
|
|
592
|
+
|
|
564
593
|
if (editor.value.childNodes[0]) {
|
|
565
594
|
// when slot mode, overwrite initial value
|
|
566
595
|
if (doc.value !== '') {
|
|
@@ -576,6 +605,9 @@ export default defineComponent({
|
|
|
576
605
|
parent: editor.value,
|
|
577
606
|
state: EditorState.create({ doc: value, extensions: extensions.value }),
|
|
578
607
|
dispatch: (tr: Transaction) => {
|
|
608
|
+
if (!view.value) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
579
611
|
view.value.update([tr]);
|
|
580
612
|
if (tr.changes.empty || !tr.docChanged) {
|
|
581
613
|
// if not change value, no fire emit event
|
|
@@ -601,8 +633,10 @@ export default defineComponent({
|
|
|
601
633
|
|
|
602
634
|
/** Destroy */
|
|
603
635
|
onUnmounted(() => {
|
|
604
|
-
view.value
|
|
605
|
-
|
|
636
|
+
if (view.value) {
|
|
637
|
+
view.value.destroy();
|
|
638
|
+
context.emit('destroy');
|
|
639
|
+
}
|
|
606
640
|
});
|
|
607
641
|
|
|
608
642
|
/**
|
|
@@ -645,42 +679,38 @@ export default defineComponent({
|
|
|
645
679
|
* @param to - end line number
|
|
646
680
|
*/
|
|
647
681
|
const getRange = (from?: number, to?: number): string | undefined =>
|
|
648
|
-
view.value
|
|
682
|
+
view.value?.state.sliceDoc(from, to);
|
|
649
683
|
/**
|
|
650
684
|
* Get the content of line.
|
|
651
685
|
*
|
|
652
686
|
* @param number - line number
|
|
653
687
|
*/
|
|
654
|
-
const getLine = (number: number): string =>
|
|
655
|
-
view.value
|
|
688
|
+
const getLine = (number: number): string | undefined =>
|
|
689
|
+
view.value?.state.doc.line(number + 1).text;
|
|
656
690
|
/** Get the number of lines in the editor. */
|
|
657
|
-
const lineCount = (): number => view.value
|
|
691
|
+
const lineCount = (): number => view.value?.state.doc.lines ?? 0;
|
|
658
692
|
/** Retrieve one end of the primary selection. */
|
|
659
|
-
const getCursor = (): number => view.value
|
|
693
|
+
const getCursor = (): number => view.value?.state.selection.main.head ?? 0;
|
|
660
694
|
/** Retrieves a list of all current selections. */
|
|
661
695
|
const listSelections = (): readonly SelectionRange[] => {
|
|
662
|
-
|
|
663
|
-
return (_view$value$state$sel = view.value.state.selection.ranges) !==
|
|
664
|
-
null && _view$value$state$sel !== undefined
|
|
665
|
-
? _view$value$state$sel
|
|
666
|
-
: [];
|
|
696
|
+
return view.value?.state.selection.ranges ?? [];
|
|
667
697
|
};
|
|
668
698
|
/** Get the currently selected code. */
|
|
669
699
|
const getSelection = (): string => {
|
|
670
|
-
|
|
671
|
-
|
|
700
|
+
if (!view.value) {
|
|
701
|
+
return '';
|
|
702
|
+
}
|
|
703
|
+
return view.value.state.sliceDoc(
|
|
672
704
|
view.value.state.selection.main.from,
|
|
673
705
|
view.value.state.selection.main.to
|
|
674
|
-
)
|
|
675
|
-
? _view$value$state$sli
|
|
676
|
-
: '';
|
|
706
|
+
);
|
|
677
707
|
};
|
|
678
708
|
/**
|
|
679
709
|
* The length of the given array should be the same as the number of active selections.
|
|
680
710
|
* Replaces the content of the selections with the strings in the array.
|
|
681
711
|
*/
|
|
682
712
|
const getSelections = (): string[] => {
|
|
683
|
-
const s = view.value
|
|
713
|
+
const s = view.value?.state;
|
|
684
714
|
if (!s) {
|
|
685
715
|
return [];
|
|
686
716
|
}
|
|
@@ -691,9 +721,9 @@ export default defineComponent({
|
|
|
691
721
|
};
|
|
692
722
|
/** Return true if any text is selected. */
|
|
693
723
|
const somethingSelected = (): boolean =>
|
|
694
|
-
view.value
|
|
724
|
+
view.value?.state.selection.ranges.some(
|
|
695
725
|
(r: { empty: boolean }) => !r.empty
|
|
696
|
-
);
|
|
726
|
+
) ?? false;
|
|
697
727
|
|
|
698
728
|
/**
|
|
699
729
|
* Replace the part of the document between from and to with the given string.
|
|
@@ -706,33 +736,45 @@ export default defineComponent({
|
|
|
706
736
|
replacement: string | Text,
|
|
707
737
|
from: number,
|
|
708
738
|
to: number
|
|
709
|
-
): void =>
|
|
710
|
-
view.value
|
|
711
|
-
|
|
712
|
-
|
|
739
|
+
): void => {
|
|
740
|
+
if (view.value) {
|
|
741
|
+
view.value.dispatch({
|
|
742
|
+
changes: { from, to, insert: replacement },
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
};
|
|
713
746
|
/**
|
|
714
747
|
* Replace the selection(s) with the given string.
|
|
715
748
|
* By default, the new selection ends up after the inserted text.
|
|
716
749
|
*
|
|
717
750
|
* @param replacement - replacement text
|
|
718
751
|
*/
|
|
719
|
-
const replaceSelection = (replacement: string | Text): void =>
|
|
720
|
-
|
|
752
|
+
const replaceSelection = (replacement: string | Text): void => {
|
|
753
|
+
if (view.value) {
|
|
754
|
+
view.value.dispatch(view.value.state.replaceSelection(replacement));
|
|
755
|
+
}
|
|
756
|
+
};
|
|
721
757
|
/**
|
|
722
758
|
* Set the cursor position.
|
|
723
759
|
*
|
|
724
760
|
* @param position - position.
|
|
725
761
|
*/
|
|
726
|
-
const setCursor = (position: number): void =>
|
|
727
|
-
view.value
|
|
762
|
+
const setCursor = (position: number): void => {
|
|
763
|
+
if (view.value) {
|
|
764
|
+
view.value.dispatch({ selection: { anchor: position } });
|
|
765
|
+
}
|
|
766
|
+
};
|
|
728
767
|
/**
|
|
729
768
|
* Set a single selection range.
|
|
730
769
|
*
|
|
731
770
|
* @param anchor - anchor position
|
|
732
771
|
* @param head -
|
|
733
772
|
*/
|
|
734
|
-
const setSelection = (anchor: number, head?: number): void =>
|
|
735
|
-
view.value
|
|
773
|
+
const setSelection = (anchor: number, head?: number): void => {
|
|
774
|
+
if (view.value) {
|
|
775
|
+
view.value.dispatch({ selection: { anchor, head } });
|
|
776
|
+
}
|
|
777
|
+
};
|
|
736
778
|
/**
|
|
737
779
|
* Sets a new set of selections. There must be at least one selection in the given array.
|
|
738
780
|
*
|
|
@@ -742,21 +784,27 @@ export default defineComponent({
|
|
|
742
784
|
const setSelections = (
|
|
743
785
|
ranges: readonly SelectionRange[],
|
|
744
786
|
primary?: number
|
|
745
|
-
): void =>
|
|
746
|
-
view.value
|
|
747
|
-
|
|
748
|
-
|
|
787
|
+
): void => {
|
|
788
|
+
if (view.value) {
|
|
789
|
+
view.value.dispatch({
|
|
790
|
+
selection: EditorSelection.create(ranges, primary),
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
};
|
|
749
794
|
/**
|
|
750
795
|
* Applies the given function to all existing selections, and calls extendSelections on the result.
|
|
751
796
|
*
|
|
752
797
|
* @param f - function
|
|
753
798
|
*/
|
|
754
|
-
const extendSelectionsBy = (f: any): void =>
|
|
755
|
-
view.value.
|
|
756
|
-
|
|
757
|
-
selection
|
|
758
|
-
|
|
759
|
-
|
|
799
|
+
const extendSelectionsBy = (f: any): void => {
|
|
800
|
+
if (view.value && selection.value) {
|
|
801
|
+
view.value.dispatch({
|
|
802
|
+
selection: EditorSelection.create(
|
|
803
|
+
selection.value.ranges.map((r: SelectionRange) => r.extend(f(r)))
|
|
804
|
+
),
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
};
|
|
760
808
|
|
|
761
809
|
const exposed = {
|
|
762
810
|
editor,
|
|
@@ -767,7 +815,7 @@ export default defineComponent({
|
|
|
767
815
|
length,
|
|
768
816
|
json,
|
|
769
817
|
diagnosticCount,
|
|
770
|
-
dom: view.value
|
|
818
|
+
dom: view.value?.contentDOM,
|
|
771
819
|
lint,
|
|
772
820
|
forceReconfigure,
|
|
773
821
|
// Bellow is CodeMirror5's function
|