vue-codemirror6 1.2.3 → 1.3.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/README.md CHANGED
@@ -51,6 +51,7 @@ This component can handle bidirectional binding by `v-model` like a general Vue
51
51
  | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
52
52
  | linter | LintSource | Set Linter. Enter a linter (eg `esLint([arbitrary rule])` function for `@codemirror/lang-javascript`, `jsonParseLinter()`function for`@codemirror/json`). See the sources for various language libraries for more information. |
53
53
  | linterConfig | Object | see <https://codemirror.net/docs/ref/#lint.linter^config> |
54
+ | forceLinting | boolean | see <https://codemirror.net/docs/ref/#lint.forceLinting> |
54
55
  | gutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
55
56
  | gutterConfig | Object | see <https://codemirror.net/docs/ref/#lint.lintGutter^config> |
56
57
  | tag | string | HTML tags used in the component. (Default is `div` tag.) |
package/dist/Meta.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type MetaInterface from './interfaces/MetaInterface';
1
+ import { default as MetaInterface } from './interfaces/MetaInterface';
2
+
2
3
  declare const meta: MetaInterface;
3
4
  export default meta;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import CodeMirror from './components/CodeMirror';
2
- import Meta from './Meta';
1
+ import { default as CodeMirror } from './components/CodeMirror';
2
+ import { default as Meta } from './Meta';
3
+
3
4
  declare const installCodeMirror: (app: any) => void;
4
5
  export { CodeMirror as default, installCodeMirror as install, Meta };
package/dist/index.es.js CHANGED
@@ -3,31 +3,37 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.3
8
+ * @version 1.3.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
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(
12
+ import { indentWithTab as G } from "@codemirror/commands";
13
+ import { indentUnit as I } from "@codemirror/language";
14
+ import { forceLinting as b, linter as P, lintGutter as Z, diagnosticCount as k } from "@codemirror/lint";
15
+ import { EditorState as s, Compartment as C, StateEffect as y, EditorSelection as w } from "@codemirror/state";
16
+ import { EditorView as r, keymap as q, placeholder as H } from "@codemirror/view";
17
+ import { basicSetup as K, minimalSetup as Q } from "codemirror";
18
+ import { isVue2 as X, h as O, defineComponent as Y, ref as v, shallowRef as ee, computed as c, watch as $, onMounted as te, nextTick as ae, onUnmounted as ne } from "vue-demi";
19
+ const le = {
20
+ version: "1.3.0",
21
+ date: "2024-04-24T08:18:55.338Z"
22
+ };
23
+ var ge = le;
24
+ const ie = (e) => e ? Object.entries(e).reduce((i, [l, u]) => (l = l.charAt(0).toUpperCase() + l.slice(1), l = `on${l}`, { ...i, [l]: u }), {}) : {};
25
+ function B(e, i = {}, l) {
26
+ if (X)
27
+ return O(e, i, l);
28
+ const { props: u, domProps: t, on: d, ...f } = i, m = d ? ie(d) : {};
29
+ return O(
24
30
  e,
25
31
  { ...f, ...u, ...t, ...m },
26
- n
32
+ l
27
33
  );
28
34
  }
29
- const ne = (e) => typeof e == "function" ? e() : e;
30
- var oe = I({
35
+ const oe = (e) => typeof e == "function" ? e() : e;
36
+ var se = Y({
31
37
  /** Component Name */
32
38
  name: "CodeMirror",
33
39
  /** Model Definition */
@@ -49,8 +55,7 @@ var oe = I({
49
55
  */
50
56
  theme: {
51
57
  type: Object,
52
- default: () => {
53
- }
58
+ default: () => ({})
54
59
  },
55
60
  /** Dark Mode */
56
61
  dark: {
@@ -104,6 +109,13 @@ var oe = I({
104
109
  type: Boolean,
105
110
  default: !1
106
111
  },
112
+ /**
113
+ * Tab character
114
+ */
115
+ indentUnit: {
116
+ type: String,
117
+ default: void 0
118
+ },
107
119
  /**
108
120
  * Allow Multiple Selection.
109
121
  *
@@ -218,7 +230,7 @@ var oe = I({
218
230
  */
219
231
  gutter: {
220
232
  type: Boolean,
221
- defalt: !1
233
+ default: !1
222
234
  },
223
235
  /**
224
236
  * Gutter Config
@@ -241,7 +253,7 @@ var oe = I({
241
253
  /** Emits */
242
254
  emits: {
243
255
  /** Model Update */
244
- "update:modelValue": (e) => !0,
256
+ "update:modelValue": (e = "") => !0,
245
257
  /** CodeMirror ViewUpdate */
246
258
  update: (e) => !0,
247
259
  /** CodeMirror onReady */
@@ -259,8 +271,8 @@ var oe = I({
259
271
  * @param props - Props
260
272
  * @param context - Context
261
273
  */
262
- setup(e, o) {
263
- const n = v(), u = v(e.modelValue), t = P(new r()), d = c({
274
+ setup(e, i) {
275
+ const l = v(), u = v(e.modelValue), t = ee(new r()), d = c({
264
276
  get: () => t.value.hasFocus,
265
277
  set: (a) => {
266
278
  a && t.value.focus();
@@ -276,27 +288,29 @@ var oe = I({
276
288
  get: () => t.value.state.toJSON(),
277
289
  set: (a) => t.value.setState(s.fromJSON(a))
278
290
  }
279
- ), p = v(0), g = v(0), h = c(() => {
280
- const a = new w(), l = new w();
291
+ ), S = v(0), g = v(0), h = c(() => {
292
+ const a = new C(), n = new C();
281
293
  return [
282
294
  // Toggle basic setup
283
- e.basic ? H : void 0,
295
+ e.basic ? K : void 0,
284
296
  // Toggle minimal setup
285
- e.minimal && !e.basic ? K : void 0,
297
+ e.minimal && !e.basic ? Q : void 0,
286
298
  // ViewUpdate event listener
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));
299
+ r.updateListener.of((o) => {
300
+ i.emit("focus", t.value.hasFocus), S.value = t.value.state.doc?.length, !(o.changes.empty || !o.docChanged) && (e.linter && (e.forceLinting && b(t.value), g.value = e.linter(t.value).length), i.emit("update", o));
289
301
  }),
290
302
  // Toggle light/dark mode.
291
303
  r.theme(e.theme, { dark: e.dark }),
292
304
  // Toggle line wrapping
293
305
  e.wrap ? r.lineWrapping : void 0,
294
306
  // Indent with tab
295
- e.tab ? Q.of([ae]) : void 0,
307
+ e.tab ? q.of([G]) : void 0,
308
+ // Tab character
309
+ e.indentUnit ? I.of(e.indentUnit) : void 0,
296
310
  // Allow Multiple Selections
297
311
  s.allowMultipleSelections.of(e.allowMultipleSelections),
298
312
  // Indent tab size
299
- e.tabSize ? l.of(s.tabSize.of(e.tabSize)) : void 0,
313
+ e.tabSize ? n.of(s.tabSize.of(e.tabSize)) : void 0,
300
314
  // locale settings
301
315
  e.phrases ? s.phrases.of(e.phrases) : void 0,
302
316
  // Readonly option
@@ -308,16 +322,16 @@ var oe = I({
308
322
  // Lang
309
323
  e.lang ? a.of(e.lang) : void 0,
310
324
  // Append Linter settings
311
- e.linter ? Y(e.linter, e.linterConfig) : void 0,
325
+ e.linter ? P(e.linter, e.linterConfig) : void 0,
312
326
  // Show 🔴 to error line when linter enabled.
313
- e.linter && e.gutter ? ee(e.gutterConfig) : void 0,
327
+ e.linter && e.gutter ? Z(e.gutterConfig) : void 0,
314
328
  // Placeholder
315
- e.placeholder ? X(e.placeholder) : void 0,
329
+ e.placeholder ? H(e.placeholder) : void 0,
316
330
  // Append Extensions
317
331
  ...e.extensions
318
- ].filter((i) => !!i);
332
+ ].filter((o) => !!o);
319
333
  });
320
- C(
334
+ $(
321
335
  h,
322
336
  (a) => {
323
337
  t.value?.dispatch({
@@ -325,7 +339,7 @@ var oe = I({
325
339
  });
326
340
  },
327
341
  { immediate: !0 }
328
- ), C(
342
+ ), $(
329
343
  () => e.modelValue,
330
344
  async (a) => {
331
345
  t.value.composing || // IME fix
@@ -337,64 +351,63 @@ var oe = I({
337
351
  });
338
352
  },
339
353
  { immediate: !0 }
340
- ), Z(async () => {
354
+ ), te(async () => {
341
355
  let a = u.value;
342
- n.value && (n.value.childNodes[0] && (u.value !== "" && console.warn(
356
+ l.value && (l.value.childNodes[0] && (u.value !== "" && console.warn(
343
357
  "[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,
358
+ ), a = l.value.childNodes[0].innerText.trim()), t.value = new r({
359
+ parent: l.value,
346
360
  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), o.emit("change", l.state));
361
+ dispatch: (n) => {
362
+ t.value.update([n]), !(n.changes.empty || !n.docChanged) && (i.emit("update:modelValue", n.state.doc.toString() ?? ""), i.emit("change", n.state));
349
363
  }
350
- }), await k(), o.emit("ready", {
364
+ }), await ae(), i.emit("ready", {
351
365
  view: t.value,
352
366
  state: t.value.state,
353
- container: n.value
367
+ container: l.value
354
368
  }));
355
- }), q(() => {
356
- t.value.destroy(), o.emit("destroy");
369
+ }), ne(() => {
370
+ t.value.destroy(), i.emit("destroy");
357
371
  });
358
372
  const V = () => {
359
- !e.linter || !t.value || (e.forceLinting && $(t.value), g.value = te(t.value.state));
373
+ !e.linter || !t.value || (e.forceLinting && b(t.value), g.value = k(t.value.state));
360
374
  }, j = () => {
361
375
  t.value?.dispatch({
362
376
  effects: y.reconfigure.of([])
363
377
  }), t.value?.dispatch({
364
378
  effects: y.appendConfig.of(h.value)
365
379
  });
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 = () => {
380
+ }, x = (a, n) => t.value.state.sliceDoc(a, n), _ = (a) => t.value.state.doc.line(a + 1).text, L = () => t.value.state.doc.lines, N = () => t.value.state.selection.main.head, U = () => {
367
381
  let a;
368
382
  return (a = t.value.state.selection.ranges) !== null && a !== void 0 ? a : [];
369
- }, D = () => {
383
+ }, z = () => {
370
384
  let a;
371
385
  return (a = t.value.state.sliceDoc(
372
386
  t.value.state.selection.main.from,
373
387
  t.value.state.selection.main.to
374
388
  )) !== null && a !== void 0 ? a : "";
375
- }, E = () => {
389
+ }, T = () => {
376
390
  const a = t.value.state;
377
391
  return a ? a.selection.ranges.map(
378
- (l) => a.sliceDoc(l.from, l.to)
392
+ (n) => a.sliceDoc(n.from, n.to)
379
393
  ) : [];
380
- }, R = () => t.value.state.selection.ranges.some(
394
+ }, D = () => t.value.state.selection.ranges.some(
381
395
  (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
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
389
- f.value.ranges.map((l) => l.extend(a(l)))
396
+ ), E = (a, n, o) => t.value.dispatch({
397
+ changes: { from: n, to: o, insert: a }
398
+ }), R = (a) => t.value.dispatch(t.value.state.replaceSelection(a)), F = (a) => t.value.dispatch({ selection: { anchor: a } }), J = (a, n) => t.value.dispatch({ selection: { anchor: a, head: n } }), A = (a, n) => t.value.dispatch({
399
+ selection: w.create(a, n)
400
+ }), W = (a) => t.value.dispatch({
401
+ selection: w.create(
402
+ f.value.ranges.map((n) => n.extend(a(n)))
390
403
  )
391
- }), S = {
392
- editor: n,
404
+ }), p = {
405
+ editor: l,
393
406
  view: t,
394
407
  cursor: m,
395
408
  selection: f,
396
409
  focus: d,
397
- length: p,
410
+ length: S,
398
411
  json: M,
399
412
  diagnosticCount: g,
400
413
  dom: t.value.contentDOM,
@@ -402,21 +415,21 @@ var oe = I({
402
415
  forceReconfigure: j,
403
416
  // Bellow is CodeMirror5's function
404
417
  getRange: x,
405
- getLine: L,
406
- lineCount: N,
407
- getCursor: z,
408
- listSelections: T,
409
- getSelection: D,
410
- getSelections: E,
411
- somethingSelected: R,
412
- replaceRange: F,
413
- replaceSelection: J,
414
- setCursor: A,
415
- setSelection: U,
416
- setSelections: W,
417
- extendSelectionsBy: _
418
+ getLine: _,
419
+ lineCount: L,
420
+ getCursor: N,
421
+ listSelections: U,
422
+ getSelection: z,
423
+ getSelections: T,
424
+ somethingSelected: D,
425
+ replaceRange: E,
426
+ replaceSelection: R,
427
+ setCursor: F,
428
+ setSelection: J,
429
+ setSelections: A,
430
+ extendSelectionsBy: W
418
431
  };
419
- return o.expose(S), S;
432
+ return i.expose(p), p;
420
433
  },
421
434
  render() {
422
435
  return B(
@@ -430,20 +443,15 @@ var oe = I({
430
443
  B(
431
444
  "aside",
432
445
  { style: "display: none;", "aria-hidden": "true" },
433
- ne(this.$slots.default)
446
+ oe(this.$slots.default)
434
447
  )
435
448
  ) : void 0
436
449
  );
437
450
  }
438
451
  });
439
- const ie = {
440
- version: "1.2.3",
441
- date: "2024-01-19T23:49:21.953Z"
442
- };
443
- var ve = ie;
444
- const me = (e) => e.component("CodeMirror", oe);
452
+ const he = (e) => e.component("CodeMirror", se);
445
453
  export {
446
- ve as Meta,
447
- oe as default,
448
- me as install
454
+ ge as Meta,
455
+ se as default,
456
+ he as install
449
457
  };
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.3
8
+ * @version 1.3.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror=function(u,n,y,r,i,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((c,[o,d])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...c,[o]:d}),{}):{};function p(e,c={},o){if(n.isVue2)return n.h(e,c,o);const{props:d,domProps:t,on:v,...g}=c,h=v?V(v):{};return n.h(e,{...g,...d,...t,...h},o)}const O=e=>typeof e=="function"?e():e;var b=n.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},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:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":e=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,c){const o=n.ref(),d=n.ref(e.modelValue),t=n.shallowRef(new r.EditorView),v=n.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),g=n.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=n.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=n.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),C=n.ref(0),m=n.ref(0),S=n.computed(()=>{const a=new i.Compartment,l=new i.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,r.EditorView.updateListener.of(s=>{c.emit("focus",t.value.hasFocus),C.value=t.value.state.doc.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),c.emit("update",s))}),r.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?r.EditorView.lineWrapping:void 0,e.tab?r.keymap.of([E.indentWithTab]):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?l.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),r.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?r.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});n.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),n.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),n.onMounted(async()=>{let a=d.value;o.value&&(o.value.childNodes[0]&&(d.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()),t.value=new r.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:l=>{t.value.update([l]),!(l.changes.empty||!l.docChanged)&&(c.emit("update:modelValue",l.state.doc),c.emit("change",l.state))}}),await n.nextTick(),c.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),n.onUnmounted(()=>{t.value.destroy(),c.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,l)=>t.value.state.sliceDoc(a,l),z=a=>t.value.state.doc.line(a+1).text,T=()=>t.value.state.doc.lines,R=()=>t.value.state.selection.main.head,_=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(l=>a.sliceDoc(l.from,l.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,l,s)=>t.value.dispatch({changes:{from:l,to:s,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),U=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,l)=>t.value.dispatch({selection:{anchor:a,head:l}}),G=(a,l)=>t.value.dispatch({selection:i.EditorSelection.create(a,l)}),I=a=>t.value.dispatch({selection:i.EditorSelection.create(g.value.ranges.map(l=>l.extend(a(l))))}),w={editor:o,view:t,cursor:h,selection:g,focus:v,length:C,json:B,diagnosticCount:m,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:N,getLine:z,lineCount:T,getCursor:R,listSelections:_,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:U,setSelection:W,setSelections:G,extendSelectionsBy:I};return c.expose(w),w},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.3",date:"2024-01-19T23:49:21.953Z"};const $=e=>e.component("CodeMirror",b);return u.Meta=M,u.default=b,u.install=$,Object.defineProperty(u,"__esModule",{value:!0}),u}({},VueDemi,codemirror,view,state,lint,commands);
12
+ var CodeMirror=function(u,E,V,f,i,c,y,l){"use strict";var O={version:"1.3.0",date:"2024-04-24T08:18:55.338Z"};const $=e=>e?Object.entries(e).reduce((r,[o,s])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...r,[o]:s}),{}):{};function p(e,r={},o){if(l.isVue2)return l.h(e,r,o);const{props:s,domProps:t,on:v,...g}=r,h=v?$(v):{};return l.h(e,{...g,...s,...t,...h},o)}const M=e=>typeof e=="function"?e():e;var b=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:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,r){const o=l.ref(),s=l.ref(e.modelValue),t=l.shallowRef(new c.EditorView),v=l.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),g=l.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=l.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),j=l.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),C=l.ref(0),m=l.ref(0),S=l.computed(()=>{const a=new i.Compartment,n=new i.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(d=>{r.emit("focus",t.value.hasFocus),C.value=t.value.state.doc?.length,!(d.changes.empty||!d.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),r.emit("update",d))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,e.indentUnit?V.indentUnit.of(e.indentUnit):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(d=>!!d)});l.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),l.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
+ `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),l.onMounted(async()=>{let a=s.value;o.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()),t.value=new c.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.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:t.value,state:t.value.state,container:o.value}))}),l.onUnmounted(()=>{t.value.destroy(),r.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,n)=>t.value.state.sliceDoc(a,n),U=a=>t.value.state.doc.line(a+1).text,z=()=>t.value.state.doc.lines,T=()=>t.value.state.selection.main.head,R=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,n,d)=>t.value.dispatch({changes:{from:n,to:d,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),W=a=>t.value.dispatch({selection:{anchor:a}}),G=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),I=(a,n)=>t.value.dispatch({selection:i.EditorSelection.create(a,n)}),Z=a=>t.value.dispatch({selection:i.EditorSelection.create(g.value.ranges.map(n=>n.extend(a(n))))}),w={editor:o,view:t,cursor:h,selection:g,focus:v,length:C,json:j,diagnosticCount:m,dom:t.value.contentDOM,lint:_,forceReconfigure:L,getRange:N,getLine:U,lineCount:z,getCursor:T,listSelections:R,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:W,setSelection:G,setSelections:I,extendSelectionsBy:Z};return r.expose(w),w},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},M(this.$slots.default)):void 0)}});const B=e=>e.component("CodeMirror",b);return u.Meta=O,u.default=b,u.install=B,Object.defineProperty(u,"__esModule",{value:!0}),u}({},commands,language,lint,state,view,codemirror,VueDemi);
package/dist/index.umd.js CHANGED
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.3
8
+ * @version 1.3.0
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- (function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue-demi"),require("codemirror"),require("@codemirror/view"),require("@codemirror/state"),require("@codemirror/lint"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","vue-demi","codemirror","@codemirror/view","@codemirror/state","@codemirror/lint","@codemirror/commands"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.CodeMirror={},l.VueDemi,l.codemirror,l.view,l.state,l.lint,l.commands))})(this,function(l,o,y,c,r,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((d,[i,u])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:u}),{}):{};function p(e,d={},i){if(o.isVue2)return o.h(e,d,i);const{props:u,domProps:t,on:v,...m}=d,h=v?V(v):{};return o.h(e,{...m,...u,...t,...h},i)}const O=e=>typeof e=="function"?e():e;var w=o.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},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:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":e=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const i=o.ref(),u=o.ref(e.modelValue),t=o.shallowRef(new c.EditorView),v=o.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=o.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=o.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=o.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),C=o.ref(0),g=o.ref(0),S=o.computed(()=>{const a=new r.Compartment,n=new r.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),C.value=t.value.state.doc.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),g.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});o.watch(S,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),o.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),o.onMounted(async()=>{let a=u.value;i.value&&(i.value.childNodes[0]&&(u.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()),t.value=new c.EditorView({parent:i.value,state:r.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc),d.emit("change",n.state))}}),await o.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:i.value}))}),o.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),g.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(S.value)})},T=(a,n)=>t.value.state.sliceDoc(a,n),q=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,z=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},R=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},_=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),U=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),W=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),G=a=>t.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))}),b={editor:i,view:t,cursor:h,selection:m,focus:v,length:C,json:B,diagnosticCount:g,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:T,getLine:q,lineCount:x,getCursor:N,listSelections:z,getSelection:R,getSelections:_,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:U,setSelections:W,extendSelectionsBy:G};return d.expose(b),b},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.3",date:"2024-01-19T23:49:21.953Z"};const $=e=>e.component("CodeMirror",w);l.Meta=M,l.default=w,l.install=$,Object.defineProperty(l,"__esModule",{value:!0})});
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,V,v,r,c,p,o){"use strict";var O={version:"1.3.0",date:"2024-04-24T08:18:55.338Z"};const $=e=>e?Object.entries(e).reduce((d,[i,u])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:u}),{}):{};function w(e,d={},i){if(o.isVue2)return o.h(e,d,i);const{props:u,domProps:t,on:m,...h}=d,g=m?$(m):{};return o.h(e,{...h,...u,...t,...g},i)}const M=e=>typeof e=="function"?e():e;var C=o.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:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const i=o.ref(),u=o.ref(e.modelValue),t=o.shallowRef(new c.EditorView),m=o.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),h=o.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),g=o.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),j=o.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),E=o.ref(0),S=o.ref(0),y=o.computed(()=>{const a=new r.Compartment,n=new r.Compartment;return[e.basic?p.basicSetup:void 0,e.minimal&&!e.basic?p.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),E.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&v.forceLinting(t.value),S.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([f.indentWithTab]):void 0,e.indentUnit?V.indentUnit.of(e.indentUnit):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?v.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?v.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});o.watch(y,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),o.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
+ `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),o.onMounted(async()=>{let a=u.value;i.value&&(i.value.childNodes[0]&&(u.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()),t.value=new c.EditorView({parent:i.value,state:r.EditorState.create({doc:a,extensions:y.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()??""),d.emit("change",n.state))}}),await o.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:i.value}))}),o.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&v.forceLinting(t.value),S.value=v.diagnosticCount(t.value.state))},q=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(y.value)})},L=(a,n)=>t.value.state.sliceDoc(a,n),T=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,U=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},z=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},R=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),G=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),I=a=>t.value.dispatch({selection:r.EditorSelection.create(h.value.ranges.map(n=>n.extend(a(n))))}),b={editor:i,view:t,cursor:g,selection:h,focus:m,length:E,json:j,diagnosticCount:S,dom:t.value.contentDOM,lint:_,forceReconfigure:q,getRange:L,getLine:T,lineCount:x,getCursor:N,listSelections:U,getSelection:z,getSelections:R,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:W,setSelections:G,extendSelectionsBy:I};return d.expose(b),b},render(){return w(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?w("aside",{style:"display: none;","aria-hidden":"true"},M(this.$slots.default)):void 0)}});const B=e=>e.component("CodeMirror",C);l.Meta=O,l.default=C,l.install=B,Object.defineProperty(l,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "vue-codemirror6",
4
- "version": "1.2.3",
4
+ "version": "1.3.0",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -55,7 +55,7 @@
55
55
  "engines": {
56
56
  "yarn": ">=1.22.19"
57
57
  },
58
- "packageManager": "yarn@4.0.2",
58
+ "packageManager": "yarn@4.1.0",
59
59
  "sideEffects": false,
60
60
  "scripts": {
61
61
  "dev": "vite",
@@ -79,48 +79,50 @@
79
79
  "vue": "^2.7.14 || ^3.4"
80
80
  },
81
81
  "devDependencies": {
82
- "@codemirror/lang-javascript": "^6.2.1",
82
+ "@codemirror/lang-javascript": "^6.2.2",
83
83
  "@codemirror/lang-json": "^6.0.1",
84
- "@codemirror/lang-markdown": "^6.2.4",
84
+ "@codemirror/lang-markdown": "^6.2.5",
85
85
  "@codemirror/lang-vue": "0.1.2",
86
- "@tsconfig/node-lts": "^20.1.1",
87
- "@types/node": "^20.11.5",
88
- "@typescript-eslint/eslint-plugin": "^6.19.0",
89
- "@vitejs/plugin-vue": "^5.0.3",
90
- "@vue/compiler-sfc": "^3.4.15",
86
+ "@eslint/js": "^9.1.1",
87
+ "@tsconfig/node-lts": "^20.1.3",
88
+ "@types/node": "^20.12.7",
89
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
90
+ "@vitejs/plugin-vue": "^5.0.4",
91
+ "@vue/compiler-sfc": "^3.4.24",
91
92
  "@vue/eslint-config-prettier": "^9.0.0",
92
93
  "@vue/tsconfig": "^0.5.1",
93
- "@vueuse/core": "^10.7.2",
94
- "bootstrap": "^5.3.2",
95
- "eslint": "^8.56.0",
96
- "eslint-config-standard-with-typescript": "^43.0.0",
94
+ "@vueuse/core": "^10.9.0",
95
+ "bootstrap": "^5.3.3",
96
+ "eslint": "^9.1.1",
97
+ "eslint-config-standard-with-typescript": "^43.0.1",
97
98
  "eslint-import-resolver-alias": "^1.1.2",
98
99
  "eslint-import-resolver-typescript": "^3.6.1",
99
- "eslint-linter-browserify": "^8.56.0",
100
- "eslint-plugin-html": "^7.1.0",
100
+ "eslint-linter-browserify": "^9.1.1",
101
+ "eslint-plugin-html": "^8.1.1",
101
102
  "eslint-plugin-import": "^2.29.1",
102
- "eslint-plugin-n": "^16.6.2",
103
+ "eslint-plugin-n": "^17.2.1",
103
104
  "eslint-plugin-promise": "^6.1.1",
104
105
  "eslint-plugin-tsdoc": "^0.2.17",
105
106
  "eslint-plugin-vue": "latest",
106
- "eslint-plugin-vuejs-accessibility": "^2.2.1",
107
+ "eslint-plugin-vuejs-accessibility": "^2.3.0",
107
108
  "eslint-plugin-yaml": "^0.5.0",
108
- "husky": "^8.0.3",
109
- "lint-staged": "^15.2.0",
109
+ "husky": "^9.0.11",
110
+ "lint-staged": "^15.2.2",
110
111
  "npm-run-all": "^4.1.5",
111
- "prettier": "^3.2.4",
112
+ "prettier": "^3.2.5",
112
113
  "rimraf": "^5.0.5",
113
114
  "rollup-plugin-visualizer": "^5.12.0",
114
- "sass": "^1.70.0",
115
- "typescript": "^5.3.3",
116
- "vite": "^5.0.12",
115
+ "sass": "^1.75.0",
116
+ "typescript": "^5.4.5",
117
+ "typescript-eslint": "^7.7.1",
118
+ "vite": "^5.2.10",
117
119
  "vite-plugin-banner": "^0.7.1",
118
- "vite-plugin-checker": "^0.6.2",
119
- "vite-plugin-dts": "^3.7.1",
120
- "vue": "^3.4.15",
121
- "vue-eslint-parser": "^9.4.0",
120
+ "vite-plugin-checker": "^0.6.4",
121
+ "vite-plugin-dts": "^3.9.0",
122
+ "vue": "^3.4.24",
123
+ "vue-eslint-parser": "^9.4.2",
122
124
  "vue-markdown-wasm": "^0.4.0",
123
- "vue-tsc": "^1.8.27"
125
+ "vue-tsc": "^2.0.14"
124
126
  },
125
127
  "husky": {
126
128
  "hooks": {
@@ -132,10 +134,12 @@
132
134
  "*": "prettier -w -u"
133
135
  },
134
136
  "resolutions": {
135
- "json5": "^2.2.3",
136
- "postcss": "^8.4.31",
137
- "semver": "^7.5.3",
138
- "yaml": "^2.3.2",
139
- "vite": ">5.0.5"
137
+ "json5": ">=2.2.3",
138
+ "ip": ">=2.0.1",
139
+ "lodash": ">=4.17.21",
140
+ "postcss": ">=8.4.31",
141
+ "semver": ">=7.5.3",
142
+ "tar": ">=6.2.1",
143
+ "yaml": ">=2.3.2"
140
144
  }
141
145
  }
@@ -1,30 +1,16 @@
1
- import {
2
- computed,
3
- defineComponent,
4
- nextTick,
5
- onMounted,
6
- onUnmounted,
7
- ref,
8
- shallowRef,
9
- watch,
10
- type ComputedRef,
11
- type PropType,
12
- type Ref,
13
- type ShallowRef,
14
- type WritableComputedRef,
15
- } from 'vue-demi';
16
-
17
1
  // Helpers
18
- import h, { slot } from '@/helpers/h-demi';
19
2
 
20
3
  // CodeMirror
21
- import { basicSetup, minimalSetup } from 'codemirror';
4
+ import { indentWithTab } from '@codemirror/commands';
5
+ import { indentUnit, type LanguageSupport } from '@codemirror/language';
22
6
  import {
23
- EditorView,
24
- keymap,
25
- placeholder,
26
- type ViewUpdate,
27
- } from '@codemirror/view';
7
+ diagnosticCount as linterDagnosticCount,
8
+ forceLinting,
9
+ linter,
10
+ lintGutter,
11
+ type Diagnostic,
12
+ type LintSource,
13
+ } from '@codemirror/lint';
28
14
  import {
29
15
  Compartment,
30
16
  EditorSelection,
@@ -37,17 +23,32 @@ import {
37
23
  type Text,
38
24
  } from '@codemirror/state';
39
25
  import {
40
- diagnosticCount as linterDagnosticCount,
41
- forceLinting,
42
- linter,
43
- lintGutter,
44
- type Diagnostic,
45
- type LintSource,
46
- } from '@codemirror/lint';
47
- import { indentWithTab } from '@codemirror/commands';
48
- import type { LanguageSupport } from '@codemirror/language';
26
+ EditorView,
27
+ keymap,
28
+ placeholder,
29
+ type ViewUpdate,
30
+ } from '@codemirror/view';
31
+ import { basicSetup, minimalSetup } from 'codemirror';
32
+ import {
33
+ computed,
34
+ defineComponent,
35
+ nextTick,
36
+ onMounted,
37
+ onUnmounted,
38
+ ref,
39
+ shallowRef,
40
+ watch,
41
+ type ComputedRef,
42
+ type PropType,
43
+ type Ref,
44
+ type ShallowRef,
45
+ type WritableComputedRef,
46
+ } from 'vue-demi';
47
+
49
48
  import type { StyleSpec } from 'style-mod';
50
49
 
50
+ import h, { slot } from '@/helpers/h-demi';
51
+
51
52
  /** CodeMirror Component */
52
53
  export default defineComponent({
53
54
  /** Component Name */
@@ -71,7 +72,9 @@ export default defineComponent({
71
72
  */
72
73
  theme: {
73
74
  type: Object as PropType<Record<string, StyleSpec>>,
74
- default: () => {},
75
+ default: () => {
76
+ return {};
77
+ },
75
78
  },
76
79
  /** Dark Mode */
77
80
  dark: {
@@ -125,6 +128,13 @@ export default defineComponent({
125
128
  type: Boolean,
126
129
  default: false,
127
130
  },
131
+ /**
132
+ * Tab character
133
+ */
134
+ indentUnit: {
135
+ type: String,
136
+ default: undefined,
137
+ },
128
138
  /**
129
139
  * Allow Multiple Selection.
130
140
  *
@@ -208,7 +218,7 @@ export default defineComponent({
208
218
  * @see {@link https://codemirror.net/docs/ref/#lint.linter}
209
219
  */
210
220
  linter: {
211
- type: Function as PropType<LintSource>,
221
+ type: Function as PropType<LintSource | any>,
212
222
  default: undefined,
213
223
  },
214
224
  /**
@@ -241,7 +251,7 @@ export default defineComponent({
241
251
  */
242
252
  gutter: {
243
253
  type: Boolean,
244
- defalt: false,
254
+ default: false,
245
255
  },
246
256
  /**
247
257
  * Gutter Config
@@ -263,19 +273,19 @@ export default defineComponent({
263
273
  /** Emits */
264
274
  emits: {
265
275
  /** Model Update */
266
- 'update:modelValue': (value: string | Text) => true,
276
+ 'update:modelValue': (_value: string | Text = '') => true,
267
277
  /** CodeMirror ViewUpdate */
268
- update: (value: ViewUpdate) => true,
278
+ update: (_value: ViewUpdate) => true,
269
279
  /** CodeMirror onReady */
270
- ready: (value: {
280
+ ready: (_value: {
271
281
  view: EditorView;
272
282
  state: EditorState;
273
283
  container: HTMLElement;
274
284
  }) => true,
275
285
  /** CodeMirror onFocus */
276
- focus: (value: boolean) => true,
286
+ focus: (_value: boolean) => true,
277
287
  /** State Changed */
278
- change: (value: EditorState) => true,
288
+ change: (_value: EditorState) => true,
279
289
  /** CodeMirror onDestroy */
280
290
  destroy: () => true,
281
291
  },
@@ -364,8 +374,9 @@ export default defineComponent({
364
374
  EditorView.updateListener.of((update: ViewUpdate): void => {
365
375
  // Emit focus status
366
376
  context.emit('focus', view.value.hasFocus);
377
+
367
378
  // Update count
368
- length.value = view.value.state.doc.length;
379
+ length.value = view.value.state.doc?.length;
369
380
 
370
381
  if (update.changes.empty || !update.docChanged) {
371
382
  // Suppress event firing if no change
@@ -390,6 +401,8 @@ export default defineComponent({
390
401
  props.wrap ? EditorView.lineWrapping : undefined,
391
402
  // Indent with tab
392
403
  props.tab ? keymap.of([indentWithTab]) : undefined,
404
+ // Tab character
405
+ props.indentUnit ? indentUnit.of(props.indentUnit) : undefined,
393
406
  // Allow Multiple Selections
394
407
  EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
395
408
  // Indent tab size
@@ -478,7 +491,6 @@ export default defineComponent({
478
491
  state: EditorState.create({ doc: value, extensions: extensions.value }),
479
492
  dispatch: (tr: Transaction) => {
480
493
  view.value.update([tr]);
481
-
482
494
  if (tr.changes.empty || !tr.docChanged) {
483
495
  // if not change value, no fire emit event
484
496
  return;
@@ -486,7 +498,7 @@ export default defineComponent({
486
498
 
487
499
  // console.log(view.state.doc.toString(), tr);
488
500
  // state.toString() is not defined, so use toJSON and toText function to convert string.
489
- context.emit('update:modelValue', tr.state.doc);
501
+ context.emit('update:modelValue', tr.state.doc.toString() ?? '');
490
502
  // Emit EditorState
491
503
  context.emit('change', tr.state);
492
504
  },
@@ -656,7 +668,6 @@ export default defineComponent({
656
668
  const extendSelectionsBy = (f: any): void =>
657
669
  view.value.dispatch({
658
670
  selection: EditorSelection.create(
659
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
660
671
  selection.value.ranges.map((r: SelectionRange) => r.extend(f(r)))
661
672
  ),
662
673
  });