2.3.3 • Published 7 months ago

monaco-vue3-editor v2.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Monaco Editor Vue3

Monaco Editor is the code editor that powers VS Code, now it's available as a Vue3 component

Install

monaco-vue3-editor 依赖

{
  "peerDependencies": {
    "bkui-vue": "^0.0.2-beta.25",
    "monaco-editor": "^0.41.0",
    "vue": "^3.2.37"
  }
}

monaco-promql 根据项目情况添加

npm i monaco-vue3-editor monaco-editor

开启辅助功能

安装monaco-editor-webpack-plugin这个模块。

npm install monaco-editor-webpack-plugin

在webpack.config.js中进行配置,MonacoWebpackPlugin可以接受language和features来配置辅助功能,具体配置参数可以查看npm官网即可。

webpack

const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
    plugins: [
        new MonacoWebpackPlugin()
    ]
}

vue-cli bkui-cli

module.exports = {
    configureWebpack(_webpackConfig) {
        webpackConfig = _webpackConfig;
        webpackConfig.plugins.push(
            new MonacoWebpackPlugin({
                // available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
                languages: ['json', 'sql']
            }),
        )
    }
}

Usage

import { defineComponent, ref } from 'vue';
import MonacoEditor from 'monaco-vue3-editor';

export default defineComponent({
  name: 'Demo',
  setup() {
    const formData = ref({
      query_text: 'select * from andy',
    });
    return {
      formData,
    };
  },
  render() {
    return (
            <div class='full-page'>
                <div>title</div>
                <div style='height:400px;'>
                    <MonacoEditor
                        theme='vs-dark'
                        language='sql'
                        v-model={this.formData.query_text}
                    />
                </div>
            </div>
    );
  },

});

Props

NameTypeDefaultDescriptionremark
v-modelstringdefault value of the current model
languagestringlanguage of the current modellanguages supported by monaco-editor view here
themestringvs-darkVS code themetheme of the monaco-editormonaco.editor.defineTheme(...)
diffEditorbooleanfalsetheme of the monaco-editormonaco.editor.defineTheme(...)
isShowHeaderbooleantruewhether show headertheme of the monaco-editormonaco.editor.defineTheme(...)
titlestring | title content | theme of the monaco-editor | monaco.editor.defineTheme(...)
isShowToolboxbooleantruewhether show Toolboxtheme of the monaco-editormonaco.editor.defineTheme(...)
isShowTooltipsbooleantruewhether show Toolbox Tooltipstheme of the monaco-editormonaco.editor.defineTheme(...)
currentLangstringToolbox tooltips defualt langtheme of the monaco-editormonaco.editor.defineTheme(...)
tooltipsobject
optionsobject{}IStandaloneEditorConstructionOptions
widthnumberstring100%container width
heightnumberstring100%container height
onBeforeMount(monaco: Monaco, dom:HTMLElement) => voidexecute before the editor instance is created

Event

NameTypeDefaultDescriptionremark
onEditorMounted(editor: monaco.editor.IStandaloneCodeEditor, monaco: Monaco,dom:HTMLElement) => voidexecute after the editor instance has been created
onChange(value: string)execute when the changed value changemonaco.editor.IModelContentChangedEvent) => void

slots

NameDescription
loadingBefore Monaco init show
toolstools
titletitle

expose

 expose({
  isFull,
  style,
  editor,
  domRef,
  loading,
  clearMistake,
  formatContext,
  fullScreen,
  resize,
});

tooltips

tools tooltips

propsvalue
formatFormat
fullScreenFull Screen
exitScreenExit Full Screen
adjustFontSizeAdjusting the font size
function getTooltips() {
      if (props?.tooltips) {
        return props.tooltips;
      }
      const currentLang = props?.currentLang ?? localStorage.getItem('blueking_language');

      if (currentLang === 'en') {
        return {
          format: 'Format',
          fullScreen: 'Full Screen',
          exitScreen: 'Exit Full Screen',
          adjustFontSize: 'Adjusting the font size',
        };
      }
      return {
        format: '格式化',
        fullScreen: '全屏',
        exitScreen: '退出全屏',
        adjustFontSize: '调整字号大小',
      };
    }
2.3.3

7 months ago

2.2.9

8 months ago

2.2.8

8 months ago

2.3.0

8 months ago

2.2.1

8 months ago

2.3.2

8 months ago

2.2.3

8 months ago

2.3.1

8 months ago

2.2.2

8 months ago

2.2.5

8 months ago

2.2.4

8 months ago

2.2.7

8 months ago

2.2.6

8 months ago

2.1.0

8 months ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago