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.
- package/README.md +68 -55
- package/dist/Meta.d.ts +4 -0
- package/dist/Meta.d.ts.map +1 -0
- package/dist/components/CodeMirror.d.ts +12 -1
- package/dist/components/CodeMirror.d.ts.map +1 -1
- package/dist/helpers/h-demi.d.ts +5 -0
- package/dist/helpers/h-demi.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +200 -134
- package/dist/index.iife.js +279 -2
- package/dist/index.umd.js +280 -2
- package/dist/interfaces/MetaInterface.d.ts +8 -0
- package/dist/interfaces/MetaInterface.d.ts.map +1 -0
- package/dist/stats.html +4034 -0
- package/package.json +21 -21
- package/src/components/CodeMirror.ts +12 -5
package/dist/index.iife.js
CHANGED
|
@@ -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.
|
|
8
|
+
* @version 1.0.3
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var CodeMirror
|
|
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.
|
|
8
|
+
* @version 1.0.3
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function
|
|
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 @@
|
|
|
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"}
|