vue-codemirror6 0.6.4 → 0.6.7
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 +23 -20
- package/dist/components/CodeMirror.d.ts +10 -10
- package/dist/components/CodeMirror.d.ts.map +1 -1
- package/dist/helpers/h-demi.d.ts +2 -3
- package/dist/helpers/h-demi.d.ts.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +128 -158
- package/dist/index.umd.js +9 -5
- package/package.json +30 -24
package/README.md
CHANGED
|
@@ -16,12 +16,14 @@ yarn add vue-codemirror6
|
|
|
16
16
|
|
|
17
17
|
This component can handle bidirectional binding by `v-model` like a general Vue component.
|
|
18
18
|
|
|
19
|
-
When using with
|
|
19
|
+
When using with Vue 2.6, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
22
|
yarn add vue-codemirror6 @vue/composition-api
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
For Vue 2.7 or later, import vue directly like Vue3.
|
|
26
|
+
|
|
25
27
|
### Props
|
|
26
28
|
|
|
27
29
|
| Props | Type | Information |
|
|
@@ -232,25 +234,26 @@ export default defineComponent({
|
|
|
232
234
|
|
|
233
235
|
## Methods
|
|
234
236
|
|
|
235
|
-
| Methods | Description
|
|
236
|
-
| ------------------------------------------------------------------- |
|
|
237
|
-
| selection
|
|
238
|
-
|
|
|
239
|
-
|
|
|
240
|
-
|
|
|
241
|
-
|
|
|
242
|
-
|
|
|
243
|
-
|
|
|
244
|
-
|
|
|
245
|
-
|
|
|
246
|
-
|
|
|
247
|
-
|
|
|
248
|
-
|
|
|
249
|
-
|
|
|
250
|
-
|
|
|
251
|
-
|
|
|
252
|
-
|
|
|
253
|
-
|
|
|
237
|
+
| Methods | Description |
|
|
238
|
+
| ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
239
|
+
| selection | Get and set the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
|
|
240
|
+
| cursor | Get and set the cursor location. |
|
|
241
|
+
| state | Get and set [EditorState](https://codemirror.net/docs/ref/#state.EditorState). |
|
|
242
|
+
| focus | Get and set focus. |
|
|
243
|
+
| getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
|
|
244
|
+
| getLine(number: number) | Get the content of line. |
|
|
245
|
+
| lineCount() | Get the number of lines in the editor. |
|
|
246
|
+
| getCursor() | Retrieve one end of the primary selection. |
|
|
247
|
+
| listSelections() | Retrieves a list of all current selections. |
|
|
248
|
+
| getSelection() | Get the currently selected code. |
|
|
249
|
+
| getSelections() | The length of the given array should be the same as the number of active selections. |
|
|
250
|
+
| somethingSelected() | Return true if any text is selected. |
|
|
251
|
+
| replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
|
|
252
|
+
| replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
|
|
253
|
+
| setCursor(position: number) | Set the cursor position. |
|
|
254
|
+
| setSelection(anchor: number, head?: number) | Set a single selection range. |
|
|
255
|
+
| setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
|
|
256
|
+
| extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
|
|
254
257
|
|
|
255
258
|
## Recommendations
|
|
256
259
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PropType, type Ref, type SetupContext } from 'vue-demi';
|
|
2
|
-
import { EditorSelection } from '@codemirror/state';
|
|
2
|
+
import { EditorSelection, EditorState } from '@codemirror/state';
|
|
3
3
|
import type { Extension, SelectionRange, Text } from '@codemirror/state';
|
|
4
4
|
import type { LanguageSupport } from '@codemirror/language';
|
|
5
5
|
import type { ViewUpdate } from '@codemirror/view';
|
|
@@ -10,8 +10,9 @@ export interface CodeMirrorEmitsInterface {
|
|
|
10
10
|
/** Model Update */
|
|
11
11
|
(e: 'update:modelValue', value: string | Text): void;
|
|
12
12
|
/** CodeMirror ViewUpdate */
|
|
13
|
-
(e: 'update', value: ViewUpdate): void;
|
|
13
|
+
(e: 'update:view', value: ViewUpdate): void;
|
|
14
14
|
}
|
|
15
|
+
/** CodeMirror Component */
|
|
15
16
|
declare const _default: import("vue-demi").DefineComponent<{
|
|
16
17
|
/** Model value */
|
|
17
18
|
modelValue: {
|
|
@@ -133,8 +134,10 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
133
134
|
context: SetupContext<import("vue-demi").EmitsOptions>;
|
|
134
135
|
editor: Ref<Element | undefined>;
|
|
135
136
|
cursor: Ref<number>;
|
|
136
|
-
selection:
|
|
137
|
-
|
|
137
|
+
selection: Ref<EditorSelection>;
|
|
138
|
+
state: Ref<EditorState>;
|
|
139
|
+
focus: Ref<boolean>;
|
|
140
|
+
getRange: (from?: number, to?: number) => string;
|
|
138
141
|
getLine: (number: number) => string;
|
|
139
142
|
lineCount: () => number;
|
|
140
143
|
getCursor: () => number;
|
|
@@ -145,12 +148,10 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
145
148
|
replaceRange: (replacement: string | Text, from: number, to: number) => void;
|
|
146
149
|
replaceSelection: (replacement: string | Text) => void;
|
|
147
150
|
setCursor: (position: number) => number;
|
|
148
|
-
setSelection: (anchor: number, head?: number
|
|
149
|
-
setSelections: (ranges: readonly SelectionRange[], primary?: number
|
|
151
|
+
setSelection: (anchor: number, head?: number) => void;
|
|
152
|
+
setSelections: (ranges: readonly SelectionRange[], primary?: number) => void;
|
|
150
153
|
extendSelectionsBy: (f: Function) => void;
|
|
151
|
-
|
|
152
|
-
hasFocus: () => boolean;
|
|
153
|
-
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
154
|
+
}, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, import("vue-demi").EmitsOptions, "update:modelValue" | "update:view", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
154
155
|
/** Model value */
|
|
155
156
|
modelValue: {
|
|
156
157
|
type: PropType<string | Text>;
|
|
@@ -285,6 +286,5 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
285
286
|
linter: LintSource;
|
|
286
287
|
lintGutter: boolean;
|
|
287
288
|
}>;
|
|
288
|
-
/** CodeMirror Component */
|
|
289
289
|
export default _default;
|
|
290
290
|
//# sourceMappingURL=CodeMirror.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAOlB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAM9E,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,IAAI,EAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAqB;AACrB,MAAM,WAAW,wBAAwB;IACvC,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACrD,4BAA4B;IAC5B,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAC7C;AAED,2BAA2B;;IAWvB,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;;;;;sBAuJO,MAAM,OAAO,MAAM,KAAG,MAAM;sBAO5B,MAAM,KAAG,MAAM;qBAGlB,MAAM;qBAEN,MAAM;0BAED,SAAS,cAAc,EAAE;wBAG3B,MAAM;yBASL,MAAM,EAAE;6BAGJ,OAAO;gCAWtB,MAAM,GAAG,IAAI,QACpB,MAAM,MACR,MAAM;oCAW2B,MAAM,GAAG,IAAI;0BAOvB,MAAM;2BAOL,MAAM,SAAS,MAAM;4BASzC,SAAS,cAAc,EAAE,YACvB,MAAM;4BAUa,QAAQ;;IA/VvC,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;AA3HtB,wBA6ZG"}
|
package/dist/helpers/h-demi.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type VNode } from 'vue-demi';
|
|
1
2
|
interface Options {
|
|
2
3
|
class?: string;
|
|
3
4
|
domProps?: Record<any, any>;
|
|
@@ -7,9 +8,7 @@ interface Options {
|
|
|
7
8
|
style?: string;
|
|
8
9
|
'aria-hidden'?: string;
|
|
9
10
|
}
|
|
10
|
-
declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) =>
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
}>;
|
|
11
|
+
declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) => VNode;
|
|
13
12
|
declare const slot: (defaultSlots: any) => any;
|
|
14
13
|
export { slot, h as default };
|
|
15
14
|
//# sourceMappingURL=h-demi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,KAAK,EAAQ,MAAM,UAAU,CAAC;AAEhE,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD,QAAA,MAAM,CAAC,SACC,MAAM,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,YACtB,OAAO,YACN,GAAG,KACZ,KAcF,CAAC;AAEF,QAAA,MAAM,IAAI,iBAAkB,GAAG,QACoC,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vue CodeMirror6 Component
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
* @author Logue {@link logue@hotmail.co.jp}
|
|
6
|
-
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
|
-
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
-
*/
|
|
9
1
|
import CodeMirror from './components/CodeMirror';
|
|
10
2
|
declare const installCodeMirror: (app: any) => any;
|
|
11
3
|
export { CodeMirror as default, installCodeMirror as install };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAGjD,QAAA,MAAM,iBAAiB,QAAS,GAAG,QAA4C,CAAC;AAEhF,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
var CodeMirror = defineComponent({
|
|
1
|
+
/**
|
|
2
|
+
* vue-codemirror6
|
|
3
|
+
*
|
|
4
|
+
* @description CodeMirror6 Component for vue2 and vue3
|
|
5
|
+
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
+
* @copyright 2022 By Masashi Yoshikawa All rights reserved.
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @version 0.6.7
|
|
9
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { isVue2 as V, Vue2 as C, h, defineComponent as x, ref as g, computed as d, watch as B, onMounted as O, nextTick as M, onUnmounted as E, toRaw as R } from "vue-demi";
|
|
13
|
+
import { trim as j, compact as T } from "lodash";
|
|
14
|
+
import { StateEffect as $, EditorState as p, EditorSelection as v } from "@codemirror/state";
|
|
15
|
+
import { EditorView as r, keymap as D } from "@codemirror/view";
|
|
16
|
+
import { linter as G, lintGutter as L } from "@codemirror/lint";
|
|
17
|
+
import { basicSetup as A, minimalSetup as F } from "codemirror";
|
|
18
|
+
import { indentWithTab as N } from "@codemirror/commands";
|
|
19
|
+
const U = (t) => t ? Object.entries(t).reduce((i, [n, s]) => (n = n.charAt(0).toUpperCase() + n.slice(1), n = `on${n}`, { ...i, [n]: s }), {}) : {}, y = (t, i = {}, n) => {
|
|
20
|
+
if (V && parseInt(C.version) < 2.7)
|
|
21
|
+
return h(t, i, n);
|
|
22
|
+
const { props: s, domProps: o, on: l, ...c } = i, u = l ? U(l) : {};
|
|
23
|
+
return h(t, { ...c, ...s, ...o, ...u }, n);
|
|
24
|
+
}, W = (t) => typeof t == "function" ? t() : t, S = x({
|
|
26
25
|
name: "CodeMirror",
|
|
27
26
|
model: {
|
|
28
27
|
prop: "modelValue",
|
|
@@ -35,51 +34,49 @@ var CodeMirror = defineComponent({
|
|
|
35
34
|
},
|
|
36
35
|
theme: {
|
|
37
36
|
type: Object,
|
|
38
|
-
default: () => {
|
|
39
|
-
return {};
|
|
40
|
-
}
|
|
37
|
+
default: () => ({})
|
|
41
38
|
},
|
|
42
39
|
dark: {
|
|
43
40
|
type: Boolean,
|
|
44
|
-
default:
|
|
41
|
+
default: !1
|
|
45
42
|
},
|
|
46
43
|
basic: {
|
|
47
44
|
type: Boolean,
|
|
48
|
-
default:
|
|
45
|
+
default: !1
|
|
49
46
|
},
|
|
50
47
|
minimal: {
|
|
51
48
|
type: Boolean,
|
|
52
|
-
default:
|
|
49
|
+
default: !1
|
|
53
50
|
},
|
|
54
51
|
wrap: {
|
|
55
52
|
type: Boolean,
|
|
56
|
-
default:
|
|
53
|
+
default: !1
|
|
57
54
|
},
|
|
58
55
|
tab: {
|
|
59
56
|
type: Boolean,
|
|
60
|
-
default:
|
|
57
|
+
default: !1
|
|
61
58
|
},
|
|
62
59
|
readonly: {
|
|
63
60
|
type: Boolean,
|
|
64
|
-
default:
|
|
61
|
+
default: !1
|
|
65
62
|
},
|
|
66
63
|
editable: {
|
|
67
64
|
type: Boolean,
|
|
68
|
-
default:
|
|
65
|
+
default: !0
|
|
69
66
|
},
|
|
70
67
|
extensions: {
|
|
71
68
|
type: Array,
|
|
72
|
-
default: () =>
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
69
|
+
default: () => []
|
|
75
70
|
},
|
|
76
71
|
phrases: {
|
|
77
72
|
type: Object,
|
|
78
|
-
default: () =>
|
|
73
|
+
default: () => {
|
|
74
|
+
}
|
|
79
75
|
},
|
|
80
76
|
lang: {
|
|
81
77
|
type: Object,
|
|
82
|
-
default: () =>
|
|
78
|
+
default: () => {
|
|
79
|
+
}
|
|
83
80
|
},
|
|
84
81
|
linter: {
|
|
85
82
|
type: Function,
|
|
@@ -87,132 +84,105 @@ var CodeMirror = defineComponent({
|
|
|
87
84
|
},
|
|
88
85
|
lintGutter: {
|
|
89
86
|
type: Boolean,
|
|
90
|
-
defalt:
|
|
87
|
+
defalt: !1
|
|
91
88
|
}
|
|
92
89
|
},
|
|
93
|
-
emits: ["update:modelValue", "update"],
|
|
94
|
-
setup(
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
onMounted(async () => {
|
|
113
|
-
let value = doc.value;
|
|
114
|
-
if (editor.value && editor.value.childNodes[0]) {
|
|
115
|
-
if (doc.value !== "") {
|
|
116
|
-
console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.");
|
|
117
|
-
}
|
|
118
|
-
value = trim(editor.value.childNodes[0].innerText);
|
|
90
|
+
emits: ["update:modelValue", "update:view"],
|
|
91
|
+
setup(t, i) {
|
|
92
|
+
const n = g(), s = g(t.modelValue);
|
|
93
|
+
let o;
|
|
94
|
+
const l = d({
|
|
95
|
+
get: () => o.state.selection,
|
|
96
|
+
set: (e) => o.dispatch({ selection: e })
|
|
97
|
+
}), c = d({
|
|
98
|
+
get: () => l.value.main.head || 0,
|
|
99
|
+
set: (e) => o.dispatch({ selection: { anchor: e } })
|
|
100
|
+
}), u = d({
|
|
101
|
+
get: () => o.state,
|
|
102
|
+
set: (e) => o.setState(e)
|
|
103
|
+
}), w = d({
|
|
104
|
+
get: () => o.hasFocus,
|
|
105
|
+
set: (e) => {
|
|
106
|
+
e && o.focus();
|
|
119
107
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
108
|
+
}), m = i.emit;
|
|
109
|
+
B(t, (e) => {
|
|
110
|
+
if (e.modelValue) {
|
|
111
|
+
if (o.composing)
|
|
112
|
+
return;
|
|
113
|
+
const a = o.state.selection;
|
|
114
|
+
o.dispatch({
|
|
115
|
+
changes: { from: 0, to: o.state.doc.length, insert: e.modelValue },
|
|
116
|
+
selection: a
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
o.dispatch({
|
|
120
|
+
effects: $.reconfigure.of(f())
|
|
131
121
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const listSelections = () => selection().ranges;
|
|
159
|
-
const getSelection = () => view.state.sliceDoc(selection().main.from, selection().main.to);
|
|
160
|
-
const getSelections = () => selection().ranges.map((r) => view.state.sliceDoc(r.from, r.to));
|
|
161
|
-
const somethingSelected = () => selection().ranges.some((r) => !r.empty);
|
|
162
|
-
const replaceRange = (replacement, from, to) => view.dispatch({
|
|
163
|
-
changes: { from, to, insert: replacement }
|
|
164
|
-
});
|
|
165
|
-
const replaceSelection = (replacement) => view.dispatch(view.state.replaceSelection(replacement));
|
|
166
|
-
const setCursor = (position) => cursor.value = position;
|
|
167
|
-
const setSelection = (anchor, head) => view.dispatch({ selection: { anchor, head } });
|
|
168
|
-
const setSelections = (ranges, primary) => view.dispatch({
|
|
169
|
-
selection: EditorSelection.create(ranges, primary)
|
|
170
|
-
});
|
|
171
|
-
const extendSelectionsBy = (f) => view.dispatch({
|
|
172
|
-
selection: EditorSelection.create(selection().ranges.map((r) => r.extend(f(r))))
|
|
173
|
-
});
|
|
174
|
-
const focus = () => view.focus();
|
|
175
|
-
const hasFocus = () => view.hasFocus;
|
|
122
|
+
}), O(async () => {
|
|
123
|
+
let e = s.value;
|
|
124
|
+
n.value && n.value.childNodes[0] && (s.value !== "" && console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."), e = j(n.value.childNodes[0].innerText)), o = new r({
|
|
125
|
+
doc: e,
|
|
126
|
+
extensions: f(),
|
|
127
|
+
parent: n.value,
|
|
128
|
+
dispatch: (a) => {
|
|
129
|
+
o.update([a]), !a.changes.empty && m("update:modelValue", o.state.doc.toString());
|
|
130
|
+
}
|
|
131
|
+
}), await M();
|
|
132
|
+
}), E(() => o.destroy());
|
|
133
|
+
const f = () => T([
|
|
134
|
+
t.basic ? A : void 0,
|
|
135
|
+
t.minimal && !t.basic ? F : void 0,
|
|
136
|
+
r.updateListener.of((e) => m("update:view", e)),
|
|
137
|
+
r.theme(t.theme, { dark: t.dark }),
|
|
138
|
+
t.wrap ? r.lineWrapping : void 0,
|
|
139
|
+
t.tab ? D.of([N]) : void 0,
|
|
140
|
+
t.phrases ? p.phrases.of(t.phrases) : void 0,
|
|
141
|
+
t.readonly ? p.readOnly.of(t.readonly) : void 0,
|
|
142
|
+
t.editable ? r.editable.of(t.editable) : void 0,
|
|
143
|
+
t.lang ? R(t.lang) : void 0,
|
|
144
|
+
t.linter ? G(t.linter) : void 0,
|
|
145
|
+
t.linter && t.lintGutter ? L() : void 0,
|
|
146
|
+
...t.extensions
|
|
147
|
+
]);
|
|
176
148
|
return {
|
|
177
|
-
context,
|
|
178
|
-
editor,
|
|
179
|
-
cursor,
|
|
180
|
-
selection,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
149
|
+
context: i,
|
|
150
|
+
editor: n,
|
|
151
|
+
cursor: c,
|
|
152
|
+
selection: l,
|
|
153
|
+
state: u,
|
|
154
|
+
focus: w,
|
|
155
|
+
getRange: (e, a) => o.state.sliceDoc(e, a),
|
|
156
|
+
getLine: (e) => o.state.doc.line(e + 1).text,
|
|
157
|
+
lineCount: () => o.state.doc.lines,
|
|
158
|
+
getCursor: () => c.value,
|
|
159
|
+
listSelections: () => o.state.selection.ranges,
|
|
160
|
+
getSelection: () => o.state.sliceDoc(o.state.selection.main.from, o.state.selection.main.to),
|
|
161
|
+
getSelections: () => o.state.selection.ranges.map((e) => o.state.sliceDoc(e.from, e.to)),
|
|
162
|
+
somethingSelected: () => o.state.selection.ranges.some((e) => !e.empty),
|
|
163
|
+
replaceRange: (e, a, b) => o.dispatch({
|
|
164
|
+
changes: { from: a, to: b, insert: e }
|
|
165
|
+
}),
|
|
166
|
+
replaceSelection: (e) => o.dispatch(o.state.replaceSelection(e)),
|
|
167
|
+
setCursor: (e) => c.value = e,
|
|
168
|
+
setSelection: (e, a) => o.dispatch({ selection: { anchor: e, head: a } }),
|
|
169
|
+
setSelections: (e, a) => o.dispatch({
|
|
170
|
+
selection: v.create(e, a)
|
|
171
|
+
}),
|
|
172
|
+
extendSelectionsBy: (e) => o.dispatch({
|
|
173
|
+
selection: v.create(l.value.ranges.map((a) => a.extend(e(a))))
|
|
174
|
+
})
|
|
197
175
|
};
|
|
198
176
|
},
|
|
199
177
|
render() {
|
|
200
|
-
return
|
|
178
|
+
return y("div", {
|
|
201
179
|
ref: "editor",
|
|
202
180
|
class: "vue-codemirror"
|
|
203
|
-
}, this.$slots.default ?
|
|
181
|
+
}, this.$slots.default ? y("aside", { style: "display: none;", "aria-hidden": "true" }, W(this.$slots.default)) : void 0);
|
|
204
182
|
}
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
212
|
-
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
213
|
-
*/
|
|
214
|
-
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
215
|
-
if (typeof window !== "undefined" && window.Vue) {
|
|
216
|
-
window.Vue.use(CodeMirror);
|
|
217
|
-
}
|
|
218
|
-
export { CodeMirror as default, installCodeMirror as install };
|
|
183
|
+
}), ce = (t) => t.component("CodeMirror", S);
|
|
184
|
+
typeof window < "u" && window.Vue && window.Vue.use(S);
|
|
185
|
+
export {
|
|
186
|
+
S as default,
|
|
187
|
+
ce as install
|
|
188
|
+
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* vue-codemirror6
|
|
3
3
|
*
|
|
4
|
+
* @description CodeMirror6 Component for vue2 and vue3
|
|
5
|
+
* @author Logue <logue@hotmail.co.jp>
|
|
6
|
+
* @copyright 2022 By Masashi Yoshikawa All rights reserved.
|
|
4
7
|
* @license MIT
|
|
5
|
-
* @
|
|
6
|
-
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
8
|
+
* @version 0.6.7
|
|
7
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
(function(a,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("lodash"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","vue-demi","lodash","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands"],n):(a=typeof globalThis<"u"?globalThis:a||self,n(a.CodeMirror={},a.VueDemi,a.lodash,a.state,a.view,a.lint,a.codemirror,a.commands))})(this,function(a,n,p,u,d,g,y,V){"use strict";const C=t=>t?Object.entries(t).reduce((r,[i,c])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...r,[i]:c}),{}):{},S=(t,r={},i)=>{if(n.isVue2&&parseInt(n.Vue2.version)<2.7)return n.h(t,r,i);const{props:c,domProps:o,on:l,...f}=r,h=l?C(l):{};return n.h(t,{...f,...c,...o,...h},i)},b=t=>typeof t=="function"?t():t,m=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{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:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update:view"],setup(t,r){const i=n.ref(),c=n.ref(t.modelValue);let o;const l=n.computed({get:()=>o.state.selection,set:e=>o.dispatch({selection:e})}),f=n.computed({get:()=>l.value.main.head||0,set:e=>o.dispatch({selection:{anchor:e}})}),h=n.computed({get:()=>o.state,set:e=>o.setState(e)}),E=n.computed({get:()=>o.hasFocus,set:e=>{e&&o.focus()}}),v=r.emit;n.watch(t,e=>{if(e.modelValue){if(o.composing)return;const s=o.state.selection;o.dispatch({changes:{from:0,to:o.state.doc.length,insert:e.modelValue},selection:s})}o.dispatch({effects:u.StateEffect.reconfigure.of(w())})}),n.onMounted(async()=>{let e=c.value;i.value&&i.value.childNodes[0]&&(c.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),e=p.trim(i.value.childNodes[0].innerText)),o=new d.EditorView({doc:e,extensions:w(),parent:i.value,dispatch:s=>{o.update([s]),!s.changes.empty&&v("update:modelValue",o.state.doc.toString())}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const w=()=>p.compact([t.basic?y.basicSetup:void 0,t.minimal&&!t.basic?y.minimalSetup:void 0,d.EditorView.updateListener.of(e=>v("update:view",e)),d.EditorView.theme(t.theme,{dark:t.dark}),t.wrap?d.EditorView.lineWrapping:void 0,t.tab?d.keymap.of([V.indentWithTab]):void 0,t.phrases?u.EditorState.phrases.of(t.phrases):void 0,t.readonly?u.EditorState.readOnly.of(t.readonly):void 0,t.editable?d.EditorView.editable.of(t.editable):void 0,t.lang?n.toRaw(t.lang):void 0,t.linter?g.linter(t.linter):void 0,t.linter&&t.lintGutter?g.lintGutter():void 0,...t.extensions]);return{context:r,editor:i,cursor:f,selection:l,state:h,focus:E,getRange:(e,s)=>o.state.sliceDoc(e,s),getLine:e=>o.state.doc.line(e+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>f.value,listSelections:()=>o.state.selection.ranges,getSelection:()=>o.state.sliceDoc(o.state.selection.main.from,o.state.selection.main.to),getSelections:()=>o.state.selection.ranges.map(e=>o.state.sliceDoc(e.from,e.to)),somethingSelected:()=>o.state.selection.ranges.some(e=>!e.empty),replaceRange:(e,s,B)=>o.dispatch({changes:{from:s,to:B,insert:e}}),replaceSelection:e=>o.dispatch(o.state.replaceSelection(e)),setCursor:e=>f.value=e,setSelection:(e,s)=>o.dispatch({selection:{anchor:e,head:s}}),setSelections:(e,s)=>o.dispatch({selection:u.EditorSelection.create(e,s)}),extendSelectionsBy:e=>o.dispatch({selection:u.EditorSelection.create(l.value.ranges.map(s=>s.extend(e(s))))})}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;","aria-hidden":"true"},b(this.$slots.default)):void 0)}}),x=t=>t.component("CodeMirror",m);typeof window<"u"&&window.Vue&&window.Vue.use(m),a.default=m,a.install=x,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "vue-codemirror6",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.7",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"description": "CodeMirror6 Component for vue2 and vue3",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"vuejs",
|
|
@@ -32,24 +33,23 @@
|
|
|
32
33
|
"bugs": {
|
|
33
34
|
"url": "https://github.com/logue/vue-codemirror6/issues"
|
|
34
35
|
},
|
|
35
|
-
"engines": {
|
|
36
|
-
"node": ">=16.15.1",
|
|
37
|
-
"yarn": ">=1.22.4"
|
|
38
|
-
},
|
|
39
|
-
"packageManager": "yarn@3.2.1",
|
|
40
|
-
"license": "MIT",
|
|
41
36
|
"main": "./dist/index.umd.js",
|
|
42
37
|
"module": "./dist/index.es.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
43
39
|
"exports": {
|
|
44
40
|
".": {
|
|
45
41
|
"import": "./dist/index.es.js",
|
|
46
42
|
"require": "./dist/index.umd.js"
|
|
47
43
|
}
|
|
48
44
|
},
|
|
49
|
-
"types": "./dist/index.d.ts",
|
|
50
45
|
"files": [
|
|
51
46
|
"/dist"
|
|
52
47
|
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=16.16.0",
|
|
50
|
+
"yarn": ">=1.22.4"
|
|
51
|
+
},
|
|
52
|
+
"packageManager": "yarn@3.2.1",
|
|
53
53
|
"sideEffects": false,
|
|
54
54
|
"scripts": {
|
|
55
55
|
"dev": "vite",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"prepare": "husky install"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"codemirror": "^6.0.0",
|
|
68
67
|
"vue-demi": "latest"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
|
-
"@vue/composition-api": "^1.
|
|
70
|
+
"@vue/composition-api": "^1.7.0",
|
|
71
|
+
"codemirror": "^6.0.1",
|
|
72
72
|
"vue": "^2.6.14 || ^3.2.37"
|
|
73
73
|
},
|
|
74
74
|
"peerDependenciesMeta": {
|
|
@@ -77,24 +77,26 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@codemirror/lang-javascript": "^6.0.
|
|
80
|
+
"@codemirror/lang-javascript": "^6.0.2",
|
|
81
81
|
"@codemirror/lang-markdown": "^6.0.0",
|
|
82
82
|
"@types/lodash": "^4.14.182",
|
|
83
|
-
"@types/node": "^18.0.
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "^5.30.
|
|
85
|
-
"@typescript-eslint/parser": "^5.30.
|
|
86
|
-
"@vitejs/plugin-vue": "^
|
|
83
|
+
"@types/node": "^18.0.6",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
|
85
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
86
|
+
"@vitejs/plugin-vue": "^3.0.1",
|
|
87
87
|
"@vue/eslint-config-prettier": "^7.0.0",
|
|
88
|
-
"
|
|
88
|
+
"@vue/tsconfig": "^0.1.3",
|
|
89
|
+
"codemirror": "^6.0.1",
|
|
90
|
+
"eslint": "^8.20.0",
|
|
89
91
|
"eslint-config-google": "^0.14.0",
|
|
90
92
|
"eslint-config-prettier": "^8.5.0",
|
|
91
93
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
92
|
-
"eslint-import-resolver-typescript": "^3.
|
|
93
|
-
"eslint-plugin-html": "^
|
|
94
|
+
"eslint-import-resolver-typescript": "^3.3.0",
|
|
95
|
+
"eslint-plugin-html": "^7.0.0",
|
|
94
96
|
"eslint-plugin-import": "^2.26.0",
|
|
95
97
|
"eslint-plugin-jsdoc": "^39.3.3",
|
|
96
98
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
97
|
-
"eslint-plugin-vue": "^9.
|
|
99
|
+
"eslint-plugin-vue": "^9.2.0",
|
|
98
100
|
"eslint-plugin-vuejs-accessibility": "^1.2.0",
|
|
99
101
|
"eslint-plugin-yaml": "^0.5.0",
|
|
100
102
|
"eslint4b-prebuilt": "^6.7.2",
|
|
@@ -103,13 +105,14 @@
|
|
|
103
105
|
"lodash": "^4.17.21",
|
|
104
106
|
"prettier": "^2.7.1",
|
|
105
107
|
"rimraf": "^3.0.2",
|
|
106
|
-
"rollup-plugin-visualizer": "^5.
|
|
107
|
-
"typescript": "4.
|
|
108
|
-
"vite": "^
|
|
109
|
-
"vite-plugin-
|
|
108
|
+
"rollup-plugin-visualizer": "^5.7.1",
|
|
109
|
+
"typescript": "^4.7.4",
|
|
110
|
+
"vite": "^3.0.2",
|
|
111
|
+
"vite-plugin-banner": "^0.3.0",
|
|
112
|
+
"vite-plugin-checker": "^0.4.9",
|
|
110
113
|
"vue": "^3.2.37",
|
|
111
114
|
"vue-eslint-parser": "^9.0.3",
|
|
112
|
-
"vue-tsc": "^0.
|
|
115
|
+
"vue-tsc": "^0.39.0"
|
|
113
116
|
},
|
|
114
117
|
"husky": {
|
|
115
118
|
"hooks": {
|
|
@@ -119,5 +122,8 @@
|
|
|
119
122
|
"lint-staged": {
|
|
120
123
|
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
121
124
|
"*": "prettier -w -u"
|
|
125
|
+
},
|
|
126
|
+
"resolutions": {
|
|
127
|
+
"prettier": "^2.7.1"
|
|
122
128
|
}
|
|
123
129
|
}
|