vue-codemirror6 1.6.2 → 1.8.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 +96 -400
- package/dist/composables/useCodeMirror.d.ts +381 -0
- package/dist/helpers/h-demi.d.ts +42 -0
- package/dist/index.d.ts +307 -770
- package/dist/index.es.js +11 -381
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/s~0.es.js +389 -0
- package/dist/s~0.es.js.map +1 -0
- package/dist/types/CodeMirrorExposed.d.ts +70 -0
- package/dist/types/Meta.d.ts +18 -0
- package/dist/wc-auto.d.ts +17 -0
- package/dist/wc-auto.es.js +17 -0
- package/dist/wc-auto.es.js.map +1 -0
- package/dist/wc-auto.umd.js +11 -0
- package/dist/wc.d.ts +62 -0
- package/dist/wc.es.js +40 -0
- package/dist/wc.es.js.map +1 -0
- package/dist/wc.umd.js +11 -0
- package/package.json +111 -78
- package/README.ja.md +0 -446
package/README.md
CHANGED
|
@@ -1,445 +1,141 @@
|
|
|
1
1
|
# vue-codemirror6
|
|
2
2
|
|
|
3
|
-
English | [日本語](README.ja.md)
|
|
4
|
-
|
|
5
3
|
<p align="center">
|
|
6
4
|
<img src="https://user-images.githubusercontent.com/480173/224358008-6ffad05d-1d97-4c18-8554-7d41b03f88ab.png" alt="logo" width="300" height="300" />
|
|
7
5
|
</p>
|
|
8
6
|
|
|
9
|
-
[](https://www.npmjs.com/package/vue-codemirror6)
|
|
8
|
+
[](https://www.npmjs.com/package/vue-codemirror6)
|
|
9
|
+
[](https://www.jsdelivr.com/package/npm/vue-codemirror6)
|
|
12
10
|
[](https://uiwjs.github.io/npm-unpkg/#/pkg/@logue/vue-codemirror6/file/README.md)
|
|
13
|
-
[](https://gitpod.io/#https://github.com/logue
|
|
14
|
-
[](https://
|
|
11
|
+
[](https://gitpod.io/#https://github.com/logue/vue-codemirror6)
|
|
12
|
+
[](https://x.com/logue256)
|
|
15
13
|
[](https://github.com/sponsors/logue)
|
|
16
14
|
|
|
17
|
-
A component for using [
|
|
15
|
+
A component for using [CodeMirror 6](https://codemirror.net/6/) with Vue. Works with both Vue 2.7 and Vue 3.
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
**📖 Documentation: <https://logue.dev/vue-codemirror6/>**
|
|
18
|
+
([English](https://logue.dev/vue-codemirror6/) | [日本語](https://logue.dev/vue-codemirror6/ja/) | [简体中文](https://logue.dev/vue-codemirror6/zh/))
|
|
20
19
|
|
|
21
|
-
##
|
|
20
|
+
## Installation
|
|
22
21
|
|
|
23
22
|
```sh
|
|
24
|
-
pnpm
|
|
23
|
+
pnpm add vue-codemirror6 codemirror
|
|
25
24
|
```
|
|
26
25
|
|
|
27
|
-
For Vue 2.7 or below, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required
|
|
26
|
+
For Vue 2.7 or below, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is also required.
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
pnpm install vue-codemirror6 @vue/composition-api
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
This component can handle bidirectional binding by `v-model` like a general Vue component.
|
|
34
|
-
|
|
35
|
-
## Props
|
|
36
|
-
|
|
37
|
-
| Props | Type | Information |
|
|
38
|
-
| ------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
39
|
-
| model-value | string \| Text | Text value. (Not `value`) |
|
|
40
|
-
| basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
|
|
41
|
-
| minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
|
|
42
|
-
| dark | boolean | Toggle Darkmode. |
|
|
43
|
-
| placeholder | string | Add placeholder text (or HTML DOM) when blank |
|
|
44
|
-
| wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
|
|
45
|
-
| tab | boolean | Enables tab indentation. |
|
|
46
|
-
| allow-multiple-selections | boolean | Allow Multiple Selection. See [allowMultipleSelections](https://codemirror.net/docs/ref/#state.EditorState^allowMultipleSelections) |
|
|
47
|
-
| tab-size | number | Configures the tab size to use in this state. |
|
|
48
|
-
| line-separator | string | Set line break (separetor) char. (Default is `\n`.) |
|
|
49
|
-
| 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. |
|
|
50
|
-
| readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
|
|
51
|
-
| disabled | boolean | This is the reversed value of the CodeMirror editable. Similar to `readonly`, but setting this value to true disables dragging. |
|
|
52
|
-
| lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
|
|
53
|
-
| phrases | Record<string, string> | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
|
|
54
|
-
| extensions | Extension[] | Includes enhancements to extend CodeMirror. |
|
|
55
|
-
| 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. |
|
|
56
|
-
| linterConfig | Object | see <https://codemirror.net/docs/ref/#lint.linter^config> |
|
|
57
|
-
| forceLinting | boolean | see <https://codemirror.net/docs/ref/#lint.forceLinting> |
|
|
58
|
-
| gutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
|
|
59
|
-
| gutterConfig | Object | see <https://codemirror.net/docs/ref/#lint.lintGutter^config> |
|
|
60
|
-
| tag | string | HTML tags used in the component. (Default is `div` tag.) |
|
|
61
|
-
| scrollIntoView | boolean | Allows an external update to scroll the form. (Default is `true`) |
|
|
62
|
-
| preserveScrollPosition | boolean | Preserves the editor scroll position when `modelValue` is updated externally. Useful to prevent jumping to the top during appended updates. (Default is `false`) |
|
|
63
|
-
| keymap | KeyBinding[] | Key bindings associate key names with command-style functions. See <https://codemirror.net/docs/ref/#view.KeyBinding> |
|
|
64
|
-
|
|
65
|
-
⚠ 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.
|
|
66
|
-
|
|
67
|
-
### Supported Languages
|
|
68
|
-
|
|
69
|
-
#### Official
|
|
70
|
-
|
|
71
|
-
- [`@codemirror/lang-angular`](https://www.npmjs.com/package/@codemirror/lang-angular)
|
|
72
|
-
- [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
|
|
73
|
-
- [`@codemirror/lang-css`](https://www.npmjs.com/package/@codemirror/lang-css)
|
|
74
|
-
- [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
|
|
75
|
-
- [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
|
|
76
|
-
- [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
|
|
77
|
-
- [`@codemirror/lang-json`](https://www.npmjs.com/package/@codemirror/lang-json)
|
|
78
|
-
- [`@codemirror/lang-lezer`](https://www.npmjs.com/package/@codemirror/lang-lezer)
|
|
79
|
-
- [`@codemirror/lang-markdown`](https://www.npmjs.com/package/@codemirror/lang-markdown)
|
|
80
|
-
- [`@codemirror/lang-php`](https://www.npmjs.com/package/@codemirror/lang-php)
|
|
81
|
-
- [`@codemirror/lang-python`](https://www.npmjs.com/package/@codemirror/lang-python)
|
|
82
|
-
- [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
|
|
83
|
-
- [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
|
|
84
|
-
- [`@codemirror/lang-vue`](https://www.npmjs.com/package/@codemirror/lang-vue)
|
|
85
|
-
- [`@codemirror/lang-west`](https://www.npmjs.com/package/@codemirror/lang-west)
|
|
86
|
-
- [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
|
|
87
|
-
|
|
88
|
-
### Unofficial
|
|
89
|
-
|
|
90
|
-
- [`@phoenix-plugin-registry/petetnt.brackets-codemirror-fortran`](https://www.npmjs.com/package/@phoenix-plugin-registry/petetnt.brackets-codemirror-fortran)
|
|
91
|
-
- [`@phoenix-plugin-registry/petetnt.brackets-codemirror-go`](https://www.npmjs.com/package/@phoenix-plugin-registry/petetnt.brackets-codemirror-go)
|
|
92
|
-
- [`@acarl005/lang-sql`](https://www.npmjs.com/package/@acarl005/lang-sql)
|
|
93
|
-
- [`@ark-us/codemirror-lang-taylor`](https://www.npmjs.com/package/@ark-us/codemirror-lang-taylor)
|
|
94
|
-
- [`@formulavize/lang-fiz`](https://www.npmjs.com/package/@formulavize/lang-fiz)
|
|
95
|
-
- [`@gravitywiz/codemirror-lang-gfcalc`](https://www.npmjs.com/package/@gravitywiz/codemirror-lang-gfcalc)
|
|
96
|
-
- [`@nextjournal/lang-clojure`](https://www.npmjs.com/package/@nextjournal/lang-clojure)
|
|
97
|
-
- [`@plutojl/lang-julia`](https://www.npmjs.com/package/@plutojl/lang-julia)
|
|
98
|
-
- [`@polybase/codemirror-lang-javascript`](https://www.npmjs.com/package/@polybase/codemirror-lang-javascript) -[`@replit/codemirror-lang-nix`](https://www.npmjs.com/package/@replit/codemirror-lang-nix)
|
|
99
|
-
- [`@replit/codemirror-lang-csharp`](https://www.npmjs.com/package/@replit/codemirror-lang-csharp)
|
|
100
|
-
- [`@replit/codemirror-lang-solidity`](https://www.npmjs.com/package/@replit/codemirror-lang-solidity)
|
|
101
|
-
- [`@replit/codemirror-lang-svelte`](https://www.npmjs.com/package/@replit/codemirror-lang-svelte)
|
|
102
|
-
- [`@zhijiu/lang-sql`](https://www.npmjs.com/package/@zhijiu/lang-sql)
|
|
103
|
-
- [`codemirror-lang-bool`](https://www.npmjs.com/package/codemirror-lang-bool)
|
|
104
|
-
- [`codemirror-lang-brainfuck`](https://www.npmjs.com/package/codemirror-lang-brainfuck)
|
|
105
|
-
- [`codemirror-lang-cherry`](https://www.npmjs.com/package/codemirror-lang-cherry)
|
|
106
|
-
- [`codemirror-lang-chordpro`](https://www.npmjs.com/package/codemirror-lang-chordpro)
|
|
107
|
-
- [`codemirror-lang-circom`](https://www.npmjs.com/package/codemirror-lang-circom)
|
|
108
|
-
- [`codemirror-lang-edn`](https://www.npmjs.com/package/codemirror-lang-edn)
|
|
109
|
-
- [`codemirror-lang-ejs`](https://www.npmjs.com/package/codemirror-lang-ejs)
|
|
110
|
-
- [`codemirror-lang-fsl`](https://www.npmjs.com/package/codemirror-lang-fsl)
|
|
111
|
-
- [`codemirror-lang-gml`](https://www.npmjs.com/package/codemirror-lang-gml)
|
|
112
|
-
- [`codemirror-lang-golfscript`](https://www.npmjs.com/package/codemirror-lang-golfscript)
|
|
113
|
-
- [`codemirror-lang-homescript`](https://www.npmjs.com/package/codemirror-lang-homescript)
|
|
114
|
-
- [`codemirror-lang-html-n8n`](https://www.npmjs.com/package/codemirror-lang-html-n8n)
|
|
115
|
-
- [`codemirror-lang-inform7`](https://www.npmjs.com/package/codemirror-lang-inform7)
|
|
116
|
-
- [`codemirror-lang-j`](https://www.npmjs.com/package/codemirror-lang-j)
|
|
117
|
-
- [`codemirror-lang-janet`](https://www.npmjs.com/package/codemirror-lang-janet)
|
|
118
|
-
- [`codemirror-lang-k`](https://www.npmjs.com/package/codemirror-lang-k)
|
|
119
|
-
- [`codemirror-lang-karol`](https://www.npmjs.com/package/codemirror-lang-karol)
|
|
120
|
-
- [`codemirror-lang-mermaid`](https://www.npmjs.com/package/codemirror-lang-mermaid)
|
|
121
|
-
- [`codemirror-lang-n8n-expression`](https://www.npmjs.com/package/codemirror-lang-n8n-expression)
|
|
122
|
-
- [`codemirror-lang-prolog`](https://www.npmjs.com/package/codemirror-lang-prolog)
|
|
123
|
-
- [`codemirror-lang-qpen`](https://www.npmjs.com/package/codemirror-lang-qpen)
|
|
124
|
-
- [`codemirror-lang-qtam`](https://www.npmjs.com/package/codemirror-lang-qtam)
|
|
125
|
-
- [`codemirror-lang-r`](https://www.npmjs.com/package/codemirror-lang-r)
|
|
126
|
-
- [`codemirror-lang-rome-ast`](https://www.npmjs.com/package/codemirror-lang-rome-ast)
|
|
127
|
-
- [`codemirror-lang-rome`](https://www.npmjs.com/package/codemirror-lang-rome)
|
|
128
|
-
- [`codemirror-lang-rush`](https://www.npmjs.com/package/codemirror-lang-rush)
|
|
129
|
-
- [`codemirror-lang-scopescript`](https://www.npmjs.com/package/codemirror-lang-scopescript)
|
|
130
|
-
- [`codemirror-lang-statement`](https://www.npmjs.com/package/codemirror-lang-statement)
|
|
131
|
-
- [`gcode-lang-codemirror`](https://www.npmjs.com/package/gcode-lang-codemirror)
|
|
132
|
-
- [`gmail-lang`](https://www.npmjs.com/package/gmail-lang)
|
|
133
|
-
- [`lang-bqn`](https://www.npmjs.com/package/lang-bqn)
|
|
134
|
-
- [`lang-clojure`](https://www.npmjs.com/package/lang-clojure)
|
|
135
|
-
- [`lang-d`](https://www.npmjs.com/package/lang-d)
|
|
136
|
-
- [`lang-feel`](https://www.npmjs.com/package/lang-feel)
|
|
137
|
-
- [`lang-firestore`](https://www.npmjs.com/package/lang-firestore)
|
|
138
|
-
|
|
139
|
-
### Supported Themes
|
|
140
|
-
|
|
141
|
-
- [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
|
|
142
|
-
- [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
|
|
143
|
-
- [`codemirror6-bootstrap-theme`](https://github.com/logue/codemirror6-bootstrap-theme)
|
|
144
|
-
|
|
145
|
-
## Example
|
|
146
|
-
|
|
147
|
-
Mark up as follows to make it work at a minimum.
|
|
28
|
+
## Quick Start
|
|
148
29
|
|
|
149
30
|
```vue
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
31
|
+
<script lang="ts" setup vapor>
|
|
32
|
+
import { ref } from 'vue';
|
|
33
|
+
import CodeMirror from 'vue-codemirror6';
|
|
153
34
|
|
|
154
|
-
|
|
155
|
-
import { ref, defineComponent } from "vue";
|
|
156
|
-
|
|
157
|
-
import CodeMirror from "vue-codemirror6";
|
|
158
|
-
|
|
159
|
-
export default defineComponent({
|
|
160
|
-
components: {
|
|
161
|
-
CodeMirror,
|
|
162
|
-
},
|
|
163
|
-
setup() {
|
|
164
|
-
const value = ref("Cozy lummox gives smart squid who asks for job pen.");
|
|
165
|
-
|
|
166
|
-
return { value };
|
|
167
|
-
},
|
|
168
|
-
});
|
|
35
|
+
const value = ref('Hello, CodeMirror!');
|
|
169
36
|
</script>
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Example using Slots
|
|
173
|
-
|
|
174
|
-
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`.
|
|
175
|
-
|
|
176
|
-
Also, insert a `<pre>` tag to prevent the text in the slot from being automatically formatted.
|
|
177
37
|
|
|
178
|
-
```vue
|
|
179
38
|
<template>
|
|
180
|
-
<code-mirror
|
|
181
|
-
<pre>
|
|
182
|
-
{
|
|
183
|
-
"key": "value"
|
|
184
|
-
}</pre>
|
|
185
|
-
</code-mirror>
|
|
39
|
+
<code-mirror v-model="value" basic />
|
|
186
40
|
</template>
|
|
187
|
-
|
|
188
|
-
<script>
|
|
189
|
-
import { ref, defineComponent } from "vue";
|
|
190
|
-
|
|
191
|
-
import { json, jsonParseLinter } from "@codemirror/lang-json";
|
|
192
|
-
|
|
193
|
-
import CodeMirror from "vue-codemirror6";
|
|
194
|
-
|
|
195
|
-
export default defineComponent({
|
|
196
|
-
components: {
|
|
197
|
-
CodeMirror,
|
|
198
|
-
},
|
|
199
|
-
setup() {
|
|
200
|
-
const lang = json();
|
|
201
|
-
const linter = jsonParseLinter();
|
|
202
|
-
return { lang, linter };
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
</script>
|
|
206
41
|
```
|
|
207
42
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
```
|
|
215
|
-
<
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
43
|
+
Props, events, languages, themes, SSR, Web Component usage and more are covered in the [documentation](https://logue.dev/vue-codemirror6/).
|
|
44
|
+
|
|
45
|
+
## Using from a CDN (jsDelivr)
|
|
46
|
+
|
|
47
|
+
vue-codemirror6 1.8.0 or later can be used without a bundler (Vue 3 only). Load the ESM files from jsDelivr through an [import map](https://developer.mozilla.org/docs/Web/HTML/Reference/Elements/script/type/importmap):
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script type="importmap">
|
|
51
|
+
{
|
|
52
|
+
"imports": {
|
|
53
|
+
"vue-codemirror6": "https://cdn.jsdelivr.net/npm/vue-codemirror6@1/dist/index.es.js",
|
|
54
|
+
"vue-codemirror6/wc": "https://cdn.jsdelivr.net/npm/vue-codemirror6@1/dist/wc.es.js",
|
|
55
|
+
"vue-codemirror6/wc-auto": "https://cdn.jsdelivr.net/npm/vue-codemirror6@1/dist/wc-auto.es.js",
|
|
56
|
+
"vue": "https://cdn.jsdelivr.net/npm/vue@3/dist/vue.esm-browser.prod.js",
|
|
57
|
+
"vue-demi": "https://cdn.jsdelivr.net/npm/vue-demi@0.14/lib/v3/index.mjs",
|
|
58
|
+
"codemirror": "https://cdn.jsdelivr.net/npm/codemirror@6/dist/index.js",
|
|
59
|
+
"@codemirror/autocomplete": "https://cdn.jsdelivr.net/npm/@codemirror/autocomplete@6/dist/index.js",
|
|
60
|
+
"@codemirror/commands": "https://cdn.jsdelivr.net/npm/@codemirror/commands@6/dist/index.js",
|
|
61
|
+
"@codemirror/language": "https://cdn.jsdelivr.net/npm/@codemirror/language@6/dist/index.js",
|
|
62
|
+
"@codemirror/lint": "https://cdn.jsdelivr.net/npm/@codemirror/lint@6/dist/index.js",
|
|
63
|
+
"@codemirror/search": "https://cdn.jsdelivr.net/npm/@codemirror/search@6/dist/index.js",
|
|
64
|
+
"@codemirror/state": "https://cdn.jsdelivr.net/npm/@codemirror/state@6/dist/index.js",
|
|
65
|
+
"@codemirror/streamparser": "https://cdn.jsdelivr.net/npm/@codemirror/streamparser@6/dist/index.js",
|
|
66
|
+
"@codemirror/view": "https://cdn.jsdelivr.net/npm/@codemirror/view@6/dist/index.js",
|
|
67
|
+
"@lezer/common": "https://cdn.jsdelivr.net/npm/@lezer/common@1/dist/index.js",
|
|
68
|
+
"@lezer/highlight": "https://cdn.jsdelivr.net/npm/@lezer/highlight@1/dist/index.js",
|
|
69
|
+
"@lezer/lr": "https://cdn.jsdelivr.net/npm/@lezer/lr@1/dist/index.js",
|
|
70
|
+
"@marijn/find-cluster-break": "https://cdn.jsdelivr.net/npm/@marijn/find-cluster-break@1/src/index.js",
|
|
71
|
+
"crelt": "https://cdn.jsdelivr.net/npm/crelt@1/index.js",
|
|
72
|
+
"style-mod": "https://cdn.jsdelivr.net/npm/style-mod@4/src/style-mod.js",
|
|
73
|
+
"w3c-keyname": "https://cdn.jsdelivr.net/npm/w3c-keyname@2/index.js",
|
|
74
|
+
|
|
75
|
+
"@codemirror/lang-javascript": "https://cdn.jsdelivr.net/npm/@codemirror/lang-javascript@6/dist/index.js",
|
|
76
|
+
"@lezer/javascript": "https://cdn.jsdelivr.net/npm/@lezer/javascript@1/dist/index.js"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
226
79
|
</script>
|
|
227
80
|
```
|
|
228
81
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
import type { ViewUpdate } from "@codemirror/view";
|
|
255
|
-
|
|
256
|
-
/** text */
|
|
257
|
-
const value: Ref<string> = ref("");
|
|
258
|
-
|
|
259
|
-
/** Dark mode **/
|
|
260
|
-
const dark: Ref<boolean> = ref(
|
|
261
|
-
window.matchMedia("(prefers-color-scheme: dark)").matches,
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* CodeMirror Language
|
|
266
|
-
*
|
|
267
|
-
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
268
|
-
*/
|
|
269
|
-
const lang: LanguageSupport = md();
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Internationalization Config.
|
|
273
|
-
* In this example, the display language to Japanese.
|
|
274
|
-
* Must be reactive when used in combination with vue-i18n.
|
|
275
|
-
*
|
|
276
|
-
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
277
|
-
*/
|
|
278
|
-
const phrases: Record<string, string> = {
|
|
279
|
-
// @codemirror/view
|
|
280
|
-
"Control character": "制御文字",
|
|
281
|
-
// @codemirror/commands
|
|
282
|
-
"Selection deleted": "選択を削除",
|
|
283
|
-
// @codemirror/language
|
|
284
|
-
"Folded lines": "折り畳まれた行",
|
|
285
|
-
"Unfolded lines": "折り畳める行",
|
|
286
|
-
to: "行き先",
|
|
287
|
-
"folded code": "折り畳まれたコード",
|
|
288
|
-
unfold: "折り畳みを解除",
|
|
289
|
-
"Fold line": "行を折り畳む",
|
|
290
|
-
"Unfold line": "行の折り畳む解除",
|
|
291
|
-
// @codemirror/search
|
|
292
|
-
"Go to line": "行き先の行",
|
|
293
|
-
go: "OK",
|
|
294
|
-
Find: "検索",
|
|
295
|
-
Replace: "置き換え",
|
|
296
|
-
next: "▼",
|
|
297
|
-
previous: "▲",
|
|
298
|
-
all: "すべて",
|
|
299
|
-
"match case": "一致条件",
|
|
300
|
-
"by word": "全文検索",
|
|
301
|
-
regexp: "正規表現",
|
|
302
|
-
replace: "置き換え",
|
|
303
|
-
"replace all": "すべてを置き換え",
|
|
304
|
-
close: "閉じる",
|
|
305
|
-
"current match": "現在の一致",
|
|
306
|
-
"replaced $ matches": "$ 件の一致を置き換え",
|
|
307
|
-
"replaced match on line $": "$ 行の一致を置き換え",
|
|
308
|
-
"on line": "した行",
|
|
309
|
-
// @codemirror/autocomplete
|
|
310
|
-
Completions: "自動補完",
|
|
311
|
-
// @codemirror/lint
|
|
312
|
-
Diagnostics: "エラー",
|
|
313
|
-
"No diagnostics": "エラーなし",
|
|
314
|
-
};
|
|
82
|
+
- Map every package to **one** URL, as above. Loading two copies of `@codemirror/state` (or Vue) breaks the editor, so avoid jsDelivr's `/+esm` URLs here; they pin dependency versions independently per package.
|
|
83
|
+
- The last two entries are for `@codemirror/lang-javascript`. Add the language packages you use (and their `@lezer/*` parsers) the same way.
|
|
84
|
+
- You only need the `vue-codemirror6*` entries you actually import.
|
|
85
|
+
- The `*.umd.js` files are for CommonJS / AMD loaders and cannot be used from a plain `<script>` tag.
|
|
86
|
+
|
|
87
|
+
### As a Vue component
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<div id="app">
|
|
91
|
+
<code-mirror v-model="value" basic :lang="lang"></code-mirror>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<script type="module">
|
|
95
|
+
import { createApp, ref } from 'vue';
|
|
96
|
+
import CodeMirror from 'vue-codemirror6';
|
|
97
|
+
import { javascript } from '@codemirror/lang-javascript';
|
|
98
|
+
|
|
99
|
+
createApp({
|
|
100
|
+
components: { CodeMirror },
|
|
101
|
+
setup() {
|
|
102
|
+
const value = ref('console.log("Hello, CodeMirror!");');
|
|
103
|
+
const lang = javascript();
|
|
104
|
+
return { value, lang };
|
|
105
|
+
}
|
|
106
|
+
}).mount('#app');
|
|
315
107
|
</script>
|
|
316
|
-
|
|
317
|
-
<template>
|
|
318
|
-
<code-mirror
|
|
319
|
-
v-model="value"
|
|
320
|
-
basic
|
|
321
|
-
:dark="dark"
|
|
322
|
-
:lang="lang"
|
|
323
|
-
:phrases="phrases"
|
|
324
|
-
/>
|
|
325
|
-
</template>
|
|
326
108
|
```
|
|
327
109
|
|
|
328
|
-
|
|
110
|
+
`vue.esm-browser.prod.js` includes the template compiler, so in-DOM templates like the one above work.
|
|
329
111
|
|
|
330
|
-
|
|
331
|
-
| ------ | ------------------------------------------------------------------------------------------------------------- |
|
|
332
|
-
| ready | When CodeMirror loaded. |
|
|
333
|
-
| focus | When focus changed. |
|
|
334
|
-
| update | When CodeMirror state changed. Returns [ViewUpdate](https://codemirror.net/docs/ref/#view.ViewUpdate) object. |
|
|
335
|
-
| change | Value changed. Returns [EditorState](https://codemirror.net/docs/ref/#state.EditorState) |
|
|
112
|
+
### As a Web Component
|
|
336
113
|
|
|
337
|
-
|
|
114
|
+
```html
|
|
115
|
+
<code-mirror></code-mirror>
|
|
338
116
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
import {
|
|
342
|
-
import CodeMirror from "vue-codemirror6";
|
|
343
|
-
|
|
344
|
-
const cm: Ref<InstanceType<typeof CodeMirror> | undefined> = ref();
|
|
117
|
+
<script type="module">
|
|
118
|
+
import 'vue-codemirror6/wc-auto';
|
|
119
|
+
import { javascript } from '@codemirror/lang-javascript';
|
|
345
120
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
121
|
+
const editor = document.querySelector('code-mirror');
|
|
122
|
+
editor.basic = true;
|
|
123
|
+
editor.lang = javascript();
|
|
124
|
+
editor.modelValue = 'console.log("Hello, CodeMirror!");';
|
|
349
125
|
</script>
|
|
350
|
-
<template>
|
|
351
|
-
<code-mirror ref="cm" />
|
|
352
|
-
</template>
|
|
353
126
|
```
|
|
354
127
|
|
|
355
|
-
|
|
356
|
-
| -------------------- | --------------------------------------------------------------------------------------------------- |
|
|
357
|
-
| view | Get and set [EditorView](https://codemirror.net/docs/ref/#view.EditorView). |
|
|
358
|
-
| selection | Get and set the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
|
|
359
|
-
| cursor | Get and set the [cursor](https://codemirror.net/docs/ref/#state.EditorSelection^cursor) location. |
|
|
360
|
-
| json | Get and set state to a JSON-serializable object. |
|
|
361
|
-
| focus | Get and set [focus](https://codemirror.net/docs/ref/#view.EditorView.focus). |
|
|
362
|
-
| lint() | Force run linter (Only if `linter` prop is specified) |
|
|
363
|
-
| forceReconfigure() | Re register all extensions. |
|
|
364
|
-
|
|
365
|
-
### CodeMirror5 backward compatible functions
|
|
366
|
-
|
|
367
|
-
The instructions below are compatible methods for those familiar with [codemirror5](https://codemirror.net/5/).
|
|
368
|
-
Since the above method is usually sufficient, its **active use is not recommended**.
|
|
369
|
-
|
|
370
|
-
| Function | Description |
|
|
371
|
-
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
372
|
-
| getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
|
|
373
|
-
| getLine(number: number) | Get the content of line. |
|
|
374
|
-
| lineCount() | Get the number of lines in the editor. |
|
|
375
|
-
| getCursor() | Retrieve one end of the primary selection. |
|
|
376
|
-
| listSelections() | Retrieves a list of all current selections. |
|
|
377
|
-
| getSelection() | Get the currently selected code. |
|
|
378
|
-
| getSelections() | The length of the given array should be the same as the number of active selections. |
|
|
379
|
-
| somethingSelected() | Return true if any text is selected. |
|
|
380
|
-
| replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
|
|
381
|
-
| replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
|
|
382
|
-
| setCursor(position: number) | Set the cursor position. |
|
|
383
|
-
| setSelection(anchor: number, head?: number) | Set a single selection range. |
|
|
384
|
-
| setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
|
|
385
|
-
| extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
|
|
386
|
-
|
|
387
|
-
## Recommendations
|
|
388
|
-
|
|
389
|
-
Since CodeMirror has a relatively large capacity, when using [vite](https://vitejs.dev), 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.
|
|
390
|
-
|
|
391
|
-
```ts
|
|
392
|
-
const config: UserConfig = {
|
|
393
|
-
// ...
|
|
394
|
-
build: {
|
|
395
|
-
rollupOptions: {
|
|
396
|
-
output: {
|
|
397
|
-
manualChunks: {
|
|
398
|
-
// ...
|
|
399
|
-
codemirror: ["vue-codemirror6"],
|
|
400
|
-
"codemirror-lang": [
|
|
401
|
-
// Add the following as needed.
|
|
402
|
-
"@codemirror/lang-html",
|
|
403
|
-
"@codemirror/lang-javascript",
|
|
404
|
-
"@codemirror/lang-markdown",
|
|
405
|
-
],
|
|
406
|
-
// ...
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
},
|
|
411
|
-
// ...
|
|
412
|
-
};
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
## Development
|
|
416
|
-
|
|
417
|
-
### Testing
|
|
128
|
+
To register a different tag name, import `register` from `vue-codemirror6/wc` and call `register('my-editor')`.
|
|
418
129
|
|
|
419
|
-
|
|
130
|
+
See the [documentation](https://logue.dev/vue-codemirror6/guide/getting-started#using-from-a-cdn-jsdelivr) for details.
|
|
420
131
|
|
|
421
|
-
|
|
422
|
-
# Run tests
|
|
423
|
-
pnpm test
|
|
132
|
+
## Links
|
|
424
133
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
# Run tests with UI
|
|
429
|
-
pnpm test:ui
|
|
430
|
-
|
|
431
|
-
# Run tests with coverage
|
|
432
|
-
pnpm test:coverage
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
The test suite includes:
|
|
436
|
-
|
|
437
|
-
- **Component Tests**: Testing basic rendering, props, events, and v-model binding
|
|
438
|
-
- **SSR Tests**: Ensuring proper server-side rendering compatibility for Nuxt.js and other SSR frameworks
|
|
439
|
-
- **Method Tests**: Verifying all exposed methods work correctly
|
|
440
|
-
- **Edge Cases**: Testing error handling and unusual scenarios
|
|
134
|
+
- [Documentation](https://logue.dev/vue-codemirror6/)
|
|
135
|
+
- [Demo](https://logue.dev/vue-codemirror6/demo/)
|
|
136
|
+
- [CHANGELOG](./CHANGELOG.md)
|
|
441
137
|
|
|
442
|
-
##
|
|
138
|
+
## License
|
|
443
139
|
|
|
444
140
|
©2022-2026 by Logue.
|
|
445
141
|
Licensed under the [MIT License](LICENSE).
|