vue-codemirror6 1.1.4 → 1.1.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/dist/Meta.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type MetaInterface from '@/interfaces/MetaInterface';
2
+ declare const meta: MetaInterface;
3
+ export default meta;
package/dist/Meta.js ADDED
@@ -0,0 +1,6 @@
1
+ // This file is auto-generated by the build system.
2
+ const meta = {
3
+ version: '1.1.6',
4
+ date: '2023-01-16T11:26:58.296Z',
5
+ };
6
+ export default meta;
@@ -0,0 +1,417 @@
1
+ import { type ObjectEmitsOptions, type PropType, type Ref } from 'vue-demi';
2
+ import { EditorState, type Extension, type Text } from '@codemirror/state';
3
+ import { EditorView, type ViewUpdate } from '@codemirror/view';
4
+ import { type LintSource } from '@codemirror/lint';
5
+ import type { LanguageSupport } from '@codemirror/language';
6
+ import type { StyleSpec } from 'style-mod';
7
+ /** Emit Interface */
8
+ export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
9
+ /** Model Update */
10
+ (e: 'update:modelValue', value: string | Text): void;
11
+ /** CodeMirror ViewUpdate */
12
+ (e: 'update', value: ViewUpdate): void;
13
+ /** CodeMirror onFocus */
14
+ (e: 'focus', value: boolean): void;
15
+ /** CodeMirror onReady */
16
+ (e: 'ready', value: {
17
+ view: EditorView;
18
+ state: EditorState;
19
+ container: HTMLElement;
20
+ }): void;
21
+ /** CodeMirror onDestroy */
22
+ (e: 'destroy'): void;
23
+ /** State Changed */
24
+ (e: 'change', value: EditorState): void;
25
+ }
26
+ /** CodeMirror Component */
27
+ declare const _default: import("vue-demi").DefineComponent<{
28
+ /** Model value */
29
+ modelValue: {
30
+ type: PropType<string | Text>;
31
+ default: string;
32
+ };
33
+ /**
34
+ * Theme
35
+ *
36
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
37
+ */
38
+ theme: {
39
+ type: PropType<{
40
+ [selector: string]: StyleSpec;
41
+ }>;
42
+ default: () => void;
43
+ };
44
+ /** Dark Mode */
45
+ dark: {
46
+ type: BooleanConstructor;
47
+ default: boolean;
48
+ };
49
+ /**
50
+ * Use Basic Setup
51
+ *
52
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
53
+ */
54
+ basic: {
55
+ type: BooleanConstructor;
56
+ default: boolean;
57
+ };
58
+ /**
59
+ * Use Minimal Setup (The basic setting has priority.)
60
+ *
61
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
62
+ */
63
+ minimal: {
64
+ type: BooleanConstructor;
65
+ default: boolean;
66
+ };
67
+ /**
68
+ * Placeholder
69
+ *
70
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
71
+ */
72
+ placeholder: {
73
+ type: PropType<string | HTMLElement>;
74
+ default: undefined;
75
+ };
76
+ /**
77
+ * Line wrapping
78
+ *
79
+ * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
80
+ *
81
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
82
+ */
83
+ wrap: {
84
+ type: BooleanConstructor;
85
+ default: boolean;
86
+ };
87
+ /**
88
+ * Allow tab key indent.
89
+ *
90
+ * @see {@link https://codemirror.net/examples/tab/}
91
+ */
92
+ tab: {
93
+ type: BooleanConstructor;
94
+ default: boolean;
95
+ };
96
+ /**
97
+ * Tab size
98
+ *
99
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
100
+ */
101
+ tabSize: {
102
+ type: NumberConstructor;
103
+ default: undefined;
104
+ };
105
+ /**
106
+ * Set line break (separetor) char.
107
+ *
108
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
109
+ */
110
+ lineSeparator: {
111
+ type: StringConstructor;
112
+ default: undefined;
113
+ };
114
+ /**
115
+ * Readonly
116
+ *
117
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
118
+ */
119
+ readonly: {
120
+ type: BooleanConstructor;
121
+ default: boolean;
122
+ };
123
+ /**
124
+ * Disable input.
125
+ *
126
+ * This is the reversed value of the CodeMirror editable.
127
+ * Similar to `readonly`, but setting this value to true disables dragging.
128
+ *
129
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
130
+ */
131
+ disabled: {
132
+ type: BooleanConstructor;
133
+ default: boolean;
134
+ };
135
+ /**
136
+ * Additional Extension
137
+ *
138
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
139
+ */
140
+ extensions: {
141
+ type: PropType<Extension[]>;
142
+ default: () => never[];
143
+ };
144
+ /**
145
+ * Language Phreses
146
+ *
147
+ * @see {@link https://codemirror.net/examples/translate/}
148
+ */
149
+ phrases: {
150
+ type: PropType<Record<string, string>>;
151
+ default: () => undefined;
152
+ };
153
+ /**
154
+ * CodeMirror Language
155
+ *
156
+ * @see {@link https://codemirror.net/docs/ref/#language}
157
+ */
158
+ lang: {
159
+ type: PropType<LanguageSupport>;
160
+ default: () => undefined;
161
+ };
162
+ /**
163
+ * CodeMirror Linter
164
+ *
165
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
166
+ */
167
+ linter: {
168
+ type: PropType<LintSource>;
169
+ default: undefined;
170
+ };
171
+ /**
172
+ * Linter Config
173
+ *
174
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
175
+ */
176
+ linterConfig: {
177
+ type: ObjectConstructor;
178
+ default: () => void;
179
+ };
180
+ /**
181
+ * Show Linter Gutter
182
+ *
183
+ * An area to 🔴 the lines with errors will be displayed.
184
+ * This feature is not enabled if `linter` is not specified.
185
+ *
186
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
187
+ */
188
+ gutter: {
189
+ type: BooleanConstructor;
190
+ defalt: boolean;
191
+ };
192
+ /**
193
+ * Gutter Config
194
+ *
195
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
196
+ */
197
+ gutterConfig: {
198
+ type: ObjectConstructor;
199
+ default: () => void;
200
+ };
201
+ /**
202
+ * Using tag
203
+ */
204
+ tag: {
205
+ type: StringConstructor;
206
+ default: string;
207
+ };
208
+ }, {
209
+ editor: Ref<HTMLElement | undefined>;
210
+ }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, CodeMirrorEmitsOptions, "update:modelValue" | "update" | "focus" | "ready" | "destroy" | "change", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
211
+ /** Model value */
212
+ modelValue: {
213
+ type: PropType<string | Text>;
214
+ default: string;
215
+ };
216
+ /**
217
+ * Theme
218
+ *
219
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
220
+ */
221
+ theme: {
222
+ type: PropType<{
223
+ [selector: string]: StyleSpec;
224
+ }>;
225
+ default: () => void;
226
+ };
227
+ /** Dark Mode */
228
+ dark: {
229
+ type: BooleanConstructor;
230
+ default: boolean;
231
+ };
232
+ /**
233
+ * Use Basic Setup
234
+ *
235
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
236
+ */
237
+ basic: {
238
+ type: BooleanConstructor;
239
+ default: boolean;
240
+ };
241
+ /**
242
+ * Use Minimal Setup (The basic setting has priority.)
243
+ *
244
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
245
+ */
246
+ minimal: {
247
+ type: BooleanConstructor;
248
+ default: boolean;
249
+ };
250
+ /**
251
+ * Placeholder
252
+ *
253
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
254
+ */
255
+ placeholder: {
256
+ type: PropType<string | HTMLElement>;
257
+ default: undefined;
258
+ };
259
+ /**
260
+ * Line wrapping
261
+ *
262
+ * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
263
+ *
264
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
265
+ */
266
+ wrap: {
267
+ type: BooleanConstructor;
268
+ default: boolean;
269
+ };
270
+ /**
271
+ * Allow tab key indent.
272
+ *
273
+ * @see {@link https://codemirror.net/examples/tab/}
274
+ */
275
+ tab: {
276
+ type: BooleanConstructor;
277
+ default: boolean;
278
+ };
279
+ /**
280
+ * Tab size
281
+ *
282
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
283
+ */
284
+ tabSize: {
285
+ type: NumberConstructor;
286
+ default: undefined;
287
+ };
288
+ /**
289
+ * Set line break (separetor) char.
290
+ *
291
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
292
+ */
293
+ lineSeparator: {
294
+ type: StringConstructor;
295
+ default: undefined;
296
+ };
297
+ /**
298
+ * Readonly
299
+ *
300
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
301
+ */
302
+ readonly: {
303
+ type: BooleanConstructor;
304
+ default: boolean;
305
+ };
306
+ /**
307
+ * Disable input.
308
+ *
309
+ * This is the reversed value of the CodeMirror editable.
310
+ * Similar to `readonly`, but setting this value to true disables dragging.
311
+ *
312
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
313
+ */
314
+ disabled: {
315
+ type: BooleanConstructor;
316
+ default: boolean;
317
+ };
318
+ /**
319
+ * Additional Extension
320
+ *
321
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
322
+ */
323
+ extensions: {
324
+ type: PropType<Extension[]>;
325
+ default: () => never[];
326
+ };
327
+ /**
328
+ * Language Phreses
329
+ *
330
+ * @see {@link https://codemirror.net/examples/translate/}
331
+ */
332
+ phrases: {
333
+ type: PropType<Record<string, string>>;
334
+ default: () => undefined;
335
+ };
336
+ /**
337
+ * CodeMirror Language
338
+ *
339
+ * @see {@link https://codemirror.net/docs/ref/#language}
340
+ */
341
+ lang: {
342
+ type: PropType<LanguageSupport>;
343
+ default: () => undefined;
344
+ };
345
+ /**
346
+ * CodeMirror Linter
347
+ *
348
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
349
+ */
350
+ linter: {
351
+ type: PropType<LintSource>;
352
+ default: undefined;
353
+ };
354
+ /**
355
+ * Linter Config
356
+ *
357
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
358
+ */
359
+ linterConfig: {
360
+ type: ObjectConstructor;
361
+ default: () => void;
362
+ };
363
+ /**
364
+ * Show Linter Gutter
365
+ *
366
+ * An area to 🔴 the lines with errors will be displayed.
367
+ * This feature is not enabled if `linter` is not specified.
368
+ *
369
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
370
+ */
371
+ gutter: {
372
+ type: BooleanConstructor;
373
+ defalt: boolean;
374
+ };
375
+ /**
376
+ * Gutter Config
377
+ *
378
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
379
+ */
380
+ gutterConfig: {
381
+ type: ObjectConstructor;
382
+ default: () => void;
383
+ };
384
+ /**
385
+ * Using tag
386
+ */
387
+ tag: {
388
+ type: StringConstructor;
389
+ default: string;
390
+ };
391
+ }>> & {
392
+ [x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
393
+ }, {
394
+ modelValue: string | Text;
395
+ theme: {
396
+ [selector: string]: StyleSpec;
397
+ };
398
+ dark: boolean;
399
+ basic: boolean;
400
+ minimal: boolean;
401
+ placeholder: string | HTMLElement;
402
+ wrap: boolean;
403
+ tab: boolean;
404
+ tabSize: number;
405
+ lineSeparator: string;
406
+ readonly: boolean;
407
+ disabled: boolean;
408
+ extensions: Extension[];
409
+ phrases: Record<string, string>;
410
+ lang: LanguageSupport;
411
+ linter: LintSource;
412
+ linterConfig: Record<string, any>;
413
+ gutter: boolean;
414
+ gutterConfig: Record<string, any>;
415
+ tag: string;
416
+ }>;
417
+ export default _default;
@@ -0,0 +1,493 @@
1
+ import { computed, defineComponent, nextTick, onMounted, onUnmounted, ref, shallowRef, watch, } from 'vue-demi';
2
+ // Helpers
3
+ import h, { slot } from '@/helpers/h-demi';
4
+ import { compact, trim } from 'lodash';
5
+ // CodeMirror
6
+ import { basicSetup, minimalSetup } from 'codemirror';
7
+ import { EditorSelection, EditorState, StateEffect, } from '@codemirror/state';
8
+ import { EditorView, keymap, placeholder, } from '@codemirror/view';
9
+ import { indentWithTab } from '@codemirror/commands';
10
+ import { forceLinting, linter, lintGutter, } from '@codemirror/lint';
11
+ /** CodeMirror Component */
12
+ export default defineComponent({
13
+ /** Component Name */
14
+ name: 'CodeMirror',
15
+ /** Model Definition */
16
+ model: {
17
+ prop: 'modelValue',
18
+ event: 'update:modelValue',
19
+ },
20
+ /** Props Definition */
21
+ props: {
22
+ /** Model value */
23
+ modelValue: {
24
+ type: String,
25
+ default: '',
26
+ },
27
+ /**
28
+ * Theme
29
+ *
30
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
31
+ */
32
+ theme: {
33
+ type: Object,
34
+ default: () => { },
35
+ },
36
+ /** Dark Mode */
37
+ dark: {
38
+ type: Boolean,
39
+ default: false,
40
+ },
41
+ /**
42
+ * Use Basic Setup
43
+ *
44
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
45
+ */
46
+ basic: {
47
+ type: Boolean,
48
+ default: false,
49
+ },
50
+ /**
51
+ * Use Minimal Setup (The basic setting has priority.)
52
+ *
53
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
54
+ */
55
+ minimal: {
56
+ type: Boolean,
57
+ default: false,
58
+ },
59
+ /**
60
+ * Placeholder
61
+ *
62
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
63
+ */
64
+ placeholder: {
65
+ type: String,
66
+ default: undefined,
67
+ },
68
+ /**
69
+ * Line wrapping
70
+ *
71
+ * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
72
+ *
73
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
74
+ */
75
+ wrap: {
76
+ type: Boolean,
77
+ default: false,
78
+ },
79
+ /**
80
+ * Allow tab key indent.
81
+ *
82
+ * @see {@link https://codemirror.net/examples/tab/}
83
+ */
84
+ tab: {
85
+ type: Boolean,
86
+ default: false,
87
+ },
88
+ /**
89
+ * Tab size
90
+ *
91
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
92
+ */
93
+ tabSize: {
94
+ type: Number,
95
+ default: undefined,
96
+ },
97
+ /**
98
+ * Set line break (separetor) char.
99
+ *
100
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
101
+ */
102
+ lineSeparator: {
103
+ type: String,
104
+ default: undefined,
105
+ },
106
+ /**
107
+ * Readonly
108
+ *
109
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
110
+ */
111
+ readonly: {
112
+ type: Boolean,
113
+ default: false,
114
+ },
115
+ /**
116
+ * Disable input.
117
+ *
118
+ * This is the reversed value of the CodeMirror editable.
119
+ * Similar to `readonly`, but setting this value to true disables dragging.
120
+ *
121
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
122
+ */
123
+ disabled: {
124
+ type: Boolean,
125
+ default: false,
126
+ },
127
+ /**
128
+ * Additional Extension
129
+ *
130
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
131
+ */
132
+ extensions: {
133
+ type: Array,
134
+ default: () => {
135
+ return [];
136
+ },
137
+ },
138
+ /**
139
+ * Language Phreses
140
+ *
141
+ * @see {@link https://codemirror.net/examples/translate/}
142
+ */
143
+ phrases: {
144
+ type: Object,
145
+ default: () => undefined,
146
+ },
147
+ /**
148
+ * CodeMirror Language
149
+ *
150
+ * @see {@link https://codemirror.net/docs/ref/#language}
151
+ */
152
+ lang: {
153
+ type: Object,
154
+ default: () => undefined,
155
+ },
156
+ /**
157
+ * CodeMirror Linter
158
+ *
159
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
160
+ */
161
+ linter: {
162
+ type: Function,
163
+ default: undefined,
164
+ },
165
+ /**
166
+ * Linter Config
167
+ *
168
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
169
+ */
170
+ linterConfig: {
171
+ type: Object,
172
+ default: () => { },
173
+ },
174
+ /**
175
+ * Show Linter Gutter
176
+ *
177
+ * An area to 🔴 the lines with errors will be displayed.
178
+ * This feature is not enabled if `linter` is not specified.
179
+ *
180
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
181
+ */
182
+ gutter: {
183
+ type: Boolean,
184
+ defalt: false,
185
+ },
186
+ /**
187
+ * Gutter Config
188
+ *
189
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
190
+ */
191
+ gutterConfig: {
192
+ type: Object,
193
+ default: () => { },
194
+ },
195
+ /**
196
+ * Using tag
197
+ */
198
+ tag: {
199
+ type: String,
200
+ default: 'div',
201
+ },
202
+ },
203
+ /** Emits */
204
+ emits: ['update:modelValue', 'update', 'ready', 'focus', 'change', 'destroy'],
205
+ /**
206
+ * Setup
207
+ *
208
+ * @param props - Props
209
+ * @param context - Context
210
+ */
211
+ setup(props, context) {
212
+ /** Editor DOM */
213
+ const editor = ref();
214
+ /** Internal value */
215
+ const doc = ref(props.modelValue);
216
+ /**
217
+ * CodeMirror Editor View
218
+ *
219
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView}
220
+ */
221
+ const view = shallowRef(new EditorView());
222
+ /**
223
+ * Editor Selection
224
+ *
225
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorSelection}
226
+ */
227
+ const selection = computed({
228
+ get: () => view.value.state.selection,
229
+ set: s => view.value.dispatch({ selection: s }),
230
+ });
231
+ /**
232
+ * Editor State
233
+ *
234
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState}
235
+ */
236
+ const state = computed({
237
+ get: () => view.value.state,
238
+ set: s => view.value.setState(s),
239
+ });
240
+ /** Cursor Position */
241
+ const cursor = computed({
242
+ get: () => view.value.state.selection.main.head || 0,
243
+ set: a => view.value.dispatch({ selection: { anchor: a } }),
244
+ });
245
+ /**
246
+ * Focus
247
+ *
248
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView.hasFocus}
249
+ */
250
+ const focus = computed({
251
+ get: () => view.value.hasFocus,
252
+ set: f => {
253
+ if (f) {
254
+ view.value.focus();
255
+ }
256
+ },
257
+ });
258
+ /** Text length */
259
+ const length = computed(() => view.value.state.doc.length);
260
+ /** Get CodeMirror Extension */
261
+ const extensions = computed(() =>
262
+ // TODO: Ignore previous prop was not changed.
263
+ compact([
264
+ // Toggle basic setup
265
+ props.basic ? basicSetup : undefined,
266
+ // Toggle minimal setup
267
+ props.minimal && !props.basic ? minimalSetup : undefined,
268
+ // ViewUpdate event listener
269
+ EditorView.updateListener.of((update) => context.emit('update', update)),
270
+ // Toggle light/dark mode.
271
+ EditorView.theme(props.theme, { dark: props.dark }),
272
+ // Toggle line wrapping
273
+ props.wrap ? EditorView.lineWrapping : undefined,
274
+ // Indent with tab
275
+ props.tab ? keymap.of([indentWithTab]) : undefined,
276
+ // Indent tab size
277
+ props.tabSize ? EditorState.tabSize.of(props.tabSize) : undefined,
278
+ // locale settings
279
+ props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
280
+ // Readonly option
281
+ EditorState.readOnly.of(props.readonly),
282
+ // Editable option
283
+ EditorView.editable.of(!props.disabled),
284
+ // Set Line break char
285
+ props.lineSeparator
286
+ ? EditorState.lineSeparator.of(props.lineSeparator)
287
+ : undefined,
288
+ // Lang
289
+ props.lang ? props.lang : undefined,
290
+ // Append Linter settings
291
+ props.linter ? linter(props.linter, props.linterConfig) : undefined,
292
+ // Show 🔴 to error line when linter enabled.
293
+ props.linter && props.gutter
294
+ ? lintGutter(props.gutterConfig)
295
+ : undefined,
296
+ // Placeholder
297
+ props.placeholder ? placeholder(props.placeholder) : undefined,
298
+ // Append Extensions (such as basic-setup)
299
+ ...props.extensions,
300
+ ]));
301
+ // for parent-to-child binding.
302
+ watch(() => props.modelValue, value => {
303
+ if (view.value.composing) {
304
+ // IME fix
305
+ return;
306
+ }
307
+ // Update
308
+ view.value.dispatch({
309
+ changes: { from: 0, to: view.value.state.doc.length, insert: value },
310
+ selection: view.value.state.selection,
311
+ scrollIntoView: true,
312
+ });
313
+ }, { immediate: true });
314
+ // Extension (mostly props) Changed
315
+ watch(extensions, exts =>
316
+ // TODO: Reduce unchanched value
317
+ view.value.dispatch({
318
+ effects: StateEffect.reconfigure.of(exts),
319
+ }));
320
+ // focus changed
321
+ watch(focus, isFocus => context.emit('focus', isFocus));
322
+ /** When loaded */
323
+ onMounted(async () => {
324
+ /** Initial value */
325
+ let value = doc.value;
326
+ if (editor.value && editor.value.childNodes[0]) {
327
+ // when slot mode, overwrite initial value
328
+ if (doc.value !== '') {
329
+ console.warn('[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.');
330
+ }
331
+ value = trim(editor.value.childNodes[0].innerText);
332
+ }
333
+ // Register Codemirror
334
+ view.value = new EditorView({
335
+ doc: value,
336
+ extensions: extensions.value,
337
+ parent: editor.value,
338
+ dispatch: tr => {
339
+ view.value.update([tr]);
340
+ // TODO: Emit lint error event
341
+ // console.log(view.state.doc.toString(), tr);
342
+ if (tr.changes.empty)
343
+ return;
344
+ // child-to-parent binding
345
+ const v = view.value.state.doc.toString();
346
+ context.emit('update:modelValue', v);
347
+ context.emit('change', view.value.state);
348
+ },
349
+ });
350
+ await nextTick();
351
+ context.emit('ready', {
352
+ view: view,
353
+ state: view.value.state,
354
+ container: editor.value,
355
+ });
356
+ });
357
+ /** Destroy */
358
+ onUnmounted(() => {
359
+ if (view.value) {
360
+ view.value.destroy();
361
+ context.emit('destroy');
362
+ }
363
+ });
364
+ /**
365
+ * Forces any linters configured to run when the editor is idle to run right away.
366
+ *
367
+ * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
368
+ */
369
+ const lint = () => {
370
+ if (props.linter) {
371
+ forceLinting(view.value);
372
+ }
373
+ };
374
+ /* ----- Bellow is experimental. ------ */
375
+ /**
376
+ * Get the text between the given points in the editor.
377
+ *
378
+ * @param from - start line number
379
+ * @param to - end line number
380
+ */
381
+ const getRange = (from, to) => view.value.state.sliceDoc(from, to);
382
+ /**
383
+ * Get the content of line.
384
+ *
385
+ * @param number - line number
386
+ */
387
+ const getLine = (number) => view.value.state.doc.line(number + 1).text;
388
+ /** Get the number of lines in the editor. */
389
+ const lineCount = () => view.value.state.doc.lines;
390
+ /** Retrieve one end of the primary selection. */
391
+ const getCursor = () => cursor.value;
392
+ /** Retrieves a list of all current selections. */
393
+ const listSelections = () => view.value.state.selection.ranges;
394
+ /** Get the currently selected code. */
395
+ const getSelection = () => view.value.state.sliceDoc(view.value.state.selection.main.from, view.value.state.selection.main.to);
396
+ /**
397
+ * The length of the given array should be the same as the number of active selections.
398
+ * Replaces the content of the selections with the strings in the array.
399
+ */
400
+ const getSelections = () => view.value.state.selection.ranges.map((r) => view.value.state.sliceDoc(r.from, r.to));
401
+ /** Return true if any text is selected. */
402
+ const somethingSelected = () => view.value.state.selection.ranges.some((r) => !r.empty);
403
+ /**
404
+ * Replace the part of the document between from and to with the given string.
405
+ *
406
+ * @param replacement - replacement text
407
+ * @param from - start string at position
408
+ * @param to - insert the string at position
409
+ */
410
+ const replaceRange = (replacement, from, to) => view.value.dispatch({
411
+ changes: { from, to, insert: replacement },
412
+ });
413
+ /**
414
+ * Replace the selection(s) with the given string.
415
+ * By default, the new selection ends up after the inserted text.
416
+ *
417
+ * @param replacement - replacement text
418
+ */
419
+ const replaceSelection = (replacement) => view.value.dispatch(view.value.state.replaceSelection(replacement));
420
+ /**
421
+ * Set the cursor position.
422
+ *
423
+ * @param position - position.
424
+ */
425
+ const setCursor = (position) => (cursor.value = position);
426
+ /**
427
+ * Set a single selection range.
428
+ *
429
+ * @param anchor - anchor position
430
+ * @param head -
431
+ */
432
+ const setSelection = (anchor, head) => view.value.dispatch({ selection: { anchor, head } });
433
+ /**
434
+ * Sets a new set of selections. There must be at least one selection in the given array.
435
+ *
436
+ * @param ranges - Selection range
437
+ * @param primary -
438
+ */
439
+ const setSelections = (ranges, primary) => view.value.dispatch({
440
+ selection: EditorSelection.create(ranges, primary),
441
+ });
442
+ /**
443
+ * Applies the given function to all existing selections, and calls extendSelections on the result.
444
+ *
445
+ * @param f - function
446
+ */
447
+ const extendSelectionsBy = (f) => view.value.dispatch({
448
+ selection: EditorSelection.create(selection.value.ranges.map((r) => r.extend(f(r)))),
449
+ });
450
+ /** Export properties and functions */
451
+ context.expose({
452
+ editor,
453
+ cursor,
454
+ selection,
455
+ state,
456
+ focus,
457
+ length,
458
+ lint,
459
+ // Bellow is CodeMirror5's function
460
+ getRange,
461
+ getLine,
462
+ lineCount,
463
+ getCursor,
464
+ listSelections,
465
+ getSelection,
466
+ getSelections,
467
+ somethingSelected,
468
+ replaceRange,
469
+ replaceSelection,
470
+ setCursor,
471
+ setSelection,
472
+ setSelections,
473
+ extendSelectionsBy,
474
+ });
475
+ return {
476
+ editor,
477
+ };
478
+ },
479
+ render() {
480
+ // <template>
481
+ // <div ref="editor" class="vue-codemirror">
482
+ // <aside v-show="!context.slots.default" aria-hidden><slot /></aside>
483
+ // </div>
484
+ // </template>
485
+ return h(this.$props.tag, {
486
+ ref: 'editor',
487
+ class: 'vue-codemirror',
488
+ }, this.$slots.default
489
+ ? // Hide original content
490
+ h('aside', { style: 'display: none;', 'aria-hidden': 'true' }, slot(this.$slots.default))
491
+ : undefined);
492
+ },
493
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * h-demi - h function for Vue 2 and 3
3
+ *
4
+ * @see {@link https://github.com/vueuse/vue-demi/issues/65}
5
+ */
6
+ import { type VNode } from 'vue-demi';
7
+ interface Options {
8
+ class?: string;
9
+ domProps?: Record<any, any>;
10
+ on?: Record<any, any>;
11
+ props?: Record<any, any>;
12
+ ref?: string;
13
+ style?: string;
14
+ 'aria-hidden'?: string;
15
+ }
16
+ declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) => VNode;
17
+ declare const slot: (defaultSlots: any) => any;
18
+ export { slot, h as default };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * h-demi - h function for Vue 2 and 3
3
+ *
4
+ * @see {@link https://github.com/vueuse/vue-demi/issues/65}
5
+ */
6
+ import { h as hDemi, isVue2, Vue2 } from 'vue-demi';
7
+ const adaptOnsV3 = (ons) => {
8
+ if (!ons)
9
+ return {};
10
+ return Object.entries(ons).reduce((ret, [key, handler]) => {
11
+ key = key.charAt(0).toUpperCase() + key.slice(1);
12
+ key = `on${key}`;
13
+ return { ...ret, [key]: handler };
14
+ }, {});
15
+ };
16
+ const h = (type, options = {}, chidren) => {
17
+ if (isVue2 && parseInt(Vue2.version) < 2.7) {
18
+ // Makeshift support :(
19
+ // Since Vue2.7 includes the Composition API, the functions in vue-demi are not used.
20
+ return hDemi(type, options, chidren);
21
+ }
22
+ const { props, domProps, on, ...extraOptions } = options;
23
+ const ons = on ? adaptOnsV3(on) : {};
24
+ return hDemi(type, { ...extraOptions, ...props, ...domProps, ...ons }, chidren);
25
+ };
26
+ const slot = (defaultSlots) => typeof defaultSlots == 'function' ? defaultSlots() : defaultSlots;
27
+ export { slot, h as default };
@@ -0,0 +1,4 @@
1
+ import CodeMirror from './components/CodeMirror';
2
+ import Meta from './Meta';
3
+ declare const installCodeMirror: (app: any) => any;
4
+ export { CodeMirror as default, installCodeMirror as install, Meta };
package/dist/index.es.js CHANGED
@@ -5,13 +5,12 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.3
8
+ * @version 1.1.6
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
12
  import { isVue2, Vue2, h as h$1, defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
13
- import compact from 'lodash/compact';
14
- import trim from 'lodash/trim';
13
+ import { compact, trim } from 'lodash';
15
14
  import { basicSetup, minimalSetup } from 'codemirror';
16
15
  import { EditorState, StateEffect, EditorSelection } from '@codemirror/state';
17
16
  import { EditorView, keymap, placeholder } from '@codemirror/view';
@@ -319,8 +318,8 @@ var CodeMirror = defineComponent({
319
318
  });
320
319
 
321
320
  const meta = {
322
- version: "1.1.3",
323
- date: "2023-01-12T02:58:45.012Z"
321
+ version: "1.1.6",
322
+ date: "2023-01-16T11:26:58.296Z"
324
323
  };
325
324
 
326
325
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -5,18 +5,13 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.3
8
+ * @version 1.1.6
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state, view, commands, lint) {
12
+ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, commands, lint) {
13
13
  'use strict';
14
14
 
15
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var compact__default = /*#__PURE__*/_interopDefaultCompat(compact);
18
- var trim__default = /*#__PURE__*/_interopDefaultCompat(trim);
19
-
20
15
  const adaptOnsV3 = (ons) => {
21
16
  if (!ons)
22
17
  return {};
@@ -162,7 +157,7 @@ var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state,
162
157
  () => view$1.value.state.doc.length
163
158
  );
164
159
  const extensions = vueDemi.computed(
165
- () => compact__default["default"]([
160
+ () => lodash.compact([
166
161
  props.basic ? codemirror.basicSetup : void 0,
167
162
  props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
168
163
  view.EditorView.updateListener.of(
@@ -212,7 +207,7 @@ var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state,
212
207
  "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
213
208
  );
214
209
  }
215
- value = trim__default["default"](editor.value.childNodes[0].innerText);
210
+ value = lodash.trim(editor.value.childNodes[0].innerText);
216
211
  }
217
212
  view$1.value = new view.EditorView({
218
213
  doc: value,
@@ -318,8 +313,8 @@ var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state,
318
313
  });
319
314
 
320
315
  const meta = {
321
- version: "1.1.3",
322
- date: "2023-01-12T02:58:45.012Z"
316
+ version: "1.1.6",
317
+ date: "2023-01-16T11:26:58.296Z"
323
318
  };
324
319
 
325
320
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -335,4 +330,4 @@ var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state,
335
330
 
336
331
  return exports;
337
332
 
338
- })({}, VueDemi, compact, trim, codemirror, state, view, commands, lint);
333
+ })({}, VueDemi, lodash, codemirror, state, view, commands, lint);
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import CodeMirror from './components/CodeMirror';
2
+ import Meta from './Meta';
3
+ // TODO: Move phrases props to option.
4
+ const installCodeMirror = (app) => app.component('CodeMirror', CodeMirror);
5
+ export { CodeMirror as default, installCodeMirror as install, Meta };
6
+ // For CDN. (Maybe Vue2 only)
7
+ // @ts-ignore
8
+ if (typeof window !== 'undefined' && window.Vue) {
9
+ // @ts-ignore
10
+ window.Vue.use(CodeMirror);
11
+ }
package/dist/index.umd.js CHANGED
@@ -5,20 +5,15 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.3
8
+ * @version 1.1.6
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
12
  (function (global, factory) {
13
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash/compact'), require('lodash/trim'), require('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
14
- typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash/compact', 'lodash/trim', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
15
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.compact, global.trim, global.codemirror, global.state, global.view, global.commands, global.lint));
16
- })(this, (function (exports, vueDemi, compact, trim, codemirror, state, view, commands, lint) { 'use strict';
17
-
18
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
-
20
- var compact__default = /*#__PURE__*/_interopDefaultCompat(compact);
21
- var trim__default = /*#__PURE__*/_interopDefaultCompat(trim);
13
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash'), require('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
14
+ typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
15
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.lodash, global.codemirror, global.state, global.view, global.commands, global.lint));
16
+ })(this, (function (exports, vueDemi, lodash, codemirror, state, view, commands, lint) { 'use strict';
22
17
 
23
18
  const adaptOnsV3 = (ons) => {
24
19
  if (!ons)
@@ -165,7 +160,7 @@
165
160
  () => view$1.value.state.doc.length
166
161
  );
167
162
  const extensions = vueDemi.computed(
168
- () => compact__default["default"]([
163
+ () => lodash.compact([
169
164
  props.basic ? codemirror.basicSetup : void 0,
170
165
  props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
171
166
  view.EditorView.updateListener.of(
@@ -215,7 +210,7 @@
215
210
  "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
216
211
  );
217
212
  }
218
- value = trim__default["default"](editor.value.childNodes[0].innerText);
213
+ value = lodash.trim(editor.value.childNodes[0].innerText);
219
214
  }
220
215
  view$1.value = new view.EditorView({
221
216
  doc: value,
@@ -321,8 +316,8 @@
321
316
  });
322
317
 
323
318
  const meta = {
324
- version: "1.1.3",
325
- date: "2023-01-12T02:58:45.012Z"
319
+ version: "1.1.6",
320
+ date: "2023-01-16T11:26:58.296Z"
326
321
  };
327
322
 
328
323
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -0,0 +1,7 @@
1
+ /** Build information meta data */
2
+ export default interface MetaInterface {
3
+ /** Version */
4
+ version: string;
5
+ /** Build date */
6
+ date: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
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": "1.1.4",
4
+ "version": "1.1.6",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -67,7 +67,7 @@
67
67
  "build:clean": "rimraf dist docs",
68
68
  "build:docs": "vite build --mode=docs",
69
69
  "build-only": "vite build",
70
- "build-declaration": "tsc -p tsconfig.app.json --composite false --declaration --declarationMap --declarationDir dist",
70
+ "build-declaration": "tsc -p tsconfig.app.json --composite false",
71
71
  "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
72
72
  "preview": "vite preview --mode=docs",
73
73
  "prepare": "husky install",
@@ -75,6 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "codemirror": "^6.0.1",
78
+ "lodash": "^4.17.21",
78
79
  "vue-demi": "latest"
79
80
  },
80
81
  "peerDependencies": {
@@ -98,26 +99,25 @@
98
99
  "@vue/eslint-config-prettier": "^7.0.0",
99
100
  "@vue/tsconfig": "^0.1.3",
100
101
  "@vueuse/core": "^9.10.0",
101
- "eslint": "^8.31.0",
102
+ "eslint": "^8.32.0",
102
103
  "eslint-config-google": "^0.14.0",
103
104
  "eslint-config-prettier": "^8.6.0",
104
105
  "eslint-import-resolver-alias": "^1.1.2",
105
106
  "eslint-import-resolver-typescript": "^3.5.3",
106
- "eslint-linter-browserify": "^8.31.0",
107
+ "eslint-linter-browserify": "^8.32.0",
107
108
  "eslint-plugin-html": "^7.1.0",
108
- "eslint-plugin-import": "^2.27.2",
109
+ "eslint-plugin-import": "^2.27.4",
109
110
  "eslint-plugin-jsdoc": "^39.6.4",
110
111
  "eslint-plugin-prettier": "^4.2.1",
111
112
  "eslint-plugin-tsdoc": "^0.2.17",
112
- "eslint-plugin-vue": "^9.8.0",
113
- "eslint-plugin-vuejs-accessibility": "^2.0.0",
113
+ "eslint-plugin-vue": "^9.9.0",
114
+ "eslint-plugin-vuejs-accessibility": "^2.1.0",
114
115
  "eslint-plugin-yaml": "^0.5.0",
115
116
  "husky": "^8.0.3",
116
117
  "lint-staged": "^13.1.0",
117
- "lodash": "^4.17.21",
118
118
  "npm-run-all": "^4.1.5",
119
- "prettier": "^2.8.2",
120
- "rimraf": "^3.0.2",
119
+ "prettier": "^2.8.3",
120
+ "rimraf": "^4.0.7",
121
121
  "rollup-plugin-visualizer": "^5.9.0",
122
122
  "typescript": "^4.9.4",
123
123
  "vite": "^4.0.4",
@@ -18,8 +18,7 @@ import {
18
18
 
19
19
  // Helpers
20
20
  import h, { slot } from '@/helpers/h-demi';
21
- import compact from 'lodash/compact';
22
- import trim from 'lodash/trim';
21
+ import { compact, trim } from 'lodash';
23
22
 
24
23
  // CodeMirror
25
24
  import { basicSetup, minimalSetup } from 'codemirror';
@@ -332,7 +331,7 @@ export default defineComponent({
332
331
  /** Get CodeMirror Extension */
333
332
  const extensions: ComputedRef<Extension[]> = computed(() =>
334
333
  // TODO: Ignore previous prop was not changed.
335
- compact([
334
+ compact<Extension>([
336
335
  // Toggle basic setup
337
336
  props.basic ? basicSetup : undefined,
338
337
  // Toggle minimal setup