vue-codemirror6 0.1.0 → 0.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/README.md +217 -224
- package/dist/components/CodeMirror.vue.d.ts +135 -34
- package/dist/components/CodeMirror.vue.d.ts.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts +9 -0
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts.map +1 -0
- package/dist/vue-codemirror6.es.js +140 -188
- package/dist/vue-codemirror6.umd.js +8 -3
- package/package.json +128 -117
- package/src/components/CodeMirror.vue +221 -185
- package/dist/index.esm.d.ts +0 -6
- package/dist/index.esm.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,117 +1,128 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"name": "vue-codemirror6",
|
|
4
|
-
"version": "0.1.
|
|
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
|
-
],
|
|
21
|
-
"author": {
|
|
22
|
-
"name": "Logue",
|
|
23
|
-
"email": "logue@hotmail.co.jp",
|
|
24
|
-
"url": "https://logue.dev/"
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://github.com/logue/vue-codemirror6",
|
|
27
|
-
"repository": {
|
|
28
|
-
"type": "git",
|
|
29
|
-
"url": "git@github.com:logue/vue-codemirror6.git"
|
|
30
|
-
},
|
|
31
|
-
"bugs": {
|
|
32
|
-
"url": "https://github.com/logue/vue-codemirror6/issues"
|
|
33
|
-
},
|
|
34
|
-
"engines": {
|
|
35
|
-
"node": ">=16"
|
|
36
|
-
},
|
|
37
|
-
"license": "MIT",
|
|
38
|
-
"main": "./dist/vue-codemirror6.umd.js",
|
|
39
|
-
"module": "./dist/vue-codemirror6.es.js",
|
|
40
|
-
"browser": {
|
|
41
|
-
"./sfc": "./src/components/CodeMirror.vue"
|
|
42
|
-
},
|
|
43
|
-
"exports": {
|
|
44
|
-
".": {
|
|
45
|
-
"import": "./dist/vue-codemirror6.es.js",
|
|
46
|
-
"require": "./dist/vue-codemirror6.umd.js"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"types": "./dist/index.d.ts",
|
|
50
|
-
"files": [
|
|
51
|
-
"/dist",
|
|
52
|
-
"/src/components/CodeMirror.vue"
|
|
53
|
-
],
|
|
54
|
-
"sideEffects": false,
|
|
55
|
-
"scripts": {
|
|
56
|
-
"dev": "vite",
|
|
57
|
-
"
|
|
58
|
-
"build
|
|
59
|
-
"
|
|
60
|
-
"lint
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"vue-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"@
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"eslint-plugin
|
|
89
|
-
"eslint
|
|
90
|
-
"
|
|
91
|
-
"eslint-
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"prettier": "^
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "vue-codemirror6",
|
|
4
|
+
"version": "0.1.2",
|
|
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
|
+
],
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Logue",
|
|
23
|
+
"email": "logue@hotmail.co.jp",
|
|
24
|
+
"url": "https://logue.dev/"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/logue/vue-codemirror6",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git@github.com:logue/vue-codemirror6.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/logue/vue-codemirror6/issues"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=16"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"main": "./dist/vue-codemirror6.umd.js",
|
|
39
|
+
"module": "./dist/vue-codemirror6.es.js",
|
|
40
|
+
"browser": {
|
|
41
|
+
"./sfc": "./src/components/CodeMirror.vue"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"import": "./dist/vue-codemirror6.es.js",
|
|
46
|
+
"require": "./dist/vue-codemirror6.umd.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
50
|
+
"files": [
|
|
51
|
+
"/dist",
|
|
52
|
+
"/src/components/CodeMirror.vue"
|
|
53
|
+
],
|
|
54
|
+
"sideEffects": false,
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "vite",
|
|
57
|
+
"clean": "rimraf node_modules/.vite",
|
|
58
|
+
"build": "vite build & vue-tsc",
|
|
59
|
+
"build:clean": "rimraf dist",
|
|
60
|
+
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
61
|
+
"switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
|
|
62
|
+
"switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
|
|
63
|
+
"prepare": "husky install",
|
|
64
|
+
"postinstall": "npx vue-demi-fix"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"vue-demi": "latest"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@codemirror/state": "^0.19.9",
|
|
71
|
+
"@codemirror/view": "^0.19.48",
|
|
72
|
+
"@vue/composition-api": "^1.4.9",
|
|
73
|
+
"vue": "^2.6.14 || ^3.2.31"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"@vue/composition-api": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@codemirror/basic-setup": "^0.19.3",
|
|
82
|
+
"@codemirror/lang-markdown": "^0.19.6",
|
|
83
|
+
"@codemirror/language": "^0.19.10",
|
|
84
|
+
"@codemirror/lint": "^0.19.6",
|
|
85
|
+
"@modyqyw/vite-plugin-eslint": "^1.2.0",
|
|
86
|
+
"@types/lodash": "^4.14.181",
|
|
87
|
+
"@types/node": "^17.0.23",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
89
|
+
"@typescript-eslint/parser": "^5.18.0",
|
|
90
|
+
"@vue/composition-api": "^1.4.9",
|
|
91
|
+
"@vue/eslint-config-typescript": "^10.0.0",
|
|
92
|
+
"eslint": "^8.12.0",
|
|
93
|
+
"eslint-config-google": "^0.14.0",
|
|
94
|
+
"eslint-config-prettier": "^8.5.0",
|
|
95
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
96
|
+
"eslint-import-resolver-typescript": "^2.7.1",
|
|
97
|
+
"eslint-plugin-import": "^2.26.0",
|
|
98
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
99
|
+
"eslint-plugin-prettier-vue": "^3.1.0",
|
|
100
|
+
"eslint-plugin-tsdoc": "^0.2.14",
|
|
101
|
+
"eslint-plugin-vue": "^8.5.0",
|
|
102
|
+
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
103
|
+
"husky": "^7.0.4",
|
|
104
|
+
"lint-staged": "^12.3.7",
|
|
105
|
+
"lodash": "^4.17.21",
|
|
106
|
+
"prettier": "^2.6.2",
|
|
107
|
+
"prettier-plugin-jsdoc": "^0.3.36",
|
|
108
|
+
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
109
|
+
"prettier-plugin-sort-imports": "^1.6.0",
|
|
110
|
+
"rimraf": "^3.0.2",
|
|
111
|
+
"typescript": "^4.6.3",
|
|
112
|
+
"vite": "^2.9.1",
|
|
113
|
+
"vite-plugin-vue2": "^1.9.3",
|
|
114
|
+
"vue": "^2.6.14",
|
|
115
|
+
"vue-eslint-parser": "^8.3.0",
|
|
116
|
+
"vue-template-compiler": "^2.6.14",
|
|
117
|
+
"vue-tsc": "^0.33.9"
|
|
118
|
+
},
|
|
119
|
+
"husky": {
|
|
120
|
+
"hooks": {
|
|
121
|
+
"pre-commit": "lint-staged"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"lint-staged": {
|
|
125
|
+
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
126
|
+
"*": "prettier -w -u"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,203 +1,239 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
</
|
|
2
|
+
<div ref="editor" class="vue-codemirror">
|
|
3
|
+
<aside v-show="!context.slots.default"><slot /></aside>
|
|
4
|
+
</div>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
|
9
|
-
import type { VNode } from 'vue';
|
|
10
|
-
|
|
11
8
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
|
|
9
|
+
computed,
|
|
10
|
+
ref,
|
|
11
|
+
watch,
|
|
12
|
+
onMounted,
|
|
13
|
+
onUnmounted,
|
|
14
|
+
defineComponent,
|
|
15
|
+
} from 'vue-demi';
|
|
16
|
+
import { EditorState } from '@codemirror/state';
|
|
17
|
+
import { EditorView } from '@codemirror/view';
|
|
21
18
|
import { compact, merge } from 'lodash';
|
|
22
19
|
|
|
23
|
-
|
|
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;
|
|
20
|
+
import type { ComputedRef, Ref, PropType, SetupContext } from 'vue-demi';
|
|
40
21
|
|
|
41
|
-
|
|
42
|
-
* Readonly
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
45
|
-
*/
|
|
46
|
-
@Prop({ type: Boolean, default: false })
|
|
47
|
-
readonly readonly!: boolean;
|
|
22
|
+
import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
|
|
48
23
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@Prop({ type: Boolean, default: true })
|
|
55
|
-
readonly editable!: boolean;
|
|
24
|
+
import type { Extension, Transaction } from '@codemirror/state';
|
|
25
|
+
import type { LanguageSupport } from '@codemirror/language';
|
|
26
|
+
import type { ViewUpdate } from '@codemirror/view';
|
|
27
|
+
import type { Diagnostic } from '@codemirror/lint';
|
|
28
|
+
import type { StyleSpec } from 'style-mod';
|
|
56
29
|
|
|
30
|
+
/** CodeMirror Component */
|
|
31
|
+
export default defineComponent({
|
|
32
|
+
/** Component Name */
|
|
33
|
+
name: 'CodeMirror',
|
|
34
|
+
/** Model Definition */
|
|
35
|
+
model: {
|
|
36
|
+
prop: 'modelValue',
|
|
37
|
+
event: 'update:modelValue',
|
|
38
|
+
},
|
|
39
|
+
/** Props Definition */
|
|
40
|
+
props: {
|
|
41
|
+
/** Model value */
|
|
42
|
+
modelValue: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: '',
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Theme
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
50
|
+
*/
|
|
51
|
+
theme: {
|
|
52
|
+
type: Object as PropType<{ [selector: string]: StyleSpec }>,
|
|
53
|
+
default: undefined,
|
|
54
|
+
},
|
|
55
|
+
/** Dark Mode */
|
|
56
|
+
dark: {
|
|
57
|
+
type: Boolean,
|
|
58
|
+
default: false,
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Readonly
|
|
62
|
+
*
|
|
63
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
64
|
+
*/
|
|
65
|
+
readonly: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
default: false,
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Editable
|
|
71
|
+
*
|
|
72
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
|
|
73
|
+
*/
|
|
74
|
+
editable: {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
default: true,
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* Additional Extension
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
82
|
+
*/
|
|
83
|
+
extensions: {
|
|
84
|
+
type: Array as PropType<Extension[]>,
|
|
85
|
+
default: undefined,
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Language Phreses
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
91
|
+
*/
|
|
92
|
+
phrases: {
|
|
93
|
+
type: Object as PropType<Record<string, string>>,
|
|
94
|
+
default: undefined,
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* CodeMirror Language
|
|
98
|
+
*
|
|
99
|
+
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
100
|
+
*/
|
|
101
|
+
lang: {
|
|
102
|
+
type: Object as PropType<LanguageSupport>,
|
|
103
|
+
default: undefined,
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* CodeMirror Linter
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
109
|
+
*/
|
|
110
|
+
linter: {
|
|
111
|
+
type: Array as PropType<Diagnostic[]>,
|
|
112
|
+
default: undefined,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
/** Emits */
|
|
116
|
+
emits: ['update:modelValue', 'update'],
|
|
57
117
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
118
|
+
* Setup
|
|
119
|
+
* @param props - Props
|
|
120
|
+
* @param context - Context
|
|
61
121
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
122
|
+
setup(props, context: SetupContext) {
|
|
123
|
+
/** Editor DOM */
|
|
124
|
+
const editor: Ref<Element | undefined> = ref<Element>();
|
|
125
|
+
|
|
126
|
+
/** Model */
|
|
127
|
+
const modelValue: Ref<string> = ref(props.modelValue);
|
|
128
|
+
|
|
129
|
+
/** Dark mode */
|
|
130
|
+
const dark: Ref<boolean | undefined> = ref(props.dark);
|
|
131
|
+
|
|
132
|
+
/** Emits */
|
|
133
|
+
const emit = context.emit as CodeMirrorEmitsInterface;
|
|
134
|
+
|
|
135
|
+
/** CodeMirror Extension */
|
|
136
|
+
const extensions: ComputedRef<Extension[]> = computed(() => {
|
|
137
|
+
/** Default extension */
|
|
138
|
+
const ext = [
|
|
139
|
+
// ViewUpdate event listener
|
|
140
|
+
EditorView.updateListener.of((update: ViewUpdate) => {
|
|
141
|
+
emit('update', update);
|
|
142
|
+
}),
|
|
143
|
+
// Toggle light/dark mode.
|
|
144
|
+
EditorView.theme(props.theme || {}, { dark: dark.value }),
|
|
145
|
+
// locale settings
|
|
146
|
+
props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
|
|
147
|
+
// Parser language setting
|
|
148
|
+
props.lang,
|
|
149
|
+
// Readonly option
|
|
150
|
+
props.readonly ? EditorState.readOnly.of(props.readonly) : undefined,
|
|
151
|
+
// Editable option
|
|
152
|
+
props.editable ? EditorView.editable.of(props.editable) : undefined,
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
if (props.linter) {
|
|
156
|
+
// Append Linter settings
|
|
157
|
+
merge(ext, props.linter);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (props.extensions) {
|
|
161
|
+
// Append Extensions (such as basic-setup)
|
|
162
|
+
merge(ext, props.extensions);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// console.debug('[CodeMirror.vue] Loaded extensions:', ext, compact(ext));
|
|
166
|
+
return compact(ext);
|
|
167
|
+
});
|
|
64
168
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
169
|
+
/** CodeMirror Editor View */
|
|
170
|
+
let view!: EditorView;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Input value changed
|
|
174
|
+
*
|
|
175
|
+
* @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
|
|
176
|
+
*/
|
|
177
|
+
watch(modelValue, current => {
|
|
178
|
+
if (view.composing) {
|
|
179
|
+
// IME fix
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Previous cursor location */
|
|
184
|
+
const previous = view.state.selection;
|
|
185
|
+
view.setState(
|
|
186
|
+
EditorState.create({
|
|
187
|
+
doc: current,
|
|
188
|
+
extensions: extensions.value,
|
|
189
|
+
selection: previous,
|
|
190
|
+
})
|
|
191
|
+
);
|
|
192
|
+
});
|
|
72
193
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
194
|
+
/** Toggle Dark mode */
|
|
195
|
+
watch(dark, () => {
|
|
196
|
+
view.setState(
|
|
197
|
+
EditorState.create({
|
|
198
|
+
doc: modelValue.value,
|
|
199
|
+
extensions: extensions.value,
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
});
|
|
80
203
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
204
|
+
/** When loaded */
|
|
205
|
+
onMounted(() => {
|
|
206
|
+
/** Initial Value */
|
|
207
|
+
const value =
|
|
208
|
+
!modelValue.value && editor.value
|
|
209
|
+
? (editor.value.childNodes[0] as HTMLDivElement).innerText
|
|
210
|
+
: modelValue.value;
|
|
211
|
+
|
|
212
|
+
// Register Codemirror
|
|
213
|
+
view = new EditorView({
|
|
214
|
+
state: EditorState.create({
|
|
215
|
+
doc: value,
|
|
216
|
+
extensions: extensions.value,
|
|
217
|
+
}),
|
|
218
|
+
parent: editor.value,
|
|
219
|
+
dispatch: (tr: Transaction) => {
|
|
220
|
+
view.update([tr]);
|
|
221
|
+
|
|
222
|
+
if (tr.changes.empty) return;
|
|
223
|
+
// to parent binding
|
|
224
|
+
modelValue.value = view.state.doc.toString();
|
|
225
|
+
emit('update:modelValue', modelValue.value);
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
});
|
|
88
229
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
readonly value!: string;
|
|
230
|
+
/** Destroy */
|
|
231
|
+
onUnmounted(() => view.destroy());
|
|
92
232
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
onValueChanged() {
|
|
100
|
-
if (this.editor.composing) {
|
|
101
|
-
// IME fix
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
/** Previous cursor location */
|
|
105
|
-
const previous = this.editor.state.selection;
|
|
106
|
-
this.editor.setState(
|
|
107
|
-
EditorState.create({
|
|
108
|
-
doc: this.value,
|
|
109
|
-
extensions: this.extension,
|
|
110
|
-
selection: previous,
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Toggle Dark mode */
|
|
116
|
-
@Watch('dark')
|
|
117
|
-
onToggleDarkMode() {
|
|
118
|
-
this.editor.setState(
|
|
119
|
-
EditorState.create({
|
|
120
|
-
doc: this.value,
|
|
121
|
-
extensions: this.extension,
|
|
122
|
-
})
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** CodeMirror Extension */
|
|
127
|
-
get extension(): Extension[] {
|
|
128
|
-
/** Default extension */
|
|
129
|
-
const ext: Extension[] = compact([
|
|
130
|
-
// ViewUpdate event listener
|
|
131
|
-
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
132
|
-
this.$emit('update', update)
|
|
133
|
-
),
|
|
134
|
-
// Toggle light/dark mode.
|
|
135
|
-
EditorView.theme(this.theme, { dark: this.dark }),
|
|
136
|
-
// locale settings
|
|
137
|
-
this.phrases ? EditorState.phrases.of(this.phrases) : undefined,
|
|
138
|
-
// Parser language setting
|
|
139
|
-
this.lang ? this.lang : undefined,
|
|
140
|
-
// Readonly option
|
|
141
|
-
EditorState.readOnly.of(this.readonly),
|
|
142
|
-
// Editable option
|
|
143
|
-
EditorView.editable.of(this.editable),
|
|
144
|
-
]);
|
|
145
|
-
|
|
146
|
-
if (this.linter.length !== 0) {
|
|
147
|
-
// Append Linter settings
|
|
148
|
-
merge(ext, this.linter);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (this.extensions.length !== 0) {
|
|
152
|
-
// Append Extensions (such as basic-setup)
|
|
153
|
-
merge(ext, this.extensions);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
console.debug('[CodeMirror.vue] Loaded extensions:', ext);
|
|
157
|
-
|
|
158
|
-
return ext;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** When loaded */
|
|
162
|
-
mounted() {
|
|
163
|
-
let value = this.value;
|
|
164
|
-
if (!this.value && this.$slots.default !== undefined) {
|
|
165
|
-
// override text node
|
|
166
|
-
// console.log(this.$slots.default);
|
|
167
|
-
value = this.getChildrenTextContent(this.$slots.default);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Register Codemirror
|
|
171
|
-
this.editor = new EditorView({
|
|
172
|
-
state: EditorState.create({
|
|
173
|
-
doc: value,
|
|
174
|
-
extensions: this.extension,
|
|
175
|
-
}),
|
|
176
|
-
parent: this.$refs.editor as Element,
|
|
177
|
-
dispatch: (tr: Transaction) => {
|
|
178
|
-
this.editor.update([tr]);
|
|
179
|
-
|
|
180
|
-
if (tr.changes.empty) return;
|
|
181
|
-
// to parent binding
|
|
182
|
-
this.$emit('input', this.editor.state.doc.toString());
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** Destroy */
|
|
188
|
-
beforeDestroy() {
|
|
189
|
-
this.editor.destroy();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/** Vue node to plain text */
|
|
193
|
-
private getChildrenTextContent(children: VNode[]): string {
|
|
194
|
-
return children
|
|
195
|
-
.map((node: VNode) =>
|
|
196
|
-
node.children
|
|
197
|
-
? this.getChildrenTextContent(node.children)
|
|
198
|
-
: node.text || '\n'
|
|
199
|
-
)
|
|
200
|
-
.join('');
|
|
201
|
-
}
|
|
202
|
-
}
|
|
233
|
+
return {
|
|
234
|
+
context,
|
|
235
|
+
editor,
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
});
|
|
203
239
|
</script>
|
package/dist/index.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=index.esm.d.ts.map
|