vue-codemirror6 1.7.0 → 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 CHANGED
@@ -1,7 +1,5 @@
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>
@@ -14,447 +12,130 @@ English | [日本語](README.ja.md)
14
12
  [![X Follow](https://img.shields.io/twitter/follow/logue256?style=plastic)](https://x.com/logue256)
15
13
  [![GitHub Sponsors](https://img.shields.io/github/sponsors/logue?label=Sponsor&logo=github&color=ea4aaa)](https://github.com/sponsors/logue)
16
14
 
17
- A component for using [CodeMirror6](https://codemirror.net/6/) with Vue. This component works in both Vue2 and Vue3.
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
- - [CHANGELOG](./CHANGELOG.md)
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
- ## Usage
20
+ ## Installation
22
21
 
23
22
  ```sh
24
- pnpm install vue-codemirror6 codemirror
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 separately.
28
-
29
- ```sh
30
- pnpm install vue-codemirror6 @vue/composition-api
31
- ```
26
+ For Vue 2.7 or below, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is also required.
32
27
 
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&lt;string, string&gt; | 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
- <template>
151
- <code-mirror v-model="value" />
152
- </template>
153
-
154
- <script>
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.");
31
+ <script lang="ts" setup vapor>
32
+ import { ref } from 'vue';
33
+ import CodeMirror from 'vue-codemirror6';
165
34
 
166
- return { value };
167
- },
168
- });
35
+ const value = ref('Hello, CodeMirror!');
169
36
  </script>
170
- ```
171
37
 
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
-
178
- ```vue
179
38
  <template>
180
- <code-mirror :lang="lang" :linter="linter">
181
- <pre>
182
- {
183
- "key": "value"
184
- }</pre
185
- >
186
- </code-mirror>
39
+ <code-mirror v-model="value" basic />
187
40
  </template>
188
-
189
- <script>
190
- import { ref, defineComponent } from "vue";
191
-
192
- import { json, jsonParseLinter } from "@codemirror/lang-json";
193
-
194
- import CodeMirror from "vue-codemirror6";
195
-
196
- export default defineComponent({
197
- components: {
198
- CodeMirror,
199
- },
200
- setup() {
201
- const lang = json();
202
- const linter = jsonParseLinter();
203
- return { lang, linter };
204
- },
205
- });
206
- </script>
207
41
  ```
208
42
 
209
- ### Using with SSR (Nuxt.js, etc.)
43
+ Props, events, languages, themes, SSR, Web Component usage and more are covered in the [documentation](https://logue.dev/vue-codemirror6/).
210
44
 
211
- This component is now SSR-compatible. CodeMirror will only be initialized on the client side, and the component will safely render without errors during server-side rendering.
45
+ ## Using from a CDN (jsDelivr)
212
46
 
213
- If you're using Nuxt 3, you can use the component directly:
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):
214
48
 
215
- ```vue
216
- <template>
217
- <code-mirror v-model="value" :lang="lang" />
218
- </template>
219
-
220
- <script lang="ts" setup vapor>
221
- import { ref } from "vue";
222
- import CodeMirror from "vue-codemirror6";
223
- import { javascript } from "@codemirror/lang-javascript";
224
-
225
- const value = ref('console.log("Hello, World!");');
226
- const lang = javascript();
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
+ }
227
79
  </script>
228
80
  ```
229
81
 
230
- For Nuxt 2 or if you encounter any issues, you can wrap the component with `<ClientOnly>`:
231
-
232
- ```vue
233
- <template>
234
- <client-only>
235
- <code-mirror v-model="value" :lang="lang" />
236
- </client-only>
237
- </template>
238
- ```
239
-
240
- ### Full Example
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.
241
86
 
242
- When using as a Markdown editor on [vite-vue3-ts-starter](https://github.com/logue/vite-vue3-ts-starter).
87
+ ### As a Vue component
243
88
 
244
- ```vue
245
- <script lang="ts" setup vapor>
246
- import { ref, defineComponent, type Ref } from "vue";
247
-
248
- // Load component
249
- import CodeMirror from "vue-codemirror6";
250
-
251
- // CodeMirror extensions
252
- import { markdown as md } from "@codemirror/lang-markdown";
253
- import type { LanguageSupport } from "@codemirror/language";
254
- import type { Extension } from "@codemirror/state";
255
- import type { ViewUpdate } from "@codemirror/view";
256
-
257
- /** text */
258
- const value: Ref<string> = ref("");
259
-
260
- /** Dark mode **/
261
- const dark: Ref<boolean> = ref(
262
- window.matchMedia("(prefers-color-scheme: dark)").matches,
263
- );
264
-
265
- /**
266
- * CodeMirror Language
267
- *
268
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
269
- */
270
- const lang: LanguageSupport = md();
271
-
272
- /**
273
- * Internationalization Config.
274
- * In this example, the display language to Japanese.
275
- * Must be reactive when used in combination with vue-i18n.
276
- *
277
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
278
- */
279
- const phrases: Record<string, string> = {
280
- // @codemirror/view
281
- "Control character": "制御文字",
282
- // @codemirror/commands
283
- "Selection deleted": "選択を削除",
284
- // @codemirror/language
285
- "Folded lines": "折り畳まれた行",
286
- "Unfolded lines": "折り畳める行",
287
- to: "行き先",
288
- "folded code": "折り畳まれたコード",
289
- unfold: "折り畳みを解除",
290
- "Fold line": "行を折り畳む",
291
- "Unfold line": "行の折り畳む解除",
292
- // @codemirror/search
293
- "Go to line": "行き先の行",
294
- go: "OK",
295
- Find: "検索",
296
- Replace: "置き換え",
297
- next: "▼",
298
- previous: "▲",
299
- all: "すべて",
300
- "match case": "一致条件",
301
- "by word": "全文検索",
302
- regexp: "正規表現",
303
- replace: "置き換え",
304
- "replace all": "すべてを置き換え",
305
- close: "閉じる",
306
- "current match": "現在の一致",
307
- "replaced $ matches": "$ 件の一致を置き換え",
308
- "replaced match on line $": "$ 行の一致を置き換え",
309
- "on line": "した行",
310
- // @codemirror/autocomplete
311
- Completions: "自動補完",
312
- // @codemirror/lint
313
- Diagnostics: "エラー",
314
- "No diagnostics": "エラーなし",
315
- };
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');
316
107
  </script>
317
-
318
- <template>
319
- <code-mirror
320
- v-model="value"
321
- basic
322
- :dark="dark"
323
- :lang="lang"
324
- :phrases="phrases"
325
- />
326
- </template>
327
108
  ```
328
109
 
329
- ## Events
330
-
331
- | Event | Description |
332
- | ------ | ------------------------------------------------------------------------------------------------------------- |
333
- | ready | When CodeMirror loaded. |
334
- | focus | When focus changed. |
335
- | update | When CodeMirror state changed. Returns [ViewUpdate](https://codemirror.net/docs/ref/#view.ViewUpdate) object. |
336
- | change | Value changed. Returns [EditorState](https://codemirror.net/docs/ref/#state.EditorState) |
337
-
338
- ## Parameter / Function
339
-
340
- ```vue
341
- <script lang="ts" setup vapor>
342
- import { ref, onMounted, type Ref, type PropType } from "vue";
343
- import CodeMirror from "vue-codemirror6";
110
+ `vue.esm-browser.prod.js` includes the template compiler, so in-DOM templates like the one above work.
344
111
 
345
- const cm: Ref<InstanceType<typeof CodeMirror> | undefined> = ref();
346
-
347
- onMounted(() => {
348
- console.log(cm.value?.json);
349
- });
350
- </script>
351
- <template>
352
- <code-mirror ref="cm" />
353
- </template>
354
- ```
355
-
356
- | Function / Parameter | Description |
357
- | -------------------- | --------------------------------------------------------------------------------------------------- |
358
- | view | Get and set [EditorView](https://codemirror.net/docs/ref/#view.EditorView). |
359
- | selection | Get and set the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
360
- | cursor | Get and set the [cursor](https://codemirror.net/docs/ref/#state.EditorSelection^cursor) location. |
361
- | json | Get and set state to a JSON-serializable object. |
362
- | focus | Get and set [focus](https://codemirror.net/docs/ref/#view.EditorView.focus). |
363
- | lint() | Force run linter (Only if `linter` prop is specified) |
364
- | forceReconfigure() | Re register all extensions. |
365
-
366
- ### CodeMirror5 backward compatible functions
367
-
368
- The instructions below are compatible methods for those familiar with [codemirror5](https://codemirror.net/5/).
369
- Since the above method is usually sufficient, its **active use is not recommended**.
370
-
371
- | Function | Description |
372
- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
373
- | getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
374
- | getLine(number: number) | Get the content of line. |
375
- | lineCount() | Get the number of lines in the editor. |
376
- | getCursor() | Retrieve one end of the primary selection. |
377
- | listSelections() | Retrieves a list of all current selections. |
378
- | getSelection() | Get the currently selected code. |
379
- | getSelections() | The length of the given array should be the same as the number of active selections. |
380
- | somethingSelected() | Return true if any text is selected. |
381
- | replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
382
- | replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
383
- | setCursor(position: number) | Set the cursor position. |
384
- | setSelection(anchor: number, head?: number) | Set a single selection range. |
385
- | setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
386
- | extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
387
-
388
- ## WebComponents Feature (Experimental)
389
-
390
- By importing it with CodeMirror, it can also be used as a Web Component.
391
-
392
- ```js
393
- import { CodeMirror } from "vue-codemirror6";
394
-
395
- customElements.define("code-mirror", CodeMirror);
396
- ```
112
+ ### As a Web Component
397
113
 
398
114
  ```html
399
115
  <code-mirror></code-mirror>
400
- ```
401
-
402
- ## Recommendations
403
-
404
- 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.
405
-
406
- ```ts
407
- const config: UserConfig = {
408
- // ...
409
- build: {
410
- rollupOptions: {
411
- output: {
412
- manualChunks: {
413
- // ...
414
- codemirror: ["vue-codemirror6"],
415
- "codemirror-lang": [
416
- // Add the following as needed.
417
- "@codemirror/lang-html",
418
- "@codemirror/lang-javascript",
419
- "@codemirror/lang-markdown",
420
- ],
421
- // ...
422
- },
423
- },
424
- },
425
- },
426
- // ...
427
- };
428
- ```
429
116
 
430
- ## Development
117
+ <script type="module">
118
+ import 'vue-codemirror6/wc-auto';
119
+ import { javascript } from '@codemirror/lang-javascript';
431
120
 
432
- ### Testing
433
-
434
- This project uses [Vitest](https://vitest.dev/) for unit testing.
435
-
436
- ```bash
437
- # Run tests
438
- pnpm test
439
-
440
- # Run tests in watch mode
441
- pnpm test:watch
121
+ const editor = document.querySelector('code-mirror');
122
+ editor.basic = true;
123
+ editor.lang = javascript();
124
+ editor.modelValue = 'console.log("Hello, CodeMirror!");';
125
+ </script>
126
+ ```
442
127
 
443
- # Run tests with UI
444
- pnpm test:ui
128
+ To register a different tag name, import `register` from `vue-codemirror6/wc` and call `register('my-editor')`.
445
129
 
446
- # Run tests with coverage
447
- pnpm test:coverage
448
- ```
130
+ See the [documentation](https://logue.dev/vue-codemirror6/guide/getting-started#using-from-a-cdn-jsdelivr) for details.
449
131
 
450
- The test suite includes:
132
+ ## Links
451
133
 
452
- - **Component Tests**: Testing basic rendering, props, events, and v-model binding
453
- - **SSR Tests**: Ensuring proper server-side rendering compatibility for Nuxt.js and other SSR frameworks
454
- - **Method Tests**: Verifying all exposed methods work correctly
455
- - **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)
456
137
 
457
- ## LICENSE
138
+ ## License
458
139
 
459
140
  ©2022-2026 by Logue.
460
141
  Licensed under the [MIT License](LICENSE).