vue-codemirror6 1.1.1 → 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 +10 -9
- package/dist/Meta.d.ts +3 -3
- package/dist/Meta.js +6 -0
- package/dist/components/CodeMirror.d.ts +417 -438
- 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 +27 -13
- package/dist/index.iife.js +36 -18
- package/dist/index.js +11 -0
- package/dist/index.umd.js +38 -20
- package/dist/interfaces/MetaInterface.d.ts +7 -7
- package/dist/interfaces/MetaInterface.js +1 -0
- package/package.json +33 -39
- package/src/components/CodeMirror.ts +50 -27
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, codemirror, state, view, c
|
|
|
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",
|
|
@@ -128,7 +133,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
128
133
|
default: "div"
|
|
129
134
|
}
|
|
130
135
|
},
|
|
131
|
-
emits: ["update:modelValue", "update", "ready", "focus", "change"],
|
|
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);
|
|
@@ -157,7 +162,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
157
162
|
() => view$1.value.state.doc.length
|
|
158
163
|
);
|
|
159
164
|
const extensions = vueDemi.computed(
|
|
160
|
-
() =>
|
|
165
|
+
() => compact__default["default"]([
|
|
161
166
|
props.basic ? codemirror.basicSetup : void 0,
|
|
162
167
|
props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
|
|
163
168
|
view.EditorView.updateListener.of(
|
|
@@ -202,8 +207,12 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
202
207
|
vueDemi.onMounted(async () => {
|
|
203
208
|
let value = doc.value;
|
|
204
209
|
if (editor.value && editor.value.childNodes[0]) {
|
|
205
|
-
if (doc.value !== "")
|
|
206
|
-
|
|
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);
|
|
207
216
|
}
|
|
208
217
|
view$1.value = new view.EditorView({
|
|
209
218
|
doc: value,
|
|
@@ -215,20 +224,27 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
215
224
|
return;
|
|
216
225
|
const v = view$1.value.state.doc.toString();
|
|
217
226
|
context.emit("update:modelValue", v);
|
|
218
|
-
context.emit("change",
|
|
227
|
+
context.emit("change", view$1.value.state);
|
|
219
228
|
}
|
|
220
229
|
});
|
|
221
230
|
await vueDemi.nextTick();
|
|
222
231
|
context.emit("ready", {
|
|
223
232
|
view: view$1,
|
|
224
|
-
state:
|
|
233
|
+
state: view$1.value.state,
|
|
225
234
|
container: editor.value
|
|
226
235
|
});
|
|
227
236
|
});
|
|
228
237
|
vueDemi.onUnmounted(() => {
|
|
229
|
-
view$1.value
|
|
238
|
+
if (view$1.value) {
|
|
239
|
+
view$1.value.destroy();
|
|
240
|
+
context.emit("destroy");
|
|
241
|
+
}
|
|
230
242
|
});
|
|
231
|
-
const lint$1 = () =>
|
|
243
|
+
const lint$1 = () => {
|
|
244
|
+
if (props.linter) {
|
|
245
|
+
lint.forceLinting(view$1.value);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
232
248
|
const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
|
|
233
249
|
const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
|
|
234
250
|
const lineCount = () => view$1.value.state.doc.lines;
|
|
@@ -258,8 +274,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
258
274
|
selection.value.ranges.map((r) => r.extend(f(r)))
|
|
259
275
|
)
|
|
260
276
|
});
|
|
261
|
-
|
|
262
|
-
context,
|
|
277
|
+
context.expose({
|
|
263
278
|
editor,
|
|
264
279
|
cursor,
|
|
265
280
|
selection,
|
|
@@ -281,6 +296,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
281
296
|
setSelection,
|
|
282
297
|
setSelections,
|
|
283
298
|
extendSelectionsBy
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
editor
|
|
284
302
|
};
|
|
285
303
|
},
|
|
286
304
|
render() {
|
|
@@ -300,8 +318,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
300
318
|
});
|
|
301
319
|
|
|
302
320
|
const meta = {
|
|
303
|
-
version: "1.1.
|
|
304
|
-
date: "2022-
|
|
321
|
+
version: "1.1.2",
|
|
322
|
+
date: "2022-12-23T18:38:01.605Z"
|
|
305
323
|
};
|
|
306
324
|
|
|
307
325
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
@@ -310,11 +328,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
|
|
|
310
328
|
}
|
|
311
329
|
|
|
312
330
|
exports.Meta = meta;
|
|
313
|
-
exports
|
|
331
|
+
exports["default"] = CodeMirror;
|
|
314
332
|
exports.install = installCodeMirror;
|
|
315
333
|
|
|
316
|
-
Object.
|
|
334
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
317
335
|
|
|
318
336
|
return exports;
|
|
319
337
|
|
|
320
|
-
})({}, 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('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
|
|
14
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
|
|
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",
|
|
@@ -131,7 +136,7 @@
|
|
|
131
136
|
default: "div"
|
|
132
137
|
}
|
|
133
138
|
},
|
|
134
|
-
emits: ["update:modelValue", "update", "ready", "focus", "change"],
|
|
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);
|
|
@@ -160,7 +165,7 @@
|
|
|
160
165
|
() => view$1.value.state.doc.length
|
|
161
166
|
);
|
|
162
167
|
const extensions = vueDemi.computed(
|
|
163
|
-
() =>
|
|
168
|
+
() => compact__default["default"]([
|
|
164
169
|
props.basic ? codemirror.basicSetup : void 0,
|
|
165
170
|
props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
|
|
166
171
|
view.EditorView.updateListener.of(
|
|
@@ -205,8 +210,12 @@
|
|
|
205
210
|
vueDemi.onMounted(async () => {
|
|
206
211
|
let value = doc.value;
|
|
207
212
|
if (editor.value && editor.value.childNodes[0]) {
|
|
208
|
-
if (doc.value !== "")
|
|
209
|
-
|
|
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);
|
|
210
219
|
}
|
|
211
220
|
view$1.value = new view.EditorView({
|
|
212
221
|
doc: value,
|
|
@@ -218,20 +227,27 @@
|
|
|
218
227
|
return;
|
|
219
228
|
const v = view$1.value.state.doc.toString();
|
|
220
229
|
context.emit("update:modelValue", v);
|
|
221
|
-
context.emit("change",
|
|
230
|
+
context.emit("change", view$1.value.state);
|
|
222
231
|
}
|
|
223
232
|
});
|
|
224
233
|
await vueDemi.nextTick();
|
|
225
234
|
context.emit("ready", {
|
|
226
235
|
view: view$1,
|
|
227
|
-
state:
|
|
236
|
+
state: view$1.value.state,
|
|
228
237
|
container: editor.value
|
|
229
238
|
});
|
|
230
239
|
});
|
|
231
240
|
vueDemi.onUnmounted(() => {
|
|
232
|
-
view$1.value
|
|
241
|
+
if (view$1.value) {
|
|
242
|
+
view$1.value.destroy();
|
|
243
|
+
context.emit("destroy");
|
|
244
|
+
}
|
|
233
245
|
});
|
|
234
|
-
const lint$1 = () =>
|
|
246
|
+
const lint$1 = () => {
|
|
247
|
+
if (props.linter) {
|
|
248
|
+
lint.forceLinting(view$1.value);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
235
251
|
const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
|
|
236
252
|
const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
|
|
237
253
|
const lineCount = () => view$1.value.state.doc.lines;
|
|
@@ -261,8 +277,7 @@
|
|
|
261
277
|
selection.value.ranges.map((r) => r.extend(f(r)))
|
|
262
278
|
)
|
|
263
279
|
});
|
|
264
|
-
|
|
265
|
-
context,
|
|
280
|
+
context.expose({
|
|
266
281
|
editor,
|
|
267
282
|
cursor,
|
|
268
283
|
selection,
|
|
@@ -284,6 +299,9 @@
|
|
|
284
299
|
setSelection,
|
|
285
300
|
setSelections,
|
|
286
301
|
extendSelectionsBy
|
|
302
|
+
});
|
|
303
|
+
return {
|
|
304
|
+
editor
|
|
287
305
|
};
|
|
288
306
|
},
|
|
289
307
|
render() {
|
|
@@ -303,8 +321,8 @@
|
|
|
303
321
|
});
|
|
304
322
|
|
|
305
323
|
const meta = {
|
|
306
|
-
version: "1.1.
|
|
307
|
-
date: "2022-
|
|
324
|
+
version: "1.1.2",
|
|
325
|
+
date: "2022-12-23T18:38:01.605Z"
|
|
308
326
|
};
|
|
309
327
|
|
|
310
328
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
@@ -313,9 +331,9 @@
|
|
|
313
331
|
}
|
|
314
332
|
|
|
315
333
|
exports.Meta = meta;
|
|
316
|
-
exports
|
|
334
|
+
exports["default"] = CodeMirror;
|
|
317
335
|
exports.install = installCodeMirror;
|
|
318
336
|
|
|
319
|
-
Object.
|
|
337
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
320
338
|
|
|
321
339
|
}));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** Build information meta data */
|
|
2
|
-
export default interface MetaInterface {
|
|
3
|
-
/** Version */
|
|
4
|
-
version: string;
|
|
5
|
-
/** Build date */
|
|
6
|
-
date: string;
|
|
7
|
-
}
|
|
1
|
+
/** Build information meta data */
|
|
2
|
+
export default interface MetaInterface {
|
|
3
|
+
/** Version */
|
|
4
|
+
version: string;
|
|
5
|
+
/** Build date */
|
|
6
|
+
date: string;
|
|
7
|
+
}
|
|
8
8
|
//# sourceMappingURL=MetaInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "vue-codemirror6",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "CodeMirror6 Component for vue2 and vue3.",
|
|
7
7
|
"keywords": [
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
42
|
"import": "./dist/index.es.js",
|
|
43
|
-
"require": "./dist/index.umd.js"
|
|
43
|
+
"require": "./dist/index.umd.js",
|
|
44
|
+
"types": "./dist/index.d.ts"
|
|
44
45
|
}
|
|
45
46
|
},
|
|
46
47
|
"files": [
|
|
@@ -55,30 +56,28 @@
|
|
|
55
56
|
"node": ">=18.12.1",
|
|
56
57
|
"yarn": ">=1.22.10"
|
|
57
58
|
},
|
|
58
|
-
"packageManager": "yarn@3.
|
|
59
|
+
"packageManager": "yarn@3.3.1",
|
|
59
60
|
"sideEffects": false,
|
|
60
61
|
"scripts": {
|
|
61
62
|
"dev": "vite",
|
|
62
|
-
"clean": "rimraf
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"build": "run-p type-check build-only build:declaration",
|
|
67
|
-
"build:declaration": "vue-tsc --composite false --declaration --emitDeclarationOnly",
|
|
68
|
-
"build:analyze": "vite build --mode analyze",
|
|
63
|
+
"clean": "rimraf node_modules/.vite",
|
|
64
|
+
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
65
|
+
"type-check": "tsc --noEmit --composite false",
|
|
66
|
+
"build": "run-p type-check build-only build-declaration",
|
|
69
67
|
"build:clean": "rimraf dist",
|
|
70
|
-
"build:docs": "vite build --config vite.config.docs.ts",
|
|
71
68
|
"build-only": "vite build",
|
|
72
|
-
"
|
|
69
|
+
"build-declaration": "tsc -p tsconfig.app.json --composite false --declaration --declarationMap --outDir dist",
|
|
73
70
|
"prepare": "husky install",
|
|
74
71
|
"version": "auto-changelog -p && git add CHANGELOG.md"
|
|
75
72
|
},
|
|
76
73
|
"dependencies": {
|
|
74
|
+
"codemirror": "^6.0.1",
|
|
75
|
+
"lodash.compact": "^3.0.1",
|
|
76
|
+
"lodash.trim": "^4.5.1",
|
|
77
77
|
"vue-demi": "latest"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"@vue/composition-api": "^1.7.1",
|
|
81
|
-
"codemirror": "^6.0.1",
|
|
82
81
|
"vue": "^2.6.14 || ^3.2.39"
|
|
83
82
|
},
|
|
84
83
|
"peerDependenciesMeta": {
|
|
@@ -87,45 +86,44 @@
|
|
|
87
86
|
}
|
|
88
87
|
},
|
|
89
88
|
"devDependencies": {
|
|
90
|
-
"@codemirror/lang-javascript": "^6.1.
|
|
89
|
+
"@codemirror/lang-javascript": "^6.1.2",
|
|
91
90
|
"@codemirror/lang-json": "^6.0.1",
|
|
92
|
-
"@codemirror/lang-markdown": "^6.0.
|
|
93
|
-
"@types/lodash": "^4.14.
|
|
94
|
-
"@types/node": "^18.11.
|
|
95
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
96
|
-
"@typescript-eslint/parser": "^5.
|
|
97
|
-
"@vitejs/plugin-vue": "^
|
|
91
|
+
"@codemirror/lang-markdown": "^6.0.5",
|
|
92
|
+
"@types/lodash": "^4.14.191",
|
|
93
|
+
"@types/node": "^18.11.17",
|
|
94
|
+
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
|
95
|
+
"@typescript-eslint/parser": "^5.47.0",
|
|
96
|
+
"@vitejs/plugin-vue": "^4.0.0",
|
|
98
97
|
"@vue/eslint-config-prettier": "^7.0.0",
|
|
99
98
|
"@vue/tsconfig": "^0.1.3",
|
|
100
|
-
"
|
|
101
|
-
"eslint": "^8.27.0",
|
|
99
|
+
"eslint": "^8.30.0",
|
|
102
100
|
"eslint-config-google": "^0.14.0",
|
|
103
101
|
"eslint-config-prettier": "^8.5.0",
|
|
104
102
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
105
103
|
"eslint-import-resolver-typescript": "^3.5.2",
|
|
106
|
-
"eslint-linter-browserify": "^8.
|
|
104
|
+
"eslint-linter-browserify": "^8.30.0",
|
|
107
105
|
"eslint-plugin-html": "^7.1.0",
|
|
108
106
|
"eslint-plugin-import": "^2.26.0",
|
|
109
|
-
"eslint-plugin-jsdoc": "^39.6.
|
|
107
|
+
"eslint-plugin-jsdoc": "^39.6.4",
|
|
110
108
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
111
|
-
"eslint-plugin-vue": "^9.
|
|
109
|
+
"eslint-plugin-vue": "^9.8.0",
|
|
112
110
|
"eslint-plugin-vuejs-accessibility": "^2.0.0",
|
|
113
111
|
"eslint-plugin-yaml": "^0.5.0",
|
|
114
|
-
"husky": "^8.0.
|
|
115
|
-
"lint-staged": "^13.0
|
|
112
|
+
"husky": "^8.0.2",
|
|
113
|
+
"lint-staged": "^13.1.0",
|
|
116
114
|
"lodash": "^4.17.21",
|
|
117
|
-
"markdown-wasm": "^1.2.0",
|
|
118
115
|
"npm-run-all": "^4.1.5",
|
|
119
|
-
"prettier": "^2.
|
|
116
|
+
"prettier": "^2.8.1",
|
|
120
117
|
"rimraf": "^3.0.2",
|
|
121
118
|
"rollup-plugin-visualizer": "^5.8.3",
|
|
122
|
-
"typescript": "^4.
|
|
123
|
-
"vite": "^
|
|
124
|
-
"vite-plugin-banner": "^0.
|
|
125
|
-
"vite-plugin-checker": "^0.5.
|
|
126
|
-
"vue": "^3.2.
|
|
119
|
+
"typescript": "^4.9.4",
|
|
120
|
+
"vite": "^4.0.3",
|
|
121
|
+
"vite-plugin-banner": "^0.7.0",
|
|
122
|
+
"vite-plugin-checker": "^0.5.3",
|
|
123
|
+
"vue": "^3.2.45",
|
|
127
124
|
"vue-eslint-parser": "^9.1.0",
|
|
128
|
-
"vue-
|
|
125
|
+
"vue-markdown-wasm": "^0.0.1",
|
|
126
|
+
"vue-tsc": "^1.0.16"
|
|
129
127
|
},
|
|
130
128
|
"husky": {
|
|
131
129
|
"hooks": {
|
|
@@ -135,9 +133,5 @@
|
|
|
135
133
|
"lint-staged": {
|
|
136
134
|
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
137
135
|
"*": "prettier -w -u"
|
|
138
|
-
},
|
|
139
|
-
"resolutions": {
|
|
140
|
-
"prettier": "^2.7.1",
|
|
141
|
-
"@codemirror/language": "<6.3.0"
|
|
142
136
|
}
|
|
143
137
|
}
|
|
@@ -18,25 +18,34 @@ import {
|
|
|
18
18
|
|
|
19
19
|
// Helpers
|
|
20
20
|
import h, { slot } from '@/helpers/h-demi';
|
|
21
|
-
import
|
|
21
|
+
import compact from 'lodash/compact';
|
|
22
|
+
import trim from 'lodash/trim';
|
|
22
23
|
|
|
23
24
|
// CodeMirror
|
|
24
25
|
import { basicSetup, minimalSetup } from 'codemirror';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
SelectionRange,
|
|
33
|
-
Text,
|
|
34
|
-
Transaction,
|
|
26
|
+
import {
|
|
27
|
+
EditorSelection,
|
|
28
|
+
EditorState,
|
|
29
|
+
StateEffect,
|
|
30
|
+
type Extension,
|
|
31
|
+
type SelectionRange,
|
|
32
|
+
type Text,
|
|
35
33
|
} from '@codemirror/state';
|
|
34
|
+
import {
|
|
35
|
+
EditorView,
|
|
36
|
+
keymap,
|
|
37
|
+
placeholder,
|
|
38
|
+
type ViewUpdate,
|
|
39
|
+
} from '@codemirror/view';
|
|
40
|
+
import { indentWithTab } from '@codemirror/commands';
|
|
41
|
+
import {
|
|
42
|
+
forceLinting,
|
|
43
|
+
linter,
|
|
44
|
+
lintGutter,
|
|
45
|
+
type LintSource,
|
|
46
|
+
} from '@codemirror/lint';
|
|
36
47
|
import type { LanguageSupport } from '@codemirror/language';
|
|
37
|
-
import type { LintSource } from '@codemirror/lint';
|
|
38
48
|
import type { StyleSpec } from 'style-mod';
|
|
39
|
-
import type { ViewUpdate } from '@codemirror/view';
|
|
40
49
|
|
|
41
50
|
/** Emit Interface */
|
|
42
51
|
export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
|
|
@@ -55,8 +64,10 @@ export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
|
|
|
55
64
|
container: HTMLElement;
|
|
56
65
|
}
|
|
57
66
|
): void;
|
|
58
|
-
/**
|
|
59
|
-
(e: '
|
|
67
|
+
/** CodeMirror onDestroy */
|
|
68
|
+
(e: 'destroy'): void;
|
|
69
|
+
/** State Changed */
|
|
70
|
+
(e: 'change', value: EditorState): void;
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
/** CodeMirror Component */
|
|
@@ -252,7 +263,7 @@ export default defineComponent({
|
|
|
252
263
|
},
|
|
253
264
|
},
|
|
254
265
|
/** Emits */
|
|
255
|
-
emits: ['update:modelValue', 'update', 'ready', 'focus', 'change'],
|
|
266
|
+
emits: ['update:modelValue', 'update', 'ready', 'focus', 'change', 'destroy'],
|
|
256
267
|
/**
|
|
257
268
|
* Setup
|
|
258
269
|
*
|
|
@@ -412,7 +423,7 @@ export default defineComponent({
|
|
|
412
423
|
doc: value,
|
|
413
424
|
extensions: extensions.value,
|
|
414
425
|
parent: editor.value,
|
|
415
|
-
dispatch:
|
|
426
|
+
dispatch: tr => {
|
|
416
427
|
view.value.update([tr]);
|
|
417
428
|
// TODO: Emit lint error event
|
|
418
429
|
// console.log(view.state.doc.toString(), tr);
|
|
@@ -420,20 +431,23 @@ export default defineComponent({
|
|
|
420
431
|
// child-to-parent binding
|
|
421
432
|
const v = view.value.state.doc.toString();
|
|
422
433
|
context.emit('update:modelValue', v);
|
|
423
|
-
context.emit('change',
|
|
434
|
+
context.emit('change', view.value.state);
|
|
424
435
|
},
|
|
425
436
|
});
|
|
426
437
|
await nextTick();
|
|
427
438
|
context.emit('ready', {
|
|
428
439
|
view: view,
|
|
429
|
-
state:
|
|
440
|
+
state: view.value.state,
|
|
430
441
|
container: editor.value,
|
|
431
442
|
});
|
|
432
443
|
});
|
|
433
444
|
|
|
434
445
|
/** Destroy */
|
|
435
446
|
onUnmounted(() => {
|
|
436
|
-
view.value
|
|
447
|
+
if (view.value) {
|
|
448
|
+
view.value.destroy();
|
|
449
|
+
context.emit('destroy');
|
|
450
|
+
}
|
|
437
451
|
});
|
|
438
452
|
|
|
439
453
|
/**
|
|
@@ -441,9 +455,13 @@ export default defineComponent({
|
|
|
441
455
|
*
|
|
442
456
|
* @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
|
|
443
457
|
*/
|
|
444
|
-
const lint = () =>
|
|
458
|
+
const lint = () => {
|
|
459
|
+
if (props.linter) {
|
|
460
|
+
forceLinting(view.value);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
445
463
|
|
|
446
|
-
|
|
464
|
+
/* ----- Bellow is experimental. ------ */
|
|
447
465
|
|
|
448
466
|
/**
|
|
449
467
|
* Get the text between the given points in the editor.
|
|
@@ -515,7 +533,7 @@ export default defineComponent({
|
|
|
515
533
|
*
|
|
516
534
|
* @param position - position.
|
|
517
535
|
*/
|
|
518
|
-
const setCursor = (position: number) => (cursor.value = position);
|
|
536
|
+
const setCursor = (position: number): number => (cursor.value = position);
|
|
519
537
|
/**
|
|
520
538
|
* Set a single selection range.
|
|
521
539
|
*
|
|
@@ -545,12 +563,12 @@ export default defineComponent({
|
|
|
545
563
|
const extendSelectionsBy = (f: Function) =>
|
|
546
564
|
view.value.dispatch({
|
|
547
565
|
selection: EditorSelection.create(
|
|
548
|
-
selection.value.ranges.map(r => r.extend(f(r)))
|
|
566
|
+
selection.value.ranges.map((r: SelectionRange) => r.extend(f(r)))
|
|
549
567
|
),
|
|
550
568
|
});
|
|
551
569
|
|
|
552
|
-
|
|
553
|
-
|
|
570
|
+
/** Export properties and functions */
|
|
571
|
+
context.expose({
|
|
554
572
|
editor,
|
|
555
573
|
cursor,
|
|
556
574
|
selection,
|
|
@@ -573,6 +591,10 @@ export default defineComponent({
|
|
|
573
591
|
setSelection,
|
|
574
592
|
setSelections,
|
|
575
593
|
extendSelectionsBy,
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
return {
|
|
597
|
+
editor,
|
|
576
598
|
};
|
|
577
599
|
},
|
|
578
600
|
render() {
|
|
@@ -588,7 +610,8 @@ export default defineComponent({
|
|
|
588
610
|
class: 'vue-codemirror',
|
|
589
611
|
},
|
|
590
612
|
this.$slots.default
|
|
591
|
-
?
|
|
613
|
+
? // Hide original content
|
|
614
|
+
h(
|
|
592
615
|
'aside',
|
|
593
616
|
{ style: 'display: none;', 'aria-hidden': 'true' },
|
|
594
617
|
slot(this.$slots.default)
|