vue-codemirror6 1.4.2 → 1.5.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
@@ -5,539 +5,303 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2026 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.4.2
8
+ * @version 1.5.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- import { indentWithTab as W } from "@codemirror/commands";
13
- import { indentUnit as G } from "@codemirror/language";
14
- import { forceLinting as w, linter as P, lintGutter as Z, diagnosticCount as q } from "@codemirror/lint";
15
- import { EditorState as u, Compartment as C, StateEffect as S, EditorSelection as O } from "@codemirror/state";
16
- import { EditorView as d, placeholder as H, keymap as K } from "@codemirror/view";
17
- import { basicSetup as Q, minimalSetup as X } from "codemirror";
18
- import { isVue2 as Y, h as V, defineComponent as ee, ref as m, shallowRef as te, computed as f, watch as B, onMounted as ae, nextTick as ne, onUnmounted as ie } from "vue-demi";
19
- const he = {
20
- version: "1.4.2",
21
- date: "2026-02-17T01:27:59.529Z"
22
- }, le = (t) => t ? Object.entries(t).reduce((l, [i, s]) => (i = i.charAt(0).toUpperCase() + i.slice(1), i = `on${i}`, { ...l, [i]: s }), {}) : {};
23
- function M(t, l = {}, i) {
24
- if (Y)
25
- return V(t, l, i);
26
- const { props: s, domProps: e, on: v, ...r } = l, h = v ? le(v) : {};
27
- return V(
28
- t,
29
- { ...r, ...s, ...e, ...h },
30
- i
31
- );
12
+ import { indentWithTab as e } from "@codemirror/commands";
13
+ import { indentUnit as t } from "@codemirror/language";
14
+ import { diagnosticCount as n, forceLinting as r, lintGutter as i, linter as a } from "@codemirror/lint";
15
+ import { Compartment as o, EditorSelection as s, EditorState as c, StateEffect as l } from "@codemirror/state";
16
+ import { EditorView as u, keymap as d, placeholder as f } from "@codemirror/view";
17
+ import { basicSetup as p, minimalSetup as m } from "codemirror";
18
+ import { computed as h, defineComponent as g, h as _, isVue2 as v, nextTick as y, onMounted as b, onUnmounted as x, ref as S, shallowRef as C, watch as w } from "vue-demi";
19
+ //#region src/Meta.ts
20
+ var T = {
21
+ version: "1.5.0",
22
+ date: "2026-03-30T11:56:36.326Z"
23
+ }, E = (e) => e ? Object.entries(e).reduce((e, [t, n]) => (t = t.charAt(0).toUpperCase() + t.slice(1), t = `on${t}`, {
24
+ ...e,
25
+ [t]: n
26
+ }), {}) : {};
27
+ function D(e, t = {}, n) {
28
+ if (v) return _(e, t, n);
29
+ let { props: r, domProps: i, on: a, ...o } = t, s = a ? E(a) : {};
30
+ return _(e, {
31
+ ...o,
32
+ ...r,
33
+ ...i,
34
+ ...s
35
+ }, n);
32
36
  }
33
- const oe = (t) => typeof t == "function" ? t() : t, ue = ee({
34
- /** Component Name */
35
- name: "CodeMirror",
36
- /** Model Definition */
37
- model: {
38
- prop: "modelValue",
39
- event: "update:modelValue"
40
- },
41
- /** Props Definition */
42
- props: {
43
- /** Model value */
44
- modelValue: {
45
- type: String,
46
- default: ""
47
- },
48
- /**
49
- * Theme
50
- *
51
- * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
52
- */
53
- theme: {
54
- type: Object,
55
- default: () => ({})
56
- },
57
- /** Dark Mode */
58
- dark: {
59
- type: Boolean,
60
- default: !1
61
- },
62
- /**
63
- * Use Basic Setup
64
- *
65
- * This will enable the basic setup for the editor.
66
- *
67
- * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
68
- */
69
- basic: {
70
- type: Boolean,
71
- default: !1
72
- },
73
- /**
74
- * Use Minimal Setup (The basic setting has priority.)
75
- *
76
- * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
77
- */
78
- minimal: {
79
- type: Boolean,
80
- default: !1
81
- },
82
- /**
83
- * Placeholder
84
- *
85
- * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
86
- */
87
- placeholder: {
88
- type: String,
89
- default: void 0
90
- },
91
- /**
92
- * Line wrapping
93
- *
94
- * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
95
- *
96
- * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
97
- */
98
- wrap: {
99
- type: Boolean,
100
- default: !1
101
- },
102
- /**
103
- * Allow tab key indent.
104
- *
105
- * This will enable the tab key to indent the current line or selection.
106
- *
107
- * @see {@link https://codemirror.net/examples/tab/}
108
- */
109
- tab: {
110
- type: Boolean,
111
- default: !1
112
- },
113
- /**
114
- * Tab character
115
- *
116
- * This is the unit of indentation used when the editor is configured to indent with tabs.
117
- * It is also used to determine the size of the tab character when the editor is configured to use tabs for indentation..
118
- *
119
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^indentUnit}
120
- */
121
- indentUnit: {
122
- type: String,
123
- default: void 0
124
- },
125
- /**
126
- * Allow Multiple Selection.
127
- *
128
- * This allows the editor to have multiple selections at the same time.
129
- * This is useful for editing multiple parts of the document at once.
130
- * If this is set to true, the editor will allow multiple selections.
131
- * If this is set to false, the editor will only allow a single selection.
132
- *
133
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^allowMultipleSelections}
134
- */
135
- allowMultipleSelections: {
136
- type: Boolean,
137
- default: !1
138
- },
139
- /**
140
- * Tab size
141
- *
142
- * This is the number of spaces that a tab character represents in the editor.
143
- * It is used to determine the size of the tab character when the editor is configured to use tabs for indentation.
144
- * If this is set to a number, the editor will use that number of spaces for each tab character.
145
- *
146
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
147
- */
148
- tabSize: {
149
- type: Number,
150
- default: void 0
151
- },
152
- /**
153
- * Set line break (separetor) char.
154
- *
155
- * This is the character that is used to separate lines in the editor.
156
- * It is used to determine the line break character when the editor is configured to use a specific line break character.
157
- *
158
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
159
- */
160
- lineSeparator: {
161
- type: String,
162
- default: void 0
163
- },
164
- /**
165
- * Readonly
166
- *
167
- * This is a CodeMirror Facet that allows you to set the editor to read-only mode.
168
- * When this is set to true, the editor will not allow any changes to be made to the document.
169
- * This is useful for displaying code that should not be edited, such as documentation or examples.
170
- * If this is set to false, the editor will allow changes to be made to the document.
171
- *
172
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
173
- */
174
- readonly: {
175
- type: Boolean,
176
- default: !1
177
- },
178
- /**
179
- * Disable input.
180
- *
181
- * This is the reversed value of the CodeMirror editable.
182
- * Similar to `readonly`, but setting this value to true disables dragging.
183
- *
184
- * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
185
- */
186
- disabled: {
187
- type: Boolean,
188
- default: !1
189
- },
190
- /**
191
- * Additional Extension
192
- *
193
- * You can use this to add any additional extensions that you want to use in the editor.
194
- *
195
- * @see {@link https://codemirror.net/docs/ref/#state.Extension}
196
- */
197
- extensions: {
198
- type: Array,
199
- default: () => []
200
- },
201
- /**
202
- * Language Phreses
203
- *
204
- * This is a CodeMirror Facet that allows you to define custom phrases for the editor.
205
- * It can be used to override default phrases or add new ones.
206
- * This is useful for translating the editor to different languages or for customizing the editor's UI.
207
- *
208
- * @see {@link https://codemirror.net/examples/translate/}
209
- */
210
- phrases: {
211
- type: Object,
212
- default: void 0
213
- },
214
- /**
215
- * CodeMirror Language
216
- *
217
- * This is a CodeMirror Facet that allows you to define the language of the editor.
218
- * It can be used to enable syntax highlighting and other language-specific features.
219
- * It is useful for displaying code in a specific language, such as JavaScript, Python, or HTML.
220
- *
221
- * @see {@link https://codemirror.net/docs/ref/#language}
222
- */
223
- lang: {
224
- type: Object,
225
- default: void 0
226
- },
227
- /**
228
- * CodeMirror Linter
229
- *
230
- * This is a CodeMirror Facet that allows you to define a linter for the editor.
231
- * It can be used to check the code for errors and warnings, and to provide feedback to the user.
232
- * It is useful for displaying code in a specific language, such as JavaScript, Python, or HTML.
233
- * This is useful for providing feedback to the user about the code they are writing.
234
- *
235
- * @see {@link https://codemirror.net/docs/ref/#lint.linter}
236
- */
237
- linter: {
238
- type: Function,
239
- default: void 0
240
- },
241
- /**
242
- * Linter Config
243
- *
244
- * This is a CodeMirror Facet that allows you to define the configuration for the linter.
245
- * It can be used to specify options for the linter, such as the severity of errors and warnings, and to customize the behavior of the linter.
246
- * This is useful for providing feedback to the user about the code they are writing.
247
- *
248
- * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
249
- */
250
- linterConfig: {
251
- type: Object,
252
- default: () => ({})
253
- },
254
- /**
255
- * Forces any linters configured to run when the editor is idle to run right away.
256
- *
257
- * This is useful for running linters on the initial load of the editor, or when the user has made changes to the code and wants to see the results immediately.
258
- *
259
- * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
260
- */
261
- forceLinting: {
262
- type: Boolean,
263
- default: !1
264
- },
265
- /**
266
- * Show Linter Gutter
267
- *
268
- * An area to 🔴 the lines with errors will be displayed.
269
- * This feature is not enabled if `linter` is not specified.
270
- *
271
- * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
272
- */
273
- gutter: {
274
- type: Boolean,
275
- default: !1
276
- },
277
- /**
278
- * Gutter Config
279
- *
280
- * This is a CodeMirror Facet that allows you to define the configuration for the gutter.
281
- * It can be used to specify options for the gutter, such as the size of the gutter, the position of the gutter, and to customize the behavior of the gutter.
282
- * This is useful for providing feedback to the user about the code they are writing.
283
- *
284
- * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
285
- */
286
- gutterConfig: {
287
- type: Object,
288
- default: void 0
289
- },
290
- /**
291
- * Using tag
292
- */
293
- tag: {
294
- type: String,
295
- default: "div"
296
- },
297
- /**
298
- * Allows an external update to scroll the form.
299
- *
300
- * This is useful for scrolling the editor to a specific position when the user has made changes to the code and wants to see the results immediately.
301
- * If this is set to true, the editor will scroll to the position specified in the transaction.
302
- * If this is set to false, the editor will not scroll to the position specified in the transaction.
303
- *
304
- * @see {@link https://codemirror.net/docs/ref/#state.TransactionSpec.scrollIntoView}
305
- */
306
- scrollIntoView: {
307
- type: Boolean,
308
- default: !0
309
- },
310
- /**
311
- * Key map
312
- * This is a CodeMirror Facet that allows you to define custom key bindings.
313
- * It can be used to override default key bindings or add new ones.
314
- *
315
- * @see {@link https://codemirror.net/docs/ref/#view.keymap}
316
- */
317
- keymap: {
318
- type: Array,
319
- default: () => []
320
- }
321
- },
322
- /** Emits */
323
- emits: {
324
- /** Model Update */
325
- "update:modelValue": (t = "") => !0,
326
- /** CodeMirror ViewUpdate */
327
- update: (t) => !0,
328
- /** CodeMirror onReady */
329
- ready: (t) => !0,
330
- /** CodeMirror onFocus */
331
- focus: (t) => !0,
332
- /** State Changed */
333
- change: (t) => !0,
334
- /** CodeMirror onDestroy */
335
- destroy: () => !0
336
- },
337
- /**
338
- * Setup
339
- *
340
- * @param props - Props
341
- * @param context - Context
342
- */
343
- setup(t, l) {
344
- const i = m(), s = m(t.modelValue), e = te(void 0), v = f({
345
- get: () => e.value?.hasFocus ?? !1,
346
- set: (a) => {
347
- a && e.value && e.value.focus();
348
- }
349
- }), r = f({
350
- get: () => e.value?.state.selection,
351
- set: (a) => {
352
- e.value && a && e.value.dispatch({ selection: a });
353
- }
354
- }), h = f({
355
- get: () => e.value?.state.selection.main.head ?? 0,
356
- set: (a) => {
357
- e.value && e.value.dispatch({ selection: { anchor: a } });
358
- }
359
- }), j = f({
360
- get: () => e.value?.state.toJSON(),
361
- set: (a) => {
362
- e.value && a && e.value.setState(u.fromJSON(a));
363
- }
364
- }), p = m(0), g = m(0), y = f(() => {
365
- const a = new C(), n = new C();
366
- if (t.basic && t.minimal)
367
- throw new Error(
368
- "[Vue CodeMirror] Both basic and minimal cannot be specified."
369
- );
370
- let o = [];
371
- return t.keymap && t.keymap.length > 0 && (o = t.keymap), t.tab && o.push(W), [
372
- // Toggle basic setup
373
- t.basic && !t.minimal ? Q : void 0,
374
- // Toggle minimal setup
375
- t.minimal && !t.basic ? X : void 0,
376
- // ViewUpdate event listener
377
- d.updateListener.of((c) => {
378
- e.value && (l.emit("focus", e.value.hasFocus), p.value = e.value.state.doc?.length, !(c.changes.empty || !c.docChanged) && (t.linter && (t.forceLinting && w(e.value), g.value = t.linter(e.value).length), l.emit("update", c)));
379
- }),
380
- // Toggle light/dark mode.
381
- d.theme(t.theme, { dark: t.dark }),
382
- // Toggle line wrapping
383
- t.wrap ? d.lineWrapping : void 0,
384
- // Tab character
385
- t.indentUnit ? G.of(t.indentUnit) : void 0,
386
- // Allow Multiple Selections
387
- u.allowMultipleSelections.of(t.allowMultipleSelections),
388
- // Indent tab size
389
- t.tabSize ? n.of(u.tabSize.of(t.tabSize)) : void 0,
390
- // locale settings
391
- t.phrases ? u.phrases.of(t.phrases) : void 0,
392
- // Readonly option
393
- u.readOnly.of(t.readonly),
394
- // Editable option
395
- d.editable.of(!t.disabled),
396
- // Set Line break char
397
- t.lineSeparator ? u.lineSeparator.of(t.lineSeparator) : void 0,
398
- // Lang
399
- t.lang ? a.of(t.lang) : void 0,
400
- // Append Linter settings
401
- t.linter ? P(t.linter, t.linterConfig) : void 0,
402
- // Show 🔴 to error line when linter enabled.
403
- t.linter && t.gutter ? Z(t.gutterConfig) : void 0,
404
- // Placeholder
405
- t.placeholder ? H(t.placeholder) : void 0,
406
- // Keymap and Indent with Tab
407
- o.length > 0 ? K.of(o) : void 0,
408
- // Append Extensions
409
- ...t.extensions
410
- ].filter((c) => !!c);
411
- });
412
- B(
413
- y,
414
- (a) => e.value?.dispatch({ effects: S.reconfigure.of(a) }),
415
- { immediate: !0 }
416
- ), B(
417
- () => t.modelValue,
418
- async (a) => {
419
- if (!e.value || e.value.composing || // IME fix
420
- e.value.state.doc.toJSON().join(t.lineSeparator ?? `
421
- `) === a)
422
- return;
423
- const n = !e.value.state.selection.ranges.every(
424
- (o) => o.anchor < a.length && o.head < a.length
425
- );
426
- e.value.dispatch({
427
- changes: { from: 0, to: e.value.state.doc.length, insert: a },
428
- selection: n ? { anchor: 0, head: 0 } : e.value.state.selection,
429
- scrollIntoView: t.scrollIntoView
430
- });
431
- },
432
- { immediate: !0 }
433
- ), ae(async () => {
434
- if (globalThis.window === void 0 || !i.value)
435
- return;
436
- let a = s.value;
437
- i.value.childNodes[0] && (s.value !== "" && console.warn(
438
- "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
439
- ), a = i.value.childNodes[0].innerText.trim()), e.value = new d({
440
- parent: i.value,
441
- state: u.create({ doc: a, extensions: y.value }),
442
- dispatch: (n) => {
443
- e.value && (e.value.update([n]), !(n.changes.empty || !n.docChanged) && (l.emit("update:modelValue", n.state.doc.toString()), l.emit("change", n.state)));
444
- }
445
- }), await ne(), l.emit("ready", {
446
- view: e.value,
447
- state: e.value.state,
448
- container: i.value
449
- });
450
- }), ie(() => {
451
- e.value && (e.value.destroy(), l.emit("destroy"));
452
- });
453
- const x = () => {
454
- !t.linter || !e.value || (t.forceLinting && w(e.value), g.value = q(e.value.state));
455
- }, L = () => {
456
- e.value?.dispatch({
457
- effects: S.reconfigure.of([])
458
- }), e.value?.dispatch({
459
- effects: S.appendConfig.of(y.value)
460
- });
461
- }, N = (a, n) => e.value?.state.sliceDoc(a, n), T = (a) => e.value?.state.doc.line(a + 1).text, U = () => e.value?.state.doc.lines ?? 0, $ = () => e.value?.state.selection.main.head ?? 0, k = () => e.value?.state.selection.ranges ?? [], z = () => e.value ? e.value.state.sliceDoc(
462
- e.value.state.selection.main.from,
463
- e.value.state.selection.main.to
464
- ) : "", E = () => {
465
- const a = e.value?.state;
466
- return a ? a.selection.ranges.map(
467
- (n) => a.sliceDoc(n.from, n.to)
468
- ) : [];
469
- }, R = () => e.value?.state.selection.ranges.some(
470
- (a) => !a.empty
471
- ) ?? !1, _ = (a, n, o) => {
472
- e.value && e.value.dispatch({
473
- changes: { from: n, to: o, insert: a }
474
- });
475
- }, D = (a) => {
476
- e.value && e.value.dispatch(e.value.state.replaceSelection(a));
477
- }, A = (a) => {
478
- e.value && e.value.dispatch({ selection: { anchor: a } });
479
- }, F = (a, n) => {
480
- e.value && e.value.dispatch({ selection: { anchor: a, head: n } });
481
- }, I = (a, n) => {
482
- e.value && e.value.dispatch({
483
- selection: O.create(a, n)
484
- });
485
- }, J = (a) => {
486
- e.value && r.value && e.value.dispatch({
487
- selection: O.create(
488
- r.value.ranges.map((n) => n.extend(a(n)))
489
- )
490
- });
491
- }, b = {
492
- editor: i,
493
- view: e,
494
- cursor: h,
495
- selection: r,
496
- focus: v,
497
- length: p,
498
- json: j,
499
- diagnosticCount: g,
500
- dom: e.value?.contentDOM,
501
- lint: x,
502
- forceReconfigure: L,
503
- // Bellow is CodeMirror5's function
504
- getRange: N,
505
- getLine: T,
506
- lineCount: U,
507
- getCursor: $,
508
- listSelections: k,
509
- getSelection: z,
510
- getSelections: E,
511
- somethingSelected: R,
512
- replaceRange: _,
513
- replaceSelection: D,
514
- setCursor: A,
515
- setSelection: F,
516
- setSelections: I,
517
- extendSelectionsBy: J
518
- };
519
- return l.expose(b), b;
520
- },
521
- render() {
522
- return M(
523
- this.$props.tag,
524
- {
525
- ref: "editor",
526
- class: "vue-codemirror"
527
- },
528
- this.$slots.default ? (
529
- // Hide original content
530
- M(
531
- "aside",
532
- { style: "display: none;", "aria-hidden": "true" },
533
- oe(this.$slots.default)
534
- )
535
- ) : void 0
536
- );
537
- }
538
- }), ge = (t) => t.component("CodeMirror", ue);
539
- export {
540
- he as Meta,
541
- ue as default,
542
- ge as install
543
- };
37
+ var O = (e) => typeof e == "function" ? e() : e, k = g({
38
+ name: "CodeMirror",
39
+ model: {
40
+ prop: "modelValue",
41
+ event: "update:modelValue"
42
+ },
43
+ props: {
44
+ modelValue: {
45
+ type: String,
46
+ default: ""
47
+ },
48
+ theme: {
49
+ type: Object,
50
+ default: () => ({})
51
+ },
52
+ dark: {
53
+ type: Boolean,
54
+ default: !1
55
+ },
56
+ basic: {
57
+ type: Boolean,
58
+ default: !1
59
+ },
60
+ minimal: {
61
+ type: Boolean,
62
+ default: !1
63
+ },
64
+ placeholder: {
65
+ type: String,
66
+ default: void 0
67
+ },
68
+ wrap: {
69
+ type: Boolean,
70
+ default: !1
71
+ },
72
+ tab: {
73
+ type: Boolean,
74
+ default: !1
75
+ },
76
+ indentUnit: {
77
+ type: String,
78
+ default: void 0
79
+ },
80
+ allowMultipleSelections: {
81
+ type: Boolean,
82
+ default: !1
83
+ },
84
+ tabSize: {
85
+ type: Number,
86
+ default: void 0
87
+ },
88
+ lineSeparator: {
89
+ type: String,
90
+ default: void 0
91
+ },
92
+ readonly: {
93
+ type: Boolean,
94
+ default: !1
95
+ },
96
+ disabled: {
97
+ type: Boolean,
98
+ default: !1
99
+ },
100
+ extensions: {
101
+ type: Array,
102
+ default: () => []
103
+ },
104
+ phrases: {
105
+ type: Object,
106
+ default: void 0
107
+ },
108
+ lang: {
109
+ type: Object,
110
+ default: void 0
111
+ },
112
+ linter: {
113
+ type: Function,
114
+ default: void 0
115
+ },
116
+ linterConfig: {
117
+ type: Object,
118
+ default: () => ({})
119
+ },
120
+ forceLinting: {
121
+ type: Boolean,
122
+ default: !1
123
+ },
124
+ gutter: {
125
+ type: Boolean,
126
+ default: !1
127
+ },
128
+ gutterConfig: {
129
+ type: Object,
130
+ default: void 0
131
+ },
132
+ tag: {
133
+ type: String,
134
+ default: "div"
135
+ },
136
+ scrollIntoView: {
137
+ type: Boolean,
138
+ default: !0
139
+ },
140
+ preserveScrollPosition: {
141
+ type: Boolean,
142
+ default: !1
143
+ },
144
+ keymap: {
145
+ type: Array,
146
+ default: () => []
147
+ }
148
+ },
149
+ emits: {
150
+ "update:modelValue": (e = "") => !0,
151
+ update: (e) => !0,
152
+ ready: (e) => !0,
153
+ focus: (e) => !0,
154
+ change: (e) => !0,
155
+ destroy: () => !0
156
+ },
157
+ setup(g, _) {
158
+ let v = S(), T = S(g.modelValue), E = C(void 0), D = h({
159
+ get: () => E.value?.hasFocus ?? !1,
160
+ set: (e) => {
161
+ e && E.value && E.value.focus();
162
+ }
163
+ }), O = h({
164
+ get: () => E.value?.state.selection,
165
+ set: (e) => {
166
+ E.value && e && E.value.dispatch({ selection: e });
167
+ }
168
+ }), k = h({
169
+ get: () => E.value?.state.selection.main.head ?? 0,
170
+ set: (e) => {
171
+ E.value && E.value.dispatch({ selection: { anchor: e } });
172
+ }
173
+ }), A = h({
174
+ get: () => E.value?.state.toJSON(),
175
+ set: (e) => {
176
+ E.value && e && E.value.setState(c.fromJSON(e));
177
+ }
178
+ }), j = S(0), M = S(0), N = h(() => {
179
+ let n = new o(), s = new o();
180
+ if (g.basic && g.minimal) throw Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");
181
+ let l = [];
182
+ return g.keymap && g.keymap.length > 0 && (l = g.keymap), g.tab && l.push(e), [
183
+ g.basic && !g.minimal ? p : void 0,
184
+ g.minimal && !g.basic ? m : void 0,
185
+ u.updateListener.of((e) => {
186
+ E.value && (_.emit("focus", E.value.hasFocus), j.value = E.value.state.doc?.length, !(e.changes.empty || !e.docChanged) && (g.linter && (g.forceLinting && r(E.value), M.value = g.linter(E.value).length), _.emit("update", e)));
187
+ }),
188
+ u.theme(g.theme, { dark: g.dark }),
189
+ g.wrap ? u.lineWrapping : void 0,
190
+ g.indentUnit ? t.of(g.indentUnit) : void 0,
191
+ c.allowMultipleSelections.of(g.allowMultipleSelections),
192
+ g.tabSize ? s.of(c.tabSize.of(g.tabSize)) : void 0,
193
+ g.phrases ? c.phrases.of(g.phrases) : void 0,
194
+ c.readOnly.of(g.readonly),
195
+ u.editable.of(!g.disabled),
196
+ g.lineSeparator ? c.lineSeparator.of(g.lineSeparator) : void 0,
197
+ g.lang ? n.of(g.lang) : void 0,
198
+ g.linter ? a(g.linter, g.linterConfig) : void 0,
199
+ g.linter && g.gutter ? i(g.gutterConfig) : void 0,
200
+ g.placeholder ? f(g.placeholder) : void 0,
201
+ l.length > 0 ? d.of(l) : void 0,
202
+ ...g.extensions
203
+ ].filter((e) => !!e);
204
+ });
205
+ w(N, (e) => E.value?.dispatch({ effects: l.reconfigure.of(e) }), { immediate: !0 }), w(() => g.modelValue, async (e) => {
206
+ if (!E.value || E.value.composing || E.value.state.doc.toJSON().join(g.lineSeparator ?? "\n") === e) return;
207
+ let t = !E.value.state.selection.ranges.every((t) => t.anchor < e.length && t.head < e.length), n = {
208
+ from: 0,
209
+ to: E.value.state.doc.length,
210
+ insert: e
211
+ }, r = g.preserveScrollPosition ? E.value.scrollSnapshot().map(E.value.state.changes(n)) : void 0;
212
+ E.value.dispatch({
213
+ changes: n,
214
+ selection: t ? {
215
+ anchor: 0,
216
+ head: 0
217
+ } : E.value.state.selection,
218
+ scrollIntoView: g.scrollIntoView,
219
+ effects: r ? [r] : void 0
220
+ });
221
+ }, { immediate: !0 }), b(async () => {
222
+ if (globalThis.window === void 0 || !v.value) return;
223
+ let e = T.value;
224
+ v.value.childNodes[0] && (T.value !== "" && console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."), e = v.value.childNodes[0].innerText.trim()), E.value = new u({
225
+ parent: v.value,
226
+ state: c.create({
227
+ doc: e,
228
+ extensions: N.value
229
+ }),
230
+ dispatch: (e) => {
231
+ E.value && (E.value.update([e]), !(e.changes.empty || !e.docChanged) && (_.emit("update:modelValue", e.state.doc.toString()), _.emit("change", e.state)));
232
+ }
233
+ }), await y(), _.emit("ready", {
234
+ view: E.value,
235
+ state: E.value.state,
236
+ container: v.value
237
+ });
238
+ }), x(() => {
239
+ E.value && (E.value.destroy(), _.emit("destroy"));
240
+ });
241
+ let P = {
242
+ editor: v,
243
+ view: E,
244
+ cursor: k,
245
+ selection: O,
246
+ focus: D,
247
+ length: j,
248
+ json: A,
249
+ diagnosticCount: M,
250
+ dom: E.value?.contentDOM,
251
+ lint: () => {
252
+ !g.linter || !E.value || (g.forceLinting && r(E.value), M.value = n(E.value.state));
253
+ },
254
+ forceReconfigure: () => {
255
+ E.value?.dispatch({ effects: l.reconfigure.of([]) }), E.value?.dispatch({ effects: l.appendConfig.of(N.value) });
256
+ },
257
+ getRange: (e, t) => E.value?.state.sliceDoc(e, t),
258
+ getLine: (e) => E.value?.state.doc.line(e + 1).text,
259
+ lineCount: () => E.value?.state.doc.lines ?? 0,
260
+ getCursor: () => E.value?.state.selection.main.head ?? 0,
261
+ listSelections: () => E.value?.state.selection.ranges ?? [],
262
+ getSelection: () => E.value ? E.value.state.sliceDoc(E.value.state.selection.main.from, E.value.state.selection.main.to) : "",
263
+ getSelections: () => {
264
+ let e = E.value?.state;
265
+ return e ? e.selection.ranges.map((t) => e.sliceDoc(t.from, t.to)) : [];
266
+ },
267
+ somethingSelected: () => E.value?.state.selection.ranges.some((e) => !e.empty) ?? !1,
268
+ replaceRange: (e, t, n) => {
269
+ E.value && E.value.dispatch({ changes: {
270
+ from: t,
271
+ to: n,
272
+ insert: e
273
+ } });
274
+ },
275
+ replaceSelection: (e) => {
276
+ E.value && E.value.dispatch(E.value.state.replaceSelection(e));
277
+ },
278
+ setCursor: (e) => {
279
+ E.value && E.value.dispatch({ selection: { anchor: e } });
280
+ },
281
+ setSelection: (e, t) => {
282
+ E.value && E.value.dispatch({ selection: {
283
+ anchor: e,
284
+ head: t
285
+ } });
286
+ },
287
+ setSelections: (e, t) => {
288
+ E.value && E.value.dispatch({ selection: s.create(e, t) });
289
+ },
290
+ extendSelectionsBy: (e) => {
291
+ E.value && O.value && E.value.dispatch({ selection: s.create(O.value.ranges.map((t) => t.extend(e(t)))) });
292
+ }
293
+ };
294
+ return _.expose(P), P;
295
+ },
296
+ render() {
297
+ return D(this.$props.tag, {
298
+ ref: "editor",
299
+ class: "vue-codemirror"
300
+ }, this.$slots.default ? D("aside", {
301
+ style: "display: none;",
302
+ "aria-hidden": "true"
303
+ }, O(this.$slots.default)) : void 0);
304
+ }
305
+ }), A = (e) => e.component("CodeMirror", k);
306
+ //#endregion
307
+ export { T as Meta, k as default, A as install };