vue-codemirror6 1.1.15 → 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.
@@ -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.15
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, lodash, codemirror, state, view, commands, lint) {
12
+ var CodeMirror = (function (exports, vueDemi, codemirror, view, state, lint, commands) {
13
13
  'use strict';
14
14
 
15
15
  const adaptOnsV3 = (ons) => {
@@ -33,7 +33,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
33
33
  chidren
34
34
  );
35
35
  }
36
- const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
36
+ const slot = (defaultSlots) => typeof defaultSlots === "function" ? defaultSlots() : defaultSlots;
37
37
 
38
38
  var CodeMirror = vueDemi.defineComponent({
39
39
  /** Component Name */
@@ -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: () => void 0
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,30 +248,30 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
246
248
  }
247
249
  },
248
250
  /** Emits */
249
- emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
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-ignore
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());
261
- const selection = vueDemi.computed({
262
- get: () => view$1.value.state.selection,
263
- set: (s) => view$1.value.dispatch({ selection: s })
264
- });
265
- const state$1 = vueDemi.computed({
266
- get: () => view$1.value.state,
267
- set: (s) => view$1.value.setState(s)
268
- });
269
- const cursor = vueDemi.computed({
270
- get: () => view$1.value.state.selection.main.head || 0,
271
- set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
272
- });
273
275
  const focus = vueDemi.computed({
274
276
  get: () => view$1.value.hasFocus,
275
277
  set: (f) => {
@@ -278,21 +280,45 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
278
280
  }
279
281
  }
280
282
  });
281
- const length = vueDemi.computed(
282
- () => view$1.value.state.doc.length
283
+ const selection = vueDemi.computed({
284
+ get: () => view$1.value.state.selection,
285
+ set: (s) => view$1.value.dispatch({ selection: s })
286
+ });
287
+ const cursor = vueDemi.computed({
288
+ get: () => view$1.value.state.selection.main.head,
289
+ set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
290
+ });
291
+ const json = vueDemi.computed(
292
+ {
293
+ get: () => view$1.value.state.toJSON(),
294
+ set: (j) => view$1.value.setState(state.EditorState.fromJSON(j))
295
+ }
283
296
  );
297
+ const length = vueDemi.ref(0);
298
+ const diagnosticCount = vueDemi.ref(0);
299
+ const language = new state.Compartment();
300
+ const tabSize = new state.Compartment();
284
301
  const extensions = vueDemi.computed(
285
302
  () => (
286
303
  // TODO: Ignore previous prop was not changed.
287
- lodash.compact([
304
+ [
288
305
  // Toggle basic setup
289
306
  props.basic ? codemirror.basicSetup : void 0,
290
307
  // Toggle minimal setup
291
308
  props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
292
309
  // ViewUpdate event listener
293
- view.EditorView.updateListener.of(
294
- (update) => context.emit("update", update)
295
- ),
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
+ }),
296
322
  // Toggle light/dark mode.
297
323
  view.EditorView.theme(props.theme, { dark: props.dark }),
298
324
  // Toggle line wrapping
@@ -302,7 +328,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
302
328
  // Allow Multiple Selections
303
329
  state.EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
304
330
  // Indent tab size
305
- props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
331
+ props.tabSize ? tabSize.of(state.EditorState.tabSize.of(props.tabSize)) : void 0,
306
332
  // locale settings
307
333
  props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
308
334
  // Readonly option
@@ -312,7 +338,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
312
338
  // Set Line break char
313
339
  props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
314
340
  // Lang
315
- props.lang ? props.lang.extension : void 0,
341
+ props.lang ? language.of(props.lang) : void 0,
316
342
  // Append Linter settings
317
343
  props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
318
344
  // Show 🔴 to error line when linter enabled.
@@ -321,96 +347,105 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
321
347
  props.placeholder ? view.placeholder(props.placeholder) : void 0,
322
348
  // Append Extensions
323
349
  ...props.extensions
324
- ])
350
+ ].filter((extension) => !!extension)
325
351
  )
