vue-codemirror6 1.0.0 → 1.0.2

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.
@@ -0,0 +1,287 @@
1
+ /**
2
+ * vue-codemirror6
3
+ *
4
+ * @description CodeMirror6 Component for vue2 and vue3.
5
+ * @author Logue <logue@hotmail.co.jp>
6
+ * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
+ * @license MIT
8
+ * @version 1.0.2
9
+ * @see {@link https://github.com/logue/vue-codemirror6}
10
+ */
11
+
12
+ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemirror, commands) {
13
+ 'use strict';
14
+
15
+ const adaptOnsV3 = (ons) => {
16
+ if (!ons)
17
+ return {};
18
+ return Object.entries(ons).reduce((ret, [key, handler]) => {
19
+ key = key.charAt(0).toUpperCase() + key.slice(1);
20
+ key = `on${key}`;
21
+ return { ...ret, [key]: handler };
22
+ }, {});
23
+ };
24
+ const h = (type, options = {}, chidren) => {
25
+ if (vueDemi.isVue2 && parseInt(vueDemi.Vue2.version) < 2.7) {
26
+ return vueDemi.h(type, options, chidren);
27
+ }
28
+ const { props, domProps, on, ...extraOptions } = options;
29
+ const ons = on ? adaptOnsV3(on) : {};
30
+ return vueDemi.h(
31
+ type,
32
+ { ...extraOptions, ...props, ...domProps, ...ons },
33
+ chidren
34
+ );
35
+ };
36
+ const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
37
+
38
+ const CodeMirror = vueDemi.defineComponent({
39
+ name: "CodeMirror",
40
+ model: {
41
+ prop: "modelValue",
42
+ event: "update:modelValue"
43
+ },
44
+ props: {
45
+ modelValue: {
46
+ type: String,
47
+ default: ""
48
+ },
49
+ theme: {
50
+ type: Object,
51
+ default: () => {
52
+ return {};
53
+ }
54
+ },
55
+ dark: {
56
+ type: Boolean,
57
+ default: false
58
+ },
59
+ basic: {
60
+ type: Boolean,
61
+ default: false
62
+ },
63
+ minimal: {
64
+ type: Boolean,
65
+ default: false
66
+ },
67
+ wrap: {
68
+ type: Boolean,
69
+ default: false
70
+ },
71
+ tab: {
72
+ type: Boolean,
73
+ default: false
74
+ },
75
+ readonly: {
76
+ type: Boolean,
77
+ default: false
78
+ },
79
+ editable: {
80
+ type: Boolean,
81
+ default: true
82
+ },
83
+ extensions: {
84
+ type: Array,
85
+ default: () => {
86
+ return [];
87
+ }
88
+ },
89
+ phrases: {
90
+ type: Object,
91
+ default: () => void 0
92
+ },
93
+ lang: {
94
+ type: Object,
95
+ default: () => void 0
96
+ },
97
+ linter: {
98
+ type: Function,
99
+ default: void 0
100
+ },
101
+ lintGutter: {
102
+ type: Boolean,
103
+ defalt: false
104
+ },
105
+ tag: {
106
+ type: String,
107
+ default: "div"
108
+ }
109
+ },
110
+ emits: ["update:modelValue", "update", "ready", "focus", "changed"],
111
+ setup(props, context) {
112
+ const editor = vueDemi.ref();
113
+ const doc = vueDemi.ref(props.modelValue);
114
+ const view$1 = vueDemi.shallowRef(new view.EditorView());
115
+ const selection = vueDemi.computed({
116
+ get: () => view$1.value.state.selection,
117
+ set: (s) => view$1.value.dispatch({ selection: s })
118
+ });
119
+ const cursor = vueDemi.computed({
120
+ get: () => selection.value.main.head || 0,
121
+ set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
122
+ });
123
+ const state$1 = vueDemi.computed({
124
+ get: () => view$1.value.state,
125
+ set: (s) => view$1.value.setState(s)
126
+ });
127
+ const focus = vueDemi.computed({
128
+ get: () => view$1.value.hasFocus,
129
+ set: (f) => {
130
+ if (f) {
131
+ view$1.value.focus();
132
+ }
133
+ }
134
+ });
135
+ const extensions = vueDemi.computed(
136
+ () => lodash.compact([
137
+ props.basic ? codemirror.basicSetup : void 0,
138
+ props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
139
+ view.EditorView.updateListener.of(
140
+ (update) => context.emit("update", update)
141
+ ),
142
+ view.EditorView.theme(props.theme, { dark: props.dark }),
143
+ props.wrap ? view.EditorView.lineWrapping : void 0,
144
+ props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
145
+ props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
146
+ state.EditorState.readOnly.of(props.readonly),
147
+ view.EditorView.editable.of(props.editable),
148
+ props.lang ? vueDemi.toRaw(props.lang) : void 0,
149
+ props.linter ? lint.linter(props.linter) : void 0,
150
+ props.linter && props.lintGutter ? lint.lintGutter() : void 0,
151
+ ...props.extensions
152
+ ])
153
+ );
154
+ vueDemi.watch(
155
+ () => props.modelValue,
156
+ (value) => {
157
+ if (!view$1.value || view$1.value.composing) {
158
+ return;
159
+ }
160
+ const previous = view$1.value.state.selection;
161
+ view$1.value.dispatch({
162
+ changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
163
+ selection: previous
164
+ });
165
+ },
166
+ { immediate: true }
167
+ );
168
+ vueDemi.watch(extensions, (e) => {
169
+ view$1.value.dispatch({
170
+ effects: state.StateEffect.reconfigure.of(e)
171
+ });
172
+ });
173
+ vueDemi.watch(focus, (isFocus) => {
174
+ context.emit("focus", isFocus);
175
+ });
176
+ vueDemi.onMounted(async () => {
177
+ let value = doc.value;
178
+ if (editor.value && editor.value.childNodes[0]) {
179
+ if (doc.value !== "") {
180
+ console.warn(
181
+ "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
182
+ );
183
+ }
184
+ value = lodash.trim(editor.value.childNodes[0].innerText);
185
+ }
186
+ view$1.value = new view.EditorView({
187
+ doc: value,
188
+ extensions: extensions.value,
189
+ parent: editor.value,
190
+ dispatch: (tr) => {
191
+ view$1.value.update([tr]);
192
+ if (tr.changes.empty)
193
+ return;
194
+ const v = view$1.value.state.doc.toString();
195
+ context.emit("update:modelValue", v);
196
+ context.emit("changed", v);
197
+ }
198
+ });
199
+ await vueDemi.nextTick();
200
+ context.emit("ready", {
201
+ view: view$1,
202
+ state: state$1.value,
203
+ container: editor.value
204
+ });
205
+ });
206
+ vueDemi.onUnmounted(() => view$1.value.destroy());
207
+ const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
208
+ const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
209
+ const lineCount = () => view$1.value.state.doc.lines;
210
+ const getCursor = () => cursor.value;
211
+ const listSelections = () => view$1.value.state.selection.ranges;
212
+ const getSelection = () => view$1.value.state.sliceDoc(
213
+ view$1.value.state.selection.main.from,
214
+ view$1.value.state.selection.main.to
215
+ );
216
+ const getSelections = () => view$1.value.state.selection.ranges.map(
217
+ (r) => view$1.value.state.sliceDoc(r.from, r.to)
218
+ );
219
+ const somethingSelected = () => view$1.value.state.selection.ranges.some(
220
+ (r) => !r.empty
221
+ );
222
+ const replaceRange = (replacement, from, to) => view$1.value.dispatch({
223
+ changes: { from, to, insert: replacement }
224
+ });
225
+ const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
226
+ const setCursor = (position) => cursor.value = position;
227
+ const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
228
+ const setSelections = (ranges, primary) => view$1.value.dispatch({
229
+ selection: state.EditorSelection.create(ranges, primary)
230
+ });
231
+ const extendSelectionsBy = (f) => view$1.value.dispatch({
232
+ selection: state.EditorSelection.create(
233
+ selection.value.ranges.map((r) => r.extend(f(r)))
234
+ )
235
+ });
236
+ return {
237
+ context,
238
+ editor,
239
+ cursor,
240
+ selection,
241
+ state: state$1,
242
+ focus,
243
+ getRange,
244
+ getLine,
245
+ lineCount,
246
+ getCursor,
247
+ listSelections,
248
+ getSelection,
249
+ getSelections,
250
+ somethingSelected,
251
+ replaceRange,
252
+ replaceSelection,
253
+ setCursor,
254
+ setSelection,
255
+ setSelections,
256
+ extendSelectionsBy
257
+ };
258
+ },
259
+ render() {
260
+ return h(
261
+ this.$props.tag,
262
+ {
263
+ ref: "editor",
264
+ class: "vue-codemirror"
265
+ },
266
+ this.$slots.default ? h(
267
+ "aside",
268
+ { style: "display: none;", "aria-hidden": "true" },
269
+ slot(this.$slots.default)
270
+ ) : void 0
271
+ );
272
+ }
273
+ });
274
+
275
+ const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
276
+ if (typeof window !== "undefined" && window.Vue) {
277
+ window.Vue.use(CodeMirror);
278
+ }
279
+
280
+ exports.default = CodeMirror;
281
+ exports.install = installCodeMirror;
282
+
283
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
284
+
285
+ return exports;
286
+
287
+ })({}, VueDemi, lodash, state, view, lint, codemirror, commands);
package/dist/index.umd.js CHANGED
@@ -1,12 +1,288 @@
1
1
  /**
2
2
  * vue-codemirror6
3
3
  *
4
- * @description CodeMirror6 Component for vue2 and vue3
4
+ * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.0.0
8
+ * @version 1.0.2
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue-demi"),require("lodash"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","vue-demi","lodash","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.CodeMirror={},i.VueDemi,i.lodash,i.state,i.view,i.lint,i.codemirror,i.commands))})(this,function(i,a,p,u,r,g,y,C){"use strict";const b=o=>o?Object.entries(o).reduce((s,[n,c])=>(n=n.charAt(0).toUpperCase()+n.slice(1),n=`on${n}`,{...s,[n]:c}),{}):{},S=(o,s={},n)=>{if(a.isVue2&&parseInt(a.Vue2.version)<2.7)return a.h(o,s,n);const{props:c,domProps:t,on:d,...f}=s,m=d?b(d):{};return a.h(o,{...f,...c,...t,...m},n)},E=o=>typeof o=="function"?o():o,h=a.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","ready","focus","changed"],setup(o,s){const n=a.ref(),c=a.ref(o.modelValue),t=a.shallowRef(new r.EditorView),d=a.computed({get:()=>t.value.state.selection,set:e=>t.value.dispatch({selection:e})}),f=a.computed({get:()=>d.value.main.head||0,set:e=>t.value.dispatch({selection:{anchor:e}})}),m=a.computed({get:()=>t.value.state,set:e=>t.value.setState(e)}),w=a.computed({get:()=>t.value.hasFocus,set:e=>{e&&t.value.focus()}}),V=a.computed(()=>p.compact([o.basic?y.basicSetup:void 0,o.minimal&&!o.basic?y.minimalSetup:void 0,r.EditorView.updateListener.of(e=>s.emit("update",e)),r.EditorView.theme(o.theme,{dark:o.dark}),o.wrap?r.EditorView.lineWrapping:void 0,o.tab?r.keymap.of([C.indentWithTab]):void 0,o.phrases?u.EditorState.phrases.of(o.phrases):void 0,o.readonly?u.EditorState.readOnly.of(o.readonly):void 0,o.editable?r.EditorView.editable.of(o.editable):void 0,o.lang?a.toRaw(o.lang):void 0,o.linter?g.linter(o.linter):void 0,o.linter&&o.lintGutter?g.lintGutter():void 0,...o.extensions]));return a.watch(()=>o.modelValue,e=>{!t.value||t.value.composing||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:e},selection:d.value})},{immediate:!0}),a.watch(V,e=>{t.value.dispatch({effects:u.StateEffect.reconfigure.of(e)})}),a.watch(w,e=>{s.emit("focus",e)}),a.onMounted(async()=>{let e=c.value;n.value&&n.value.childNodes[0]&&(c.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),e=p.trim(n.value.childNodes[0].innerText)),t.value=new r.EditorView({doc:e,extensions:V.value,parent:n.value,dispatch:l=>{if(t.value.update([l]),l.changes.empty)return;const v=t.value.state.doc.toString();s.emit("update:modelValue",v),s.emit("changed",v)}}),await a.nextTick(),s.emit("ready",{view:t,state:m.value,container:n.value})}),a.onUnmounted(()=>t.value.destroy()),{context:s,editor:n,cursor:f,selection:d,state:m,focus:w,getRange:(e,l)=>t.value.state.sliceDoc(e,l),getLine:e=>t.value.state.doc.line(e+1).text,lineCount:()=>t.value.state.doc.lines,getCursor:()=>f.value,listSelections:()=>t.value.state.selection.ranges,getSelection:()=>t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to),getSelections:()=>t.value.state.selection.ranges.map(e=>t.value.state.sliceDoc(e.from,e.to)),somethingSelected:()=>t.value.state.selection.ranges.some(e=>!e.empty),replaceRange:(e,l,v)=>t.value.dispatch({changes:{from:l,to:v,insert:e}}),replaceSelection:e=>t.value.dispatch(t.value.state.replaceSelection(e)),setCursor:e=>f.value=e,setSelection:(e,l)=>t.value.dispatch({selection:{anchor:e,head:l}}),setSelections:(e,l)=>t.value.dispatch({selection:u.EditorSelection.create(e,l)}),extendSelectionsBy:e=>t.value.dispatch({selection:u.EditorSelection.create(d.value.ranges.map(l=>l.extend(e(l))))})}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;","aria-hidden":"true"},E(this.$slots.default)):void 0)}}),B=o=>o.component("CodeMirror",h);typeof window<"u"&&window.Vue&&window.Vue.use(h),i.default=h,i.install=B,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
12
+ (function (global, factory) {
13
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/lint'), require('codemirror'), require('@codemirror/commands')) :
14
+ typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', '@codemirror/state', '@codemirror/view', '@codemirror/lint', 'codemirror', '@codemirror/commands'], factory) :
15
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.lodash, global.state, global.view, global.lint, global.codemirror, global.commands));
16
+ })(this, (function (exports, vueDemi, lodash, state, view, lint, codemirror, commands) { 'use strict';
17
+
18
+ const adaptOnsV3 = (ons) => {
19
+ if (!ons)
20
+ return {};
21
+ return Object.entries(ons).reduce((ret, [key, handler]) => {
22
+ key = key.charAt(0).toUpperCase() + key.slice(1);
23
+ key = `on${key}`;
24
+ return { ...ret, [key]: handler };
25
+ }, {});
26
+ };
27
+ const h = (type, options = {}, chidren) => {
28
+ if (vueDemi.isVue2 && parseInt(vueDemi.Vue2.version) < 2.7) {
29
+ return vueDemi.h(type, options, chidren);
30
+ }
31
+ const { props, domProps, on, ...extraOptions } = options;
32
+ const ons = on ? adaptOnsV3(on) : {};
33
+ return vueDemi.h(
34
+ type,
35
+ { ...extraOptions, ...props, ...domProps, ...ons },
36
+ chidren
37
+ );
38
+ };
39
+ const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
40
+
41
+ const CodeMirror = vueDemi.defineComponent({
42
+ name: "CodeMirror",
43
+ model: {
44
+ prop: "modelValue",
45
+ event: "update:modelValue"
46
+ },
47
+ props: {
48
+ modelValue: {
49
+ type: String,
50
+ default: ""
51
+ },
52
+ theme: {
53
+ type: Object,
54
+ default: () => {
55
+ return {};
56
+ }
57
+ },
58
+ dark: {
59
+ type: Boolean,
60
+ default: false
61
+ },
62
+ basic: {
63
+ type: Boolean,
64
+ default: false
65
+ },
66
+ minimal: {
67
+ type: Boolean,
68
+ default: false
69
+ },
70
+ wrap: {
71
+ type: Boolean,
72
+ default: false
73
+ },
74
+ tab: {
75
+ type: Boolean,
76
+ default: false
77
+ },
78
+ readonly: {
79
+ type: Boolean,
80
+ default: false
81
+ },
82
+ editable: {
83
+ type: Boolean,
84
+ default: true
85
+ },
86
+ extensions: {
87
+ type: Array,
88
+ default: () => {
89
+ return [];
90
+ }
91
+ },
92
+ phrases: {
93
+ type: Object,
94
+ default: () => void 0
95
+ },
96
+ lang: {
97
+ type: Object,
98
+ default: () => void 0
99
+ },
100
+ linter: {
101
+ type: Function,
102
+ default: void 0
103
+ },
104
+ lintGutter: {
105
+ type: Boolean,
106
+ defalt: false
107
+ },
108
+ tag: {
109
+ type: String,
110
+ default: "div"
111
+ }
112
+ },
113
+ emits: ["update:modelValue", "update", "ready", "focus", "changed"],
114
+ setup(props, context) {
115
+ const editor = vueDemi.ref();
116
+ const doc = vueDemi.ref(props.modelValue);
117
+ const view$1 = vueDemi.shallowRef(new view.EditorView());
118
+ const selection = vueDemi.computed({
119
+ get: () => view$1.value.state.selection,
120
+ set: (s) => view$1.value.dispatch({ selection: s })
121
+ });
122
+ const cursor = vueDemi.computed({
123
+ get: () => selection.value.main.head || 0,
124
+ set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
125
+ });
126
+ const state$1 = vueDemi.computed({
127
+ get: () => view$1.value.state,
128
+ set: (s) => view$1.value.setState(s)
129
+ });
130
+ const focus = vueDemi.computed({
131
+ get: () => view$1.value.hasFocus,
132
+ set: (f) => {
133
+ if (f) {
134
+ view$1.value.focus();
135
+ }
136
+ }
137
+ });
138
+ const extensions = vueDemi.computed(
139
+ () => lodash.compact([
140
+ props.basic ? codemirror.basicSetup : void 0,
141
+ props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
142
+ view.EditorView.updateListener.of(
143
+ (update) => context.emit("update", update)
144
+ ),
145
+ view.EditorView.theme(props.theme, { dark: props.dark }),
146
+ props.wrap ? view.EditorView.lineWrapping : void 0,
147
+ props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
148
+ props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
149
+ state.EditorState.readOnly.of(props.readonly),
150
+ view.EditorView.editable.of(props.editable),
151
+ props.lang ? vueDemi.toRaw(props.lang) : void 0,
152
+ props.linter ? lint.linter(props.linter) : void 0,
153
+ props.linter && props.lintGutter ? lint.lintGutter() : void 0,
154
+ ...props.extensions
155
+ ])
156
+ );
157
+ vueDemi.watch(
158
+ () => props.modelValue,
159
+ (value) => {
160
+ if (!view$1.value || view$1.value.composing) {
161
+ return;
162
+ }
163
+ const previous = view$1.value.state.selection;
164
+ view$1.value.dispatch({
165
+ changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
166
+ selection: previous
167
+ });
168
+ },
169
+ { immediate: true }
170
+ );
171
+ vueDemi.watch(extensions, (e) => {
172
+ view$1.value.dispatch({
173
+ effects: state.StateEffect.reconfigure.of(e)
174
+ });
175
+ });
176
+ vueDemi.watch(focus, (isFocus) => {
177
+ context.emit("focus", isFocus);
178
+ });
179
+ vueDemi.onMounted(async () => {
180
+ let value = doc.value;
181
+ if (editor.value && editor.value.childNodes[0]) {
182
+ if (doc.value !== "") {
183
+ console.warn(
184
+ "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
185
+ );
186
+ }
187
+ value = lodash.trim(editor.value.childNodes[0].innerText);
188
+ }
189
+ view$1.value = new view.EditorView({
190
+ doc: value,
191
+ extensions: extensions.value,
192
+ parent: editor.value,
193
+ dispatch: (tr) => {
194
+ view$1.value.update([tr]);
195
+ if (tr.changes.empty)
196
+ return;
197
+ const v = view$1.value.state.doc.toString();
198
+ context.emit("update:modelValue", v);
199
+ context.emit("changed", v);
200
+ }
201
+ });
202
+ await vueDemi.nextTick();
203
+ context.emit("ready", {
204
+ view: view$1,
205
+ state: state$1.value,
206
+ container: editor.value
207
+ });
208
+ });
209
+ vueDemi.onUnmounted(() => view$1.value.destroy());
210
+ const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
211
+ const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
212
+ const lineCount = () => view$1.value.state.doc.lines;
213
+ const getCursor = () => cursor.value;
214
+ const listSelections = () => view$1.value.state.selection.ranges;
215
+ const getSelection = () => view$1.value.state.sliceDoc(
216
+ view$1.value.state.selection.main.from,
217
+ view$1.value.state.selection.main.to
218
+ );
219
+ const getSelections = () => view$1.value.state.selection.ranges.map(
220
+ (r) => view$1.value.state.sliceDoc(r.from, r.to)
221
+ );
222
+ const somethingSelected = () => view$1.value.state.selection.ranges.some(
223
+ (r) => !r.empty
224
+ );
225
+ const replaceRange = (replacement, from, to) => view$1.value.dispatch({
226
+ changes: { from, to, insert: replacement }
227
+ });
228
+ const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
229
+ const setCursor = (position) => cursor.value = position;
230
+ const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
231
+ const setSelections = (ranges, primary) => view$1.value.dispatch({
232
+ selection: state.EditorSelection.create(ranges, primary)
233
+ });
234
+ const extendSelectionsBy = (f) => view$1.value.dispatch({
235
+ selection: state.EditorSelection.create(
236
+ selection.value.ranges.map((r) => r.extend(f(r)))
237
+ )
238
+ });
239
+ return {
240
+ context,
241
+ editor,
242
+ cursor,
243
+ selection,
244
+ state: state$1,
245
+ focus,
246
+ getRange,
247
+ getLine,
248
+ lineCount,
249
+ getCursor,
250
+ listSelections,
251
+ getSelection,
252
+ getSelections,
253
+ somethingSelected,
254
+ replaceRange,
255
+ replaceSelection,
256
+ setCursor,
257
+ setSelection,
258
+ setSelections,
259
+ extendSelectionsBy
260
+ };
261
+ },
262
+ render() {
263
+ return h(
264
+ this.$props.tag,
265
+ {
266
+ ref: "editor",
267
+ class: "vue-codemirror"
268
+ },
269
+ this.$slots.default ? h(
270
+ "aside",
271
+ { style: "display: none;", "aria-hidden": "true" },
272
+ slot(this.$slots.default)
273
+ ) : void 0
274
+ );
275
+ }
276
+ });
277
+
278
+ const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
279
+ if (typeof window !== "undefined" && window.Vue) {
280
+ window.Vue.use(CodeMirror);
281
+ }
282
+
283
+ exports.default = CodeMirror;
284
+ exports.install = installCodeMirror;
285
+
286
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
287
+
288
+ }));
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "vue-codemirror6",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "license": "MIT",
6
- "description": "CodeMirror6 Component for vue2 and vue3",
6
+ "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
8
8
  "vuejs",
9
9
  "vue",
@@ -54,7 +54,7 @@
54
54
  "node": ">=16.17.0",
55
55
  "yarn": ">=1.22.10"
56
56
  },
57
- "packageManager": "yarn@3.2.2",
57
+ "packageManager": "yarn@3.2.3",
58
58
  "sideEffects": false,
59
59
  "scripts": {
60
60
  "dev": "vite",
@@ -74,7 +74,7 @@
74
74
  "peerDependencies": {
75
75
  "@vue/composition-api": "^1.7.0",
76
76
  "codemirror": "^6.0.1",
77
- "vue": "^2.6.14 || ^3.2.37"
77
+ "vue": "^2.6.14 || ^3.2.39"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@vue/composition-api": {
@@ -84,24 +84,24 @@
84
84
  "devDependencies": {
85
85
  "@codemirror/lang-javascript": "^6.0.2",
86
86
  "@codemirror/lang-markdown": "^6.0.1",
87
- "@types/lodash": "^4.14.184",
88
- "@types/node": "^18.7.8",
89
- "@typescript-eslint/eslint-plugin": "^5.33.1",
90
- "@typescript-eslint/parser": "^5.33.1",
91
- "@vitejs/plugin-vue": "^3.0.3",
87
+ "@types/lodash": "^4.14.185",
88
+ "@types/node": "^18.7.18",
89
+ "@typescript-eslint/eslint-plugin": "^5.37.0",
90
+ "@typescript-eslint/parser": "^5.37.0",
91
+ "@vitejs/plugin-vue": "^3.1.0",
92
92
  "@vue/eslint-config-prettier": "^7.0.0",
93
93
  "@vue/tsconfig": "^0.1.3",
94
94
  "codemirror": "^6.0.1",
95
- "eslint": "^8.22.0",
95
+ "eslint": "^8.23.1",
96
96
  "eslint-config-google": "^0.14.0",
97
97
  "eslint-config-prettier": "^8.5.0",
98
98
  "eslint-import-resolver-alias": "^1.1.2",
99
- "eslint-import-resolver-typescript": "^3.4.2",
99
+ "eslint-import-resolver-typescript": "^3.5.1",
100
100
  "eslint-plugin-html": "^7.1.0",
101
101
  "eslint-plugin-import": "^2.26.0",
102
102
  "eslint-plugin-jsdoc": "^39.3.6",
103
- "eslint-plugin-tsdoc": "^0.2.16",
104
- "eslint-plugin-vue": "^9.3.0",
103
+ "eslint-plugin-tsdoc": "^0.2.17",
104
+ "eslint-plugin-vue": "^9.4.0",
105
105
  "eslint-plugin-vuejs-accessibility": "^1.2.0",
106
106
  "eslint-plugin-yaml": "^0.5.0",
107
107
  "eslint4b-prebuilt": "^6.7.2",
@@ -110,14 +110,14 @@
110
110
  "lodash": "^4.17.21",
111
111
  "prettier": "^2.7.1",
112
112
  "rimraf": "^3.0.2",
113
- "rollup-plugin-visualizer": "^5.7.1",
114
- "typescript": "^4.7.4",
115
- "vite": "^3.0.9",
116
- "vite-plugin-banner": "^0.3.0",
117
- "vite-plugin-checker": "^0.4.9",
118
- "vue": "^3.2.37",
119
- "vue-eslint-parser": "^9.0.3",
120
- "vue-tsc": "^0.40.1"
113
+ "rollup-plugin-visualizer": "^5.8.1",
114
+ "typescript": "^4.8.3",
115
+ "vite": "^3.1.1",
116
+ "vite-plugin-banner": "^0.5.0",
117
+ "vite-plugin-checker": "^0.5.1",
118
+ "vue": "^3.2.39",
119
+ "vue-eslint-parser": "^9.1.0",
120
+ "vue-tsc": "^0.40.13"
121
121
  },
122
122
  "husky": {
123
123
  "hooks": {