vue-codemirror6 0.6.1 → 0.6.4

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
@@ -61,6 +61,7 @@ Notice: `lang` and `linter` can also be set together in `extensions`. This is de
61
61
 
62
62
  - [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
63
63
  - [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
64
+ - [`codemirror6-bootstrap-theme`](https://github.com/logue/codemirror6-bootstrap-theme)
64
65
 
65
66
  ## Example
66
67
 
@@ -12,7 +12,6 @@ export interface CodeMirrorEmitsInterface {
12
12
  /** CodeMirror ViewUpdate */
13
13
  (e: 'update', value: ViewUpdate): void;
14
14
  }
15
- /** CodeMirror Component */
16
15
  declare const _default: import("vue-demi").DefineComponent<{
17
16
  /** Model value */
18
17
  modelValue: {
@@ -135,7 +134,7 @@ declare const _default: import("vue-demi").DefineComponent<{
135
134
  editor: Ref<Element | undefined>;
136
135
  cursor: Ref<number>;
137
136
  selection: () => EditorSelection;
138
- getRange: (from?: number, to?: number) => string;
137
+ getRange: (from?: number | undefined, to?: number | undefined) => string;
139
138
  getLine: (number: number) => string;
140
139
  lineCount: () => number;
141
140
  getCursor: () => number;
@@ -146,8 +145,8 @@ declare const _default: import("vue-demi").DefineComponent<{
146
145
  replaceRange: (replacement: string | Text, from: number, to: number) => void;
147
146
  replaceSelection: (replacement: string | Text) => void;
148
147
  setCursor: (position: number) => number;
149
- setSelection: (anchor: number, head?: number) => void;
150
- setSelections: (ranges: readonly SelectionRange[], primary?: number) => void;
148
+ setSelection: (anchor: number, head?: number | undefined) => void;
149
+ setSelections: (ranges: readonly SelectionRange[], primary?: number | undefined) => void;
151
150
  extendSelectionsBy: (f: Function) => void;
152
151
  focus: () => void;
153
152
  hasFocus: () => boolean;
@@ -286,5 +285,6 @@ declare const _default: import("vue-demi").DefineComponent<{
286
285
  linter: LintSource;
287
286
  lintGutter: boolean;
288
287
  }>;
288
+ /** CodeMirror Component */
289
289
  export default _default;
290
290
  //# sourceMappingURL=CodeMirror.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAA4B,MAAM,mBAAmB,CAAC;AAU9E,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,IAAI,EAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAqB;AACrB,MAAM,WAAW,wBAAwB;IACvC,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACrD,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC;AAED,2BAA2B;;IAWvB,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;;qBAgJI,eAAe;sBAUZ,MAAM,OAAO,MAAM,KAAG,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
  }
9
10
  declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) => import("vue-demi").VNode<import("vue-demi").RendererNode, import("vue-demi").RendererElement, {
10
11
  [key: string]: any;
@@ -1 +1 @@
1
- {"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAWD,QAAA,MAAM,CAAC,SACC,MAAM,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,YACtB,OAAO,YACN,GAAG;;EAWd,CAAC;AAEF,QAAA,MAAM,IAAI,iBAAkB,GAAG,QACoC,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD,QAAA,MAAM,CAAC,SACC,MAAM,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,YACtB,OAAO,YACN,GAAG;;EAWd,CAAC;AAEF,QAAA,MAAM,IAAI,iBAAkB,GAAG,QACoC,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAGjD,QAAA,MAAM,iBAAiB,mBAAiD,CAAC;AAEzE,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAGjD,QAAA,MAAM,iBAAiB,mBAAiD,CAAC;AAEzE,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isVue2, h as h$1, defineComponent, ref, toRefs, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
1
+ import { isVue2, h as h$1, defineComponent, ref, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
2
2
  import { StateEffect, EditorState, EditorSelection } from "@codemirror/state";
3
3
  import { EditorView, keymap } from "@codemirror/view";
4
4
  import { linter, lintGutter } from "@codemirror/lint";
@@ -41,7 +41,7 @@ var CodeMirror = defineComponent({
41
41
  },
42
42
  dark: {
43
43
  type: Boolean,
44
- default: false
44
+ default: window.matchMedia("(prefers-color-scheme: dark)").matches
45
45
  },
46
46
  basic: {
47
47
  type: Boolean,
@@ -93,30 +93,20 @@ var CodeMirror = defineComponent({
93
93
  emits: ["update:modelValue", "update"],
94
94
  setup(props, context) {
95
95
  const editor = ref();
96
- const { dark } = toRefs(props);
97
96
  const doc = ref(props.modelValue);
97
+ let view;
98
98
  const cursor = computed({
99
99
  get: () => view.state.selection.main.head,
100
100
  set: (p) => view.dispatch({ selection: { anchor: p } })
101
101
  });
102
102
  const emit = context.emit;
103
- let view;
104
- watch(doc, (value) => {
105
- if (view.composing) {
106
- return;
107
- }
108
- view.dispatch({
109
- changes: { from: 0, to: value.length, insert: value },
110
- selection: { anchor: cursor.value }
111
- });
112
- });
113
103
  watch(() => props.modelValue, (text) => view.dispatch({
114
104
  changes: { from: 0, to: view.state.doc.length, insert: text },
115
105
  selection: { anchor: cursor.value }
116
106
  }));
117
- watch(dark, () => {
107
+ watch(() => props.dark, () => {
118
108
  view.dispatch({
119
- effects: StateEffect.appendConfig.of(EditorView.theme(props.theme, { dark: dark.value }))
109
+ effects: StateEffect.reconfigure.of(getExtensions())
120
110
  });
121
111
  });
122
112
  onMounted(async () => {
@@ -147,7 +137,7 @@ var CodeMirror = defineComponent({
147
137
  props.basic ? basicSetup : void 0,
148
138
  props.minimal && !props.basic ? minimalSetup : void 0,
149
139
  EditorView.updateListener.of((update) => emit("update", update)),
150
- EditorView.theme(props.theme, { dark: dark.value }),
140
+ EditorView.theme(props.theme, { dark: props.dark }),
151
141
  props.wrap ? EditorView.lineWrapping : void 0,
152
142
  props.tab ? keymap.of([indentWithTab]) : void 0,
153
143
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
@@ -210,7 +200,7 @@ var CodeMirror = defineComponent({
210
200
  return h("div", {
211
201
  ref: "editor",
212
202
  class: "vue-codemirror"
213
- }, this.$slots.default ? h("aside", { style: "display: none;" }, slot(this.$slots.default)) : void 0);
203
+ }, this.$slots.default ? h("aside", { style: "display: none;", "aria-hidden": "true" }, slot(this.$slots.default)) : void 0);
214
204
  }
215
205
  });
216
206
  /**
@@ -222,4 +212,7 @@ var CodeMirror = defineComponent({
222
212
  * @see {@link https://github.com/logue/vue-codemirror6}
223
213
  */
224
214
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
215
+ if (typeof window !== "undefined" && window.Vue) {
216
+ window.Vue.use(CodeMirror);
217
+ }
225
218
  export { CodeMirror as default, installCodeMirror as install };
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.codemirror,r.commands,r.lodash))})(this,function(r,n,m,c,p,g,V,y){"use strict";const C=e=>e?Object.entries(e).reduce((d,[i,l])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:l}),{}):null,S=(e,d={},i)=>{if(n.isVue2)return n.h(e,d,i);const{props:l,domProps:u,on:s,...h}=d,o=s?C(s):{};return n.h(e,{...h,...l,...u,...o},i)},w=e=>typeof e=="function"?e():e;var v=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},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update"],setup(e,d){const i=n.ref(),{dark:l}=n.toRefs(e),u=n.ref(e.modelValue),s=n.computed({get:()=>o.state.selection.main.head,set:t=>o.dispatch({selection:{anchor:t}})}),h=d.emit;let o;n.watch(u,t=>{o.composing||o.dispatch({changes:{from:0,to:t.length,insert:t},selection:{anchor:s.value}})}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:{anchor:s.value}})),n.watch(l,()=>{o.dispatch({effects:m.StateEffect.appendConfig.of(c.EditorView.theme(e.theme,{dark:l.value}))})}),n.onMounted(async()=>{let t=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."),t=y.trim(i.value.childNodes[0].innerText)),o=new c.EditorView({doc:t,extensions:E(),parent:i.value,dispatch:a=>{o.update([a]),!a.changes.empty&&(u.value=o.state.doc.toString(),h("update:modelValue",u.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const E=()=>y.compact([e.basic?g.basicSetup:void 0,e.minimal&&!e.basic?g.minimalSetup:void 0,c.EditorView.updateListener.of(a=>h("update",a)),c.EditorView.theme(e.theme,{dark:l.value}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([V.indentWithTab]):void 0,e.phrases?m.EditorState.phrases.of(e.phrases):void 0,e.readonly?m.EditorState.readOnly.of(e.readonly):void 0,e.editable?c.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?p.linter(e.linter):void 0,e.linter&&e.lintGutter?p.lintGutter():void 0,...e.extensions]),f=()=>o.state.selection;return{context:d,editor:i,cursor:s,selection:f,getRange:(t,a)=>o.state.sliceDoc(t,a),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>s.value,listSelections:()=>f().ranges,getSelection:()=>o.state.sliceDoc(f().main.from,f().main.to),getSelections:()=>f().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>f().ranges.some(t=>!t.empty),replaceRange:(t,a,b)=>o.dispatch({changes:{from:a,to:b,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>s.value=t,setSelection:(t,a)=>o.dispatch({selection:{anchor:t,head:a}}),setSelections:(t,a)=>o.dispatch({selection:m.EditorSelection.create(t,a)}),extendSelectionsBy:t=>o.dispatch({selection:m.EditorSelection.create(f().ranges.map(a=>a.extend(t(a))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;"},w(this.$slots.default)):void 0)}});/**
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.codemirror,r.commands,r.lodash))})(this,function(r,n,f,u,g,y,w,S){"use strict";const V=e=>e?Object.entries(e).reduce((d,[i,s])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:s}),{}):null,v=(e,d={},i)=>{if(n.isVue2)return n.h(e,d,i);const{props:s,domProps:o,on:c,...m}=d,h=c?V(c):{};return n.h(e,{...m,...s,...o,...h},i)},C=e=>typeof e=="function"?e():e;var p=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:window.matchMedia("(prefers-color-scheme: dark)").matches},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update"],setup(e,d){const i=n.ref(),s=n.ref(e.modelValue);let o;const c=n.computed({get:()=>o.state.selection.main.head,set:t=>o.dispatch({selection:{anchor:t}})}),m=d.emit;n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:{anchor:c.value}})),n.watch(()=>e.dark,()=>{o.dispatch({effects:f.StateEffect.reconfigure.of(h())})}),n.onMounted(async()=>{let t=s.value;i.value&&i.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=S.trim(i.value.childNodes[0].innerText)),o=new u.EditorView({doc:t,extensions:h(),parent:i.value,dispatch:a=>{o.update([a]),!a.changes.empty&&(s.value=o.state.doc.toString(),m("update:modelValue",s.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>S.compact([e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,u.EditorView.updateListener.of(a=>m("update",a)),u.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?u.EditorView.lineWrapping:void 0,e.tab?u.keymap.of([w.indentWithTab]):void 0,e.phrases?f.EditorState.phrases.of(e.phrases):void 0,e.readonly?f.EditorState.readOnly.of(e.readonly):void 0,e.editable?u.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?g.linter(e.linter):void 0,e.linter&&e.lintGutter?g.lintGutter():void 0,...e.extensions]),l=()=>o.state.selection;return{context:d,editor:i,cursor:c,selection:l,getRange:(t,a)=>o.state.sliceDoc(t,a),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>c.value,listSelections:()=>l().ranges,getSelection:()=>o.state.sliceDoc(l().main.from,l().main.to),getSelections:()=>l().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>l().ranges.some(t=>!t.empty),replaceRange:(t,a,b)=>o.dispatch({changes:{from:a,to:b,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>c.value=t,setSelection:(t,a)=>o.dispatch({selection:{anchor:t,head:a}}),setSelections:(t,a)=>o.dispatch({selection:f.EditorSelection.create(t,a)}),extendSelectionsBy:t=>o.dispatch({selection:f.EditorSelection.create(l().ranges.map(a=>a.extend(t(a))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return v("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?v("aside",{style:"display: none;","aria-hidden":"true"},C(this.$slots.default)):void 0)}});/**
2
2
  * Vue CodeMirror6 Component
3
3
  *
4
4
  * @license MIT
5
5
  * @author Logue {@link logue@hotmail.co.jp}
6
6
  * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
7
7
  * @see {@link https://github.com/logue/vue-codemirror6}
8
- */const x=e=>e.component("CodeMirror",v);r.default=v,r.install=x,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ */const x=e=>e.component("CodeMirror",p);typeof window<"u"&&window.Vue&&window.Vue.use(p),r.default=p,r.install=x,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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": "0.6.1",
4
+ "version": "0.6.4",
5
5
  "description": "CodeMirror6 Component for vue2 and vue3",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -55,7 +55,7 @@
55
55
  "dev": "vite",
56
56
  "clean": "rimraf node_modules/.vite && npx vue-demi-fix",
57
57
  "build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
58
- "build:analyze": "vue-tsc --noEmit && vite build --mode analyze",
58
+ "build:analyze": "vue-tsc --noEmit & vue-tsc --declaration --emitDeclarationOnly & vite build --mode analyze",
59
59
  "build:docs": "vite build --config vite.config.docs.ts",
60
60
  "build:clean": "rimraf dist",
61
61
  "lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
@@ -80,36 +80,36 @@
80
80
  "@codemirror/lang-javascript": "^6.0.0",
81
81
  "@codemirror/lang-markdown": "^6.0.0",
82
82
  "@types/lodash": "^4.14.182",
83
- "@types/node": "^17.0.43",
84
- "@typescript-eslint/eslint-plugin": "^5.28.0",
85
- "@typescript-eslint/parser": "^5.28.0",
83
+ "@types/node": "^18.0.0",
84
+ "@typescript-eslint/eslint-plugin": "^5.30.0",
85
+ "@typescript-eslint/parser": "^5.30.0",
86
86
  "@vitejs/plugin-vue": "^2.3.3",
87
87
  "@vue/eslint-config-prettier": "^7.0.0",
88
- "eslint": "^8.17.0",
88
+ "eslint": "^8.18.0",
89
89
  "eslint-config-google": "^0.14.0",
90
90
  "eslint-config-prettier": "^8.5.0",
91
91
  "eslint-import-resolver-alias": "^1.1.2",
92
- "eslint-import-resolver-typescript": "^2.7.1",
92
+ "eslint-import-resolver-typescript": "^3.1.1",
93
93
  "eslint-plugin-html": "^6.2.0",
94
94
  "eslint-plugin-import": "^2.26.0",
95
- "eslint-plugin-jsdoc": "^39.3.2",
95
+ "eslint-plugin-jsdoc": "^39.3.3",
96
96
  "eslint-plugin-tsdoc": "^0.2.16",
97
97
  "eslint-plugin-vue": "^9.1.1",
98
98
  "eslint-plugin-vuejs-accessibility": "^1.2.0",
99
99
  "eslint-plugin-yaml": "^0.5.0",
100
100
  "eslint4b-prebuilt": "^6.7.2",
101
101
  "husky": "^8.0.1",
102
- "lint-staged": "^13.0.1",
102
+ "lint-staged": "^13.0.3",
103
103
  "lodash": "^4.17.21",
104
- "prettier": "^2.7.0",
104
+ "prettier": "^2.7.1",
105
105
  "rimraf": "^3.0.2",
106
106
  "rollup-plugin-visualizer": "^5.6.0",
107
- "typescript": "^4.7.3",
108
- "vite": "^2.9.12",
107
+ "typescript": "4.6.*",
108
+ "vite": "^2.9.13",
109
109
  "vite-plugin-checker": "^0.4.6",
110
110
  "vue": "^3.2.37",
111
- "vue-eslint-parser": "^9.0.2",
112
- "vue-tsc": "^0.37.8"
111
+ "vue-eslint-parser": "^9.0.3",
112
+ "vue-tsc": "^0.38.2"
113
113
  },
114
114
  "husky": {
115
115
  "hooks": {