Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

codemirror-editor-vue3

rennzhang50kMIT2.8.0TypeScript support: included

CodeMirror component for Vue3

codemirror-editor-vue3, vue3 codemirror, codemirror, vue3, log mode, log

readme

GitHub stars npm downloads GitHub issues GitHub forks GitHub last commit license

Introduction

简体中文

The codemirror component of vue3. This component is developed based on Codemirror 5 and only vue3 is supported.

In addition to the officially supported modes, the log output presentation mode is added, out of the box, but not necessarily suitable for all scenarios.

For complete documentation and more cases, please check codemirror-editor-vue3 docs.

Install

npm install codemirror-editor-vue3 codemirror@^5 -S
yarn add codemirror-editor-vue3 codemirror@">=5.64.0 <6"
pnpm i codemirror-editor-vue3 codemirror@^5 -S

If your project requires Typescript support, you will also need to install the '@types/codemirror' dependency.

npm install @types/codemirror -D

Register global component

Do not recommend global registration components, which will result in the type of prompt on the template that cannot be properly obtained.

main.js:

import { createApp } from "vue";
import App from "./App.vue";
import { InstallCodeMirror } from "codemirror-editor-vue3";

const app = createApp(App);
app.use(InstallCodeMirror);
app.mount("#app");

The global registered component name is Codemirror or you can customize a component name, for example:

app.use(InstallCodeMirror, { componentName: "customName" });

Use in components

<template>
  <Codemirror
    v-model:value="code"
    :options="cmOptions"
    border
    placeholder="test placeholder"
    :height="200"
    @change="change"
  />
</template>

<script>
import Codemirror from "codemirror-editor-vue3";

// placeholder
import "codemirror/addon/display/placeholder.js";

// language
import "codemirror/mode/javascript/javascript.js";
// placeholder
import "codemirror/addon/display/placeholder.js";
// theme
import "codemirror/theme/dracula.css";

import { ref } from "vue";
export default {
  components: { Codemirror },
  setup() {
    const code = ref(`
var i = 0;
for (; i < 9; i++) {
  console.log(i);
  // more statements
}`);

    return {
      code,
      cmOptions: {
        mode: "text/javascript", // Language mode
        theme: "dracula", // Theme
      },
    };
  },
};
</script>

Language highlighting

You can click on the following link to view corresponding language cases

More cases are gradually being added, and you can also refer to document to achieve more language modes.

Component Props

name description type default
value(v-model) Editor content string ""
options Configuration options of codemirror5 EditorConfiguration DEFAULT_OPTIONS
placeholder Editor placeholder content to introduce codemirror related files string ""
border Whether to display editor borders boolean false
width width string 100%
height height string 100%
original-style Using the original style, disable the second modification of the style for this component (but does not affect width, height, and border) boolean false
KeepCursorInEnd Always keep the mouse position on the last line boolean false
merge merge mode, can also be used as diff pattern boolean false

Events

Component Events

The following three are only the events encapsulated by this component. Please refer to more events Codemirror Events

event name description params
change value or instance changes (value: string, cm: Editor) => void
input input (value: string) => void
ready The Codemirror component is mounted (cm: Editor) => void;

Codemirror Events

The following events are official events of Codemirror5. You can refer to the official documents for details Codemirror Event,You can use this component to bind events directly through components, for example:

vue {8-10} <Codemirror v-model:value="code" :options="{ mode: 'text/x-vue', theme: 'default' }" border placeholder="test-placeholder" :height="200" @change="onChange" @blur="onBlur" @focus="onFocus" @scroll="onScroll" />

All event names are as follows:

  • changes
  • scroll
  • beforeChange
  • cursorActivity
  • keyHandled
  • inputRead
  • electricInput
  • beforeSelectionChange
  • viewportChange
  • swapDoc
  • gutterClick
  • gutterContextMenu
  • focus
  • blur
  • refresh
  • optionChange
  • scrollCursorIntoView
  • update

changelog

2.8.0 (2024-09-20)

2.8.0-beta.0 (2024-09-20)

Features

  • 去除不必要的dependencies依赖 (b35d6e1)

2.7.1 (2024-09-05)

Bug Fixes

  • #54: handle empty value in isStringNumber function (10cab8b), closes #54

2.7.0 (2024-06-13)

Features

  • 调整useViewControl逻辑 (8979694)

2.6.1 (2024-06-13)

Bug Fixes

  • 文档打包忽略特定地址 (db91b82)
  • 修复跳转错误 (40a6b82)

Features

  • 调整文档首页样式 (50a2df0)

2.6.0 (2024-06-11)

2.6.0-beta.0 (2024-06-11)

Features

  • 文档更新,支持配置生成案例 (dca8355)

