vue-codemirror6 0.0.4 → 0.1.0

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
@@ -1,14 +1,129 @@
1
1
  # vue-codemirror6
2
2
 
3
- A component for using [CodeMirror6](https://codemirror.net/6/) with Vue. Unlike [surmon-china's vue-codemirror](https://github.com/surmon-china/vue-codemirror), it is for CodeMirror6.
3
+ [![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/vue-codemirror6/badge)](https://www.jsdelivr.com/package/npm/vue-codemirror6)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/vue-codemirror6.svg?style=flat)](https://www.npmjs.com/package/vue-codemirror6)
5
+ [![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/vue-codemirror6/file/README.md)
6
+ [![npm version](https://img.shields.io/npm/v/vue-codemirror6.svg)](https://www.npmjs.com/package/@uiw/react-codemirror)
7
+ [![Open in Gitpod](https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod)](https://gitpod.io/#https://github.com/logue/vue-codemirror6)
8
+
9
+ A component for using [CodeMirror6](https://codemirror.net/6/) with Vue. Unrelated to [surmon-china's vue-codemirror](https://github.com/surmon-china/vue-codemirror), it is for CodeMirror6.
4
10
 
5
11
  ## Usage
6
12
 
13
+ This component can handle bidirectional binding by `v-model` like a general Vue component.
14
+
15
+ ### Props
16
+
17
+ | Props | Type | Information |
18
+ | ---------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
+ | value | string? | Initial text value. |
20
+ | dark | boolean | Toggle Darkmode. If you use Vuetify, I recommend that you enter `$vuetify.theme.dark`. |
21
+ | 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. |
22
+ | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
23
+ | 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. |
24
+ | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
25
+ | 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/> |
26
+ | extensions | Extension[] | Includes enhancements to extend CodeMirror. Such as [@codemirror/basic-setup](https://github.com/codemirror/basic-setup). |
27
+ | linter | Diagnostic[] | Set Linter. see example <https://codesandbox.io/s/f6nb0?file=/src/index.js> |
28
+
29
+ Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
30
+
31
+ ### Events
32
+
33
+ | name | Information |
34
+ | ------ | ------------------------------------------------------------------------------------- |
35
+ | input | When value changed. |
36
+ | update | CodeMirror ViewUpdate event. see <https://codemirror.net/6/docs/ref/#view.ViewUpdate> |
37
+
38
+ ### Support Languages
39
+
40
+ - [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
41
+ - [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
42
+ - [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
43
+ - [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
44
+ - [`@codemirror/lang-json`](https://www.npmjs.com/package/@codemirror/lang-json)
45
+ - [`@codemirror/lang-lezer`](https://www.npmjs.com/package/@codemirror/lang-lezer)
46
+ - [`@codemirror/lang-markdown`](https://www.npmjs.com/package/@codemirror/lang-markdown)
47
+ - [`@codemirror/lang-php`](https://www.npmjs.com/package/@codemirror/lang-php)
48
+ - [`@codemirror/lang-python`](https://www.npmjs.com/package/@codemirror/lang-python)
49
+ - [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
50
+ - [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
51
+ - [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
52
+
53
+ ### Supported Themes
54
+
55
+ - [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
56
+ - [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
57
+
58
+ ## Example
59
+
60
+ Mark up as follows to make it work at a minimum.
61
+
62
+ ```vue
63
+ <template>
64
+ <code-mirror v-model="value" />
65
+ </template>
66
+
67
+ <script>
68
+ import Vue from 'vue';
69
+
70
+ import CodeMirror from '@/components/CodeMirror.vue';
71
+
72
+ export default Vue.extend({
73
+ components: {
74
+ CodeMirror,
75
+ },
76
+ data() {
77
+ return {
78
+ value: 'The quick brown fox jumps over the lazy dog.',
79
+ };
80
+ },
81
+ });
82
+ </script>
83
+ ```
84
+
85
+ ### Example using Slots
86
+
87
+ The contents of the slot will overwrite the existing `value`. For this reason, it is recommended to use it when simply displaying with a `readonly` prop without using `v-model` or `value`.
88
+
89
+ Also, insert a `<pre>` tag to prevent the text in the slot from being automatically formatted.
90
+
91
+ ```vue
92
+ <template>
93
+ <code-mirror :lang="lang" :editable="false">
94
+ <pre>
95
+ {
96
+ "key": "value"
97
+ }</pre
98
+ >
99
+ </code-mirror>
100
+ </template>
101
+
102
+ <script>
103
+ import { Component, Vue } from 'vue-property-decorator';
104
+
105
+ import { json } from '@codemirror/lang-json';
106
+
107
+ export default Vue.extend({
108
+ components: {
109
+ CodeMirror,
110
+ },
111
+ data() {
112
+ return {
113
+ lang: json(),
114
+ };
115
+ },
116
+ });
117
+ </script>
118
+ ```
119
+
120
+ ### Full Example
121
+
7
122
  When using as a Markdown editor on [Vuetify](https://vuetifyjs.com/).
8
123
 
9
124
  ```vue
10
125
  <template>
11
- <codemirror
126
+ <code-mirror
12
127
  v-model="value"
13
128
  :lang="lang"
14
129
  :phrases="phreses"
@@ -25,11 +140,11 @@ import { Component, Vue } from 'vue-property-decorator';
25
140
  import CodeMirror from 'vue-codemirror6';
26
141
 
27
142
  // CodeMirror extensions
28
- import { basicSetup } from '@codemirror/basic-setup';
143
+ import type { LanguageSupport } from '@codemirror/language';
29
144
  import { markdown } from '@codemirror/lang-markdown';
30
- import type { ViewUpdate } from '@codemirror/view';
145
+ import { basicSetup } from '@codemirror/basic-setup';
31
146
  import type { Extension } from '@codemirror/state';
32
- import type { LanguageSupport } from '@codemirror/language';
147
+ import type { ViewUpdate } from '@codemirror/view';
33
148
 
34
149
  @Component({ components: { CodeMirror } })
35
150
  export default class Home extends Vue {
@@ -39,14 +154,15 @@ export default class Home extends Vue {
39
154
  /**
40
155
  * CodeMirror Language
41
156
  *
42
- * @see {@link https://codemirror.net/6/docs/ref/#language|@codemirror/language}
157
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
43
158
  */
44
159
  lang: LanguageSupport = markdown();
45
160
 
46
161
  /**
47
- * Internationalization Config
162
+ * Internationalization Config.
163
+ * In this example, the display language to Japanese.
48
164
  *
49
- * @see {@link https://codemirror.net/6/examples/translate/|Example: Internationalization}
165
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
50
166
  */
51
167
  phrases: Record<string, string> = {
52
168
  // @codemirror/view
@@ -77,29 +193,30 @@ export default class Home extends Vue {
77
193
  // @codemirror/lint
78
194
  Diagnostics: 'エラー',
79
195
  'No diagnostics': 'エラーなし',
80
- }
196
+ };
81
197
 
82
198
  /**
83
199
  * CodeMirror Extensions
84
200
  *
85
- * @see {@link:https://codemirror.net/6/docs/ref/#state.Extension|Extending Editor State}
201
+ * @see {@link:https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
86
202
  */
87
203
  extensions: Extension[] = [
88
- /** @see {@link:https://codemirror.net/6/docs/ref/#basic-setup|basic-setup} */
89
- basicSetup
90
- ]
204
+ /** @see {@link:https://codemirror.net/6/docs/ref/#basic-setup | basic-setup} */
205
+ basicSetup,
206
+ ];
91
207
 
92
208
  /**
93
209
  * CodeMirror Hook View update event
94
210
  *
95
- * @param update View Update
211
+ * @param update - View Update
96
212
  *
97
213
  * @see {@link https://codemirror.net/6/docs/ref/#view.ViewUpdate|class ViewUpdate}
98
214
  */
99
215
  onCmUpdate(update: ViewUpdate) {
100
- console.log(update)
216
+ console.log(update);
101
217
  }
102
218
  }
219
+ </script>
103
220
  ```
104
221
 
105
222
  ## LICENSE
@@ -1,5 +1,5 @@
1
1
  import { Vue } from 'vue-property-decorator';
2
- import type { Extension } from '@codemirror/state';
2
+ import { type Extension } from '@codemirror/state';
3
3
  import type { LanguageSupport } from '@codemirror/language';
4
4
  import type { Diagnostic } from '@codemirror/lint';
5
5
  import type { StyleSpec } from 'style-mod';
@@ -7,25 +7,61 @@ import type { StyleSpec } from 'style-mod';
7
7
  export default class CodeMirror extends Vue {
8
8
  /** Editor */
9
9
  private editor;
10
- /** Theme */
10
+ /**
11
+ * Theme
12
+ *
13
+ * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
14
+ */
11
15
  readonly theme: {
12
16
  [selector: string]: StyleSpec;
13
17
  };
14
18
  /** Dark Mode */
15
19
  readonly dark: boolean;
16
- /** Language Phreses */
20
+ /**
21
+ * Readonly
22
+ *
23
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
24
+ */
25
+ readonly readonly: boolean;
26
+ /**
27
+ * Editable
28
+ *
29
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
30
+ */
31
+ readonly editable: boolean;
32
+ /**
33
+ * Language Phreses
34
+ *
35
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
36
+ */
17
37
  readonly phrases: Record<string, string>;
18
- /** Additional Extension */
38
+ /**
39
+ * Additional Extension
40
+ *
41
+ * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
42
+ */
19
43
  readonly extensions: Extension[];
20
- /** CodeMirror Language */
44
+ /**
45
+ * CodeMirror Language
46
+ *
47
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
48
+ */
21
49
  readonly lang: LanguageSupport;
22
- /** CodeMirror Linter */
50
+ /**
51
+ * CodeMirror Linter
52
+ *
53
+ * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
54
+ */
23
55
  readonly linter: Diagnostic[];
24
56
  /** Input */
25
57
  readonly value: string;
26
- /** Input value changed */
58
+ /**
59
+ * Input value changed
60
+ *
61
+ * @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
62
+ */
27
63
  onValueChanged(): void;
28
- /** Darkmode */
64
+ /** Toggle Dark mode */
29
65
  onToggleDarkMode(): void;
30
66
  /** CodeMirror Extension */
31
67
  get extension(): Extension[];
@@ -33,5 +69,7 @@ export default class CodeMirror extends Vue {
33
69
  mounted(): void;
34
70
  /** Destroy */
35
71
  beforeDestroy(): void;
72
+ /** Vue node to plain text */
73
+ private getChildrenTextContent;
36
74
  }
37
75
  //# 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":"AACA,OAAO,EAAmB,GAAG,EAAS,MAAM,wBAAwB,CAAC;AAErE,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;AAGnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAI3C,2BAA2B;AAC3B,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,GAAG;IACzC,aAAa;IACb,OAAO,CAAC,MAAM,CAAc;IAE5B,YAAY;IAEZ,QAAQ,CAAC,KAAK,EAAG;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAEnD,gBAAgB;IAEhB,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAC;IAExB,uBAAuB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