vue-codemirror6 0.6.5 → 0.6.8
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 +31 -26
- package/dist/components/CodeMirror.d.ts +11 -11
- 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.map +1 -1
- package/dist/index.es.js +114 -155
- package/dist/index.umd.js +2 -2
- package/package.json +28 -26
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ For Vue 2.7 or later, import vue directly like Vue3.
|
|
|
30
30
|
| ---------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
31
|
| basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
|
|
32
32
|
| minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
|
|
33
|
-
| dark | boolean | Toggle Darkmode.
|
|
33
|
+
| dark | boolean | Toggle Darkmode. |
|
|
34
34
|
| wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
|
|
35
35
|
| tab | boolean | Enables tab indentation. |
|
|
36
36
|
| theme | { [selector: string]: StyleSpec } | Specify the theme. For example, if you use [@codemirror/theme-one-dark](https://github.com/codemirror/theme-one-dark), import `oneDark` and put it in this prop. |
|
|
@@ -170,6 +170,11 @@ export default defineComponent({
|
|
|
170
170
|
/** text */
|
|
171
171
|
const value: Ref<string> = ref('');
|
|
172
172
|
|
|
173
|
+
/** Dark mode **/
|
|
174
|
+
const dark: Ref<boolean> = ref(
|
|
175
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
176
|
+
);
|
|
177
|
+
|
|
173
178
|
/**
|
|
174
179
|
* CodeMirror Language
|
|
175
180
|
*
|
|
@@ -177,12 +182,6 @@ export default defineComponent({
|
|
|
177
182
|
*/
|
|
178
183
|
const lang: LanguageSupport = md();
|
|
179
184
|
|
|
180
|
-
/** Dark mode **/
|
|
181
|
-
const dark = ref(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
182
|
-
|
|
183
|
-
/** When dark value changed, sync vuetify's dark mode */
|
|
184
|
-
watch(dark, v => (vuetify.theme.dark = v));
|
|
185
|
-
|
|
186
185
|
/**
|
|
187
186
|
* Internationalization Config.
|
|
188
187
|
* In this example, the display language to Japanese.
|
|
@@ -221,6 +220,9 @@ export default defineComponent({
|
|
|
221
220
|
'No diagnostics': 'エラーなし',
|
|
222
221
|
});
|
|
223
222
|
|
|
223
|
+
/** When dark value changed, sync vuetify's dark mode */
|
|
224
|
+
watch(dark, v => (vuetify.theme.dark = v));
|
|
225
|
+
|
|
224
226
|
return {
|
|
225
227
|
dark,
|
|
226
228
|
value,
|
|
@@ -234,25 +236,26 @@ export default defineComponent({
|
|
|
234
236
|
|
|
235
237
|
## Methods
|
|
236
238
|
|
|
237
|
-
| Methods | Description
|
|
238
|
-
| ------------------------------------------------------------------- |
|
|
239
|
-
| selection
|
|
240
|
-
|
|
|
241
|
-
|
|
|
242
|
-
|
|
|
243
|
-
|
|
|
244
|
-
|
|
|
245
|
-
|
|
|
246
|
-
|
|
|
247
|
-
|
|
|
248
|
-
|
|
|
249
|
-
|
|
|
250
|
-
|
|
|
251
|
-
|
|
|
252
|
-
|
|
|
253
|
-
|
|
|
254
|
-
|
|
|
255
|
-
|
|
|
239
|
+
| Methods | Description |
|
|
240
|
+
| ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
241
|
+
| selection | Get and set the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
|
|
242
|
+
| cursor | Get and set the cursor location. |
|
|
243
|
+
| state | Get and set [EditorState](https://codemirror.net/docs/ref/#state.EditorState). |
|
|
244
|
+
| focus | Get and set focus. |
|
|
245
|
+
| getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
|
|
246
|
+
| getLine(number: number) | Get the content of line. |
|
|
247
|
+
| lineCount() | Get the number of lines in the editor. |
|
|
248
|
+
| getCursor() | Retrieve one end of the primary selection. |
|
|
249
|
+
| listSelections() | Retrieves a list of all current selections. |
|
|
250
|
+
| getSelection() | Get the currently selected code. |
|
|
251
|
+
| getSelections() | The length of the given array should be the same as the number of active selections. |
|
|
252
|
+
| somethingSelected() | Return true if any text is selected. |
|
|
253
|
+
| replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
|
|
254
|
+
| replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
|
|
255
|
+
| setCursor(position: number) | Set the cursor position. |
|
|
256
|
+
| setSelection(anchor: number, head?: number) | Set a single selection range. |
|
|
257
|
+
| setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
|
|
258
|
+
| extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
|
|
256
259
|
|
|
257
260
|
## Recommendations
|
|
258
261
|
|
|
@@ -294,3 +297,5 @@ const config: UserConfig = {
|
|
|
294
297
|
## LICENSE
|
|
295
298
|
|
|
296
299
|
[MIT](LICENSE)
|
|
300
|
+
|
|
301
|
+
© 2022 by Logue.
|
|
@@ -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: {
|
|
@@ -122,7 +123,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
122
123
|
*/
|
|
123
124
|
linter: {
|
|
124
125
|
type: PropType<LintSource>;
|
|
125
|
-
default:
|
|
126
|
+
default: undefined;
|
|
126
127
|
};
|
|
127
128
|
/** Show Gutter */
|
|
128
129
|
lintGutter: {
|
|
@@ -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,11 +148,9 @@ 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
|
-
focus: () => void;
|
|
152
|
-
hasFocus: () => boolean;
|
|
153
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: {
|
|
@@ -260,7 +261,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
260
261
|
*/
|
|
261
262
|
linter: {
|
|
262
263
|
type: PropType<LintSource>;
|
|
263
|
-
default:
|
|
264
|
+
default: undefined;
|
|
264
265
|
};
|
|
265
266
|
/** Show Gutter */
|
|
266
267
|
lintGutter: {
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,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;;;;;;;;;;;;sBA6JO,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;;IArWvC,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,wBAmaG"}
|
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAGjD,QAAA,MAAM,iBAAiB,
|
|
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
|
@@ -5,35 +5,23 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 0.6.
|
|
8
|
+
* @version 0.6.8
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { isVue2,
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { EditorView, keymap } from "@codemirror/view";
|
|
16
|
-
import { linter, lintGutter } from "@codemirror/lint";
|
|
17
|
-
import { basicSetup, minimalSetup } from "codemirror";
|
|
18
|
-
import { indentWithTab } from "@codemirror/commands";
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return { ...ret, [key]: handler };
|
|
26
|
-
}, {});
|
|
27
|
-
};
|
|
28
|
-
const h = (type, options = {}, chidren) => {
|
|
29
|
-
if (isVue2)
|
|
30
|
-
return h$1(type, options, chidren);
|
|
31
|
-
const { props, domProps, on, ...extraOptions } = options;
|
|
32
|
-
const ons = on ? adaptOnsV3(on) : {};
|
|
33
|
-
return h$1(type, { ...extraOptions, ...props, ...domProps, ...ons }, chidren);
|
|
34
|
-
};
|
|
35
|
-
const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
|
|
36
|
-
var CodeMirror = defineComponent({
|
|
12
|
+
import { isVue2 as V, Vue2 as x, h, defineComponent as B, ref as p, computed as r, toRaw as O, watch as v, onMounted as M, nextTick as R, onUnmounted as j } from "vue-demi";
|
|
13
|
+
import { compact as E, trim as T } from "lodash";
|
|
14
|
+
import { EditorState as g, StateEffect as $, EditorSelection as y } from "@codemirror/state";
|
|
15
|
+
import { EditorView as d, 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 }), {}) : {}, S = (t, i = {}, n) => {
|
|
20
|
+
if (V && parseInt(x.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, w = B({
|
|
37
25
|
name: "CodeMirror",
|
|
38
26
|
model: {
|
|
39
27
|
prop: "modelValue",
|
|
@@ -46,181 +34,152 @@ var CodeMirror = defineComponent({
|
|
|
46
34
|
},
|
|
47
35
|
theme: {
|
|
48
36
|
type: Object,
|
|
49
|
-
default: () => {
|
|
50
|
-
return {};
|
|
51
|
-
}
|
|
37
|
+
default: () => ({})
|
|
52
38
|
},
|
|
53
39
|
dark: {
|
|
54
40
|
type: Boolean,
|
|
55
|
-
default:
|
|
41
|
+
default: !1
|
|
56
42
|
},
|
|
57
43
|
basic: {
|
|
58
44
|
type: Boolean,
|
|
59
|
-
default:
|
|
45
|
+
default: !1
|
|
60
46
|
},
|
|
61
47
|
minimal: {
|
|
62
48
|
type: Boolean,
|
|
63
|
-
default:
|
|
49
|
+
default: !1
|
|
64
50
|
},
|
|
65
51
|
wrap: {
|
|
66
52
|
type: Boolean,
|
|
67
|
-
default:
|
|
53
|
+
default: !1
|
|
68
54
|
},
|
|
69
55
|
tab: {
|
|
70
56
|
type: Boolean,
|
|
71
|
-
default:
|
|
57
|
+
default: !1
|
|
72
58
|
},
|
|
73
59
|
readonly: {
|
|
74
60
|
type: Boolean,
|
|
75
|
-
default:
|
|
61
|
+
default: !1
|
|
76
62
|
},
|
|
77
63
|
editable: {
|
|
78
64
|
type: Boolean,
|
|
79
|
-
default:
|
|
65
|
+
default: !0
|
|
80
66
|
},
|
|
81
67
|
extensions: {
|
|
82
68
|
type: Array,
|
|
83
|
-
default: () =>
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
69
|
+
default: () => []
|
|
86
70
|
},
|
|
87
71
|
phrases: {
|
|
88
72
|
type: Object,
|
|
89
|
-
default: () =>
|
|
73
|
+
default: () => {
|
|
74
|
+
}
|
|
90
75
|
},
|
|
91
76
|
lang: {
|
|
92
77
|
type: Object,
|
|
93
|
-
default: () =>
|
|
78
|
+
default: () => {
|
|
79
|
+
}
|
|
94
80
|
},
|
|
95
81
|
linter: {
|
|
96
82
|
type: Function,
|
|
97
|
-
default:
|
|
83
|
+
default: void 0
|
|
98
84
|
},
|
|
99
85
|
lintGutter: {
|
|
100
86
|
type: Boolean,
|
|
101
|
-
defalt:
|
|
87
|
+
defalt: !1
|
|
102
88
|
}
|
|
103
89
|
},
|
|
104
90
|
emits: ["update:modelValue", "update:view"],
|
|
105
|
-
setup(
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
91
|
+
setup(t, i) {
|
|
92
|
+
const n = p(), s = p(t.modelValue);
|
|
93
|
+
let o;
|
|
94
|
+
const l = r({
|
|
95
|
+
get: () => o.state.selection,
|
|
96
|
+
set: (e) => o.dispatch({ selection: e })
|
|
97
|
+
}), c = r({
|
|
98
|
+
get: () => l.value.main.head || 0,
|
|
99
|
+
set: (e) => o.dispatch({ selection: { anchor: e } })
|
|
100
|
+
}), u = r({
|
|
101
|
+
get: () => o.state,
|
|
102
|
+
set: (e) => o.setState(e)
|
|
103
|
+
}), b = r({
|
|
104
|
+
get: () => o.hasFocus,
|
|
105
|
+
set: (e) => {
|
|
106
|
+
e && o.focus();
|
|
117
107
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
}), m = r(() => E([
|
|
109
|
+
t.basic ? A : void 0,
|
|
110
|
+
t.minimal && !t.basic ? F : void 0,
|
|
111
|
+
d.updateListener.of((e) => f("update:view", e)),
|
|
112
|
+
d.theme(t.theme, { dark: t.dark }),
|
|
113
|
+
t.wrap ? d.lineWrapping : void 0,
|
|
114
|
+
t.tab ? D.of([N]) : void 0,
|
|
115
|
+
t.phrases ? g.phrases.of(t.phrases) : void 0,
|
|
116
|
+
t.readonly ? g.readOnly.of(t.readonly) : void 0,
|
|
117
|
+
t.editable ? d.editable.of(t.editable) : void 0,
|
|
118
|
+
t.lang ? O(t.lang) : void 0,
|
|
119
|
+
t.linter ? G(t.linter) : void 0,
|
|
120
|
+
t.linter && t.lintGutter ? L() : void 0,
|
|
121
|
+
...t.extensions
|
|
122
|
+
])), f = i.emit;
|
|
123
|
+
return v(() => t.modelValue, (e) => {
|
|
124
|
+
if (o.composing)
|
|
125
|
+
return;
|
|
126
|
+
const a = o.state.selection;
|
|
127
|
+
o.dispatch({
|
|
128
|
+
changes: { from: 0, to: o.state.doc.length, insert: e },
|
|
129
|
+
selection: a
|
|
122
130
|
});
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
effects: StateEffect.reconfigure.of(getExtensions())
|
|
131
|
+
}), v(m, (e) => {
|
|
132
|
+
o.dispatch({
|
|
133
|
+
effects: $.reconfigure.of(e)
|
|
127
134
|
});
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
view = new EditorView({
|
|
138
|
-
doc: value,
|
|
139
|
-
extensions: getExtensions(),
|
|
140
|
-
parent: editor.value,
|
|
141
|
-
dispatch: (tr) => {
|
|
142
|
-
view.update([tr]);
|
|
143
|
-
if (tr.changes.empty)
|
|
144
|
-
return;
|
|
145
|
-
emit("update:modelValue", view.state.doc.toString());
|
|
135
|
+
}), M(async () => {
|
|
136
|
+
let e = s.value;
|
|
137
|
+
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 = T(n.value.childNodes[0].innerText)), o = new d({
|
|
138
|
+
doc: e,
|
|
139
|
+
extensions: m.value,
|
|
140
|
+
parent: n.value,
|
|
141
|
+
dispatch: (a) => {
|
|
142
|
+
o.update([a]), !a.changes.empty && f("update:modelValue", o.state.doc.toString());
|
|
146
143
|
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const getSelection = () => view.state.sliceDoc(selection().main.from, selection().main.to);
|
|
176
|
-
const getSelections = () => selection().ranges.map((r) => view.state.sliceDoc(r.from, r.to));
|
|
177
|
-
const somethingSelected = () => selection().ranges.some((r) => !r.empty);
|
|
178
|
-
const replaceRange = (replacement, from, to) => view.dispatch({
|
|
179
|
-
changes: { from, to, insert: replacement }
|
|
180
|
-
});
|
|
181
|
-
const replaceSelection = (replacement) => view.dispatch(view.state.replaceSelection(replacement));
|
|
182
|
-
const setCursor = (position) => cursor.value = position;
|
|
183
|
-
const setSelection = (anchor, head) => view.dispatch({ selection: { anchor, head } });
|
|
184
|
-
const setSelections = (ranges, primary) => view.dispatch({
|
|
185
|
-
selection: EditorSelection.create(ranges, primary)
|
|
186
|
-
});
|
|
187
|
-
const extendSelectionsBy = (f) => view.dispatch({
|
|
188
|
-
selection: EditorSelection.create(selection().ranges.map((r) => r.extend(f(r))))
|
|
189
|
-
});
|
|
190
|
-
const focus = () => view.focus();
|
|
191
|
-
const hasFocus = () => view.hasFocus;
|
|
192
|
-
return {
|
|
193
|
-
context,
|
|
194
|
-
editor,
|
|
195
|
-
cursor,
|
|
196
|
-
selection,
|
|
197
|
-
getRange,
|
|
198
|
-
getLine,
|
|
199
|
-
lineCount,
|
|
200
|
-
getCursor,
|
|
201
|
-
listSelections,
|
|
202
|
-
getSelection,
|
|
203
|
-
getSelections,
|
|
204
|
-
somethingSelected,
|
|
205
|
-
replaceRange,
|
|
206
|
-
replaceSelection,
|
|
207
|
-
setCursor,
|
|
208
|
-
setSelection,
|
|
209
|
-
setSelections,
|
|
210
|
-
extendSelectionsBy,
|
|
211
|
-
focus,
|
|
212
|
-
hasFocus
|
|
144
|
+
}), await R();
|
|
145
|
+
}), j(() => o.destroy()), {
|
|
146
|
+
context: i,
|
|
147
|
+
editor: n,
|
|
148
|
+
cursor: c,
|
|
149
|
+
selection: l,
|
|
150
|
+
state: u,
|
|
151
|
+
focus: b,
|
|
152
|
+
getRange: (e, a) => o.state.sliceDoc(e, a),
|
|
153
|
+
getLine: (e) => o.state.doc.line(e + 1).text,
|
|
154
|
+
lineCount: () => o.state.doc.lines,
|
|
155
|
+
getCursor: () => c.value,
|
|
156
|
+
listSelections: () => o.state.selection.ranges,
|
|
157
|
+
getSelection: () => o.state.sliceDoc(o.state.selection.main.from, o.state.selection.main.to),
|
|
158
|
+
getSelections: () => o.state.selection.ranges.map((e) => o.state.sliceDoc(e.from, e.to)),
|
|
159
|
+
somethingSelected: () => o.state.selection.ranges.some((e) => !e.empty),
|
|
160
|
+
replaceRange: (e, a, C) => o.dispatch({
|
|
161
|
+
changes: { from: a, to: C, insert: e }
|
|
162
|
+
}),
|
|
163
|
+
replaceSelection: (e) => o.dispatch(o.state.replaceSelection(e)),
|
|
164
|
+
setCursor: (e) => c.value = e,
|
|
165
|
+
setSelection: (e, a) => o.dispatch({ selection: { anchor: e, head: a } }),
|
|
166
|
+
setSelections: (e, a) => o.dispatch({
|
|
167
|
+
selection: y.create(e, a)
|
|
168
|
+
}),
|
|
169
|
+
extendSelectionsBy: (e) => o.dispatch({
|
|
170
|
+
selection: y.create(l.value.ranges.map((a) => a.extend(e(a))))
|
|
171
|
+
})
|
|
213
172
|
};
|
|
214
173
|
},
|
|
215
174
|
render() {
|
|
216
|
-
return
|
|
175
|
+
return S("div", {
|
|
217
176
|
ref: "editor",
|
|
218
177
|
class: "vue-codemirror"
|
|
219
|
-
}, this.$slots.default ?
|
|
178
|
+
}, this.$slots.default ? S("aside", { style: "display: none;", "aria-hidden": "true" }, W(this.$slots.default)) : void 0);
|
|
220
179
|
}
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
180
|
+
}), ce = (t) => t.component("CodeMirror", w);
|
|
181
|
+
typeof window < "u" && window.Vue && window.Vue.use(w);
|
|
182
|
+
export {
|
|
183
|
+
w as default,
|
|
184
|
+
ce as install
|
|
185
|
+
};
|
package/dist/index.umd.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 0.6.
|
|
8
|
+
* @version 0.6.8
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function(
|
|
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)}),B=n.computed({get:()=>o.hasFocus,set:e=>{e&&o.focus()}}),v=n.computed(()=>p.compact([t.basic?y.basicSetup:void 0,t.minimal&&!t.basic?y.minimalSetup:void 0,d.EditorView.updateListener.of(e=>w("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])),w=r.emit;return n.watch(()=>t.modelValue,e=>{if(o.composing)return;const s=o.state.selection;o.dispatch({changes:{from:0,to:o.state.doc.length,insert:e},selection:s})}),n.watch(v,e=>{o.dispatch({effects:u.StateEffect.reconfigure.of(e)})}),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:v.value,parent:i.value,dispatch:s=>{o.update([s]),!s.changes.empty&&w("update:modelValue",o.state.doc.toString())}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy()),{context:r,editor:i,cursor:f,selection:l,state:h,focus:B,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,E)=>o.dispatch({changes:{from:s,to:E,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.8",
|
|
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.1",
|
|
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.
|
|
81
|
-
"@codemirror/lang-markdown": "^6.0.
|
|
80
|
+
"@codemirror/lang-javascript": "^6.0.2",
|
|
81
|
+
"@codemirror/lang-markdown": "^6.0.1",
|
|
82
82
|
"@types/lodash": "^4.14.182",
|
|
83
|
-
"@types/node": "^18.
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
85
|
-
"@typescript-eslint/parser": "^5.
|
|
86
|
-
"@vitejs/plugin-vue": "^
|
|
83
|
+
"@types/node": "^18.6.3",
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
85
|
+
"@typescript-eslint/parser": "^5.31.0",
|
|
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.21.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.1.0",
|
|
94
96
|
"eslint-plugin-import": "^2.26.0",
|
|
95
|
-
"eslint-plugin-jsdoc": "^39.3.
|
|
97
|
+
"eslint-plugin-jsdoc": "^39.3.4",
|
|
96
98
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
97
|
-
"eslint-plugin-vue": "^9.
|
|
99
|
+
"eslint-plugin-vue": "^9.3.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,14 +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": "^
|
|
108
|
+
"rollup-plugin-visualizer": "^5.7.1",
|
|
109
|
+
"typescript": "^4.7.4",
|
|
110
|
+
"vite": "^3.0.4",
|
|
109
111
|
"vite-plugin-banner": "^0.3.0",
|
|
110
|
-
"vite-plugin-checker": "^0.4.
|
|
112
|
+
"vite-plugin-checker": "^0.4.9",
|
|
111
113
|
"vue": "^3.2.37",
|
|
112
114
|
"vue-eslint-parser": "^9.0.3",
|
|
113
|
-
"vue-tsc": "^0.
|
|
115
|
+
"vue-tsc": "^0.39.4"
|
|
114
116
|
},
|
|
115
117
|
"husky": {
|
|
116
118
|
"hooks": {
|