vue-codemirror6 1.1.16 → 1.1.18
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 +8 -0
- package/README.md +31 -11
- package/dist/index.es.js +94 -62
- package/dist/index.iife.js +94 -61
- package/dist/index.umd.js +96 -63
- package/dist/src/components/CodeMirror.d.ts +451 -16
- package/package.json +17 -18
- package/src/components/CodeMirror.ts +139 -111
package/dist/index.iife.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.1.
|
|
8
|
+
* @version 1.1.18
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var CodeMirror = (function (exports, vueDemi,
|
|
12
|
+
var CodeMirror = (function (exports, vueDemi, codemirror, view, state, lint, commands) {
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
15
|
const adaptOnsV3 = (ons) => {
|
|
@@ -205,7 +205,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
205
205
|
*/
|
|
206
206
|
linterConfig: {
|
|
207
207
|
type: Object,
|
|
208
|
-
default: () =>
|
|
208
|
+
default: () => {
|
|
209
|
+
return { needsRefresh: true };
|
|
210
|
+
}
|
|
209
211
|
},
|
|
210
212
|
/**
|
|
211
213
|
* Forces any linters configured to run when the editor is idle to run right away.
|
|
@@ -246,55 +248,77 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
246
248
|
}
|
|
247
249
|
},
|
|
248
250
|
/** Emits */
|
|
249
|
-
emits:
|
|
251
|
+
emits: {
|
|
252
|
+
/** Model Update */
|
|
253
|
+
"update:modelValue": (value) => true,
|
|
254
|
+
/** CodeMirror ViewUpdate */
|
|
255
|
+
update: (value) => true,
|
|
256
|
+
/** CodeMirror onReady */
|
|
257
|
+
ready: (value) => true,
|
|
258
|
+
/** CodeMirror onFocus */
|
|
259
|
+
focus: (value) => true,
|
|
260
|
+
/** State Changed */
|
|
261
|
+
change: (value) => true,
|
|
262
|
+
/** CodeMirror onDestroy */
|
|
263
|
+
destroy: () => true
|
|
264
|
+
},
|
|
250
265
|
/**
|
|
251
266
|
* Setup
|
|
252
267
|
*
|
|
253
268
|
* @param props - Props
|
|
254
269
|
* @param context - Context
|
|
255
270
|
*/
|
|
256
|
-
// @ts-expect-error
|
|
257
271
|
setup(props, context) {
|
|
258
272
|
const editor = vueDemi.ref();
|
|
259
273
|
const doc = vueDemi.ref(props.modelValue);
|
|
260
274
|
const view$1 = vueDemi.shallowRef(new view.EditorView());
|
|
275
|
+
const focus = vueDemi.computed({
|
|
276
|
+
get: () => view$1.value.hasFocus,
|
|
277
|
+
set: (f) => {
|
|
278
|
+
if (f) {
|
|
279
|
+
view$1.value.focus();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
261
283
|
const selection = vueDemi.computed({
|
|
262
284
|
get: () => view$1.value.state.selection,
|
|
263
285
|
set: (s) => view$1.value.dispatch({ selection: s })
|
|
264
286
|
});
|
|
265
|
-
const state$1 = vueDemi.computed({
|
|
266
|
-
get: () => view$1.value.state,
|
|
267
|
-
set: (s) => view$1.value.setState(s)
|
|
268
|
-
});
|
|
269
287
|
const cursor = vueDemi.computed({
|
|
270
288
|
get: () => view$1.value.state.selection.main.head,
|
|
271
289
|
set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
|
|
272
290
|
});
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
view$1.value.focus();
|
|
278
|
-
}
|
|
291
|
+
const json = vueDemi.computed(
|
|
292
|
+
{
|
|
293
|
+
get: () => view$1.value.state.toJSON(),
|
|
294
|
+
set: (j) => view$1.value.setState(state.EditorState.fromJSON(j))
|
|
279
295
|
}
|
|
280
|
-
});
|
|
281
|
-
const length = vueDemi.computed(
|
|
282
|
-
() => view$1.value.state.doc.length
|
|
283
296
|
);
|
|
297
|
+
const length = vueDemi.ref(0);
|
|
298
|
+
const diagnosticCount = vueDemi.ref(0);
|
|
284
299
|
const language = new state.Compartment();
|
|
285
300
|
const tabSize = new state.Compartment();
|
|
286
301
|
const extensions = vueDemi.computed(
|
|
287
302
|
() => (
|
|
288
303
|
// TODO: Ignore previous prop was not changed.
|
|
289
|
-
|
|
304
|
+
[
|
|
290
305
|
// Toggle basic setup
|
|
291
306
|
props.basic ? codemirror.basicSetup : void 0,
|
|
292
307
|
// Toggle minimal setup
|
|
293
308
|
props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
|
|
294
309
|
// ViewUpdate event listener
|
|
295
|
-
view.EditorView.updateListener.of(
|
|
296
|
-
(update
|
|
297
|
-
|
|
310
|
+
view.EditorView.updateListener.of((update) => {
|
|
311
|
+
if (update.changes.empty || !update.docChanged) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (props.linter) {
|
|
315
|
+
if (props.forceLinting) {
|
|
316
|
+
lint.forceLinting(view$1.value);
|
|
317
|
+
}
|
|
318
|
+
diagnosticCount.value = props.linter(view$1.value).length;
|
|
319
|
+
}
|
|
320
|
+
context.emit("update", update);
|
|
321
|
+
}),
|
|
298
322
|
// Toggle light/dark mode.
|
|
299
323
|
view.EditorView.theme(props.theme, { dark: props.dark }),
|
|
300
324
|
// Toggle line wrapping
|
|
@@ -323,61 +347,62 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
323
347
|
props.placeholder ? view.placeholder(props.placeholder) : void 0,
|
|
324
348
|
// Append Extensions
|
|
325
349
|
...props.extensions
|
|
326
|
-
])
|
|
350
|
+
].filter((extension) => !!extension)
|
|
327
351
|
)
|
|
328
352
|
);
|
|
353
|
+
vueDemi.watch(
|
|
354
|
+
extensions,
|
|
355
|
+
(exts) => {
|
|
356
|
+
view$1.value?.dispatch({
|
|
357
|
+
effects: state.StateEffect.reconfigure.of(exts)
|
|
358
|
+
});
|
|
359
|
+
},
|
|
360
|
+
{ immediate: true }
|
|
361
|
+
);
|
|
329
362
|
vueDemi.watch(
|
|
330
363
|
() => props.modelValue,
|
|
331
|
-
(value) => {
|
|
364
|
+
async (value) => {
|
|
332
365
|
if (view$1.value.composing) {
|
|
333
366
|
return;
|
|
334
367
|
}
|
|
335
|
-
if (props.linter && props.forceLinting) {
|
|
336
|
-
lint.forceLinting(view$1.value);
|
|
337
|
-
}
|
|
338
368
|
view$1.value.dispatch({
|
|
339
369
|
changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
|
|
340
370
|
selection: view$1.value.state.selection,
|
|
341
371
|
scrollIntoView: true
|
|
342
372
|
});
|
|
373
|
+
length.value = view$1.value.state.doc.length;
|
|
343
374
|
},
|
|
344
375
|
{ immediate: true }
|
|
345
376
|
);
|
|
346
|
-
vueDemi.watch(
|
|
347
|
-
() => extensions.value,
|
|
348
|
-
(exts) => {
|
|
349
|
-
view$1.value.dispatch({
|
|
350
|
-
effects: state.StateEffect.reconfigure.of(exts)
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
);
|
|
354
377
|
vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
|
|
355
378
|
vueDemi.onMounted(async () => {
|
|
356
379
|
let value = doc.value;
|
|
357
|
-
if (editor.value
|
|
380
|
+
if (!editor.value) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (editor.value.childNodes[0]) {
|
|
358
384
|
if (doc.value !== "") {
|
|
359
385
|
console.warn(
|
|
360
386
|
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
361
387
|
);
|
|
362
388
|
}
|
|
363
|
-
value =
|
|
389
|
+
value = editor.value.childNodes[0].innerText.trim();
|
|
364
390
|
}
|
|
365
391
|
view$1.value = new view.EditorView({
|
|
366
|
-
doc: value,
|
|
367
|
-
extensions: extensions.value,
|
|
368
392
|
parent: editor.value,
|
|
393
|
+
state: state.EditorState.create({ doc: value, extensions: extensions.value }),
|
|
369
394
|
dispatch: (tr) => {
|
|
370
395
|
view$1.value.update([tr]);
|
|
371
|
-
if (tr.changes.empty)
|
|
396
|
+
if (tr.changes.empty || !tr.docChanged) {
|
|
372
397
|
return;
|
|
373
|
-
|
|
374
|
-
context.emit("update:modelValue",
|
|
375
|
-
context.emit("change",
|
|
398
|
+
}
|
|
399
|
+
context.emit("update:modelValue", tr.state.doc.toString());
|
|
400
|
+
context.emit("change", tr.state);
|
|
376
401
|
}
|
|
377
402
|
});
|
|
378
403
|
await vueDemi.nextTick();
|
|
379
404
|
context.emit("ready", {
|
|
380
|
-
view: view$1,
|
|
405
|
+
view: view$1.value,
|
|
381
406
|
state: view$1.value.state,
|
|
382
407
|
container: editor.value
|
|
383
408
|
});
|
|
@@ -387,30 +412,40 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
387
412
|
context.emit("destroy");
|
|
388
413
|
});
|
|
389
414
|
const lint$1 = () => {
|
|
390
|
-
if (props.linter) {
|
|
415
|
+
if (!props.linter || !view$1.value) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (props.forceLinting) {
|
|
391
419
|
lint.forceLinting(view$1.value);
|
|
392
420
|
}
|
|
421
|
+
diagnosticCount.value = lint.diagnosticCount(view$1.value.state);
|
|
393
422
|
};
|
|
394
423
|
const forceReconfigure = () => {
|
|
395
|
-
view$1.value
|
|
424
|
+
view$1.value?.dispatch({
|
|
396
425
|
effects: state.StateEffect.reconfigure.of([])
|
|
397
426
|
});
|
|
398
|
-
view$1.value
|
|
427
|
+
view$1.value?.dispatch({
|
|
399
428
|
effects: state.StateEffect.appendConfig.of(extensions.value)
|
|
400
429
|
});
|
|
401
430
|
};
|
|
402
431
|
const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
|
|
403
432
|
const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
|
|
404
433
|
const lineCount = () => view$1.value.state.doc.lines;
|
|
405
|
-
const getCursor = () =>
|
|
406
|
-
const listSelections = () => view$1.value.state.selection.ranges;
|
|
434
|
+
const getCursor = () => view$1.value.state.selection.main.head;
|
|
435
|
+
const listSelections = () => view$1.value.state.selection.ranges ?? [];
|
|
407
436
|
const getSelection = () => view$1.value.state.sliceDoc(
|
|
408
437
|
view$1.value.state.selection.main.from,
|
|
409
438
|
view$1.value.state.selection.main.to
|
|
410
|
-
);
|
|
411
|
-
const getSelections = () =>
|
|
412
|
-
|
|
413
|
-
|
|
439
|
+
) ?? "";
|
|
440
|
+
const getSelections = () => {
|
|
441
|
+
const s = view$1.value.state;
|
|
442
|
+
if (!s) {
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
return s.selection.ranges.map(
|
|
446
|
+
(r) => s.sliceDoc(r.from, r.to)
|
|
447
|
+
);
|
|
448
|
+
};
|
|
414
449
|
const somethingSelected = () => view$1.value.state.selection.ranges.some(
|
|
415
450
|
(r) => !r.empty
|
|
416
451
|
);
|
|
@@ -418,7 +453,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
418
453
|
changes: { from, to, insert: replacement }
|
|
419
454
|
});
|
|
420
455
|
const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
|
|
421
|
-
const setCursor = (position) =>
|
|
456
|
+
const setCursor = (position) => view$1.value.dispatch({ selection: { anchor: position } });
|
|
422
457
|
const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
|
|
423
458
|
const setSelections = (ranges, primary) => view$1.value.dispatch({
|
|
424
459
|
selection: state.EditorSelection.create(ranges, primary)
|
|
@@ -433,9 +468,10 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
433
468
|
view: view$1,
|
|
434
469
|
cursor,
|
|
435
470
|
selection,
|
|
436
|
-
state: state$1,
|
|
437
471
|
focus,
|
|
438
472
|
length,
|
|
473
|
+
json,
|
|
474
|
+
diagnosticCount,
|
|
439
475
|
lint: lint$1,
|
|
440
476
|
forceReconfigure,
|
|
441
477
|
// Bellow is CodeMirror5's function
|
|
@@ -460,19 +496,16 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
460
496
|
},
|
|
461
497
|
render() {
|
|
462
498
|
return h(
|
|
463
|
-
// @ts-expect-error
|
|
464
499
|
this.$props.tag,
|
|
465
500
|
{
|
|
466
501
|
ref: "editor",
|
|
467
502
|
class: "vue-codemirror"
|
|
468
503
|
},
|
|
469
|
-
// @ts-expect-error
|
|
470
504
|
this.$slots.default ? (
|
|
471
505
|
// Hide original content
|
|
472
506
|
h(
|
|
473
507
|
"aside",
|
|
474
508
|
{ style: "display: none;", "aria-hidden": "true" },
|
|
475
|
-
// @ts-expect-error
|
|
476
509
|
slot(this.$slots.default)
|
|
477
510
|
)
|
|
478
511
|
) : void 0
|
|
@@ -481,8 +514,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
481
514
|
});
|
|
482
515
|
|
|
483
516
|
const meta = {
|
|
484
|
-
version: "1.1.
|
|
485
|
-
date: "2023-
|
|
517
|
+
version: "1.1.18",
|
|
518
|
+
date: "2023-04-04T00:08:06.631Z"
|
|
486
519
|
};
|
|
487
520
|
|
|
488
521
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
@@ -498,4 +531,4 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
498
531
|
|
|
499
532
|
return exports;
|
|
500
533
|
|
|
501
|
-
})({}, VueDemi,
|
|
534
|
+
})({}, VueDemi, codemirror, view, state, lint, commands);
|
package/dist/index.umd.js
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.1.
|
|
8
|
+
* @version 1.1.18
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
(function (global, factory) {
|
|
13
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('
|
|
14
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', '
|
|
15
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.
|
|
16
|
-
})(this, (function (exports, vueDemi,
|
|
13
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('codemirror'), require('@codemirror/view'), require('@codemirror/state'), require('@codemirror/lint'), require('@codemirror/commands')) :
|
|
14
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'codemirror', '@codemirror/view', '@codemirror/state', '@codemirror/lint', '@codemirror/commands'], factory) :
|
|
15
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.codemirror, global.view, global.state, global.lint, global.commands));
|
|
16
|
+
})(this, (function (exports, vueDemi, codemirror, view, state, lint, commands) { 'use strict';
|
|
17
17
|
|
|
18
18
|
const adaptOnsV3 = (ons) => {
|
|
19
19
|
if (!ons)
|
|
@@ -208,7 +208,9 @@
|
|
|
208
208
|
*/
|
|
209
209
|
linterConfig: {
|
|
210
210
|
type: Object,
|
|
211
|
-
default: () =>
|
|
211
|
+
default: () => {
|
|
212
|
+
return { needsRefresh: true };
|
|
213
|
+
}
|
|
212
214
|
},
|
|
213
215
|
/**
|
|
214
216
|
* Forces any linters configured to run when the editor is idle to run right away.
|
|
@@ -249,55 +251,77 @@
|
|
|
249
251
|
}
|
|
250
252
|
},
|
|
251
253
|
/** Emits */
|
|
252
|
-
emits:
|
|
254
|
+
emits: {
|
|
255
|
+
/** Model Update */
|
|
256
|
+
"update:modelValue": (value) => true,
|
|
257
|
+
/** CodeMirror ViewUpdate */
|
|
258
|
+
update: (value) => true,
|
|
259
|
+
/** CodeMirror onReady */
|
|
260
|
+
ready: (value) => true,
|
|
261
|
+
/** CodeMirror onFocus */
|
|
262
|
+
focus: (value) => true,
|
|
263
|
+
/** State Changed */
|
|
264
|
+
change: (value) => true,
|
|
265
|
+
/** CodeMirror onDestroy */
|
|
266
|
+
destroy: () => true
|
|
267
|
+
},
|
|
253
268
|
/**
|
|
254
269
|
* Setup
|
|
255
270
|
*
|
|
256
271
|
* @param props - Props
|
|
257
272
|
* @param context - Context
|
|
258
273
|
*/
|
|
259
|
-
// @ts-expect-error
|
|
260
274
|
setup(props, context) {
|
|
261
275
|
const editor = vueDemi.ref();
|
|
262
276
|
const doc = vueDemi.ref(props.modelValue);
|
|
263
277
|
const view$1 = vueDemi.shallowRef(new view.EditorView());
|
|
278
|
+
const focus = vueDemi.computed({
|
|
279
|
+
get: () => view$1.value.hasFocus,
|
|
280
|
+
set: (f) => {
|
|
281
|
+
if (f) {
|
|
282
|
+
view$1.value.focus();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
264
286
|
const selection = vueDemi.computed({
|
|
265
287
|
get: () => view$1.value.state.selection,
|
|
266
288
|
set: (s) => view$1.value.dispatch({ selection: s })
|
|
267
289
|
});
|
|
268
|
-
const state$1 = vueDemi.computed({
|
|
269
|
-
get: () => view$1.value.state,
|
|
270
|
-
set: (s) => view$1.value.setState(s)
|
|
271
|
-
});
|
|
272
290
|
const cursor = vueDemi.computed({
|
|
273
291
|
get: () => view$1.value.state.selection.main.head,
|
|
274
292
|
set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
|
|
275
293
|
});
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
view$1.value.focus();
|
|
281
|
-
}
|
|
294
|
+
const json = vueDemi.computed(
|
|
295
|
+
{
|
|
296
|
+
get: () => view$1.value.state.toJSON(),
|
|
297
|
+
set: (j) => view$1.value.setState(state.EditorState.fromJSON(j))
|
|
282
298
|
}
|
|
283
|
-
});
|
|
284
|
-
const length = vueDemi.computed(
|
|
285
|
-
() => view$1.value.state.doc.length
|
|
286
299
|
);
|
|
300
|
+
const length = vueDemi.ref(0);
|
|
301
|
+
const diagnosticCount = vueDemi.ref(0);
|
|
287
302
|
const language = new state.Compartment();
|
|
288
303
|
const tabSize = new state.Compartment();
|
|
289
304
|
const extensions = vueDemi.computed(
|
|
290
305
|
() => (
|
|
291
306
|
// TODO: Ignore previous prop was not changed.
|
|
292
|
-
|
|
307
|
+
[
|
|
293
308
|
// Toggle basic setup
|
|
294
309
|
props.basic ? codemirror.basicSetup : void 0,
|
|
295
310
|
// Toggle minimal setup
|
|
296
311
|
props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
|
|
297
312
|
// ViewUpdate event listener
|
|
298
|
-
view.EditorView.updateListener.of(
|
|
299
|
-
(update
|
|
300
|
-
|
|
313
|
+
view.EditorView.updateListener.of((update) => {
|
|
314
|
+
if (update.changes.empty || !update.docChanged) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (props.linter) {
|
|
318
|
+
if (props.forceLinting) {
|
|
319
|
+
lint.forceLinting(view$1.value);
|
|
320
|
+
}
|
|
321
|
+
diagnosticCount.value = props.linter(view$1.value).length;
|
|
322
|
+
}
|
|
323
|
+
context.emit("update", update);
|
|
324
|
+
}),
|
|
301
325
|
// Toggle light/dark mode.
|
|
302
326
|
view.EditorView.theme(props.theme, { dark: props.dark }),
|
|
303
327
|
// Toggle line wrapping
|
|
@@ -326,61 +350,62 @@
|
|
|
326
350
|
props.placeholder ? view.placeholder(props.placeholder) : void 0,
|
|
327
351
|
// Append Extensions
|
|
328
352
|
...props.extensions
|
|
329
|
-
])
|
|
353
|
+
].filter((extension) => !!extension)
|
|
330
354
|
)
|
|
331
355
|
);
|
|
356
|
+
vueDemi.watch(
|
|
357
|
+
extensions,
|
|
358
|
+
(exts) => {
|
|
359
|
+
view$1.value?.dispatch({
|
|
360
|
+
effects: state.StateEffect.reconfigure.of(exts)
|
|
361
|
+
});
|
|
362
|
+
},
|
|
363
|
+
{ immediate: true }
|
|
364
|
+
);
|
|
332
365
|
vueDemi.watch(
|
|
333
366
|
() => props.modelValue,
|
|
334
|
-
(value) => {
|
|
367
|
+
async (value) => {
|
|
335
368
|
if (view$1.value.composing) {
|
|
336
369
|
return;
|
|
337
370
|
}
|
|
338
|
-
if (props.linter && props.forceLinting) {
|
|
339
|
-
lint.forceLinting(view$1.value);
|
|
340
|
-
}
|
|
341
371
|
view$1.value.dispatch({
|
|
342
372
|
changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
|
|
343
373
|
selection: view$1.value.state.selection,
|
|
344
374
|
scrollIntoView: true
|
|
345
375
|
});
|
|
376
|
+
length.value = view$1.value.state.doc.length;
|
|
346
377
|
},
|
|
347
378
|
{ immediate: true }
|
|
348
379
|
);
|
|
349
|
-
vueDemi.watch(
|
|
350
|
-
() => extensions.value,
|
|
351
|
-
(exts) => {
|
|
352
|
-
view$1.value.dispatch({
|
|
353
|
-
effects: state.StateEffect.reconfigure.of(exts)
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
);
|
|
357
380
|
vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
|
|
358
381
|
vueDemi.onMounted(async () => {
|
|
359
382
|
let value = doc.value;
|
|
360
|
-
if (editor.value
|
|
383
|
+
if (!editor.value) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (editor.value.childNodes[0]) {
|
|
361
387
|
if (doc.value !== "") {
|
|
362
388
|
console.warn(
|
|
363
389
|
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
364
390
|
);
|
|
365
391
|
}
|
|
366
|
-
value =
|
|
392
|
+
value = editor.value.childNodes[0].innerText.trim();
|
|
367
393
|
}
|
|
368
394
|
view$1.value = new view.EditorView({
|
|
369
|
-
doc: value,
|
|
370
|
-
extensions: extensions.value,
|
|
371
395
|
parent: editor.value,
|
|
396
|
+
state: state.EditorState.create({ doc: value, extensions: extensions.value }),
|
|
372
397
|
dispatch: (tr) => {
|
|
373
398
|
view$1.value.update([tr]);
|
|
374
|
-
if (tr.changes.empty)
|
|
399
|
+
if (tr.changes.empty || !tr.docChanged) {
|
|
375
400
|
return;
|
|
376
|
-
|
|
377
|
-
context.emit("update:modelValue",
|
|
378
|
-
context.emit("change",
|
|
401
|
+
}
|
|
402
|
+
context.emit("update:modelValue", tr.state.doc.toString());
|
|
403
|
+
context.emit("change", tr.state);
|
|
379
404
|
}
|
|
380
405
|
});
|
|
381
406
|
await vueDemi.nextTick();
|
|
382
407
|
context.emit("ready", {
|
|
383
|
-
view: view$1,
|
|
408
|
+
view: view$1.value,
|
|
384
409
|
state: view$1.value.state,
|
|
385
410
|
container: editor.value
|
|
386
411
|
});
|
|
@@ -390,30 +415,40 @@
|
|
|
390
415
|
context.emit("destroy");
|
|
391
416
|
});
|
|
392
417
|
const lint$1 = () => {
|
|
393
|
-
if (props.linter) {
|
|
418
|
+
if (!props.linter || !view$1.value) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (props.forceLinting) {
|
|
394
422
|
lint.forceLinting(view$1.value);
|
|
395
423
|
}
|
|
424
|
+
diagnosticCount.value = lint.diagnosticCount(view$1.value.state);
|
|
396
425
|
};
|
|
397
426
|
const forceReconfigure = () => {
|
|
398
|
-
view$1.value
|
|
427
|
+
view$1.value?.dispatch({
|
|
399
428
|
effects: state.StateEffect.reconfigure.of([])
|
|
400
429
|
});
|
|
401
|
-
view$1.value
|
|
430
|
+
view$1.value?.dispatch({
|
|
402
431
|
effects: state.StateEffect.appendConfig.of(extensions.value)
|
|
403
432
|
});
|
|
404
433
|
};
|
|
405
434
|
const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
|
|
406
435
|
const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
|
|
407
436
|
const lineCount = () => view$1.value.state.doc.lines;
|
|
408
|
-
const getCursor = () =>
|
|
409
|
-
const listSelections = () => view$1.value.state.selection.ranges;
|
|
437
|
+
const getCursor = () => view$1.value.state.selection.main.head;
|
|
438
|
+
const listSelections = () => view$1.value.state.selection.ranges ?? [];
|
|
410
439
|
const getSelection = () => view$1.value.state.sliceDoc(
|
|
411
440
|
view$1.value.state.selection.main.from,
|
|
412
441
|
view$1.value.state.selection.main.to
|
|
413
|
-
);
|
|
414
|
-
const getSelections = () =>
|
|
415
|
-
|
|
416
|
-
|
|
442
|
+
) ?? "";
|
|
443
|
+
const getSelections = () => {
|
|
444
|
+
const s = view$1.value.state;
|
|
445
|
+
if (!s) {
|
|
446
|
+
return [];
|
|
447
|
+
}
|
|
448
|
+
return s.selection.ranges.map(
|
|
449
|
+
(r) => s.sliceDoc(r.from, r.to)
|
|
450
|
+
);
|
|
451
|
+
};
|
|
417
452
|
const somethingSelected = () => view$1.value.state.selection.ranges.some(
|
|
418
453
|
(r) => !r.empty
|
|
419
454
|
);
|
|
@@ -421,7 +456,7 @@
|
|
|
421
456
|
changes: { from, to, insert: replacement }
|
|
422
457
|
});
|
|
423
458
|
const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
|
|
424
|
-
const setCursor = (position) =>
|
|
459
|
+
const setCursor = (position) => view$1.value.dispatch({ selection: { anchor: position } });
|
|
425
460
|
const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
|
|
426
461
|
const setSelections = (ranges, primary) => view$1.value.dispatch({
|
|
427
462
|
selection: state.EditorSelection.create(ranges, primary)
|
|
@@ -436,9 +471,10 @@
|
|
|
436
471
|
view: view$1,
|
|
437
472
|
cursor,
|
|
438
473
|
selection,
|
|
439
|
-
state: state$1,
|
|
440
474
|
focus,
|
|
441
475
|
length,
|
|
476
|
+
json,
|
|
477
|
+
diagnosticCount,
|
|
442
478
|
lint: lint$1,
|
|
443
479
|
forceReconfigure,
|
|
444
480
|
// Bellow is CodeMirror5's function
|
|
@@ -463,19 +499,16 @@
|
|
|
463
499
|
},
|
|
464
500
|
render() {
|
|
465
501
|
return h(
|
|
466
|
-
// @ts-expect-error
|
|
467
502
|
this.$props.tag,
|
|
468
503
|
{
|
|
469
504
|
ref: "editor",
|
|
470
505
|
class: "vue-codemirror"
|
|
471
506
|
},
|
|
472
|
-
// @ts-expect-error
|
|
473
507
|
this.$slots.default ? (
|
|
474
508
|
// Hide original content
|
|
475
509
|
h(
|
|
476
510
|
"aside",
|
|
477
511
|
{ style: "display: none;", "aria-hidden": "true" },
|
|
478
|
-
// @ts-expect-error
|
|
479
512
|
slot(this.$slots.default)
|
|
480
513
|
)
|
|
481
514
|
) : void 0
|
|
@@ -484,8 +517,8 @@
|
|
|
484
517
|
});
|
|
485
518
|
|
|
486
519
|
const meta = {
|
|
487
|
-
version: "1.1.
|
|
488
|
-
date: "2023-
|
|
520
|
+
version: "1.1.18",
|
|
521
|
+
date: "2023-04-04T00:08:06.631Z"
|
|
489
522
|
};
|
|
490
523
|
|
|
491
524
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|