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