Giter Site home page Giter Site logo

siyidev / codemirror-editor-vue3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rennzhang/codemirror-editor-vue3

0.0 0.0 0.0 2.5 MB

CodeMirror component for Vue3

Home Page: https://rennzhang.github.io/codemirror-editor-vue3

License: MIT License

Shell 1.24% JavaScript 2.67% TypeScript 55.23% CSS 3.28% HTML 0.64% Vue 34.54% Less 2.40%

codemirror-editor-vue3's Introduction

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 [email protected] -S
yarn add codemirror-editor-vue3 codemirror@">=5.64.0 <6"
pnpm i codemirror-editor-vue3 codemirror@">=5.64.0 <6" -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 { InstallCodemirro } from "codemirror-editor-vue3";

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

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

app.use(InstallCodemirro, { 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>

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:

<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

codemirror-editor-vue3's People

Contributors

rennzhang avatar nichtich avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.