vue-codemirror6 0.6.2 → 0.6.5

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 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 Vue2, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
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
- - ['codemirror6-bootstrap-theme'](https://github.com/logue/codemirror6-bootstrap-theme)
66
+ - [`codemirror6-bootstrap-theme`](https://github.com/logue/codemirror6-bootstrap-theme)
65
67
 
66
68
  ## Example
67
69
 
@@ -0,0 +1,290 @@
1
+ import { type PropType, type Ref, type SetupContext } from 'vue-demi';
2
+ import { EditorSelection } from '@codemirror/state';
3
+ import type { Extension, SelectionRange, Text } from '@codemirror/state';
4
+ import type { LanguageSupport } from '@codemirror/language';
5
+ import type { ViewUpdate } from '@codemirror/view';
6
+ import type { LintSource } from '@codemirror/lint';
7
+ import type { StyleSpec } from 'style-mod';
8
+ /** Emit Interface */
9
+ export interface CodeMirrorEmitsInterface {
10
+ /** Model Update */
11
+ (e: 'update:modelValue', value: string | Text): void;
12
+ /** CodeMirror ViewUpdate */
13
+ (e: 'update', value: ViewUpdate): void;
14
+ }
15
+ declare const _default: import("vue-demi").DefineComponent<{
16
+ /** Model value */
17
+ modelValue: {
18
+ type: PropType<string | Text>;
19
+ default: string;
20
+ };
21
+ /**
22
+ * Theme
23
+ *
24
+ * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
25
+ */
26
+ theme: {
27
+ type: PropType<{
28
+ [selector: string]: StyleSpec;
29
+ }>;
30
+ default: () => {};
31
+ };
32
+ /** Dark Mode */
33
+ dark: {
34
+ type: BooleanConstructor;
35
+ default: boolean;
36
+ };
37
+ /**
38
+ * Use Basic Setup
39
+ *
40
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
41
+ */
42
+ basic: {
43
+ type: BooleanConstructor;
44
+ default: boolean;
45
+ };
46
+ /**
47
+ * Use Minimal Setup (The basic setting has priority.)
48
+ *
49
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
50
+ */
51
+ minimal: {
52
+ type: BooleanConstructor;
53
+ default: boolean;
54
+ };
55
+ /**
56
+ * Line wrapping
57
+ *
58
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
59
+ */
60
+ wrap: {
61
+ type: BooleanConstructor;
62
+ default: boolean;
63
+ };
64
+ /**
65
+ * Tab handling
66
+ *
67
+ * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
68
+ */
69
+ tab: {
70
+ type: BooleanConstructor;
71
+ default: boolean;
72
+ };
73
+ /**
74
+ * Readonly
75
+ *
76
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
77
+ */
78
+ readonly: {
79
+ type: BooleanConstructor;
80
+ default: boolean;
81
+ };
82
+ /**
83
+ * Editable
84
+ *
85
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
86
+ */
87
+ editable: {
88
+ type: BooleanConstructor;
89
+ default: boolean;
90
+ };
91
+ /**
92
+ * Additional Extension
93
+ *
94
+ * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
95
+ */
96
+ extensions: {
97
+ type: PropType<Extension[]>;
98
+ default: () => never[];
99
+ };
100
+ /**
101
+ * Language Phreses
102
+ *
103
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
104
+ */
105
+ phrases: {
106
+ type: PropType<Record<string, string>>;
107
+ default: () => undefined;
108
+ };
109
+ /**
110
+ * CodeMirror Language
111
+ *
112
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
113
+ */
114
+ lang: {
115
+ type: PropType<LanguageSupport>;
116
+ default: () => undefined;
117
+ };
118
+ /**
119
+ * CodeMirror Linter
120
+ *
121
+ * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
122
+ */
123
+ linter: {
124
+ type: PropType<LintSource>;
125
+ default: () => undefined;
126
+ };
127
+ /** Show Gutter */
128
+ lintGutter: {
129
+ type: BooleanConstructor;
130
+ defalt: boolean;
131
+ };
132
+ }, {
133
+ context: SetupContext<import("vue-demi").EmitsOptions>;
134
+ editor: Ref<Element | undefined>;
135
+ cursor: Ref<number>;
136
+ selection: () => EditorSelection;
137
+ getRange: (from?: number | undefined, to?: number | undefined) => string;
138
+ getLine: (number: number) => string;
139
+ lineCount: () => number;
140
+ getCursor: () => number;
141
+ listSelections: () => readonly SelectionRange[];
142
+ getSelection: () => string;
143
+ getSelections: () => string[];
144
+ somethingSelected: () => boolean;
145
+ replaceRange: (replacement: string | Text, from: number, to: number) => void;
146
+ replaceSelection: (replacement: string | Text) => void;
147
+ setCursor: (position: number) => number;
148
+ setSelection: (anchor: number, head?: number | undefined) => void;
149
+ setSelections: (ranges: readonly SelectionRange[], primary?: number | undefined) => void;
150
+ extendSelectionsBy: (f: Function) => void;
151
+ focus: () => void;
152
+ hasFocus: () => boolean;
153
+ }, 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
+ /** Model value */
155
+ modelValue: {
156
+ type: PropType<string | Text>;
157
+ default: string;
158
+ };
159
+ /**
160
+ * Theme
161
+ *
162
+ * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
163
+ */
164
+ theme: {
165
+ type: PropType<{
166
+ [selector: string]: StyleSpec;
167
+ }>;
168
+ default: () => {};
169
+ };
170
+ /** Dark Mode */
171
+ dark: {
172
+ type: BooleanConstructor;
173
+ default: boolean;
174
+ };
175
+ /**
176
+ * Use Basic Setup
177
+ *
178
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
179
+ */
180
+ basic: {
181
+ type: BooleanConstructor;
182
+ default: boolean;
183
+ };
184
+ /**
185
+ * Use Minimal Setup (The basic setting has priority.)
186
+ *
187
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
188
+ */
189
+ minimal: {
190
+ type: BooleanConstructor;
191
+ default: boolean;
192
+ };
193
+ /**
194
+ * Line wrapping
195
+ *
196
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
197
+ */
198
+ wrap: {
199
+ type: BooleanConstructor;
200
+ default: boolean;
201
+ };
202
+ /**
203
+ * Tab handling
204
+ *
205
+ * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
206
+ */
207
+ tab: {
208
+ type: BooleanConstructor;
209
+ default: boolean;
210
+ };
211
+ /**
212
+ * Readonly
213
+ *
214
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
215
+ */
216
+ readonly: {
217
+ type: BooleanConstructor;
218
+ default: boolean;
219
+ };
220
+ /**
221
+ * Editable
222
+ *
223
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
224
+ */
225
+ editable: {
226
+ type: BooleanConstructor;
227
+ default: boolean;
228
+ };
229
+ /**
230
+ * Additional Extension
231
+ *
232
+ * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
233
+ */
234
+ extensions: {
235
+ type: PropType<Extension[]>;
236
+ default: () => never[];
237
+ };
238
+ /**
239
+ * Language Phreses
240
+ *
241
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
242
+ */
243
+ phrases: {
244
+ type: PropType<Record<string, string>>;
245
+ default: () => undefined;
246
+ };
247
+ /**
248
+ * CodeMirror Language
249
+ *
250
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
251
+ */
252
+ lang: {
253
+ type: PropType<LanguageSupport>;
254
+ default: () => undefined;
255
+ };
256
+ /**
257
+ * CodeMirror Linter
258
+ *
259
+ * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
260
+ */
261
+ linter: {
262
+ type: PropType<LintSource>;
263
+ default: () => undefined;
264
+ };
265
+ /** Show Gutter */
266
+ lintGutter: {
267
+ type: BooleanConstructor;
268
+ defalt: boolean;
269
+ };
270
+ }>>, {
271
+ modelValue: string | Text;
272
+ theme: {
273
+ [selector: string]: StyleSpec;
274
+ };
275
+ dark: boolean;
276
+ basic: boolean;
277
+ minimal: boolean;
278
+ wrap: boolean;
279
+ tab: boolean;
280
+ readonly: boolean;
281
+ editable: boolean;
282
+ extensions: Extension[];
283
+ phrases: Record<string, string>;
284
+ lang: LanguageSupport;
285
+ linter: LintSource;
286
+ lintGutter: boolean;
287
+ }>;
288
+ /** CodeMirror Component */
289
+ export default _default;
290
+ //# sourceMappingURL=CodeMirror.d.ts.map
@@ -0,0 +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;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,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC;;IAaG,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;;;;;;;;;qBAoII,eAAe;sEAUU,MAAM;sBAO5B,MAAM,KAAG,MAAM;qBAGlB,MAAM;qBAEN,MAAM;0BAED,SAAS,cAAc,EAAE;wBAE3B,MAAM;yBAML,MAAM,EAAE;6BAGJ,OAAO;gCAWtB,MAAM,GAAG,IAAI,QACpB,MAAM,MACR,MAAM;oCAW2B,MAAM,GAAG,IAAI;0BAOvB,MAAM;2BAOL,MAAM;4BAS1B,SAAS,cAAc,EAAE;4BAWJ,QAAQ;;oBAUlB,OAAO;;IA5V5B,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;;;;;;;;;;;;;;;;;;;;;;;AA5HtB,2BAA2B;AAC3B,wBAqZG"}
@@ -0,0 +1,15 @@
1
+ interface Options {
2
+ class?: string;
3
+ domProps?: Record<any, any>;
4
+ on?: Record<any, any>;
5
+ props?: Record<any, any>;
6
+ ref?: string;
7
+ style?: string;
8
+ 'aria-hidden'?: string;
9
+ }
10
+ declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) => import("vue-demi").VNode<import("vue-demi").RendererNode, import("vue-demi").RendererElement, {
11
+ [key: string]: any;
12
+ }>;
13
+ declare const slot: (defaultSlots: any) => any;
14
+ export { slot, h as default };
15
+ //# sourceMappingURL=h-demi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAEA,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;;EAWd,CAAC;AAEF,QAAA,MAAM,IAAI,iBAAkB,GAAG,QACoC,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import CodeMirror from './components/CodeMirror';
2
+ declare const installCodeMirror: (app: any) => any;
3
+ export { CodeMirror as default, installCodeMirror as install };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,mBAAiD,CAAC;AAEzE,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,10 +1,21 @@
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.5
9
+ * @see {@link https://github.com/logue/vue-codemirror6}
10
+ */
11
+
1
12
  import { isVue2, 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
21
  return null;
@@ -41,7 +52,7 @@ var CodeMirror = defineComponent({
41
52
  },
42
53
  dark: {
43
54
  type: Boolean,
44
- default: window.matchMedia("(prefers-color-scheme: dark)").matches
55
+ default: false
45
56
  },
46
57
  basic: {
47
58
  type: Boolean,
@@ -83,36 +94,33 @@ var CodeMirror = defineComponent({
83
94
  },
84
95
  linter: {
85
96
  type: Function,
86
- default: void 0
97
+ default: () => void 0
87
98
  },
88
99
  lintGutter: {
89
100
  type: Boolean,
90
101
  defalt: false
91
102
  }
92
103
  },
93
- emits: ["update:modelValue", "update"],
104
+ emits: ["update:modelValue", "update:view"],
94
105
  setup(props, context) {
95
106
  const editor = ref();
96
107
  const doc = ref(props.modelValue);
108
+ let view;
97
109
  const cursor = computed({
98
- get: () => view.state.selection.main.head,
110
+ get: () => view.state.selection.main.head || 0,
99
111
  set: (p) => view.dispatch({ selection: { anchor: p } })
100
112
  });
101
113
  const emit = context.emit;
102
- let view;
103
- watch(doc, (value) => {
114
+ watch(() => props.modelValue, (text) => {
104
115
  if (view.composing) {
105
116
  return;
106
117
  }
118
+ const previous = view.state.selection;
107
119
  view.dispatch({
108
- changes: { from: 0, to: value.length, insert: value },
109
- selection: { anchor: cursor.value }
120
+ changes: { from: 0, to: view.state.doc.length, insert: text },
121
+ selection: previous
110
122
  });
111
123
  });
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
124
  watch(() => props.dark, () => {
117
125
  view.dispatch({
118
126
  effects: StateEffect.reconfigure.of(getExtensions())
@@ -134,8 +142,7 @@ var CodeMirror = defineComponent({
134
142
  view.update([tr]);
135
143
  if (tr.changes.empty)
136
144
  return;
137
- doc.value = view.state.doc.toString();
138
- emit("update:modelValue", doc.value);
145
+ emit("update:modelValue", view.state.doc.toString());
139
146
  }
140
147
  });
141
148
  await nextTick();
@@ -212,13 +219,8 @@ var CodeMirror = defineComponent({
212
219
  }, this.$slots.default ? h("aside", { style: "display: none;", "aria-hidden": "true" }, slot(this.$slots.default)) : void 0);
213
220
  }
214
221
  });
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
222
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
223
+ if (typeof window !== "undefined" && window.Vue) {
224
+ window.Vue.use(CodeMirror);
225
+ }
224
226
  export { CodeMirror as default, installCodeMirror as install };
package/dist/index.umd.js CHANGED
@@ -1,8 +1,12 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.codemirror,r.commands,r.lodash))})(this,function(r,n,f,u,g,p,w,y){"use strict";const V=e=>e?Object.entries(e).reduce((c,[i,s])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...c,[i]:s}),{}):null,S=(e,c={},i)=>{if(n.isVue2)return n.h(e,c,i);const{props:s,domProps:d,on:m,...o}=c,h=m?V(m):{};return n.h(e,{...o,...s,...d,...h},i)},C=e=>typeof e=="function"?e():e;var v=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:window.matchMedia("(prefers-color-scheme: dark)").matches},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"],setup(e,c){const i=n.ref(),s=n.ref(e.modelValue),d=n.computed({get:()=>o.state.selection.main.head,set:t=>o.dispatch({selection:{anchor:t}})}),m=c.emit;let o;n.watch(s,t=>{o.composing||o.dispatch({changes:{from:0,to:t.length,insert:t},selection:{anchor:d.value}})}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:{anchor:d.value}})),n.watch(()=>e.dark,()=>{o.dispatch({effects:f.StateEffect.reconfigure.of(h())})}),n.onMounted(async()=>{let t=s.value;i.value&&i.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=y.trim(i.value.childNodes[0].innerText)),o=new u.EditorView({doc:t,extensions:h(),parent:i.value,dispatch:a=>{o.update([a]),!a.changes.empty&&(s.value=o.state.doc.toString(),m("update:modelValue",s.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>y.compact([e.basic?p.basicSetup:void 0,e.minimal&&!e.basic?p.minimalSetup:void 0,u.EditorView.updateListener.of(a=>m("update",a)),u.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?u.EditorView.lineWrapping:void 0,e.tab?u.keymap.of([w.indentWithTab]):void 0,e.phrases?f.EditorState.phrases.of(e.phrases):void 0,e.readonly?f.EditorState.readOnly.of(e.readonly):void 0,e.editable?u.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]),l=()=>o.state.selection;return{context:c,editor:i,cursor:d,selection:l,getRange:(t,a)=>o.state.sliceDoc(t,a),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>d.value,listSelections:()=>l().ranges,getSelection:()=>o.state.sliceDoc(l().main.from,l().main.to),getSelections:()=>l().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>l().ranges.some(t=>!t.empty),replaceRange:(t,a,b)=>o.dispatch({changes:{from:a,to:b,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>d.value=t,setSelection:(t,a)=>o.dispatch({selection:{anchor:t,head:a}}),setSelections:(t,a)=>o.dispatch({selection:f.EditorSelection.create(t,a)}),extendSelectionsBy:t=>o.dispatch({selection:f.EditorSelection.create(l().ranges.map(a=>a.extend(t(a))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;","aria-hidden":"true"},C(this.$slots.default)):void 0)}});/**
2
- * Vue CodeMirror6 Component
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
- * @author Logue {@link logue@hotmail.co.jp}
6
- * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
8
+ * @version 0.6.5
7
9
  * @see {@link https://github.com/logue/vue-codemirror6}
8
- */const x=e=>e.component("CodeMirror",v);r.default=v,r.install=x,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
10
+ */
11
+
12
+ (function(r,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):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.lodash,r.state,r.view,r.lint,r.codemirror,r.commands))})(this,function(r,n,g,f,c,y,S,w){"use strict";const V=e=>e?Object.entries(e).reduce((s,[a,l])=>(a=a.charAt(0).toUpperCase()+a.slice(1),a=`on${a}`,{...s,[a]:l}),{}):null,v=(e,s={},a)=>{if(n.isVue2)return n.h(e,s,a);const{props:l,domProps:o,on:u,...m}=s,h=u?V(u):{};return n.h(e,{...m,...l,...o,...h},a)},C=e=>typeof e=="function"?e():e;var p=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:()=>{}},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update:view"],setup(e,s){const a=n.ref(),l=n.ref(e.modelValue);let o;const u=n.computed({get:()=>o.state.selection.main.head||0,set:t=>o.dispatch({selection:{anchor:t}})}),m=s.emit;n.watch(()=>e.modelValue,t=>{if(o.composing)return;const i=o.state.selection;o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:i})}),n.watch(()=>e.dark,()=>{o.dispatch({effects:f.StateEffect.reconfigure.of(h())})}),n.onMounted(async()=>{let t=l.value;a.value&&a.value.childNodes[0]&&(l.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=g.trim(a.value.childNodes[0].innerText)),o=new c.EditorView({doc:t,extensions:h(),parent:a.value,dispatch:i=>{o.update([i]),!i.changes.empty&&m("update:modelValue",o.state.doc.toString())}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>g.compact([e.basic?S.basicSetup:void 0,e.minimal&&!e.basic?S.minimalSetup:void 0,c.EditorView.updateListener.of(i=>m("update",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?f.EditorState.phrases.of(e.phrases):void 0,e.readonly?f.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?y.linter(e.linter):void 0,e.linter&&e.lintGutter?y.lintGutter():void 0,...e.extensions]),d=()=>o.state.selection;return{context:s,editor:a,cursor:u,selection:d,getRange:(t,i)=>o.state.sliceDoc(t,i),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>u.value,listSelections:()=>d().ranges,getSelection:()=>o.state.sliceDoc(d().main.from,d().main.to),getSelections:()=>d().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>d().ranges.some(t=>!t.empty),replaceRange:(t,i,b)=>o.dispatch({changes:{from:i,to:b,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>u.value=t,setSelection:(t,i)=>o.dispatch({selection:{anchor:t,head:i}}),setSelections:(t,i)=>o.dispatch({selection:f.EditorSelection.create(t,i)}),extendSelectionsBy:t=>o.dispatch({selection:f.EditorSelection.create(d().ranges.map(i=>i.extend(t(i))))}),focus:()=>o.focus(),hasFocus:()=>o.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",p);typeof window<"u"&&window.Vue&&window.Vue.use(p),r.default=p,r.install=x,Object.defineProperties(r,{__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.2",
4
+ "version": "0.6.5",
5
5
  "description": "CodeMirror6 Component for vue2 and vue3",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -55,7 +55,7 @@
55
55
  "dev": "vite",
56
56
  "clean": "rimraf node_modules/.vite && npx vue-demi-fix",
57
57
  "build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
58
- "build:analyze": "vue-tsc --noEmit && vite build --mode analyze",
58
+ "build:analyze": "vue-tsc --noEmit & vue-tsc --declaration --emitDeclarationOnly & vite build --mode analyze",
59
59
  "build:docs": "vite build --config vite.config.docs.ts",
60
60
  "build:clean": "rimraf dist",
61
61
  "lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
@@ -64,11 +64,11 @@
64
64
  "prepare": "husky install"
65
65
  },
66
66
  "dependencies": {
67
- "codemirror": "^6.0.0",
67
+ "codemirror": "^6.0.1",
68
68
  "vue-demi": "latest"
69
69
  },
70
70
  "peerDependencies": {
71
- "@vue/composition-api": "^1.6.2",
71
+ "@vue/composition-api": "^1.6.3",
72
72
  "vue": "^2.6.14 || ^3.2.37"
73
73
  },
74
74
  "peerDependenciesMeta": {
@@ -77,19 +77,19 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
- "@codemirror/lang-javascript": "^6.0.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.0",
84
- "@typescript-eslint/eslint-plugin": "^5.29.0",
85
- "@typescript-eslint/parser": "^5.29.0",
83
+ "@types/node": "^18.0.1",
84
+ "@typescript-eslint/eslint-plugin": "^5.30.4",
85
+ "@typescript-eslint/parser": "^5.30.4",
86
86
  "@vitejs/plugin-vue": "^2.3.3",
87
87
  "@vue/eslint-config-prettier": "^7.0.0",
88
- "eslint": "^8.18.0",
88
+ "eslint": "^8.19.0",
89
89
  "eslint-config-google": "^0.14.0",
90
90
  "eslint-config-prettier": "^8.5.0",
91
91
  "eslint-import-resolver-alias": "^1.1.2",
92
- "eslint-import-resolver-typescript": "^2.7.1",
92
+ "eslint-import-resolver-typescript": "^3.2.0",
93
93
  "eslint-plugin-html": "^6.2.0",
94
94
  "eslint-plugin-import": "^2.26.0",
95
95
  "eslint-plugin-jsdoc": "^39.3.3",
@@ -99,17 +99,18 @@
99
99
  "eslint-plugin-yaml": "^0.5.0",
100
100
  "eslint4b-prebuilt": "^6.7.2",
101
101
  "husky": "^8.0.1",
102
- "lint-staged": "^13.0.2",
102
+ "lint-staged": "^13.0.3",
103
103
  "lodash": "^4.17.21",
104
104
  "prettier": "^2.7.1",
105
105
  "rimraf": "^3.0.2",
106
106
  "rollup-plugin-visualizer": "^5.6.0",
107
- "typescript": "^4.7.4",
108
- "vite": "^2.9.12",
109
- "vite-plugin-checker": "^0.4.6",
107
+ "typescript": "4.6.*",
108
+ "vite": "^2.9.13",
109
+ "vite-plugin-banner": "^0.3.0",
110
+ "vite-plugin-checker": "^0.4.7",
110
111
  "vue": "^3.2.37",
111
- "vue-eslint-parser": "^9.0.2",
112
- "vue-tsc": "^0.38.1"
112
+ "vue-eslint-parser": "^9.0.3",
113
+ "vue-tsc": "^0.38.2"
113
114
  },
114
115
  "husky": {
115
116
  "hooks": {
@@ -119,5 +120,8 @@
119
120
  "lint-staged": {
120
121
  "*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
121
122
  "*": "prettier -w -u"
123
+ },
124
+ "resolutions": {
125
+ "prettier": "^2.7.1"
122
126
  }
123
127
  }