326
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
+ );
327
362
  vueDemi.watch(
328
363
  () => props.modelValue,
329
- (value) => {
364
+ async (value) => {
330
365
  if (view$1.value.composing) {
331
366
  return;
332
367
  }
333
- if (props.linter && props.forceLinting) {
334
- lint.forceLinting(view$1.value);
335
- }
336
368
  view$1.value.dispatch({
337
369
  changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
338
370
  selection: view$1.value.state.selection,
339
371
  scrollIntoView: true
340
372
  });
373
+ length.value = view$1.value.state.doc.length;
341
374
  },
342
375
  { immediate: true }
343
376
  );
344
- vueDemi.watch(
345
- () => extensions.value,
346
- (exts) => {
347
- view$1.value.dispatch({
348
- effects: state.StateEffect.reconfigure.of(exts)
349
- });
350
- }
351
- );
352
377
  vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
353
378
  vueDemi.onMounted(async () => {
354
379
  let value = doc.value;
355
- if (editor.value && editor.value.childNodes[0]) {
380
+ if (!editor.value) {
381
+ return;
382
+ }
383
+ if (editor.value.childNodes[0]) {
356
384
  if (doc.value !== "") {
357
385
  console.warn(
358
386
  "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
359
387
  );
360
388
  }
361
- value = lodash.trim(editor.value.childNodes[0].innerText);
389
+ value = editor.value.childNodes[0].innerText.trim();
362
390
  }
363
391
  view$1.value = new view.EditorView({
364
- doc: value,
365
- extensions: extensions.value,
366
392
  parent: editor.value,
393
+ state: state.EditorState.create({ doc: value, extensions: extensions.value }),
367
394
  dispatch: (tr) => {
368
395
  view$1.value.update([tr]);
369
- if (tr.changes.empty)
396
+ if (tr.changes.empty || !tr.docChanged) {
370
397
  return;
371
- const v = view$1.value.state.doc.toString();
372
- context.emit("update:modelValue", v);
373
- context.emit("change", view$1.value.state);
398
+ }
399
+ context.emit("update:modelValue", tr.state.doc.toString());
400
+ context.emit("change", tr.state);
374
401
  }
375
402
  });
376
403
  await vueDemi.nextTick();
377
404
  context.emit("ready", {
378
- view: view$1,
405
+ view: view$1.value,
379
406
  state: view$1.value.state,
380
407
  container: editor.value
381
408
  });
382
409
  });
383
410
  vueDemi.onUnmounted(() => {
384
- if (view$1.value) {
385
- view$1.value.destroy();
386
- context.emit("destroy");
387
- }
411
+ view$1.value.destroy();
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.dispatch({
424
+ view$1.value?.dispatch({
396
425
  effects: state.StateEffect.reconfigure.of([])
397
426
  });
398
- view$1.value.dispatch({
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 = () => cursor.value;
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 = () => view$1.value.state.selection.ranges.map(
412
- (r) => view$1.value.state.sliceDoc(r.from, r.to)
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) => cursor.value = 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)
@@ -430,11 +465,13 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
430
465
  });
431
466
  context.expose({
432
467
  editor,
468
+ view: view$1,
433
469
  cursor,
434
470
  selection,
435
- state: state$1,
436
471
  focus,
437
472
  length,
473
+ json,
474
+ diagnosticCount,
438
475
  lint: lint$1,
439
476
  forceReconfigure,
440
477
  // Bellow is CodeMirror5's function
@@ -459,19 +496,16 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
459
496
  },
460
497
  render() {
461
498
  return h(
462
- // @ts-ignore
463
499
  this.$props.tag,
464
500
  {
465
501
  ref: "editor",
466
502
  class: "vue-codemirror"
467
503
  },
468
- // @ts-ignore
469
504
  this.$slots.default ? (
470
505
  // Hide original content
471
506
  h(
472
507
  "aside",
473
508
  { style: "display: none;", "aria-hidden": "true" },
474
- // @ts-ignore
475
509
  slot(this.$slots.default)
476
510
  )
477
511
  ) : void 0
@@ -480,8 +514,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
480
514
  });
481
515
 
482
516
  const meta = {
483
- version: "1.1.15",
484
- date: "2023-03-14T09:58:31.925Z"
517
+ version: "1.1.18",
518
+ date: "2023-04-04T00:08:06.631Z"
485
519
  };
486
520
 
487
521
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -497,4 +531,4 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
497
531
 
498
532
  return exports;
499
533
 
500
- })({}, VueDemi, lodash, codemirror, state, view, commands, lint);
534
+ })({}, VueDemi, codemirror, view, state, lint, commands);