vue-codemirror6 0.5.1 → 0.5.4
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/README.md +8 -7
- package/dist/components/CodeMirror.d.ts +39 -31
- package/dist/components/CodeMirror.d.ts.map +1 -1
- package/dist/helpers/h-demi.d.ts +1 -1
- package/dist/helpers/h-demi.d.ts.map +1 -1
- package/dist/index.es.js +83 -44
- package/dist/index.umd.js +2 -2
- package/package.json +8 -13
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts +0 -9
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ yarn add vue-codemirror6 @vue/composition-api
|
|
|
37
37
|
| phrases | Record<string, string> | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
|
|
38
38
|
| extensions | Extension[] | Includes enhancements to extend CodeMirror. |
|
|
39
39
|
| linter | LintSource | Set Linter. Enter a linter (eg `esLint([arbitrary rule])` function for `@codemirror / lang-javascript`, `jsonParseLinter()`function for`@codemirror/json`). See the sources for various language libraries for more information. |
|
|
40
|
+
| lintGutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
|
|
40
41
|
|
|
41
42
|
Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
|
|
42
43
|
|
|
@@ -126,7 +127,7 @@ export default defineComponent({
|
|
|
126
127
|
|
|
127
128
|
### Full Example
|
|
128
129
|
|
|
129
|
-
When using as a Markdown editor on [vite-vue2-vuetify-ts-starter](https://github.com/logue/vite-vue2-vuetify-ts-starter
|
|
130
|
+
When using as a Markdown editor on [vite-vue2-vuetify-ts-starter](https://github.com/logue/vite-vue2-vuetify-ts-starter).
|
|
130
131
|
|
|
131
132
|
```vue
|
|
132
133
|
<template>
|
|
@@ -241,12 +242,12 @@ const config: UserConfig = {
|
|
|
241
242
|
// ...
|
|
242
243
|
codemirror: [
|
|
243
244
|
// Split CodeMirror code.
|
|
244
|
-
'@codemirror/basic-setup'
|
|
245
|
-
'@codemirror/commands'
|
|
246
|
-
'@codemirror/language'
|
|
247
|
-
'@codemirror/lint'
|
|
248
|
-
'@codemirror/state'
|
|
249
|
-
'@codemirror/view'
|
|
245
|
+
'@codemirror/basic-setup',
|
|
246
|
+
'@codemirror/commands',
|
|
247
|
+
'@codemirror/language',
|
|
248
|
+
'@codemirror/lint',
|
|
249
|
+
'@codemirror/state',
|
|
250
|
+
'@codemirror/view',
|
|
250
251
|
// Add the following as needed.
|
|
251
252
|
'@codemirror/lang-html',
|
|
252
253
|
'@codemirror/lang-javascript',
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { type PropType, type Ref, type SetupContext } from 'vue-demi';
|
|
2
2
|
import { EditorSelection } from '@codemirror/state';
|
|
3
|
-
import type { Extension, Text } from '@codemirror/state';
|
|
3
|
+
import type { Extension, SelectionRange, Text } from '@codemirror/state';
|
|
4
4
|
import type { LanguageSupport } from '@codemirror/language';
|
|
5
|
+
import type { ViewUpdate } from '@codemirror/view';
|
|
5
6
|
import type { LintSource } from '@codemirror/lint';
|
|
6
7
|
import type { StyleSpec } from 'style-mod';
|
|
8
|
+
/** Emit Interface */
|
|
9
|
+
export interface CodeMirrorEmitsInterface {
|
|
10
|
+
/** Model Update */
|
|
11
|
+
(e: 'update:modelValue', value: string | Text): void;
|
|
12
|
+
/** CodeMirror ViewUpdate */
|
|
13
|
+
(e: 'update', value: ViewUpdate): void;
|
|
14
|
+
}
|
|
7
15
|
/** CodeMirror Component */
|
|
8
16
|
declare const _default: import("vue-demi").DefineComponent<{
|
|
9
17
|
/** Model value */
|
|
@@ -11,18 +19,6 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
11
19
|
type: PropType<string | Text>;
|
|
12
20
|
default: string;
|
|
13
21
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Selection
|
|
16
|
-
*
|
|
17
|
-
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
18
|
-
*/
|
|
19
|
-
selection: {
|
|
20
|
-
type: PropType<EditorSelection | {
|
|
21
|
-
anchor: number;
|
|
22
|
-
head?: number | undefined;
|
|
23
|
-
}>;
|
|
24
|
-
default: () => undefined;
|
|
25
|
-
};
|
|
26
22
|
/**
|
|
27
23
|
* Theme
|
|
28
24
|
*
|
|
@@ -118,29 +114,39 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
118
114
|
*/
|
|
119
115
|
linter: {
|
|
120
116
|
type: PropType<LintSource>;
|
|
121
|
-
default:
|
|
117
|
+
default: undefined;
|
|
118
|
+
};
|
|
119
|
+
/** Show Gutter */
|
|
120
|
+
lintGutter: {
|
|
121
|
+
type: BooleanConstructor;
|
|
122
|
+
defalt: boolean;
|
|
122
123
|
};
|
|
123
124
|
}, {
|
|
124
125
|
context: SetupContext<import("vue-demi").EmitsOptions>;
|
|
125
126
|
editor: Ref<Element | undefined>;
|
|
127
|
+
selection: () => EditorSelection;
|
|
128
|
+
getRange: (a?: number, b?: number) => string;
|
|
129
|
+
getLine: (n: number) => string;
|
|
130
|
+
lineCount: () => number;
|
|
131
|
+
getCursor: () => number;
|
|
132
|
+
listSelections: () => readonly SelectionRange[];
|
|
133
|
+
getSelection: () => string;
|
|
134
|
+
getSelections: () => string[];
|
|
135
|
+
somethingSelected: () => boolean;
|
|
136
|
+
replaceRange: (text: string | Text, from: number, to: number) => void;
|
|
137
|
+
replaceSelection: (text: string | Text) => void;
|
|
138
|
+
setCursor: (pos: number) => void;
|
|
139
|
+
setSelection: (anchor: number, head: number) => void;
|
|
140
|
+
setSelections: (ranges: readonly SelectionRange[], mainIndex?: number | undefined) => void;
|
|
141
|
+
extendSelectionsBy: (f: any) => void;
|
|
142
|
+
focus: () => void;
|
|
143
|
+
hasFocus: () => boolean;
|
|
126
144
|
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
127
145
|
/** Model value */
|
|
128
146
|
modelValue: {
|
|
129
147
|
type: PropType<string | Text>;
|
|
130
148
|
default: string;
|
|
131
149
|
};
|
|
132
|
-
/**
|
|
133
|
-
* Selection
|
|
134
|
-
*
|
|
135
|
-
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
136
|
-
*/
|
|
137
|
-
selection: {
|
|
138
|
-
type: PropType<EditorSelection | {
|
|
139
|
-
anchor: number;
|
|
140
|
-
head?: number | undefined;
|
|
141
|
-
}>;
|
|
142
|
-
default: () => undefined;
|
|
143
|
-
};
|
|
144
150
|
/**
|
|
145
151
|
* Theme
|
|
146
152
|
*
|
|
@@ -236,14 +242,15 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
236
242
|
*/
|
|
237
243
|
linter: {
|
|
238
244
|
type: PropType<LintSource>;
|
|
239
|
-
default:
|
|
245
|
+
default: undefined;
|
|
246
|
+
};
|
|
247
|
+
/** Show Gutter */
|
|
248
|
+
lintGutter: {
|
|
249
|
+
type: BooleanConstructor;
|
|
250
|
+
defalt: boolean;
|
|
240
251
|
};
|
|
241
252
|
}>>, {
|
|
242
253
|
modelValue: string | Text;
|
|
243
|
-
selection: EditorSelection | {
|
|
244
|
-
anchor: number;
|
|
245
|
-
head?: number | undefined;
|
|
246
|
-
};
|
|
247
254
|
theme: {
|
|
248
255
|
[selector: string]: StyleSpec;
|
|
249
256
|
};
|
|
@@ -257,6 +264,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
257
264
|
phrases: Record<string, string>;
|
|
258
265
|
lang: LanguageSupport;
|
|
259
266
|
linter: LintSource;
|
|
267
|
+
lintGutter: boolean;
|
|
260
268
|
}>;
|
|
261
269
|
export default _default;
|
|
262
270
|
//# sourceMappingURL=CodeMirror.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AAUjE,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,IAAI,EAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAqB;AACrB,MAAM,WAAW,wBAAwB;IACvC,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACrD,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC;AAED,2BAA2B;;IAWvB,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;qBAiJI,eAAe;mBAKf,MAAM,MAAM,MAAM,KAAG,MAAM;iBAE7B,MAAM,KAAG,MAAM;qBACb,MAAM;qBACN,MAAM;0BACD,SAAS,cAAc,EAAE;wBAC3B,MAAM;yBAEL,MAAM,EAAE;6BAEJ,OAAO;yBAIT,MAAM,GAAG,IAAI,QAAQ,MAAM,MAAM,MAAM;6BAInC,MAAM,GAAG,IAAI;qBAErB,MAAM;2BAEA,MAAM,QAAQ,MAAM;4BAGxC,SAAS,cAAc,EAAE,cACrB,MAAM,GAAG,SAAS;;;oBAeX,OAAO;;IAvS5B,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;;;;;;;;;;;;;;;AAlHtB,wBA2VG"}
|
package/dist/helpers/h-demi.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
interface Options {
|
|
2
|
+
class?: string;
|
|
2
3
|
domProps?: Record<any, any>;
|
|
3
4
|
on?: Record<any, any>;
|
|
4
5
|
props?: Record<any, any>;
|
|
5
6
|
ref?: string;
|
|
6
|
-
class?: string;
|
|
7
7
|
style?: string;
|
|
8
8
|
}
|
|
9
9
|
declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) => import("vue-demi").VNode<import("vue-demi").RendererNode, import("vue-demi").RendererElement, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAWD,QAAA,MAAM,CAAC,SACC,MAAM,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,YACtB,OAAO,YACN,GAAG;;EAWd,CAAC;AAEF,QAAA,MAAM,IAAI,iBAAkB,GAAG,QACoC,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isVue2, h as h$1, defineComponent, ref, toRefs,
|
|
2
|
-
import { EditorState } from "@codemirror/state";
|
|
1
|
+
import { isVue2, h as h$1, defineComponent, ref, toRefs, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
|
|
2
|
+
import { EditorState, EditorSelection } from "@codemirror/state";
|
|
3
3
|
import { EditorView, keymap } from "@codemirror/view";
|
|
4
4
|
import { linter, lintGutter } from "@codemirror/lint";
|
|
5
5
|
import { basicSetup } from "@codemirror/basic-setup";
|
|
6
6
|
import { indentWithTab } from "@codemirror/commands";
|
|
7
|
-
import {
|
|
7
|
+
import { trim, compact } from "lodash";
|
|
8
8
|
const adaptOnsV3 = (ons) => {
|
|
9
9
|
if (!ons)
|
|
10
10
|
return null;
|
|
@@ -19,14 +19,9 @@ const h = (type, options = {}, chidren) => {
|
|
|
19
19
|
return h$1(type, options, chidren);
|
|
20
20
|
const { props, domProps, on, ...extraOptions } = options;
|
|
21
21
|
const ons = on ? adaptOnsV3(on) : {};
|
|
22
|
-
|
|
23
|
-
return h$1(type, params, chidren);
|
|
24
|
-
};
|
|
25
|
-
const slot = (defaultSlots) => {
|
|
26
|
-
if (typeof defaultSlots == "function")
|
|
27
|
-
return defaultSlots();
|
|
28
|
-
return defaultSlots;
|
|
22
|
+
return h$1(type, { ...extraOptions, ...props, ...domProps, ...ons }, chidren);
|
|
29
23
|
};
|
|
24
|
+
const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
|
|
30
25
|
var CodeMirror = defineComponent({
|
|
31
26
|
name: "CodeMirror",
|
|
32
27
|
model: {
|
|
@@ -38,10 +33,6 @@ var CodeMirror = defineComponent({
|
|
|
38
33
|
type: String,
|
|
39
34
|
default: ""
|
|
40
35
|
},
|
|
41
|
-
selection: {
|
|
42
|
-
type: Object,
|
|
43
|
-
default: () => void 0
|
|
44
|
-
},
|
|
45
36
|
theme: {
|
|
46
37
|
type: Object,
|
|
47
38
|
default: () => {
|
|
@@ -87,62 +78,52 @@ var CodeMirror = defineComponent({
|
|
|
87
78
|
default: () => void 0
|
|
88
79
|
},
|
|
89
80
|
linter: {
|
|
90
|
-
type:
|
|
91
|
-
default:
|
|
81
|
+
type: Function,
|
|
82
|
+
default: void 0
|
|
83
|
+
},
|
|
84
|
+
lintGutter: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
defalt: false
|
|
92
87
|
}
|
|
93
88
|
},
|
|
94
89
|
emits: ["update:modelValue", "update"],
|
|
95
90
|
setup(props, context) {
|
|
96
91
|
const editor = ref();
|
|
97
|
-
const doc = ref(props.modelValue);
|
|
98
92
|
const { dark } = toRefs(props);
|
|
93
|
+
const doc = ref(props.modelValue);
|
|
99
94
|
const emit = context.emit;
|
|
100
|
-
const exts = computed(() => {
|
|
101
|
-
const ext = [
|
|
102
|
-
props.basic ? basicSetup : void 0,
|
|
103
|
-
EditorView.updateListener.of((update) => emit("update", update)),
|
|
104
|
-
EditorView.theme(props.theme, { dark: dark.value }),
|
|
105
|
-
props.wrap ? EditorView.lineWrapping : void 0,
|
|
106
|
-
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
107
|
-
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
108
|
-
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
109
|
-
props.editable ? EditorView.editable.of(props.editable) : void 0,
|
|
110
|
-
props.lang ? toRaw(props.lang) : void 0,
|
|
111
|
-
props.linter ? linter(props.linter) : void 0,
|
|
112
|
-
props.linter ? lintGutter() : void 0
|
|
113
|
-
];
|
|
114
|
-
if (props.extensions) {
|
|
115
|
-
merge(ext, props.extensions);
|
|
116
|
-
}
|
|
117
|
-
return compact(ext);
|
|
118
|
-
});
|
|
119
95
|
let view;
|
|
120
|
-
watch(doc, (
|
|
96
|
+
watch(doc, (value) => {
|
|
121
97
|
if (view.composing) {
|
|
122
98
|
return;
|
|
123
99
|
}
|
|
124
100
|
const previous = view.state.selection;
|
|
125
101
|
view.setState(EditorState.create({
|
|
126
|
-
doc:
|
|
127
|
-
extensions:
|
|
102
|
+
doc: value,
|
|
103
|
+
extensions: getExtensions(),
|
|
128
104
|
selection: previous
|
|
129
105
|
}));
|
|
130
106
|
});
|
|
107
|
+
watch(() => props.modelValue, (text) => view.dispatch({
|
|
108
|
+
changes: { from: 0, to: view.state.doc.length, insert: text }
|
|
109
|
+
}));
|
|
131
110
|
watch(dark, () => {
|
|
132
111
|
view.setState(EditorState.create({
|
|
133
112
|
doc: doc.value,
|
|
134
|
-
extensions:
|
|
113
|
+
extensions: getExtensions()
|
|
135
114
|
}));
|
|
136
115
|
});
|
|
137
116
|
onMounted(async () => {
|
|
138
|
-
if (
|
|
117
|
+
if (editor.value && editor.value.childNodes[0]) {
|
|
118
|
+
if (doc.value !== "") {
|
|
119
|
+
console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.");
|
|
120
|
+
}
|
|
139
121
|
doc.value = trim(editor.value.childNodes[0].innerText);
|
|
140
122
|
}
|
|
141
123
|
view = new EditorView({
|
|
142
124
|
state: EditorState.create({
|
|
143
125
|
doc: doc.value,
|
|
144
|
-
|
|
145
|
-
extensions: exts.value
|
|
126
|
+
extensions: getExtensions()
|
|
146
127
|
}),
|
|
147
128
|
parent: editor.value,
|
|
148
129
|
dispatch: (tr) => {
|
|
@@ -156,9 +137,67 @@ var CodeMirror = defineComponent({
|
|
|
156
137
|
await nextTick();
|
|
157
138
|
});
|
|
158
139
|
onUnmounted(() => view.destroy());
|
|
140
|
+
const getExtensions = () => {
|
|
141
|
+
const extensions = compact([
|
|
142
|
+
props.basic ? basicSetup : void 0,
|
|
143
|
+
EditorView.updateListener.of((update) => emit("update", update)),
|
|
144
|
+
EditorView.theme(props.theme, { dark: dark.value }),
|
|
145
|
+
props.wrap ? EditorView.lineWrapping : void 0,
|
|
146
|
+
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
147
|
+
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
148
|
+
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
149
|
+
props.editable ? EditorView.editable.of(props.editable) : void 0,
|
|
150
|
+
props.lang ? toRaw(props.lang) : void 0,
|
|
151
|
+
props.linter ? linter(props.linter) : void 0,
|
|
152
|
+
props.linter && props.lintGutter ? lintGutter() : void 0,
|
|
153
|
+
...props.extensions
|
|
154
|
+
]);
|
|
155
|
+
console.debug("[CodeMirror.vue] Loaded extensions: ", extensions);
|
|
156
|
+
return extensions;
|
|
157
|
+
};
|
|
158
|
+
const selection = () => view.state.selection;
|
|
159
|
+
const getRange = (a, b) => view.state.sliceDoc(a, b);
|
|
160
|
+
const getLine = (n) => view.state.doc.line(n + 1).text;
|
|
161
|
+
const lineCount = () => view.state.doc.lines;
|
|
162
|
+
const getCursor = () => selection().main.head;
|
|
163
|
+
const listSelections = () => selection().ranges;
|
|
164
|
+
const getSelection = () => view.state.sliceDoc(selection().main.from, selection().main.to);
|
|
165
|
+
const getSelections = () => selection().ranges.map((r) => view.state.sliceDoc(r.from, r.to));
|
|
166
|
+
const somethingSelected = () => selection().ranges.some((r) => !r.empty);
|
|
167
|
+
const replaceRange = (text, from, to) => view.dispatch({
|
|
168
|
+
changes: { from, to, insert: text }
|
|
169
|
+
});
|
|
170
|
+
const replaceSelection = (text) => view.dispatch(view.state.replaceSelection(text));
|
|
171
|
+
const setCursor = (pos) => view.dispatch({ selection: { anchor: pos } });
|
|
172
|
+
const setSelection = (anchor, head) => view.dispatch({ selection: { anchor, head } });
|
|
173
|
+
const setSelections = (ranges, mainIndex) => view.dispatch({
|
|
174
|
+
selection: EditorSelection.create(ranges, mainIndex)
|
|
175
|
+
});
|
|
176
|
+
const extendSelectionsBy = (f) => view.dispatch({
|
|
177
|
+
selection: EditorSelection.create(selection().ranges.map((r) => r.extend(f(r))))
|
|
178
|
+
});
|
|
179
|
+
const focus = () => view.focus();
|
|
180
|
+
const hasFocus = () => view.hasFocus;
|
|
159
181
|
return {
|
|
160
182
|
context,
|
|
161
|
-
editor
|
|
183
|
+
editor,
|
|
184
|
+
selection,
|
|
185
|
+
getRange,
|
|
186
|
+
getLine,
|
|
187
|
+
lineCount,
|
|
188
|
+
getCursor,
|
|
189
|
+
listSelections,
|
|
190
|
+
getSelection,
|
|
191
|
+
getSelections,
|
|
192
|
+
somethingSelected,
|
|
193
|
+
replaceRange,
|
|
194
|
+
replaceSelection,
|
|
195
|
+
setCursor,
|
|
196
|
+
setSelection,
|
|
197
|
+
setSelections,
|
|
198
|
+
extendSelectionsBy,
|
|
199
|
+
focus,
|
|
200
|
+
hasFocus
|
|
162
201
|
};
|
|
163
202
|
},
|
|
164
203
|
render() {
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(r,
|
|
1
|
+
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("@codemirror/basic-setup"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","@codemirror/basic-setup","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.basicSetup,r.commands,r.lodash))})(this,function(r,n,d,u,p,v,x,S){"use strict";const C=e=>e?Object.entries(e).reduce((l,[i,f])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...l,[i]:f}),{}):null,g=(e,l={},i)=>{if(n.isVue2)return n.h(e,l,i);const{props:f,domProps:a,on:m,...o}=l,h=m?C(m):{};return n.h(e,{...o,...f,...a,...h},i)},V=e=>typeof e=="function"?e():e;var y=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},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update"],setup(e,l){const i=n.ref(),{dark:f}=n.toRefs(e),a=n.ref(e.modelValue),m=l.emit;let o;n.watch(a,t=>{if(o.composing)return;const s=o.state.selection;o.setState(d.EditorState.create({doc:t,extensions:h(),selection:s}))}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t}})),n.watch(f,()=>{o.setState(d.EditorState.create({doc:a.value,extensions:h()}))}),n.onMounted(async()=>{i.value&&i.value.childNodes[0]&&(a.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a.value=S.trim(i.value.childNodes[0].innerText)),o=new u.EditorView({state:d.EditorState.create({doc:a.value,extensions:h()}),parent:i.value,dispatch:t=>{o.update([t]),!t.changes.empty&&(a.value=o.state.doc.toString(),m("update:modelValue",a.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>{const t=S.compact([e.basic?v.basicSetup:void 0,u.EditorView.updateListener.of(s=>m("update",s)),u.EditorView.theme(e.theme,{dark:f.value}),e.wrap?u.EditorView.lineWrapping:void 0,e.tab?u.keymap.of([x.indentWithTab]):void 0,e.phrases?d.EditorState.phrases.of(e.phrases):void 0,e.readonly?d.EditorState.readOnly.of(e.readonly):void 0,e.editable?u.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?p.linter(e.linter):void 0,e.linter&&e.lintGutter?p.lintGutter():void 0,...e.extensions]);return console.debug("[CodeMirror.vue] Loaded extensions: ",t),t},c=()=>o.state.selection;return{context:l,editor:i,selection:c,getRange:(t,s)=>o.state.sliceDoc(t,s),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>c().main.head,listSelections:()=>c().ranges,getSelection:()=>o.state.sliceDoc(c().main.from,c().main.to),getSelections:()=>c().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>c().ranges.some(t=>!t.empty),replaceRange:(t,s,w)=>o.dispatch({changes:{from:s,to:w,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>o.dispatch({selection:{anchor:t}}),setSelection:(t,s)=>o.dispatch({selection:{anchor:t,head:s}}),setSelections:(t,s)=>o.dispatch({selection:d.EditorSelection.create(t,s)}),extendSelectionsBy:t=>o.dispatch({selection:d.EditorSelection.create(c().ranges.map(s=>s.extend(t(s))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return g("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?g("aside",{style:"display: none;"},V(this.$slots.default)):void 0)}});/**
|
|
2
2
|
* Vue CodeMirror6 Component
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author Logue {@link logue@hotmail.co.jp}
|
|
6
6
|
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
7
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
-
*/const
|
|
8
|
+
*/const b=e=>e.component("CodeMirror",y);r.default=y,r.install=b,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
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": "0.5.
|
|
4
|
+
"version": "0.5.4",
|
|
5
5
|
"description": "CodeMirror6 Component for vue2 and vue3",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
@@ -40,9 +40,6 @@
|
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"main": "./dist/index.umd.js",
|
|
42
42
|
"module": "./dist/index.es.js",
|
|
43
|
-
"browser": {
|
|
44
|
-
"./sfc": "./src/components/CodeMirror.vue"
|
|
45
|
-
},
|
|
46
43
|
"exports": {
|
|
47
44
|
".": {
|
|
48
45
|
"import": "./dist/index.es.js",
|
|
@@ -51,8 +48,7 @@
|
|
|
51
48
|
},
|
|
52
49
|
"types": "./dist/index.d.ts",
|
|
53
50
|
"files": [
|
|
54
|
-
"/dist"
|
|
55
|
-
"/src/components/CodeMirror.vue"
|
|
51
|
+
"/dist"
|
|
56
52
|
],
|
|
57
53
|
"sideEffects": false,
|
|
58
54
|
"scripts": {
|
|
@@ -89,8 +85,8 @@
|
|
|
89
85
|
"@codemirror/lang-markdown": "^0.20.1",
|
|
90
86
|
"@types/lodash": "^4.14.182",
|
|
91
87
|
"@types/node": "^17.0.36",
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
93
|
-
"@typescript-eslint/parser": "^5.
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
|
89
|
+
"@typescript-eslint/parser": "^5.27.0",
|
|
94
90
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
95
91
|
"@vue/eslint-config-prettier": "^7.0.0",
|
|
96
92
|
"eslint": "^8.16.0",
|
|
@@ -98,19 +94,18 @@
|
|
|
98
94
|
"eslint-config-prettier": "^8.5.0",
|
|
99
95
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
100
96
|
"eslint-import-resolver-typescript": "^2.7.1",
|
|
97
|
+
"eslint-plugin-html": "^6.2.0",
|
|
101
98
|
"eslint-plugin-import": "^2.26.0",
|
|
102
99
|
"eslint-plugin-jsdoc": "^39.3.2",
|
|
103
100
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
104
101
|
"eslint-plugin-vue": "^9.0.1",
|
|
105
102
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
103
|
+
"eslint-plugin-yaml": "^0.5.0",
|
|
106
104
|
"eslint4b-prebuilt": "^6.7.2",
|
|
107
105
|
"husky": "^8.0.1",
|
|
108
|
-
"lint-staged": "^12.4.
|
|
106
|
+
"lint-staged": "^12.4.3",
|
|
109
107
|
"lodash": "^4.17.21",
|
|
110
108
|
"prettier": "^2.6.2",
|
|
111
|
-
"prettier-plugin-jsdoc": "^0.3.38",
|
|
112
|
-
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
113
|
-
"prettier-plugin-sort-imports": "^1.6.1",
|
|
114
109
|
"rimraf": "^3.0.2",
|
|
115
110
|
"rollup-plugin-visualizer": "^5.6.0",
|
|
116
111
|
"typescript": "^4.7.2",
|
|
@@ -118,7 +113,7 @@
|
|
|
118
113
|
"vite-plugin-checker": "^0.4.6",
|
|
119
114
|
"vue": "^3.2.36",
|
|
120
115
|
"vue-eslint-parser": "^9.0.2",
|
|
121
|
-
"vue-tsc": "^0.
|
|
116
|
+
"vue-tsc": "^0.35.2"
|
|
122
117
|
},
|
|
123
118
|
"husky": {
|
|
124
119
|
"hooks": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ViewUpdate } from '@codemirror/view';
|
|
2
|
-
/** Emit Interface */
|
|
3
|
-
export default interface CodeMirrorEmitsInterface {
|
|
4
|
-
/** Model Update */
|
|
5
|
-
(e: 'update:modelValue', value: string | Text): void;
|
|
6
|
-
/** CodeMirror ViewUpdate */
|
|
7
|
-
(e: 'update', value: ViewUpdate): void;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=CodeMirrorEmitsInterface.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirrorEmitsInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/CodeMirrorEmitsInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAqB;AACrB,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACrD,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC"}
|