2.5.8 (2024-04-07)

Features

  • 🌟 Document optimization: adding code validation cases
  • 🌟 Document optimization: Change search to MiniSearch(f0e0880)
  • 🌟 Width and height support percentage, removing excess styles
  • 🐞 Fix some known issues

  • 🌟 文档优化:增加代码校验案例
  • 🌟 文档优化:搜索改用MiniSearch (f0e0880)
  • 🌟 宽高支持百分比,去除多余样式
  • 🐞 修复一些已知问题

Bug Fixes

2.4.1 (2023-11-07)

2.4.0 (2023-11-07)

2.4.0-beta.1 (2023-11-07)

2.3.1 (2023-11-06)

Bug Fixes

Features

2.3.0 (2023-03-07)

2.3.0-beta.1 (2023-03-07)

2.3.0-beta2 (2023-03-07)

Bug Fixes

  • Repair the packaging issues lead to cannot be highlighted (a355314)

2.2.1 (2023-03-03)

2.2.0 (2023-02-09)

2.1.9-beta1 (2023-02-09)

Bug Fixes

  • Data not updated when all code is selected for deletion(#30) (95b43ea)

2.1.8 (2023-01-31)

2.1.7 (2022-06-06)

Bug Fixes

2.1.6 (2022-06-02)

Bug Fixes

  • type: change codemirror event type(#19) (f29a9f5)

2.1.4 (2022-05-29)

Bug Fixes

  • 取出 emit 出现警告 (882d120)

Features

  • Set the default height to 200 (1faa2f9)

2.1.3

2022-05-07

  • 🌟 feat: Provides an option to turn off automatic style injection. Disable the plugin's secondary modifications and direct injection of styles into this header, removing all '! important` #17

  • ⚙️ type: Ts type adjustment, better TS support.


  • 🌟 新功能: 提供关闭自动样式注入的选项,禁用本插件二次修改并直接注入到此头部的样式,去掉所有的!important #17

  • ⚙️ 类型: ts 类型调整,更好的 ts 支持

2.0.6

2022-03-23

  • 🐞 fix: Repair "PlaceHolder" cannot respond to update issues #15

  • 🐞 fix: 修复 "PlaceHolder" 不能响应式更新的 bug #15

2.0.4

2022-03-17

  • 🐞 Fix the problem that the merge mode failed to be used. #14
  • 🌟 Add ts type: get the type of component through ref CmComponentRef.

  • 🐞 修复 merge 模式报错无法使用问题 #14
  • 🌟 增加 ts 类型:通过 ref 获取组件的类型CmComponentRef

2.0.3

2022-03-15

  • 🐞 Repair cannot dynamically set the width and height #11.

  • 🐞 修复无法动态设置宽度和高度问题 #11

2.0.2

2022-03-10

  • 🐞 Fix the log mode, createTitle function parameters Symbol has no default value.

  • 🐞 修复 log 模式中, createTitle 函数参数 symbol 没有默认值问题

2.0.1

2022-03-09

  • 🐞 Fix errors in README

  • 🐞 修复 README 中错误

2.0.0

2022-03-08

  • 🌟 Use TS reconstruction partial code, fully support TS type check.
    • Modify registration global component mode

  • 🌟 使用 ts 重构部分代码,全面支持 ts 类型检查
    • 修改注册全局组件方式

1.0.1

2022-01-04

  • 🌟 Change the version number only.

  • 🌟 仅修改版本号

0.3.5

2021-12-16

  • 🌟 Update part of document content
  • 🐞 Fix the problem that this component is used in pop-up boxes or other animation effects, and changes the value before the animation ends, resulting in style disorder.

  • 🌟 更新文档部分内容
  • 🐞 修复本组件在弹出框或其他带有动画效果中使用,在动画结束前改变 value 导致样式错乱的问题

0.3.2

2021-12-15

  • 🌟 Support styles to be automatically injected into the head tag, and there is no need to introduce component styles separately. (The related styles of codemirror itself still need to be introduced manually)
  • 🌟 Increase the support of KeepCursorInEnd attribute, which can only be used in fclog mode.
  • 🌟 Refactor partial code.
  • 🐞 Fix cannot call the scrollTo method of the instance.

  • 🌟 支持组件样式自动注入 head 标签中,不需要单独引入组件样式。(codemirror 本身的相关样式依然需要手动引入)
  • 🌟 所有模式都可以使用 KeepCursorInEnd 属性,之前只能在fclog模式中使用
  • 🌟 重构部分代码
  • 🐞 修复不能调用实例的 scrollTo 方法问题

0.2.4

2021-09-08

  • Delete useless dependencies

v0.2.3

2021-09-01

  • Update the readme to English