vue-codemirror6 1.1.0 → 1.1.1

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
@@ -27,25 +27,27 @@ This component can handle bidirectional binding by `v-model` like a general Vue
27
27
 
28
28
  ## Props
29
29
 
30
- | Props | Type | Information |
31
- | ------------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
32
- | basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
33
- | minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
34
- | dark | boolean | Toggle Darkmode. |
35
- | placeholder | string | Add placeholder text when blank |
36
- | wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
37
- | tab | boolean | Enables tab indentation. |
38
- | 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. |
39
- | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
40
- | disabled | boolean | This is the reversed value of the CodeMirror editable. Similar to `readonly`, but setting this value to true disables dragging. |
41
- | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
42
- | 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/> |
43
- | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
44
- | linter | LintSource | Set Linter. Enter a linter (eg `esLint([arbitrary rule])` function for `@codemirror/lang-javascript`, `jsonParseLinter()`function for`@codemirror/json`). See the sources for various language libraries for more information. |
45
- | linterConfig | Object | see <https://codemirror.net/docs/ref/#lint.linter^config> |
46
- | gutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
47
- | gutterConfig | Object | see <https://codemirror.net/docs/ref/#lint.lintGutter^config> |
48
- | tag | string | HTML tags used in the component. (Default is `div` tag.) |
30
+ | Props | Type | Information |
31
+ | -------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
32
+ | basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
33
+ | minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
34
+ | dark | boolean | Toggle Darkmode. |
35
+ | placeholder | string | Add placeholder text when blank |
36
+ | wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
37
+ | tab | boolean | Enables tab indentation. |
38
+ | tab-size | number | Configures the tab size to use in this state. |
39
+ | line-separator | string | Set line break (separetor) char. |
40
+ | 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. |
41
+ | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
42
+ | disabled | boolean | This is the reversed value of the CodeMirror editable. Similar to `readonly`, but setting this value to true disables dragging. |
43
+ | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
44
+ | 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/> |
45
+ | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
46
+ | linter | LintSource | Set Linter. Enter a linter (eg `esLint([arbitrary rule])` function for `@codemirror/lang-javascript`, `jsonParseLinter()`function for`@codemirror/json`). See the sources for various language libraries for more information. |
47
+ | linterConfig | Object | see <https://codemirror.net/docs/ref/#lint.linter^config> |
48
+ | gutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
49
+ | gutterConfig | Object | see <https://codemirror.net/docs/ref/#lint.lintGutter^config> |
50
+ | tag | string | HTML tags used in the component. (Default is `div` tag.) |
49
51
 
50
52
  ⚠ Notice: `lang` and `linter` can also be set together in `extensions`. These are separated for compatibility with previous versions of CodeMirror settings and for typing props.
51
53
 
@@ -1,11 +1,11 @@
1
- import { type ObjectEmitsOptions, type PropType, type Ref, type SetupContext, type WritableComputedRef } from 'vue-demi';
1
+ import { type ComputedRef, type ObjectEmitsOptions, type PropType, type Ref, type SetupContext, type WritableComputedRef } from 'vue-demi';
2
2
  import { EditorSelection, EditorState } from '@codemirror/state';
3
3
  import { EditorView } from '@codemirror/view';
4
4
  import type { Extension, SelectionRange, Text } from '@codemirror/state';
5
5
  import type { LanguageSupport } from '@codemirror/language';
6
- import type { ViewUpdate } from '@codemirror/view';
7
6
  import type { LintSource } from '@codemirror/lint';
8
7
  import type { StyleSpec } from 'style-mod';
8
+ import type { ViewUpdate } from '@codemirror/view';
9
9
  /** Emit Interface */
10
10
  export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
11
11
  /** Model Update */
@@ -22,8 +22,6 @@ export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
22
22
  }): void;
23
23
  /** onChange (same as update:modelValue) */
24
24
  (e: 'change', value: string | Text): void;
25
- /** CodeMirror linter active diagnostic aount */
26
- (e: 'diagnosticCount', value: number): void;
27
25
  }
28
26
  /** CodeMirror Component */
