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