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/CHANGELOG.md +21 -13
- package/README.ja.md +454 -0
- package/README.md +11 -0
- package/dist/index.cjs.js +3 -3
- package/dist/index.es.js +296 -532
- package/dist/index.iife.js +3 -3
- package/dist/index.umd.js +3 -3
- package/dist/src/Meta.d.ts +3 -0
- package/dist/{index.d.ts → src/index.d.ts} +26 -1
- package/package.json +33 -33
- package/dist/Meta.d.ts +0 -3
- /package/dist/{helpers → src/helpers}/h-demi.d.ts +0 -0
- /package/dist/{interfaces → src/interfaces}/MetaInterface.d.ts +0 -0
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.
|
|
8
|
+
* @version 1.5.0
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { indentWithTab as
|
|
13
|
-
import { indentUnit as
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { EditorView as
|
|
17
|
-
import { basicSetup as
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
* @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 };
|