29
27
  declare const _default: import("vue-demi").DefineComponent<{
@@ -35,13 +33,13 @@ declare const _default: import("vue-demi").DefineComponent<{
35
33
  /**
36
34
  * Theme
37
35
  *
38
- * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
36
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
39
37
  */
40
38
  theme: {
41
39
  type: PropType<{
42
40
  [selector: string]: StyleSpec;
43
41
  }>;
44
- default: () => {};
42
+ default: () => void;
45
43
  };
46
44
  /** Dark Mode */
47
45
  dark: {
@@ -51,7 +49,7 @@ declare const _default: import("vue-demi").DefineComponent<{
51
49
  /**
52
50
  * Use Basic Setup
53
51
  *
54
- * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
52
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
55
53
  */
56
54
  basic: {
57
55
  type: BooleanConstructor;
@@ -60,7 +58,7 @@ declare const _default: import("vue-demi").DefineComponent<{
60
58
  /**
61
59
  * Use Minimal Setup (The basic setting has priority.)
62
60
  *
63
- * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
61
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
64
62
  */
65
63
  minimal: {
66
64
  type: BooleanConstructor;
@@ -68,9 +66,11 @@ declare const _default: import("vue-demi").DefineComponent<{
68
66
  };
69
67
  /**
70
68
  * Placeholder
69
+ *
70
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
71
71
  */
72
72
  placeholder: {
73
- type: StringConstructor;
73
+ type: PropType<string | HTMLElement>;
74
74
  default: undefined;
75
75
  };
76
76
  /**
@@ -78,7 +78,7 @@ declare const _default: import("vue-demi").DefineComponent<{
78
78
  *
79
79
  * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
80
80
  *
81
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
81
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
82
82
  */
83
83
  wrap: {
84
84
  type: BooleanConstructor;
@@ -87,16 +87,34 @@ declare const _default: import("vue-demi").DefineComponent<{
87
87
  /**
88
88
  * Allow tab key indent.
89
89
  *
90
- * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
90
+ * @see {@link https://codemirror.net/examples/tab/}
91
91
  */
92
92
  tab: {
93
93
  type: BooleanConstructor;
94
94
  default: boolean;
95
95
  };
96
+ /**
97
+ * Tab size
98
+ *
99
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
100
+ */
101
+ tabSize: {
102
+ type: NumberConstructor;
103
+ default: undefined;
104
+ };
105
+ /**
106
+ * Set line break (separetor) char.
107
+ *
108
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
109
+ */
110
+ lineSeparator: {
111
+ type: StringConstructor;
112
+ default: undefined;
113
+ };
96
114
  /**
97
115
  * Readonly
98
116
  *
99
- * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
117
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
100
118
  */
101
119
  readonly: {
102
120
  type: BooleanConstructor;
@@ -108,7 +126,7 @@ declare const _default: import("vue-demi").DefineComponent<{
108
126
  * This is the reversed value of the CodeMirror editable.
109
127
  * Similar to `readonly`, but setting this value to true disables dragging.
110
128
  *
111
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
129
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
112
130
  */
113
131
  disabled: {
114
132
  type: BooleanConstructor;
@@ -117,7 +135,7 @@ declare const _default: import("vue-demi").DefineComponent<{
117
135
  /**
118
136
  * Additional Extension
119
137
  *
120
- * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
138
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
121
139
  */
122
140
  extensions: {
123
141
  type: PropType<Extension[]>;
@@ -126,7 +144,7 @@ declare const _default: import("vue-demi").DefineComponent<{
126
144
  /**
127
145
  * Language Phreses
128
146
  *
129
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
147
+ * @see {@link https://codemirror.net/examples/translate/}
130
148
  */
131
149
  phrases: {
132
150
  type: PropType<Record<string, string>>;
@@ -135,7 +153,7 @@ declare const _default: import("vue-demi").DefineComponent<{
135
153
  /**
136
154
  * CodeMirror Language
137
155
  *
138
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
156
+ * @see {@link https://codemirror.net/docs/ref/#language}
139
157
  */
140
158
  lang: {
141
159
  type: PropType<LanguageSupport>;
@@ -144,7 +162,7 @@ declare const _default: import("vue-demi").DefineComponent<{
144
162
  /**
145
163
  * CodeMirror Linter
146
164
  *
147
- * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
165
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
148
166
  */
149
167
  linter: {
150
168
  type: PropType<LintSource>;
@@ -164,6 +182,8 @@ declare const _default: import("vue-demi").DefineComponent<{
164
182
  *
165
183
  * An area to 🔴 the lines with errors will be displayed.
166
184
  * This feature is not enabled if `linter` is not specified.
185
+ *
186
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
167
187
  */
168
188
  gutter: {
169
189
  type: BooleanConstructor;
@@ -192,6 +212,8 @@ declare const _default: import("vue-demi").DefineComponent<{
192
212
  selection: WritableComputedRef<EditorSelection>;
193
213
  state: WritableComputedRef<EditorState>;
194
214
  focus: WritableComputedRef<boolean>;
215
+ length: ComputedRef<number>;
216
+ lint: () => void;
195
217
  getRange: (from?: number, to?: number) => string;
196
218
  getLine: (number: number) => string;
197
219
  lineCount: () => number;
@@ -206,7 +228,7 @@ declare const _default: import("vue-demi").DefineComponent<{
206
228
  setSelection: (anchor: number, head?: number) => void;
207
229
  setSelections: (ranges: readonly SelectionRange[], primary?: number) => void;
208
230
  extendSelectionsBy: (f: Function) => void;
209
- }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, CodeMirrorEmitsOptions, "update:modelValue" | "update" | "focus" | "ready" | "diagnosticCount" | "changed", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
231
+ }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, CodeMirrorEmitsOptions, "update:modelValue" | "update" | "focus" | "ready" | "change", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
210
232
  /** Model value */
211
233
  modelValue: {
212
234
  type: PropType<string | Text>;
@@ -215,13 +237,13 @@ declare const _default: import("vue-demi").DefineComponent<{
215
237
  /**
216
238
  * Theme
217
239
  *
218
- * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
240
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
219
241
  */
220
242
  theme: {
221
243
  type: PropType<{
222
244
  [selector: string]: StyleSpec;
223
245
  }>;
224
- default: () => {};
246
+ default: () => void;
225
247
  };
226
248
  /** Dark Mode */
227
249
  dark: {
@@ -231,7 +253,7 @@ declare const _default: import("vue-demi").DefineComponent<{
231
253
  /**
232
254
  * Use Basic Setup
233
255
  *
234
- * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
256
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
235
257
  */
236
258
  basic: {
237
259
  type: BooleanConstructor;
@@ -240,7 +262,7 @@ declare const _default: import("vue-demi").DefineComponent<{
240
262
  /**
241
263
  * Use Minimal Setup (The basic setting has priority.)
242
264
  *
243
- * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
265
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
244
266
  */
245
267
  minimal: {
246
268
  type: BooleanConstructor;
@@ -248,9 +270,11 @@ declare const _default: import("vue-demi").DefineComponent<{
248
270
  };
249
271
  /**
250
272
  * Placeholder
273
+ *
274
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
251
275
  */
252
276
  placeholder: {
253
- type: StringConstructor;
277
+ type: PropType<string | HTMLElement>;
254
278
  default: undefined;
255
279
  };
256
280
  /**
@@ -258,7 +282,7 @@ declare const _default: import("vue-demi").DefineComponent<{
258
282
  *
259
283
  * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
260
284
  *
261
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
285
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
262
286
  */
263
287
  wrap: {
264
288
  type: BooleanConstructor;
@@ -267,16 +291,34 @@ declare const _default: import("vue-demi").DefineComponent<{
267
291
  /**
268
292
  * Allow tab key indent.
269
293
  *
270
- * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
294
+ * @see {@link https://codemirror.net/examples/tab/}
271
295
  */
272
296
  tab: {
273
297
  type: BooleanConstructor;
274
298
  default: boolean;
275
299
  };
300
+ /**
301
+ * Tab size
302
+ *
303
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
304
+ */
305
+ tabSize: {
306
+ type: NumberConstructor;
307
+ default: undefined;
308
+ };
309
+ /**
310
+ * Set line break (separetor) char.
311
+ *
312
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
313
+ */
314
+ lineSeparator: {
315
+ type: StringConstructor;
316
+ default: undefined;
317
+ };
276
318
  /**
277
319
  * Readonly
278
320
  *
279
- * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
321
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
280
322
  */
281
323
  readonly: {
282
324
  type: BooleanConstructor;
@@ -288,7 +330,7 @@ declare const _default: import("vue-demi").DefineComponent<{
288
330
  * This is the reversed value of the CodeMirror editable.
289
331
  * Similar to `readonly`, but setting this value to true disables dragging.
290
332
  *
291
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
333
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
292
334
  */
293
335
  disabled: {
294
336
  type: BooleanConstructor;
@@ -297,7 +339,7 @@ declare const _default: import("vue-demi").DefineComponent<{
297
339
  /**
298
340
  * Additional Extension
299
341
  *
300
- * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
342
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
301
343
  */
302
344
  extensions: {
303
345
  type: PropType<Extension[]>;
@@ -306,7 +348,7 @@ declare const _default: import("vue-demi").DefineComponent<{
306
348
  /**
307
349
  * Language Phreses
308
350
  *
309
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
351
+ * @see {@link https://codemirror.net/examples/translate/}
310
352
  */
311
353
  phrases: {
312
354
  type: PropType<Record<string, string>>;
@@ -315,7 +357,7 @@ declare const _default: import("vue-demi").DefineComponent<{
315
357
  /**
316
358
  * CodeMirror Language
317
359
  *
318
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
360
+ * @see {@link https://codemirror.net/docs/ref/#language}
319
361
  */
320
362
  lang: {
321
363
  type: PropType<LanguageSupport>;
@@ -324,7 +366,7 @@ declare const _default: import("vue-demi").DefineComponent<{
324
366
  /**
325
367
  * CodeMirror Linter
326
368
  *
327
- * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
369
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
328
370
  */
329
371
  linter: {
330
372
  type: PropType<LintSource>;
@@ -344,6 +386,8 @@ declare const _default: import("vue-demi").DefineComponent<{
344
386
  *
345
387
  * An area to 🔴 the lines with errors will be displayed.
346
388
  * This feature is not enabled if `linter` is not specified.
389
+ *
390
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
347
391
  */
348
392
  gutter: {
349
393
  type: BooleanConstructor;
@@ -375,9 +419,11 @@ declare const _default: import("vue-demi").DefineComponent<{
375
419
  dark: boolean;
376
420
  basic: boolean;
377
421
  minimal: boolean;
378
- placeholder: string;
422
+ placeholder: string | HTMLElement;
379
423
  wrap: boolean;
380
424
  tab: boolean;
425
+ tabSize: number;
426
+ lineSeparator: string;
381
427
  readonly: boolean;
382
428
  disabled: boolean;
383
429
  extensions: Extension[];
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,kBAAkB,EACvB,KAAK,QAAQ,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co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.0
8
+ * @version 1.1.1
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
12
  import { isVue2, Vue2, h as h$1, defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
13
13
  import { compact, trim } from 'lodash';
14
+ import { basicSetup, minimalSetup } from 'codemirror';
14
15
  import { EditorState, StateEffect, EditorSelection } from '@codemirror/state';
15
16
  import { EditorView, keymap, placeholder } from '@codemirror/view';
16
- import { linter, lintGutter, diagnosticCount } from '@codemirror/lint';
17
- import { basicSetup, minimalSetup } from 'codemirror';
18
17
  import { indentWithTab } from '@codemirror/commands';
18
+ import { linter, lintGutter, forceLinting } from '@codemirror/lint';
19
19
 
20
20
  const adaptOnsV3 = (ons) => {
21
21
  if (!ons)
@@ -54,7 +54,6 @@ const CodeMirror = defineComponent({
54
54
  theme: {
55
55
  type: Object,
56
56
  default: () => {
57
- return {};
58
57
  }
59
58
  },
60
59
  dark: {
@@ -81,6 +80,14 @@ const CodeMirror = defineComponent({
81
80
  type: Boolean,
82
81
  default: false
83
82
  },
83
+ tabSize: {
84
+ type: Number,
85
+ default: void 0
86
+ },
87
+ lineSeparator: {
88
+ type: String,
89
+ default: void 0
90
+ },
84
91
  readonly: {
85
92
  type: Boolean,
86
93
  default: false
@@ -126,14 +133,7 @@ const CodeMirror = defineComponent({
126
133
  default: "div"
127
134
  }
128
135
  },
129
- emits: [
130
- "update:modelValue",
131
- "update",
132
- "ready",
133
- "focus",
134
- "changed",
135
- "diagnosticCount"
136
- ],
136
+ emits: ["update:modelValue", "update", "ready", "focus", "change"],
137
137
  setup(props, context) {
138
138
  const editor = ref();
139
139
  const doc = ref(props.modelValue);
@@ -142,14 +142,14 @@ const CodeMirror = defineComponent({
142
142
  get: () => view.value.state.selection,
143
143
  set: (s) => view.value.dispatch({ selection: s })
144
144
  });
145
- const cursor = computed({
146
- get: () => selection.value.main.head || 0,
147
- set: (a) => view.value.dispatch({ selection: { anchor: a } })
148
- });
149
145
  const state = computed({
150
146
  get: () => view.value.state,
151
147
  set: (s) => view.value.setState(s)
152
148
  });
149
+ const cursor = computed({
150
+ get: () => view.value.state.selection.main.head || 0,
151
+ set: (a) => view.value.dispatch({ selection: { anchor: a } })
152
+ });
153
153
  const focus = computed({
154
154
  get: () => view.value.hasFocus,
155
155
  set: (f) => {
@@ -158,6 +158,9 @@ const CodeMirror = defineComponent({
158
158
  }
159
159
  }
160
160
  });
161
+ const length = computed(
162
+ () => view.value.state.doc.length
163
+ );
161
164
  const extensions = computed(
162
165
  () => compact([
163
166
  props.basic ? basicSetup : void 0,
@@ -168,9 +171,11 @@ const CodeMirror = defineComponent({
168
171
  EditorView.theme(props.theme, { dark: props.dark }),
169
172
  props.wrap ? EditorView.lineWrapping : void 0,
170
173
  props.tab ? keymap.of([indentWithTab]) : void 0,
174
+ props.tabSize ? EditorState.tabSize.of(props.tabSize) : void 0,
171
175
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
172
176
  EditorState.readOnly.of(props.readonly),
173
177
  EditorView.editable.of(!props.disabled),
178
+ props.lineSeparator ? EditorState.lineSeparator.of(props.lineSeparator) : void 0,
174
179
  props.lang ? props.lang : void 0,
175
180
  props.linter ? linter(props.linter, props.linterConfig) : void 0,
176
181
  props.linter && props.gutter ? lintGutter(props.gutterConfig) : void 0,
@@ -181,16 +186,12 @@ const CodeMirror = defineComponent({
181
186
  watch(
182
187
  () => props.modelValue,
183
188
  (value) => {
184
- if (!view.value || view.value.composing) {
189
+ if (view.value.composing) {
185
190
  return;
186
191
  }
187
- const current = view.value.state;
188
- if (props.linter) {
189
- context.emit("diagnosticCount", diagnosticCount(current));
190
- }
191
192
  view.value.dispatch({
192
- changes: { from: 0, to: current.doc.length, insert: value },
193
- selection: current.selection,
193
+ changes: { from: 0, to: view.value.state.doc.length, insert: value },
194
+ selection: view.value.state.selection,
194
195
  scrollIntoView: true
195
196
  });
196
197
  },
@@ -219,7 +220,7 @@ const CodeMirror = defineComponent({
219
220
  return;
220
221
  const v = view.value.state.doc.toString();
221
222
  context.emit("update:modelValue", v);
222
- context.emit("changed", v);
223
+ context.emit("change", v);
223
224
  }
224
225
  });
225
226
  await nextTick();
@@ -232,6 +233,7 @@ const CodeMirror = defineComponent({
232
233
  onUnmounted(() => {
233
234
  view.value.destroy();
234
235
  });
236
+ const lint = () => forceLinting(view.value);
235
237
  const getRange = (from, to) => view.value.state.sliceDoc(from, to);
236
238
  const getLine = (number) => view.value.state.doc.line(number + 1).text;
237
239
  const lineCount = () => view.value.state.doc.lines;
@@ -268,6 +270,8 @@ const CodeMirror = defineComponent({
268
270
  selection,
269
271
  state,
270
272
  focus,
273
+ length,
274
+ lint,
271
275
  getRange,
272
276
  getLine,
273
277
  lineCount,
@@ -301,8 +305,8 @@ const CodeMirror = defineComponent({
301
305
  });
302
306
 
303
307
  const meta = {
304
- version: "1.1.0",
305
- date: "2022-10-31T12:33:21.284Z"
308
+ version: "1.1.1",
309
+ date: "2022-11-07T00:40:00.830Z"
306
310
  };
307
311
 
308
312
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -5,11 +5,11 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.0
8
+ * @version 1.1.1
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemirror, commands) {
12
+ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, commands, lint) {
13
13
  'use strict';
14
14
 
15
15
  const adaptOnsV3 = (ons) => {
@@ -49,7 +49,6 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
49
49
  theme: {
50
50
  type: Object,
51
51
  default: () => {
52
- return {};
53
52
  }
54
53
  },
55
54
  dark: {
@@ -76,6 +75,14 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
76
75
  type: Boolean,
77
76
  default: false
78
77
  },
78
+ tabSize: {
79
+ type: Number,
80
+ default: void 0
81
+ },
82
+ lineSeparator: {
83
+ type: String,
84
+ default: void 0
85
+ },
79
86
  readonly: {
80
87
  type: Boolean,
81
88
  default: false
@@ -121,14 +128,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
121
128
  default: "div"
122
129
  }
123
130
  },
124
- emits: [
125
- "update:modelValue",
126
- "update",
127
- "ready",
128
- "focus",
129
- "changed",
130
- "diagnosticCount"
131
- ],
131
+ emits: ["update:modelValue", "update", "ready", "focus", "change"],
132
132
  setup(props, context) {
133
133
  const editor = vueDemi.ref();
134
134
  const doc = vueDemi.ref(props.modelValue);
@@ -137,14 +137,14 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
137
137
  get: () => view$1.value.state.selection,
138
138
  set: (s) => view$1.value.dispatch({ selection: s })
139
139
  });
140
- const cursor = vueDemi.computed({
141
- get: () => selection.value.main.head || 0,
142
- set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
143
- });
144
140
  const state$1 = vueDemi.computed({
145
141
  get: () => view$1.value.state,
146
142
  set: (s) => view$1.value.setState(s)
147
143
  });
144
+ const cursor = vueDemi.computed({
145
+ get: () => view$1.value.state.selection.main.head || 0,
146
+ set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
147
+ });
148
148
  const focus = vueDemi.computed({
149
149
  get: () => view$1.value.hasFocus,
150
150
  set: (f) => {
@@ -153,6 +153,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
153
153
  }
154
154
  }
155
155
  });
156
+ const length = vueDemi.computed(
157
+ () => view$1.value.state.doc.length
158
+ );
156
159
  const extensions = vueDemi.computed(
157
160
  () => lodash.compact([
158
161
  props.basic ? codemirror.basicSetup : void 0,
@@ -163,9 +166,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
163
166
  view.EditorView.theme(props.theme, { dark: props.dark }),
164
167
  props.wrap ? view.EditorView.lineWrapping : void 0,
165
168
  props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
169
+ props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
166
170
  props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
167
171
  state.EditorState.readOnly.of(props.readonly),
168
172
  view.EditorView.editable.of(!props.disabled),
173
+ props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
169
174
  props.lang ? props.lang : void 0,
170
175
  props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
171
176
  props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
@@ -176,16 +181,12 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
176
181
  vueDemi.watch(
177
182
  () => props.modelValue,
178
183
  (value) => {
179
- if (!view$1.value || view$1.value.composing) {
184
+ if (view$1.value.composing) {
180
185
  return;
181
186
  }
182
- const current = view$1.value.state;
183
- if (props.linter) {
184
- context.emit("diagnosticCount", lint.diagnosticCount(current));
185
- }
186
187
  view$1.value.dispatch({
187
- changes: { from: 0, to: current.doc.length, insert: value },
188
- selection: current.selection,
188
+ changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
189
+ selection: view$1.value.state.selection,
189
190
  scrollIntoView: true
190
191
  });
191
192
  },
@@ -214,7 +215,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
214
215
  return;
215
216
  const v = view$1.value.state.doc.toString();
216
217
  context.emit("update:modelValue", v);
217
- context.emit("changed", v);
218
+ context.emit("change", v);
218
219
  }
219
220
  });
220
221
  await vueDemi.nextTick();
@@ -227,6 +228,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
227
228
  vueDemi.onUnmounted(() => {
228
229
  view$1.value.destroy();
229
230
  });
231
+ const lint$1 = () => lint.forceLinting(view$1.value);
230
232
  const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
231
233
  const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
232
234
  const lineCount = () => view$1.value.state.doc.lines;
@@ -263,6 +265,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
263
265
  selection,
264
266
  state: state$1,
265
267
  focus,
268
+ length,
269
+ lint: lint$1,
266
270
  getRange,
267
271
  getLine,
268
272
  lineCount,
@@ -296,8 +300,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
296
300
  });
297
301
 
298
302
  const meta = {
299
- version: "1.1.0",
300
- date: "2022-10-31T12:33:21.284Z"
303
+ version: "1.1.1",
304
+ date: "2022-11-07T00:40:00.830Z"
301
305
  };
302
306
 
303
307
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -313,4 +317,4 @@ var CodeMirror = (function (exports, vueDemi, lodash, state, view, lint, codemir
313
317
 
314
318
  return exports;
315
319
 
316
- })({}, VueDemi, lodash, state, view, lint, codemirror, commands);
320
+ })({}, VueDemi, lodash, codemirror, state, view, commands, lint);
package/dist/index.umd.js CHANGED
@@ -5,15 +5,15 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.0
8
+ * @version 1.1.1
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
12
  (function (global, factory) {
13
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/lint'), require('codemirror'), require('@codemirror/commands')) :
14
- typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', '@codemirror/state', '@codemirror/view', '@codemirror/lint', 'codemirror', '@codemirror/commands'], factory) :
15
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.lodash, global.state, global.view, global.lint, global.codemirror, global.commands));
16
- })(this, (function (exports, vueDemi, lodash, state, view, lint, codemirror, commands) { 'use strict';
13
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash'), require('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
14
+ typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
15
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.lodash, global.codemirror, global.state, global.view, global.commands, global.lint));
16
+ })(this, (function (exports, vueDemi, lodash, codemirror, state, view, commands, lint) { 'use strict';
17
17
 
18
18
  const adaptOnsV3 = (ons) => {
19
19
  if (!ons)
@@ -52,7 +52,6 @@
52
52
  theme: {
53
53
  type: Object,
54
54
  default: () => {
55
- return {};
56
55
  }
57
56
  },
58
57
  dark: {
@@ -79,6 +78,14 @@
79
78
  type: Boolean,
80
79
  default: false
81
80
  },
81
+ tabSize: {
82
+ type: Number,
83
+ default: void 0
84
+ },
85
+ lineSeparator: {
86
+ type: String,
87
+ default: void 0
88
+ },
82
89
  readonly: {
83
90
  type: Boolean,
84
91
  default: false
@@ -124,14 +131,7 @@
124
131
  default: "div"
125
132
  }
126
133
  },
127
- emits: [
128
- "update:modelValue",
129
- "update",
130
- "ready",
131
- "focus",
132
- "changed",
133
- "diagnosticCount"
134
- ],
134
+ emits: ["update:modelValue", "update", "ready", "focus", "change"],
135
135
  setup(props, context) {
136
136
  const editor = vueDemi.ref();
137
137
  const doc = vueDemi.ref(props.modelValue);
@@ -140,14 +140,14 @@
140
140
  get: () => view$1.value.state.selection,
141
141
  set: (s) => view$1.value.dispatch({ selection: s })
142
142
  });
143
- const cursor = vueDemi.computed({
144
- get: () => selection.value.main.head || 0,
145
- set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
146
- });
147
143
  const state$1 = vueDemi.computed({
148
144
  get: () => view$1.value.state,
149
145
  set: (s) => view$1.value.setState(s)
150
146
  });
147
+ const cursor = vueDemi.computed({
148
+ get: () => view$1.value.state.selection.main.head || 0,
149
+ set: (a) => view$1.value.dispatch({ selection: { anchor: a } })
150
+ });
151
151
  const focus = vueDemi.computed({
152
152
  get: () => view$1.value.hasFocus,
153
153
  set: (f) => {
@@ -156,6 +156,9 @@
156
156
  }
157
157
  }
158
158
  });
159
+ const length = vueDemi.computed(
160
+ () => view$1.value.state.doc.length
161
+ );
159
162
  const extensions = vueDemi.computed(
160
163
  () => lodash.compact([
161
164
  props.basic ? codemirror.basicSetup : void 0,
@@ -166,9 +169,11 @@
166
169
  view.EditorView.theme(props.theme, { dark: props.dark }),
167
170
  props.wrap ? view.EditorView.lineWrapping : void 0,
168
171
  props.tab ? view.keymap.of([commands.indentWithTab]) : void 0,
172
+ props.tabSize ? state.EditorState.tabSize.of(props.tabSize) : void 0,
169
173
  props.phrases ? state.EditorState.phrases.of(props.phrases) : void 0,
170
174
  state.EditorState.readOnly.of(props.readonly),
171
175
  view.EditorView.editable.of(!props.disabled),
176
+ props.lineSeparator ? state.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
172
177
  props.lang ? props.lang : void 0,
173
178
  props.linter ? lint.linter(props.linter, props.linterConfig) : void 0,
174
179
  props.linter && props.gutter ? lint.lintGutter(props.gutterConfig) : void 0,
@@ -179,16 +184,12 @@
179
184
  vueDemi.watch(
180
185
  () => props.modelValue,
181
186
  (value) => {
182
- if (!view$1.value || view$1.value.composing) {
187
+ if (view$1.value.composing) {
183
188
  return;
184
189
  }
185
- const current = view$1.value.state;
186
- if (props.linter) {
187
- context.emit("diagnosticCount", lint.diagnosticCount(current));
188
- }
189
190
  view$1.value.dispatch({
190
- changes: { from: 0, to: current.doc.length, insert: value },
191
- selection: current.selection,
191
+ changes: { from: 0, to: view$1.value.state.doc.length, insert: value },
192
+ selection: view$1.value.state.selection,
192
193
  scrollIntoView: true
193
194
  });
194
195
  },
@@ -217,7 +218,7 @@
217
218
  return;
218
219
  const v = view$1.value.state.doc.toString();
219
220
  context.emit("update:modelValue", v);
220
- context.emit("changed", v);
221
+ context.emit("change", v);
221
222
  }
222
223
  });
223
224
  await vueDemi.nextTick();
@@ -230,6 +231,7 @@
230
231
  vueDemi.onUnmounted(() => {
231
232
  view$1.value.destroy();
232
233
  });
234
+ const lint$1 = () => lint.forceLinting(view$1.value);
233
235
  const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
234
236
  const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
235
237
  const lineCount = () => view$1.value.state.doc.lines;
@@ -266,6 +268,8 @@
266
268
  selection,
267
269
  state: state$1,
268
270
  focus,
271
+ length,
272
+ lint: lint$1,
269
273
  getRange,
270
274
  getLine,
271
275
  lineCount,
@@ -299,8 +303,8 @@
299
303
  });
300
304
 
301
305
  const meta = {
302
- version: "1.1.0",
303
- date: "2022-10-31T12:33:21.284Z"
306
+ version: "1.1.1",
307
+ date: "2022-11-07T00:40:00.830Z"
304
308
  };
305
309
 
306
310
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
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": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -52,20 +52,23 @@
52
52
  "./sfc": "./src/components/CodeMirror.ts"
53
53
  },
54
54
  "engines": {
55
- "node": ">=16.18.0",
55
+ "node": ">=18.12.1",
56
56
  "yarn": ">=1.22.10"
57
57
  },
58
58
  "packageManager": "yarn@3.2.4",
59
59
  "sideEffects": false,
60
60
  "scripts": {
61
61
  "dev": "vite",
62
- "clean": "rimraf node_modules/.vite && npx vue-demi-fix",
63
- "build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
64
- "build:analyze": "vue-tsc --noEmit & vue-tsc --declaration --emitDeclarationOnly & vite build --mode analyze",
65
- "build:docs": "vite build --config vite.config.docs.ts",
62
+ "clean": "rimraf ./node_modules/.vite",
63
+ "type-check": "vue-tsc --noEmit --composite false",
64
+ "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
65
+ "lint:style": "stylelint \"./**/*.{css,sass,scss,htm,html,vue}\" --fix --cache-location ./node_modules/.vite/vite-plugin-stylelint && prettier \"./**/*.{css,sass,scss,htm,html,vue}\" -w -u",
66
+ "build": "run-p type-check build-only build:declaration",
67
+ "build:declaration": "vue-tsc --composite false --declaration --emitDeclarationOnly",
68
+ "build:analyze": "vite build --mode analyze",
66
69
  "build:clean": "rimraf dist",
67
- "lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
68
- "lint:markup": "vue-tsc --noEmit",
70
+ "build:docs": "vite build --config vite.config.docs.ts",
71
+ "build-only": "vite build",
69
72
  "preview": "vite preview --config vite.config.docs.ts",
70
73
  "prepare": "husky install",
71
74
  "version": "auto-changelog -p && git add CHANGELOG.md"
@@ -86,16 +89,16 @@
86
89
  "devDependencies": {
87
90
  "@codemirror/lang-javascript": "^6.1.1",
88
91
  "@codemirror/lang-json": "^6.0.1",
89
- "@codemirror/lang-markdown": "6.0.2",
90
- "@types/lodash": "^4.14.186",
91
- "@types/node": "^18.11.8",
92
- "@typescript-eslint/eslint-plugin": "^5.41.0",
93
- "@typescript-eslint/parser": "^5.41.0",
92
+ "@codemirror/lang-markdown": "^6.0.4",
93
+ "@types/lodash": "^4.14.188",
94
+ "@types/node": "^18.11.9",
95
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
96
+ "@typescript-eslint/parser": "^5.42.0",
94
97
  "@vitejs/plugin-vue": "^3.2.0",
95
98
  "@vue/eslint-config-prettier": "^7.0.0",
96
99
  "@vue/tsconfig": "^0.1.3",
97
100
  "codemirror": "^6.0.1",
98
- "eslint": "^8.26.0",
101
+ "eslint": "^8.27.0",
99
102
  "eslint-config-google": "^0.14.0",
100
103
  "eslint-config-prettier": "^8.5.0",
101
104
  "eslint-import-resolver-alias": "^1.1.2",
@@ -103,7 +106,7 @@
103
106
  "eslint-linter-browserify": "^8.26.0",
104
107
  "eslint-plugin-html": "^7.1.0",
105
108
  "eslint-plugin-import": "^2.26.0",
106
- "eslint-plugin-jsdoc": "^39.4.0",
109
+ "eslint-plugin-jsdoc": "^39.6.2",
107
110
  "eslint-plugin-tsdoc": "^0.2.17",
108
111
  "eslint-plugin-vue": "^9.7.0",
109
112
  "eslint-plugin-vuejs-accessibility": "^2.0.0",
@@ -112,6 +115,7 @@
112
115
  "lint-staged": "^13.0.3",
113
116
  "lodash": "^4.17.21",
114
117
  "markdown-wasm": "^1.2.0",
118
+ "npm-run-all": "^4.1.5",
115
119
  "prettier": "^2.7.1",
116
120
  "rimraf": "^3.0.2",
117
121
  "rollup-plugin-visualizer": "^5.8.3",
@@ -133,6 +137,7 @@
133
137
  "*": "prettier -w -u"
134
138
  },
135
139
  "resolutions": {
136
- "prettier": "^2.7.1"
140
+ "prettier": "^2.7.1",
141
+ "@codemirror/language": "<6.3.0"
137
142
  }
138
143
  }
@@ -21,11 +21,11 @@ import h, { slot } from '@/helpers/h-demi';
21
21
  import { compact, trim } from 'lodash';
22
22
 
23
23
  // CodeMirror
24
+ import { basicSetup, minimalSetup } from 'codemirror';
24
25
  import { EditorSelection, EditorState, StateEffect } from '@codemirror/state';
25
26
  import { EditorView, keymap, placeholder } from '@codemirror/view';
26
- import { linter, lintGutter, diagnosticCount } from '@codemirror/lint';
27
- import { basicSetup, minimalSetup } from 'codemirror';
28
27
  import { indentWithTab } from '@codemirror/commands';
28
+ import { forceLinting, linter, lintGutter } from '@codemirror/lint';
29
29
 
30
30
  import type {
31
31
  Extension,
@@ -34,9 +34,9 @@ import type {
34
34
  Transaction,
35
35
  } from '@codemirror/state';
36
36
  import type { LanguageSupport } from '@codemirror/language';
37
- import type { ViewUpdate } from '@codemirror/view';
38
37
  import type { LintSource } from '@codemirror/lint';
39
38
  import type { StyleSpec } from 'style-mod';
39
+ import type { ViewUpdate } from '@codemirror/view';
40
40
 
41
41
  /** Emit Interface */
42
42
  export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
@@ -57,8 +57,6 @@ export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
57
57
  ): void;
58
58
  /** onChange (same as update:modelValue) */
59
59
  (e: 'change', value: string | Text): void;
60
- /** CodeMirror linter active diagnostic aount */
61
- (e: 'diagnosticCount', value: number): void;
62
60
  }
63
61
 
64
62
  /** CodeMirror Component */
@@ -80,13 +78,11 @@ export default defineComponent({
80
78
  /**
81
79
  * Theme
82
80
  *
83
- * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
81
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}
84
82
  */
85
83
  theme: {
86
84
  type: Object as PropType<{ [selector: string]: StyleSpec }>,
87
- default: () => {
88
- return {};
89
- },
85
+ default: () => {},
90
86
  },
91
87
  /** Dark Mode */
92
88
  dark: {
@@ -96,7 +92,7 @@ export default defineComponent({
96
92
  /**
97
93
  * Use Basic Setup
98
94
  *
99
- * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup | basicSetup}
95
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}
100
96
  */
101
97
  basic: {
102
98
  type: Boolean,
@@ -105,7 +101,7 @@ export default defineComponent({
105
101
  /**
106
102
  * Use Minimal Setup (The basic setting has priority.)
107
103
  *
108
- * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup | minimalSetup}
104
+ * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}
109
105
  */
110
106
  minimal: {
111
107
  type: Boolean,
@@ -113,9 +109,11 @@ export default defineComponent({
113
109
  },
114
110
  /**
115
111
  * Placeholder
112
+ *
113
+ * @see {@link https://codemirror.net/docs/ref/#view.placeholder}
116
114
  */
117
115
  placeholder: {
118
- type: String,
116
+ type: String as PropType<string | HTMLElement>,
119
117
  default: undefined,
120
118
  },
121
119
  /**
@@ -123,7 +121,7 @@ export default defineComponent({
123
121
  *
124
122
  * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).
125
123
  *
126
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
124
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}
127
125
  */
128
126
  wrap: {
129
127
  type: Boolean,
@@ -132,16 +130,34 @@ export default defineComponent({
132
130
  /**
133
131
  * Allow tab key indent.
134
132
  *
135
- * @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
133
+ * @see {@link https://codemirror.net/examples/tab/}
136
134
  */
137
135
  tab: {
138
136
  type: Boolean,
139
137
  default: false,
140
138
  },
139
+ /**
140
+ * Tab size
141
+ *
142
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}
143
+ */
144
+ tabSize: {
145
+ type: Number,
146
+ default: undefined,
147
+ },
148
+ /**
149
+ * Set line break (separetor) char.
150
+ *
151
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}
152
+ */
153
+ lineSeparator: {
154
+ type: String,
155
+ default: undefined,
156
+ },
141
157
  /**
142
158
  * Readonly
143
159
  *
144
- * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
160
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}
145
161
  */
146
162
  readonly: {
147
163
  type: Boolean,
@@ -153,7 +169,7 @@ export default defineComponent({
153
169
  * This is the reversed value of the CodeMirror editable.
154
170
  * Similar to `readonly`, but setting this value to true disables dragging.
155
171
  *
156
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
172
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}
157
173
  */
158
174
  disabled: {
159
175
  type: Boolean,
@@ -162,7 +178,7 @@ export default defineComponent({
162
178
  /**
163
179
  * Additional Extension
164
180
  *
165
- * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
181
+ * @see {@link https://codemirror.net/docs/ref/#state.Extension}
166
182
  */
167
183
  extensions: {
168
184
  type: Array as PropType<Extension[]>,
@@ -173,7 +189,7 @@ export default defineComponent({
173
189
  /**
174
190
  * Language Phreses
175
191
  *
176
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
192
+ * @see {@link https://codemirror.net/examples/translate/}
177
193
  */
178
194
  phrases: {
179
195
  type: Object as PropType<Record<string, string>>,
@@ -182,7 +198,7 @@ export default defineComponent({
182
198
  /**
183
199
  * CodeMirror Language
184
200
  *
185
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
201
+ * @see {@link https://codemirror.net/docs/ref/#language}
186
202
  */
187
203
  lang: {
188
204
  type: Object as PropType<LanguageSupport>,
@@ -191,7 +207,7 @@ export default defineComponent({
191
207
  /**
192
208
  * CodeMirror Linter
193
209
  *
194
- * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
210
+ * @see {@link https://codemirror.net/docs/ref/#lint.linter}
195
211
  */
196
212
  linter: {
197
213
  type: Function as PropType<LintSource>,
@@ -211,6 +227,8 @@ export default defineComponent({
211
227
  *
212
228
  * An area to 🔴 the lines with errors will be displayed.
213
229
  * This feature is not enabled if `linter` is not specified.
230
+ *
231
+ * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}
214
232
  */
215
233
  gutter: {
216
234
  type: Boolean,
@@ -234,14 +252,7 @@ export default defineComponent({
234
252
  },
235
253
  },
236
254
  /** Emits */
237
- emits: [
238
- 'update:modelValue',
239
- 'update',
240
- 'ready',
241
- 'focus',
242
- 'changed',
243
- 'diagnosticCount',
244
- ],
255
+ emits: ['update:modelValue', 'update', 'ready', 'focus', 'change'],
245
256
  /**
246
257
  * Setup
247
258
  *
@@ -255,28 +266,44 @@ export default defineComponent({
255
266
  /** Internal value */
256
267
  const doc: Ref<string | Text> = ref(props.modelValue);
257
268
 
258
- /** CodeMirror Editor View */
269
+ /**
270
+ * CodeMirror Editor View
271
+ *
272
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView}
273
+ */
259
274
  const view: ShallowRef<EditorView> = shallowRef(new EditorView());
260
275
 
261
- /** Selection */
276
+ /**
277
+ * Editor Selection
278
+ *
279
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorSelection}
280
+ */
262
281
  const selection: WritableComputedRef<EditorSelection> = computed({
263
282
  get: () => view.value.state.selection,
264
283
  set: s => view.value.dispatch({ selection: s }),
265
284
  });
266
285
 
267
- /** Cursor Position */
268
- const cursor: WritableComputedRef<number> = computed({
269
- get: () => selection.value.main.head || 0,
270
- set: a => view.value.dispatch({ selection: { anchor: a } }),
271
- });
272
-
273
- /** Editor State */
286
+ /**
287
+ * Editor State
288
+ *
289
+ * @see {@link https://codemirror.net/docs/ref/#state.EditorState}
290
+ */
274
291
  const state: WritableComputedRef<EditorState> = computed({
275
292
  get: () => view.value.state,
276
293
  set: s => view.value.setState(s),
277
294
  });
278
295
 
279
- /** Focus */
296
+ /** Cursor Position */
297
+ const cursor: WritableComputedRef<number> = computed({
298
+ get: () => view.value.state.selection.main.head || 0,
299
+ set: a => view.value.dispatch({ selection: { anchor: a } }),
300
+ });
301
+
302
+ /**
303
+ * Focus
304
+ *
305
+ * @see {@link https://codemirror.net/docs/ref/#view.EditorView.hasFocus}
306
+ */
280
307
  const focus: WritableComputedRef<boolean> = computed({
281
308
  get: () => view.value.hasFocus,
282
309
  set: f => {
@@ -286,6 +313,11 @@ export default defineComponent({
286
313
  },
287
314
  });
288
315
 
316
+ /** Text length */
317
+ const length: ComputedRef<number> = computed(
318
+ () => view.value.state.doc.length
319
+ );
320
+
289
321
  /** Get CodeMirror Extension */
290
322
  const extensions: ComputedRef<Extension[]> = computed(() =>
291
323
  // TODO: Ignore previous prop was not changed.
@@ -304,12 +336,18 @@ export default defineComponent({
304
336
  props.wrap ? EditorView.lineWrapping : undefined,
305
337
  // Indent with tab
306
338
  props.tab ? keymap.of([indentWithTab]) : undefined,
339
+ // Indent tab size
340
+ props.tabSize ? EditorState.tabSize.of(props.tabSize) : undefined,
307
341
  // locale settings
308
342
  props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
309
343
  // Readonly option
310
344
  EditorState.readOnly.of(props.readonly),
311
345
  // Editable option
312
346
  EditorView.editable.of(!props.disabled),
347
+ // Set Line break char
348
+ props.lineSeparator
349
+ ? EditorState.lineSeparator.of(props.lineSeparator)
350
+ : undefined,
313
351
  // Lang
314
352
  props.lang ? props.lang : undefined,
315
353
  // Append Linter settings
@@ -329,21 +367,15 @@ export default defineComponent({
329
367
  watch(
330
368
  () => props.modelValue,
331
369
  value => {
332
- if (!view.value || view.value.composing) {
370
+ if (view.value.composing) {
333
371
  // IME fix
334
372
  return;
335
373
  }
336
- /** Current Editor State */
337
- const current: EditorState = view.value.state;
338
374
 
339
- if (props.linter) {
340
- // Lint error count.
341
- context.emit('diagnosticCount', diagnosticCount(current));
342
- }
343
375
  // Update
344
376
  view.value.dispatch({
345
- changes: { from: 0, to: current.doc.length, insert: value },
346
- selection: current.selection,
377
+ changes: { from: 0, to: view.value.state.doc.length, insert: value },
378
+ selection: view.value.state.selection,
347
379
  scrollIntoView: true,
348
380
  });
349
381
  },
@@ -388,7 +420,7 @@ export default defineComponent({
388
420
  // child-to-parent binding
389
421
  const v = view.value.state.doc.toString();
390
422
  context.emit('update:modelValue', v);
391
- context.emit('changed', v);
423
+ context.emit('change', v);
392
424
  },
393
425
  });
394
426
  await nextTick();
@@ -404,6 +436,13 @@ export default defineComponent({
404
436
  view.value.destroy();
405
437
  });
406
438
 
439
+ /**
440
+ * Forces any linters configured to run when the editor is idle to run right away.
441
+ *
442
+ * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
443
+ */
444
+ const lint = () => forceLinting(view.value);
445
+
407
446
  // Bellow is experimental.
408
447
 
409
448
  /**
@@ -517,6 +556,8 @@ export default defineComponent({
517
556
  selection,
518
557
  state,
519
558
  focus,
559
+ length,
560
+ lint,
520
561
  // Bellow is CodeMirror5's function
521
562
  getRange,
522
563
  getLine,