vue-codemirror6 1.3.22 → 1.4.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 +15 -3
- package/README.md +58 -0
- package/dist/index.cjs.js +3 -3
- package/dist/index.d.ts +646 -1
- package/dist/index.es.js +139 -122
- package/dist/index.iife.js +3 -3
- package/dist/index.umd.js +3 -3
- package/package.json +47 -38
- package/dist/components/CodeMirror.d.ts +0 -633
- package/src/components/CodeMirror.ts +0 -816
package/dist/index.es.js
CHANGED
|
@@ -5,33 +5,32 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.4.1
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { indentWithTab as W } from "@codemirror/commands";
|
|
13
13
|
import { indentUnit as G } from "@codemirror/language";
|
|
14
14
|
import { linter as P, lintGutter as Z, forceLinting as w, diagnosticCount as q } from "@codemirror/lint";
|
|
15
|
-
import { EditorState as
|
|
16
|
-
import { EditorView as
|
|
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
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
|
|
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
19
|
const he = {
|
|
20
|
-
version: "1.
|
|
21
|
-
date: "2025-
|
|
22
|
-
},
|
|
23
|
-
function M(
|
|
20
|
+
version: "1.4.1",
|
|
21
|
+
date: "2025-10-17T22:30:13.688Z"
|
|
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
24
|
if (Y)
|
|
25
|
-
return V(
|
|
26
|
-
const { props:
|
|
25
|
+
return V(t, l, i);
|
|
26
|
+
const { props: s, domProps: e, on: v, ...r } = l, h = v ? le(v) : {};
|
|
27
27
|
return V(
|
|
28
|
-
|
|
29
|
-
{ ...
|
|
30
|
-
|
|
28
|
+
t,
|
|
29
|
+
{ ...r, ...s, ...e, ...h },
|
|
30
|
+
i
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
const oe = (
|
|
34
|
-
var se = ee({
|
|
33
|
+
const oe = (t) => typeof t == "function" ? t() : t, ue = ee({
|
|
35
34
|
/** Component Name */
|
|
36
35
|
name: "CodeMirror",
|
|
37
36
|
/** Model Definition */
|
|
@@ -63,6 +62,8 @@ var se = ee({
|
|
|
63
62
|
/**
|
|
64
63
|
* Use Basic Setup
|
|
65
64
|
*
|
|
65
|
+
* This will enable the basic setup for the editor.
|
|
66
|
+
*
|
|
66
67
|
* @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
|
|
67
68
|
*/
|
|
68
69
|
basic: {
|
|
@@ -101,6 +102,8 @@ var se = ee({
|
|
|
101
102
|
/**
|
|
102
103
|
* Allow tab key indent.
|
|
103
104
|
*
|
|
105
|
+
* This will enable the tab key to indent the current line or selection.
|
|
106
|
+
*
|
|
104
107
|
* @see {@link https://codemirror.net/examples/tab/}
|
|
105
108
|
*/
|
|
106
109
|
tab: {
|
|
@@ -109,6 +112,7 @@ var se = ee({
|
|
|
109
112
|
},
|
|
110
113
|
/**
|
|
111
114
|
* Tab character
|
|
115
|
+
*
|
|
112
116
|
* This is the unit of indentation used when the editor is configured to indent with tabs.
|
|
113
117
|
* It is also used to determine the size of the tab character when the editor is configured to use tabs for indentation..
|
|
114
118
|
*
|
|
@@ -120,6 +124,7 @@ var se = ee({
|
|
|
120
124
|
},
|
|
121
125
|
/**
|
|
122
126
|
* Allow Multiple Selection.
|
|
127
|
+
*
|
|
123
128
|
* This allows the editor to have multiple selections at the same time.
|
|
124
129
|
* This is useful for editing multiple parts of the document at once.
|
|
125
130
|
* If this is set to true, the editor will allow multiple selections.
|
|
@@ -133,6 +138,7 @@ var se = ee({
|
|
|
133
138
|
},
|
|
134
139
|
/**
|
|
135
140
|
* Tab size
|
|
141
|
+
*
|
|
136
142
|
* This is the number of spaces that a tab character represents in the editor.
|
|
137
143
|
* It is used to determine the size of the tab character when the editor is configured to use tabs for indentation.
|
|
138
144
|
* If this is set to a number, the editor will use that number of spaces for each tab character.
|
|
@@ -316,15 +322,15 @@ var se = ee({
|
|
|
316
322
|
/** Emits */
|
|
317
323
|
emits: {
|
|
318
324
|
/** Model Update */
|
|
319
|
-
"update:modelValue": (
|
|
325
|
+
"update:modelValue": (t = "") => !0,
|
|
320
326
|
/** CodeMirror ViewUpdate */
|
|
321
|
-
update: (
|
|
327
|
+
update: (t) => !0,
|
|
322
328
|
/** CodeMirror onReady */
|
|
323
|
-
ready: (
|
|
329
|
+
ready: (t) => !0,
|
|
324
330
|
/** CodeMirror onFocus */
|
|
325
|
-
focus: (
|
|
331
|
+
focus: (t) => !0,
|
|
326
332
|
/** State Changed */
|
|
327
|
-
change: (
|
|
333
|
+
change: (t) => !0,
|
|
328
334
|
/** CodeMirror onDestroy */
|
|
329
335
|
destroy: () => !0
|
|
330
336
|
},
|
|
@@ -334,171 +340,183 @@ var se = ee({
|
|
|
334
340
|
* @param props - Props
|
|
335
341
|
* @param context - Context
|
|
336
342
|
*/
|
|
337
|
-
setup(
|
|
338
|
-
const
|
|
339
|
-
get: () =>
|
|
343
|
+
setup(t, l) {
|
|
344
|
+
const i = m(), s = m(t.modelValue), e = te(void 0), v = f({
|
|
345
|
+
get: () => e.value?.hasFocus ?? !1,
|
|
340
346
|
set: (a) => {
|
|
341
|
-
a &&
|
|
347
|
+
a && e.value && e.value.focus();
|
|
342
348
|
}
|
|
343
|
-
}),
|
|
344
|
-
get: () =>
|
|
345
|
-
set: (a) =>
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
|
|
352
|
-
|
|
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));
|
|
353
363
|
}
|
|
354
|
-
), p = m(0), g = m(0), y =
|
|
364
|
+
}), p = m(0), g = m(0), y = f(() => {
|
|
355
365
|
const a = new C(), n = new C();
|
|
356
|
-
if (
|
|
366
|
+
if (t.basic && t.minimal)
|
|
357
367
|
throw new Error(
|
|
358
368
|
"[Vue CodeMirror] Both basic and minimal cannot be specified."
|
|
359
369
|
);
|
|
360
370
|
let o = [];
|
|
361
|
-
return
|
|
371
|
+
return t.keymap && t.keymap.length > 0 && (o = t.keymap), t.tab && o.push(W), [
|
|
362
372
|
// Toggle basic setup
|
|
363
|
-
|
|
373
|
+
t.basic && !t.minimal ? Q : void 0,
|
|
364
374
|
// Toggle minimal setup
|
|
365
|
-
|
|
375
|
+
t.minimal && !t.basic ? X : void 0,
|
|
366
376
|
// ViewUpdate event listener
|
|
367
|
-
|
|
368
|
-
|
|
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)));
|
|
369
379
|
}),
|
|
370
380
|
// Toggle light/dark mode.
|
|
371
|
-
|
|
381
|
+
d.theme(t.theme, { dark: t.dark }),
|
|
372
382
|
// Toggle line wrapping
|
|
373
|
-
|
|
383
|
+
t.wrap ? d.lineWrapping : void 0,
|
|
374
384
|
// Tab character
|
|
375
|
-
|
|
385
|
+
t.indentUnit ? G.of(t.indentUnit) : void 0,
|
|
376
386
|
// Allow Multiple Selections
|
|
377
|
-
|
|
387
|
+
u.allowMultipleSelections.of(t.allowMultipleSelections),
|
|
378
388
|
// Indent tab size
|
|
379
|
-
|
|
389
|
+
t.tabSize ? n.of(u.tabSize.of(t.tabSize)) : void 0,
|
|
380
390
|
// locale settings
|
|
381
|
-
|
|
391
|
+
t.phrases ? u.phrases.of(t.phrases) : void 0,
|
|
382
392
|
// Readonly option
|
|
383
|
-
|
|
393
|
+
u.readOnly.of(t.readonly),
|
|
384
394
|
// Editable option
|
|
385
|
-
|
|
395
|
+
d.editable.of(!t.disabled),
|
|
386
396
|
// Set Line break char
|
|
387
|
-
|
|
397
|
+
t.lineSeparator ? u.lineSeparator.of(t.lineSeparator) : void 0,
|
|
388
398
|
// Lang
|
|
389
|
-
|
|
399
|
+
t.lang ? a.of(t.lang) : void 0,
|
|
390
400
|
// Append Linter settings
|
|
391
|
-
|
|
401
|
+
t.linter ? P(t.linter, t.linterConfig) : void 0,
|
|
392
402
|
// Show 🔴 to error line when linter enabled.
|
|
393
|
-
|
|
403
|
+
t.linter && t.gutter ? Z(t.gutterConfig) : void 0,
|
|
394
404
|
// Placeholder
|
|
395
|
-
|
|
405
|
+
t.placeholder ? H(t.placeholder) : void 0,
|
|
396
406
|
// Keymap and Indent with Tab
|
|
397
|
-
o.length
|
|
407
|
+
o.length > 0 ? K.of(o) : void 0,
|
|
398
408
|
// Append Extensions
|
|
399
|
-
...
|
|
400
|
-
].filter((
|
|
409
|
+
...t.extensions
|
|
410
|
+
].filter((c) => !!c);
|
|
401
411
|
});
|
|
402
412
|
B(
|
|
403
413
|
y,
|
|
404
|
-
(a) =>
|
|
414
|
+
(a) => e.value?.dispatch({ effects: S.reconfigure.of(a) }),
|
|
405
415
|
{ immediate: !0 }
|
|
406
416
|
), B(
|
|
407
|
-
() =>
|
|
417
|
+
() => t.modelValue,
|
|
408
418
|
async (a) => {
|
|
409
|
-
if (
|
|
410
|
-
|
|
419
|
+
if (!e.value || e.value.composing || // IME fix
|
|
420
|
+
e.value.state.doc.toJSON().join(t.lineSeparator ?? `
|
|
411
421
|
`) === a)
|
|
412
422
|
return;
|
|
413
|
-
const n = !
|
|
423
|
+
const n = !e.value.state.selection.ranges.every(
|
|
414
424
|
(o) => o.anchor < a.length && o.head < a.length
|
|
415
425
|
);
|
|
416
|
-
|
|
417
|
-
changes: { from: 0, to:
|
|
418
|
-
selection: n ? { anchor: 0, head: 0 } :
|
|
419
|
-
scrollIntoView:
|
|
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
|
|
420
430
|
});
|
|
421
431
|
},
|
|
422
432
|
{ immediate: !0 }
|
|
423
433
|
), ae(async () => {
|
|
424
|
-
|
|
425
|
-
|
|
434
|
+
if (globalThis.window === void 0 || !i.value)
|
|
435
|
+
return;
|
|
436
|
+
let a = s.value;
|
|
437
|
+
i.value.childNodes[0] && (s.value !== "" && console.warn(
|
|
426
438
|
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
427
|
-
), a =
|
|
428
|
-
parent:
|
|
429
|
-
state:
|
|
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 }),
|
|
430
442
|
dispatch: (n) => {
|
|
431
|
-
|
|
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)));
|
|
432
444
|
}
|
|
433
|
-
}), await ne(),
|
|
434
|
-
view:
|
|
435
|
-
state:
|
|
436
|
-
container:
|
|
437
|
-
})
|
|
438
|
-
}),
|
|
439
|
-
|
|
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"));
|
|
440
452
|
});
|
|
441
|
-
const
|
|
442
|
-
!
|
|
443
|
-
},
|
|
444
|
-
|
|
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({
|
|
445
457
|
effects: S.reconfigure.of([])
|
|
446
|
-
}),
|
|
458
|
+
}), e.value?.dispatch({
|
|
447
459
|
effects: S.appendConfig.of(y.value)
|
|
448
460
|
});
|
|
449
|
-
},
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return (a = t.value.state.sliceDoc(
|
|
455
|
-
t.value.state.selection.main.from,
|
|
456
|
-
t.value.state.selection.main.to
|
|
457
|
-
)) !== null && a !== void 0 ? a : "";
|
|
458
|
-
}, E = () => {
|
|
459
|
-
const a = t.value.state;
|
|
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;
|
|
460
466
|
return a ? a.selection.ranges.map(
|
|
461
467
|
(n) => a.sliceDoc(n.from, n.to)
|
|
462
468
|
) : [];
|
|
463
|
-
}, R = () =>
|
|
469
|
+
}, R = () => e.value?.state.selection.ranges.some(
|
|
464
470
|
(a) => !a.empty
|
|
465
|
-
),
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
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,
|
|
476
494
|
cursor: h,
|
|
477
|
-
selection:
|
|
478
|
-
focus:
|
|
495
|
+
selection: r,
|
|
496
|
+
focus: v,
|
|
479
497
|
length: p,
|
|
480
|
-
json:
|
|
498
|
+
json: j,
|
|
481
499
|
diagnosticCount: g,
|
|
482
|
-
dom:
|
|
483
|
-
lint:
|
|
484
|
-
forceReconfigure:
|
|
500
|
+
dom: e.value?.contentDOM,
|
|
501
|
+
lint: x,
|
|
502
|
+
forceReconfigure: L,
|
|
485
503
|
// Bellow is CodeMirror5's function
|
|
486
|
-
getRange:
|
|
487
|
-
getLine:
|
|
488
|
-
lineCount:
|
|
489
|
-
getCursor:
|
|
504
|
+
getRange: N,
|
|
505
|
+
getLine: T,
|
|
506
|
+
lineCount: U,
|
|
507
|
+
getCursor: $,
|
|
490
508
|
listSelections: k,
|
|
491
509
|
getSelection: z,
|
|
492
510
|
getSelections: E,
|
|
493
511
|
somethingSelected: R,
|
|
494
|
-
replaceRange:
|
|
512
|
+
replaceRange: _,
|
|
495
513
|
replaceSelection: D,
|
|
496
514
|
setCursor: A,
|
|
497
515
|
setSelection: F,
|
|
498
516
|
setSelections: I,
|
|
499
517
|
extendSelectionsBy: J
|
|
500
518
|
};
|
|
501
|
-
return
|
|
519
|
+
return l.expose(b), b;
|
|
502
520
|
},
|
|
503
521
|
render() {
|
|
504
522
|
return M(
|
|
@@ -517,10 +535,9 @@ var se = ee({
|
|
|
517
535
|
) : void 0
|
|
518
536
|
);
|
|
519
537
|
}
|
|
520
|
-
});
|
|
521
|
-
const ge = (e) => e.component("CodeMirror", se);
|
|
538
|
+
}), ge = (t) => t.component("CodeMirror", ue);
|
|
522
539
|
export {
|
|
523
540
|
he as Meta,
|
|
524
|
-
|
|
541
|
+
ue as default,
|
|
525
542
|
ge as install
|
|
526
543
|
};
|
package/dist/index.iife.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.4.1
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var CodeMirror=function(
|
|
13
|
-
`)===a)return;const n=!
|
|
12
|
+
var CodeMirror=(function(s,E,O,f,o,c,b,l){"use strict";const M={version:"1.4.1",date:"2025-10-17T22:30:13.688Z"},B=t=>t?Object.entries(t).reduce((r,[i,d])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...r,[i]:d}),{}):{};function w(t,r={},i){if(l.isVue2)return l.h(t,r,i);const{props:d,domProps:e,on:g,...v}=r,m=g?B(g):{};return l.h(t,{...v,...d,...e,...m},i)}const j=t=>typeof t=="function"?t():t,C=l.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:void 0},tag:{type:String,default:"div"},scrollIntoView:{type:Boolean,default:!0},keymap:{type:Array,default:()=>[]}},emits:{"update:modelValue":(t="")=>!0,update:t=>!0,ready:t=>!0,focus:t=>!0,change:t=>!0,destroy:()=>!0},setup(t,r){const i=l.ref(),d=l.ref(t.modelValue),e=l.shallowRef(void 0),g=l.computed({get:()=>e.value?.hasFocus??!1,set:a=>{a&&e.value&&e.value.focus()}}),v=l.computed({get:()=>e.value?.state.selection,set:a=>{e.value&&a&&e.value.dispatch({selection:a})}}),m=l.computed({get:()=>e.value?.state.selection.main.head??0,set:a=>{e.value&&e.value.dispatch({selection:{anchor:a}})}}),_=l.computed({get:()=>e.value?.state.toJSON(),set:a=>{e.value&&a&&e.value.setState(o.EditorState.fromJSON(a))}}),p=l.ref(0),y=l.ref(0),S=l.computed(()=>{const a=new o.Compartment,n=new o.Compartment;if(t.basic&&t.minimal)throw new Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");let u=[];return t.keymap&&t.keymap.length>0&&(u=t.keymap),t.tab&&u.push(E.indentWithTab),[t.basic&&!t.minimal?b.basicSetup:void 0,t.minimal&&!t.basic?b.minimalSetup:void 0,c.EditorView.updateListener.of(h=>{e.value&&(r.emit("focus",e.value.hasFocus),p.value=e.value.state.doc?.length,!(h.changes.empty||!h.docChanged)&&(t.linter&&(t.forceLinting&&f.forceLinting(e.value),y.value=t.linter(e.value).length),r.emit("update",h)))}),c.EditorView.theme(t.theme,{dark:t.dark}),t.wrap?c.EditorView.lineWrapping:void 0,t.indentUnit?O.indentUnit.of(t.indentUnit):void 0,o.EditorState.allowMultipleSelections.of(t.allowMultipleSelections),t.tabSize?n.of(o.EditorState.tabSize.of(t.tabSize)):void 0,t.phrases?o.EditorState.phrases.of(t.phrases):void 0,o.EditorState.readOnly.of(t.readonly),c.EditorView.editable.of(!t.disabled),t.lineSeparator?o.EditorState.lineSeparator.of(t.lineSeparator):void 0,t.lang?a.of(t.lang):void 0,t.linter?f.linter(t.linter,t.linterConfig):void 0,t.linter&&t.gutter?f.lintGutter(t.gutterConfig):void 0,t.placeholder?c.placeholder(t.placeholder):void 0,u.length>0?c.keymap.of(u):void 0,...t.extensions].filter(h=>!!h)});l.watch(S,a=>e.value?.dispatch({effects:o.StateEffect.reconfigure.of(a)}),{immediate:!0}),l.watch(()=>t.modelValue,async a=>{if(!e.value||e.value.composing||e.value.state.doc.toJSON().join(t.lineSeparator??`
|
|
13
|
+
`)===a)return;const n=!e.value.state.selection.ranges.every(u=>u.anchor<a.length&&u.head<a.length);e.value.dispatch({changes:{from:0,to:e.value.state.doc.length,insert:a},selection:n?{anchor:0,head:0}:e.value.state.selection,scrollIntoView:t.scrollIntoView})},{immediate:!0}),l.onMounted(async()=>{if(globalThis.window===void 0||!i.value)return;let a=d.value;i.value.childNodes[0]&&(d.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=i.value.childNodes[0].innerText.trim()),e.value=new c.EditorView({parent:i.value,state:o.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{e.value&&(e.value.update([n]),!(n.changes.empty||!n.docChanged)&&(r.emit("update:modelValue",n.state.doc.toString()),r.emit("change",n.state)))}}),await l.nextTick(),r.emit("ready",{view:e.value,state:e.value.state,container:i.value})}),l.onUnmounted(()=>{e.value&&(e.value.destroy(),r.emit("destroy"))});const $=()=>{!t.linter||!e.value||(t.forceLinting&&f.forceLinting(e.value),y.value=f.diagnosticCount(e.value.state))},N=()=>{e.value?.dispatch({effects:o.StateEffect.reconfigure.of([])}),e.value?.dispatch({effects:o.StateEffect.appendConfig.of(S.value)})},T=(a,n)=>e.value?.state.sliceDoc(a,n),U=a=>e.value?.state.doc.line(a+1).text,k=()=>e.value?.state.doc.lines??0,z=()=>e.value?.state.selection.main.head??0,R=()=>e.value?.state.selection.ranges??[],A=()=>e.value?e.value.state.sliceDoc(e.value.state.selection.main.from,e.value.state.selection.main.to):"",F=()=>{const a=e.value?.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},I=()=>e.value?.state.selection.ranges.some(a=>!a.empty)??!1,J=(a,n,u)=>{e.value&&e.value.dispatch({changes:{from:n,to:u,insert:a}})},x=a=>{e.value&&e.value.dispatch(e.value.state.replaceSelection(a))},P=a=>{e.value&&e.value.dispatch({selection:{anchor:a}})},W=(a,n)=>{e.value&&e.value.dispatch({selection:{anchor:a,head:n}})},G=(a,n)=>{e.value&&e.value.dispatch({selection:o.EditorSelection.create(a,n)})},Z=a=>{e.value&&v.value&&e.value.dispatch({selection:o.EditorSelection.create(v.value.ranges.map(n=>n.extend(a(n))))})},V={editor:i,view:e,cursor:m,selection:v,focus:g,length:p,json:_,diagnosticCount:y,dom:e.value?.contentDOM,lint:$,forceReconfigure:N,getRange:T,getLine:U,lineCount:k,getCursor:z,listSelections:R,getSelection:A,getSelections:F,somethingSelected:I,replaceRange:J,replaceSelection:x,setCursor:P,setSelection:W,setSelections:G,extendSelectionsBy:Z};return r.expose(V),V},render(){return w(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?w("aside",{style:"display: none;","aria-hidden":"true"},j(this.$slots.default)):void 0)}}),L=t=>t.component("CodeMirror",C);return s.Meta=M,s.default=C,s.install=L,Object.defineProperty(s,"__esModule",{value:!0}),s})({},commands,language,lint,state,view,codemirror,VueDemi);
|
package/dist/index.umd.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2025 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.4.1
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,function(l,f,O,v,r,
|
|
13
|
-
`)===a)return;const n=!
|
|
12
|
+
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,(function(l,f,O,v,r,c,w,i){"use strict";const M={version:"1.4.1",date:"2025-10-17T22:30:13.688Z"},B=t=>t?Object.entries(t).reduce((d,[o,s])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...d,[o]:s}),{}):{};function C(t,d={},o){if(i.isVue2)return i.h(t,d,o);const{props:s,domProps:e,on:g,...m}=d,y=g?B(g):{};return i.h(t,{...m,...s,...e,...y},o)}const j=t=>typeof t=="function"?t():t,b=i.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:void 0},tag:{type:String,default:"div"},scrollIntoView:{type:Boolean,default:!0},keymap:{type:Array,default:()=>[]}},emits:{"update:modelValue":(t="")=>!0,update:t=>!0,ready:t=>!0,focus:t=>!0,change:t=>!0,destroy:()=>!0},setup(t,d){const o=i.ref(),s=i.ref(t.modelValue),e=i.shallowRef(void 0),g=i.computed({get:()=>e.value?.hasFocus??!1,set:a=>{a&&e.value&&e.value.focus()}}),m=i.computed({get:()=>e.value?.state.selection,set:a=>{e.value&&a&&e.value.dispatch({selection:a})}}),y=i.computed({get:()=>e.value?.state.selection.main.head??0,set:a=>{e.value&&e.value.dispatch({selection:{anchor:a}})}}),q=i.computed({get:()=>e.value?.state.toJSON(),set:a=>{e.value&&a&&e.value.setState(r.EditorState.fromJSON(a))}}),V=i.ref(0),S=i.ref(0),p=i.computed(()=>{const a=new r.Compartment,n=new r.Compartment;if(t.basic&&t.minimal)throw new Error("[Vue CodeMirror] Both basic and minimal cannot be specified.");let u=[];return t.keymap&&t.keymap.length>0&&(u=t.keymap),t.tab&&u.push(f.indentWithTab),[t.basic&&!t.minimal?w.basicSetup:void 0,t.minimal&&!t.basic?w.minimalSetup:void 0,c.EditorView.updateListener.of(h=>{e.value&&(d.emit("focus",e.value.hasFocus),V.value=e.value.state.doc?.length,!(h.changes.empty||!h.docChanged)&&(t.linter&&(t.forceLinting&&v.forceLinting(e.value),S.value=t.linter(e.value).length),d.emit("update",h)))}),c.EditorView.theme(t.theme,{dark:t.dark}),t.wrap?c.EditorView.lineWrapping:void 0,t.indentUnit?O.indentUnit.of(t.indentUnit):void 0,r.EditorState.allowMultipleSelections.of(t.allowMultipleSelections),t.tabSize?n.of(r.EditorState.tabSize.of(t.tabSize)):void 0,t.phrases?r.EditorState.phrases.of(t.phrases):void 0,r.EditorState.readOnly.of(t.readonly),c.EditorView.editable.of(!t.disabled),t.lineSeparator?r.EditorState.lineSeparator.of(t.lineSeparator):void 0,t.lang?a.of(t.lang):void 0,t.linter?v.linter(t.linter,t.linterConfig):void 0,t.linter&&t.gutter?v.lintGutter(t.gutterConfig):void 0,t.placeholder?c.placeholder(t.placeholder):void 0,u.length>0?c.keymap.of(u):void 0,...t.extensions].filter(h=>!!h)});i.watch(p,a=>e.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)}),{immediate:!0}),i.watch(()=>t.modelValue,async a=>{if(!e.value||e.value.composing||e.value.state.doc.toJSON().join(t.lineSeparator??`
|
|
13
|
+
`)===a)return;const n=!e.value.state.selection.ranges.every(u=>u.anchor<a.length&&u.head<a.length);e.value.dispatch({changes:{from:0,to:e.value.state.doc.length,insert:a},selection:n?{anchor:0,head:0}:e.value.state.selection,scrollIntoView:t.scrollIntoView})},{immediate:!0}),i.onMounted(async()=>{if(globalThis.window===void 0||!o.value)return;let a=s.value;o.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),e.value=new c.EditorView({parent:o.value,state:r.EditorState.create({doc:a,extensions:p.value}),dispatch:n=>{e.value&&(e.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()),d.emit("change",n.state)))}}),await i.nextTick(),d.emit("ready",{view:e.value,state:e.value.state,container:o.value})}),i.onUnmounted(()=>{e.value&&(e.value.destroy(),d.emit("destroy"))});const L=()=>{!t.linter||!e.value||(t.forceLinting&&v.forceLinting(e.value),S.value=v.diagnosticCount(e.value.state))},_=()=>{e.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),e.value?.dispatch({effects:r.StateEffect.appendConfig.of(p.value)})},$=(a,n)=>e.value?.state.sliceDoc(a,n),x=a=>e.value?.state.doc.line(a+1).text,N=()=>e.value?.state.doc.lines??0,U=()=>e.value?.state.selection.main.head??0,k=()=>e.value?.state.selection.ranges??[],z=()=>e.value?e.value.state.sliceDoc(e.value.state.selection.main.from,e.value.state.selection.main.to):"",R=()=>{const a=e.value?.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},A=()=>e.value?.state.selection.ranges.some(a=>!a.empty)??!1,F=(a,n,u)=>{e.value&&e.value.dispatch({changes:{from:n,to:u,insert:a}})},I=a=>{e.value&&e.value.dispatch(e.value.state.replaceSelection(a))},J=a=>{e.value&&e.value.dispatch({selection:{anchor:a}})},P=(a,n)=>{e.value&&e.value.dispatch({selection:{anchor:a,head:n}})},W=(a,n)=>{e.value&&e.value.dispatch({selection:r.EditorSelection.create(a,n)})},G=a=>{e.value&&m.value&&e.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))})},E={editor:o,view:e,cursor:y,selection:m,focus:g,length:V,json:q,diagnosticCount:S,dom:e.value?.contentDOM,lint:L,forceReconfigure:_,getRange:$,getLine:x,lineCount:N,getCursor:U,listSelections:k,getSelection:z,getSelections:R,somethingSelected:A,replaceRange:F,replaceSelection:I,setCursor:J,setSelection:P,setSelections:W,extendSelectionsBy:G};return d.expose(E),E},render(){return C(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?C("aside",{style:"display: none;","aria-hidden":"true"},j(this.$slots.default)):void 0)}}),T=t=>t.component("CodeMirror",b);l.Meta=M,l.default=b,l.install=T,Object.defineProperty(l,"__esModule",{value:!0})}));
|