vue-codemirror6 1.1.32 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -9,37 +9,25 @@
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- import { isVue2, h as h$1, defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
13
- import { basicSetup, minimalSetup } from 'codemirror';
14
- import { EditorView, keymap, placeholder } from '@codemirror/view';
15
- import { EditorState, Compartment, StateEffect, EditorSelection } from '@codemirror/state';
16
- import { forceLinting, linter, lintGutter, diagnosticCount } from '@codemirror/lint';
17
- import { indentWithTab } from '@codemirror/commands';
18
-
19
- const adaptOnsV3 = (ons) => {
20
- if (!ons)
21
- return {};
22
- return Object.entries(ons).reduce((ret, [key, handler]) => {
23
- key = key.charAt(0).toUpperCase() + key.slice(1);
24
- key = `on${key}`;
25
- return { ...ret, [key]: handler };
26
- }, {});
27
- };
28
- function h(type, options = {}, chidren) {
29
- if (isVue2) {
30
- return h$1(type, options, chidren);
31
- }
32
- const { props, domProps, on, ...extraOptions } = options;
33
- const ons = on ? adaptOnsV3(on) : {};
34
- return h$1(
35
- type,
36
- { ...extraOptions, ...props, ...domProps, ...ons },
37
- chidren
12
+ import { isVue2 as G, h as b, defineComponent as I, ref as v, shallowRef as P, computed as c, watch as C, onMounted as Z, nextTick as k, onUnmounted as q } from "vue-demi";
13
+ import { basicSetup as H, minimalSetup as K } from "codemirror";
14
+ import { EditorView as r, keymap as Q, placeholder as X } from "@codemirror/view";
15
+ import { EditorState as s, Compartment as w, StateEffect as y, EditorSelection as O } from "@codemirror/state";
16
+ import { forceLinting as $, linter as Y, lintGutter as ee, diagnosticCount as te } from "@codemirror/lint";
17
+ import { indentWithTab as ae } from "@codemirror/commands";
18
+ const le = (e) => e ? Object.entries(e).reduce((o, [n, u]) => (n = n.charAt(0).toUpperCase() + n.slice(1), n = `on${n}`, { ...o, [n]: u }), {}) : {};
19
+ function B(e, o = {}, n) {
20
+ if (G)
21
+ return b(e, o, n);
22
+ const { props: u, domProps: t, on: d, ...f } = o, m = d ? le(d) : {};
23
+ return b(
24
+ e,
25
+ { ...f, ...u, ...t, ...m },
26
+ n
38
27
  );
39
28
  }
40
- const slot = (defaultSlots) => typeof defaultSlots === "function" ? defaultSlots() : defaultSlots;
41
-
42
- var CodeMirror = defineComponent({
29
+ const ne = (e) => typeof e == "function" ? e() : e;
30
+ var oe = I({
43
31
  /** Component Name */
44
32
  name: "CodeMirror",
45
33
  /** Model Definition */
@@ -67,7 +55,7 @@ var CodeMirror = defineComponent({
67
55
  /** Dark Mode */
68
56
  dark: {
69
57
  type: Boolean,
70
- default: false
58
+ default: !1
71
59
  },
72
60
  /**
73
61
  * Use Basic Setup
@@ -76,7 +64,7 @@ var CodeMirror = defineComponent({
76
64
  */
77
65
  basic: {
78
66
  type: Boolean,
79
- default: false
67
+ default: !1
80
68
  },
81
69
  /**
82
70
  * Use Minimal Setup (The basic setting has priority.)
@@ -85,7 +73,7 @@ var CodeMirror = defineComponent({
85
73
  */
86
74
  minimal: {
87
75
  type: Boolean,
88
- default: false
76
+ default: !1
89
77
  },
90
78
  /**
91
79
  * Placeholder
@@ -105,7 +93,7 @@ var CodeMirror = defineComponent({
105
93
  */
106
94
  wrap: {
107
95
  type: Boolean,
108
- default: false
96
+ default: !1
109
97
  },
110
98
  /**
111
99
  * Allow tab key indent.
@@ -114,7 +102,7 @@ var CodeMirror = defineComponent({
114
102
  */
115
103
  tab: {
116
104
  type: Boolean,
117
- default: false
105
+ default: !1
118
106
  },
119
107
  /**
120
108
  * Allow Multiple Selection.
@@ -123,7 +111,7 @@ var CodeMirror = defineComponent({
123
111
  */
124
112
  allowMultipleSelections: {
125
113
  type: Boolean,
126
- default: false
114
+ default: !1
127
115
  },
128
116
  /**
129
117
  * Tab size
@@ -150,7 +138,7 @@ var CodeMirror = defineComponent({
150
138
  */
151
139
  readonly: {
152
140
  type: Boolean,
153
- default: false
141
+ default: !1
154
142
  },
155
143
  /**
156
144
  * Disable input.
@@ -162,7 +150,7 @@ var CodeMirror = defineComponent({
162
150
  */
163
151
  disabled: {
164
152
  type: Boolean,
165
- default: false
153
+ default: !1
166
154
  },
167
155
  /**
168
156
  * Additional Extension
@@ -171,9 +159,7 @@ var CodeMirror = defineComponent({
171
159
  */
172
160
  extensions: {
173
161
  type: Array,
174
- default: () => {
175
- return [];
176
- }
162
+ default: () => []
177
163
  },
178
164
  /**
179
165
  * Language Phreses
@@ -182,7 +168,8 @@ var CodeMirror = defineComponent({
182
168
  */
183
169
  phrases: {
184
170
  type: Object,
185
- default: () => void 0
171
+ default: () => {
172
+ }
186
173
  },
187
174
  /**
188
175
  * CodeMirror Language
@@ -191,7 +178,8 @@ var CodeMirror = defineComponent({
191
178
  */
192
179
  lang: {
193
180
  type: Object,
194
- default: () => void 0
181
+ default: () => {
182
+ }
195
183
  },
196
184
  /**
197
185
  * CodeMirror Linter
@@ -209,9 +197,7 @@ var CodeMirror = defineComponent({
209
197
  */
210
198
  linterConfig: {
211
199
  type: Object,
212
- default: () => {
213
- return {};
214
- }
200
+ default: () => ({})
215
201
  },
216
202
  /**
217
203
  * Forces any linters configured to run when the editor is idle to run right away.
@@ -220,7 +206,7 @@ var CodeMirror = defineComponent({
220
206
  */
221
207
  forceLinting: {
222
208
  type: Boolean,
223
- default: false
209
+ default: !1
224
210
  },
225
211
  /**
226
212
  * Show Linter Gutter
@@ -232,7 +218,7 @@ var CodeMirror = defineComponent({
232
218
  */
233
219
  gutter: {
234
220
  type: Boolean,
235
- defalt: false
221
+ defalt: !1
236
222
  },
237
223
  /**
238
224
  * Gutter Config
@@ -241,7 +227,8 @@ var CodeMirror = defineComponent({
241
227
  */
242
228
  gutterConfig: {
243
229
  type: Object,
244
- default: () => void 0
230
+ default: () => {
231
+ }
245
232
  },
246
233
  /**
247
234
  * Using tag
@@ -254,17 +241,17 @@ var CodeMirror = defineComponent({
254
241
  /** Emits */
255
242
  emits: {
256
243
  /** Model Update */
257
- "update:modelValue": (value) => true,
244
+ "update:modelValue": (e) => !0,
258
245
  /** CodeMirror ViewUpdate */
259
- update: (value) => true,
246
+ update: (e) => !0,
260
247
  /** CodeMirror onReady */
261
- ready: (value) => true,
248
+ ready: (e) => !0,
262
249
  /** CodeMirror onFocus */
263
- focus: (value) => true,
250
+ focus: (e) => !0,
264
251
  /** State Changed */
265
- change: (value) => true,
252
+ change: (e) => !0,
266
253
  /** CodeMirror onDestroy */
267
- destroy: () => true
254
+ destroy: () => !0
268
255
  },
269
256
  /**
270
257
  * Setup
@@ -272,238 +259,166 @@ var CodeMirror = defineComponent({
272
259
  * @param props - Props
273
260
  * @param context - Context
274
261
  */
275
- setup(props, context) {
276
- const editor = ref();
277
- const doc = ref(props.modelValue);
278
- const view = shallowRef(new EditorView());
279
- const focus = computed({
280
- get: () => view.value.hasFocus,
281
- set: (f) => {
282
- if (f) {
283
- view.value.focus();
284
- }
262
+ setup(e, o) {
263
+ const n = v(), u = v(e.modelValue), t = P(new r()), d = c({
264
+ get: () => t.value.hasFocus,
265
+ set: (a) => {
266
+ a && t.value.focus();
285
267
  }
286
- });
287
- const selection = computed({
288
- get: () => view.value.state.selection,
289
- set: (s) => view.value.dispatch({ selection: s })
290
- });
291
- const cursor = computed({
292
- get: () => view.value.state.selection.main.head,
293
- set: (a) => view.value.dispatch({ selection: { anchor: a } })
294
- });
295
- const json = computed(
268
+ }), f = c({
269
+ get: () => t.value.state.selection,
270
+ set: (a) => t.value.dispatch({ selection: a })
271
+ }), m = c({
272
+ get: () => t.value.state.selection.main.head,
273
+ set: (a) => t.value.dispatch({ selection: { anchor: a } })
274
+ }), M = c(
296
275
  {
297
- get: () => view.value.state.toJSON(),
298
- set: (j) => view.value.setState(EditorState.fromJSON(j))
276
+ get: () => t.value.state.toJSON(),
277
+ set: (a) => t.value.setState(s.fromJSON(a))
299
278
  }
300
- );
301
- const length = ref(0);
302
- const diagnosticCount$1 = ref(0);
303
- const extensions = computed(() => {
304
- const language = new Compartment();
305
- const tabSize = new Compartment();
279
+ ), p = v(0), g = v(0), h = c(() => {
280
+ const a = new w(), l = new w();
306
281
  return [
307
282
  // Toggle basic setup
308
- props.basic ? basicSetup : void 0,
283
+ e.basic ? H : void 0,
309
284
  // Toggle minimal setup
310
- props.minimal && !props.basic ? minimalSetup : void 0,
285
+ e.minimal && !e.basic ? K : void 0,
311
286
  // ViewUpdate event listener
312
- EditorView.updateListener.of((update) => {
313
- context.emit("focus", view.value.hasFocus);
314
- length.value = view.value.state.doc.length;
315
- if (update.changes.empty || !update.docChanged) {
316
- return;
317
- }
318
- if (props.linter) {
319
- if (props.forceLinting) {
320
- forceLinting(view.value);
321
- }
322
- diagnosticCount$1.value = props.linter(view.value).length;
323
- }
324
- context.emit("update", update);
287
+ r.updateListener.of((i) => {
288
+ o.emit("focus", t.value.hasFocus), p.value = t.value.state.doc.length, !(i.changes.empty || !i.docChanged) && (e.linter && (e.forceLinting && $(t.value), g.value = e.linter(t.value).length), o.emit("update", i));
325
289
  }),
326
290
  // Toggle light/dark mode.
327
- EditorView.theme(props.theme, { dark: props.dark }),
291
+ r.theme(e.theme, { dark: e.dark }),
328
292
  // Toggle line wrapping
329
- props.wrap ? EditorView.lineWrapping : void 0,
293
+ e.wrap ? r.lineWrapping : void 0,
330
294
  // Indent with tab
331
- props.tab ? keymap.of([indentWithTab]) : void 0,
295
+ e.tab ? Q.of([ae]) : void 0,
332
296
  // Allow Multiple Selections
333
- EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
297
+ s.allowMultipleSelections.of(e.allowMultipleSelections),
334
298
  // Indent tab size
335
- props.tabSize ? tabSize.of(EditorState.tabSize.of(props.tabSize)) : void 0,
299
+ e.tabSize ? l.of(s.tabSize.of(e.tabSize)) : void 0,
336
300
  // locale settings
337
- props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
301
+ e.phrases ? s.phrases.of(e.phrases) : void 0,
338
302
  // Readonly option
339
- EditorState.readOnly.of(props.readonly),
303
+ s.readOnly.of(e.readonly),
340
304
  // Editable option
341
- EditorView.editable.of(!props.disabled),
305
+ r.editable.of(!e.disabled),
342
306
  // Set Line break char
343
- props.lineSeparator ? EditorState.lineSeparator.of(props.lineSeparator) : void 0,
307
+ e.lineSeparator ? s.lineSeparator.of(e.lineSeparator) : void 0,
344
308
  // Lang
345
- props.lang ? language.of(props.lang) : void 0,
309
+ e.lang ? a.of(e.lang) : void 0,
346
310
  // Append Linter settings
347
- props.linter ? linter(props.linter, props.linterConfig) : void 0,
311
+ e.linter ? Y(e.linter, e.linterConfig) : void 0,
348
312
  // Show 🔴 to error line when linter enabled.
349
- props.linter && props.gutter ? lintGutter(props.gutterConfig) : void 0,
313
+ e.linter && e.gutter ? ee(e.gutterConfig) : void 0,
350
314
  // Placeholder
351
- props.placeholder ? placeholder(props.placeholder) : void 0,
315
+ e.placeholder ? X(e.placeholder) : void 0,
352
316
  // Append Extensions
353
- ...props.extensions
354
- ].filter((extension) => !!extension);
317
+ ...e.extensions
318
+ ].filter((i) => !!i);
355
319
  });
356
- watch(
357
- extensions,
358
- (exts) => {
359
- view.value?.dispatch({
360
- effects: StateEffect.reconfigure.of(exts)
320
+ C(
321
+ h,
322
+ (a) => {
323
+ t.value?.dispatch({
324
+ effects: y.reconfigure.of(a)
361
325
  });
362
326
  },
363
- { immediate: true }
364
- );
365
- watch(
366
- () => props.modelValue,
367
- async (value) => {
368
- if (view.value.composing || // IME fix
369
- view.value.state.doc.toJSON().join(props.lineSeparator ?? "\n") === value) {
370
- return;
371
- }
372
- view.value.dispatch({
373
- changes: { from: 0, to: view.value.state.doc.length, insert: value },
374
- selection: view.value.state.selection,
375
- scrollIntoView: true
327
+ { immediate: !0 }
328
+ ), C(
329
+ () => e.modelValue,
330
+ async (a) => {
331
+ t.value.composing || // IME fix
332
+ t.value.state.doc.toJSON().join(e.lineSeparator ?? `
333
+ `) === a || t.value.dispatch({
334
+ changes: { from: 0, to: t.value.state.doc.length, insert: a },
335
+ selection: t.value.state.selection,
336
+ scrollIntoView: !0
376
337
  });
377
338
  },
378
- { immediate: true }
379
- );
380
- onMounted(async () => {
381
- let value = doc.value;
382
- if (!editor.value) {
383
- return;
384
- }
385
- if (editor.value.childNodes[0]) {
386
- if (doc.value !== "") {
387
- console.warn(
388
- "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
389
- );
339
+ { immediate: !0 }
340
+ ), Z(async () => {
341
+ let a = u.value;
342
+ n.value && (n.value.childNodes[0] && (u.value !== "" && console.warn(
343
+ "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
344
+ ), a = n.value.childNodes[0].innerText.trim()), t.value = new r({
345
+ parent: n.value,
346
+ state: s.create({ doc: a, extensions: h.value }),
347
+ dispatch: (l) => {
348
+ t.value.update([l]), !(l.changes.empty || !l.docChanged) && (o.emit("update:modelValue", l.state.doc.toString()), o.emit("change", l.state));
390
349
  }
391
- value = editor.value.childNodes[0].innerText.trim();
392
- }
393
- view.value = new EditorView({
394
- parent: editor.value,
395
- state: EditorState.create({ doc: value, extensions: extensions.value }),
396
- dispatch: (tr) => {
397
- view.value.update([tr]);
398
- if (tr.changes.empty || !tr.docChanged) {
399
- return;
400
- }
401
- context.emit("update:modelValue", tr.state.doc.toString());
402
- context.emit("change", tr.state);
403
- }
404
- });
405
- await nextTick();
406
- context.emit("ready", {
407
- view: view.value,
408
- state: view.value.state,
409
- container: editor.value
410
- });
411
- });
412
- onUnmounted(() => {
413
- view.value.destroy();
414
- context.emit("destroy");
350
+ }), await k(), o.emit("ready", {
351
+ view: t.value,
352
+ state: t.value.state,
353
+ container: n.value
354
+ }));
355
+ }), q(() => {
356
+ t.value.destroy(), o.emit("destroy");
415
357
  });
416
- const lint = () => {
417
- if (!props.linter || !view.value) {
418
- return;
419
- }
420
- if (props.forceLinting) {
421
- forceLinting(view.value);
422
- }
423
- diagnosticCount$1.value = diagnosticCount(view.value.state);
424
- };
425
- const forceReconfigure = () => {
426
- view.value?.dispatch({
427
- effects: StateEffect.reconfigure.of([])
428
- });
429
- view.value?.dispatch({
430
- effects: StateEffect.appendConfig.of(extensions.value)
358
+ const V = () => {
359
+ !e.linter || !t.value || (e.forceLinting && $(t.value), g.value = te(t.value.state));
360
+ }, j = () => {
361
+ t.value?.dispatch({
362
+ effects: y.reconfigure.of([])
363
+ }), t.value?.dispatch({
364
+ effects: y.appendConfig.of(h.value)
431
365
  });
432
- };
433
- const getRange = (from, to) => view.value.state.sliceDoc(from, to);
434
- const getLine = (number) => view.value.state.doc.line(number + 1).text;
435
- const lineCount = () => view.value.state.doc.lines;
436
- const getCursor = () => view.value.state.selection.main.head;
437
- const listSelections = () => {
438
- let _view$value$state$sel;
439
- return (_view$value$state$sel = view.value.state.selection.ranges) !== null && _view$value$state$sel !== void 0 ? _view$value$state$sel : [];
440
- };
441
- const getSelection = () => {
442
- let _view$value$state$sli;
443
- return (_view$value$state$sli = view.value.state.sliceDoc(
444
- view.value.state.selection.main.from,
445
- view.value.state.selection.main.to
446
- )) !== null && _view$value$state$sli !== void 0 ? _view$value$state$sli : "";
447
- };
448
- const getSelections = () => {
449
- const s = view.value.state;
450
- if (!s) {
451
- return [];
452
- }
453
- return s.selection.ranges.map(
454
- (r) => s.sliceDoc(r.from, r.to)
455
- );
456
- };
457
- const somethingSelected = () => view.value.state.selection.ranges.some(
458
- (r) => !r.empty
459
- );
460
- const replaceRange = (replacement, from, to) => view.value.dispatch({
461
- changes: { from, to, insert: replacement }
462
- });
463
- const replaceSelection = (replacement) => view.value.dispatch(view.value.state.replaceSelection(replacement));
464
- const setCursor = (position) => view.value.dispatch({ selection: { anchor: position } });
465
- const setSelection = (anchor, head) => view.value.dispatch({ selection: { anchor, head } });
466
- const setSelections = (ranges, primary) => view.value.dispatch({
467
- selection: EditorSelection.create(ranges, primary)
468
- });
469
- const extendSelectionsBy = (f) => view.value.dispatch({
470
- selection: EditorSelection.create(
471
- selection.value.ranges.map((r) => r.extend(f(r)))
366
+ }, x = (a, l) => t.value.state.sliceDoc(a, l), L = (a) => t.value.state.doc.line(a + 1).text, N = () => t.value.state.doc.lines, z = () => t.value.state.selection.main.head, T = () => {
367
+ let a;
368
+ return (a = t.value.state.selection.ranges) !== null && a !== void 0 ? a : [];
369
+ }, D = () => {
370
+ let a;
371
+ return (a = t.value.state.sliceDoc(
372
+ t.value.state.selection.main.from,
373
+ t.value.state.selection.main.to
374
+ )) !== null && a !== void 0 ? a : "";
375
+ }, E = () => {
376
+ const a = t.value.state;
377
+ return a ? a.selection.ranges.map(
378
+ (l) => a.sliceDoc(l.from, l.to)
379
+ ) : [];
380
+ }, R = () => t.value.state.selection.ranges.some(
381
+ (a) => !a.empty
382
+ ), F = (a, l, i) => t.value.dispatch({
383
+ changes: { from: l, to: i, insert: a }
384
+ }), J = (a) => t.value.dispatch(t.value.state.replaceSelection(a)), A = (a) => t.value.dispatch({ selection: { anchor: a } }), U = (a, l) => t.value.dispatch({ selection: { anchor: a, head: l } }), W = (a, l) => t.value.dispatch({
385
+ selection: O.create(a, l)
386
+ }), _ = (a) => t.value.dispatch({
387
+ selection: O.create(
388
+ f.value.ranges.map((l) => l.extend(a(l)))
472
389
  )
473
- });
474
- const exposed = {
475
- editor,
476
- view,
477
- cursor,
478
- selection,
479
- focus,
480
- length,
481
- json,
482
- diagnosticCount: diagnosticCount$1,
483
- dom: view.value.contentDOM,
484
- lint,
485
- forceReconfigure,
390
+ }), S = {
391
+ editor: n,
392
+ view: t,
393
+ cursor: m,
394
+ selection: f,
395
+ focus: d,
396
+ length: p,
397
+ json: M,
398
+ diagnosticCount: g,
399
+ dom: t.value.contentDOM,
400
+ lint: V,
401
+ forceReconfigure: j,
486
402
  // Bellow is CodeMirror5's function
487
- getRange,
488
- getLine,
489
- lineCount,
490
- getCursor,
491
- listSelections,
492
- getSelection,
493
- getSelections,
494
- somethingSelected,
495
- replaceRange,
496
- replaceSelection,
497
- setCursor,
498
- setSelection,
499
- setSelections,
500
- extendSelectionsBy
403
+ getRange: x,
404
+ getLine: L,
405
+ lineCount: N,
406
+ getCursor: z,
407
+ listSelections: T,
408
+ getSelection: D,
409
+ getSelections: E,
410
+ somethingSelected: R,
411
+ replaceRange: F,
412
+ replaceSelection: J,
413
+ setCursor: A,
414
+ setSelection: U,
415
+ setSelections: W,
416
+ extendSelectionsBy: _
501
417
  };
502
- context.expose(exposed);
503
- return exposed;
418
+ return o.expose(S), S;
504
419
  },
505
420
  render() {
506
- return h(
421
+ return B(
507
422
  this.$props.tag,
508
423
  {
509
424
  ref: "editor",
@@ -511,22 +426,23 @@ var CodeMirror = defineComponent({
511
426
  },
512
427
  this.$slots.default ? (
513
428
  // Hide original content
514
- h(
429
+ B(
515
430
  "aside",
516
431
  { style: "display: none;", "aria-hidden": "true" },
517
- slot(this.$slots.default)
432
+ ne(this.$slots.default)
518
433
  )
519
434
  ) : void 0
520
435
  );
521
436
  }
522
437
  });
523
-
524
- const meta = {
438
+ const ie = {
525
439
  version: "1.1.32",
526
- date: "2023-12-12T00:31:01.513Z"
440
+ date: "2023-12-21T01:06:31.106Z"
441
+ };
442
+ var ve = ie;
443
+ const me = (e) => e.component("CodeMirror", oe);
444
+ export {
445
+ ve as Meta,
446
+ oe as default,
447
+ me as install
527
448
  };
528
- var meta$1 = meta;
529
-
530
- const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
531
-
532
- export { meta$1 as Meta, CodeMirror as default, installCodeMirror as install };