Gathering detailed insights and metrics for vue-codemirror6
Gathering detailed insights and metrics for vue-codemirror6
Gathering detailed insights and metrics for vue-codemirror6
Gathering detailed insights and metrics for vue-codemirror6
@amoayun/vue-codemirror
基于vue3的一款codemirror,简单实用,支持双向绑定。CodeMirror6 Component for vue3.
@sinau/codemirror6
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
⌨️ @codemirror 6 component for @vuejs. Vue2 & Vue3 both supported.
npm install vue-codemirror6
Typescript
Module System
Node Version
NPM Version
67.3
Supply Chain
98.7
Quality
87.4
Maintenance
100
Vulnerability
100
License
TypeScript (52.88%)
Vue (33.7%)
JavaScript (9.15%)
SCSS (2.4%)
HTML (1.86%)
Total Downloads
171,046
Last Day
838
Last Week
5,342
Last Month
15,868
Last Year
113,935
156 Stars
188 Commits
21 Forks
5 Watching
7 Branches
5 Contributors
Minified
Minified + Gzipped
Latest Version
1.3.10
Package Id
vue-codemirror6@1.3.10
Unpacked Size
108.53 kB
Size
26.11 kB
File Count
18
NPM Version
10.9.2
Node Version
23.5.0
Publised On
08 Jan 2025
Cumulative downloads
Total Downloads
Last day
-30.7%
838
Compared to previous day
Last week
15.2%
5,342
Compared to previous week
Last month
66.9%
15,868
Compared to previous month
Last year
150%
113,935
Compared to previous year
8
1
43
A component for using CodeMirror6 with Vue. This component works in both Vue2 and Vue3.
1yarn add vue-codemirror6 codemirror
For Vue 2.7 or below, @vue/composition-api is required separately.
1yarn add vue-codemirror6 @vue/composition-api
This component can handle bidirectional binding by v-model
like a general Vue component.
Props | Type | Information |
---|---|---|
model-value | string | Text | Text value. (Not value ) |
basic | boolean | Use basicSetup. |
minimal | boolean | Use miniSetup. If a basic prop is also specified, that setting will take precedence. |
dark | boolean | Toggle Darkmode. |
placeholder | string | Add placeholder text (or HTML DOM) when blank |
wrap | boolean | Line text wrapping. see lineWrapping. |
tab | boolean | Enables tab indentation. |
allow-multiple-selections | boolean | Allow Multiple Selection. See allowMultipleSelections |
tab-size | number | Configures the tab size to use in this state. |
line-separator | string | Set line break (separetor) char. (Default is \n .) |
theme | { [selector: string]: StyleSpec } | Specify the theme. For example, if you use @codemirror/theme-one-dark, import oneDark and put it in this prop. |
readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
disabled | boolean | This is the reversed value of the CodeMirror editable. Similar to readonly , but setting this value to true disables dragging. |
lang | LanguageSupport | The language you want to have syntax highlighting. see https://codemirror.net/6/#languages |
phrases | Record<string, string> | Specify here if you want to make the displayed character string multilingual. see https://codemirror.net/6/examples/translate/ |
extensions | Extension[] | Includes enhancements to extend CodeMirror. |
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. |
linterConfig | Object | see https://codemirror.net/docs/ref/#lint.linter^config |
forceLinting | boolean | see https://codemirror.net/docs/ref/#lint.forceLinting |
gutter | boolean | Display 🔴 on the line where there was an error when linter was specified. It will not work if linter is not specified. |
gutterConfig | Object | see https://codemirror.net/docs/ref/#lint.lintGutter^config |
tag | string | HTML tags used in the component. (Default is div tag.) |
⚠ 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.
@codemirror/lang-angular
@codemirror/lang-cpp
@codemirror/lang-css
@codemirror/lang-html
@codemirror/lang-java
@codemirror/lang-javascript
@codemirror/lang-json
@codemirror/lang-lezer
@codemirror/lang-markdown
@codemirror/lang-php
@codemirror/lang-python
@codemirror/lang-rust
@codemirror/lang-sql
@codemirror/lang-vue
@codemirror/lang-west
@codemirror/lang-xml
@acarl005/lang-sql
@ark-us/codemirror-lang-taylor
@formulavize/lang-fiz
@gravitywiz/codemirror-lang-gfcalc
@nextjournal/lang-clojure
@plutojl/lang-julia
@polybase/codemirror-lang-javascript
-@replit/codemirror-lang-nix
@replit/codemirror-lang-csharp
@replit/codemirror-lang-solidity
@replit/codemirror-lang-svelte
@zhijiu/lang-sql
codemirror-lang-bool
codemirror-lang-brainfuck
codemirror-lang-cherry
codemirror-lang-chordpro
codemirror-lang-circom
codemirror-lang-edn
codemirror-lang-ejs
codemirror-lang-fsl
codemirror-lang-gml
codemirror-lang-golfscript
codemirror-lang-homescript
codemirror-lang-html-n8n
codemirror-lang-inform7
codemirror-lang-j
codemirror-lang-janet
codemirror-lang-k
codemirror-lang-karol
codemirror-lang-mermaid
codemirror-lang-n8n-expression
codemirror-lang-prolog
codemirror-lang-qpen
codemirror-lang-qtam
codemirror-lang-r
codemirror-lang-rome-ast
codemirror-lang-rome
codemirror-lang-rush
codemirror-lang-scopescript
codemirror-lang-statement
gcode-lang-codemirror
gmail-lang
lang-bqn
lang-clojure
lang-d
lang-feel
lang-firestore
Mark up as follows to make it work at a minimum.
1<template> 2 <code-mirror v-model="value" /> 3</template> 4 5<script> 6import { ref, defineComponent } from 'vue'; 7 8import CodeMirror from 'vue-codemirror6'; 9 10export default defineComponent({ 11 components: { 12 CodeMirror, 13 }, 14 setup() { 15 const value = ref('Cozy lummox gives smart squid who asks for job pen.'); 16 17 return { value }; 18 }, 19}); 20</script>
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
.
Also, insert a <pre>
tag to prevent the text in the slot from being automatically formatted.
1<template> 2 <code-mirror :lang="lang" :linter="linter"> 3 <pre> 4{ 5 "key": "value" 6}</pre 7 > 8 </code-mirror> 9</template> 10 11<script> 12import { ref, defineComponent } from 'vue'; 13 14import { json, jsonParseLinter } from '@codemirror/lang-json'; 15 16import CodeMirror from 'vue-codemirror6'; 17 18export default defineComponent({ 19 components: { 20 CodeMirror, 21 }, 22 setup() { 23 const lang = json(); 24 const linter = jsonParseLinter(); 25 return { lang, linter }; 26 }, 27}); 28</script>
When using as a Markdown editor on https://github.com/logue/vite-vue3-ts-starter.
1<script lang="ts" setup> 2import { ref, defineComponent, type Ref } from 'vue'; 3 4// Load component 5import CodeMirror from 'vue-codemirror6'; 6 7// CodeMirror extensions 8import { markdown as md } from '@codemirror/lang-markdown'; 9import type { LanguageSupport } from '@codemirror/language'; 10import type { Extension } from '@codemirror/state'; 11import type { ViewUpdate } from '@codemirror/view'; 12 13/** text */ 14const value: Ref<string> = ref(''); 15 16/** Dark mode **/ 17const dark: Ref<boolean> = ref( 18 window.matchMedia('(prefers-color-scheme: dark)').matches 19); 20 21/** 22 * CodeMirror Language 23 * 24 * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language} 25 */ 26const lang: LanguageSupport = md(); 27 28/** 29 * Internationalization Config. 30 * In this example, the display language to Japanese. 31 * Must be reactive when used in combination with vue-i18n. 32 * 33 * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization} 34 */ 35const phrases: Record<string, string> = { 36 // @codemirror/view 37 'Control character': '制御文字', 38 // @codemirror/commands 39 'Selection deleted': '選択を削除', 40 // @codemirror/language 41 'Folded lines': '折り畳まれた行', 42 'Unfolded lines': '折り畳める行', 43 to: '行き先', 44 'folded code': '折り畳まれたコード', 45 unfold: '折り畳みを解除', 46 'Fold line': '行を折り畳む', 47 'Unfold line': '行の折り畳む解除', 48 // @codemirror/search 49 'Go to line': '行き先の行', 50 go: 'OK', 51 Find: '検索', 52 Replace: '置き換え', 53 next: '▼', 54 previous: '▲', 55 all: 'すべて', 56 'match case': '一致条件', 57 'by word': '全文検索', 58 regexp: '正規表現', 59 replace: '置き換え', 60 'replace all': 'すべてを置き換え', 61 close: '閉じる', 62 'current match': '現在の一致', 63 'replaced $ matches': '$ 件の一致を置き換え', 64 'replaced match on line $': '$ 行の一致を置き換え', 65 'on line': 'した行', 66 // @codemirror/autocomplete 67 Completions: '自動補完', 68 // @codemirror/lint 69 Diagnostics: 'エラー', 70 'No diagnostics': 'エラーなし', 71}; 72</script> 73 74<template> 75 <code-mirror 76 v-model="value" 77 basic 78 :dark="dark" 79 :lang="lang" 80 :phrases="phrases" 81 /> 82</template>
Event | Description |
---|---|
ready | When CodeMirror loaded. |
focus | When focus changed. |
update | When CodeMirror state changed. Returns ViewUpdate object. |
change | Value changed. Returns EditorState |
1<script setup lang="ts"> 2import { ref, onMounted, type Ref, type PropType } from 'vue'; 3import CodeMirror from 'vue-codemirror6'; 4 5const cm: Ref<InstanceType<typeof CodeMirror> | undefined> = ref(); 6 7onMounted(() => { 8 console.log(cm.value?.json); 9}); 10</script> 11<template> 12 <code-mirror ref="cm" /> 13</template>
Function / Parameter | Description |
---|---|
view | Get and set EditorView. |
selection | Get and set the EditorSelection instance. |
cursor | Get and set the cursor location. |
json | Get and set state to a JSON-serializable object. |
focus | Get and set focus. |
lint() | Force run linter (Only if linter prop is specified) |
forceReconfigure() | Re register all extensions. |
The instructions below are compatible methods for those familiar with codemirror5. Since the above method is usually sufficient, its active use is not recommended.
Function | Description |
---|---|
getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
getLine(number: number) | Get the content of line. |
lineCount() | Get the number of lines in the editor. |
getCursor() | Retrieve one end of the primary selection. |
listSelections() | Retrieves a list of all current selections. |
getSelection() | Get the currently selected code. |
getSelections() | The length of the given array should be the same as the number of active selections. |
somethingSelected() | Return true if any text is selected. |
replaceRange(replacement: string | Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
replaceSelection(replacement: string | Text) | Replace the selection(s) with the given string. |
setCursor(position: number) | Set the cursor position. |
setSelection(anchor: number, head?: number) | Set a single selection range. |
setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
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
option at build time as shown below.
1const config: UserConfig = { 2 // ... 3 build: { 4 rollupOptions: { 5 output: { 6 manualChunks: { 7 // ... 8 codemirror: [ 9 // Split CodeMirror code. 10 'vue-codemirror6', 11 'codemirror', 12 '@codemirror/autocomplete', 13 '@codemirror/commands', 14 '@codemirror/language', 15 '@codemirror/lint', 16 '@codemirror/search', 17 '@codemirror/state', 18 '@codemirror/view', 19 ], 20 'codemirror-lang': [ 21 // Add the following as needed. 22 '@codemirror/lang-html', 23 '@codemirror/lang-javascript', 24 '@codemirror/lang-markdown', 25 ], 26 // ... 27 }, 28 }, 29 }, 30 }, 31 // ... 32};
©2022-2025 by Logue. Licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.