vue-codemirror6 0.3.2 → 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 +254 -219
- package/dist/components/CodeMirror.vue.d.ts +231 -9
- 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 +51 -27
- package/dist/vue-codemirror6.umd.js +2 -2
- package/package.json +40 -30
- package/src/components/CodeMirror.vue +92 -37
|
@@ -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
|
*
|
|
@@ -159,12 +374,19 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
159
374
|
default: undefined;
|
|
160
375
|
};
|
|
161
376
|
}>>, {
|
|
162
|
-
|
|
377
|
+
readonly: boolean;
|
|
378
|
+
modelValue: string | Text;
|
|
379
|
+
selection: EditorSelection | {
|
|
380
|
+
anchor: number;
|
|
381
|
+
head?: number | undefined;
|
|
382
|
+
};
|
|
163
383
|
theme: {
|
|
164
384
|
[selector: string]: StyleSpec;
|
|
165
385
|
};
|
|
166
386
|
dark: boolean;
|
|
167
|
-
|
|
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":"
|
|
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, watch, onMounted, onUnmounted, install } from "vue-demi";
|
|
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,14 +23,32 @@ const _sfc_main = defineComponent({
|
|
|
21
23
|
type: String,
|
|
22
24
|
default: ""
|
|
23
25
|
},
|
|
24
|
-
|
|
26
|
+
selection: {
|
|
25
27
|
type: Object,
|
|
26
28
|
default: void 0
|
|
27
29
|
},
|
|
30
|
+
theme: {
|
|
31
|
+
type: Object,
|
|
32
|
+
default: () => {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
},
|
|
28
36
|
dark: {
|
|
29
37
|
type: Boolean,
|
|
30
38
|
default: false
|
|
31
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
|
+
},
|
|
32
52
|
readonly: {
|
|
33
53
|
type: Boolean,
|
|
34
54
|
default: false
|
|
@@ -57,19 +77,20 @@ const _sfc_main = defineComponent({
|
|
|
57
77
|
emits: ["update:modelValue", "update"],
|
|
58
78
|
setup(props, context) {
|
|
59
79
|
const editor = ref();
|
|
60
|
-
const
|
|
61
|
-
const dark =
|
|
80
|
+
const doc = ref(props.modelValue);
|
|
81
|
+
const { dark } = toRefs(props);
|
|
62
82
|
const emit = context.emit;
|
|
63
|
-
const
|
|
83
|
+
const exts = computed(() => {
|
|
64
84
|
const ext = [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}),
|
|
68
|
-
|
|
85
|
+
props.basic ? basicSetup : void 0,
|
|
86
|
+
EditorView.updateListener.of((update) => emit("update", update)),
|
|
87
|
+
EditorView.theme(props.theme, { dark: dark.value }),
|
|
88
|
+
props.wrap ? EditorView.lineWrapping : void 0,
|
|
89
|
+
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
69
90
|
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
70
|
-
props.lang,
|
|
71
91
|
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
72
|
-
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
|
|
73
94
|
];
|
|
74
95
|
if (props.linter) {
|
|
75
96
|
merge(ext, props.linter);
|
|
@@ -80,39 +101,43 @@ const _sfc_main = defineComponent({
|
|
|
80
101
|
return compact(ext);
|
|
81
102
|
});
|
|
82
103
|
let view;
|
|
83
|
-
watch(
|
|
104
|
+
watch(doc, (current) => {
|
|
84
105
|
if (view.composing) {
|
|
85
106
|
return;
|
|
86
107
|
}
|
|
87
108
|
const previous = view.state.selection;
|
|
88
109
|
view.setState(EditorState.create({
|
|
89
110
|
doc: current,
|
|
90
|
-
extensions:
|
|
111
|
+
extensions: exts.value,
|
|
91
112
|
selection: previous
|
|
92
113
|
}));
|
|
93
114
|
});
|
|
94
115
|
watch(dark, () => {
|
|
95
116
|
view.setState(EditorState.create({
|
|
96
|
-
doc:
|
|
97
|
-
extensions:
|
|
117
|
+
doc: doc.value,
|
|
118
|
+
extensions: exts.value
|
|
98
119
|
}));
|
|
99
120
|
});
|
|
100
|
-
onMounted(() => {
|
|
101
|
-
|
|
121
|
+
onMounted(async () => {
|
|
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
|
});
|
|
140
|
+
await nextTick();
|
|
116
141
|
});
|
|
117
142
|
onUnmounted(() => view.destroy());
|
|
118
143
|
return {
|
|
@@ -143,8 +168,7 @@ var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]
|
|
|
143
168
|
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
144
169
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
145
170
|
*/
|
|
146
|
-
|
|
147
|
-
const installCodeMirror = (app) => {
|
|
171
|
+
const installCodeMirror = isVue2 ? (app) => {
|
|
148
172
|
app.component("CodeMirror", CodeMirror);
|
|
149
|
-
};
|
|
150
|
-
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,f,
|
|
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",
|
|
@@ -33,7 +32,8 @@
|
|
|
33
32
|
"url": "https://github.com/logue/vue-codemirror6/issues"
|
|
34
33
|
},
|
|
35
34
|
"engines": {
|
|
36
|
-
"node": ">=16"
|
|
35
|
+
"node": ">=16.15.0",
|
|
36
|
+
"yarn": "^1.22.18"
|
|
37
37
|
},
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"main": "./dist/vue-codemirror6.umd.js",
|
|
@@ -56,11 +56,15 @@
|
|
|
56
56
|
"scripts": {
|
|
57
57
|
"dev": "vite",
|
|
58
58
|
"clean": "rimraf node_modules/.vite",
|
|
59
|
-
"build": "vite build & vue-tsc",
|
|
59
|
+
"build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
|
|
60
|
+
"build:analyze": "vue-tsc --noEmit && vite build --mode analyze",
|
|
61
|
+
"build:docs": "vite build --config vite.config.docs.ts",
|
|
60
62
|
"build:clean": "rimraf dist",
|
|
61
|
-
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier .
|
|
63
|
+
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
|
|
64
|
+
"lint:markup": "vue-tsc --noEmit",
|
|
62
65
|
"switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
|
|
63
66
|
"switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
|
|
67
|
+
"preview": "vite preview --config vite.config.docs.ts",
|
|
64
68
|
"prepare": "husky install",
|
|
65
69
|
"postinstall": "npx vue-demi-fix"
|
|
66
70
|
},
|
|
@@ -68,29 +72,33 @@
|
|
|
68
72
|
"vue-demi": "latest"
|
|
69
73
|
},
|
|
70
74
|
"peerDependencies": {
|
|
71
|
-
"@codemirror/
|
|
72
|
-
"@codemirror/
|
|
73
|
-
"@
|
|
74
|
-
"vue": "
|
|
75
|
+
"@codemirror/basic-setup": "latest",
|
|
76
|
+
"@codemirror/state": "latest",
|
|
77
|
+
"@codemirror/view": "latest",
|
|
78
|
+
"@vue/composition-api": "latest",
|
|
79
|
+
"vue": "^2.6.14 || ^3.2.33"
|
|
75
80
|
},
|
|
76
81
|
"peerDependenciesMeta": {
|
|
77
82
|
"@vue/composition-api": {
|
|
78
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"@codemirror/basic-setup": {
|
|
86
|
+
"optional": true
|
|
79
87
|
}
|
|
80
88
|
},
|
|
81
89
|
"devDependencies": {
|
|
82
|
-
"@codemirror/basic-setup": "^0.
|
|
83
|
-
"@codemirror/lang-markdown": "^0.
|
|
84
|
-
"@codemirror/language": "^0.
|
|
85
|
-
"@codemirror/lint": "^0.
|
|
86
|
-
"@modyqyw/vite-plugin-eslint": "^1.2
|
|
87
|
-
"@types/lodash": "^4.14.
|
|
88
|
-
"@types/node": "^17.0.
|
|
89
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
90
|
-
"@typescript-eslint/parser": "^5.
|
|
91
|
-
"@vitejs/plugin-vue": "^2.3.
|
|
90
|
+
"@codemirror/basic-setup": "^0.20.0",
|
|
91
|
+
"@codemirror/lang-markdown": "^0.20.0",
|
|
92
|
+
"@codemirror/language": "^0.20.1",
|
|
93
|
+
"@codemirror/lint": "^0.20.2",
|
|
94
|
+
"@modyqyw/vite-plugin-eslint": "^1.3.2",
|
|
95
|
+
"@types/lodash": "^4.14.182",
|
|
96
|
+
"@types/node": "^17.0.34",
|
|
97
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
98
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
99
|
+
"@vitejs/plugin-vue": "^2.3.3",
|
|
92
100
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
93
|
-
"eslint": "^8.
|
|
101
|
+
"eslint": "^8.15.0",
|
|
94
102
|
"eslint-config-google": "^0.14.0",
|
|
95
103
|
"eslint-config-prettier": "^8.5.0",
|
|
96
104
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
@@ -98,23 +106,25 @@
|
|
|
98
106
|
"eslint-plugin-import": "^2.26.0",
|
|
99
107
|
"eslint-plugin-prettier": "^4.0.0",
|
|
100
108
|
"eslint-plugin-prettier-vue": "^3.1.0",
|
|
101
|
-
"eslint-plugin-tsdoc": "^0.2.
|
|
102
|
-
"eslint-plugin-vue": "^
|
|
109
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
110
|
+
"eslint-plugin-vue": "^9.0.1",
|
|
103
111
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
104
|
-
"husky": "^
|
|
105
|
-
"lint-staged": "^12.
|
|
112
|
+
"husky": "^8.0.1",
|
|
113
|
+
"lint-staged": "^12.4.1",
|
|
106
114
|
"lodash": "^4.17.21",
|
|
107
115
|
"prettier": "^2.6.2",
|
|
108
|
-
"prettier-plugin-jsdoc": "^0.3.
|
|
116
|
+
"prettier-plugin-jsdoc": "^0.3.38",
|
|
109
117
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
110
118
|
"prettier-plugin-sort-imports": "^1.6.0",
|
|
111
119
|
"rimraf": "^3.0.2",
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
120
|
+
"rollup-plugin-visualizer": "^5.6.0",
|
|
121
|
+
"typescript": "^4.6.4",
|
|
122
|
+
"vite": "^2.9.9",
|
|
123
|
+
"vite-plugin-checker": "^0.4.6",
|
|
124
|
+
"vue": "^3.2.34",
|
|
125
|
+
"vue-eslint-parser": "^9.0.2",
|
|
116
126
|
"vue-template-compiler": "^2.6.14",
|
|
117
|
-
"vue-tsc": "^0.
|
|
127
|
+
"vue-tsc": "^0.34.15"
|
|
118
128
|
},
|
|
119
129
|
"husky": {
|
|
120
130
|
"hooks": {
|