Giter Site home page Giter Site logo

monaco-editor-vue3's Introduction

Monaco Editor Vue3

npm npm NPM npm bundle size

Monaco Editor is the code editor that powers VS Code, now it's available as a Vue3 component <MonacoEditor> thanks to this project.

Install

pnpm install monaco-editor-vue3

Or

yarn add monaco-editor-vue3

Or

npm i monaco-editor-vue3

Usage

Use ESM version with webpack

Use monaco-editor-webpack-plugin:

// webpack.config.js
const MonacoEditorPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
  plugins: [
    new MonacoEditorPlugin({
      // https://github.com/Microsoft/monaco-editor-webpack-plugin#options
      // Include a subset of languages support
      // Some language extensions like typescript are so huge that may impact build performance
      // e.g. Build full languages support with webpack 4.0 takes over 80 seconds
      // Languages are loaded on demand at runtime
      languages: ['javascript', 'css', 'html', 'typescript'],
    }),
  ],
};

Then use the component:

<template>
  <MonacoEditor
    theme="vs"
    :options="options"
    language="javascript"
    :width="800"
    :height="800"
    :diffEditor="true"
    :original="original"
    v-model:value="value"
  ></MonacoEditor>
</template>

<script>
import MonacoEditor from 'monaco-editor-vue3';

export default {
  components: {
    MonacoEditor,
  },

  data() {
    return {
      code: 'const noop = () => {}',
    };
  },
};
</script>

<style>
.editor {
  width: 600px;
  height: 800px;
}
</style>

Use ESM version with Vite

See Stackblitz Demo

Use ESM version with rollup

Use rollup-plugin-monaco-editor:

// rollup.config.js
import { nodeResolve } from '@rollup/plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import commonjs from '@rollup/plugin-commonjs';
import monaco from 'rollup-plugin-monaco-editor';

export default {
  output: {
    format: 'es',
    dir: 'dist',
  },
  // ...other config
  plugins: [
    // ...other plugins
    // handle .css files
    postcss(),
    monaco({
      languages: ['json'],
    }),
    nodeResolve(),
    commonjs(),
  ],
};

Props

  • width: Editor width, eg: 800px or 800.
  • height: Editor height, eg: 800px or 800.
  • options: The second argument of monaco.editor.create.
  • value: A shortcut to set options.value.
  • theme: A shortcut to set options.theme.
  • language: A shortcut to set options.language.
  • diffEditor: boolean Indicate that this is a DiffEditor, false by default.
  • original: if diffEditor set true, this will be used .

Component Events

editorWillMount

Called before mounting the editor.

editorDidMount

Called when the editor is mounted.

change

Editor value is updated.

Editor Events

You can listen to the editor events directly like this:

<template>
  <MonacoEditor v-model="code" @editorDidMount="editorDidMount" />
</template>

<script>
export default {
  methods: {
    editorDidMount(editor) {
      // Listen to `scroll` event
      editor.onDidScrollChange((e) => {
        console.log(e);
      });
    },
  },

  data() {
    return {
      code: '...',
    };
  },
};
</script>

Refer to this page for all editor events.

Typescript

create monaco-editor-vue3.d.ts in your root.

declare module 'monaco-editor-vue3';

This will allow ts compilation without errors, but may not include all the types.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

Monaco Editor Vue3 © bazingaedward, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

monaco-editor-vue3's People

Contributors

bazingaedward avatar josef-friedrich avatar liaronce avatar qasimrazvi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

monaco-editor-vue3's Issues

Docs pointing to wrong dependency

Hello, I am unsure if this is really the right way of doing it but, it seems that the readme is using the wrong reference when injecting the component.

import MonacoEditor from 'vue-monaco'

by changing this line to this line

import MonacoEditor from 'monaco-editor-vue3';

Now monaco in properly injected.

Am I the only one having this problem?

emit failed

v-model:value
can't update outside prop var

代码展开图标丢失

image
我看官方仓库有相关的issus,但是是css-loader的问题,vite的rollup貌似没有相关的loader,我查到说是vite内部自行处理css文件?

在Vue3+Vite+TS项目中使用报错 Component is missing template or render function.

问题

我根据 See Stackblitz Demo 中的DEMO在我的项目上使用了 monaco-editor-vue3,但遇到了控制台报错 Component is missing template or render function.,同时在页面上也未展示出monaco编辑器组件
image

我也尝试在 Stackblitz 在线演示中检查,发现存在同样的问题
image

环境

  • Windows 11
  • Vite ^4.3.9
  • Vue ^3.3.4
  • TypeScript ^5.0.2

期望

期待得到您的支持与解决 👍

New release

The last release was over a year ago.
Is it possible to get a new release?

Unexpected usage at EditorSimpleWorker

I get this error in the console. It still works however..

Error: Unexpected usage at EditorSimpleWorker.loadForeignModule (webpack-internal:///./node_modules/monaco-editor-vue3/node_modules/monaco-editor/esm/vs/editor/common/services/editorSimpleWorker.js:480:31) at eval (webpack-internal:///./node_modules/monaco-editor-vue3/node_modules/monaco-editor/esm/vs/editor/browser/services/webWorker.js:44:30) Error: Unexpected usage

How to configure it with Vite

I was able to integrate and bring the UI part but wasn't able to understand the webpack or the rollup part.
Can anyone help, how do I use this with vite. Steps would be nice please or a demo would be great.

Unnecessary blank space at the end

The scroll appears after I press enter on the first line so when I write a lot of lines, there is a blank space at the end of the editor when I scroll down. I think the scroll should appear after I press enter in the last line of the editor according to the height. How to solve this?

how to get `monaco-editor` instance?

I use monaco-editor as sql editor, i want to add sql syntax prompt, I find official document has anguages.registerCompletionItemProvider function, so i how to get monaco-editor instance?

如何进行校验

如何对编辑器内容进行校验,比如 json 格式内容,我看官方的实例好像跟这个不太一样,这个没有 languages,我看了很多资料。
不知道具体有用例,我尝试用ajv等,但是找不到入手点

after import 'monaco-editor-vue3', quasar hmr doesn't work

After a few days of struggle, I finally found out why hmr doesn't work properly in quasar. When I comment the line below everything works!

import MonacoEditor from "monaco-editor-vue3";

my quasar version is:

 » Dev mode............... spa
 » Pkg quasar............. v2.16.6
 » Pkg @quasar/app-vite... v2.0.0-beta.15

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.