vue-codemirror6 0.1.3 → 0.1.7
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 +255 -217
- package/dist/components/CodeMirror.vue.d.ts +187 -23
- package/dist/components/CodeMirror.vue.d.ts.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts +1 -1
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts.map +1 -1
- package/dist/vue-codemirror6.es.js +67 -33
- package/dist/vue-codemirror6.umd.js +2 -2
- package/package.json +37 -37
- package/src/components/CodeMirror.vue +100 -42
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.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"description": "CodeMirror6 Component for vue2",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"url": "https://github.com/logue/vue-codemirror6/issues"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=16"
|
|
35
|
+
"node": ">=16.15.0",
|
|
36
|
+
"yarn": ">=1.22.4"
|
|
36
37
|
},
|
|
37
38
|
"license": "MIT",
|
|
38
39
|
"main": "./dist/vue-codemirror6.umd.js",
|
|
@@ -54,23 +55,24 @@
|
|
|
54
55
|
"sideEffects": false,
|
|
55
56
|
"scripts": {
|
|
56
57
|
"dev": "vite",
|
|
57
|
-
"clean": "rimraf node_modules/.vite",
|
|
58
|
-
"build": "vite build & vue-tsc",
|
|
58
|
+
"clean": "rimraf node_modules/.vite && npx vue-demi-fix",
|
|
59
|
+
"build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
|
|
60
|
+
"build:analyze": "vue-tsc --noEmit && vite build --mode analyze",
|
|
59
61
|
"build:clean": "rimraf dist",
|
|
60
|
-
"lint": "eslint
|
|
61
|
-
"
|
|
62
|
-
"switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
|
|
62
|
+
"lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
|
|
63
|
+
"lint:markup": "vue-tsc --noEmit",
|
|
63
64
|
"prepare": "husky install",
|
|
64
65
|
"postinstall": "npx vue-demi-fix"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"vue-demi": "
|
|
68
|
+
"vue-demi": ">=0.12.5"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"@codemirror/
|
|
71
|
-
"@codemirror/
|
|
72
|
-
"@
|
|
73
|
-
"vue": "
|
|
71
|
+
"@codemirror/basic-setup": ">=0.20",
|
|
72
|
+
"@codemirror/state": ">=0.20",
|
|
73
|
+
"@codemirror/view": ">=0.20",
|
|
74
|
+
"@vue/composition-api": "=>1.6.2",
|
|
75
|
+
"vue": "^2.6.14 || ^3.2.36"
|
|
74
76
|
},
|
|
75
77
|
"peerDependenciesMeta": {
|
|
76
78
|
"@vue/composition-api": {
|
|
@@ -78,43 +80,41 @@
|
|
|
78
80
|
}
|
|
79
81
|
},
|
|
80
82
|
"devDependencies": {
|
|
81
|
-
"@codemirror/basic-setup": "^0.
|
|
82
|
-
"@codemirror/lang-markdown": "^0.
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"@
|
|
86
|
-
"@
|
|
87
|
-
"@
|
|
88
|
-
"@
|
|
89
|
-
"
|
|
90
|
-
"@vue/composition-api": "^1.4.9",
|
|
91
|
-
"@vue/eslint-config-typescript": "^10.0.0",
|
|
92
|
-
"eslint": "^8.12.0",
|
|
83
|
+
"@codemirror/basic-setup": "^0.20.0",
|
|
84
|
+
"@codemirror/lang-markdown": "^0.20.1",
|
|
85
|
+
"@types/lodash": "^4.14.182",
|
|
86
|
+
"@types/node": "^17.0.35",
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
88
|
+
"@typescript-eslint/parser": "^5.26.0",
|
|
89
|
+
"@vue/composition-api": "^1.6.2",
|
|
90
|
+
"@vue/eslint-config-prettier": "^7.0.0",
|
|
91
|
+
"eslint": "^8.16.0",
|
|
93
92
|
"eslint-config-google": "^0.14.0",
|
|
94
93
|
"eslint-config-prettier": "^8.5.0",
|
|
95
94
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
96
95
|
"eslint-import-resolver-typescript": "^2.7.1",
|
|
97
96
|
"eslint-plugin-import": "^2.26.0",
|
|
98
|
-
"eslint-plugin-
|
|
99
|
-
"eslint-plugin-
|
|
100
|
-
"eslint-plugin-
|
|
101
|
-
"eslint-plugin-vue": "^8.5.0",
|
|
97
|
+
"eslint-plugin-jsdoc": "^39.3.2",
|
|
98
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
99
|
+
"eslint-plugin-vue": "^9.0.1",
|
|
102
100
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
103
|
-
"husky": "^
|
|
104
|
-
"lint-staged": "^12.
|
|
101
|
+
"husky": "^8.0.1",
|
|
102
|
+
"lint-staged": "^12.4.2",
|
|
105
103
|
"lodash": "^4.17.21",
|
|
106
104
|
"prettier": "^2.6.2",
|
|
107
|
-
"prettier-plugin-jsdoc": "^0.3.
|
|
105
|
+
"prettier-plugin-jsdoc": "^0.3.38",
|
|
108
106
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
109
|
-
"prettier-plugin-sort-imports": "^1.6.
|
|
107
|
+
"prettier-plugin-sort-imports": "^1.6.1",
|
|
110
108
|
"rimraf": "^3.0.2",
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"vite
|
|
109
|
+
"rollup-plugin-visualizer": "^5.6.0",
|
|
110
|
+
"typescript": "^4.7.2",
|
|
111
|
+
"vite": "^2.9.9",
|
|
112
|
+
"vite-plugin-checker": "^0.4.6",
|
|
113
|
+
"vite-plugin-vue2": "^2.0.1",
|
|
114
114
|
"vue": "^2.6.14",
|
|
115
|
-
"vue-eslint-parser": "^
|
|
115
|
+
"vue-eslint-parser": "^9.0.2",
|
|
116
116
|
"vue-template-compiler": "^2.6.14",
|
|
117
|
-
"vue-tsc": "^0.
|
|
117
|
+
"vue-tsc": "^0.34.16"
|
|
118
118
|
},
|
|
119
119
|
"husky": {
|
|
120
120
|
"hooks": {
|
|
@@ -7,21 +7,30 @@
|
|
|
7
7
|
<script lang="ts">
|
|
8
8
|
import {
|
|
9
9
|
computed,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
defineComponent,
|
|
11
|
+
nextTick,
|
|
12
12
|
onMounted,
|
|
13
13
|
onUnmounted,
|
|
14
|
-
|
|
14
|
+
ref,
|
|
15
|
+
toRaw,
|
|
16
|
+
toRefs,
|
|
17
|
+
watch,
|
|
18
|
+
type ComputedRef,
|
|
19
|
+
type PropType,
|
|
20
|
+
type Ref,
|
|
21
|
+
type SetupContext,
|
|
15
22
|
} from 'vue-demi';
|
|
16
|
-
import { EditorState } from '@codemirror/state';
|
|
17
|
-
import { EditorView } from '@codemirror/view';
|
|
18
|
-
import { compact, merge } from 'lodash';
|
|
19
23
|
|
|
20
|
-
import
|
|
24
|
+
import { EditorSelection, EditorState } from '@codemirror/state';
|
|
25
|
+
import { EditorView, keymap } from '@codemirror/view';
|
|
26
|
+
import { basicSetup } from '@codemirror/basic-setup';
|
|
27
|
+
import { indentWithTab } from '@codemirror/commands';
|
|
28
|
+
|
|
29
|
+
import { compact, merge, trim } from 'lodash';
|
|
21
30
|
|
|
22
31
|
import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
|
|
23
32
|
|
|
24
|
-
import type { Extension, Transaction } from '@codemirror/state';
|
|
33
|
+
import type { Extension, Text, Transaction } from '@codemirror/state';
|
|
25
34
|
import type { LanguageSupport } from '@codemirror/language';
|
|
26
35
|
import type { ViewUpdate } from '@codemirror/view';
|
|
27
36
|
import type { Diagnostic } from '@codemirror/lint';
|
|
@@ -40,9 +49,20 @@ export default defineComponent({
|
|
|
40
49
|
props: {
|
|
41
50
|
/** Model value */
|
|
42
51
|
modelValue: {
|
|
43
|
-
type: String
|
|
52
|
+
type: String as PropType<string | Text>,
|
|
44
53
|
default: '',
|
|
45
54
|
},
|
|
55
|
+
/**
|
|
56
|
+
* Selection
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
59
|
+
*/
|
|
60
|
+
selection: {
|
|
61
|
+
type: Object as PropType<
|
|
62
|
+
EditorSelection | { anchor: number; head?: number }
|
|
63
|
+
>,
|
|
64
|
+
default: () => undefined,
|
|
65
|
+
},
|
|
46
66
|
/**
|
|
47
67
|
* Theme
|
|
48
68
|
*
|
|
@@ -50,13 +70,42 @@ export default defineComponent({
|
|
|
50
70
|
*/
|
|
51
71
|
theme: {
|
|
52
72
|
type: Object as PropType<{ [selector: string]: StyleSpec }>,
|
|
53
|
-
default:
|
|
73
|
+
default: () => {
|
|
74
|
+
return {};
|
|
75
|
+
},
|
|
54
76
|
},
|
|
55
77
|
/** Dark Mode */
|
|
56
78
|
dark: {
|
|
57
79
|
type: Boolean,
|
|
58
80
|
default: false,
|
|
59
81
|
},
|
|
82
|
+
/**
|
|
83
|
+
* Use Basic Setup
|
|
84
|
+
*
|
|
85
|
+
* @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
|
|
86
|
+
*/
|
|
87
|
+
basic: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false,
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Line wrapping
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
|
|
95
|
+
*/
|
|
96
|
+
wrap: {
|
|
97
|
+
type: Boolean,
|
|
98
|
+
default: false,
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Tab handling
|
|
102
|
+
*
|
|
103
|
+
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
|
|
104
|
+
*/
|
|
105
|
+
tab: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: false,
|
|
108
|
+
},
|
|
60
109
|
/**
|
|
61
110
|
* Readonly
|
|
62
111
|
*
|
|
@@ -82,7 +131,9 @@ export default defineComponent({
|
|
|
82
131
|
*/
|
|
83
132
|
extensions: {
|
|
84
133
|
type: Array as PropType<Extension[]>,
|
|
85
|
-
default:
|
|
134
|
+
default: () => {
|
|
135
|
+
return [];
|
|
136
|
+
},
|
|
86
137
|
},
|
|
87
138
|
/**
|
|
88
139
|
* Language Phreses
|
|
@@ -91,7 +142,7 @@ export default defineComponent({
|
|
|
91
142
|
*/
|
|
92
143
|
phrases: {
|
|
93
144
|
type: Object as PropType<Record<string, string>>,
|
|
94
|
-
default: undefined,
|
|
145
|
+
default: () => undefined,
|
|
95
146
|
},
|
|
96
147
|
/**
|
|
97
148
|
* CodeMirror Language
|
|
@@ -100,7 +151,7 @@ export default defineComponent({
|
|
|
100
151
|
*/
|
|
101
152
|
lang: {
|
|
102
153
|
type: Object as PropType<LanguageSupport>,
|
|
103
|
-
default: undefined,
|
|
154
|
+
default: () => undefined,
|
|
104
155
|
},
|
|
105
156
|
/**
|
|
106
157
|
* CodeMirror Linter
|
|
@@ -109,47 +160,54 @@ export default defineComponent({
|
|
|
109
160
|
*/
|
|
110
161
|
linter: {
|
|
111
162
|
type: Array as PropType<Diagnostic[]>,
|
|
112
|
-
default: undefined,
|
|
163
|
+
default: () => undefined,
|
|
113
164
|
},
|
|
114
165
|
},
|
|
115
166
|
/** Emits */
|
|
116
167
|
emits: ['update:modelValue', 'update'],
|
|
117
168
|
/**
|
|
118
169
|
* Setup
|
|
170
|
+
*
|
|
119
171
|
* @param props - Props
|
|
120
172
|
* @param context - Context
|
|
121
173
|
*/
|
|
122
174
|
setup(props, context: SetupContext) {
|
|
123
175
|
/** Editor DOM */
|
|
124
|
-
const editor: Ref<Element | undefined> = ref
|
|
176
|
+
const editor: Ref<Element | undefined> = ref();
|
|
125
177
|
|
|
126
|
-
/**
|
|
127
|
-
const
|
|
178
|
+
/** Internal value */
|
|
179
|
+
const doc: Ref<string | Text | undefined> = ref(props.modelValue);
|
|
128
180
|
|
|
129
181
|
/** Dark mode */
|
|
130
|
-
const dark
|
|
182
|
+
const { dark } = toRefs(props);
|
|
131
183
|
|
|
132
184
|
/** Emits */
|
|
133
185
|
const emit = context.emit as CodeMirrorEmitsInterface;
|
|
134
186
|
|
|
135
187
|
/** CodeMirror Extension */
|
|
136
|
-
const
|
|
188
|
+
const exts: ComputedRef<Extension[]> = computed(() => {
|
|
137
189
|
/** Default extension */
|
|
138
190
|
const ext = [
|
|
191
|
+
// Toggle basic setup
|
|
192
|
+
props.basic ? basicSetup : undefined,
|
|
139
193
|
// ViewUpdate event listener
|
|
140
|
-
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
141
|
-
emit('update', update)
|
|
142
|
-
|
|
194
|
+
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
195
|
+
emit('update', update)
|
|
196
|
+
),
|
|
143
197
|
// Toggle light/dark mode.
|
|
144
|
-
EditorView.theme(props.theme
|
|
198
|
+
EditorView.theme(props.theme, { dark: dark.value }),
|
|
199
|
+
// Toggle line wrapping
|
|
200
|
+
props.wrap ? EditorView.lineWrapping : undefined,
|
|
201
|
+
// Indent with tab
|
|
202
|
+
props.tab ? keymap.of([indentWithTab]) : undefined,
|
|
145
203
|
// locale settings
|
|
146
204
|
props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
|
|
147
|
-
// Parser language setting
|
|
148
|
-
props.lang,
|
|
149
205
|
// Readonly option
|
|
150
206
|
props.readonly ? EditorState.readOnly.of(props.readonly) : undefined,
|
|
151
207
|
// Editable option
|
|
152
208
|
props.editable ? EditorView.editable.of(props.editable) : undefined,
|
|
209
|
+
// Lang
|
|
210
|
+
props.lang ? toRaw(props.lang) : undefined,
|
|
153
211
|
];
|
|
154
212
|
|
|
155
213
|
if (props.linter) {
|
|
@@ -162,19 +220,19 @@ export default defineComponent({
|
|
|
162
220
|
merge(ext, props.extensions);
|
|
163
221
|
}
|
|
164
222
|
|
|
165
|
-
// console.debug('[CodeMirror.vue] Loaded extensions:',
|
|
223
|
+
// console.debug('[CodeMirror.vue] Loaded extensions:', compact(ext));
|
|
166
224
|
return compact(ext);
|
|
167
225
|
});
|
|
168
226
|
|
|
169
227
|
/** CodeMirror Editor View */
|
|
170
|
-
let view
|
|
228
|
+
let view: EditorView;
|
|
171
229
|
|
|
172
230
|
/**
|
|
173
231
|
* Input value changed
|
|
174
232
|
*
|
|
175
233
|
* @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
|
|
176
234
|
*/
|
|
177
|
-
watch(
|
|
235
|
+
watch(doc, current => {
|
|
178
236
|
if (view.composing) {
|
|
179
237
|
// IME fix
|
|
180
238
|
return;
|
|
@@ -185,35 +243,34 @@ export default defineComponent({
|
|
|
185
243
|
view.setState(
|
|
186
244
|
EditorState.create({
|
|
187
245
|
doc: current,
|
|
188
|
-
extensions:
|
|
246
|
+
extensions: exts.value,
|
|
189
247
|
selection: previous,
|
|
190
248
|
})
|
|
191
249
|
);
|
|
192
250
|
});
|
|
193
251
|
|
|
194
|
-
/** Toggle Dark mode */
|
|
195
252
|
watch(dark, () => {
|
|
196
253
|
view.setState(
|
|
197
254
|
EditorState.create({
|
|
198
|
-
doc:
|
|
199
|
-
extensions:
|
|
255
|
+
doc: doc.value,
|
|
256
|
+
extensions: exts.value,
|
|
200
257
|
})
|
|
201
258
|
);
|
|
202
259
|
});
|
|
203
260
|
|
|
204
261
|
/** When loaded */
|
|
205
|
-
onMounted(() => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
: modelValue.value;
|
|
262
|
+
onMounted(async () => {
|
|
263
|
+
// overwrite initial value
|
|
264
|
+
if (doc.value == '' && editor.value) {
|
|
265
|
+
doc.value = trim((editor.value.childNodes[0] as HTMLElement).innerText);
|
|
266
|
+
}
|
|
211
267
|
|
|
212
268
|
// Register Codemirror
|
|
213
269
|
view = new EditorView({
|
|
214
270
|
state: EditorState.create({
|
|
215
|
-
doc: value,
|
|
216
|
-
|
|
271
|
+
doc: doc.value,
|
|
272
|
+
selection: props.selection,
|
|
273
|
+
extensions: exts.value,
|
|
217
274
|
}),
|
|
218
275
|
parent: editor.value,
|
|
219
276
|
dispatch: (tr: Transaction) => {
|
|
@@ -221,10 +278,11 @@ export default defineComponent({
|
|
|
221
278
|
|
|
222
279
|
if (tr.changes.empty) return;
|
|
223
280
|
// to parent binding
|
|
224
|
-
|
|
225
|
-
emit('update:modelValue',
|
|
281
|
+
doc.value = view.state.doc.toString();
|
|
282
|
+
emit('update:modelValue', doc.value);
|
|
226
283
|
},
|
|
227
284
|
});
|
|
285
|
+
await nextTick();
|
|
228
286
|
});
|
|
229
287
|
|
|
230
288
|
/** Destroy */
|