vue-codemirror6 1.5.2 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +157 -150
- package/README.ja.md +3 -4
- package/README.md +3 -4
- package/dist/index.cjs +461 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +704 -689
- package/dist/index.es.js +407 -298
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +491 -4
- package/dist/index.umd.js.map +1 -0
- package/package.json +53 -77
- package/dist/index.cjs.js +0 -13
- package/dist/index.iife.js +0 -13
- package/dist/src/Meta.d.ts +0 -3
- package/dist/src/helpers/h-demi.d.ts +0 -15
- package/dist/src/index.d.ts +0 -705
- package/dist/src/interfaces/MetaInterface.d.ts +0 -8
package/dist/index.es.js
CHANGED
|
@@ -3,307 +3,416 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @description CodeMirror6 Component for vue2 and vue3.
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
-
* @copyright 2022-2026 By Masashi Yoshikawa All rights reserved.
|
|
7
6
|
* @license MIT
|
|
8
|
-
* @version 1.
|
|
7
|
+
* @version 1.6.1
|
|
9
8
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
|
-
import { indentWithTab
|
|
13
|
-
import { indentUnit
|
|
14
|
-
import { diagnosticCount as
|
|
15
|
-
import { Compartment
|
|
16
|
-
import { EditorView
|
|
17
|
-
import { basicSetup
|
|
18
|
-
import { computed
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
import { indentWithTab } from "@codemirror/commands";
|
|
12
|
+
import { indentUnit } from "@codemirror/language";
|
|
13
|
+
import { diagnosticCount as lint_diagnosticCount, forceLinting, lintGutter, linter } from "@codemirror/lint";
|
|
14
|
+
import { Compartment, EditorSelection, EditorState, StateEffect } from "@codemirror/state";
|
|
15
|
+
import { EditorView, keymap, placeholder } from "@codemirror/view";
|
|
16
|
+
import { basicSetup, minimalSetup } from "codemirror";
|
|
17
|
+
import { computed, defineComponent, h, isVue2, nextTick, onMounted, onUnmounted, ref, shallowRef, watch } from "vue-demi";
|
|
18
|
+
const Meta = {
|
|
19
|
+
version: "1.6.1",
|
|
20
|
+
date: "2026-07-03T10:18:25.379Z"
|
|
21
|
+
};
|
|
22
|
+
const src_Meta = Meta;
|
|
23
|
+
const adaptOnsV3 = (ons)=>{
|
|
24
|
+
if (!ons) return {};
|
|
25
|
+
return Object.entries(ons).reduce((ret, [key, handler])=>{
|
|
26
|
+
key = key.charAt(0).toUpperCase() + key.slice(1);
|
|
27
|
+
key = `on${key}`;
|
|
28
|
+
return {
|
|
29
|
+
...ret,
|
|
30
|
+
[key]: handler
|
|
31
|
+
};
|
|
32
|
+
}, {});
|
|
33
|
+
};
|
|
34
|
+
function h_demi_h(type, options = {}, children) {
|
|
35
|
+
if (isVue2) return h(type, options, children);
|
|
36
|
+
const { props, domProps, on, ...extraOptions } = options;
|
|
37
|
+
const ons = on ? adaptOnsV3(on) : {};
|
|
38
|
+
return h(type, {
|
|
39
|
+
...extraOptions,
|
|
40
|
+
...props,
|
|
41
|
+
...domProps,
|
|
42
|
+
...ons
|
|
43
|
+
}, children);
|
|
36
44
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
45
|
+
const slot = (defaultSlots)=>'function' == typeof defaultSlots ? defaultSlots() : defaultSlots ?? [];
|
|
46
|
+
const CodeMirror = defineComponent({
|
|
47
|
+
name: 'CodeMirror',
|
|
48
|
+
model: {
|
|
49
|
+
prop: 'modelValue',
|
|
50
|
+
event: 'update:modelValue'
|
|
51
|
+
},
|
|
52
|
+
props: {
|
|
53
|
+
modelValue: {
|
|
54
|
+
type: String,
|
|
55
|
+
default: ''
|
|
56
|
+
},
|
|
57
|
+
theme: {
|
|
58
|
+
type: Object,
|
|
59
|
+
default: ()=>({})
|
|
60
|
+
},
|
|
61
|
+
dark: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false
|
|
64
|
+
},
|
|
65
|
+
basic: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
default: false
|
|
68
|
+
},
|
|
69
|
+
minimal: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: false
|
|
72
|
+
},
|
|
73
|
+
placeholder: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: void 0
|
|
76
|
+
},
|
|
77
|
+
wrap: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: false
|
|
80
|
+
},
|
|
81
|
+
tab: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: false
|
|
84
|
+
},
|
|
85
|
+
indentUnit: {
|
|
86
|
+
type: String,
|
|
87
|
+
default: void 0
|
|
88
|
+
},
|
|
89
|
+
allowMultipleSelections: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: false
|
|
92
|
+
},
|
|
93
|
+
tabSize: {
|
|
94
|
+
type: Number,
|
|
95
|
+
default: void 0
|
|
96
|
+
},
|
|
97
|
+
lineSeparator: {
|
|
98
|
+
type: String,
|
|
99
|
+
default: void 0
|
|
100
|
+
},
|
|
101
|
+
readonly: {
|
|
102
|
+
type: Boolean,
|
|
103
|
+
default: false
|
|
104
|
+
},
|
|
105
|
+
disabled: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: false
|
|
108
|
+
},
|
|
109
|
+
extensions: {
|
|
110
|
+
type: Array,
|
|
111
|
+
default: ()=>[]
|
|
112
|
+
},
|
|
113
|
+
phrases: {
|
|
114
|
+
type: Object,
|
|
115
|
+
default: void 0
|
|
116
|
+
},
|
|
117
|
+
lang: {
|
|
118
|
+
type: Object,
|
|
119
|
+
default: void 0
|
|
120
|
+
},
|
|
121
|
+
linter: {
|
|
122
|
+
type: Function,
|
|
123
|
+
default: void 0
|
|
124
|
+
},
|
|
125
|
+
linterConfig: {
|
|
126
|
+
type: Object,
|
|
127
|
+
default: ()=>({})
|
|
128
|
+
},
|
|
129
|
+
forceLinting: {
|
|
130
|
+
type: Boolean,
|
|
131
|
+
default: false
|
|
132
|
+
},
|
|
133
|
+
gutter: {
|
|
134
|
+
type: Boolean,
|
|
135
|
+
default: false
|
|
136
|
+
},
|
|
137
|
+
gutterConfig: {
|
|
138
|
+
type: Object,
|
|
139
|
+
default: void 0
|
|
140
|
+
},
|
|
141
|
+
tag: {
|
|
142
|
+
type: String,
|
|
143
|
+
default: 'div'
|
|
144
|
+
},
|
|
145
|
+
scrollIntoView: {
|
|
146
|
+
type: Boolean,
|
|
147
|
+
default: true
|
|
148
|
+
},
|
|
149
|
+
preserveScrollPosition: {
|
|
150
|
+
type: Boolean,
|
|
151
|
+
default: false
|
|
152
|
+
},
|
|
153
|
+
keymap: {
|
|
154
|
+
type: Array,
|
|
155
|
+
default: ()=>[]
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
emits: {
|
|
159
|
+
'update:modelValue': (_value = '')=>true,
|
|
160
|
+
update: (_value)=>true,
|
|
161
|
+
ready: (_value)=>true,
|
|
162
|
+
focus: (_value)=>true,
|
|
163
|
+
change: (_value)=>true,
|
|
164
|
+
destroy: ()=>true
|
|
165
|
+
},
|
|
166
|
+
setup (props, context) {
|
|
167
|
+
const editor = ref();
|
|
168
|
+
const doc = ref(props.modelValue);
|
|
169
|
+
const view = shallowRef(void 0);
|
|
170
|
+
const focus = computed({
|
|
171
|
+
get: ()=>view.value?.hasFocus ?? false,
|
|
172
|
+
set: (f)=>{
|
|
173
|
+
if (f && view.value) view.value.focus();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const selection = computed({
|
|
177
|
+
get: ()=>view.value?.state.selection,
|
|
178
|
+
set: (selection)=>{
|
|
179
|
+
if (view.value && selection) view.value.dispatch({
|
|
180
|
+
selection
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const cursor = computed({
|
|
185
|
+
get: ()=>view.value?.state.selection.main.head ?? 0,
|
|
186
|
+
set: (anchor)=>{
|
|
187
|
+
if (view.value) view.value.dispatch({
|
|
188
|
+
selection: {
|
|
189
|
+
anchor
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const json = computed({
|
|
195
|
+
get: ()=>view.value?.state.toJSON(),
|
|
196
|
+
set: (j)=>{
|
|
197
|
+
if (view.value && j) view.value.setState(EditorState.fromJSON(j));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
const length = ref(0);
|
|
201
|
+
const diagnosticCount = ref(0);
|
|
202
|
+
const extensions = computed(()=>{
|
|
203
|
+
const language = new Compartment();
|
|
204
|
+
const tabSize = new Compartment();
|
|
205
|
+
if (props.basic && props.minimal) throw new Error('[Vue CodeMirror] Both basic and minimal cannot be specified.');
|
|
206
|
+
let keymaps = [];
|
|
207
|
+
if (props.keymap && props.keymap.length > 0) keymaps = props.keymap;
|
|
208
|
+
if (props.tab) keymaps.push(indentWithTab);
|
|
209
|
+
return [
|
|
210
|
+
props.basic && !props.minimal ? basicSetup : void 0,
|
|
211
|
+
props.minimal && !props.basic ? minimalSetup : void 0,
|
|
212
|
+
EditorView.updateListener.of((update)=>{
|
|
213
|
+
if (!view.value) return;
|
|
214
|
+
context.emit('focus', view.value.hasFocus);
|
|
215
|
+
length.value = view.value.state.doc?.length;
|
|
216
|
+
if (update.changes.empty || !update.docChanged) return;
|
|
217
|
+
if (props.linter) {
|
|
218
|
+
if (props.forceLinting) forceLinting(view.value);
|
|
219
|
+
diagnosticCount.value = props.linter(view.value).length;
|
|
220
|
+
}
|
|
221
|
+
context.emit('update', update);
|
|
222
|
+
}),
|
|
223
|
+
EditorView.theme(props.theme, {
|
|
224
|
+
dark: props.dark
|
|
225
|
+
}),
|
|
226
|
+
props.wrap ? EditorView.lineWrapping : void 0,
|
|
227
|
+
props.indentUnit ? indentUnit.of(props.indentUnit) : void 0,
|
|
228
|
+
EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
|
|
229
|
+
props.tabSize ? tabSize.of(EditorState.tabSize.of(props.tabSize)) : void 0,
|
|
230
|
+
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
231
|
+
EditorState.readOnly.of(props.readonly),
|
|
232
|
+
EditorView.editable.of(!props.disabled),
|
|
233
|
+
props.lineSeparator ? EditorState.lineSeparator.of(props.lineSeparator) : void 0,
|
|
234
|
+
props.lang ? language.of(props.lang) : void 0,
|
|
235
|
+
props.linter ? linter(props.linter, props.linterConfig) : void 0,
|
|
236
|
+
props.linter && props.gutter ? lintGutter(props.gutterConfig) : void 0,
|
|
237
|
+
props.placeholder ? placeholder(props.placeholder) : void 0,
|
|
238
|
+
keymaps.length > 0 ? keymap.of(keymaps) : void 0,
|
|
239
|
+
...props.extensions
|
|
240
|
+
].filter((extension)=>!!extension);
|
|
241
|
+
});
|
|
242
|
+
watch(extensions, (exts)=>view.value?.dispatch({
|
|
243
|
+
effects: StateEffect.reconfigure.of(exts)
|
|
244
|
+
}), {
|
|
245
|
+
immediate: true
|
|
246
|
+
});
|
|
247
|
+
watch(()=>props.modelValue, async (value)=>{
|
|
248
|
+
if (!view.value) return;
|
|
249
|
+
if (view.value.composing || view.value.state.doc.toJSON().join(props.lineSeparator ?? '\n') === value) return;
|
|
250
|
+
const isSelectionOutOfRange = !view.value.state.selection.ranges.every((range)=>range.anchor < value.length && range.head < value.length);
|
|
251
|
+
const changes = {
|
|
252
|
+
from: 0,
|
|
253
|
+
to: view.value.state.doc.length,
|
|
254
|
+
insert: value
|
|
255
|
+
};
|
|
256
|
+
const scrollSnapshot = props.preserveScrollPosition ? view.value.scrollSnapshot().map(view.value.state.changes(changes)) : void 0;
|
|
257
|
+
view.value.dispatch({
|
|
258
|
+
changes,
|
|
259
|
+
selection: isSelectionOutOfRange ? {
|
|
260
|
+
anchor: 0,
|
|
261
|
+
head: 0
|
|
262
|
+
} : view.value.state.selection,
|
|
263
|
+
scrollIntoView: props.scrollIntoView,
|
|
264
|
+
effects: scrollSnapshot ? [
|
|
265
|
+
scrollSnapshot
|
|
266
|
+
] : void 0
|
|
267
|
+
});
|
|
268
|
+
}, {
|
|
269
|
+
immediate: true
|
|
270
|
+
});
|
|
271
|
+
onMounted(async ()=>{
|
|
272
|
+
if (void 0 === globalThis.window || !editor.value) return;
|
|
273
|
+
let value = doc.value;
|
|
274
|
+
if (editor.value.childNodes[0]) {
|
|
275
|
+
if ('' !== doc.value) console.warn('[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.');
|
|
276
|
+
value = editor.value.childNodes[0].innerText.trim();
|
|
277
|
+
}
|
|
278
|
+
view.value = new EditorView({
|
|
279
|
+
parent: editor.value,
|
|
280
|
+
state: EditorState.create({
|
|
281
|
+
doc: value,
|
|
282
|
+
extensions: extensions.value
|
|
283
|
+
}),
|
|
284
|
+
dispatch: (tr)=>{
|
|
285
|
+
if (!view.value) return;
|
|
286
|
+
view.value.update([
|
|
287
|
+
tr
|
|
288
|
+
]);
|
|
289
|
+
if (tr.changes.empty || !tr.docChanged) return;
|
|
290
|
+
context.emit('update:modelValue', tr.state.doc.toString());
|
|
291
|
+
context.emit('change', tr.state);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
await nextTick();
|
|
295
|
+
context.emit('ready', {
|
|
296
|
+
view: view.value,
|
|
297
|
+
state: view.value.state,
|
|
298
|
+
container: editor.value
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
onUnmounted(()=>{
|
|
302
|
+
if (view.value) {
|
|
303
|
+
view.value.destroy();
|
|
304
|
+
context.emit('destroy');
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
const lint = ()=>{
|
|
308
|
+
if (!props.linter || !view.value) return;
|
|
309
|
+
if (props.forceLinting) forceLinting(view.value);
|
|
310
|
+
diagnosticCount.value = lint_diagnosticCount(view.value.state);
|
|
311
|
+
};
|
|
312
|
+
const forceReconfigure = ()=>{
|
|
313
|
+
view.value?.dispatch({
|
|
314
|
+
effects: StateEffect.reconfigure.of([])
|
|
315
|
+
});
|
|
316
|
+
view.value?.dispatch({
|
|
317
|
+
effects: StateEffect.appendConfig.of(extensions.value)
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
const getRange = (from, to)=>view.value?.state.sliceDoc(from, to);
|
|
321
|
+
const getLine = (number)=>view.value?.state.doc.line(number + 1).text;
|
|
322
|
+
const lineCount = ()=>view.value?.state.doc.lines ?? 0;
|
|
323
|
+
const getCursor = ()=>view.value?.state.selection.main.head ?? 0;
|
|
324
|
+
const listSelections = ()=>view.value?.state.selection.ranges ?? [];
|
|
325
|
+
const getSelection = ()=>{
|
|
326
|
+
if (!view.value) return '';
|
|
327
|
+
return view.value.state.sliceDoc(view.value.state.selection.main.from, view.value.state.selection.main.to);
|
|
328
|
+
};
|
|
329
|
+
const getSelections = ()=>{
|
|
330
|
+
const s = view.value?.state;
|
|
331
|
+
if (!s) return [];
|
|
332
|
+
return s.selection.ranges.map((r)=>s.sliceDoc(r.from, r.to));
|
|
333
|
+
};
|
|
334
|
+
const somethingSelected = ()=>view.value?.state.selection.ranges.some((r)=>!r.empty) ?? false;
|
|
335
|
+
const replaceRange = (replacement, from, to)=>{
|
|
336
|
+
if (view.value) view.value.dispatch({
|
|
337
|
+
changes: {
|
|
338
|
+
from,
|
|
339
|
+
to,
|
|
340
|
+
insert: replacement
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
const replaceSelection = (replacement)=>{
|
|
345
|
+
if (view.value) view.value.dispatch(view.value.state.replaceSelection(replacement));
|
|
346
|
+
};
|
|
347
|
+
const setCursor = (position)=>{
|
|
348
|
+
if (view.value) view.value.dispatch({
|
|
349
|
+
selection: {
|
|
350
|
+
anchor: position
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
const setSelection = (anchor, head)=>{
|
|
355
|
+
if (view.value) view.value.dispatch({
|
|
356
|
+
selection: {
|
|
357
|
+
anchor,
|
|
358
|
+
head
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
const setSelections = (ranges, primary)=>{
|
|
363
|
+
if (view.value) view.value.dispatch({
|
|
364
|
+
selection: EditorSelection.create(ranges, primary)
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
const extendSelectionsBy = (f)=>{
|
|
368
|
+
if (view.value && selection.value) view.value.dispatch({
|
|
369
|
+
selection: EditorSelection.create(selection.value.ranges.map((r)=>r.extend(f(r))))
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
const exposed = {
|
|
373
|
+
editor,
|
|
374
|
+
view,
|
|
375
|
+
cursor,
|
|
376
|
+
selection,
|
|
377
|
+
focus,
|
|
378
|
+
length,
|
|
379
|
+
json,
|
|
380
|
+
diagnosticCount,
|
|
381
|
+
dom: view.value?.contentDOM,
|
|
382
|
+
lint,
|
|
383
|
+
forceReconfigure,
|
|
384
|
+
getRange,
|
|
385
|
+
getLine,
|
|
386
|
+
lineCount,
|
|
387
|
+
getCursor,
|
|
388
|
+
listSelections,
|
|
389
|
+
getSelection,
|
|
390
|
+
getSelections,
|
|
391
|
+
somethingSelected,
|
|
392
|
+
replaceRange,
|
|
393
|
+
replaceSelection,
|
|
394
|
+
setCursor,
|
|
395
|
+
setSelection,
|
|
396
|
+
setSelections,
|
|
397
|
+
extendSelectionsBy
|
|
398
|
+
};
|
|
399
|
+
context.expose(exposed);
|
|
400
|
+
return exposed;
|
|
401
|
+
},
|
|
402
|
+
render () {
|
|
403
|
+
return h_demi_h(this.$props.tag, {
|
|
404
|
+
ref: 'editor',
|
|
405
|
+
class: 'vue-codemirror'
|
|
406
|
+
}, this.$slots.default ? h_demi_h('aside', {
|
|
407
|
+
style: 'display: none;',
|
|
408
|
+
'aria-hidden': 'true'
|
|
409
|
+
}, slot(this.$slots.default)) : void 0);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
const installCodeMirror = (app)=>{
|
|
413
|
+
app.component('CodeMirror', CodeMirror);
|
|
307
414
|
};
|
|
308
|
-
|
|
309
|
-
export {
|
|
415
|
+
export default CodeMirror;
|
|
416
|
+
export { installCodeMirror as install, src_Meta as Meta };
|
|
417
|
+
|
|
418
|
+
//# sourceMappingURL=index.es.js.map
|