vue-codemirror6 0.3.3 → 0.3.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 CHANGED
@@ -19,13 +19,16 @@ When using with Vue2, [@vue/composition-api](https://www.npmjs.com/package/@vue/
19
19
 
20
20
  | Props | Type | Information |
21
21
  | ---------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22
- | dark | boolean | Toggle Darkmode. If you use Vuetify, I recommend that you enter `$vuetify.theme.dark`. |
22
+ | basic | boolean | Use [basic-setup](https://codemirror.net/6/docs/ref/#basic-setup). |
23
+ | dark | boolean | Toggle Darkmode. It can be changed in real time, but the input value will return to the initial value. |
24
+ | wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
25
+ | tab | boolean | Enables tab indentation. |
23
26
  | 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. |
24
27
  | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
25
28
  | editable | boolean | When this is set to false, it is similar to `readonly`, except that the cursor is not displayed like the normal pre tag. |
26
29
  | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
27
30
  | phrases | Record&lt;string, string&gt; | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
28
- | extensions | Extension[] | Includes enhancements to extend CodeMirror. Such as [@codemirror/basic-setup](https://github.com/codemirror/basic-setup). |
31
+ | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
29
32
  | linter | Diagnostic[] | Set Linter. see example <https://codesandbox.io/s/f6nb0?file=/src/index.js> |
30
33
 
31
34
  Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
@@ -121,23 +124,22 @@ When using as a Markdown editor on [Vuetify](https://vuetifyjs.com/).
121
124
  <template>
122
125
  <code-mirror
123
126
  v-model="value"
127
+ basic
128
+ :dark="dark"
124
129
  :lang="lang"
125
130
  :phrases="phreses"
126
- :extensions="extensions"
127
- :dark="$vuetify.theme.dark"
128
131
  />
129
132
  </template>
130
133
 
131
134
  <script lang="ts">
132
- import { ref, type Ref, defineComponent } from 'vue';
135
+ import { ref, defineComponent, type Ref } from 'vue';
133
136
 
134
137
  // Load component
135
138
  import CodeMirror from 'vue-codemirror6';
136
139
 
137
140
  // CodeMirror extensions
138
141
  import type { LanguageSupport } from '@codemirror/language';
139
- import { markdown } from '@codemirror/lang-markdown';
140
- import { basicSetup } from '@codemirror/basic-setup';
142
+ import { markdown as md } from '@codemirror/lang-markdown';
141
143
  import type { Extension } from '@codemirror/state';
142
144
  import type { ViewUpdate } from '@codemirror/view';
143
145
 
@@ -146,6 +148,12 @@ export default defineComponent({
146
148
  CodeMirror,
147
149
  },
148
150
  setup() {
151
+ /**
152
+ * Get Vuetify instance
153
+ * @see {@link https://github.com/logue/vite-vue2-vuetify-ts-starter | vite-vue2-vuetify-ts-starter}
154
+ */
155
+ const vuetify = useVuetify();
156
+
149
157
  /** text */
150
158
  const value: Ref<string> = ref('');
151
159
 
@@ -154,7 +162,13 @@ export default defineComponent({
154
162
  *
155
163
  * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
156
164
  */
157
- const lang: Ref<LanguageSupport> = ref(markdown());
165
+ const lang: Ref<LanguageSupport> = ref(md());
166
+
167
+ /** Dark mode **/
168
+ const dark = ref(window.matchMedia('(prefers-color-scheme: dark)').matches);
169
+
170
+ /** When dark value changed, sync vuetify's dark mode */
171
+ watch(dark, v => (vuetify.theme.dark = v));
158
172
 
159
173
  /**
160
174
  * Internationalization Config.
@@ -193,27 +207,49 @@ export default defineComponent({
193
207
  'No diagnostics': 'エラーなし',
194
208
  });
195
209
 
196
- /**
197
- * CodeMirror Extensions
198
- *
199
- * @see {@link:https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
200
- */
201
- const extensions: Ref<Extension[]> = ref([
202
- /** @see {@link:https://codemirror.net/6/docs/ref/#basic-setup | basic-setup} */
203
- basicSetup,
204
- ]);
205
-
206
210
  return {
211
+ dark,
207
212
  value,
208
213
  lang,
209
214
  phrases,
210
- extensions,
211
215
  };
212
216
  },
213
217
  });
214
218
  </script>
215
219
  ```
216
220
 
221
+ ## Recommendations
222
+
223
+ Since CodeMirror has a relatively large capacity, when using vite, it is recommended to set it to output as a separate file using the [`manualChunks`](https://vitejs.dev/guide/build.html#chunking-strategy) option at build time as shown below.
224
+
225
+ ```ts
226
+ const config: UserConfig = {
227
+ // ...
228
+ build: {
229
+ rollupOptions: {
230
+ output: {
231
+ manualChunks: {
232
+ // ...
233
+ codemirror: [
234
+ // Split CodeMirror code.
235
+ 'vue-codemirror6',
236
+ '@codemirror/state',
237
+ '@codemirror/view',
238
+ '@codemirror/basic-setup',
239
+ // Add the following as needed.
240
+ '@codemirror/lang-html',
241
+ '@codemirror/lang-javascript',
242
+ '@codemirror/lang-markdown',
243
+ ],
244
+ // ...
245
+ },
246
+ },
247
+ },
248
+ },
249
+ // ...
250
+ };
251
+ ```
252
+
217
253
  ## LICENSE
218
254
 
219
255
  [MIT](LICENSE)
@@ -1,14 +1,28 @@
1
- import type { Ref, PropType, SetupContext } from 'vue-demi';
2
- import type { Extension } from '@codemirror/state';
1
+ import { type PropType, type Ref, type SetupContext } from 'vue-demi';
2
+ import { EditorSelection } from '@codemirror/state';
3
+ import type { Extension, Text } from '@codemirror/state';
3
4
  import type { LanguageSupport } from '@codemirror/language';
4
5
  import type { Diagnostic } from '@codemirror/lint';
5
6
  import type { StyleSpec } from 'style-mod';
7
+ /** CodeMirror Component */
6
8
  declare const _default: import("vue-demi").DefineComponent<{
7
9
  /** Model value */
8
10
  modelValue: {
9
- type: StringConstructor;
11
+ type: PropType<string | Text>;
10
12
  default: string;
11
13
  };
14
+ /**
15
+ * Selection
16
+ *
17
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
18
+ */
19
+ selection: {
20
+ type: PropType<EditorSelection | {
21
+ anchor: number;
22
+ head?: number | undefined;
23
+ }>;
24
+ default: () => undefined;
25
+ };
12
26
  /**
13
27
  * Theme
14
28
  *
@@ -18,13 +32,40 @@ declare const _default: import("vue-demi").DefineComponent<{
18
32
  type: PropType<{
19
33
  [selector: string]: StyleSpec;
20
34
  }>;
21
- default: undefined;
35
+ default: () => {};
22
36
  };
23
37
  /** Dark Mode */
24
38
  dark: {
25
39
  type: BooleanConstructor;
26
40
  default: boolean;
27
41
  };
42
+ /**
43
+ * Use Basic Setup
44
+ *
45
+ * @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
46
+ */
47
+ basic: {
48
+ type: BooleanConstructor;
49
+ default: boolean;
50
+ };
51
+ /**
52
+ * Line wrapping
53
+ *
54
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
55
+ */
56
+ wrap: {
57
+ type: BooleanConstructor;
58
+ default: boolean;
59
+ };
60
+ /**
61
+ * Tab handling
62
+ *
63
+ * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
64
+ */
65
+ tab: {
66
+ type: BooleanConstructor;
67
+ default: boolean;
68
+ };
28
69
  /**
29
70
  * Readonly
30
71
  *
@@ -50,7 +91,7 @@ declare const _default: import("vue-demi").DefineComponent<{
50
91
  */
51
92
  extensions: {
52
93
  type: PropType<Extension[]>;
53
- default: undefined;
94
+ default: () => never[];
54
95
  };
55
96
  /**
56
97
  * Language Phreses
@@ -59,7 +100,7 @@ declare const _default: import("vue-demi").DefineComponent<{
59
100
  */
60
101
  phrases: {
61
102
  type: PropType<Record<string, string>>;
62
- default: undefined;
103
+ default: () => undefined;
63
104
  };
64
105
  /**
65
106
  * CodeMirror Language
@@ -68,7 +109,7 @@ declare const _default: import("vue-demi").DefineComponent<{
68
109
  */
69
110
  lang: {
70
111
  type: PropType<LanguageSupport>;
71
- default: undefined;
112
+ default: () => undefined;
72
113
  };
73
114
  /**
74
115
  * CodeMirror Linter
@@ -77,7 +118,7 @@ declare const _default: import("vue-demi").DefineComponent<{
77
118
  */
78
119
  linter: {
79
120
  type: PropType<Diagnostic[]>;
80
- default: undefined;
121
+ default: () => undefined;
81
122
  };
82
123
  }, {
83
124
  context: SetupContext<import("vue-demi").EmitsOptions>;
@@ -85,9 +126,21 @@ declare const _default: import("vue-demi").DefineComponent<{
85
126
  }, 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<{
86
127
  /** Model value */
87
128
  modelValue: {
88
- type: StringConstructor;
129
+ type: PropType<string | Text>;
89
130
  default: string;
90
131
  };
132
+ /**
133
+ * Selection
134
+ *
135
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
136
+ */
137
+ selection: {
138
+ type: PropType<EditorSelection | {
139
+ anchor: number;
140
+ head?: number | undefined;
141
+ }>;
142
+ default: () => undefined;
143
+ };
91
144
  /**
92
145
  * Theme
93
146
  *
@@ -97,13 +150,40 @@ declare const _default: import("vue-demi").DefineComponent<{
97
150
  type: PropType<{
98
151
  [selector: string]: StyleSpec;
99
152
  }>;
100
- default: undefined;
153
+ default: () => {};
101
154
  };
102
155
  /** Dark Mode */
103
156
  dark: {
104
157
  type: BooleanConstructor;
105
158
  default: boolean;
106
159
  };
160
+ /**
161
+ * Use Basic Setup
162
+ *
163
+ * @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
164
+ */
165
+ basic: {
166
+ type: BooleanConstructor;
167
+ default: boolean;
168
+ };
169
+ /**
170
+ * Line wrapping
171
+ *
172
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
173
+ */
174
+ wrap: {
175
+ type: BooleanConstructor;
176
+ default: boolean;
177
+ };
178
+ /**
179
+ * Tab handling
180
+ *
181
+ * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
182
+ */
183
+ tab: {
184
+ type: BooleanConstructor;
185
+ default: boolean;
186
+ };
107
187
  /**
108
188
  * Readonly
109
189
  *
@@ -129,7 +209,7 @@ declare const _default: import("vue-demi").DefineComponent<{
129
209
  */
130
210
  extensions: {
131
211
  type: PropType<Extension[]>;
132
- default: undefined;
212
+ default: () => never[];
133
213
  };
134
214
  /**
135
215
  * Language Phreses
@@ -138,7 +218,7 @@ declare const _default: import("vue-demi").DefineComponent<{
138
218
  */
139
219
  phrases: {
140
220
  type: PropType<Record<string, string>>;
141
- default: undefined;
221
+ default: () => undefined;
142
222
  };
143
223
  /**
144
224
  * CodeMirror Language
@@ -147,7 +227,7 @@ declare const _default: import("vue-demi").DefineComponent<{
147
227
  */
148
228
  lang: {
149
229
  type: PropType<LanguageSupport>;
150
- default: undefined;
230
+ default: () => undefined;
151
231
  };
152
232
  /**
153
233
  * CodeMirror Linter
@@ -156,21 +236,27 @@ declare const _default: import("vue-demi").DefineComponent<{
156
236
  */
157
237
  linter: {
158
238
  type: PropType<Diagnostic[]>;
159
- default: undefined;
239
+ default: () => undefined;
160
240
  };
161
241
  }>>, {
162
242
  readonly: boolean;
163
- modelValue: string;
243
+ modelValue: string | Text;
244
+ selection: EditorSelection | {
245
+ anchor: number;
246
+ head?: number | undefined;
247
+ };
164
248
  theme: {
165
249
  [selector: string]: StyleSpec;
166
250
  };
167
251
  dark: boolean;
252
+ basic: boolean;
253
+ wrap: boolean;
254
+ tab: boolean;
168
255
  editable: boolean;
169
256
  extensions: Extension[];
170
257
  phrases: Record<string, string>;
171
258
  lang: LanguageSupport;
172
259
  linter: Diagnostic[];
173
260
  }>;
174
- /** CodeMirror Component */
175
261
  export default _default;
176
262
  //# sourceMappingURL=CodeMirror.vue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAe,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIzE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;;IAavC,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IApEH,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;;;;;;;;;;AA/EP,2BAA2B;AAC3B,wBA+MG"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAWL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AASjE,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,2BAA2B;;IAWvB,kBAAkB;;;;;IAKlB;;;;OAIG;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IA9GH,kBAAkB;;;;;IAKlB;;;;OAIG;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;gBAlG6B,MAAM;;;;;;;;;;;;;;;;AAtB1C,wBAgQG"}
package/dist/index.d.ts CHANGED
@@ -7,8 +7,6 @@
7
7
  * @see {@link https://github.com/logue/vue-codemirror6}
8
8
  */
9
9
  import CodeMirror from './components/CodeMirror.vue';
10
- import { App } from 'vue-demi';
11
- declare const installCodeMirror: (app: App) => void;
12
- export { CodeMirror, installCodeMirror as install };
13
- export default CodeMirror;
10
+ declare const installCodeMirror: void | ((app: any) => any);
11
+ export { CodeMirror as default, installCodeMirror as install };
14
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAW,GAAG,EAAE,MAAM,UAAU,CAAC;AAIxC,QAAA,MAAM,iBAAiB,QAAS,GAAG,SAElC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC;AACpD,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AAGrD,QAAA,MAAM,iBAAiB,4BAEV,CAAC;AAEd,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
@@ -2,7 +2,7 @@ import type { ViewUpdate } from '@codemirror/view';
2
2
  /** Emit Interface */
3
3
  export default interface CodeMirrorEmitsInterface {
4
4
  /** Model Update */
5
- (e: 'update:modelValue', value: string): void;
5
+ (e: 'update:modelValue', value: string | Text): void;
6
6
  /** CodeMirror ViewUpdate */
7
7
  (e: 'update', value: ViewUpdate): void;
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirrorEmitsInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/CodeMirrorEmitsInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAqB;AACrB,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACxC"}
1
+ {"version":3,"file":"CodeMirrorEmitsInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/CodeMirrorEmitsInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,qBAAqB;AACrB,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,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"}
@@ -1,7 +1,9 @@
1
- import { defineComponent, ref, computed, watch, onMounted, onUnmounted, install } from "vue-demi";
1
+ import { defineComponent, ref, toRefs, computed, toRaw, watch, onMounted, nextTick, onUnmounted, isVue2, install } from "vue-demi";
2
2
  import { EditorState } from "@codemirror/state";
3
- import { EditorView } from "@codemirror/view";
4
- import { merge, compact } from "lodash";
3
+ import { EditorView, keymap } from "@codemirror/view";
4
+ import { basicSetup } from "@codemirror/basic-setup";
5
+ import { indentWithTab } from "@codemirror/commands";
6
+ import { merge, compact, trim } from "lodash";
5
7
  import { openBlock, createElementBlock, withDirectives, createElementVNode, renderSlot, vShow } from "vue";
6
8
  var _export_sfc = (sfc, props) => {
7
9
  const target = sfc.__vccOpts || sfc;
@@ -21,14 +23,32 @@ const _sfc_main = defineComponent({
21
23
  type: String,
22
24
  default: ""
23
25
  },
26
+ selection: {
27
+ type: Object,
28
+ default: () => void 0
29
+ },
24
30
  theme: {
25
31
  type: Object,
26
- default: void 0
32
+ default: () => {
33
+ return {};
34
+ }
27
35
  },
28
36
  dark: {
29
37
  type: Boolean,
30
38
  default: false
31
39
  },
40
+ basic: {
41
+ type: Boolean,
42
+ default: false
43
+ },
44
+ wrap: {
45
+ type: Boolean,
46
+ default: false
47
+ },
48
+ tab: {
49
+ type: Boolean,
50
+ default: false
51
+ },
32
52
  readonly: {
33
53
  type: Boolean,
34
54
  default: false
@@ -39,37 +59,40 @@ const _sfc_main = defineComponent({
39
59
  },
40
60
  extensions: {
41
61
  type: Array,
42
- default: void 0
62
+ default: () => {
63
+ return [];
64
+ }
43
65
  },
44
66
  phrases: {
45
67
  type: Object,
46
- default: void 0
68
+ default: () => void 0
47
69
  },
48
70
  lang: {
49
71
  type: Object,
50
- default: void 0
72
+ default: () => void 0
51
73
  },
52
74
  linter: {
53
75
  type: Array,
54
- default: void 0
76
+ default: () => void 0
55
77
  }
56
78
  },
57
79
  emits: ["update:modelValue", "update"],
58
80
  setup(props, context) {
59
81
  const editor = ref();
60
- const modelValue = ref(props.modelValue);
61
- const dark = ref(props.dark);
82
+ const doc = ref(props.modelValue);
83
+ const { dark } = toRefs(props);
62
84
  const emit = context.emit;
63
- const extensions = computed(() => {
85
+ const exts = computed(() => {
64
86
  const ext = [
65
- EditorView.updateListener.of((update) => {
66
- emit("update", update);
67
- }),
68
- EditorView.theme(props.theme || {}, { dark: dark.value }),
87
+ props.basic ? basicSetup : void 0,
88
+ EditorView.updateListener.of((update) => emit("update", update)),
89
+ EditorView.theme(props.theme, { dark: dark.value }),
90
+ props.wrap ? EditorView.lineWrapping : void 0,
91
+ props.tab ? keymap.of([indentWithTab]) : void 0,
69
92
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
70
- props.lang,
71
93
  props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
72
- props.editable ? EditorView.editable.of(props.editable) : void 0
94
+ props.editable ? EditorView.editable.of(props.editable) : void 0,
95
+ props.lang ? toRaw(props.lang) : void 0
73
96
  ];
74
97
  if (props.linter) {
75
98
  merge(ext, props.linter);
@@ -80,39 +103,43 @@ const _sfc_main = defineComponent({
80
103
  return compact(ext);
81
104
  });
82
105
  let view;
83
- watch(modelValue, (current) => {
106
+ watch(doc, (current) => {
84
107
  if (view.composing) {
85
108
  return;
86
109
  }
87
110
  const previous = view.state.selection;
88
111
  view.setState(EditorState.create({
89
112
  doc: current,
90
- extensions: extensions.value,
113
+ extensions: exts.value,
91
114
  selection: previous
92
115
  }));
93
116
  });
94
117
  watch(dark, () => {
95
118
  view.setState(EditorState.create({
96
- doc: modelValue.value,
97
- extensions: extensions.value
119
+ doc: doc.value,
120
+ extensions: exts.value
98
121
  }));
99
122
  });
100
- onMounted(() => {
101
- const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
123
+ onMounted(async () => {
124
+ if (doc.value == "" && editor.value) {
125
+ doc.value = trim(editor.value.childNodes[0].innerText);
126
+ }
102
127
  view = new EditorView({
103
128
  state: EditorState.create({
104
- doc: value,
105
- extensions: extensions.value
129
+ doc: doc.value,
130
+ selection: props.selection,
131
+ extensions: exts.value
106
132
  }),
107
133
  parent: editor.value,
108
134
  dispatch: (tr) => {
109
135
  view.update([tr]);
110
136
  if (tr.changes.empty)
111
137
  return;
112
- modelValue.value = view.state.doc.toString();
113
- emit("update:modelValue", modelValue.value);
138
+ doc.value = view.state.doc.toString();
139
+ emit("update:modelValue", doc.value);
114
140
  }
115
141
  });
142
+ await nextTick();
116
143
  });
117
144
  onUnmounted(() => view.destroy());
118
145
  return {
@@ -143,8 +170,5 @@ var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]
143
170
  * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
144
171
  * @see {@link https://github.com/logue/vue-codemirror6}
145
172
  */
146
- install();
147
- const installCodeMirror = (app) => {
148
- app.component("CodeMirror", CodeMirror);
149
- };
150
- export { CodeMirror, CodeMirror as default, installCodeMirror as install };
173
+ const installCodeMirror = isVue2 ? (app) => app.component("CodeMirror", CodeMirror) : install();
174
+ export { CodeMirror as default, installCodeMirror as install };
@@ -1,8 +1,8 @@
1
- (function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.lodash,o.Vue))})(this,function(o,t,s,f,m,i){"use strict";var p=(e,u)=>{const d=e.__vccOpts||e;for(const[r,c]of u)d[r]=c;return d};const V=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:void 0},dark:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:void 0},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Array,default:void 0}},emits:["update:modelValue","update"],setup(e,u){const d=t.ref(),r=t.ref(e.modelValue),c=t.ref(e.dark),y=u.emit,h=t.computed(()=>{const a=[f.EditorView.updateListener.of(l=>{y("update",l)}),f.EditorView.theme(e.theme||{},{dark:c.value}),e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?f.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(a,e.linter),e.extensions&&m.merge(a,e.extensions),m.compact(a)});let n;return t.watch(r,a=>{if(n.composing)return;const l=n.state.selection;n.setState(s.EditorState.create({doc:a,extensions:h.value,selection:l}))}),t.watch(c,()=>{n.setState(s.EditorState.create({doc:r.value,extensions:h.value}))}),t.onMounted(()=>{const a=!r.value&&d.value?d.value.childNodes[0].innerText:r.value;n=new f.EditorView({state:s.EditorState.create({doc:a,extensions:h.value}),parent:d.value,dispatch:l=>{n.update([l]),!l.changes.empty&&(r.value=n.state.doc.toString(),y("update:modelValue",r.value))}})}),t.onUnmounted(()=>n.destroy()),{context:u,editor:d}}}),S={ref:"editor",class:"vue-codemirror"};function _(e,u,d,r,c,y){return i.openBlock(),i.createElementBlock("div",S,[i.withDirectives(i.createElementVNode("aside",null,[i.renderSlot(e.$slots,"default")],512),[[i.vShow,!e.context.slots.default]])],512)}var v=p(V,[["render",_]]);/**
1
+ (function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/basic-setup"),require("@codemirror/commands"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/basic-setup","@codemirror/commands","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.basicSetup,o.commands,o.lodash,o.Vue))})(this,function(o,t,s,n,h,S,f,l){"use strict";var V=(e,c)=>{const a=e.__vccOpts||e;for(const[r,u]of c)a[r]=u;return a};const b=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},selection:{type:Object,default:()=>{}},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{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:Array,default:()=>{}}},emits:["update:modelValue","update"],setup(e,c){const a=t.ref(),r=t.ref(e.modelValue),{dark:u}=t.toRefs(e),m=c.emit,y=t.computed(()=>{const i=[e.basic?h.basicSetup:void 0,n.EditorView.updateListener.of(p=>m("update",p)),n.EditorView.theme(e.theme,{dark:u.value}),e.wrap?n.EditorView.lineWrapping:void 0,e.tab?n.keymap.of([S.indentWithTab]):void 0,e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?n.EditorView.editable.of(e.editable):void 0,e.lang?t.toRaw(e.lang):void 0];return e.linter&&f.merge(i,e.linter),e.extensions&&f.merge(i,e.extensions),f.compact(i)});let d;return t.watch(r,i=>{if(d.composing)return;const p=d.state.selection;d.setState(s.EditorState.create({doc:i,extensions:y.value,selection:p}))}),t.watch(u,()=>{d.setState(s.EditorState.create({doc:r.value,extensions:y.value}))}),t.onMounted(async()=>{r.value==""&&a.value&&(r.value=f.trim(a.value.childNodes[0].innerText)),d=new n.EditorView({state:s.EditorState.create({doc:r.value,selection:e.selection,extensions:y.value}),parent:a.value,dispatch:i=>{d.update([i]),!i.changes.empty&&(r.value=d.state.doc.toString(),m("update:modelValue",r.value))}}),await t.nextTick()}),t.onUnmounted(()=>d.destroy()),{context:c,editor:a}}}),w={ref:"editor",class:"vue-codemirror"};function E(e,c,a,r,u,m){return l.openBlock(),l.createElementBlock("div",w,[l.withDirectives(l.createElementVNode("aside",null,[l.renderSlot(e.$slots,"default")],512),[[l.vShow,!e.context.slots.default]])],512)}var v=V(b,[["render",E]]);/**
2
2
  * Vue CodeMirror6 Component
3
3
  *
4
4
  * @license MIT
5
5
  * @author Logue {@link logue@hotmail.co.jp}
6
6
  * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
7
7
  * @see {@link https://github.com/logue/vue-codemirror6}
8
- */t.install();const E=e=>{e.component("CodeMirror",v)};o.CodeMirror=v,o.default=v,o.install=E,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ */const _=t.isVue2?e=>e.component("CodeMirror",v):t.install();o.default=v,o.install=_,Object.defineProperties(o,{__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.3.3",
4
+ "version": "0.3.7",
5
5
  "description": "CodeMirror6 Component for vue3",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -10,7 +10,6 @@
10
10
  "vue-codemirror",
11
11
  "code-editor",
12
12
  "text-editor",
13
- "vue2",
14
13
  "vue3",
15
14
  "web-editor",
16
15
  "vue-plugin",
@@ -33,7 +32,8 @@
33
32
  "url": "https://github.com/logue/vue-codemirror6/issues"
34
33
  },
35
34
  "engines": {
36
- "node": ">=16"
35
+ "node": ">=16.15.0",
36
+ "yarn": ">=1.22.4"
37
37
  },
38
38
  "license": "MIT",
39
39
  "main": "./dist/vue-codemirror6.umd.js",
@@ -55,24 +55,25 @@
55
55
  "sideEffects": false,
56
56
  "scripts": {
57
57
  "dev": "vite",
58
- "clean": "rimraf node_modules/.vite",
58
+ "clean": "rimraf node_modules/.vite && npx vue-demi-fix",
59
59
  "build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
60
+ "build:analyze": "vue-tsc --noEmit && vite build --mode analyze",
61
+ "build:docs": "vite build --config vite.config.docs.ts",
60
62
  "build:clean": "rimraf dist",
61
- "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
63
+ "lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
62
64
  "lint:markup": "vue-tsc --noEmit",
63
- "switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
64
- "switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
65
+ "preview": "vite preview --config vite.config.docs.ts",
65
66
  "prepare": "husky install",
66
67
  "postinstall": "npx vue-demi-fix"
67
68
  },
68
69
  "dependencies": {
69
- "vue-demi": "latest"
70
+ "vue-demi": ">=0.12.5"
70
71
  },
71
72
  "peerDependencies": {
72
- "@codemirror/state": "latest",
73
- "@codemirror/view": "latest",
74
- "@vue/composition-api": "latest",
75
- "vue": "^2.6.14 || ^3.2.33"
73
+ "@codemirror/basic-setup": ">=0.20",
74
+ "@codemirror/state": ">=0.20",
75
+ "@codemirror/view": ">=0.20",
76
+ "vue": "^2.6.14 || ^3.2.36"
76
77
  },
77
78
  "peerDependenciesMeta": {
78
79
  "@vue/composition-api": {
@@ -81,41 +82,38 @@
81
82
  },
82
83
  "devDependencies": {
83
84
  "@codemirror/basic-setup": "^0.20.0",
84
- "@codemirror/lang-markdown": "^0.20.0",
85
- "@codemirror/language": "^0.20.0",
86
- "@codemirror/lint": "^0.20.1",
87
- "@modyqyw/vite-plugin-eslint": "^1.3.0",
85
+ "@codemirror/lang-markdown": "^0.20.1",
88
86
  "@types/lodash": "^4.14.182",
89
- "@types/node": "^17.0.27",
90
- "@typescript-eslint/eslint-plugin": "^5.21.0",
91
- "@typescript-eslint/parser": "^5.21.0",
92
- "@vitejs/plugin-vue": "^2.3.1",
93
- "@vue/eslint-config-typescript": "^10.0.0",
94
- "eslint": "^8.14.0",
87
+ "@types/node": "^17.0.35",
88
+ "@typescript-eslint/eslint-plugin": "^5.26.0",
89
+ "@typescript-eslint/parser": "^5.26.0",
90
+ "@vitejs/plugin-vue": "^2.3.3",
91
+ "@vue/eslint-config-prettier": "^7.0.0",
92
+ "eslint": "^8.16.0",
95
93
  "eslint-config-google": "^0.14.0",
96
94
  "eslint-config-prettier": "^8.5.0",
97
95
  "eslint-import-resolver-alias": "^1.1.2",
98
96
  "eslint-import-resolver-typescript": "^2.7.1",
99
97
  "eslint-plugin-import": "^2.26.0",
100
- "eslint-plugin-prettier": "^4.0.0",
101
- "eslint-plugin-prettier-vue": "^3.1.0",
98
+ "eslint-plugin-jsdoc": "^39.3.2",
102
99
  "eslint-plugin-tsdoc": "^0.2.16",
103
- "eslint-plugin-vue": "^8.7.1",
100
+ "eslint-plugin-vue": "^9.0.1",
104
101
  "eslint-plugin-vuejs-accessibility": "^1.1.1",
105
- "husky": "^7.0.4",
106
- "lint-staged": "^12.4.0",
102
+ "husky": "^8.0.1",
103
+ "lint-staged": "^12.4.2",
107
104
  "lodash": "^4.17.21",
108
105
  "prettier": "^2.6.2",
109
106
  "prettier-plugin-jsdoc": "^0.3.38",
110
107
  "prettier-plugin-md-nocjsp": "^1.2.0",
111
- "prettier-plugin-sort-imports": "^1.6.0",
108
+ "prettier-plugin-sort-imports": "^1.6.1",
112
109
  "rimraf": "^3.0.2",
113
- "typescript": "^4.6.3",
114
- "vite": "^2.9.5",
115
- "vue": "^3.2.33",
116
- "vue-eslint-parser": "^8.3.0",
117
- "vue-template-compiler": "^2.6.14",
118
- "vue-tsc": "^0.34.10"
110
+ "rollup-plugin-visualizer": "^5.6.0",
111
+ "typescript": "^4.7.2",
112
+ "vite": "^2.9.9",
113
+ "vite-plugin-checker": "^0.4.6",
114
+ "vue": "^3.2.36",
115
+ "vue-eslint-parser": "^9.0.2",
116
+ "vue-tsc": "^0.34.16"
119
117
  },
120
118
  "husky": {
121
119
  "hooks": {
@@ -7,21 +7,30 @@
7
7
  <script lang="ts">
8
8
  import {
9
9
  computed,
10
- ref,
11
- watch,
10
+ defineComponent,
11
+ nextTick,
12
12
  onMounted,
13
13
  onUnmounted,
14
- defineComponent,
14
+ ref,
15
+ toRaw,
16
+ toRefs,
17
+ watch,
18
+ type ComputedRef,
19
+ type PropType,
20
+ type Ref,
21
+ type SetupContext,
15
22
  } from 'vue-demi';
16
- import { EditorState } from '@codemirror/state';
17
- import { EditorView } from '@codemirror/view';
18
- import { compact, merge } from 'lodash';
19
23
 
20
- import type { ComputedRef, Ref, PropType, SetupContext } from 'vue-demi';
24
+ import { EditorSelection, EditorState } from '@codemirror/state';
25
+ import { EditorView, keymap } from '@codemirror/view';
26
+ import { basicSetup } from '@codemirror/basic-setup';
27
+ import { indentWithTab } from '@codemirror/commands';
28
+
29
+ import { compact, merge, trim } from 'lodash';
21
30
 
22
31
  import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
23
32
 
24
- import type { Extension, Transaction } from '@codemirror/state';
33
+ import type { Extension, Text, Transaction } from '@codemirror/state';
25
34
  import type { LanguageSupport } from '@codemirror/language';
26
35
  import type { ViewUpdate } from '@codemirror/view';
27
36
  import type { Diagnostic } from '@codemirror/lint';
@@ -40,9 +49,20 @@ export default defineComponent({
40
49
  props: {
41
50
  /** Model value */
42
51
  modelValue: {
43
- type: String,
52
+ type: String as PropType<string | Text>,
44
53
  default: '',
45
54
  },
55
+ /**
56
+ * Selection
57
+ *
58
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
59
+ */
60
+ selection: {
61
+ type: Object as PropType<
62
+ EditorSelection | { anchor: number; head?: number }
63
+ >,
64
+ default: () => undefined,
65
+ },
46
66
  /**
47
67
  * Theme
48
68
  *
@@ -50,13 +70,42 @@ export default defineComponent({
50
70
  */
51
71
  theme: {
52
72
  type: Object as PropType<{ [selector: string]: StyleSpec }>,
53
- default: undefined,
73
+ default: () => {
74
+ return {};
75
+ },
54
76
  },
55
77
  /** Dark Mode */
56
78
  dark: {
57
79
  type: Boolean,
58
80
  default: false,
59
81
  },
82
+ /**
83
+ * Use Basic Setup
84
+ *
85
+ * @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
86
+ */
87
+ basic: {
88
+ type: Boolean,
89
+ default: false,
90
+ },
91
+ /**
92
+ * Line wrapping
93
+ *
94
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
95
+ */
96
+ wrap: {
97
+ type: Boolean,
98
+ default: false,
99
+ },
100
+ /**
101
+ * Tab handling
102
+ *
103
+ * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
104
+ */
105
+ tab: {
106
+ type: Boolean,
107
+ default: false,
108
+ },
60
109
  /**
61
110
  * Readonly
62
111
  *
@@ -82,7 +131,9 @@ export default defineComponent({
82
131
  */
83
132
  extensions: {
84
133
  type: Array as PropType<Extension[]>,
85
- default: undefined,
134
+ default: () => {
135
+ return [];
136
+ },
86
137
  },
87
138
  /**
88
139
  * Language Phreses
@@ -91,7 +142,7 @@ export default defineComponent({
91
142
  */
92
143
  phrases: {
93
144
  type: Object as PropType<Record<string, string>>,
94
- default: undefined,
145
+ default: () => undefined,
95
146
  },
96
147
  /**
97
148
  * CodeMirror Language
@@ -100,7 +151,7 @@ export default defineComponent({
100
151
  */
101
152
  lang: {
102
153
  type: Object as PropType<LanguageSupport>,
103
- default: undefined,
154
+ default: () => undefined,
104
155
  },
105
156
  /**
106
157
  * CodeMirror Linter
@@ -109,47 +160,54 @@ export default defineComponent({
109
160
  */
110
161
  linter: {
111
162
  type: Array as PropType<Diagnostic[]>,
112
- default: undefined,
163
+ default: () => undefined,
113
164
  },
114
165
  },
115
166
  /** Emits */
116
167
  emits: ['update:modelValue', 'update'],
117
168
  /**
118
169
  * Setup
170
+ *
119
171
  * @param props - Props
120
172
  * @param context - Context
121
173
  */
122
174
  setup(props, context: SetupContext) {
123
175
  /** Editor DOM */
124
- const editor: Ref<Element | undefined> = ref<Element>();
176
+ const editor: Ref<Element | undefined> = ref();
125
177
 
126
- /** Model */
127
- const modelValue: Ref<string> = ref(props.modelValue);
178
+ /** Internal value */
179
+ const doc: Ref<string | Text | undefined> = ref(props.modelValue);
128
180
 
129
181
  /** Dark mode */
130
- const dark: Ref<boolean | undefined> = ref(props.dark);
182
+ const { dark } = toRefs(props);
131
183
 
132
184
  /** Emits */
133
185
  const emit = context.emit as CodeMirrorEmitsInterface;
134
186
 
135
187
  /** CodeMirror Extension */
136
- const extensions: ComputedRef<Extension[]> = computed(() => {
188
+ const exts: ComputedRef<Extension[]> = computed(() => {
137
189
  /** Default extension */
138
190
  const ext = [
191
+ // Toggle basic setup
192
+ props.basic ? basicSetup : undefined,
139
193
  // ViewUpdate event listener
140
- EditorView.updateListener.of((update: ViewUpdate) => {
141
- emit('update', update);
142
- }),
194
+ EditorView.updateListener.of((update: ViewUpdate) =>
195
+ emit('update', update)
196
+ ),
143
197
  // Toggle light/dark mode.
144
- EditorView.theme(props.theme || {}, { dark: dark.value }),
198
+ EditorView.theme(props.theme, { dark: dark.value }),
199
+ // Toggle line wrapping
200
+ props.wrap ? EditorView.lineWrapping : undefined,
201
+ // Indent with tab
202
+ props.tab ? keymap.of([indentWithTab]) : undefined,
145
203
  // locale settings
146
204
  props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
147
- // Parser language setting
148
- props.lang,
149
205
  // Readonly option
150
206
  props.readonly ? EditorState.readOnly.of(props.readonly) : undefined,
151
207
  // Editable option
152
208
  props.editable ? EditorView.editable.of(props.editable) : undefined,
209
+ // Lang
210
+ props.lang ? toRaw(props.lang) : undefined,
153
211
  ];
154
212
 
155
213
  if (props.linter) {
@@ -162,19 +220,19 @@ export default defineComponent({
162
220
  merge(ext, props.extensions);
163
221
  }
164
222
 
165
- // console.debug('[CodeMirror.vue] Loaded extensions:', ext, compact(ext));
223
+ // console.debug('[CodeMirror.vue] Loaded extensions:', compact(ext));
166
224
  return compact(ext);
167
225
  });
168
226
 
169
227
  /** CodeMirror Editor View */
170
- let view!: EditorView;
228
+ let view: EditorView;
171
229
 
172
230
  /**
173
231
  * Input value changed
174
232
  *
175
233
  * @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
176
234
  */
177
- watch(modelValue, current => {
235
+ watch(doc, current => {
178
236
  if (view.composing) {
179
237
  // IME fix
180
238
  return;
@@ -185,35 +243,34 @@ export default defineComponent({
185
243
  view.setState(
186
244
  EditorState.create({
187
245
  doc: current,
188
- extensions: extensions.value,
246
+ extensions: exts.value,
189
247
  selection: previous,
190
248
  })
191
249
  );
192
250
  });
193
251
 
194
- /** Toggle Dark mode */
195
252
  watch(dark, () => {
196
253
  view.setState(
197
254
  EditorState.create({
198
- doc: modelValue.value,
199
- extensions: extensions.value,
255
+ doc: doc.value,
256
+ extensions: exts.value,
200
257
  })
201
258
  );
202
259
  });
203
260
 
204
261
  /** When loaded */
205
- onMounted(() => {
206
- /** Initial Value */
207
- const value =
208
- !modelValue.value && editor.value
209
- ? (editor.value.childNodes[0] as HTMLDivElement).innerText
210
- : modelValue.value;
262
+ onMounted(async () => {
263
+ // overwrite initial value
264
+ if (doc.value == '' && editor.value) {
265
+ doc.value = trim((editor.value.childNodes[0] as HTMLElement).innerText);
266
+ }
211
267
 
212
268
  // Register Codemirror
213
269
  view = new EditorView({
214
270
  state: EditorState.create({
215
- doc: value,
216
- extensions: extensions.value,
271
+ doc: doc.value,
272
+ selection: props.selection,
273
+ extensions: exts.value,
217
274
  }),
218
275
  parent: editor.value,
219
276
  dispatch: (tr: Transaction) => {
@@ -221,10 +278,11 @@ export default defineComponent({
221
278
 
222
279
  if (tr.changes.empty) return;
223
280
  // to parent binding
224
- modelValue.value = view.state.doc.toString();
225
- emit('update:modelValue', modelValue.value);
281
+ doc.value = view.state.doc.toString();
282
+ emit('update:modelValue', doc.value);
226
283
  },
227
284
  });
285
+ await nextTick();
228
286
  });
229
287
 
230
288
  /** Destroy */