vue-codemirror6 1.1.27 → 1.1.28
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/package.json +31 -27
- package/dist/Meta.d.ts +0 -3
- package/dist/components/CodeMirror.d.ts +0 -3
- package/dist/index.d.ts +0 -4
- package/dist/index.es.js +0 -532
- package/dist/index.iife.js +0 -536
- package/dist/index.umd.js +0 -537
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.1.
|
|
4
|
+
"version": "1.1.28",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "CodeMirror6 Component for vue2 and vue3.",
|
|
7
7
|
"keywords": [
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
"engines": {
|
|
56
56
|
"yarn": ">=1.22.19"
|
|
57
57
|
},
|
|
58
|
-
"packageManager": "yarn@
|
|
58
|
+
"packageManager": "yarn@4.0.1",
|
|
59
59
|
"sideEffects": false,
|
|
60
60
|
"scripts": {
|
|
61
61
|
"dev": "vite",
|
|
62
62
|
"clean": "rimraf node_modules/.vite",
|
|
63
63
|
"type-check": "tsc --noEmit --composite false",
|
|
64
|
-
"build": "run-p type-check build-only",
|
|
64
|
+
"build": "run-p type-check \"build-only {@}\" --",
|
|
65
65
|
"build:analyze": "vite build --mode=analyze",
|
|
66
66
|
"build:clean": "rimraf dist docs",
|
|
67
67
|
"build:docs": "vite build --mode=docs",
|
|
@@ -81,46 +81,46 @@
|
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@codemirror/lang-javascript": "^6.2.1",
|
|
83
83
|
"@codemirror/lang-json": "^6.0.1",
|
|
84
|
-
"@codemirror/lang-markdown": "^6.2.
|
|
84
|
+
"@codemirror/lang-markdown": "^6.2.2",
|
|
85
85
|
"@codemirror/lang-vue": "^0.1.2",
|
|
86
86
|
"@tsconfig/node-lts": "^18.12.5",
|
|
87
|
-
"@types/node": "^20.
|
|
88
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
89
|
-
"@vitejs/plugin-vue": "^4.
|
|
90
|
-
"@vue/compiler-sfc": "^3.3.
|
|
87
|
+
"@types/node": "^20.9.0",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
89
|
+
"@vitejs/plugin-vue": "^4.4.0",
|
|
90
|
+
"@vue/compiler-sfc": "^3.3.8",
|
|
91
91
|
"@vue/eslint-config-prettier": "^8.0.0",
|
|
92
92
|
"@vue/tsconfig": "^0.4.0",
|
|
93
|
-
"@vueuse/core": "^10.
|
|
94
|
-
"bootstrap": "^5.3.
|
|
95
|
-
"eslint": "^8.
|
|
96
|
-
"eslint-config-standard-with-typescript": "^39.
|
|
93
|
+
"@vueuse/core": "^10.5.0",
|
|
94
|
+
"bootstrap": "^5.3.2",
|
|
95
|
+
"eslint": "^8.53.0",
|
|
96
|
+
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
97
97
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
98
|
-
"eslint-import-resolver-typescript": "^3.6.
|
|
99
|
-
"eslint-linter-browserify": "^8.
|
|
98
|
+
"eslint-import-resolver-typescript": "^3.6.1",
|
|
99
|
+
"eslint-linter-browserify": "^8.53.0",
|
|
100
100
|
"eslint-plugin-html": "^7.1.0",
|
|
101
|
-
"eslint-plugin-import": "^2.
|
|
102
|
-
"eslint-plugin-n": "^16.0
|
|
101
|
+
"eslint-plugin-import": "^2.29.0",
|
|
102
|
+
"eslint-plugin-n": "^16.3.0",
|
|
103
103
|
"eslint-plugin-promise": "^6.1.1",
|
|
104
104
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
105
105
|
"eslint-plugin-vue": "latest",
|
|
106
106
|
"eslint-plugin-vuejs-accessibility": "^2.2.0",
|
|
107
107
|
"eslint-plugin-yaml": "^0.5.0",
|
|
108
108
|
"husky": "^8.0.3",
|
|
109
|
-
"lint-staged": "^
|
|
109
|
+
"lint-staged": "^15.0.2",
|
|
110
110
|
"npm-run-all": "^4.1.5",
|
|
111
111
|
"prettier": "^3.0.3",
|
|
112
|
-
"rimraf": "^5.0.
|
|
112
|
+
"rimraf": "^5.0.5",
|
|
113
113
|
"rollup-plugin-visualizer": "^5.9.2",
|
|
114
|
-
"sass": "
|
|
114
|
+
"sass": "~1.69.5",
|
|
115
115
|
"typescript": "^5.2.2",
|
|
116
|
-
"vite": "^4.
|
|
117
|
-
"vite-plugin-banner": "^0.7.
|
|
116
|
+
"vite": "^4.5.0",
|
|
117
|
+
"vite-plugin-banner": "^0.7.1",
|
|
118
118
|
"vite-plugin-checker": "^0.6.2",
|
|
119
|
-
"vite-plugin-dts": "^3.
|
|
120
|
-
"vue": "^3.3.
|
|
121
|
-
"vue-eslint-parser": "^9.3.
|
|
119
|
+
"vite-plugin-dts": "^3.6.3",
|
|
120
|
+
"vue": "^3.3.8",
|
|
121
|
+
"vue-eslint-parser": "^9.3.2",
|
|
122
122
|
"vue-markdown-wasm": "^0.3.12",
|
|
123
|
-
"vue-tsc": "^1.8.
|
|
123
|
+
"vue-tsc": "^1.8.22"
|
|
124
124
|
},
|
|
125
125
|
"husky": {
|
|
126
126
|
"hooks": {
|
|
@@ -128,13 +128,17 @@
|
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
"lint-staged": {
|
|
131
|
-
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
131
|
+
"*.{js,ts,json,htm,html,vue}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
132
132
|
"*": "prettier -w -u"
|
|
133
133
|
},
|
|
134
134
|
"resolutions": {
|
|
135
135
|
"http-cache-semantics": "^4.1.1",
|
|
136
136
|
"json5": "^2.2.3",
|
|
137
|
+
"postcss": "^8.4.31",
|
|
137
138
|
"semver": "^7.5.2",
|
|
138
|
-
"
|
|
139
|
+
"tough-cookie": "^4.1.3",
|
|
140
|
+
"vite": "^4.3.9",
|
|
141
|
+
"word-wrap": "^1.2.4",
|
|
142
|
+
"yaml": "^2.3.2"
|
|
139
143
|
}
|
|
140
144
|
}
|
package/dist/Meta.d.ts
DELETED
package/dist/index.d.ts
DELETED
package/dist/index.es.js
DELETED
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vue-codemirror6
|
|
3
|
-
*
|
|
4
|
-
* @description CodeMirror6 Component for vue2 and vue3.
|
|
5
|
-
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
|
|
7
|
-
* @license MIT
|
|
8
|
-
* @version 1.1.27
|
|
9
|
-
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { isVue2, h as h$1, defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
|
|
13
|
-
import { basicSetup, minimalSetup } from 'codemirror';
|
|
14
|
-
import { EditorView, keymap, placeholder } from '@codemirror/view';
|
|
15
|
-
import { EditorState, Compartment, StateEffect, EditorSelection } from '@codemirror/state';
|
|
16
|
-
import { forceLinting, linter, lintGutter, diagnosticCount } from '@codemirror/lint';
|
|
17
|
-
import { indentWithTab } from '@codemirror/commands';
|
|
18
|
-
|
|
19
|
-
const adaptOnsV3 = (ons) => {
|
|
20
|
-
if (!ons)
|
|
21
|
-
return {};
|
|
22
|
-
return Object.entries(ons).reduce((ret, [key, handler]) => {
|
|
23
|
-
key = key.charAt(0).toUpperCase() + key.slice(1);
|
|
24
|
-
key = `on${key}`;
|
|
25
|
-
return { ...ret, [key]: handler };
|
|
26
|
-
}, {});
|
|
27
|
-
};
|
|
28
|
-
function h(type, options = {}, chidren) {
|
|
29
|
-
if (isVue2) {
|
|
30
|
-
return h$1(type, options, chidren);
|
|
31
|
-
}
|
|
32
|
-
const { props, domProps, on, ...extraOptions } = options;
|
|
33
|
-
const ons = on ? adaptOnsV3(on) : {};
|
|
34
|
-
return h$1(
|
|
35
|
-
type,
|
|
36
|
-
{ ...extraOptions, ...props, ...domProps, ...ons },
|
|
37
|
-
chidren
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
const slot = (defaultSlots) => typeof defaultSlots === "function" ? defaultSlots() : defaultSlots;
|
|
41
|
-
|
|
42
|
-
var CodeMirror = defineComponent({
|
|
43
|
-
/** Component Name */
|
|
44
|
-
name: "CodeMirror",
|
|
45
|
-
/** Model Definition */
|
|
46
|
-
model: {
|
|
47
|
-
prop: "modelValue",
|
|
48
|
-
event: "update:modelValue"
|
|
49
|
-
},
|
|
50
|
-
/** Props Definition */
|
|
51
|
-
props: {
|
|
52
|
-
/** Model value */
|
|
53
|
-
modelValue: {
|
|
54
|
-
type: String,
|
|
55
|
-
default: ""
|
|
56
|
-
},
|
|
57
|
-
/**
|
|
58
|
-
* Theme
|
|
59
|
-
*
|
|
60
|
-
* @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
|
|
61
|
-
*/
|
|
62
|
-
theme: {
|
|
63
|
-
type: Object,
|
|
64
|
-
default: () => {
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
/** Dark Mode */
|
|
68
|
-
dark: {
|
|
69
|
-
type: Boolean,
|
|
70
|
-
default: false
|
|
71
|
-
},
|
|
72
|
-
/**
|
|
73
|
-
* Use Basic Setup
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
|
|
76
|
-
*/
|
|
77
|
-
basic: {
|
|
78
|
-
type: Boolean,
|
|
79
|
-
default: false
|
|
80
|
-
},
|
|
81
|
-
/**
|
|
82
|
-
* Use Minimal Setup (The basic setting has priority.)
|
|
83
|
-
*
|
|
84
|
-
* @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
|
|
85
|
-
*/
|
|
86
|
-
minimal: {
|
|
87
|
-
type: Boolean,
|
|
88
|
-
default: false
|
|
89
|
-
},
|
|
90
|
-
/**
|
|
91
|
-
* Placeholder
|
|
92
|
-
*
|
|
93
|
-
* @see {@link https://codemirror.net/docs/ref/#view.placeholder}
|
|
94
|
-
*/
|
|
95
|
-
placeholder: {
|
|
96
|
-
type: String,
|
|
97
|
-
default: void 0
|
|
98
|
-
},
|
|
99
|
-
/**
|
|
100
|
-
* Line wrapping
|
|
101
|
-
*
|
|
102
|
-
* An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
|
|
103
|
-
*
|
|
104
|
-
* @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
|
|
105
|
-
*/
|
|
106
|
-
wrap: {
|
|
107
|
-
type: Boolean,
|
|
108
|
-
default: false
|
|
109
|
-
},
|
|
110
|
-
/**
|
|
111
|
-
* Allow tab key indent.
|
|
112
|
-
*
|
|
113
|
-
* @see {@link https://codemirror.net/examples/tab/}
|
|
114
|
-
*/
|
|
115
|
-
tab: {
|
|
116
|
-
type: Boolean,
|
|
117
|
-
default: false
|
|
118
|
-
},
|
|
119
|
-
/**
|
|
120
|
-
* Allow Multiple Selection.
|
|
121
|
-
*
|
|
122
|
-
* @see {@link https://codemirror.net/docs/ref/#state.EditorState^allowMultipleSelections}
|
|
123
|
-
*/
|
|
124
|
-
allowMultipleSelections: {
|
|
125
|
-
type: Boolean,
|
|
126
|
-
default: false
|
|
127
|
-
},
|
|
128
|
-
/**
|
|
129
|
-
* Tab size
|
|
130
|
-
*
|
|
131
|
-
* @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
|
|
132
|
-
*/
|
|
133
|
-
tabSize: {
|
|
134
|
-
type: Number,
|
|
135
|
-
default: void 0
|
|
136
|
-
},
|
|
137
|
-
/**
|
|
138
|
-
* Set line break (separetor) char.
|
|
139
|
-
*
|
|
140
|
-
* @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
|
|
141
|
-
*/
|
|
142
|
-
lineSeparator: {
|
|
143
|
-
type: String,
|
|
144
|
-
default: void 0
|
|
145
|
-
},
|
|
146
|
-
/**
|
|
147
|
-
* Readonly
|
|
148
|
-
*
|
|
149
|
-
* @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
|
|
150
|
-
*/
|
|
151
|
-
readonly: {
|
|
152
|
-
type: Boolean,
|
|
153
|
-
default: false
|
|
154
|
-
},
|
|
155
|
-
/**
|
|
156
|
-
* Disable input.
|
|
157
|
-
*
|
|
158
|
-
* This is the reversed value of the CodeMirror editable.
|
|
159
|
-
* Similar to `readonly`, but setting this value to true disables dragging.
|
|
160
|
-
*
|
|
161
|
-
* @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
|
|
162
|
-
*/
|
|
163
|
-
disabled: {
|
|
164
|
-
type: Boolean,
|
|
165
|
-
default: false
|
|
166
|
-
},
|
|
167
|
-
/**
|
|
168
|
-
* Additional Extension
|
|
169
|
-
*
|
|
170
|
-
* @see {@link https://codemirror.net/docs/ref/#state.Extension}
|
|
171
|
-
*/
|
|
172
|
-
extensions: {
|
|
173
|
-
type: Array,
|
|
174
|
-
default: () => {
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
/**
|
|
179
|
-
* Language Phreses
|
|
180
|
-
*
|
|
181
|
-
* @see {@link https://codemirror.net/examples/translate/}
|
|
182
|
-
*/
|
|
183
|
-
phrases: {
|
|
184
|
-
type: Object,
|
|
185
|
-
default: () => void 0
|
|
186
|
-
},
|
|
187
|
-
/**
|
|
188
|
-
* CodeMirror Language
|
|
189
|
-
*
|
|
190
|
-
* @see {@link https://codemirror.net/docs/ref/#language}
|
|
191
|
-
*/
|
|
192
|
-
lang: {
|
|
193
|
-
type: Object,
|
|
194
|
-
default: () => void 0
|
|
195
|
-
},
|
|
196
|
-
/**
|
|
197
|
-
* CodeMirror Linter
|
|
198
|
-
*
|
|
199
|
-
* @see {@link https://codemirror.net/docs/ref/#lint.linter}
|
|
200
|
-
*/
|
|
201
|
-
linter: {
|
|
202
|
-
type: Function,
|
|
203
|
-
default: void 0
|
|
204
|
-
},
|
|
205
|
-
/**
|
|
206
|
-
* Linter Config
|
|
207
|
-
*
|
|
208
|
-
* @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
|
|
209
|
-
*/
|
|
210
|
-
linterConfig: {
|
|
211
|
-
type: Object,
|
|
212
|
-
default: () => {
|
|
213
|
-
return { needsRefresh: true };
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
/**
|
|
217
|
-
* Forces any linters configured to run when the editor is idle to run right away.
|
|
218
|
-
*
|
|
219
|
-
* @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
|
|
220
|
-
*/
|
|
221
|
-
forceLinting: {
|
|
222
|
-
type: Boolean,
|
|
223
|
-
default: false
|
|
224
|
-
},
|
|
225
|
-
/**
|
|
226
|
-
* Show Linter Gutter
|
|
227
|
-
*
|
|
228
|
-
* An area to 🔴 the lines with errors will be displayed.
|
|
229
|
-
* This feature is not enabled if `linter` is not specified.
|
|
230
|
-
*
|
|
231
|
-
* @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
|
|
232
|
-
*/
|
|
233
|
-
gutter: {
|
|
234
|
-
type: Boolean,
|
|
235
|
-
defalt: false
|
|
236
|
-
},
|
|
237
|
-
/**
|
|
238
|
-
* Gutter Config
|
|
239
|
-
*
|
|
240
|
-
* @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
|
|
241
|
-
*/
|
|
242
|
-
gutterConfig: {
|
|
243
|
-
type: Object,
|
|
244
|
-
default: () => void 0
|
|
245
|
-
},
|
|
246
|
-
/**
|
|
247
|
-
* Using tag
|
|
248
|
-
*/
|
|
249
|
-
tag: {
|
|
250
|
-
type: String,
|
|
251
|
-
default: "div"
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
/** Emits */
|
|
255
|
-
emits: {
|
|
256
|
-
/** Model Update */
|
|
257
|
-
"update:modelValue": (value) => true,
|
|
258
|
-
/** CodeMirror ViewUpdate */
|
|
259
|
-
update: (value) => true,
|
|
260
|
-
/** CodeMirror onReady */
|
|
261
|
-
ready: (value) => true,
|
|
262
|
-
/** CodeMirror onFocus */
|
|
263
|
-
focus: (value) => true,
|
|
264
|
-
/** State Changed */
|
|
265
|
-
change: (value) => true,
|
|
266
|
-
/** CodeMirror onDestroy */
|
|
267
|
-
destroy: () => true
|
|
268
|
-
},
|
|
269
|
-
/**
|
|
270
|
-
* Setup
|
|
271
|
-
*
|
|
272
|
-
* @param props - Props
|
|
273
|
-
* @param context - Context
|
|
274
|
-
*/
|
|
275
|
-
setup(props, context) {
|
|
276
|
-
const editor = ref();
|
|
277
|
-
const doc = ref(props.modelValue);
|
|
278
|
-
const view = shallowRef(new EditorView());
|
|
279
|
-
const focus = computed({
|
|
280
|
-
get: () => view.value.hasFocus,
|
|
281
|
-
set: (f) => {
|
|
282
|
-
if (f) {
|
|
283
|
-
view.value.focus();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
const selection = computed({
|
|
288
|
-
get: () => view.value.state.selection,
|
|
289
|
-
set: (s) => view.value.dispatch({ selection: s })
|
|
290
|
-
});
|
|
291
|
-
const cursor = computed({
|
|
292
|
-
get: () => view.value.state.selection.main.head,
|
|
293
|
-
set: (a) => view.value.dispatch({ selection: { anchor: a } })
|
|
294
|
-
});
|
|
295
|
-
const json = computed(
|
|
296
|
-
{
|
|
297
|
-
get: () => view.value.state.toJSON(),
|
|
298
|
-
set: (j) => view.value.setState(EditorState.fromJSON(j))
|
|
299
|
-
}
|
|
300
|
-
);
|
|
301
|
-
const length = ref(0);
|
|
302
|
-
const diagnosticCount$1 = ref(0);
|
|
303
|
-
const extensions = computed(() => {
|
|
304
|
-
const language = new Compartment();
|
|
305
|
-
const tabSize = new Compartment();
|
|
306
|
-
return [
|
|
307
|
-
// Toggle basic setup
|
|
308
|
-
props.basic ? basicSetup : void 0,
|
|
309
|
-
// Toggle minimal setup
|
|
310
|
-
props.minimal && !props.basic ? minimalSetup : void 0,
|
|
311
|
-
// ViewUpdate event listener
|
|
312
|
-
EditorView.updateListener.of((update) => {
|
|
313
|
-
context.emit("focus", view.value.hasFocus);
|
|
314
|
-
length.value = view.value.state.doc.length;
|
|
315
|
-
if (update.changes.empty || !update.docChanged) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (props.linter) {
|
|
319
|
-
if (props.forceLinting) {
|
|
320
|
-
forceLinting(view.value);
|
|
321
|
-
}
|
|
322
|
-
diagnosticCount$1.value = props.linter(view.value).length;
|
|
323
|
-
}
|
|
324
|
-
context.emit("update", update);
|
|
325
|
-
}),
|
|
326
|
-
// Toggle light/dark mode.
|
|
327
|
-
EditorView.theme(props.theme, { dark: props.dark }),
|
|
328
|
-
// Toggle line wrapping
|
|
329
|
-
props.wrap ? EditorView.lineWrapping : void 0,
|
|
330
|
-
// Indent with tab
|
|
331
|
-
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
332
|
-
// Allow Multiple Selections
|
|
333
|
-
EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
|
|
334
|
-
// Indent tab size
|
|
335
|
-
props.tabSize ? tabSize.of(EditorState.tabSize.of(props.tabSize)) : void 0,
|
|
336
|
-
// locale settings
|
|
337
|
-
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
338
|
-
// Readonly option
|
|
339
|
-
EditorState.readOnly.of(props.readonly),
|
|
340
|
-
// Editable option
|
|
341
|
-
EditorView.editable.of(!props.disabled),
|
|
342
|
-
// Set Line break char
|
|
343
|
-
props.lineSeparator ? EditorState.lineSeparator.of(props.lineSeparator) : void 0,
|
|
344
|
-
// Lang
|
|
345
|
-
props.lang ? language.of(props.lang) : void 0,
|
|
346
|
-
// Append Linter settings
|
|
347
|
-
props.linter ? linter(props.linter, props.linterConfig) : void 0,
|
|
348
|
-
// Show 🔴 to error line when linter enabled.
|
|
349
|
-
props.linter && props.gutter ? lintGutter(props.gutterConfig) : void 0,
|
|
350
|
-
// Placeholder
|
|
351
|
-
props.placeholder ? placeholder(props.placeholder) : void 0,
|
|
352
|
-
// Append Extensions
|
|
353
|
-
...props.extensions
|
|
354
|
-
].filter((extension) => !!extension);
|
|
355
|
-
});
|
|
356
|
-
watch(
|
|
357
|
-
extensions,
|
|
358
|
-
(exts) => {
|
|
359
|
-
view.value?.dispatch({
|
|
360
|
-
effects: StateEffect.reconfigure.of(exts)
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
{ immediate: true }
|
|
364
|
-
);
|
|
365
|
-
watch(
|
|
366
|
-
() => props.modelValue,
|
|
367
|
-
async (value) => {
|
|
368
|
-
if (view.value.composing || // IME fix
|
|
369
|
-
view.value.state.doc.toJSON().join(props.lineSeparator ?? "\n") === value) {
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
view.value.dispatch({
|
|
373
|
-
changes: { from: 0, to: view.value.state.doc.length, insert: value },
|
|
374
|
-
selection: view.value.state.selection,
|
|
375
|
-
scrollIntoView: true
|
|
376
|
-
});
|
|
377
|
-
},
|
|
378
|
-
{ immediate: true }
|
|
379
|
-
);
|
|
380
|
-
onMounted(async () => {
|
|
381
|
-
let value = doc.value;
|
|
382
|
-
if (!editor.value) {
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
if (editor.value.childNodes[0]) {
|
|
386
|
-
if (doc.value !== "") {
|
|
387
|
-
console.warn(
|
|
388
|
-
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
value = editor.value.childNodes[0].innerText.trim();
|
|
392
|
-
}
|
|
393
|
-
view.value = new EditorView({
|
|
394
|
-
parent: editor.value,
|
|
395
|
-
state: EditorState.create({ doc: value, extensions: extensions.value }),
|
|
396
|
-
dispatch: (tr) => {
|
|
397
|
-
view.value.update([tr]);
|
|
398
|
-
if (tr.changes.empty || !tr.docChanged) {
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
context.emit("update:modelValue", tr.state.doc.toString());
|
|
402
|
-
context.emit("change", tr.state);
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
await nextTick();
|
|
406
|
-
context.emit("ready", {
|
|
407
|
-
view: view.value,
|
|
408
|
-
state: view.value.state,
|
|
409
|
-
container: editor.value
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
onUnmounted(() => {
|
|
413
|
-
view.value.destroy();
|
|
414
|
-
context.emit("destroy");
|
|
415
|
-
});
|
|
416
|
-
const lint = () => {
|
|
417
|
-
if (!props.linter || !view.value) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
if (props.forceLinting) {
|
|
421
|
-
forceLinting(view.value);
|
|
422
|
-
}
|
|
423
|
-
diagnosticCount$1.value = diagnosticCount(view.value.state);
|
|
424
|
-
};
|
|
425
|
-
const forceReconfigure = () => {
|
|
426
|
-
view.value?.dispatch({
|
|
427
|
-
effects: StateEffect.reconfigure.of([])
|
|
428
|
-
});
|
|
429
|
-
view.value?.dispatch({
|
|
430
|
-
effects: StateEffect.appendConfig.of(extensions.value)
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
const getRange = (from, to) => view.value.state.sliceDoc(from, to);
|
|
434
|
-
const getLine = (number) => view.value.state.doc.line(number + 1).text;
|
|
435
|
-
const lineCount = () => view.value.state.doc.lines;
|
|
436
|
-
const getCursor = () => view.value.state.selection.main.head;
|
|
437
|
-
const listSelections = () => {
|
|
438
|
-
let _view$value$state$sel;
|
|
439
|
-
return (_view$value$state$sel = view.value.state.selection.ranges) !== null && _view$value$state$sel !== void 0 ? _view$value$state$sel : [];
|
|
440
|
-
};
|
|
441
|
-
const getSelection = () => {
|
|
442
|
-
let _view$value$state$sli;
|
|
443
|
-
return (_view$value$state$sli = view.value.state.sliceDoc(
|
|
444
|
-
view.value.state.selection.main.from,
|
|
445
|
-
view.value.state.selection.main.to
|
|
446
|
-
)) !== null && _view$value$state$sli !== void 0 ? _view$value$state$sli : "";
|
|
447
|
-
};
|
|
448
|
-
const getSelections = () => {
|
|
449
|
-
const s = view.value.state;
|
|
450
|
-
if (!s) {
|
|
451
|
-
return [];
|
|
452
|
-
}
|
|
453
|
-
return s.selection.ranges.map(
|
|
454
|
-
(r) => s.sliceDoc(r.from, r.to)
|
|
455
|
-
);
|
|
456
|
-
};
|
|
457
|
-
const somethingSelected = () => view.value.state.selection.ranges.some(
|
|
458
|
-
(r) => !r.empty
|
|
459
|
-
);
|
|
460
|
-
const replaceRange = (replacement, from, to) => view.value.dispatch({
|
|
461
|
-
changes: { from, to, insert: replacement }
|
|
462
|
-
});
|
|
463
|
-
const replaceSelection = (replacement) => view.value.dispatch(view.value.state.replaceSelection(replacement));
|
|
464
|
-
const setCursor = (position) => view.value.dispatch({ selection: { anchor: position } });
|
|
465
|
-
const setSelection = (anchor, head) => view.value.dispatch({ selection: { anchor, head } });
|
|
466
|
-
const setSelections = (ranges, primary) => view.value.dispatch({
|
|
467
|
-
selection: EditorSelection.create(ranges, primary)
|
|
468
|
-
});
|
|
469
|
-
const extendSelectionsBy = (f) => view.value.dispatch({
|
|
470
|
-
selection: EditorSelection.create(
|
|
471
|
-
selection.value.ranges.map((r) => r.extend(f(r)))
|
|
472
|
-
)
|
|
473
|
-
});
|
|
474
|
-
const exposed = {
|
|
475
|
-
editor,
|
|
476
|
-
view,
|
|
477
|
-
cursor,
|
|
478
|
-
selection,
|
|
479
|
-
focus,
|
|
480
|
-
length,
|
|
481
|
-
json,
|
|
482
|
-
diagnosticCount: diagnosticCount$1,
|
|
483
|
-
dom: view.value.contentDOM,
|
|
484
|
-
lint,
|
|
485
|
-
forceReconfigure,
|
|
486
|
-
// Bellow is CodeMirror5's function
|
|
487
|
-
getRange,
|
|
488
|
-
getLine,
|
|
489
|
-
lineCount,
|
|
490
|
-
getCursor,
|
|
491
|
-
listSelections,
|
|
492
|
-
getSelection,
|
|
493
|
-
getSelections,
|
|
494
|
-
somethingSelected,
|
|
495
|
-
replaceRange,
|
|
496
|
-
replaceSelection,
|
|
497
|
-
setCursor,
|
|
498
|
-
setSelection,
|
|
499
|
-
setSelections,
|
|
500
|
-
extendSelectionsBy
|
|
501
|
-
};
|
|
502
|
-
context.expose(exposed);
|
|
503
|
-
return exposed;
|
|
504
|
-
},
|
|
505
|
-
render() {
|
|
506
|
-
return h(
|
|
507
|
-
this.$props.tag,
|
|
508
|
-
{
|
|
509
|
-
ref: "editor",
|
|
510
|
-
class: "vue-codemirror"
|
|
511
|
-
},
|
|
512
|
-
this.$slots.default ? (
|
|
513
|
-
// Hide original content
|
|
514
|
-
h(
|
|
515
|
-
"aside",
|
|
516
|
-
{ style: "display: none;", "aria-hidden": "true" },
|
|
517
|
-
slot(this.$slots.default)
|
|
518
|
-
)
|
|
519
|
-
) : void 0
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
const meta = {
|
|
525
|
-
version: "1.1.27",
|
|
526
|
-
date: "2023-09-01T16:38:44.335Z"
|
|
527
|
-
};
|
|
528
|
-
var meta$1 = meta;
|
|
529
|
-
|
|
530
|
-
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
531
|
-
|
|
532
|
-
export { meta$1 as Meta, CodeMirror as default, installCodeMirror as install };
|