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
|
@@ -1,75 +1,176 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Ref, PropType, SetupContext } from 'vue-demi';
|
|
2
|
+
import type { Extension } from '@codemirror/state';
|
|
3
3
|
import type { LanguageSupport } from '@codemirror/language';
|
|
4
4
|
import type { Diagnostic } from '@codemirror/lint';
|
|
5
5
|
import type { StyleSpec } from 'style-mod';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
declare const _default: import("vue-demi").DefineComponent<{
|
|
7
|
+
/** Model value */
|
|
8
|
+
modelValue: {
|
|
9
|
+
type: StringConstructor;
|
|
10
|
+
default: string;
|
|
11
|
+
};
|
|
10
12
|
/**
|
|
11
13
|
* Theme
|
|
12
14
|
*
|
|
13
15
|
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
14
16
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
theme: {
|
|
18
|
+
type: PropType<{
|
|
19
|
+
[selector: string]: StyleSpec;
|
|
20
|
+
}>;
|
|
21
|
+
default: undefined;
|
|
17
22
|
};
|
|
18
23
|
/** Dark Mode */
|
|
19
|
-
|
|
24
|
+
dark: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
default: boolean;
|
|
27
|
+
};
|
|
20
28
|
/**
|
|
21
29
|
* Readonly
|
|
22
30
|
*
|
|
23
31
|
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
24
32
|
*/
|
|
25
|
-
readonly
|
|
33
|
+
readonly: {
|
|
34
|
+
type: BooleanConstructor;
|
|
35
|
+
default: boolean;
|
|
36
|
+
};
|
|
26
37
|
/**
|
|
27
38
|
* Editable
|
|
28
39
|
*
|
|
29
40
|
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
|
|
30
41
|
*/
|
|
31
|
-
|
|
42
|
+
editable: {
|
|
43
|
+
type: BooleanConstructor;
|
|
44
|
+
default: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Additional Extension
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
50
|
+
*/
|
|
51
|
+
extensions: {
|
|
52
|
+
type: PropType<Extension[]>;
|
|
53
|
+
default: undefined;
|
|
54
|
+
};
|
|
32
55
|
/**
|
|
33
56
|
* Language Phreses
|
|
34
57
|
*
|
|
35
58
|
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
36
59
|
*/
|
|
37
|
-
|
|
60
|
+
phrases: {
|
|
61
|
+
type: PropType<Record<string, string>>;
|
|
62
|
+
default: undefined;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* CodeMirror Language
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
68
|
+
*/
|
|
69
|
+
lang: {
|
|
70
|
+
type: PropType<LanguageSupport>;
|
|
71
|
+
default: undefined;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* CodeMirror Linter
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
77
|
+
*/
|
|
78
|
+
linter: {
|
|
79
|
+
type: PropType<Diagnostic[]>;
|
|
80
|
+
default: undefined;
|
|
81
|
+
};
|
|
82
|
+
}, {
|
|
83
|
+
context: SetupContext<import("vue-demi").EmitsOptions>;
|
|
84
|
+
editor: Ref<Element | undefined>;
|
|
85
|
+
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
86
|
+
/** Model value */
|
|
87
|
+
modelValue: {
|
|
88
|
+
type: StringConstructor;
|
|
89
|
+
default: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Theme
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
95
|
+
*/
|
|
96
|
+
theme: {
|
|
97
|
+
type: PropType<{
|
|
98
|
+
[selector: string]: StyleSpec;
|
|
99
|
+
}>;
|
|
100
|
+
default: undefined;
|
|
101
|
+
};
|
|
102
|
+
/** Dark Mode */
|
|
103
|
+
dark: {
|
|
104
|
+
type: BooleanConstructor;
|
|
105
|
+
default: boolean;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Readonly
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
111
|
+
*/
|
|
112
|
+
readonly: {
|
|
113
|
+
type: BooleanConstructor;
|
|
114
|
+
default: boolean;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Editable
|
|
118
|
+
*
|
|
119
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
|
|
120
|
+
*/
|
|
121
|
+
editable: {
|
|
122
|
+
type: BooleanConstructor;
|
|
123
|
+
default: boolean;
|
|
124
|
+
};
|
|
38
125
|
/**
|
|
39
126
|
* Additional Extension
|
|
40
127
|
*
|
|
41
128
|
* @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
42
129
|
*/
|
|
43
|
-
|
|
130
|
+
extensions: {
|
|
131
|
+
type: PropType<Extension[]>;
|
|
132
|
+
default: undefined;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Language Phreses
|
|
136
|
+
*
|
|
137
|
+
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
138
|
+
*/
|
|
139
|
+
phrases: {
|
|
140
|
+
type: PropType<Record<string, string>>;
|
|
141
|
+
default: undefined;
|
|
142
|
+
};
|
|
44
143
|
/**
|
|
45
144
|
* CodeMirror Language
|
|
46
145
|
*
|
|
47
146
|
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
48
147
|
*/
|
|
49
|
-
|
|
148
|
+
lang: {
|
|
149
|
+
type: PropType<LanguageSupport>;
|
|
150
|
+
default: undefined;
|
|
151
|
+
};
|
|
50
152
|
/**
|
|
51
153
|
* CodeMirror Linter
|
|
52
154
|
*
|
|
53
155
|
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
54
156
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
157
|
+
linter: {
|
|
158
|
+
type: PropType<Diagnostic[]>;
|
|
159
|
+
default: undefined;
|
|
160
|
+
};
|
|
161
|
+
}>>, {
|
|
162
|
+
modelValue: string;
|
|
163
|
+
theme: {
|
|
164
|
+
[selector: string]: StyleSpec;
|
|
165
|
+
};
|
|
166
|
+
dark: boolean;
|
|
167
|
+
readonly: boolean;
|
|
168
|
+
editable: boolean;
|
|
169
|
+
extensions: Extension[];
|
|
170
|
+
phrases: Record<string, string>;
|
|
171
|
+
lang: LanguageSupport;
|
|
172
|
+
linter: Diagnostic[];
|
|
173
|
+
}>;
|
|
174
|
+
/** CodeMirror Component */
|
|
175
|
+
export default _default;
|
|
75
176
|
//# sourceMappingURL=CodeMirror.vue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAe,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIzE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;;IAavC,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IApEH,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;;;;;;;;;;AA/EP,2BAA2B;AAC3B,wBA+MG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Vue CodeMirror6 Component
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @author Logue {@link logue@hotmail.co.jp}
|
|
6
|
+
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
+
*/
|
|
9
|
+
import CodeMirror from './components/CodeMirror.vue';
|
|
10
|
+
import { App } from 'vue-demi';
|
|
11
|
+
declare const installCodeMirror: (app: App) => void;
|
|
12
|
+
export { CodeMirror, installCodeMirror as install };
|
|
13
|
+
export default CodeMirror;
|
|
4
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAW,GAAG,EAAE,MAAM,UAAU,CAAC;AAIxC,QAAA,MAAM,iBAAiB,QAAS,GAAG,SAElC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC;AACpD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ViewUpdate } from '@codemirror/view';
|
|
2
|
+
/** Emit Interface */
|
|
3
|
+
export default interface CodeMirrorEmitsInterface {
|
|
4
|
+
/** Model Update */
|
|
5
|
+
(e: 'update:modelValue', value: string): void;
|
|
6
|
+
/** CodeMirror ViewUpdate */
|
|
7
|
+
(e: 'update', value: ViewUpdate): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=CodeMirrorEmitsInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeMirrorEmitsInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/CodeMirrorEmitsInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAqB;AACrB,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC"}
|
|
@@ -1,198 +1,150 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineComponent, ref, computed, watch, onMounted, onUnmounted, install } from "vue-demi";
|
|
2
2
|
import { EditorState } from "@codemirror/state";
|
|
3
3
|
import { EditorView } from "@codemirror/view";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (decorator = decorators[i])
|
|
11
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
12
|
-
if (kind && result)
|
|
13
|
-
__defProp(target, key, result);
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
let CodeMirror = class extends Vue {
|
|
17
|
-
onValueChanged() {
|
|
18
|
-
if (this.editor.composing) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const previous = this.editor.state.selection;
|
|
22
|
-
this.editor.setState(EditorState.create({
|
|
23
|
-
doc: this.value,
|
|
24
|
-
extensions: this.extension,
|
|
25
|
-
selection: previous
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
onToggleDarkMode() {
|
|
29
|
-
this.editor.setState(EditorState.create({
|
|
30
|
-
doc: this.value,
|
|
31
|
-
extensions: this.extension
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
get extension() {
|
|
35
|
-
const ext = compact([
|
|
36
|
-
EditorView.updateListener.of((update) => this.$emit("update", update)),
|
|
37
|
-
EditorView.theme(this.theme, { dark: this.dark }),
|
|
38
|
-
this.phrases ? EditorState.phrases.of(this.phrases) : void 0,
|
|
39
|
-
this.lang ? this.lang : void 0,
|
|
40
|
-
EditorState.readOnly.of(this.readonly),
|
|
41
|
-
EditorView.editable.of(this.editable)
|
|
42
|
-
]);
|
|
43
|
-
if (this.linter.length !== 0) {
|
|
44
|
-
merge(ext, this.linter);
|
|
45
|
-
}
|
|
46
|
-
if (this.extensions.length !== 0) {
|
|
47
|
-
merge(ext, this.extensions);
|
|
48
|
-
}
|
|
49
|
-
console.debug("[CodeMirror.vue] Loaded extensions:", ext);
|
|
50
|
-
return ext;
|
|
51
|
-
}
|
|
52
|
-
mounted() {
|
|
53
|
-
let value = this.value;
|
|
54
|
-
if (!this.value && this.$slots.default !== void 0) {
|
|
55
|
-
value = this.getChildrenTextContent(this.$slots.default);
|
|
56
|
-
}
|
|
57
|
-
this.editor = new EditorView({
|
|
58
|
-
state: EditorState.create({
|
|
59
|
-
doc: value,
|
|
60
|
-
extensions: this.extension
|
|
61
|
-
}),
|
|
62
|
-
parent: this.$refs.editor,
|
|
63
|
-
dispatch: (tr) => {
|
|
64
|
-
this.editor.update([tr]);
|
|
65
|
-
if (tr.changes.empty)
|
|
66
|
-
return;
|
|
67
|
-
this.$emit("input", this.editor.state.doc.toString());
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
beforeDestroy() {
|
|
72
|
-
this.editor.destroy();
|
|
73
|
-
}
|
|
74
|
-
getChildrenTextContent(children) {
|
|
75
|
-
return children.map((node) => node.children ? this.getChildrenTextContent(node.children) : node.text || "\n").join("");
|
|
4
|
+
import { merge, compact } from "lodash";
|
|
5
|
+
import { openBlock, createElementBlock, withDirectives, createElementVNode, renderSlot, vShow } from "vue";
|
|
6
|
+
var _export_sfc = (sfc, props) => {
|
|
7
|
+
const target = sfc.__vccOpts || sfc;
|
|
8
|
+
for (const [key, val] of props) {
|
|
9
|
+
target[key] = val;
|
|
76
10
|
}
|
|
11
|
+
return target;
|
|
77
12
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
13
|
+
const _sfc_main = defineComponent({
|
|
14
|
+
name: "CodeMirror",
|
|
15
|
+
model: {
|
|
16
|
+
prop: "modelValue",
|
|
17
|
+
event: "update:modelValue"
|
|
18
|
+
},
|
|
19
|
+
props: {
|
|
20
|
+
modelValue: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: ""
|
|
23
|
+
},
|
|
24
|
+
theme: {
|
|
25
|
+
type: Object,
|
|
26
|
+
default: void 0
|
|
27
|
+
},
|
|
28
|
+
dark: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: false
|
|
31
|
+
},
|
|
32
|
+
readonly: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: false
|
|
35
|
+
},
|
|
36
|
+
editable: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: true
|
|
39
|
+
},
|
|
40
|
+
extensions: {
|
|
41
|
+
type: Array,
|
|
42
|
+
default: void 0
|
|
43
|
+
},
|
|
44
|
+
phrases: {
|
|
45
|
+
type: Object,
|
|
46
|
+
default: void 0
|
|
47
|
+
},
|
|
48
|
+
lang: {
|
|
49
|
+
type: Object,
|
|
50
|
+
default: void 0
|
|
51
|
+
},
|
|
52
|
+
linter: {
|
|
53
|
+
type: Array,
|
|
54
|
+
default: void 0
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
emits: ["update:modelValue", "update"],
|
|
58
|
+
setup(props, context) {
|
|
59
|
+
const editor = ref();
|
|
60
|
+
const modelValue = ref(props.modelValue);
|
|
61
|
+
const dark = ref(props.dark);
|
|
62
|
+
const emit = context.emit;
|
|
63
|
+
const extensions = computed(() => {
|
|
64
|
+
const ext = [
|
|
65
|
+
EditorView.updateListener.of((update) => {
|
|
66
|
+
emit("update", update);
|
|
67
|
+
}),
|
|
68
|
+
EditorView.theme(props.theme || {}, { dark: dark.value }),
|
|
69
|
+
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
70
|
+
props.lang,
|
|
71
|
+
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
72
|
+
props.editable ? EditorView.editable.of(props.editable) : void 0
|
|
73
|
+
];
|
|
74
|
+
if (props.linter) {
|
|
75
|
+
merge(ext, props.linter);
|
|
141
76
|
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
77
|
+
if (props.extensions) {
|
|
78
|
+
merge(ext, props.extensions);
|
|
144
79
|
}
|
|
145
|
-
|
|
146
|
-
|
|
80
|
+
return compact(ext);
|
|
81
|
+
});
|
|
82
|
+
let view;
|
|
83
|
+
watch(modelValue, (current) => {
|
|
84
|
+
if (view.composing) {
|
|
85
|
+
return;
|
|
147
86
|
}
|
|
87
|
+
const previous = view.state.selection;
|
|
88
|
+
view.setState(EditorState.create({
|
|
89
|
+
doc: current,
|
|
90
|
+
extensions: extensions.value,
|
|
91
|
+
selection: previous
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
watch(dark, () => {
|
|
95
|
+
view.setState(EditorState.create({
|
|
96
|
+
doc: modelValue.value,
|
|
97
|
+
extensions: extensions.value
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
onMounted(() => {
|
|
101
|
+
const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
|
|
102
|
+
view = new EditorView({
|
|
103
|
+
state: EditorState.create({
|
|
104
|
+
doc: value,
|
|
105
|
+
extensions: extensions.value
|
|
106
|
+
}),
|
|
107
|
+
parent: editor.value,
|
|
108
|
+
dispatch: (tr) => {
|
|
109
|
+
view.update([tr]);
|
|
110
|
+
if (tr.changes.empty)
|
|
111
|
+
return;
|
|
112
|
+
modelValue.value = view.state.doc.toString();
|
|
113
|
+
emit("update:modelValue", modelValue.value);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
onUnmounted(() => view.destroy());
|
|
118
|
+
return {
|
|
119
|
+
context,
|
|
120
|
+
editor
|
|
148
121
|
};
|
|
149
|
-
options._ssrRegister = hook;
|
|
150
|
-
} else if (injectStyles) {
|
|
151
|
-
hook = shadowMode ? function() {
|
|
152
|
-
injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot);
|
|
153
|
-
} : injectStyles;
|
|
154
|
-
}
|
|
155
|
-
if (hook) {
|
|
156
|
-
if (options.functional) {
|
|
157
|
-
options._injectStyles = hook;
|
|
158
|
-
var originalRender = options.render;
|
|
159
|
-
options.render = function renderWithStyleInjection(h, context) {
|
|
160
|
-
hook.call(context);
|
|
161
|
-
return originalRender(h, context);
|
|
162
|
-
};
|
|
163
|
-
} else {
|
|
164
|
-
var existing = options.beforeCreate;
|
|
165
|
-
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
exports: scriptExports,
|
|
170
|
-
options
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
const __cssModules = {};
|
|
174
|
-
var __component__ = /* @__PURE__ */ normalizeComponent(CodeMirror, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
|
|
175
|
-
function __vue2_injectStyles(context) {
|
|
176
|
-
for (let o in __cssModules) {
|
|
177
|
-
this[o] = __cssModules[o];
|
|
178
122
|
}
|
|
179
|
-
}
|
|
180
|
-
var component$1 = /* @__PURE__ */ function() {
|
|
181
|
-
return __component__.exports;
|
|
182
|
-
}();
|
|
183
|
-
var component = /* @__PURE__ */ (() => {
|
|
184
|
-
const installable = component$1;
|
|
185
|
-
installable.install = (Vue2) => {
|
|
186
|
-
Vue2.component("CodeMirror", installable);
|
|
187
|
-
};
|
|
188
|
-
return installable;
|
|
189
|
-
})();
|
|
190
|
-
var namedExports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
191
|
-
__proto__: null,
|
|
192
|
-
"default": component
|
|
193
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
194
|
-
Object.entries(namedExports).forEach(([exportName, exported]) => {
|
|
195
|
-
if (exportName !== "default")
|
|
196
|
-
component[exportName] = exported;
|
|
197
123
|
});
|
|
198
|
-
|
|
124
|
+
const _hoisted_1 = {
|
|
125
|
+
ref: "editor",
|
|
126
|
+
class: "vue-codemirror"
|
|
127
|
+
};
|
|
128
|
+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
129
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
130
|
+
withDirectives(createElementVNode("aside", null, [
|
|
131
|
+
renderSlot(_ctx.$slots, "default")
|
|
132
|
+
], 512), [
|
|
133
|
+
[vShow, !_ctx.context.slots.default]
|
|
134
|
+
])
|
|
135
|
+
], 512);
|
|
136
|
+
}
|
|
137
|
+
var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
138
|
+
/**
|
|
139
|
+
* Vue CodeMirror6 Component
|
|
140
|
+
*
|
|
141
|
+
* @license MIT
|
|
142
|
+
* @author Logue {@link logue@hotmail.co.jp}
|
|
143
|
+
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
144
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
145
|
+
*/
|
|
146
|
+
install();
|
|
147
|
+
const installCodeMirror = (app) => {
|
|
148
|
+
app.component("CodeMirror", CodeMirror);
|
|
149
|
+
};
|
|
150
|
+
export { CodeMirror, CodeMirror as default, installCodeMirror as install };
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
(function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.lodash,o.Vue))})(this,function(o,t,s,f,m,i){"use strict";var p=(e,u)=>{const d=e.__vccOpts||e;for(const[r,c]of u)d[r]=c;return d};const V=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:void 0},dark:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:void 0},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Array,default:void 0}},emits:["update:modelValue","update"],setup(e,u){const d=t.ref(),r=t.ref(e.modelValue),c=t.ref(e.dark),y=u.emit,h=t.computed(()=>{const a=[f.EditorView.updateListener.of(l=>{y("update",l)}),f.EditorView.theme(e.theme||{},{dark:c.value}),e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?f.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(a,e.linter),e.extensions&&m.merge(a,e.extensions),m.compact(a)});let n;return t.watch(r,a=>{if(n.composing)return;const l=n.state.selection;n.setState(s.EditorState.create({doc:a,extensions:h.value,selection:l}))}),t.watch(c,()=>{n.setState(s.EditorState.create({doc:r.value,extensions:h.value}))}),t.onMounted(()=>{const a=!r.value&&d.value?d.value.childNodes[0].innerText:r.value;n=new f.EditorView({state:s.EditorState.create({doc:a,extensions:h.value}),parent:d.value,dispatch:l=>{n.update([l]),!l.changes.empty&&(r.value=n.state.doc.toString(),y("update:modelValue",r.value))}})}),t.onUnmounted(()=>n.destroy()),{context:u,editor:d}}}),S={ref:"editor",class:"vue-codemirror"};function _(e,u,d,r,c,y){return i.openBlock(),i.createElementBlock("div",S,[i.withDirectives(i.createElementVNode("aside",null,[i.renderSlot(e.$slots,"default")],512),[[i.vShow,!e.context.slots.default]])],512)}var v=p(V,[["render",_]]);/**
|
|
2
|
+
* Vue CodeMirror6 Component
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @author Logue {@link logue@hotmail.co.jp}
|
|
6
|
+
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
+
*/t.install();const E=e=>{e.component("CodeMirror",v)};o.CodeMirror=v,o.default=v,o.install=E,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|