vue-codemirror6 0.0.2 → 0.0.5
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 +36 -8
- package/dist/vue-codemirror6.es.js +5282 -9413
- package/dist/vue-codemirror6.umd.js +28 -12
- package/package.json +51 -28
- package/src/components/CodeMirror.vue +187 -0
- package/types/entry.d.ts +0 -4
- package/types/entry.d.ts.map +0 -1
- package/types/entry.esm.d.ts +0 -6
- package/types/entry.esm.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "vue-codemirror6",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.0.5",
|
|
5
|
+
"description": "CodeMirror6 Component for vue2",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vuejs",
|
|
8
|
+
"vue",
|
|
9
|
+
"vue-components",
|
|
10
|
+
"vue-codemirror",
|
|
11
|
+
"code-editor",
|
|
12
|
+
"text-editor",
|
|
13
|
+
"vue2",
|
|
14
|
+
"web-editor",
|
|
15
|
+
"vue-plugin",
|
|
16
|
+
"vue-component",
|
|
17
|
+
"codemirror-editor",
|
|
18
|
+
"vue-resource",
|
|
19
|
+
"codemirror6"
|
|
20
|
+
],
|
|
6
21
|
"author": {
|
|
7
22
|
"name": "Logue",
|
|
8
23
|
"email": "logue@hotmail.co.jp",
|
|
@@ -22,62 +37,73 @@
|
|
|
22
37
|
"license": "MIT",
|
|
23
38
|
"main": "./dist/vue-codemirror6.umd.js",
|
|
24
39
|
"module": "./dist/vue-codemirror6.es.js",
|
|
40
|
+
"browser": {
|
|
41
|
+
"./sfc": "./src/components/CodeMirror.vue"
|
|
42
|
+
},
|
|
25
43
|
"exports": {
|
|
26
44
|
".": {
|
|
27
45
|
"import": "./dist/vue-codemirror6.es.js",
|
|
28
46
|
"require": "./dist/vue-codemirror6.umd.js"
|
|
29
47
|
}
|
|
30
48
|
},
|
|
31
|
-
"types": "./
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
32
50
|
"files": [
|
|
33
51
|
"/dist",
|
|
34
|
-
"/
|
|
52
|
+
"/src/components/CodeMirror.vue"
|
|
35
53
|
],
|
|
36
54
|
"sideEffects": false,
|
|
37
55
|
"scripts": {
|
|
38
|
-
"
|
|
39
|
-
"build
|
|
56
|
+
"dev": "vite",
|
|
57
|
+
"build": "vite build & vue-tsc",
|
|
58
|
+
"build:clean": "rimraf dist",
|
|
40
59
|
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
41
|
-
"lint:markup": "vue-tsc",
|
|
60
|
+
"lint:markup": "vue-tsc --noEmit",
|
|
42
61
|
"prepare": "husky install"
|
|
43
62
|
},
|
|
44
63
|
"dependencies": {
|
|
45
|
-
"@codemirror/
|
|
46
|
-
"@codemirror/
|
|
47
|
-
"@codemirror/
|
|
64
|
+
"@codemirror/basic-setup": "^0.19.1",
|
|
65
|
+
"@codemirror/lang-markdown": "^0.19.6",
|
|
66
|
+
"@codemirror/language": "^0.19.8",
|
|
67
|
+
"@codemirror/lint": "^0.19.6",
|
|
68
|
+
"@codemirror/view": "^0.19.47",
|
|
48
69
|
"lodash": "^4.17.21",
|
|
49
70
|
"vue": "^2.6.14",
|
|
50
71
|
"vue-class-component": "^7.2.6",
|
|
51
72
|
"vue-property-decorator": "^9.1.2"
|
|
52
73
|
},
|
|
53
74
|
"devDependencies": {
|
|
54
|
-
"@types/lodash": "^4.14.
|
|
55
|
-
"@types/node": "^17.0.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
75
|
+
"@types/lodash": "^4.14.180",
|
|
76
|
+
"@types/node": "^17.0.21",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
78
|
+
"@typescript-eslint/parser": "^5.15.0",
|
|
58
79
|
"@vue/compiler-sfc": "^3.2.31",
|
|
59
80
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
60
|
-
"eslint": "^8.
|
|
81
|
+
"eslint": "^8.11.0",
|
|
61
82
|
"eslint-config-google": "^0.14.0",
|
|
62
|
-
"eslint-config-prettier": "^8.
|
|
83
|
+
"eslint-config-prettier": "^8.5.0",
|
|
84
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
85
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
86
|
+
"eslint-plugin-import": "^2.25.4",
|
|
63
87
|
"eslint-plugin-prettier": "^4.0.0",
|
|
64
88
|
"eslint-plugin-prettier-vue": "^3.1.0",
|
|
65
89
|
"eslint-plugin-tsdoc": "^0.2.14",
|
|
66
|
-
"eslint-plugin-vue": "^8.
|
|
90
|
+
"eslint-plugin-vue": "^8.5.0",
|
|
67
91
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
68
92
|
"husky": "^7.0.4",
|
|
69
|
-
"lint-staged": "^12.3.
|
|
70
|
-
"prettier": "^2.
|
|
71
|
-
"prettier-plugin-jsdoc": "^0.3.
|
|
93
|
+
"lint-staged": "^12.3.6",
|
|
94
|
+
"prettier": "^2.6.0",
|
|
95
|
+
"prettier-plugin-jsdoc": "^0.3.31",
|
|
72
96
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
97
|
+
"prettier-plugin-sort-imports": "^1.6.0",
|
|
73
98
|
"rimraf": "^3.0.2",
|
|
74
|
-
"typescript": "
|
|
75
|
-
"vite": "^2.8.
|
|
99
|
+
"typescript": ">=3.3.1 <4.6.0",
|
|
100
|
+
"vite": "^2.8.6",
|
|
101
|
+
"vite-dts": "^1.0.4",
|
|
76
102
|
"vite-plugin-eslint": "^1.3.0",
|
|
77
103
|
"vite-plugin-vue2": "^1.9.3",
|
|
78
|
-
"vue-eslint-parser": "^8.
|
|
104
|
+
"vue-eslint-parser": "^8.3.0",
|
|
79
105
|
"vue-template-compiler": "^2.6.14",
|
|
80
|
-
"vue-tsc": "^0.
|
|
106
|
+
"vue-tsc": "^0.33.2"
|
|
81
107
|
},
|
|
82
108
|
"husky": {
|
|
83
109
|
"hooks": {
|
|
@@ -85,10 +111,7 @@
|
|
|
85
111
|
}
|
|
86
112
|
},
|
|
87
113
|
"lint-staged": {
|
|
88
|
-
"*.{
|
|
89
|
-
"eslint --fix --cache"
|
|
90
|
-
],
|
|
91
|
-
"*.{js,ts,json,yml,yaml,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
114
|
+
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
92
115
|
"*": "prettier -w -u"
|
|
93
116
|
}
|
|
94
117
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="editor">
|
|
3
|
+
<template v-if="!$slots.default"><slot /></template>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
|
9
|
+
import type { VNode } from 'vue';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
EditorState,
|
|
13
|
+
type Extension,
|
|
14
|
+
type Transaction,
|
|
15
|
+
} from '@codemirror/state';
|
|
16
|
+
import { EditorView, type ViewUpdate } from '@codemirror/view';
|
|
17
|
+
import type { LanguageSupport } from '@codemirror/language';
|
|
18
|
+
import type { Diagnostic } from '@codemirror/lint';
|
|
19
|
+
import type { StyleSpec } from 'style-mod';
|
|
20
|
+
|
|
21
|
+
import { compact, merge } from 'lodash';
|
|
22
|
+
|
|
23
|
+
@Component({ name: 'CodeMirror' })
|
|
24
|
+
/** CodeMirror Component */
|
|
25
|
+
export default class CodeMirror extends Vue {
|
|
26
|
+
/** Editor */
|
|
27
|
+
private editor!: EditorView;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Theme
|
|
31
|
+
*
|
|
32
|
+
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
33
|
+
*/
|
|
34
|
+
@Prop({ type: Object, default: () => {} })
|
|
35
|
+
readonly theme!: { [selector: string]: StyleSpec };
|
|
36
|
+
|
|
37
|
+
/** Dark Mode */
|
|
38
|
+
@Prop({ type: Boolean, default: false })
|
|
39
|
+
readonly dark!: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Language Phreses
|
|
43
|
+
*
|
|
44
|
+
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
45
|
+
*/
|
|
46
|
+
@Prop({ type: Object })
|
|
47
|
+
readonly phrases!: Record<string, string>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Additional Extension
|
|
51
|
+
*
|
|
52
|
+
* @see {@link:https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
53
|
+
*/
|
|
54
|
+
@Prop({ type: Array, default: () => [] })
|
|
55
|
+
readonly extensions!: Extension[];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* CodeMirror Language
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
61
|
+
*/
|
|
62
|
+
@Prop({ type: Object })
|
|
63
|
+
readonly lang!: LanguageSupport;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* CodeMirror Linter
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
69
|
+
*/
|
|
70
|
+
@Prop({ type: Array, default: () => [] })
|
|
71
|
+
readonly linter!: Diagnostic[];
|
|
72
|
+
|
|
73
|
+
/** Input */
|
|
74
|
+
@Prop({ type: String, default: '' })
|
|
75
|
+
readonly value!: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Input value changed
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
|
|
81
|
+
*/
|
|
82
|
+
@Watch('value')
|
|
83
|
+
onValueChanged() {
|
|
84
|
+
/** Previous cursor location */
|
|
85
|
+
const previous = this.editor.state.selection;
|
|
86
|
+
/*
|
|
87
|
+
this.editor.dispatch({
|
|
88
|
+
changes: {
|
|
89
|
+
from: 0,
|
|
90
|
+
to: this.editor.state.doc.length,
|
|
91
|
+
insert: this.value,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
*/
|
|
95
|
+
this.editor.setState(
|
|
96
|
+
EditorState.create({
|
|
97
|
+
doc: this.value,
|
|
98
|
+
extensions: this.extension,
|
|
99
|
+
selection: previous,
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Darkmode */
|
|
105
|
+
@Watch('dark')
|
|
106
|
+
onToggleDarkMode() {
|
|
107
|
+
this.editor.setState(
|
|
108
|
+
EditorState.create({
|
|
109
|
+
doc: this.value,
|
|
110
|
+
extensions: this.extension,
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** CodeMirror Extension */
|
|
116
|
+
get extension(): Extension[] {
|
|
117
|
+
/** Default extension */
|
|
118
|
+
const ext: Extension[] = compact([
|
|
119
|
+
// ViewUpdate event listener
|
|
120
|
+
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
121
|
+
this.$emit('update', update)
|
|
122
|
+
),
|
|
123
|
+
// Toggle light/dark mode.
|
|
124
|
+
EditorView.theme(this.theme, { dark: this.dark }),
|
|
125
|
+
// locale settings
|
|
126
|
+
this.phrases ? EditorState.phrases.of(this.phrases) : undefined,
|
|
127
|
+
// Parser language setting
|
|
128
|
+
this.lang ? this.lang : undefined,
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
if (this.linter.length !== 0) {
|
|
132
|
+
// Append Linter settings
|
|
133
|
+
merge(ext, this.linter);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (this.extensions.length !== 0) {
|
|
137
|
+
// Append Extensions (such as basic-setup)
|
|
138
|
+
merge(ext, this.extensions);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.debug('[CodeMirror.vue] Loaded extensions:', ext);
|
|
142
|
+
|
|
143
|
+
return ext;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** When loaded */
|
|
147
|
+
mounted() {
|
|
148
|
+
let value = this.value;
|
|
149
|
+
if (!this.value && this.$slots.default !== undefined) {
|
|
150
|
+
// override text node
|
|
151
|
+
value = this.getChildrenTextContent(this.$slots.default);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Register Codemirror
|
|
155
|
+
this.editor = new EditorView({
|
|
156
|
+
state: EditorState.create({
|
|
157
|
+
doc: value,
|
|
158
|
+
extensions: this.extension,
|
|
159
|
+
}),
|
|
160
|
+
parent: this.$refs.editor as Element,
|
|
161
|
+
dispatch: (tr: Transaction) => {
|
|
162
|
+
this.editor.update([tr]);
|
|
163
|
+
|
|
164
|
+
if (tr.changes.empty) return;
|
|
165
|
+
// to parent binding
|
|
166
|
+
this.$emit('input', this.editor.state.doc.toString());
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Destroy */
|
|
172
|
+
beforeDestroy() {
|
|
173
|
+
this.editor.destroy();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Vue node to plain text */
|
|
177
|
+
private getChildrenTextContent(children: VNode[]): string {
|
|
178
|
+
return children
|
|
179
|
+
.map((node: VNode) =>
|
|
180
|
+
node.children
|
|
181
|
+
? this.getChildrenTextContent(node.children)
|
|
182
|
+
: node.text || '\n'
|
|
183
|
+
)
|
|
184
|
+
.join('');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
</script>
|
package/types/entry.d.ts
DELETED
package/types/entry.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AACA,OAAkB,KAAK,YAAY,MAAM,aAAa,CAAC;;AASvD,wBAC0C"}
|
package/types/entry.esm.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { PluginObject } from 'vue';
|
|
2
|
-
import component from './components/CodeMirror.vue';
|
|
3
|
-
declare type InstallableComponent = typeof component & PluginObject<any>;
|
|
4
|
-
declare const _default: InstallableComponent;
|
|
5
|
-
export default _default;
|
|
6
|
-
//# sourceMappingURL=entry.esm.d.ts.map
|
package/types/entry.esm.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.esm.d.ts","sourceRoot":"","sources":["../src/entry.esm.ts"],"names":[],"mappings":"AAAA,OAAa,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AAGzC,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAGpD,aAAK,oBAAoB,GAAG,OAAO,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;;AAKjE,wBASK"}
|