vue-codemirror6 0.6.3 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -21
- package/dist/components/CodeMirror.d.ts +3 -3
- 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 +39 -33
- package/dist/index.umd.js +9 -5
- package/package.json +19 -14
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 |
|
|
@@ -61,7 +63,7 @@ Notice: `lang` and `linter` can also be set together in `extensions`. This is de
|
|
|
61
63
|
|
|
62
64
|
- [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
|
|
63
65
|
- [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
|
|
64
|
-
- [
|
|
66
|
+
- [`codemirror6-bootstrap-theme`](https://github.com/logue/codemirror6-bootstrap-theme)
|
|
65
67
|
|
|
66
68
|
## Example
|
|
67
69
|
|
|
@@ -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
|
+
| getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
|
|
242
|
+
| getLine(number: number) | Get the content of line. |
|
|
243
|
+
| lineCount() | Get the number of lines in the editor. |
|
|
244
|
+
| getCursor() | Retrieve one end of the primary selection. |
|
|
245
|
+
| listSelections() | Retrieves a list of all current selections. |
|
|
246
|
+
| getSelection() | Get the currently selected code. |
|
|
247
|
+
| getSelections() | The length of the given array should be the same as the number of active selections. |
|
|
248
|
+
| somethingSelected() | Return true if any text is selected. |
|
|
249
|
+
| replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
|
|
250
|
+
| replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
|
|
251
|
+
| setCursor(position: number) | Set the cursor position. |
|
|
252
|
+
| setSelection(anchor: number, head?: number) | Set a single selection range. |
|
|
253
|
+
| setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
|
|
254
|
+
| extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
|
|
255
|
+
| focus() | Set focus |
|
|
256
|
+
| hasFocus() | is Focused |
|
|
254
257
|
|
|
255
258
|
## Recommendations
|
|
256
259
|
|
|
@@ -10,7 +10,7 @@ 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
15
|
/** CodeMirror Component */
|
|
16
16
|
declare const _default: import("vue-demi").DefineComponent<{
|
|
@@ -134,7 +134,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
134
134
|
context: SetupContext<import("vue-demi").EmitsOptions>;
|
|
135
135
|
editor: Ref<Element | undefined>;
|
|
136
136
|
cursor: Ref<number>;
|
|
137
|
-
selection:
|
|
137
|
+
selection: Ref<EditorSelection>;
|
|
138
138
|
getRange: (from?: number, to?: number) => string;
|
|
139
139
|
getLine: (number: number) => string;
|
|
140
140
|
lineCount: () => number;
|
|
@@ -151,7 +151,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
151
151
|
extendSelectionsBy: (f: Function) => void;
|
|
152
152
|
focus: () => void;
|
|
153
153
|
hasFocus: () => boolean;
|
|
154
|
-
}, 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<{
|
|
155
155
|
/** Model value */
|
|
156
156
|
modelValue: {
|
|
157
157
|
type: PropType<string | Text>;
|
|
@@ -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,EAA4B,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;;;;;;;;;;sBAiJO,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;;oBAUlB,OAAO;;IAnW5B,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,wBA4ZG"}
|
package/dist/helpers/h-demi.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { 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,EAAQ,MAAM,UAAU,CAAC;AAE3D,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,mBAAiD,CAAC;AAEzE,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
|
|
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.6
|
|
9
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { isVue2, Vue2, h as h$1, defineComponent, ref, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
|
|
13
|
+
import { trim, compact } from "lodash";
|
|
2
14
|
import { StateEffect, EditorState, EditorSelection } from "@codemirror/state";
|
|
3
15
|
import { EditorView, keymap } from "@codemirror/view";
|
|
4
16
|
import { linter, lintGutter } from "@codemirror/lint";
|
|
5
17
|
import { basicSetup, minimalSetup } from "codemirror";
|
|
6
18
|
import { indentWithTab } from "@codemirror/commands";
|
|
7
|
-
import { trim, compact } from "lodash";
|
|
8
19
|
const adaptOnsV3 = (ons) => {
|
|
9
20
|
if (!ons)
|
|
10
|
-
return
|
|
21
|
+
return {};
|
|
11
22
|
return Object.entries(ons).reduce((ret, [key, handler]) => {
|
|
12
23
|
key = key.charAt(0).toUpperCase() + key.slice(1);
|
|
13
24
|
key = `on${key}`;
|
|
@@ -15,8 +26,9 @@ const adaptOnsV3 = (ons) => {
|
|
|
15
26
|
}, {});
|
|
16
27
|
};
|
|
17
28
|
const h = (type, options = {}, chidren) => {
|
|
18
|
-
if (isVue2)
|
|
29
|
+
if (isVue2 && parseInt(Vue2.version) < 2.7) {
|
|
19
30
|
return h$1(type, options, chidren);
|
|
31
|
+
}
|
|
20
32
|
const { props, domProps, on, ...extraOptions } = options;
|
|
21
33
|
const ons = on ? adaptOnsV3(on) : {};
|
|
22
34
|
return h$1(type, { ...extraOptions, ...props, ...domProps, ...ons }, chidren);
|
|
@@ -41,7 +53,7 @@ var CodeMirror = defineComponent({
|
|
|
41
53
|
},
|
|
42
54
|
dark: {
|
|
43
55
|
type: Boolean,
|
|
44
|
-
default:
|
|
56
|
+
default: false
|
|
45
57
|
},
|
|
46
58
|
basic: {
|
|
47
59
|
type: Boolean,
|
|
@@ -90,29 +102,30 @@ var CodeMirror = defineComponent({
|
|
|
90
102
|
defalt: false
|
|
91
103
|
}
|
|
92
104
|
},
|
|
93
|
-
emits: ["update:modelValue", "update"],
|
|
105
|
+
emits: ["update:modelValue", "update:view"],
|
|
94
106
|
setup(props, context) {
|
|
95
107
|
const editor = ref();
|
|
96
108
|
const doc = ref(props.modelValue);
|
|
109
|
+
let view;
|
|
110
|
+
const selection = computed({
|
|
111
|
+
get: () => view.state.selection,
|
|
112
|
+
set: (s) => view.dispatch({ selection: s })
|
|
113
|
+
});
|
|
97
114
|
const cursor = computed({
|
|
98
|
-
get: () =>
|
|
99
|
-
set: (
|
|
115
|
+
get: () => selection.value.main.head || 0,
|
|
116
|
+
set: (a) => view.dispatch({ selection: { anchor: a } })
|
|
100
117
|
});
|
|
101
118
|
const emit = context.emit;
|
|
102
|
-
|
|
103
|
-
watch(doc, (value) => {
|
|
119
|
+
watch(() => props.modelValue, (text) => {
|
|
104
120
|
if (view.composing) {
|
|
105
121
|
return;
|
|
106
122
|
}
|
|
123
|
+
const previous = view.state.selection;
|
|
107
124
|
view.dispatch({
|
|
108
|
-
changes: { from: 0, to:
|
|
109
|
-
selection:
|
|
125
|
+
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
126
|
+
selection: previous
|
|
110
127
|
});
|
|
111
128
|
});
|
|
112
|
-
watch(() => props.modelValue, (text) => view.dispatch({
|
|
113
|
-
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
114
|
-
selection: { anchor: cursor.value }
|
|
115
|
-
}));
|
|
116
129
|
watch(() => props.dark, () => {
|
|
117
130
|
view.dispatch({
|
|
118
131
|
effects: StateEffect.reconfigure.of(getExtensions())
|
|
@@ -134,8 +147,7 @@ var CodeMirror = defineComponent({
|
|
|
134
147
|
view.update([tr]);
|
|
135
148
|
if (tr.changes.empty)
|
|
136
149
|
return;
|
|
137
|
-
|
|
138
|
-
emit("update:modelValue", doc.value);
|
|
150
|
+
emit("update:modelValue", view.state.doc.toString());
|
|
139
151
|
}
|
|
140
152
|
});
|
|
141
153
|
await nextTick();
|
|
@@ -145,7 +157,7 @@ var CodeMirror = defineComponent({
|
|
|
145
157
|
const extensions = compact([
|
|
146
158
|
props.basic ? basicSetup : void 0,
|
|
147
159
|
props.minimal && !props.basic ? minimalSetup : void 0,
|
|
148
|
-
EditorView.updateListener.of((update) => emit("update", update)),
|
|
160
|
+
EditorView.updateListener.of((update) => emit("update:view", update)),
|
|
149
161
|
EditorView.theme(props.theme, { dark: props.dark }),
|
|
150
162
|
props.wrap ? EditorView.lineWrapping : void 0,
|
|
151
163
|
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
@@ -159,15 +171,14 @@ var CodeMirror = defineComponent({
|
|
|
159
171
|
]);
|
|
160
172
|
return extensions;
|
|
161
173
|
};
|
|
162
|
-
const selection = () => view.state.selection;
|
|
163
174
|
const getRange = (from, to) => view.state.sliceDoc(from, to);
|
|
164
175
|
const getLine = (number) => view.state.doc.line(number + 1).text;
|
|
165
176
|
const lineCount = () => view.state.doc.lines;
|
|
166
177
|
const getCursor = () => cursor.value;
|
|
167
|
-
const listSelections = () => selection
|
|
168
|
-
const getSelection = () => view.state.sliceDoc(selection
|
|
169
|
-
const getSelections = () => selection
|
|
170
|
-
const somethingSelected = () => selection
|
|
178
|
+
const listSelections = () => view.state.selection.ranges;
|
|
179
|
+
const getSelection = () => view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to);
|
|
180
|
+
const getSelections = () => view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to));
|
|
181
|
+
const somethingSelected = () => view.state.selection.ranges.some((r) => !r.empty);
|
|
171
182
|
const replaceRange = (replacement, from, to) => view.dispatch({
|
|
172
183
|
changes: { from, to, insert: replacement }
|
|
173
184
|
});
|
|
@@ -178,7 +189,7 @@ var CodeMirror = defineComponent({
|
|
|
178
189
|
selection: EditorSelection.create(ranges, primary)
|
|
179
190
|
});
|
|
180
191
|
const extendSelectionsBy = (f) => view.dispatch({
|
|
181
|
-
selection: EditorSelection.create(selection
|
|
192
|
+
selection: EditorSelection.create(selection.value.ranges.map((r) => r.extend(f(r))))
|
|
182
193
|
});
|
|
183
194
|
const focus = () => view.focus();
|
|
184
195
|
const hasFocus = () => view.hasFocus;
|
|
@@ -212,13 +223,8 @@ var CodeMirror = defineComponent({
|
|
|
212
223
|
}, this.$slots.default ? h("aside", { style: "display: none;", "aria-hidden": "true" }, slot(this.$slots.default)) : void 0);
|
|
213
224
|
}
|
|
214
225
|
});
|
|
215
|
-
/**
|
|
216
|
-
* Vue CodeMirror6 Component
|
|
217
|
-
*
|
|
218
|
-
* @license MIT
|
|
219
|
-
* @author Logue {@link logue@hotmail.co.jp}
|
|
220
|
-
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
221
|
-
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
222
|
-
*/
|
|
223
226
|
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
227
|
+
if (typeof window !== "undefined" && window.Vue) {
|
|
228
|
+
window.Vue.use(CodeMirror);
|
|
229
|
+
}
|
|
224
230
|
export { CodeMirror as default, installCodeMirror as install };
|
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.6
|
|
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,c,g,y,w){"use strict";const V=e=>e?Object.entries(e).reduce((r,[s,d])=>(s=s.charAt(0).toUpperCase()+s.slice(1),s=`on${s}`,{...r,[s]:d}),{}):{},v=(e,r={},s)=>{if(n.isVue2&&parseInt(n.Vue2.version)<2.7)return n.h(e,r,s);const{props:d,domProps:t,on:l,...f}=r,m=l?V(l):{};return n.h(e,{...f,...d,...t,...m},s)},C=e=>typeof e=="function"?e():e;var h=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(e,r){const s=n.ref(),d=n.ref(e.modelValue);let t;const l=n.computed({get:()=>t.state.selection,set:o=>t.dispatch({selection:o})}),f=n.computed({get:()=>l.value.main.head||0,set:o=>t.dispatch({selection:{anchor:o}})}),m=r.emit;n.watch(()=>e.modelValue,o=>{if(t.composing)return;const i=t.state.selection;t.dispatch({changes:{from:0,to:t.state.doc.length,insert:o},selection:i})}),n.watch(()=>e.dark,()=>{t.dispatch({effects:u.StateEffect.reconfigure.of(S())})}),n.onMounted(async()=>{let o=d.value;s.value&&s.value.childNodes[0]&&(d.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),o=p.trim(s.value.childNodes[0].innerText)),t=new c.EditorView({doc:o,extensions:S(),parent:s.value,dispatch:i=>{t.update([i]),!i.changes.empty&&m("update:modelValue",t.state.doc.toString())}}),await n.nextTick()}),n.onUnmounted(()=>t.destroy());const S=()=>p.compact([e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(i=>m("update:view",i)),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([w.indentWithTab]):void 0,e.phrases?u.EditorState.phrases.of(e.phrases):void 0,e.readonly?u.EditorState.readOnly.of(e.readonly):void 0,e.editable?c.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?g.linter(e.linter):void 0,e.linter&&e.lintGutter?g.lintGutter():void 0,...e.extensions]);return{context:r,editor:s,cursor:f,selection:l,getRange:(o,i)=>t.state.sliceDoc(o,i),getLine:o=>t.state.doc.line(o+1).text,lineCount:()=>t.state.doc.lines,getCursor:()=>f.value,listSelections:()=>t.state.selection.ranges,getSelection:()=>t.state.sliceDoc(t.state.selection.main.from,t.state.selection.main.to),getSelections:()=>t.state.selection.ranges.map(o=>t.state.sliceDoc(o.from,o.to)),somethingSelected:()=>t.state.selection.ranges.some(o=>!o.empty),replaceRange:(o,i,b)=>t.dispatch({changes:{from:i,to:b,insert:o}}),replaceSelection:o=>t.dispatch(t.state.replaceSelection(o)),setCursor:o=>f.value=o,setSelection:(o,i)=>t.dispatch({selection:{anchor:o,head:i}}),setSelections:(o,i)=>t.dispatch({selection:u.EditorSelection.create(o,i)}),extendSelectionsBy:o=>t.dispatch({selection:u.EditorSelection.create(l.value.ranges.map(i=>i.extend(o(i))))}),focus:()=>t.focus(),hasFocus:()=>t.hasFocus}},render(){return v("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?v("aside",{style:"display: none;","aria-hidden":"true"},C(this.$slots.default)):void 0)}});const x=e=>e.component("CodeMirror",h);typeof window<"u"&&window.Vue&&window.Vue.use(h),a.default=h,a.install=x,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "vue-codemirror6",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.6",
|
|
5
5
|
"description": "CodeMirror6 Component for vue2 and vue3",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
@@ -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,39 +77,41 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@codemirror/lang-javascript": "^6.0.
|
|
80
|
+
"@codemirror/lang-javascript": "^6.0.1",
|
|
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.
|
|
85
|
-
"@typescript-eslint/parser": "^5.
|
|
83
|
+
"@types/node": "^18.0.3",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
85
|
+
"@typescript-eslint/parser": "^5.30.5",
|
|
86
86
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
87
87
|
"@vue/eslint-config-prettier": "^7.0.0",
|
|
88
|
-
"
|
|
88
|
+
"codemirror": "^6.0.1",
|
|
89
|
+
"eslint": "^8.19.0",
|
|
89
90
|
"eslint-config-google": "^0.14.0",
|
|
90
91
|
"eslint-config-prettier": "^8.5.0",
|
|
91
92
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
92
|
-
"eslint-import-resolver-typescript": "^2.
|
|
93
|
+
"eslint-import-resolver-typescript": "^3.2.4",
|
|
93
94
|
"eslint-plugin-html": "^6.2.0",
|
|
94
95
|
"eslint-plugin-import": "^2.26.0",
|
|
95
96
|
"eslint-plugin-jsdoc": "^39.3.3",
|
|
96
97
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
97
|
-
"eslint-plugin-vue": "^9.
|
|
98
|
+
"eslint-plugin-vue": "^9.2.0",
|
|
98
99
|
"eslint-plugin-vuejs-accessibility": "^1.2.0",
|
|
99
100
|
"eslint-plugin-yaml": "^0.5.0",
|
|
100
101
|
"eslint4b-prebuilt": "^6.7.2",
|
|
101
102
|
"husky": "^8.0.1",
|
|
102
|
-
"lint-staged": "^13.0.
|
|
103
|
+
"lint-staged": "^13.0.3",
|
|
103
104
|
"lodash": "^4.17.21",
|
|
104
105
|
"prettier": "^2.7.1",
|
|
105
106
|
"rimraf": "^3.0.2",
|
|
106
107
|
"rollup-plugin-visualizer": "^5.6.0",
|
|
107
108
|
"typescript": "^4.7.4",
|
|
108
|
-
"vite": "^2.9.
|
|
109
|
-
"vite-plugin-
|
|
109
|
+
"vite": "^2.9.13",
|
|
110
|
+
"vite-plugin-banner": "^0.3.0",
|
|
111
|
+
"vite-plugin-checker": "^0.4.8",
|
|
110
112
|
"vue": "^3.2.37",
|
|
111
113
|
"vue-eslint-parser": "^9.0.3",
|
|
112
|
-
"vue-tsc": "^0.38.
|
|
114
|
+
"vue-tsc": "^0.38.2"
|
|
113
115
|
},
|
|
114
116
|
"husky": {
|
|
115
117
|
"hooks": {
|
|
@@ -119,5 +121,8 @@
|
|
|
119
121
|
"lint-staged": {
|
|
120
122
|
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
121
123
|
"*": "prettier -w -u"
|
|
124
|
+
},
|
|
125
|
+
"resolutions": {
|
|
126
|
+
"prettier": "^2.7.1"
|
|
122
127
|
}
|
|
123
128
|
}
|