vue-codemirror6 1.1.26 → 1.1.28

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.
@@ -1,539 +0,0 @@
1
- /**
2
- * vue-codemirror6
3
- *
4
- * @description CodeMirror6 Component for vue2 and vue3.
5
- * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
- * @license MIT
8
- * @version 1.1.25
9
- * @see {@link https://github.com/logue/vue-codemirror6}
10
- */
11
-
12
- var CodeMirror = (function (exports, vueDemi, codemirror, view, state, lint, commands) {
13
- 'use strict';
14
-
15
- const adaptOnsV3 = (ons) => {
16
- if (!ons)
17
- return {};
18
- return Object.entries(ons).reduce((ret, [key, handler]) => {
19
- key = key.charAt(0).toUpperCase() + key.slice(1);
20
- key = `on${key}`;
21
- return { ...ret, [key]: handler };
22
- }, {});
23
- };
24
- function h(type, options = {}, chidren) {
25
- if (vueDemi.isVue2) {
26
- return vueDemi.h(type, options, chidren);
27
- }
28
- const { props, domProps, on, ...extraOptions } = options;
29
- const ons = on ? adaptOnsV3(on) : {};
30
- return vueDemi.h(
31
- type,
32
- { ...extraOptions, ...props, ...domProps, ...ons },
33
- chidren
34
- );
35
- }
36
- const slot = (defaultSlots) => typeof defaultSlots === "function" ? defaultSlots() : defaultSlots;
37
-
38
- var CodeMirror = vueDemi.defineComponent({
39
- /** Component Name */
40
- name: "CodeMirror",
41
- /** Model Definition */
42
- model: {
43
- prop: "modelValue",
44
- event: "update:modelValue"
45
- },
46
- /** Props Definition */
47
- props: {
48
- /** Model value */
49
- modelValue: {
50
- type: String,
51
- default: ""
52
- },
53
- /**
54
- * Theme
55
- *
56
- * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
57
- */
58
- theme: {
59
- type: Object,
60
- default: () => {
61
- }
62
- },
63
- /** Dark Mode */
64
- dark: {
65
- type: Boolean,
66
- default: false
67
- },
68
- /**
69
- * Use Basic Setup
70
- *
71
- * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
72
- */
73
- basic: {
74
- type: Boolean,
75
- default: false
76
- },
77
- /**
78
- * Use Minimal Setup (The basic setting has priority.)
79
- *
80
- * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
81
- */
82
- minimal: {
83
- type: Boolean,
84
- default: false
85
- },
86
- /**
87
- * Placeholder
88
- *
89
- * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
90
- */
91
- placeholder: {
92
- type: String,
93
- default: void 0
94
- },
95
- /**
96
- * Line wrapping
97
- *
98
- * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
99
- *
100
- * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
101
- */
102
- wrap: {
103
- type: Boolean,
104
- default: false
105
- },
106
- /**
107
- * Allow tab key indent.
108
- *
109
- * @see {@link https://codemirror.net/examples/tab/}
110
- */
111
- tab: {
112
- type: Boolean,
113
- default: false
114
- },
115
- /**
116
- * Allow Multiple Selection.
117
- *
118
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^allowMultipleSelections}
119
- */
120
- allowMultipleSelections: {
121
- type: Boolean,
122
- default: false
123
- },
124
- /**
125
- * Tab size
126
- *
127
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
128
- */
129
- tabSize: {
130
- type: Number,
131
- default: void 0
132
- },
133
- /**
134
- * Set line break (separetor) char.
135
- *
136
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
137
- */
138
- lineSeparator: {
139
- type: String,
140
- default: void 0
141
- },
142
- /**
143
- * Readonly
144
- *
145
- * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
146
- */
147
- readonly: {
148
- type: Boolean,
149
- default: false
150
- },
151
- /**
152
- * Disable input.
153
- *
154
- * This is the reversed value of the CodeMirror editable.
155
- * Similar to `readonly`, but setting this value to true disables dragging.
156
- *
157
- * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
158
- */
159
- disabled: {
160
- type: Boolean,
161
- default: false
162
- },
163
- /**
164
- * Additional Extension
165
- *
166
- * @see {@link https://codemirror.net/docs/ref/#state.Extension}
167
- */
168
- extensions: {
169
- type: Array,
170
- default: () => {
171
- return [];
172
- }
173
- },
174
- /**
175
- * Language Phreses
176
- *
177
- * @see {@link https://codemirror.net/examples/translate/}
178
- */
179
- phrases: {
180
- type: Object,
181
- default: () => void 0
182
- },
183
- /**
184
- * CodeMirror Language
185
- *
186
- * @see {@link https://codemirror.net/docs/ref/#language}
187
- */
188
- lang: {
189
- type: Object,
190
- default: () => void 0
191
- },
192
- /**
193
- * CodeMirror Linter
194
- *
195
- * @see {@link https://codemirror.net/docs/ref/#lint.linter}
196
- */
197
- linter: {
198
- type: Function,
199
- default: void 0
200
- },
201
- /**
202
- * Linter Config
203
- *
204
- * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}
205
- */
206
- linterConfig: {
207
- type: Object,
208
- default: () => {
209
- return { needsRefresh: true };
210
- }
211
- },
212
- /**
213
- * Forces any linters configured to run when the editor is idle to run right away.
214
- *
215
- * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
216
- */
217
- forceLinting: {
218
- type: Boolean,
219
- default: false
220
- },
221
- /**
222
- * Show Linter Gutter
223
- *
224
- * An area to 🔴 the lines with errors will be displayed.
225
- * This feature is not enabled if `linter` is not specified.
226
- *
227
- * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
228
- */
229
- gutter: {
230
- type: Boolean,
231
- defalt: false
232
- },
233
- /**
234
- * Gutter Config
235
- *
236
- * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}
237
- */
238
- gutterConfig: {
239
- type: Object,
240
- default: () => void 0
241
- },
242
- /**
243
- * Using tag
244
- */
245
- tag: {
246
- type: String,
247
- default: "div"
248
- }
249
- },
250
- /** Emits */
251
- emits: {
252
- /** Model Update */
253
- "update:modelValue": (value) => true,
254
- /** CodeMirror ViewUpdate */
255
- update: (value) => true,
256
- /** CodeMirror onReady */
257
- ready: (value) => true,
258
- /** CodeMirror onFocus */
259
- focus: (value) => true,
260
- /** State Changed */
261
- change: (value) => true,
262
- /** CodeMirror onDestroy */
263
- destroy: () => true
264
- },
265
- /**
266
- * Setup
267
- *
268
- * @param props - Props
269
- * @param context - Context
270
- */
271
- setup(props, context) {
272
- const editor = vueDemi.ref();
273
- const doc = vueDemi.ref(props.modelValue);
274
- const view$1 = vueDemi.shallowRef(new view.EditorView());
275
- const focus = vueDemi.computed({
276
- get: () => view$1.value.hasFocus,
277
- set: (f) => {
278
- if (f) {
279
- view$1.value.focus();
280
- }
281
- }
282
- });
283
- const selection = vueDemi.computed({
284
- get: () => view$1.value.state.selection,
285
- set: (s) => view$1.value.dispatch({ selection: s })
286
- });
287
- const cursor = vueDemi.computed({
288
- get: () => view$1.value.state.selection.main.head,
289
- set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
290
- });
291
- const json = vueDemi.computed(
292
- {
293
- get: () => view$1.value.state.toJSON(),
294
- set: (j) => view$1.value.setState(state.EditorState.fromJSON(j))
295
- }
296
- );
297
- const length = vueDemi.ref(0);
298
- const diagnosticCount = vueDemi.ref(0);
299
- const language = new state.Compartment();
300
- const tabSize = new state.Compartment();
301
- const extensions = vueDemi.computed(
302
- () => (
303
- // TODO: Ignore previous prop was not changed.
304
- [
305
- // Toggle basic setup
306
- props.basic ? codemirror.basicSetup : void 0,
307
- // Toggle minimal setup
308
- props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
309
- // ViewUpdate event listener
310
- view.EditorView.updateListener.of((update) => {
311
- if (update.changes.empty || !update.docChanged) {
312
- return;
313
- }
314
- if (props.linter) {
315
- if (props.forceLinting) {
316
- lint.forceLinting(view$1.value);
317
- }
318
- diagnosticCount.value = props.linter(view$1.value).length;
319
- }
320
- context.emit("update", update);
321
- }),
322
- // Toggle light/dark mode.
323
- view.EditorView.theme(props.theme, { dark: props.dark }),
324
- // Toggle line wrapping
325
- props.wrap ? view.EditorView.lineWrapping : void 0,
326
- // Indent with tab
327
- props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
328
- // Allow Multiple Selections
329
- state.EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
330
- // Indent tab size
331
- props.tabSize ? tabSize.of(state.EditorState.tabSize.of(props.tabSize)) : void 0,
332
- // locale settings
333
- props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
334
- // Readonly option
335
- state.EditorState.readOnly.of(props.readonly),
336
- // Editable option
337
- view.EditorView.editable.of(!props.disabled),
338
- // Set Line break char
339
- props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
340
- // Lang
341
- props.lang ? language.of(props.lang) : void 0,
342
- // Append Linter settings
343
- props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
344
- // Show 🔴 to error line when linter enabled.
345
- props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
346
- // Placeholder
347
- props.placeholder ? view.placeholder(props.placeholder) : void 0,
348
- // Append Extensions
349
- ...props.extensions
350
- ].filter((extension) => !!extension)
351
- )
352
- );
353
- vueDemi.watch(
354
- extensions,
355
- (exts) => {
356
- view$1.value?.dispatch({
357
- effects: state.StateEffect.reconfigure.of(exts)
358
- });
359
- },
360
- { immediate: true }
361
- );
362
- vueDemi.watch(
363
- () => props.modelValue,
364
- async (value) => {
365
- if (view$1.value.composing || // IME fix
366
- view$1.value.state.doc.toJSON().join(props.lineSeparator ?? "\n") === value) {
367
- length.value = view$1.value.state.doc.length;
368
- return;
369
- }
370
- view$1.value.dispatch({
371
- changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
372
- selection: view$1.value.state.selection,
373
- scrollIntoView: true
374
- });
375
- length.value = view$1.value.state.doc.length;
376
- },
377
- { immediate: true }
378
- );
379
- vueDemi.watch(focus, (isFocus) => context.emit("focus", isFocus));
380
- vueDemi.onMounted(async () => {
381
- let value = doc.value;
382
- if (!editor.value) {
383
- return;
384
- }
385
- if (editor.value.childNodes[0]) {
386
- if (doc.value !== "") {
387
- console.warn(
388
- "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
389
- );
390
- }
391
- value = editor.value.childNodes[0].innerText.trim();
392
- }
393
- view$1.value = new view.EditorView({
394
- parent: editor.value,
395
- state: state.EditorState.create({ doc: value, extensions: extensions.value }),
396
- dispatch: (tr) => {
397
- view$1.value.update([tr]);
398
- if (tr.changes.empty || !tr.docChanged) {
399
- return;
400
- }
401
- context.emit("update:modelValue", tr.state.doc.toString());
402
- context.emit("change", tr.state);
403
- }
404
- });
405
- await vueDemi.nextTick();
406
- context.emit("ready", {
407
- view: view$1.value,
408
- state: view$1.value.state,
409
- container: editor.value
410
- });
411
- });
412
- vueDemi.onUnmounted(() => {
413
- view$1.value.destroy();
414
- context.emit("destroy");
415
- });
416
- const lint$1 = () => {
417
- if (!props.linter || !view$1.value) {
418
- return;
419
- }
420
- if (props.forceLinting) {
421
- lint.forceLinting(view$1.value);
422
- }
423
- diagnosticCount.value = lint.diagnosticCount(view$1.value.state);
424
- };
425
- const forceReconfigure = () => {
426
- view$1.value?.dispatch({
427
- effects: state.StateEffect.reconfigure.of([])
428
- });
429
- view$1.value?.dispatch({
430
- effects: state.StateEffect.appendConfig.of(extensions.value)
431
- });
432
- };
433
- const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
434
- const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
435
- const lineCount = () => view$1.value.state.doc.lines;
436
- const getCursor = () => view$1.value.state.selection.main.head;
437
- const listSelections = () => {
438
- let _view$value$state$sel;
439
- return (_view$value$state$sel = view$1.value.state.selection.ranges) !== null && _view$value$state$sel !== void 0 ? _view$value$state$sel : [];
440
- };
441
- const getSelection = () => {
442
- let _view$value$state$sli;
443
- return (_view$value$state$sli = view$1.value.state.sliceDoc(
444
- view$1.value.state.selection.main.from,
445
- view$1.value.state.selection.main.to
446
- )) !== null && _view$value$state$sli !== void 0 ? _view$value$state$sli : "";
447
- };
448
- const getSelections = () => {
449
- const s = view$1.value.state;
450
- if (!s) {
451
- return [];
452
- }
453
- return s.selection.ranges.map(
454
- (r) => s.sliceDoc(r.from, r.to)
455
- );
456
- };
457
- const somethingSelected = () => view$1.value.state.selection.ranges.some(
458
- (r) => !r.empty
459
- );
460
- const replaceRange = (replacement, from, to) => view$1.value.dispatch({
461
- changes: { from, to, insert: replacement }
462
- });
463
- const replaceSelection = (replacement) => view$1.value.dispatch(view$1.value.state.replaceSelection(replacement));
464
- const setCursor = (position) => view$1.value.dispatch({ selection: { anchor: position } });
465
- const setSelection = (anchor, head) => view$1.value.dispatch({ selection: { anchor, head } });
466
- const setSelections = (ranges, primary) => view$1.value.dispatch({
467
- selection: state.EditorSelection.create(ranges, primary)
468
- });
469
- const extendSelectionsBy = (f) => view$1.value.dispatch({
470
- selection: state.EditorSelection.create(
471
- selection.value.ranges.map((r) => r.extend(f(r)))
472
- )
473
- });
474
- const exposed = {
475
- editor,
476
- view: view$1,
477
- cursor,
478
- selection,
479
- focus,
480
- length,
481
- json,
482
- diagnosticCount,
483
- lint: lint$1,
484
- forceReconfigure,
485
- // Bellow is CodeMirror5's function
486
- getRange,
487
- getLine,
488
- lineCount,
489
- getCursor,
490
- listSelections,
491
- getSelection,
492
- getSelections,
493
- somethingSelected,
494
- replaceRange,
495
- replaceSelection,
496
- setCursor,
497
- setSelection,
498
- setSelections,
499
- extendSelectionsBy
500
- };
501
- context.expose(exposed);
502
- return exposed;
503
- },
504
- render() {
505
- return h(
506
- this.$props.tag,
507
- {
508
- ref: "editor",
509
- class: "vue-codemirror"
510
- },
511
- this.$slots.default ? (
512
- // Hide original content
513
- h(
514
- "aside",
515
- { style: "display: none;", "aria-hidden": "true" },
516
- slot(this.$slots.default)
517
- )
518
- ) : void 0
519
- );
520
- }
521
- });
522
-
523
- const meta = {
524
- version: "1.1.25",
525
- date: "2023-08-16T11:00:18.396Z"
526
- };
527
- var meta$1 = meta;
528
-
529
- const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
530
-
531
- exports.Meta = meta$1;
532
- exports["default"] = CodeMirror;
533
- exports.install = installCodeMirror;
534
-
535
- Object.defineProperty(exports, '__esModule', { value: true });
536
-
537
- return exports;
538
-
539
- })({}, VueDemi, codemirror, view, state, lint, commands);