vue-codemirror6 1.1.0 → 1.1.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.
- package/CHANGELOG.md +14 -0
- package/README.md +29 -26
- package/dist/Meta.d.ts +3 -3
- package/dist/Meta.js +6 -0
- package/dist/components/CodeMirror.d.ts +417 -392
- package/dist/components/CodeMirror.d.ts.map +1 -1
- package/dist/components/CodeMirror.js +494 -0
- package/dist/helpers/h-demi.d.ts +18 -18
- package/dist/helpers/h-demi.js +27 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.es.js +51 -33
- package/dist/index.iife.js +58 -36
- package/dist/index.js +11 -0
- package/dist/index.umd.js +60 -38
- package/dist/interfaces/MetaInterface.d.ts +7 -7
- package/dist/interfaces/MetaInterface.js +1 -0
- package/package.json +36 -37
- package/src/components/CodeMirror.ts +133 -69
package/dist/index.es.js
CHANGED
|
@@ -5,17 +5,18 @@
|
|
|
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.1.
|
|
8
|
+
* @version 1.1.2
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { isVue2, Vue2, h as h$1, defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
|
|
13
|
-
import
|
|
13
|
+
import compact from 'lodash/compact';
|
|
14
|
+
import trim from 'lodash/trim';
|
|
15
|
+
import { basicSetup, minimalSetup } from 'codemirror';
|
|
14
16
|
import { EditorState, StateEffect, EditorSelection } from '@codemirror/state';
|
|
15
17
|
import { EditorView, keymap, placeholder } from '@codemirror/view';
|
|
16
|
-
import { linter, lintGutter, diagnosticCount } from '@codemirror/lint';
|
|
17
|
-
import { basicSetup, minimalSetup } from 'codemirror';
|
|
18
18
|
import { indentWithTab } from '@codemirror/commands';
|
|
19
|
+
import { linter, lintGutter, forceLinting } from '@codemirror/lint';
|
|
19
20
|
|
|
20
21
|
const adaptOnsV3 = (ons) => {
|
|
21
22
|
if (!ons)
|
|
@@ -40,7 +41,7 @@ const h = (type, options = {}, chidren) => {
|
|
|
40
41
|
};
|
|
41
42
|
const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
var CodeMirror = defineComponent({
|
|
44
45
|
name: "CodeMirror",
|
|
45
46
|
model: {
|
|
46
47
|
prop: "modelValue",
|
|
@@ -54,7 +55,6 @@ const CodeMirror = defineComponent({
|
|
|
54
55
|
theme: {
|
|
55
56
|
type: Object,
|
|
56
57
|
default: () => {
|
|
57
|
-
return {};
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
dark: {
|
|
@@ -81,6 +81,14 @@ const CodeMirror = defineComponent({
|
|
|
81
81
|
type: Boolean,
|
|
82
82
|
default: false
|
|
83
83
|
},
|
|
84
|
+
tabSize: {
|
|
85
|
+
type: Number,
|
|
86
|
+
default: void 0
|
|
87
|
+
},
|
|
88
|
+
lineSeparator: {
|
|
89
|
+
type: String,
|
|
90
|
+
default: void 0
|
|
91
|
+
},
|
|
84
92
|
readonly: {
|
|
85
93
|
type: Boolean,
|
|
86
94
|
default: false
|
|
@@ -126,14 +134,7 @@ const CodeMirror = defineComponent({
|
|
|
126
134
|
default: "div"
|
|
127
135
|
}
|
|
128
136
|
},
|
|
129
|
-
emits: [
|
|
130
|
-
"update:modelValue",
|
|
131
|
-
"update",
|
|
132
|
-
"ready",
|
|
133
|
-
"focus",
|
|
134
|
-
"changed",
|
|
135
|
-
"diagnosticCount"
|
|
136
|
-
],
|
|
137
|
+
emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
|
|
137
138
|
setup(props, context) {
|
|
138
139
|
const editor = ref();
|
|
139
140
|
const doc = ref(props.modelValue);
|
|
@@ -142,14 +143,14 @@ const CodeMirror = defineComponent({
|
|
|
142
143
|
get: () => view.value.state.selection,
|
|
143
144
|
set: (s) => view.value.dispatch({ selection: s })
|
|
144
145
|
});
|
|
145
|
-
const cursor = computed({
|
|
146
|
-
get: () => selection.value.main.head || 0,
|
|
147
|
-
set: (a) => view.value.dispatch({ selection: { anchor: a } })
|
|
148
|
-
});
|
|
149
146
|
const state = computed({
|
|
150
147
|
get: () => view.value.state,
|
|
151
148
|
set: (s) => view.value.setState(s)
|
|
152
149
|
});
|
|
150
|
+
const cursor = computed({
|
|
151
|
+
get: () => view.value.state.selection.main.head || 0,
|
|
152
|
+
set: (a) => view.value.dispatch({ selection: { anchor: a } })
|
|
153
|
+
});
|
|
153
154
|
const focus = computed({
|
|
154
155
|
get: () => view.value.hasFocus,
|
|
155
156
|
set: (f) => {
|
|
@@ -158,6 +159,9 @@ const CodeMirror = defineComponent({
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
});
|
|
162
|
+
const length = computed(
|
|
163
|
+
() => view.value.state.doc.length
|
|
164
|
+
);
|
|
161
165
|
const extensions = computed(
|
|
162
166
|
() => compact([
|
|
163
167
|
props.basic ? basicSetup : void 0,
|
|
@@ -168,9 +172,11 @@ const CodeMirror = defineComponent({
|
|
|
168
172
|
EditorView.theme(props.theme, { dark: props.dark }),
|
|
169
173
|
props.wrap ? EditorView.lineWrapping : void 0,
|
|
170
174
|
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
175
|
+
props.tabSize ? EditorState.tabSize.of(props.tabSize) : void 0,
|
|
171
176
|
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
172
177
|
EditorState.readOnly.of(props.readonly),
|
|
173
178
|
EditorView.editable.of(!props.disabled),
|
|
179
|
+
props.lineSeparator ? EditorState.lineSeparator.of(props.lineSeparator) : void 0,
|
|
174
180
|
props.lang ? props.lang : void 0,
|
|
175
181
|
props.linter ? linter(props.linter, props.linterConfig) : void 0,
|
|
176
182
|
props.linter && props.gutter ? lintGutter(props.gutterConfig) : void 0,
|
|
@@ -181,16 +187,12 @@ const CodeMirror = defineComponent({
|
|
|
181
187
|
watch(
|
|
182
188
|
() => props.modelValue,
|
|
183
189
|
(value) => {
|
|
184
|
-
if (
|
|
190
|
+
if (view.value.composing) {
|
|
185
191
|
return;
|
|
186
192
|
}
|
|
187
|
-
const current = view.value.state;
|
|
188
|
-
if (props.linter) {
|
|
189
|
-
context.emit("diagnosticCount", diagnosticCount(current));
|
|
190
|
-
}
|
|
191
193
|
view.value.dispatch({
|
|
192
|
-
changes: { from: 0, to:
|
|
193
|
-
selection:
|
|
194
|
+
changes: { from: 0, to: view.value.state.doc.length, insert: value },
|
|
195
|
+
selection: view.value.state.selection,
|
|
194
196
|
scrollIntoView: true
|
|
195
197
|
});
|
|
196
198
|
},
|
|
@@ -206,7 +208,11 @@ const CodeMirror = defineComponent({
|
|
|
206
208
|
onMounted(async () => {
|
|
207
209
|
let value = doc.value;
|
|
208
210
|
if (editor.value && editor.value.childNodes[0]) {
|
|
209
|
-
if (doc.value !== "")
|
|
211
|
+
if (doc.value !== "") {
|
|
212
|
+
console.warn(
|
|
213
|
+
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
214
|
+
);
|
|
215
|
+
}
|
|
210
216
|
value = trim(editor.value.childNodes[0].innerText);
|
|
211
217
|
}
|
|
212
218
|
view.value = new EditorView({
|
|
@@ -219,19 +225,27 @@ const CodeMirror = defineComponent({
|
|
|
219
225
|
return;
|
|
220
226
|
const v = view.value.state.doc.toString();
|
|
221
227
|
context.emit("update:modelValue", v);
|
|
222
|
-
context.emit("
|
|
228
|
+
context.emit("change", view.value.state);
|
|
223
229
|
}
|
|
224
230
|
});
|
|
225
231
|
await nextTick();
|
|
226
232
|
context.emit("ready", {
|
|
227
233
|
view,
|
|
228
|
-
state:
|
|
234
|
+
state: view.value.state,
|
|
229
235
|
container: editor.value
|
|
230
236
|
});
|
|
231
237
|
});
|
|
232
238
|
onUnmounted(() => {
|
|
233
|
-
view.value
|
|
239
|
+
if (view.value) {
|
|
240
|
+
view.value.destroy();
|
|
241
|
+
context.emit("destroy");
|
|
242
|
+
}
|
|
234
243
|
});
|
|
244
|
+
const lint = () => {
|
|
245
|
+
if (props.linter) {
|
|
246
|
+
forceLinting(view.value);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
235
249
|
const getRange = (from, to) => view.value.state.sliceDoc(from, to);
|
|
236
250
|
const getLine = (number) => view.value.state.doc.line(number + 1).text;
|
|
237
251
|
const lineCount = () => view.value.state.doc.lines;
|
|
@@ -261,13 +275,14 @@ const CodeMirror = defineComponent({
|
|
|
261
275
|
selection.value.ranges.map((r) => r.extend(f(r)))
|
|
262
276
|
)
|
|
263
277
|
});
|
|
264
|
-
|
|
265
|
-
context,
|
|
278
|
+
context.expose({
|
|
266
279
|
editor,
|
|
267
280
|
cursor,
|
|
268
281
|
selection,
|
|
269
282
|
state,
|
|
270
283
|
focus,
|
|
284
|
+
length,
|
|
285
|
+
lint,
|
|
271
286
|
getRange,
|
|
272
287
|
getLine,
|
|
273
288
|
lineCount,
|
|
@@ -282,6 +297,9 @@ const CodeMirror = defineComponent({
|
|
|
282
297
|
setSelection,
|
|
283
298
|
setSelections,
|
|
284
299
|
extendSelectionsBy
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
editor
|
|
285
303
|
};
|
|
286
304
|
},
|
|
287
305
|
render() {
|
|
@@ -301,8 +319,8 @@ const CodeMirror = defineComponent({
|
|
|
301
319
|
});
|
|
302
320
|
|
|
303
321
|
const meta = {
|
|
304
|
-
version: "1.1.
|
|
305
|
-
date: "2022-
|
|
322
|
+
version: "1.1.2",
|
|
323
|
+
date: "2022-12-23T18:38:01.605Z"
|
|
306
324
|
};
|
|
307
325
|
|
|
308
326
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
package/dist/index.iife.js
CHANGED
|
@@ -5,13 +5,18 @@
|
|
|
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.1.
|
|
8
|
+
* @version 1.1.2
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var CodeMirror = (function (exports, vueDemi,
|
|
12
|
+
var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state, view, commands, lint) {
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var compact__default = /*#__PURE__*/_interopDefaultCompat(compact);
|
|
18
|
+
var trim__default = /*#__PURE__*/_interopDefaultCompat(trim);
|
|
19
|
+
|
|
15
20
|
const adaptOnsV3 = (ons) => {
|
|
16
21
|
if (!ons)
|
|
17
22
|
return {};
|
|
@@ -35,7 +40,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
35
40
|
};
|
|
36
41
|
const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
var CodeMirror = vueDemi.defineComponent({
|
|
39
44
|
name: "CodeMirror",
|
|
40
45
|
model: {
|
|
41
46
|
prop: "modelValue",
|
|
@@ -49,7 +54,6 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
49
54
|
theme: {
|
|
50
55
|
type: Object,
|
|
51
56
|
default: () => {
|
|
52
|
-
return {};
|
|
53
57
|
}
|
|
54
58
|
},
|
|
55
59
|
dark: {
|
|
@@ -76,6 +80,14 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
76
80
|
type: Boolean,
|
|
77
81
|
default: false
|
|
78
82
|
},
|
|
83
|
+
tabSize: {
|
|
84
|
+
type: Number,
|
|
85
|
+
default: void 0
|
|
86
|
+
},
|
|
87
|
+
lineSeparator: {
|
|
88
|
+
type: String,
|
|
89
|
+
default: void 0
|
|
90
|
+
},
|
|
79
91
|
readonly: {
|
|
80
92
|
type: Boolean,
|
|
81
93
|
default: false
|
|
@@ -121,14 +133,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
121
133
|
default: "div"
|
|
122
134
|
}
|
|
123
135
|
},
|
|
124
|
-
emits: [
|
|
125
|
-
"update:modelValue",
|
|
126
|
-
"update",
|
|
127
|
-
"ready",
|
|
128
|
-
"focus",
|
|
129
|
-
"changed",
|
|
130
|
-
"diagnosticCount"
|
|
131
|
-
],
|
|
136
|
+
emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
|
|
132
137
|
setup(props, context) {
|
|
133
138
|
const editor = vueDemi.ref();
|
|
134
139
|
const doc = vueDemi.ref(props.modelValue);
|
|
@@ -137,14 +142,14 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
137
142
|
get: () => view$1.value.state.selection,
|
|
138
143
|
set: (s) => view$1.value.dispatch({ selection: s })
|
|
139
144
|
});
|
|
140
|
-
const cursor = vueDemi.computed({
|
|
141
|
-
get: () => selection.value.main.head || 0,
|
|
142
|
-
set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
|
|
143
|
-
});
|
|
144
145
|
const state$1 = vueDemi.computed({
|
|
145
146
|
get: () => view$1.value.state,
|
|
146
147
|
set: (s) => view$1.value.setState(s)
|
|
147
148
|
});
|
|
149
|
+
const cursor = vueDemi.computed({
|
|
150
|
+
get: () => view$1.value.state.selection.main.head || 0,
|
|
151
|
+
set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
|
|
152
|
+
});
|
|
148
153
|
const focus = vueDemi.computed({
|
|
149
154
|
get: () => view$1.value.hasFocus,
|
|
150
155
|
set: (f) => {
|
|
@@ -153,8 +158,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
});
|
|
161
|
+
const length = vueDemi.computed(
|
|
162
|
+
() => view$1.value.state.doc.length
|
|
163
|
+
);
|
|
156
164
|
const extensions = vueDemi.computed(
|
|
157
|
-
() =>
|
|
165
|
+
() => compact__default["default"]([
|
|
158
166
|
props.basic ? codemirror.basicSetup : void 0,
|
|
159
167
|
props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
|
|
160
168
|
view.EditorView.updateListener.of(
|
|
@@ -163,9 +171,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
163
171
|
view.EditorView.theme(props.theme, { dark: props.dark }),
|
|
164
172
|
props.wrap ? view.EditorView.lineWrapping : void 0,
|
|
165
173
|
props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
|
|
174
|
+
props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
|
|
166
175
|
props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
|
|
167
176
|
state.EditorState.readOnly.of(props.readonly),
|
|
168
177
|
view.EditorView.editable.of(!props.disabled),
|
|
178
|
+
props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
|
|
169
179
|
props.lang ? props.lang : void 0,
|
|
170
180
|
props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
|
|
171
181
|
props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
|
|
@@ -176,16 +186,12 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
176
186
|
vueDemi.watch(
|
|
177
187
|
() => props.modelValue,
|
|
178
188
|
(value) => {
|
|
179
|
-
if (
|
|
189
|
+
if (view$1.value.composing) {
|
|
180
190
|
return;
|
|
181
191
|
}
|
|
182
|
-
const current = view$1.value.state;
|
|
183
|
-
if (props.linter) {
|
|
184
|
-
context.emit("diagnosticCount", lint.diagnosticCount(current));
|
|
185
|
-
}
|
|
186
192
|
view$1.value.dispatch({
|
|
187
|
-
changes: { from: 0, to:
|
|
188
|
-
selection:
|
|
193
|
+
changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
|
|
194
|
+
selection: view$1.value.state.selection,
|
|
189
195
|
scrollIntoView: true
|
|
190
196
|
});
|
|
191
197
|
},
|
|
@@ -201,8 +207,12 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
201
207
|
vueDemi.onMounted(async () => {
|
|
202
208
|
let value = doc.value;
|
|
203
209
|
if (editor.value && editor.value.childNodes[0]) {
|
|
204
|
-
if (doc.value !== "")
|
|
205
|
-
|
|
210
|
+
if (doc.value !== "") {
|
|
211
|
+
console.warn(
|
|
212
|
+
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
value = trim__default["default"](editor.value.childNodes[0].innerText);
|
|
206
216
|
}
|
|
207
217
|
view$1.value = new view.EditorView({
|
|
208
218
|
doc: value,
|
|
@@ -214,19 +224,27 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
214
224
|
return;
|
|
215
225
|
const v = view$1.value.state.doc.toString();
|
|
216
226
|
context.emit("update:modelValue", v);
|
|
217
|
-
context.emit("
|
|
227
|
+
context.emit("change", view$1.value.state);
|
|
218
228
|
}
|
|
219
229
|
});
|
|
220
230
|
await vueDemi.nextTick();
|
|
221
231
|
context.emit("ready", {
|
|
222
232
|
view: view$1,
|
|
223
|
-
state:
|
|
233
|
+
state: view$1.value.state,
|
|
224
234
|
container: editor.value
|
|
225
235
|
});
|
|
226
236
|
});
|
|
227
237
|
vueDemi.onUnmounted(() => {
|
|
228
|
-
view$1.value
|
|
238
|
+
if (view$1.value) {
|
|
239
|
+
view$1.value.destroy();
|
|
240
|
+
context.emit("destroy");
|
|
241
|
+
}
|
|
229
242
|
});
|
|
243
|
+
const lint$1 = () => {
|
|
244
|
+
if (props.linter) {
|
|
245
|
+
lint.forceLinting(view$1.value);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
230
248
|
const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
|
|
231
249
|
const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
|
|
232
250
|
const lineCount = () => view$1.value.state.doc.lines;
|
|
@@ -256,13 +274,14 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
256
274
|
selection.value.ranges.map((r) => r.extend(f(r)))
|
|
257
275
|
)
|
|
258
276
|
});
|
|
259
|
-
|
|
260
|
-
context,
|
|
277
|
+
context.expose({
|
|
261
278
|
editor,
|
|
262
279
|
cursor,
|
|
263
280
|
selection,
|
|
264
281
|
state: state$1,
|
|
265
282
|
focus,
|
|
283
|
+
length,
|
|
284
|
+
lint: lint$1,
|
|
266
285
|
getRange,
|
|
267
286
|
getLine,
|
|
268
287
|
lineCount,
|
|
@@ -277,6 +296,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
277
296
|
setSelection,
|
|
278
297
|
setSelections,
|
|
279
298
|
extendSelectionsBy
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
editor
|
|
280
302
|
};
|
|
281
303
|
},
|
|
282
304
|
render() {
|
|
@@ -296,8 +318,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
296
318
|
});
|
|
297
319
|
|
|
298
320
|
const meta = {
|
|
299
|
-
version: "1.1.
|
|
300
|
-
date: "2022-
|
|
321
|
+
version: "1.1.2",
|
|
322
|
+
date: "2022-12-23T18:38:01.605Z"
|
|
301
323
|
};
|
|
302
324
|
|
|
303
325
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
@@ -306,11 +328,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
|
|
|
306
328
|
}
|
|
307
329
|
|
|
308
330
|
exports.Meta = meta;
|
|
309
|
-
exports
|
|
331
|
+
exports["default"] = CodeMirror;
|
|
310
332
|
exports.install = installCodeMirror;
|
|
311
333
|
|
|
312
|
-
Object.
|
|
334
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
313
335
|
|
|
314
336
|
return exports;
|
|
315
337
|
|
|
316
|
-
})({}, VueDemi,
|
|
338
|
+
})({}, VueDemi, compact, trim, codemirror, state, view, commands, lint);
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import CodeMirror from './components/CodeMirror';
|
|
2
|
+
import Meta from './Meta';
|
|
3
|
+
// TODO: Move phrases props to option.
|
|
4
|
+
const installCodeMirror = (app) => app.component('CodeMirror', CodeMirror);
|
|
5
|
+
export { CodeMirror as default, installCodeMirror as install, Meta };
|
|
6
|
+
// For CDN. (Maybe Vue2 only)
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
window.Vue.use(CodeMirror);
|
|
11
|
+
}
|
package/dist/index.umd.js
CHANGED
|
@@ -5,15 +5,20 @@
|
|
|
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.1.
|
|
8
|
+
* @version 1.1.2
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
(function (global, factory) {
|
|
13
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash'), require('
|
|
14
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', '
|
|
15
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.
|
|
16
|
-
})(this, (function (exports, vueDemi,
|
|
13
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash/compact'), require('lodash/trim'), require('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
|
|
14
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash/compact', 'lodash/trim', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
|
|
15
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.compact, global.trim, global.codemirror, global.state, global.view, global.commands, global.lint));
|
|
16
|
+
})(this, (function (exports, vueDemi, compact, trim, codemirror, state, view, commands, lint) { 'use strict';
|
|
17
|
+
|
|
18
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var compact__default = /*#__PURE__*/_interopDefaultCompat(compact);
|
|
21
|
+
var trim__default = /*#__PURE__*/_interopDefaultCompat(trim);
|
|
17
22
|
|
|
18
23
|
const adaptOnsV3 = (ons) => {
|
|
19
24
|
if (!ons)
|
|
@@ -38,7 +43,7 @@
|
|
|
38
43
|
};
|
|
39
44
|
const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
var CodeMirror = vueDemi.defineComponent({
|
|
42
47
|
name: "CodeMirror",
|
|
43
48
|
model: {
|
|
44
49
|
prop: "modelValue",
|
|
@@ -52,7 +57,6 @@
|
|
|
52
57
|
theme: {
|
|
53
58
|
type: Object,
|
|
54
59
|
default: () => {
|
|
55
|
-
return {};
|
|
56
60
|
}
|
|
57
61
|
},
|
|
58
62
|
dark: {
|
|
@@ -79,6 +83,14 @@
|
|
|
79
83
|
type: Boolean,
|
|
80
84
|
default: false
|
|
81
85
|
},
|
|
86
|
+
tabSize: {
|
|
87
|
+
type: Number,
|
|
88
|
+
default: void 0
|
|
89
|
+
},
|
|
90
|
+
lineSeparator: {
|
|
91
|
+
type: String,
|
|
92
|
+
default: void 0
|
|
93
|
+
},
|
|
82
94
|
readonly: {
|
|
83
95
|
type: Boolean,
|
|
84
96
|
default: false
|
|
@@ -124,14 +136,7 @@
|
|
|
124
136
|
default: "div"
|
|
125
137
|
}
|
|
126
138
|
},
|
|
127
|
-
emits: [
|
|
128
|
-
"update:modelValue",
|
|
129
|
-
"update",
|
|
130
|
-
"ready",
|
|
131
|
-
"focus",
|
|
132
|
-
"changed",
|
|
133
|
-
"diagnosticCount"
|
|
134
|
-
],
|
|
139
|
+
emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
|
|
135
140
|
setup(props, context) {
|
|
136
141
|
const editor = vueDemi.ref();
|
|
137
142
|
const doc = vueDemi.ref(props.modelValue);
|
|
@@ -140,14 +145,14 @@
|
|
|
140
145
|
get: () => view$1.value.state.selection,
|
|
141
146
|
set: (s) => view$1.value.dispatch({ selection: s })
|
|
142
147
|
});
|
|
143
|
-
const cursor = vueDemi.computed({
|
|
144
|
-
get: () => selection.value.main.head || 0,
|
|
145
|
-
set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
|
|
146
|
-
});
|
|
147
148
|
const state$1 = vueDemi.computed({
|
|
148
149
|
get: () => view$1.value.state,
|
|
149
150
|
set: (s) => view$1.value.setState(s)
|
|
150
151
|
});
|
|
152
|
+
const cursor = vueDemi.computed({
|
|
153
|
+
get: () => view$1.value.state.selection.main.head || 0,
|
|
154
|
+
set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
|
|
155
|
+
});
|
|
151
156
|
const focus = vueDemi.computed({
|
|
152
157
|
get: () => view$1.value.hasFocus,
|
|
153
158
|
set: (f) => {
|
|
@@ -156,8 +161,11 @@
|
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
});
|
|
164
|
+
const length = vueDemi.computed(
|
|
165
|
+
() => view$1.value.state.doc.length
|
|
166
|
+
);
|
|
159
167
|
const extensions = vueDemi.computed(
|
|
160
|
-
() =>
|
|
168
|
+
() => compact__default["default"]([
|
|
161
169
|
props.basic ? codemirror.basicSetup : void 0,
|
|
162
170
|
props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
|
|
163
171
|
view.EditorView.updateListener.of(
|
|
@@ -166,9 +174,11 @@
|
|
|
166
174
|
view.EditorView.theme(props.theme, { dark: props.dark }),
|
|
167
175
|
props.wrap ? view.EditorView.lineWrapping : void 0,
|
|
168
176
|
props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
|
|
177
|
+
props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
|
|
169
178
|
props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
|
|
170
179
|
state.EditorState.readOnly.of(props.readonly),
|
|
171
180
|
view.EditorView.editable.of(!props.disabled),
|
|
181
|
+
props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
|
|
172
182
|
props.lang ? props.lang : void 0,
|
|
173
183
|
props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
|
|
174
184
|
props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
|
|
@@ -179,16 +189,12 @@
|
|
|
179
189
|
vueDemi.watch(
|
|
180
190
|
() => props.modelValue,
|
|
181
191
|
(value) => {
|
|
182
|
-
if (
|
|
192
|
+
if (view$1.value.composing) {
|
|
183
193
|
return;
|
|
184
194
|
}
|
|
185
|
-
const current = view$1.value.state;
|
|
186
|
-
if (props.linter) {
|
|
187
|
-
context.emit("diagnosticCount", lint.diagnosticCount(current));
|
|
188
|
-
}
|
|
189
195
|
view$1.value.dispatch({
|
|
190
|
-
changes: { from: 0, to:
|
|
191
|
-
selection:
|
|
196
|
+
changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
|
|
197
|
+
selection: view$1.value.state.selection,
|
|
192
198
|
scrollIntoView: true
|
|
193
199
|
});
|
|
194
200
|
},
|
|
@@ -204,8 +210,12 @@
|
|
|
204
210
|
vueDemi.onMounted(async () => {
|
|
205
211
|
let value = doc.value;
|
|
206
212
|
if (editor.value && editor.value.childNodes[0]) {
|
|
207
|
-
if (doc.value !== "")
|
|
208
|
-
|
|
213
|
+
if (doc.value !== "") {
|
|
214
|
+
console.warn(
|
|
215
|
+
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
value = trim__default["default"](editor.value.childNodes[0].innerText);
|
|
209
219
|
}
|
|
210
220
|
view$1.value = new view.EditorView({
|
|
211
221
|
doc: value,
|
|
@@ -217,19 +227,27 @@
|
|
|
217
227
|
return;
|
|
218
228
|
const v = view$1.value.state.doc.toString();
|
|
219
229
|
context.emit("update:modelValue", v);
|
|
220
|
-
context.emit("
|
|
230
|
+
context.emit("change", view$1.value.state);
|
|
221
231
|
}
|
|
222
232
|
});
|
|
223
233
|
await vueDemi.nextTick();
|
|
224
234
|
context.emit("ready", {
|
|
225
235
|
view: view$1,
|
|
226
|
-
state:
|
|
236
|
+
state: view$1.value.state,
|
|
227
237
|
container: editor.value
|
|
228
238
|
});
|
|
229
239
|
});
|
|
230
240
|
vueDemi.onUnmounted(() => {
|
|
231
|
-
view$1.value
|
|
241
|
+
if (view$1.value) {
|
|
242
|
+
view$1.value.destroy();
|
|
243
|
+
context.emit("destroy");
|
|
244
|
+
}
|
|
232
245
|
});
|
|
246
|
+
const lint$1 = () => {
|
|
247
|
+
if (props.linter) {
|
|
248
|
+
lint.forceLinting(view$1.value);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
233
251
|
const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
|
|
234
252
|
const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
|
|
235
253
|
const lineCount = () => view$1.value.state.doc.lines;
|
|
@@ -259,13 +277,14 @@
|
|
|
259
277
|
selection.value.ranges.map((r) => r.extend(f(r)))
|
|
260
278
|
)
|
|
261
279
|
});
|
|
262
|
-
|
|
263
|
-
context,
|
|
280
|
+
context.expose({
|
|
264
281
|
editor,
|
|
265
282
|
cursor,
|
|
266
283
|
selection,
|
|
267
284
|
state: state$1,
|
|
268
285
|
focus,
|
|
286
|
+
length,
|
|
287
|
+
lint: lint$1,
|
|
269
288
|
getRange,
|
|
270
289
|
getLine,
|
|
271
290
|
lineCount,
|
|
@@ -280,6 +299,9 @@
|
|
|
280
299
|
setSelection,
|
|
281
300
|
setSelections,
|
|
282
301
|
extendSelectionsBy
|
|
302
|
+
});
|
|
303
|
+
return {
|
|
304
|
+
editor
|
|
283
305
|
};
|
|
284
306
|
},
|
|
285
307
|
render() {
|
|
@@ -299,8 +321,8 @@
|
|
|
299
321
|
});
|
|
300
322
|
|
|
301
323
|
const meta = {
|
|
302
|
-
version: "1.1.
|
|
303
|
-
date: "2022-
|
|
324
|
+
version: "1.1.2",
|
|
325
|
+
date: "2022-12-23T18:38:01.605Z"
|
|
304
326
|
};
|
|
305
327
|
|
|
306
328
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
@@ -309,9 +331,9 @@
|
|
|
309
331
|
}
|
|
310
332
|
|
|
311
333
|
exports.Meta = meta;
|
|
312
|
-
exports
|
|
334
|
+
exports["default"] = CodeMirror;
|
|
313
335
|
exports.install = installCodeMirror;
|
|
314
336
|
|
|
315
|
-
Object.
|
|
337
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
316
338
|
|
|
317
339
|
}));
|