vue-codemirror6 1.0.1 → 1.0.3

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.
@@ -5,8 +5,285 @@
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.1
8
+ * @version 1.0.3
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror=function(f,n,m,r,i,p,S,b){"use strict";const C=a=>a?Object.entries(a).reduce((s,[o,d])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...s,[o]:d}),{}):{},y=(a,s={},o)=>{if(n.isVue2&&parseInt(n.Vue2.version)<2.7)return n.h(a,s,o);const{props:d,domProps:t,on:c,...u}=s,v=c?C(c):{};return n.h(a,{...u,...d,...t,...v},o)},E=a=>typeof a=="function"?a():a,g=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","ready","focus","changed"],setup(a,s){const o=n.ref(),d=n.ref(a.modelValue),t=n.shallowRef(new i.EditorView),c=n.computed({get:()=>t.value.state.selection,set:e=>t.value.dispatch({selection:e})}),u=n.computed({get:()=>c.value.main.head||0,set:e=>t.value.dispatch({selection:{anchor:e}})}),v=n.computed({get:()=>t.value.state,set:e=>t.value.setState(e)}),w=n.computed({get:()=>t.value.hasFocus,set:e=>{e&&t.value.focus()}}),V=n.computed(()=>m.compact([a.basic?S.basicSetup:void 0,a.minimal&&!a.basic?S.minimalSetup:void 0,i.EditorView.updateListener.of(e=>s.emit("update",e)),i.EditorView.theme(a.theme,{dark:a.dark}),a.wrap?i.EditorView.lineWrapping:void 0,a.tab?i.keymap.of([b.indentWithTab]):void 0,a.phrases?r.EditorState.phrases.of(a.phrases):void 0,r.EditorState.readOnly.of(a.readonly),i.EditorView.editable.of(a.editable),a.lang?n.toRaw(a.lang):void 0,a.linter?p.linter(a.linter):void 0,a.linter&&a.lintGutter?p.lintGutter():void 0,...a.extensions]));return n.watch(()=>a.modelValue,e=>{!t.value||t.value.composing||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:e},selection:c.value})},{immediate:!0}),n.watch(V,e=>{t.value.dispatch({effects:r.StateEffect.reconfigure.of(e)})}),n.watch(w,e=>{s.emit("focus",e)}),n.onMounted(async()=>{let e=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."),e=m.trim(o.value.childNodes[0].innerText)),t.value=new i.EditorView({doc:e,extensions:V.value,parent:o.value,dispatch:l=>{if(t.value.update([l]),l.changes.empty)return;const h=t.value.state.doc.toString();s.emit("update:modelValue",h),s.emit("changed",h)}}),await n.nextTick(),s.emit("ready",{view:t,state:v.value,container:o.value})}),n.onUnmounted(()=>t.value.destroy()),{context:s,editor:o,cursor:u,selection:c,state:v,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:()=>u.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,h)=>t.value.dispatch({changes:{from:l,to:h,insert:e}}),replaceSelection:e=>t.value.dispatch(t.value.state.replaceSelection(e)),setCursor:e=>u.value=e,setSelection:(e,l)=>t.value.dispatch({selection:{anchor:e,head:l}}),setSelections:(e,l)=>t.value.dispatch({selection:r.EditorSelection.create(e,l)}),extendSelectionsBy:e=>t.value.dispatch({selection:r.EditorSelection.create(c.value.ranges.map(l=>l.extend(e(l))))})}},render(){return y("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?y("aside",{style:"display: none;","aria-hidden":"true"},E(this.$slots.default)):void 0)}}),B=a=>a.component("CodeMirror",g);return typeof window<"u"&&window.Vue&&window.Vue.use(g),f.default=g,f.install=B,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),f}({},VueDemi,lodash,state,view,lint,codemirror,commands);
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
+ value = lodash.trim(editor.value.childNodes[0].innerText);
181
+ }
182
+ view$1.value = new view.EditorView({
183
+ doc: value,
184
+ extensions: extensions.value,
185
+ parent: editor.value,
186
+ dispatch: (tr) => {
187
+ view$1.value.update([tr]);
188
+ if (tr.changes.empty)
189
+ return;
190
+ const v = view$1.value.state.doc.toString();
191
+ context.emit("update:modelValue", v);
192
+ context.emit("changed", v);
193
+ }
194
+ });
195
+ await vueDemi.nextTick();
196
+ context.emit("ready", {
197
+ view: view$1,
198
+ state: state$1.value,
199
+ container: editor.value
200
+ });
201
+ });
202
+ vueDemi.onUnmounted(() => view$1.value.destroy());
203
+ const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
204
+ const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
205
+ const lineCount = () => view$1.value.state.doc.lines;
206
+ const getCursor = () => cursor.value;
207
+ const listSelections = () => view$1.value.state.selection.ranges;
208
+ const getSelection = () => view$1.value.state.sliceDoc(
209
+ view$1.value.state.selection.main.from,
210
+ view$1.value.state.selection.main.to
211
+ );
212
+ const getSelections = () => view$1.value.state.selection.ranges.map(
213
+ (r) => view$1.value.state.sliceDoc(r.from, r.to)
214
+ );
215
+ const somethingSelected = () => view$1.value.state.selection.ranges.some(
216
+ (r) => !r.empty
217
+ );
218
+ const replaceRange = (replacement, from, to) => view$1.value.dispatch({
219
+ changes: { from, to, insert: replacement }
220
+ });
221
+ const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
222
+ const setCursor = (position) => cursor.value = position;
223
+ const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
224
+ const setSelections = (ranges, primary) => view$1.value.dispatch({
225
+ selection: state.EditorSelection.create(ranges, primary)
226
+ });
227
+ const extendSelectionsBy = (f) => view$1.value.dispatch({
228
+ selection: state.EditorSelection.create(
229
+ selection.value.ranges.map((r) => r.extend(f(r)))
230
+ )
231
+ });
232
+ return {
233
+ context,
234
+ editor,
235
+ cursor,
236
+ selection,
237
+ state: state$1,
238
+ focus,
239
+ getRange,
240
+ getLine,
241
+ lineCount,
242
+ getCursor,
243
+ listSelections,
244
+ getSelection,
245
+ getSelections,
246
+ somethingSelected,
247
+ replaceRange,
248
+ replaceSelection,
249
+ setCursor,
250
+ setSelection,
251
+ setSelections,
252
+ extendSelectionsBy
253
+ };
254
+ },
255
+ render() {
256
+ return h(
257
+ this.$props.tag,
258
+ {
259
+ ref: "editor",
260
+ class: "vue-codemirror"
261
+ },
262
+ this.$slots.default ? h(
263
+ "aside",
264
+ { style: "display: none;", "aria-hidden": "true" },
265
+ slot(this.$slots.default)
266
+ ) : void 0
267
+ );
268
+ }
269
+ });
270
+
271
+ const meta = {
272
+ version: "1.0.3",
273
+ date: "2022-10-11T23:57:24.765Z"
274
+ };
275
+
276
+ const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
277
+ if (typeof window !== "undefined" && window.Vue) {
278
+ window.Vue.use(CodeMirror);
279
+ }
280
+
281
+ exports.Meta = meta;
282
+ exports.default = CodeMirror;
283
+ exports.install = installCodeMirror;
284
+
285
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
286
+
287
+ return exports;
288
+
289
+ })({}, VueDemi, lodash, state, view, lint, codemirror, commands);
package/dist/index.umd.js CHANGED
@@ -5,8 +5,286 @@
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.1
8
+ * @version 1.0.3
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 E=o=>o?Object.entries(o).reduce((l,[n,c])=>(n=n.charAt(0).toUpperCase()+n.slice(1),n=`on${n}`,{...l,[n]:c}),{}):{},S=(o,l={},n)=>{if(a.isVue2&&parseInt(a.Vue2.version)<2.7)return a.h(o,l,n);const{props:c,domProps:t,on:d,...f}=l,m=d?E(d):{};return a.h(o,{...f,...c,...t,...m},n)},b=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,l){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=>l.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,u.EditorState.readOnly.of(o.readonly),r.EditorView.editable.of(o.editable),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=>{l.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:s=>{if(t.value.update([s]),s.changes.empty)return;const v=t.value.state.doc.toString();l.emit("update:modelValue",v),l.emit("changed",v)}}),await a.nextTick(),l.emit("ready",{view:t,state:m.value,container:n.value})}),a.onUnmounted(()=>t.value.destroy()),{context:l,editor:n,cursor:f,selection:d,state:m,focus:w,getRange:(e,s)=>t.value.state.sliceDoc(e,s),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,s,v)=>t.value.dispatch({changes:{from:s,to:v,insert:e}}),replaceSelection:e=>t.value.dispatch(t.value.state.replaceSelection(e)),setCursor:e=>f.value=e,setSelection:(e,s)=>t.value.dispatch({selection:{anchor:e,head:s}}),setSelections:(e,s)=>t.value.dispatch({selection:u.EditorSelection.create(e,s)}),extendSelectionsBy:e=>t.value.dispatch({selection:u.EditorSelection.create(d.value.ranges.map(s=>s.extend(e(s))))})}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;","aria-hidden":"true"},b(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
+ value = lodash.trim(editor.value.childNodes[0].innerText);
184
+ }
185
+ view$1.value = new view.EditorView({
186
+ doc: value,
187
+ extensions: extensions.value,
188
+ parent: editor.value,
189
+ dispatch: (tr) => {
190
+ view$1.value.update([tr]);
191
+ if (tr.changes.empty)
192
+ return;
193
+ const v = view$1.value.state.doc.toString();
194
+ context.emit("update:modelValue", v);
195
+ context.emit("changed", v);
196
+ }
197
+ });
198
+ await vueDemi.nextTick();
199
+ context.emit("ready", {
200
+ view: view$1,
201
+ state: state$1.value,
202
+ container: editor.value
203
+ });
204
+ });
205
+ vueDemi.onUnmounted(() => view$1.value.destroy());
206
+ const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
207
+ const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
208
+ const lineCount = () => view$1.value.state.doc.lines;
209
+ const getCursor = () => cursor.value;
210
+ const listSelections = () => view$1.value.state.selection.ranges;
211
+ const getSelection = () => view$1.value.state.sliceDoc(
212
+ view$1.value.state.selection.main.from,
213
+ view$1.value.state.selection.main.to
214
+ );
215
+ const getSelections = () => view$1.value.state.selection.ranges.map(
216
+ (r) => view$1.value.state.sliceDoc(r.from, r.to)
217
+ );
218
+ const somethingSelected = () => view$1.value.state.selection.ranges.some(
219
+ (r) => !r.empty
220
+ );
221
+ const replaceRange = (replacement, from, to) => view$1.value.dispatch({
222
+ changes: { from, to, insert: replacement }
223
+ });
224
+ const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
225
+ const setCursor = (position) => cursor.value = position;
226
+ const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
227
+ const setSelections = (ranges, primary) => view$1.value.dispatch({
228
+ selection: state.EditorSelection.create(ranges, primary)
229
+ });
230
+ const extendSelectionsBy = (f) => view$1.value.dispatch({
231
+ selection: state.EditorSelection.create(
232
+ selection.value.ranges.map((r) => r.extend(f(r)))
233
+ )
234
+ });
235
+ return {
236
+ context,
237
+ editor,
238
+ cursor,
239
+ selection,
240
+ state: state$1,
241
+ focus,
242
+ getRange,
243
+ getLine,
244
+ lineCount,
245
+ getCursor,
246
+ listSelections,
247
+ getSelection,
248
+ getSelections,
249
+ somethingSelected,
250
+ replaceRange,
251
+ replaceSelection,
252
+ setCursor,
253
+ setSelection,
254
+ setSelections,
255
+ extendSelectionsBy
256
+ };
257
+ },
258
+ render() {
259
+ return h(
260
+ this.$props.tag,
261
+ {
262
+ ref: "editor",
263
+ class: "vue-codemirror"
264
+ },
265
+ this.$slots.default ? h(
266
+ "aside",
267
+ { style: "display: none;", "aria-hidden": "true" },
268
+ slot(this.$slots.default)
269
+ ) : void 0
270
+ );
271
+ }
272
+ });
273
+
274
+ const meta = {
275
+ version: "1.0.3",
276
+ date: "2022-10-11T23:57:24.765Z"
277
+ };
278
+
279
+ const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
280
+ if (typeof window !== "undefined" && window.Vue) {
281
+ window.Vue.use(CodeMirror);
282
+ }
283
+
284
+ exports.Meta = meta;
285
+ exports.default = CodeMirror;
286
+ exports.install = installCodeMirror;
287
+
288
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
289
+
290
+ }));
@@ -0,0 +1,8 @@
1
+ /** Build information meta data */
2
+ export default interface MetaInterface {
3
+ /** Version */
4
+ version: string;
5
+ /** Build date */
6
+ date: string;
7
+ }
8
+ //# sourceMappingURL=MetaInterface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetaInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/MetaInterface.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,MAAM,CAAC,OAAO,WAAW,aAAa;IACpC,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;CACd"}