All Projects → egoist → Vue Monaco

egoist / Vue Monaco

Licence: mit
MonacoEditor component for Vue.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Monaco

Monaco Editor
A browser based code editor
Stars: ✭ 27,382 (+5713.59%)
Mutual labels:  vscode, editor, monaco-editor
Monacode
An es-module wrapper around the monaco editor and prettier
Stars: ✭ 137 (-70.91%)
Mutual labels:  vscode, editor
Vscoq
A Visual Studio Code extension for Coq [[email protected],@fakusb]
Stars: ✭ 138 (-70.7%)
Mutual labels:  vscode, editor
Vscode Chrome Debug
Debug your JavaScript code running in Google Chrome from VS Code.
Stars: ✭ 2,126 (+351.38%)
Mutual labels:  vscode, editor
Monaco React
Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins
Stars: ✭ 788 (+67.3%)
Mutual labels:  vscode, editor
Cn Vscode Docs
VScode说明文档翻译
Stars: ✭ 970 (+105.94%)
Mutual labels:  vscode, editor
Vscodium
binary releases of VS Code without MS branding/telemetry/licensing
Stars: ✭ 14,639 (+3008.07%)
Mutual labels:  vscode, editor
React Monaco Editor
Monaco Editor for React.
Stars: ✭ 2,536 (+438.43%)
Mutual labels:  editor, monaco-editor
Synedit
SynEdit main project
Stars: ✭ 324 (-31.21%)
Mutual labels:  editor, component
Vue Designer
Vue component design tool
Stars: ✭ 333 (-29.3%)
Mutual labels:  editor, component
Vscode Vuehelper
🐵vscode插件,vue,vue-router和vuex的代码提示
Stars: ✭ 351 (-25.48%)
Mutual labels:  vscode, editor
Monaco Languageclient
NPM module to connect Monaco editor with language servers
Stars: ✭ 419 (-11.04%)
Mutual labels:  vscode, monaco-editor
Vue Tinymce Editor
This a component provides use of tinymce for vue developers
Stars: ✭ 216 (-54.14%)
Mutual labels:  editor, component
Vuerd Vscode
ERD Editor vscode extension
Stars: ✭ 95 (-79.83%)
Mutual labels:  vscode, editor
Vue Monaco Editor
Monaco Editor Vue Component
Stars: ✭ 187 (-60.3%)
Mutual labels:  editor, monaco-editor
Yn
Yank Note 一款面向程序员的 Markdown 笔记应用。支持加密文档,代码片段运行,内置终端,图表嵌入,HTML 小工具。
Stars: ✭ 143 (-69.64%)
Mutual labels:  vscode, monaco-editor
Object Editor React
Schema-aware editor for structured JSON objects (drop-in React component)
Stars: ✭ 104 (-77.92%)
Mutual labels:  editor, component
Tagger
Zero Dependency, Vanilla JavaScript Tag Editor
Stars: ✭ 135 (-71.34%)
Mutual labels:  editor, component
Vuerd
ERD Editor
Stars: ✭ 208 (-55.84%)
Mutual labels:  vscode, editor
For Editor
for-editor - A markdown editor based on React
Stars: ✭ 358 (-23.99%)
Mutual labels:  editor, component

vue-monaco

NPM version NPM downloads CircleCI donate

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

Install

npm install vue-monaco

Or

yarn add vue-monaco

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 class="editor" v-model="code" language="javascript" />
</template>

<script>
import MonacoEditor from 'vue-monaco'

export default {
  components: {
    MonacoEditor
  },

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

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

Use AMD version

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  </head>
  <body>
    <div id="app"></div>

    <script src="https://unpkg.com/vue"></script>
    <script src="https://unpkg.com/vue-monaco"></script>
    <script src="monaco-editor/min/vs/loader.js"></script>
    <script>
      require.config({ paths: { vs: 'monaco-editor/min/vs' } })

      new Vue({
        el: '#app',
        template: `
          <monaco-editor
            style="width:800px;height:600px;border:1px solid grey"
            v-model="code" 
            language="javascript" 
            :amdRequire="amdRequire"
          />`,
        data: {
          code: 'const noop = () => {}'
        },
        methods: {
          amdRequire: require
        }
      })
    </script>
  </body>
</html>

When loading monaco-editor from a CDN, you need to change require.config to look like this:

require.config({ paths: { vs: 'http://www.mycdn.com/monaco-editor/min/vs' } })

// Before loading vs/editor/editor.main, define a global MonacoEnvironment that overwrites
// the default worker url location (used when creating WebWorkers). The problem here is that
// HTML5 does not allow cross-domain web workers, so we need to proxy the instantiation of
// a web worker through a same-domain script
window.MonacoEnvironment = {
  getWorkerUrl: function(workerId, label) {
    return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
        self.MonacoEnvironment = {
          baseUrl: 'http://www.mycdn.com/monaco-editor/min/'
        };
        importScripts('http://www.mycdn.com/monaco-editor/min/vs/base/worker/workerMain.js');`)}`
  }
}

Props

  • 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.
  • amdRequire: Load monaco-editor using given amd-style require function.
  • diffEditor: boolean Indicate that this is a DiffEditor, false by default.

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.

Methods

Use ref to interact with the MonacoEditor component in order to access methods: <MonacoEditor ref="editor" />, then this.$refs.editor.getEditor() will be available.

Use the DiffEditor

Use diffEditor prop to indicate that this is a DiffEditor, use original prop to set the content for the original editor, use value prop to set the content for the modified editor.

<MonacoEditor
  language="javascript"
  :diffEditor="true"
  :value="code"
  :original="originalCode"
/>

In this case, the component's getEditor() returns the IStandaloneDiffEditor instance, while you can use getModifiedEditor() to get the modified editor which is an IStandaloneCodeEditor instance.

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

vue-monaco © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

Website · GitHub @egoist · Twitter @_egoistlily

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].