vue-codemirror6 0.1.3 → 0.1.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
@@ -1,217 +1,255 @@
1
- # vue-codemirror6
2
-
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/vue-codemirror6)
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.
10
-
11
- ## Usage
12
-
13
- This component can handle bidirectional binding by `v-model` like a general Vue component.
14
- When using with Vue2, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
15
-
16
- ### Props
17
-
18
- | Props | Type | Information |
19
- | ---------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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
- ### Supported Languages
32
-
33
- - [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
34
- - [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
35
- - [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
36
- - [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
37
- - [`@codemirror/lang-json`](https://www.npmjs.com/package/@codemirror/lang-json)
38
- - [`@codemirror/lang-lezer`](https://www.npmjs.com/package/@codemirror/lang-lezer)
39
- - [`@codemirror/lang-markdown`](https://www.npmjs.com/package/@codemirror/lang-markdown)
40
- - [`@codemirror/lang-php`](https://www.npmjs.com/package/@codemirror/lang-php)
41
- - [`@codemirror/lang-python`](https://www.npmjs.com/package/@codemirror/lang-python)
42
- - [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
43
- - [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
44
- - [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
45
-
46
- ### Supported Themes
47
-
48
- - [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
49
- - [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
50
-
51
- ## Example
52
-
53
- Mark up as follows to make it work at a minimum.
54
-
55
- ```vue
56
- <template>
57
- <code-mirror v-model="value" />
58
- </template>
59
-
60
- <script>
61
- import { ref, defineComponent } from 'vue';
62
-
63
- import CodeMirror from 'vue-codemirror6';
64
-
65
- export default defineComponent({
66
- components: {
67
- CodeMirror,
68
- },
69
- setup() {
70
- const value = ref('Cozy lummox gives smart squid who asks for job pen.');
71
-
72
- return { value };
73
- },
74
- });
75
- </script>
76
- ```
77
-
78
- ### Example using Slots
79
-
80
- The contents of the slot will overwrite the existing `v-model`. For this reason, it is recommended to use it when simply displaying with a `readonly` prop without using `v-model`.
81
-
82
- Also, insert a `<pre>` tag to prevent the text in the slot from being automatically formatted.
83
-
84
- ```vue
85
- <template>
86
- <code-mirror :lang="lang" :editable="false">
87
- <pre>
88
- {
89
- "key": "value"
90
- }</pre
91
- >
92
- </code-mirror>
93
- </template>
94
-
95
- <script>
96
- import { ref, defineComponent } from 'vue';
97
-
98
- import { json } from '@codemirror/lang-json';
99
-
100
- import CodeMirror from 'vue-codemirror6';
101
-
102
- export default defineComponent({
103
- components: {
104
- CodeMirror,
105
- },
106
- setup() {
107
- const lang = ref(json());
108
- return { lang };
109
- },
110
- });
111
- </script>
112
- ```
113
-
114
- ### Full Example
115
-
116
- When using as a Markdown editor on [Vuetify](https://vuetifyjs.com/).
117
-
118
- ```vue
119
- <template>
120
- <code-mirror
121
- v-model="value"
122
- :lang="lang"
123
- :phrases="phreses"
124
- :extensions="extensions"
125
- :dark="$vuetify.theme.dark"
126
- />
127
- </template>
128
-
129
- <script lang="ts">
130
- import { ref, type Ref, defineComponent } from 'vue';
131
-
132
- // Load component
133
- import CodeMirror from 'vue-codemirror6';
134
-
135
- // CodeMirror extensions
136
- import type { LanguageSupport } from '@codemirror/language';
137
- import { markdown } from '@codemirror/lang-markdown';
138
- import { basicSetup } from '@codemirror/basic-setup';
139
- import type { Extension } from '@codemirror/state';
140
- import type { ViewUpdate } from '@codemirror/view';
141
-
142
- export default defineComponent({
143
- components: {
144
- CodeMirror,
145
- },
146
- setup() {
147
- /** text */
148
- const value: Ref<string> = ref('');
149
-
150
- /**
151
- * CodeMirror Language
152
- *
153
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
154
- */
155
- const lang: Ref<LanguageSupport> = ref(markdown());
156
-
157
- /**
158
- * Internationalization Config.
159
- * In this example, the display language to Japanese.
160
- *
161
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
162
- */
163
- const phrases: Ref<Record<string, string>> = ref({
164
- // @codemirror/view
165
- 'Control character': '制御文字',
166
- // @codemirror/fold
167
- 'Folded lines': '折り畳まれた行',
168
- 'Unfolded lines': '折り畳める行',
169
- to: '行き先',
170
- 'folded code': '折り畳まれたコード',
171
- unfold: '折り畳む解除',
172
- 'Fold line': '行を折り畳む',
173
- 'Unfold line': '行の折り畳む解除',
174
- // @codemirror/search
175
- 'Go to line': '行き先の行',
176
- go: 'OK',
177
- Find: '検索',
178
- Replace: '置き換え',
179
- next: '▼',
180
- previous: '▲',
181
- all: 'すべて',
182
- 'match case': '一致条件',
183
- regexp: '正規表現',
184
- replace: '置き換え',
185
- 'replace all': 'すべてを置き換え',
186
- close: '閉じる',
187
- 'current match': '現在の一致',
188
- 'on line': 'した行',
189
- // @codemirror/lint
190
- Diagnostics: 'エラー',
191
- 'No diagnostics': 'エラーなし',
192
- });
193
-
194
- /**
195
- * CodeMirror Extensions
196
- *
197
- * @see {@link:https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
198
- */
199
- const extensions: Ref<Extension[]> = ref([
200
- /** @see {@link:https://codemirror.net/6/docs/ref/#basic-setup | basic-setup} */
201
- basicSetup,
202
- ]);
203
-
204
- return {
205
- value,
206
- lang,
207
- phrases,
208
- extensions,
209
- };
210
- },
211
- });
212
- </script>
213
- ```
214
-
215
- ## LICENSE
216
-
217
- [MIT](LICENSE)
1
+ # vue-codemirror6
2
+
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/vue-codemirror6)
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.
10
+
11
+ If you are using Vue3, please use `0.3.x`. (The component itself supports both, but the script generated by vue-demi can only output one)
12
+
13
+ ## Usage
14
+
15
+ This component can handle bidirectional binding by `v-model` like a general Vue component.
16
+ When using with Vue2, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
17
+
18
+ ### Props
19
+
20
+ | Props | Type | Information |
21
+ | ---------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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. |
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. |
27
+ | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
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. |
29
+ | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
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/> |
31
+ | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
32
+ | linter | Diagnostic[] | Set Linter. see example <https://codesandbox.io/s/f6nb0?file=/src/index.js> |
33
+
34
+ Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
35
+
36
+ ### Supported Languages
37
+
38
+ - [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
39
+ - [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
40
+ - [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
41
+ - [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
42
+ - [`@codemirror/lang-json`](https://www.npmjs.com/package/@codemirror/lang-json)
43
+ - [`@codemirror/lang-lezer`](https://www.npmjs.com/package/@codemirror/lang-lezer)
44
+ - [`@codemirror/lang-markdown`](https://www.npmjs.com/package/@codemirror/lang-markdown)
45
+ - [`@codemirror/lang-php`](https://www.npmjs.com/package/@codemirror/lang-php)
46
+ - [`@codemirror/lang-python`](https://www.npmjs.com/package/@codemirror/lang-python)
47
+ - [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
48
+ - [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
49
+ - [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
50
+
51
+ ### Supported Themes
52
+
53
+ - [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
54
+ - [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
55
+
56
+ ## Example
57
+
58
+ Mark up as follows to make it work at a minimum.
59
+
60
+ ```vue
61
+ <template>
62
+ <code-mirror v-model="value" />
63
+ </template>
64
+
65
+ <script>
66
+ import { ref, defineComponent } from 'vue';
67
+
68
+ import CodeMirror from 'vue-codemirror6';
69
+
70
+ export default defineComponent({
71
+ components: {
72
+ CodeMirror,
73
+ },
74
+ setup() {
75
+ const value = ref('Cozy lummox gives smart squid who asks for job pen.');
76
+
77
+ return { value };
78
+ },
79
+ });
80
+ </script>
81
+ ```
82
+
83
+ ### Example using Slots
84
+
85
+ The contents of the slot will overwrite the existing `v-model`. For this reason, it is recommended to use it when simply displaying with a `readonly` prop without using `v-model`.
86
+
87
+ Also, insert a `<pre>` tag to prevent the text in the slot from being automatically formatted.
88
+
89
+ ```vue
90
+ <template>
91
+ <code-mirror :lang="lang" :editable="false">
92
+ <pre>
93
+ {
94
+ "key": "value"
95
+ }</pre
96
+ >
97
+ </code-mirror>
98
+ </template>
99
+
100
+ <script>
101
+ import { ref, defineComponent } from 'vue';
102
+
103
+ import { json } from '@codemirror/lang-json';
104
+
105
+ import CodeMirror from 'vue-codemirror6';
106
+
107
+ export default defineComponent({
108
+ components: {
109
+ CodeMirror,
110
+ },
111
+ setup() {
112
+ const lang = ref(json());
113
+ return { lang };
114
+ },
115
+ });
116
+ </script>
117
+ ```
118
+
119
+ ### Full Example
120
+
121
+ When using as a Markdown editor on [Vuetify](https://vuetifyjs.com/).
122
+
123
+ ```vue
124
+ <template>
125
+ <code-mirror
126
+ v-model="value"
127
+ basic
128
+ :dark="dark"
129
+ :lang="lang"
130
+ :phrases="phreses"
131
+ />
132
+ </template>
133
+
134
+ <script lang="ts">
135
+ import { ref, defineComponent, type Ref } from 'vue';
136
+
137
+ // Load component
138
+ import CodeMirror from 'vue-codemirror6';
139
+
140
+ // CodeMirror extensions
141
+ import type { LanguageSupport } from '@codemirror/language';
142
+ import { markdown as md } from '@codemirror/lang-markdown';
143
+ import type { Extension } from '@codemirror/state';
144
+ import type { ViewUpdate } from '@codemirror/view';
145
+
146
+ export default defineComponent({
147
+ components: {
148
+ CodeMirror,
149
+ },
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
+
157
+ /** text */
158
+ const value: Ref<string> = ref('');
159
+
160
+ /**
161
+ * CodeMirror Language
162
+ *
163
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
164
+ */
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));
172
+
173
+ /**
174
+ * Internationalization Config.
175
+ * In this example, the display language to Japanese.
176
+ *
177
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
178
+ */
179
+ const phrases: Ref<Record<string, string>> = ref({
180
+ // @codemirror/view
181
+ 'Control character': '制御文字',
182
+ // @codemirror/fold
183
+ 'Folded lines': '折り畳まれた行',
184
+ 'Unfolded lines': '折り畳める行',
185
+ to: '行き先',
186
+ 'folded code': '折り畳まれたコード',
187
+ unfold: '折り畳む解除',
188
+ 'Fold line': '行を折り畳む',
189
+ 'Unfold line': '行の折り畳む解除',
190
+ // @codemirror/search
191
+ 'Go to line': '行き先の行',
192
+ go: 'OK',
193
+ Find: '検索',
194
+ Replace: '置き換え',
195
+ next: '▼',
196
+ previous: '▲',
197
+ all: 'すべて',
198
+ 'match case': '一致条件',
199
+ regexp: '正規表現',
200
+ replace: '置き換え',
201
+ 'replace all': 'すべてを置き換え',
202
+ close: '閉じる',
203
+ 'current match': '現在の一致',
204
+ 'on line': 'した行',
205
+ // @codemirror/lint
206
+ Diagnostics: 'エラー',
207
+ 'No diagnostics': 'エラーなし',
208
+ });
209
+
210
+ return {
211
+ dark,
212
+ value,
213
+ lang,
214
+ phrases,
215
+ };
216
+ },
217
+ });
218
+ </script>
219
+ ```
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
+
253
+ ## LICENSE
254
+
255
+ [MIT](LICENSE)