vue-codemirror6 0.3.5 → 0.3.6
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 +3 -0
- package/dist/components/CodeMirror.vue.d.ts +230 -8
- package/dist/components/CodeMirror.vue.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/vue-codemirror6.es.js +47 -24
- package/dist/vue-codemirror6.umd.js +2 -2
- package/package.json +14 -10
- package/src/components/CodeMirror.vue +89 -43
package/README.md
CHANGED
|
@@ -19,7 +19,10 @@ When using with Vue2, [@vue/composition-api](https://www.npmjs.com/package/@vue/
|
|
|
19
19
|
|
|
20
20
|
| Props | Type | Information |
|
|
21
21
|
| ---------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| basic | boolean | Use [basic-setup](https://codemirror.net/6/docs/ref/#basic-setup). |
|
|
22
23
|
| dark | boolean | Toggle Darkmode. If you use Vuetify, I recommend that you enter `$vuetify.theme.dark`. |
|
|
24
|
+
| wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
|
|
25
|
+
| tab | boolean | Enables tab indentation. |
|
|
23
26
|
| theme | { [selector: string]: StyleSpec } | Specify the theme. For example, if you use [@codemirror/theme-one-dark](https://github.com/codemirror/theme-one-dark), import `oneDark` and put it in this prop. |
|
|
24
27
|
| readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
|
|
25
28
|
| editable | boolean | When this is set to false, it is similar to `readonly`, except that the cursor is not displayed like the normal pre tag. |
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import
|
|
1
|
+
import { type PropType, type Ref, type SetupContext } from 'vue-demi';
|
|
2
|
+
import { EditorSelection } from '@codemirror/state';
|
|
3
|
+
import type { Extension, Text } from '@codemirror/state';
|
|
3
4
|
import type { LanguageSupport } from '@codemirror/language';
|
|
4
5
|
import type { Diagnostic } from '@codemirror/lint';
|
|
5
6
|
import type { StyleSpec } from 'style-mod';
|
|
6
7
|
declare const _default: import("vue-demi").DefineComponent<{
|
|
7
8
|
/** Model value */
|
|
8
9
|
modelValue: {
|
|
9
|
-
type:
|
|
10
|
+
type: PropType<string | Text>;
|
|
10
11
|
default: string;
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Selection
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
17
|
+
*/
|
|
18
|
+
selection: {
|
|
19
|
+
type: PropType<EditorSelection | {
|
|
20
|
+
anchor: number;
|
|
21
|
+
head?: number | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
default: undefined;
|
|
24
|
+
};
|
|
12
25
|
/**
|
|
13
26
|
* Theme
|
|
14
27
|
*
|
|
@@ -18,13 +31,40 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
18
31
|
type: PropType<{
|
|
19
32
|
[selector: string]: StyleSpec;
|
|
20
33
|
}>;
|
|
21
|
-
default: () =>
|
|
34
|
+
default: () => {};
|
|
22
35
|
};
|
|
23
36
|
/** Dark Mode */
|
|
24
37
|
dark: {
|
|
25
38
|
type: BooleanConstructor;
|
|
26
39
|
default: boolean;
|
|
27
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Use Basic Setup
|
|
43
|
+
*
|
|
44
|
+
* @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
|
|
45
|
+
*/
|
|
46
|
+
basic: {
|
|
47
|
+
type: BooleanConstructor;
|
|
48
|
+
default: boolean;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Line wrapping
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
|
|
54
|
+
*/
|
|
55
|
+
wrap: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
default: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Tab handling
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
|
|
63
|
+
*/
|
|
64
|
+
tab: {
|
|
65
|
+
type: BooleanConstructor;
|
|
66
|
+
default: boolean;
|
|
67
|
+
};
|
|
28
68
|
/**
|
|
29
69
|
* Readonly
|
|
30
70
|
*
|
|
@@ -82,12 +122,160 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
82
122
|
}, {
|
|
83
123
|
context: SetupContext<import("vue-demi").EmitsOptions>;
|
|
84
124
|
editor: Ref<Element | undefined>;
|
|
85
|
-
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").
|
|
125
|
+
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").ComponentProvideOptions, {
|
|
126
|
+
/** Component Name */
|
|
127
|
+
name: string;
|
|
128
|
+
/** Model Definition */
|
|
129
|
+
model: {
|
|
130
|
+
prop: string;
|
|
131
|
+
event: string;
|
|
132
|
+
};
|
|
133
|
+
/** Props Definition */
|
|
134
|
+
props: {
|
|
135
|
+
/** Model value */
|
|
136
|
+
modelValue: {
|
|
137
|
+
type: PropType<string | Text>;
|
|
138
|
+
default: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Selection
|
|
142
|
+
*
|
|
143
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
144
|
+
*/
|
|
145
|
+
selection: {
|
|
146
|
+
type: PropType<EditorSelection | {
|
|
147
|
+
anchor: number;
|
|
148
|
+
head?: number | undefined;
|
|
149
|
+
}>;
|
|
150
|
+
default: undefined;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Theme
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
156
|
+
*/
|
|
157
|
+
theme: {
|
|
158
|
+
type: PropType<{
|
|
159
|
+
[selector: string]: StyleSpec;
|
|
160
|
+
}>;
|
|
161
|
+
default: () => {};
|
|
162
|
+
};
|
|
163
|
+
/** Dark Mode */
|
|
164
|
+
dark: {
|
|
165
|
+
type: BooleanConstructor;
|
|
166
|
+
default: boolean;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Use Basic Setup
|
|
170
|
+
*
|
|
171
|
+
* @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
|
|
172
|
+
*/
|
|
173
|
+
basic: {
|
|
174
|
+
type: BooleanConstructor;
|
|
175
|
+
default: boolean;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Line wrapping
|
|
179
|
+
*
|
|
180
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
|
|
181
|
+
*/
|
|
182
|
+
wrap: {
|
|
183
|
+
type: BooleanConstructor;
|
|
184
|
+
default: boolean;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Tab handling
|
|
188
|
+
*
|
|
189
|
+
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
|
|
190
|
+
*/
|
|
191
|
+
tab: {
|
|
192
|
+
type: BooleanConstructor;
|
|
193
|
+
default: boolean;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Readonly
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
199
|
+
*/
|
|
200
|
+
readonly: {
|
|
201
|
+
type: BooleanConstructor;
|
|
202
|
+
default: boolean;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Editable
|
|
206
|
+
*
|
|
207
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
|
|
208
|
+
*/
|
|
209
|
+
editable: {
|
|
210
|
+
type: BooleanConstructor;
|
|
211
|
+
default: boolean;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Additional Extension
|
|
215
|
+
*
|
|
216
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
217
|
+
*/
|
|
218
|
+
extensions: {
|
|
219
|
+
type: PropType<Extension[]>;
|
|
220
|
+
default: undefined;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Language Phreses
|
|
224
|
+
*
|
|
225
|
+
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
226
|
+
*/
|
|
227
|
+
phrases: {
|
|
228
|
+
type: PropType<Record<string, string>>;
|
|
229
|
+
default: undefined;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* CodeMirror Language
|
|
233
|
+
*
|
|
234
|
+
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
235
|
+
*/
|
|
236
|
+
lang: {
|
|
237
|
+
type: PropType<LanguageSupport>;
|
|
238
|
+
default: undefined;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* CodeMirror Linter
|
|
242
|
+
*
|
|
243
|
+
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
244
|
+
*/
|
|
245
|
+
linter: {
|
|
246
|
+
type: PropType<Diagnostic[]>;
|
|
247
|
+
default: undefined;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
/** Emits */
|
|
251
|
+
emits: ("update:modelValue" | "update")[];
|
|
252
|
+
/**
|
|
253
|
+
* Setup
|
|
254
|
+
* @param props - Props
|
|
255
|
+
* @param context - Context
|
|
256
|
+
*/
|
|
257
|
+
setup(props: any, context: SetupContext): {
|
|
258
|
+
context: SetupContext<import("vue-demi").EmitsOptions>;
|
|
259
|
+
editor: Ref<Element | undefined>;
|
|
260
|
+
};
|
|
261
|
+
}, import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
86
262
|
/** Model value */
|
|
87
263
|
modelValue: {
|
|
88
|
-
type:
|
|
264
|
+
type: PropType<string | Text>;
|
|
89
265
|
default: string;
|
|
90
266
|
};
|
|
267
|
+
/**
|
|
268
|
+
* Selection
|
|
269
|
+
*
|
|
270
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
271
|
+
*/
|
|
272
|
+
selection: {
|
|
273
|
+
type: PropType<EditorSelection | {
|
|
274
|
+
anchor: number;
|
|
275
|
+
head?: number | undefined;
|
|
276
|
+
}>;
|
|
277
|
+
default: undefined;
|
|
278
|
+
};
|
|
91
279
|
/**
|
|
92
280
|
* Theme
|
|
93
281
|
*
|
|
@@ -97,13 +285,40 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
97
285
|
type: PropType<{
|
|
98
286
|
[selector: string]: StyleSpec;
|
|
99
287
|
}>;
|
|
100
|
-
default: () =>
|
|
288
|
+
default: () => {};
|
|
101
289
|
};
|
|
102
290
|
/** Dark Mode */
|
|
103
291
|
dark: {
|
|
104
292
|
type: BooleanConstructor;
|
|
105
293
|
default: boolean;
|
|
106
294
|
};
|
|
295
|
+
/**
|
|
296
|
+
* Use Basic Setup
|
|
297
|
+
*
|
|
298
|
+
* @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
|
|
299
|
+
*/
|
|
300
|
+
basic: {
|
|
301
|
+
type: BooleanConstructor;
|
|
302
|
+
default: boolean;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Line wrapping
|
|
306
|
+
*
|
|
307
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
|
|
308
|
+
*/
|
|
309
|
+
wrap: {
|
|
310
|
+
type: BooleanConstructor;
|
|
311
|
+
default: boolean;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Tab handling
|
|
315
|
+
*
|
|
316
|
+
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
|
|
317
|
+
*/
|
|
318
|
+
tab: {
|
|
319
|
+
type: BooleanConstructor;
|
|
320
|
+
default: boolean;
|
|
321
|
+
};
|
|
107
322
|
/**
|
|
108
323
|
* Readonly
|
|
109
324
|
*
|
|
@@ -160,11 +375,18 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
160
375
|
};
|
|
161
376
|
}>>, {
|
|
162
377
|
readonly: boolean;
|
|
163
|
-
modelValue: string;
|
|
378
|
+
modelValue: string | Text;
|
|
379
|
+
selection: EditorSelection | {
|
|
380
|
+
anchor: number;
|
|
381
|
+
head?: number | undefined;
|
|
382
|
+
};
|
|
164
383
|
theme: {
|
|
165
384
|
[selector: string]: StyleSpec;
|
|
166
385
|
};
|
|
167
386
|
dark: boolean;
|
|
387
|
+
basic: boolean;
|
|
388
|
+
wrap: boolean;
|
|
389
|
+
tab: boolean;
|
|
168
390
|
editable: boolean;
|
|
169
391
|
extensions: Extension[];
|
|
170
392
|
phrases: Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAWL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AASjE,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtE,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;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IArHL,qBAAqB;;IAErB,uBAAuB;;;;;IAKvB,uBAAuB;;QAErB,kBAAkB;;;;;QAKlB;;;;WAIG;;;wBAG6B,MAAM;;;;;QAItC;;;;WAIG;;;;;;;QAOH,gBAAgB;;;;;QAKhB;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;QAKH;;;;WAIG;;;;;;IAML,YAAY;;IAEZ;;;;OAIG;+BACmB,YAAY;;;;;IAzHhC,kBAAkB;;;;;IAKlB;;;;OAIG;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;gBAhG6B,MAAM;;;;;;;;;;;;;;;;AAvB1C,2BAA2B;AAC3B,wBA6PG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
8
|
*/
|
|
9
9
|
import CodeMirror from './components/CodeMirror.vue';
|
|
10
|
-
import {
|
|
11
|
-
declare const installCodeMirror: (app:
|
|
12
|
-
export { CodeMirror, installCodeMirror as install };
|
|
13
|
-
export default CodeMirror;
|
|
10
|
+
import { Vue2 } from 'vue-demi';
|
|
11
|
+
declare const installCodeMirror: void | ((app: typeof Vue2) => void);
|
|
12
|
+
export { CodeMirror as default, installCodeMirror as install };
|
|
14
13
|
//# 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":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAmB,IAAI,EAAE,MAAM,UAAU,CAAC;AAEjD,QAAA,MAAM,iBAAiB,gBACb,WAAW,UAGR,CAAC;AAEd,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { defineComponent, ref, computed,
|
|
1
|
+
import { defineComponent, ref, toRefs, computed, toRaw, watch, onMounted, nextTick, onUnmounted, isVue2, install } from "vue-demi";
|
|
2
2
|
import { EditorState } from "@codemirror/state";
|
|
3
|
-
import { EditorView } from "@codemirror/view";
|
|
4
|
-
import {
|
|
3
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
4
|
+
import { basicSetup } from "@codemirror/basic-setup";
|
|
5
|
+
import { indentWithTab } from "@codemirror/commands";
|
|
6
|
+
import { merge, compact, trim } from "lodash";
|
|
5
7
|
import { openBlock, createElementBlock, withDirectives, createElementVNode, renderSlot, vShow } from "vue";
|
|
6
8
|
var _export_sfc = (sfc, props) => {
|
|
7
9
|
const target = sfc.__vccOpts || sfc;
|
|
@@ -21,15 +23,32 @@ const _sfc_main = defineComponent({
|
|
|
21
23
|
type: String,
|
|
22
24
|
default: ""
|
|
23
25
|
},
|
|
26
|
+
selection: {
|
|
27
|
+
type: Object,
|
|
28
|
+
default: void 0
|
|
29
|
+
},
|
|
24
30
|
theme: {
|
|
25
31
|
type: Object,
|
|
26
32
|
default: () => {
|
|
33
|
+
return {};
|
|
27
34
|
}
|
|
28
35
|
},
|
|
29
36
|
dark: {
|
|
30
37
|
type: Boolean,
|
|
31
38
|
default: false
|
|
32
39
|
},
|
|
40
|
+
basic: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
43
|
+
},
|
|
44
|
+
wrap: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false
|
|
47
|
+
},
|
|
48
|
+
tab: {
|
|
49
|
+
type: Boolean,
|
|
50
|
+
default: false
|
|
51
|
+
},
|
|
33
52
|
readonly: {
|
|
34
53
|
type: Boolean,
|
|
35
54
|
default: false
|
|
@@ -58,17 +77,20 @@ const _sfc_main = defineComponent({
|
|
|
58
77
|
emits: ["update:modelValue", "update"],
|
|
59
78
|
setup(props, context) {
|
|
60
79
|
const editor = ref();
|
|
61
|
-
const
|
|
62
|
-
const dark =
|
|
80
|
+
const doc = ref(props.modelValue);
|
|
81
|
+
const { dark } = toRefs(props);
|
|
63
82
|
const emit = context.emit;
|
|
64
|
-
const
|
|
83
|
+
const exts = computed(() => {
|
|
65
84
|
const ext = [
|
|
85
|
+
props.basic ? basicSetup : void 0,
|
|
66
86
|
EditorView.updateListener.of((update) => emit("update", update)),
|
|
67
87
|
EditorView.theme(props.theme, { dark: dark.value }),
|
|
88
|
+
props.wrap ? EditorView.lineWrapping : void 0,
|
|
89
|
+
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
68
90
|
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
69
|
-
props.lang,
|
|
70
91
|
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
71
|
-
props.editable ? EditorView.editable.of(props.editable) : void 0
|
|
92
|
+
props.editable ? EditorView.editable.of(props.editable) : void 0,
|
|
93
|
+
props.lang ? toRaw(props.lang) : void 0
|
|
72
94
|
];
|
|
73
95
|
if (props.linter) {
|
|
74
96
|
merge(ext, props.linter);
|
|
@@ -79,38 +101,40 @@ const _sfc_main = defineComponent({
|
|
|
79
101
|
return compact(ext);
|
|
80
102
|
});
|
|
81
103
|
let view;
|
|
82
|
-
watch(
|
|
104
|
+
watch(doc, (current) => {
|
|
83
105
|
if (view.composing) {
|
|
84
106
|
return;
|
|
85
107
|
}
|
|
86
108
|
const previous = view.state.selection;
|
|
87
109
|
view.setState(EditorState.create({
|
|
88
110
|
doc: current,
|
|
89
|
-
extensions:
|
|
111
|
+
extensions: exts.value,
|
|
90
112
|
selection: previous
|
|
91
113
|
}));
|
|
92
114
|
});
|
|
93
|
-
watch(
|
|
115
|
+
watch(dark, () => {
|
|
94
116
|
view.setState(EditorState.create({
|
|
95
|
-
doc:
|
|
96
|
-
extensions: value
|
|
117
|
+
doc: doc.value,
|
|
118
|
+
extensions: exts.value
|
|
97
119
|
}));
|
|
98
|
-
|
|
99
|
-
}, { deep: true });
|
|
120
|
+
});
|
|
100
121
|
onMounted(async () => {
|
|
101
|
-
|
|
122
|
+
if (doc.value == "" && editor.value) {
|
|
123
|
+
doc.value = trim(editor.value.childNodes[0].innerText);
|
|
124
|
+
}
|
|
102
125
|
view = new EditorView({
|
|
103
126
|
state: EditorState.create({
|
|
104
|
-
doc: value,
|
|
105
|
-
|
|
127
|
+
doc: doc.value,
|
|
128
|
+
selection: props.selection,
|
|
129
|
+
extensions: exts.value
|
|
106
130
|
}),
|
|
107
131
|
parent: editor.value,
|
|
108
132
|
dispatch: (tr) => {
|
|
109
133
|
view.update([tr]);
|
|
110
134
|
if (tr.changes.empty)
|
|
111
135
|
return;
|
|
112
|
-
|
|
113
|
-
emit("update:modelValue",
|
|
136
|
+
doc.value = view.state.doc.toString();
|
|
137
|
+
emit("update:modelValue", doc.value);
|
|
114
138
|
}
|
|
115
139
|
});
|
|
116
140
|
await nextTick();
|
|
@@ -144,8 +168,7 @@ var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]
|
|
|
144
168
|
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
145
169
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
146
170
|
*/
|
|
147
|
-
|
|
148
|
-
const installCodeMirror = (app) => {
|
|
171
|
+
const installCodeMirror = isVue2 ? (app) => {
|
|
149
172
|
app.component("CodeMirror", CodeMirror);
|
|
150
|
-
};
|
|
151
|
-
export { CodeMirror
|
|
173
|
+
} : install();
|
|
174
|
+
export { CodeMirror as default, installCodeMirror as install };
|
|
@@ -1,8 +1,8 @@
|
|
|
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,
|
|
1
|
+
(function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/basic-setup"),require("@codemirror/commands"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/basic-setup","@codemirror/commands","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.basicSetup,o.commands,o.lodash,o.Vue))})(this,function(o,t,s,n,h,S,f,l){"use strict";var V=(e,c)=>{const r=e.__vccOpts||e;for(const[a,u]of c)r[a]=u;return r};const b=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},selection:{type:Object,default:void 0},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},wrap:{type:Boolean,default:!1},tab:{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,c){const r=t.ref(),a=t.ref(e.modelValue),{dark:u}=t.toRefs(e),m=c.emit,y=t.computed(()=>{const i=[e.basic?h.basicSetup:void 0,n.EditorView.updateListener.of(p=>m("update",p)),n.EditorView.theme(e.theme,{dark:u.value}),e.wrap?n.EditorView.lineWrapping:void 0,e.tab?n.keymap.of([S.indentWithTab]):void 0,e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?n.EditorView.editable.of(e.editable):void 0,e.lang?t.toRaw(e.lang):void 0];return e.linter&&f.merge(i,e.linter),e.extensions&&f.merge(i,e.extensions),f.compact(i)});let d;return t.watch(a,i=>{if(d.composing)return;const p=d.state.selection;d.setState(s.EditorState.create({doc:i,extensions:y.value,selection:p}))}),t.watch(u,()=>{d.setState(s.EditorState.create({doc:a.value,extensions:y.value}))}),t.onMounted(async()=>{a.value==""&&r.value&&(a.value=f.trim(r.value.childNodes[0].innerText)),d=new n.EditorView({state:s.EditorState.create({doc:a.value,selection:e.selection,extensions:y.value}),parent:r.value,dispatch:i=>{d.update([i]),!i.changes.empty&&(a.value=d.state.doc.toString(),m("update:modelValue",a.value))}}),await t.nextTick()}),t.onUnmounted(()=>d.destroy()),{context:c,editor:r}}}),w={ref:"editor",class:"vue-codemirror"};function E(e,c,r,a,u,m){return l.openBlock(),l.createElementBlock("div",w,[l.withDirectives(l.createElementVNode("aside",null,[l.renderSlot(e.$slots,"default")],512),[[l.vShow,!e.context.slots.default]])],512)}var v=V(b,[["render",E]]);/**
|
|
2
2
|
* Vue CodeMirror6 Component
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author Logue {@link logue@hotmail.co.jp}
|
|
6
6
|
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
7
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
-
*/
|
|
8
|
+
*/const _=t.isVue2?e=>{e.component("CodeMirror",v)}:t.install();o.default=v,o.install=_,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
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": "0.3.
|
|
4
|
+
"version": "0.3.6",
|
|
5
5
|
"description": "CodeMirror6 Component for vue3",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"vue-codemirror",
|
|
11
11
|
"code-editor",
|
|
12
12
|
"text-editor",
|
|
13
|
-
"vue2",
|
|
14
13
|
"vue3",
|
|
15
14
|
"web-editor",
|
|
16
15
|
"vue-plugin",
|
|
@@ -73,6 +72,7 @@
|
|
|
73
72
|
"vue-demi": "latest"
|
|
74
73
|
},
|
|
75
74
|
"peerDependencies": {
|
|
75
|
+
"@codemirror/basic-setup": "latest",
|
|
76
76
|
"@codemirror/state": "latest",
|
|
77
77
|
"@codemirror/view": "latest",
|
|
78
78
|
"@vue/composition-api": "latest",
|
|
@@ -81,18 +81,21 @@
|
|
|
81
81
|
"peerDependenciesMeta": {
|
|
82
82
|
"@vue/composition-api": {
|
|
83
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"@codemirror/basic-setup": {
|
|
86
|
+
"optional": true
|
|
84
87
|
}
|
|
85
88
|
},
|
|
86
89
|
"devDependencies": {
|
|
87
90
|
"@codemirror/basic-setup": "^0.20.0",
|
|
88
91
|
"@codemirror/lang-markdown": "^0.20.0",
|
|
89
|
-
"@codemirror/language": "^0.20.
|
|
92
|
+
"@codemirror/language": "^0.20.1",
|
|
90
93
|
"@codemirror/lint": "^0.20.2",
|
|
91
94
|
"@modyqyw/vite-plugin-eslint": "^1.3.2",
|
|
92
95
|
"@types/lodash": "^4.14.182",
|
|
93
|
-
"@types/node": "^17.0.
|
|
94
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
95
|
-
"@typescript-eslint/parser": "^5.
|
|
96
|
+
"@types/node": "^17.0.34",
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
98
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
96
99
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
97
100
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
98
101
|
"eslint": "^8.15.0",
|
|
@@ -104,7 +107,7 @@
|
|
|
104
107
|
"eslint-plugin-prettier": "^4.0.0",
|
|
105
108
|
"eslint-plugin-prettier-vue": "^3.1.0",
|
|
106
109
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
107
|
-
"eslint-plugin-vue": "^
|
|
110
|
+
"eslint-plugin-vue": "^9.0.1",
|
|
108
111
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
109
112
|
"husky": "^8.0.1",
|
|
110
113
|
"lint-staged": "^12.4.1",
|
|
@@ -117,10 +120,11 @@
|
|
|
117
120
|
"rollup-plugin-visualizer": "^5.6.0",
|
|
118
121
|
"typescript": "^4.6.4",
|
|
119
122
|
"vite": "^2.9.9",
|
|
120
|
-
"
|
|
121
|
-
"vue
|
|
123
|
+
"vite-plugin-checker": "^0.4.6",
|
|
124
|
+
"vue": "^3.2.34",
|
|
125
|
+
"vue-eslint-parser": "^9.0.2",
|
|
122
126
|
"vue-template-compiler": "^2.6.14",
|
|
123
|
-
"vue-tsc": "^0.34.
|
|
127
|
+
"vue-tsc": "^0.34.15"
|
|
124
128
|
},
|
|
125
129
|
"husky": {
|
|
126
130
|
"hooks": {
|
|
@@ -7,24 +7,30 @@
|
|
|
7
7
|
<script lang="ts">
|
|
8
8
|
import {
|
|
9
9
|
computed,
|
|
10
|
-
ref,
|
|
11
|
-
watch,
|
|
12
|
-
onMounted,
|
|
13
|
-
onUnmounted,
|
|
14
10
|
defineComponent,
|
|
15
11
|
nextTick,
|
|
12
|
+
onMounted,
|
|
13
|
+
onUnmounted,
|
|
14
|
+
ref,
|
|
15
|
+
toRaw,
|
|
16
|
+
toRefs,
|
|
17
|
+
watch,
|
|
16
18
|
type ComputedRef,
|
|
17
|
-
type Ref,
|
|
18
19
|
type PropType,
|
|
20
|
+
type Ref,
|
|
19
21
|
type SetupContext,
|
|
20
22
|
} from 'vue-demi';
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
23
|
+
|
|
24
|
+
import { EditorSelection, EditorState } from '@codemirror/state';
|
|
25
|
+
import { EditorView, keymap } from '@codemirror/view';
|
|
26
|
+
import { basicSetup } from '@codemirror/basic-setup';
|
|
27
|
+
import { indentWithTab } from '@codemirror/commands';
|
|
28
|
+
|
|
29
|
+
import { compact, merge, trim } from 'lodash';
|
|
24
30
|
|
|
25
31
|
import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
|
|
26
32
|
|
|
27
|
-
import type { Extension, Transaction } from '@codemirror/state';
|
|
33
|
+
import type { Extension, Text, Transaction } from '@codemirror/state';
|
|
28
34
|
import type { LanguageSupport } from '@codemirror/language';
|
|
29
35
|
import type { ViewUpdate } from '@codemirror/view';
|
|
30
36
|
import type { Diagnostic } from '@codemirror/lint';
|
|
@@ -43,9 +49,20 @@ export default defineComponent({
|
|
|
43
49
|
props: {
|
|
44
50
|
/** Model value */
|
|
45
51
|
modelValue: {
|
|
46
|
-
type: String
|
|
52
|
+
type: String as PropType<string | Text>,
|
|
47
53
|
default: '',
|
|
48
54
|
},
|
|
55
|
+
/**
|
|
56
|
+
* Selection
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
59
|
+
*/
|
|
60
|
+
selection: {
|
|
61
|
+
type: Object as PropType<
|
|
62
|
+
EditorSelection | { anchor: number; head?: number }
|
|
63
|
+
>,
|
|
64
|
+
default: undefined,
|
|
65
|
+
},
|
|
49
66
|
/**
|
|
50
67
|
* Theme
|
|
51
68
|
*
|
|
@@ -53,13 +70,42 @@ export default defineComponent({
|
|
|
53
70
|
*/
|
|
54
71
|
theme: {
|
|
55
72
|
type: Object as PropType<{ [selector: string]: StyleSpec }>,
|
|
56
|
-
default: () => {
|
|
73
|
+
default: () => {
|
|
74
|
+
return {};
|
|
75
|
+
},
|
|
57
76
|
},
|
|
58
77
|
/** Dark Mode */
|
|
59
78
|
dark: {
|
|
60
79
|
type: Boolean,
|
|
61
80
|
default: false,
|
|
62
81
|
},
|
|
82
|
+
/**
|
|
83
|
+
* Use Basic Setup
|
|
84
|
+
*
|
|
85
|
+
* @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
|
|
86
|
+
*/
|
|
87
|
+
basic: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false,
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Line wrapping
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
|
|
95
|
+
*/
|
|
96
|
+
wrap: {
|
|
97
|
+
type: Boolean,
|
|
98
|
+
default: false,
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Tab handling
|
|
102
|
+
*
|
|
103
|
+
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
|
|
104
|
+
*/
|
|
105
|
+
tab: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: false,
|
|
108
|
+
},
|
|
63
109
|
/**
|
|
64
110
|
* Readonly
|
|
65
111
|
*
|
|
@@ -126,33 +172,39 @@ export default defineComponent({
|
|
|
126
172
|
/** Editor DOM */
|
|
127
173
|
const editor: Ref<Element | undefined> = ref();
|
|
128
174
|
|
|
129
|
-
/**
|
|
130
|
-
const
|
|
175
|
+
/** Internal value */
|
|
176
|
+
const doc: Ref<string | Text | undefined> = ref(props.modelValue);
|
|
131
177
|
|
|
132
178
|
/** Dark mode */
|
|
133
|
-
const dark
|
|
179
|
+
const { dark } = toRefs(props);
|
|
134
180
|
|
|
135
181
|
/** Emits */
|
|
136
182
|
const emit = context.emit as CodeMirrorEmitsInterface;
|
|
137
183
|
|
|
138
184
|
/** CodeMirror Extension */
|
|
139
|
-
const
|
|
185
|
+
const exts: ComputedRef<Extension[]> = computed(() => {
|
|
140
186
|
/** Default extension */
|
|
141
187
|
const ext = [
|
|
188
|
+
// Toggle basic setup
|
|
189
|
+
props.basic ? basicSetup : undefined,
|
|
142
190
|
// ViewUpdate event listener
|
|
143
191
|
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
144
192
|
emit('update', update)
|
|
145
193
|
),
|
|
146
194
|
// Toggle light/dark mode.
|
|
147
195
|
EditorView.theme(props.theme, { dark: dark.value }),
|
|
196
|
+
// Toggle line wrapping
|
|
197
|
+
props.wrap ? EditorView.lineWrapping : undefined,
|
|
198
|
+
// Indent with tab
|
|
199
|
+
props.tab ? keymap.of([indentWithTab]) : undefined,
|
|
148
200
|
// locale settings
|
|
149
201
|
props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
|
|
150
|
-
// Parser language setting
|
|
151
|
-
props.lang,
|
|
152
202
|
// Readonly option
|
|
153
203
|
props.readonly ? EditorState.readOnly.of(props.readonly) : undefined,
|
|
154
204
|
// Editable option
|
|
155
205
|
props.editable ? EditorView.editable.of(props.editable) : undefined,
|
|
206
|
+
// Lang
|
|
207
|
+
props.lang ? toRaw(props.lang) : undefined,
|
|
156
208
|
];
|
|
157
209
|
|
|
158
210
|
if (props.linter) {
|
|
@@ -165,19 +217,19 @@ export default defineComponent({
|
|
|
165
217
|
merge(ext, props.extensions);
|
|
166
218
|
}
|
|
167
219
|
|
|
168
|
-
// console.debug('[CodeMirror.vue] Loaded extensions:',
|
|
220
|
+
// console.debug('[CodeMirror.vue] Loaded extensions:', compact(ext));
|
|
169
221
|
return compact(ext);
|
|
170
222
|
});
|
|
171
223
|
|
|
172
224
|
/** CodeMirror Editor View */
|
|
173
|
-
let view
|
|
225
|
+
let view: EditorView;
|
|
174
226
|
|
|
175
227
|
/**
|
|
176
228
|
* Input value changed
|
|
177
229
|
*
|
|
178
230
|
* @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
|
|
179
231
|
*/
|
|
180
|
-
watch(
|
|
232
|
+
watch(doc, current => {
|
|
181
233
|
if (view.composing) {
|
|
182
234
|
// IME fix
|
|
183
235
|
return;
|
|
@@ -188,40 +240,34 @@ export default defineComponent({
|
|
|
188
240
|
view.setState(
|
|
189
241
|
EditorState.create({
|
|
190
242
|
doc: current,
|
|
191
|
-
extensions:
|
|
243
|
+
extensions: exts.value,
|
|
192
244
|
selection: previous,
|
|
193
245
|
})
|
|
194
246
|
);
|
|
195
247
|
});
|
|
196
248
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
})
|
|
206
|
-
);
|
|
207
|
-
await nextTick();
|
|
208
|
-
},
|
|
209
|
-
{ deep: true }
|
|
210
|
-
);
|
|
249
|
+
watch(dark, () => {
|
|
250
|
+
view.setState(
|
|
251
|
+
EditorState.create({
|
|
252
|
+
doc: doc.value,
|
|
253
|
+
extensions: exts.value,
|
|
254
|
+
})
|
|
255
|
+
);
|
|
256
|
+
});
|
|
211
257
|
|
|
212
258
|
/** When loaded */
|
|
213
259
|
onMounted(async () => {
|
|
214
260
|
/** Initial Value */
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
: modelValue.value;
|
|
261
|
+
if (doc.value == '' && editor.value) {
|
|
262
|
+
doc.value = trim((editor.value.childNodes[0] as HTMLElement).innerText);
|
|
263
|
+
}
|
|
219
264
|
|
|
220
265
|
// Register Codemirror
|
|
221
266
|
view = new EditorView({
|
|
222
267
|
state: EditorState.create({
|
|
223
|
-
doc: value,
|
|
224
|
-
|
|
268
|
+
doc: doc.value,
|
|
269
|
+
selection: props.selection,
|
|
270
|
+
extensions: exts.value,
|
|
225
271
|
}),
|
|
226
272
|
parent: editor.value,
|
|
227
273
|
dispatch: (tr: Transaction) => {
|
|
@@ -229,8 +275,8 @@ export default defineComponent({
|
|
|
229
275
|
|
|
230
276
|
if (tr.changes.empty) return;
|
|
231
277
|
// to parent binding
|
|
232
|
-
|
|
233
|
-
emit('update:modelValue',
|
|
278
|
+
doc.value = view.state.doc.toString();
|
|
279
|
+
emit('update:modelValue', doc.value);
|
|
234
280
|
},
|
|
235
281
|
});
|
|
236
282
|
await nextTick();
|