vue-codemirror6 0.5.3 → 0.6.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
@@ -26,7 +26,8 @@ yarn add vue-codemirror6 @vue/composition-api
26
26
 
27
27
  | Props | Type | Information |
28
28
  | ---------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29
- | basic | boolean | Use [basic-setup](https://codemirror.net/6/docs/ref/#basic-setup). |
29
+ | basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
30
+ | minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
30
31
  | dark | boolean | Toggle Darkmode. It can be changed in real time, but the input value will return to the initial value. |
31
32
  | wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
32
33
  | tab | boolean | Enables tab indentation. |
@@ -228,6 +229,28 @@ export default defineComponent({
228
229
  </script>
229
230
  ```
230
231
 
232
+ ## Methods
233
+
234
+ | Methods | Description |
235
+ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
236
+ | selection() | Get the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
237
+ | getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
238
+ | getLine(number: number) | Get the content of line. |
239
+ | lineCount() | Get the number of lines in the editor. |
240
+ | getCursor() | Retrieve one end of the primary selection. |
241
+ | listSelections() | Retrieves a list of all current selections. |
242
+ | getSelection() | Get the currently selected code. |
243
+ | getSelections() | The length of the given array should be the same as the number of active selections. |
244
+ | somethingSelected() | Return true if any text is selected. |
245
+ | replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
246
+ | replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
247
+ | setCursor(position: number) | Set the cursor position. |
248
+ | setSelection(anchor: number, head?: number) | Set a single selection range. |
249
+ | setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
250
+ | extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
251
+ | focus() | Set focus |
252
+ | hasFocus() | is Focused |
253
+
231
254
  ## Recommendations
232
255
 
233
256
  Since CodeMirror has a relatively large capacity, when using vite, it is recommended to set it to output as a separate file using the [`manualChunks`](https://vitejs.dev/guide/build.html#chunking-strategy) option at build time as shown below.
@@ -242,10 +265,13 @@ const config: UserConfig = {
242
265
  // ...
243
266
  codemirror: [
244
267
  // Split CodeMirror code.
245
- '@codemirror/basic-setup',
268
+ 'vue-codemirror6'
269
+ 'codemirror',
270
+ '@codemirror/autocomplete',
246
271
  '@codemirror/commands',
247
272
  '@codemirror/language',
248
273
  '@codemirror/lint',
274
+ '@codemirror/search',
249
275
  '@codemirror/state',
250
276
  '@codemirror/view',
251
277
  // Add the following as needed.
@@ -38,12 +38,21 @@ declare const _default: import("vue-demi").DefineComponent<{
38
38
  /**
39
39
  * Use Basic Setup
40
40
  *
41
- * @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
41
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
42
42
  */
43
43
  basic: {
44
44
  type: BooleanConstructor;
45
45
  default: boolean;
46
46
  };
47
+ /**
48
+ * Use Minimal Setup (The basic setting has priority.)
49
+ *
50
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
51
+ */
52
+ minimal: {
53
+ type: BooleanConstructor;
54
+ default: boolean;
55
+ };
47
56
  /**
48
57
  * Line wrapping
49
58
  *
@@ -125,20 +134,20 @@ declare const _default: import("vue-demi").DefineComponent<{
125
134
  context: SetupContext<import("vue-demi").EmitsOptions>;
126
135
  editor: Ref<Element | undefined>;
127
136
  selection: () => EditorSelection;
128
- getRange: (a?: number, b?: number) => string;
129
- getLine: (n: number) => string;
137
+ getRange: (from?: number, to?: number) => string;
138
+ getLine: (number: number) => string;
130
139
  lineCount: () => number;
131
140
  getCursor: () => number;
132
141
  listSelections: () => readonly SelectionRange[];
133
142
  getSelection: () => string;
134
143
  getSelections: () => string[];
135
144
  somethingSelected: () => boolean;
136
- replaceRange: (text: string | Text, from: number, to: number) => void;
137
- replaceSelection: (text: string | Text) => void;
138
- setCursor: (pos: number) => void;
139
- setSelection: (anchor: number, head: number) => void;
140
- setSelections: (ranges: readonly SelectionRange[], mainIndex?: number | undefined) => void;
141
- extendSelectionsBy: (f: any) => void;
145
+ replaceRange: (replacement: string | Text, from: number, to: number) => void;
146
+ replaceSelection: (replacement: string | Text) => void;
147
+ setCursor: (position: number) => void;
148
+ setSelection: (anchor: number, head?: number) => void;
149
+ setSelections: (ranges: readonly SelectionRange[], primary?: number) => void;
150
+ extendSelectionsBy: (f: Function) => void;
142
151
  focus: () => void;
143
152
  hasFocus: () => boolean;
144
153
  }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
@@ -166,12 +175,21 @@ declare const _default: import("vue-demi").DefineComponent<{
166
175
  /**
167
176
  * Use Basic Setup
168
177
  *
169
- * @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
178
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
170
179
  */
171
180
  basic: {
172
181
  type: BooleanConstructor;
173
182
  default: boolean;
174
183
  };
184
+ /**
185
+ * Use Minimal Setup (The basic setting has priority.)
186
+ *
187
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
188
+ */
189
+ minimal: {
190
+ type: BooleanConstructor;
191
+ default: boolean;
192
+ };
175
193
  /**
176
194
  * Line wrapping
177
195
  *
@@ -256,6 +274,7 @@ declare const _default: import("vue-demi").DefineComponent<{
256
274
  };
257
275
  dark: boolean;
258
276
  basic: boolean;
277
+ minimal: boolean;
259
278
  wrap: boolean;
260
279
  tab: boolean;
261
280
  readonly: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AAUjE,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;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;qBAiJI,eAAe;mBAKf,MAAM,MAAM,MAAM,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efs, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
2
- import { EditorState, EditorSelection } from "@codemirror/state";
2
+ import { EditorState, StateEffect, EditorSelection } from "@codemirror/state";
3
3
  import { EditorView, keymap } from "@codemirror/view";
4
4
  import { linter, lintGutter } from "@codemirror/lint";
5
- import { basicSetup } from "@codemirror/basic-setup";
5
+ import { basicSetup, minimalSetup } from "codemirror";
6
6
  import { indentWithTab } from "@codemirror/commands";
7
7
  import { trim, compact } from "lodash";
8
8
  const adaptOnsV3 = (ons) => {
@@ -47,6 +47,10 @@ var CodeMirror = defineComponent({
47
47
  type: Boolean,
48
48
  default: false
49
49
  },
50
+ minimal: {
51
+ type: Boolean,
52
+ default: false
53
+ },
50
54
  wrap: {
51
55
  type: Boolean,
52
56
  default: false
@@ -104,25 +108,25 @@ var CodeMirror = defineComponent({
104
108
  selection: previous
105
109
  }));
106
110
  });
107
- watch(() => props.modelValue, (v) => view.setState(EditorState.create({ doc: v, extensions: getExtensions() })));
111
+ watch(() => props.modelValue, (text) => view.dispatch({
112
+ changes: { from: 0, to: view.state.doc.length, insert: text }
113
+ }));
108
114
  watch(dark, () => {
109
- view.setState(EditorState.create({
110
- doc: doc.value,
111
- extensions: getExtensions()
112
- }));
115
+ view.dispatch({
116
+ effects: StateEffect.appendConfig.of(EditorView.theme(props.theme, { dark: dark.value }))
117
+ });
113
118
  });
114
119
  onMounted(async () => {
120
+ let value = doc.value;
115
121
  if (editor.value && editor.value.childNodes[0]) {
116
122
  if (doc.value !== "") {
117
123
  console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.");
118
124
  }
119
- doc.value = trim(editor.value.childNodes[0].innerText);
125
+ value = trim(editor.value.childNodes[0].innerText);
120
126
  }
121
127
  view = new EditorView({
122
- state: EditorState.create({
123
- doc: doc.value,
124
- extensions: getExtensions()
125
- }),
128
+ doc: value,
129
+ extensions: getExtensions(),
126
130
  parent: editor.value,
127
131
  dispatch: (tr) => {
128
132
  view.update([tr]);
@@ -138,6 +142,7 @@ var CodeMirror = defineComponent({
138
142
  const getExtensions = () => {
139
143
  const extensions = compact([
140
144
  props.basic ? basicSetup : void 0,
145
+ props.minimal && !props.basic ? minimalSetup : void 0,
141
146
  EditorView.updateListener.of((update) => emit("update", update)),
142
147
  EditorView.theme(props.theme, { dark: dark.value }),
143
148
  props.wrap ? EditorView.lineWrapping : void 0,
@@ -150,26 +155,25 @@ var CodeMirror = defineComponent({
150
155
  props.linter && props.lintGutter ? lintGutter() : void 0,
151
156
  ...props.extensions
152
157
  ]);
153
- console.debug("[CodeMirror.vue] Loaded extensions: ", extensions);
154
158
  return extensions;
155
159
  };
156
160
  const selection = () => view.state.selection;
157
- const getRange = (a, b) => view.state.sliceDoc(a, b);
158
- const getLine = (n) => view.state.doc.line(n + 1).text;
161
+ const getRange = (from, to) => view.state.sliceDoc(from, to);
162
+ const getLine = (number) => view.state.doc.line(number + 1).text;
159
163
  const lineCount = () => view.state.doc.lines;
160
164
  const getCursor = () => selection().main.head;
161
165
  const listSelections = () => selection().ranges;
162
166
  const getSelection = () => view.state.sliceDoc(selection().main.from, selection().main.to);
163
167
  const getSelections = () => selection().ranges.map((r) => view.state.sliceDoc(r.from, r.to));
164
168
  const somethingSelected = () => selection().ranges.some((r) => !r.empty);
165
- const replaceRange = (text, from, to) => view.dispatch({
166
- changes: { from, to, insert: text }
169
+ const replaceRange = (replacement, from, to) => view.dispatch({
170
+ changes: { from, to, insert: replacement }
167
171
  });
168
- const replaceSelection = (text) => view.dispatch(view.state.replaceSelection(text));
169
- const setCursor = (pos) => view.dispatch({ selection: { anchor: pos } });
172
+ const replaceSelection = (replacement) => view.dispatch(view.state.replaceSelection(replacement));
173
+ const setCursor = (position) => view.dispatch({ selection: { anchor: position } });
170
174
  const setSelection = (anchor, head) => view.dispatch({ selection: { anchor, head } });
171
- const setSelections = (ranges, mainIndex) => view.dispatch({
172
- selection: EditorSelection.create(ranges, mainIndex)
175
+ const setSelections = (ranges, primary) => view.dispatch({
176
+ selection: EditorSelection.create(ranges, primary)
173
177
  });
174
178
  const extendSelectionsBy = (f) => view.dispatch({
175
179
  selection: EditorSelection.create(selection().ranges.map((r) => r.extend(f(r))))
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/basic-setup"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","@codemirror/basic-setup","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.basicSetup,r.commands,r.lodash))})(this,function(r,n,d,u,p,v,x,S){"use strict";const C=e=>e?Object.entries(e).reduce((l,[i,f])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...l,[i]:f}),{}):null,g=(e,l={},i)=>{if(n.isVue2)return n.h(e,l,i);const{props:f,domProps:a,on:h,...o}=l,m=h?C(h):{};return n.h(e,{...o,...f,...a,...m},i)},V=e=>typeof e=="function"?e():e;var y=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},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,l){const i=n.ref(),{dark:f}=n.toRefs(e),a=n.ref(e.modelValue),h=l.emit;let o;n.watch(a,t=>{if(o.composing)return;const s=o.state.selection;o.setState(d.EditorState.create({doc:t,extensions:m(),selection:s}))}),n.watch(()=>e.modelValue,t=>o.setState(d.EditorState.create({doc:t,extensions:m()}))),n.watch(f,()=>{o.setState(d.EditorState.create({doc:a.value,extensions:m()}))}),n.onMounted(async()=>{i.value&&i.value.childNodes[0]&&(a.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a.value=S.trim(i.value.childNodes[0].innerText)),o=new u.EditorView({state:d.EditorState.create({doc:a.value,extensions:m()}),parent:i.value,dispatch:t=>{o.update([t]),!t.changes.empty&&(a.value=o.state.doc.toString(),h("update:modelValue",a.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const m=()=>{const t=S.compact([e.basic?v.basicSetup:void 0,u.EditorView.updateListener.of(s=>h("update",s)),u.EditorView.theme(e.theme,{dark:f.value}),e.wrap?u.EditorView.lineWrapping:void 0,e.tab?u.keymap.of([x.indentWithTab]):void 0,e.phrases?d.EditorState.phrases.of(e.phrases):void 0,e.readonly?d.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?p.linter(e.linter):void 0,e.linter&&e.lintGutter?p.lintGutter():void 0,...e.extensions]);return console.debug("[CodeMirror.vue] Loaded extensions: ",t),t},c=()=>o.state.selection;return{context:l,editor:i,selection:c,getRange:(t,s)=>o.state.sliceDoc(t,s),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>c().main.head,listSelections:()=>c().ranges,getSelection:()=>o.state.sliceDoc(c().main.from,c().main.to),getSelections:()=>c().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>c().ranges.some(t=>!t.empty),replaceRange:(t,s,w)=>o.dispatch({changes:{from:s,to:w,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>o.dispatch({selection:{anchor:t}}),setSelection:(t,s)=>o.dispatch({selection:{anchor:t,head:s}}),setSelections:(t,s)=>o.dispatch({selection:d.EditorSelection.create(t,s)}),extendSelectionsBy:t=>o.dispatch({selection:d.EditorSelection.create(c().ranges.map(s=>s.extend(t(s))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return g("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?g("aside",{style:"display: none;"},V(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,d,p,g,V,S){"use strict";const C=e=>e?Object.entries(e).reduce((c,[a,l])=>(a=a.charAt(0).toUpperCase()+a.slice(1),a=`on${a}`,{...c,[a]:l}),{}):null,y=(e,c={},a)=>{if(n.isVue2)return n.h(e,c,a);const{props:l,domProps:u,on:m,...o}=c,h=m?C(m):{};return n.h(e,{...o,...l,...u,...h},a)},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,c){const a=n.ref(),{dark:l}=n.toRefs(e),u=n.ref(e.modelValue),m=c.emit;let o;n.watch(u,t=>{if(o.composing)return;const i=o.state.selection;o.setState(f.EditorState.create({doc:t,extensions:h(),selection:i}))}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t}})),n.watch(l,()=>{o.dispatch({effects:f.StateEffect.appendConfig.of(d.EditorView.theme(e.theme,{dark:l.value}))})}),n.onMounted(async()=>{let t=u.value;a.value&&a.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=S.trim(a.value.childNodes[0].innerText)),o=new d.EditorView({doc:t,extensions:h(),parent:a.value,dispatch:i=>{o.update([i]),!i.changes.empty&&(u.value=o.state.doc.toString(),m("update:modelValue",u.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>S.compact([e.basic?g.basicSetup:void 0,e.minimal&&!e.basic?g.minimalSetup:void 0,d.EditorView.updateListener.of(i=>m("update",i)),d.EditorView.theme(e.theme,{dark:l.value}),e.wrap?d.EditorView.lineWrapping:void 0,e.tab?d.keymap.of([V.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?d.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]),s=()=>o.state.selection;return{context:c,editor:a,selection:s,getRange:(t,i)=>o.state.sliceDoc(t,i),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>s().main.head,listSelections:()=>s().ranges,getSelection:()=>o.state.sliceDoc(s().main.from,s().main.to),getSelections:()=>s().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>s().ranges.some(t=>!t.empty),replaceRange:(t,i,E)=>o.dispatch({changes:{from:i,to:E,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>o.dispatch({selection:{anchor:t}}),setSelection:(t,i)=>o.dispatch({selection:{anchor:t,head:i}}),setSelections:(t,i)=>o.dispatch({selection:f.EditorSelection.create(t,i)}),extendSelectionsBy:t=>o.dispatch({selection:f.EditorSelection.create(s().ranges.map(i=>i.extend(t(i))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return y("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?y("aside",{style:"display: none;"},w(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 b=e=>e.component("CodeMirror",y);r.default=y,r.install=b,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ */const x=e=>e.component("CodeMirror",v);r.default=v,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.5.3",
4
+ "version": "0.6.0",
5
5
  "description": "CodeMirror6 Component for vue2 and vue3",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -33,7 +33,7 @@
33
33
  "url": "https://github.com/logue/vue-codemirror6/issues"
34
34
  },
35
35
  "engines": {
36
- "node": ">=16.15.0",
36
+ "node": ">=16.15.1",
37
37
  "yarn": ">=1.22.4"
38
38
  },
39
39
  "packageManager": "yarn@3.2.1",
@@ -64,16 +64,12 @@
64
64
  "prepare": "husky install"
65
65
  },
66
66
  "dependencies": {
67
- "@codemirror/basic-setup": "latest",
68
- "@codemirror/commands": "latest",
69
- "@codemirror/lint": "latest",
70
- "@codemirror/state": "latest",
71
- "@codemirror/view": "latest",
67
+ "codemirror": "^6.0.0",
72
68
  "vue-demi": "latest"
73
69
  },
74
70
  "peerDependencies": {
75
71
  "@vue/composition-api": "^1.6.2",
76
- "vue": "^2.6.14 || ^3.2.36"
72
+ "vue": "^2.6.14 || ^3.2.37"
77
73
  },
78
74
  "peerDependenciesMeta": {
79
75
  "@vue/composition-api": {
@@ -81,15 +77,15 @@
81
77
  }
82
78
  },
83
79
  "devDependencies": {
84
- "@codemirror/lang-javascript": "^0.20.0",
85
- "@codemirror/lang-markdown": "^0.20.1",
80
+ "@codemirror/lang-javascript": "^6.0.0",
81
+ "@codemirror/lang-markdown": "^6.0.0",
86
82
  "@types/lodash": "^4.14.182",
87
- "@types/node": "^17.0.36",
88
- "@typescript-eslint/eslint-plugin": "^5.27.0",
89
- "@typescript-eslint/parser": "^5.27.0",
83
+ "@types/node": "^17.0.41",
84
+ "@typescript-eslint/eslint-plugin": "^5.27.1",
85
+ "@typescript-eslint/parser": "^5.27.1",
90
86
  "@vitejs/plugin-vue": "^2.3.3",
91
87
  "@vue/eslint-config-prettier": "^7.0.0",
92
- "eslint": "^8.16.0",
88
+ "eslint": "^8.17.0",
93
89
  "eslint-config-google": "^0.14.0",
94
90
  "eslint-config-prettier": "^8.5.0",
95
91
  "eslint-import-resolver-alias": "^1.1.2",
@@ -98,22 +94,22 @@
98
94
  "eslint-plugin-import": "^2.26.0",
99
95
  "eslint-plugin-jsdoc": "^39.3.2",
100
96
  "eslint-plugin-tsdoc": "^0.2.16",
101
- "eslint-plugin-vue": "^9.0.1",
102
- "eslint-plugin-vuejs-accessibility": "^1.1.1",
97
+ "eslint-plugin-vue": "^9.1.0",
98
+ "eslint-plugin-vuejs-accessibility": "^1.2.0",
103
99
  "eslint-plugin-yaml": "^0.5.0",
104
100
  "eslint4b-prebuilt": "^6.7.2",
105
101
  "husky": "^8.0.1",
106
- "lint-staged": "^12.4.3",
102
+ "lint-staged": "^13.0.1",
107
103
  "lodash": "^4.17.21",
108
104
  "prettier": "^2.6.2",
109
105
  "rimraf": "^3.0.2",
110
106
  "rollup-plugin-visualizer": "^5.6.0",
111
- "typescript": "^4.7.2",
112
- "vite": "^2.9.9",
107
+ "typescript": "^4.7.3",
108
+ "vite": "^2.9.10",
113
109
  "vite-plugin-checker": "^0.4.6",
114
- "vue": "^3.2.36",
110
+ "vue": "^3.2.37",
115
111
  "vue-eslint-parser": "^9.0.2",
116
- "vue-tsc": "^0.35.2"
112
+ "vue-tsc": "^0.37.3"
117
113
  },
118
114
  "husky": {
119
115
  "hooks": {