react monacoeditor
v3.6.0
摩納哥編輯器組件。 demo @uiwjs.github.io/react-monacoeditor/
npm install @uiw/react-monacoeditor --save import React from 'react' ;
import MonacoEditor from '@uiw/react-monacoeditor' ;
export default function Demo ( ) {
return (
< MonacoEditor
language = "html"
value = "<h1>I ♥ react-monacoeditor</h1>"
height = "300px"
options = { {
theme : 'vs-dark' ,
} }
/>
) ;
} import React from 'react' ;
import { render } from 'react-dom' ;
import MonacoEditor from '@uiw/react-monacoeditor' ;
const code = `import React, { PureComponent } from 'react';
import MonacoEditor from '@uiw/react-monacoeditor';
export default class App extends PureComponent {
render() {
return (
<MonacoEditor
language="html"
value="<h1>I ♥ react-codemirror2</h1>"
options={{
selectOnLineNumbers: true,
roundedSelection: false,
cursorStyle: 'line',
automaticLayout: false,
theme: 'vs-dark',
}}
/>
);
}
}
` ;
class App extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
code : '// type your code...' ,
}
}
editorDidMount ( editor , monaco ) {
console . log ( 'editorDidMount' , editor , monaco ) ;
editor . focus ( ) ;
}
onChange ( newValue , e ) {
console . log ( 'onChange' , newValue , e ) ;
}
render ( ) {
const options = {
selectOnLineNumbers : true ,
roundedSelection : false ,
readOnly : false ,
cursorStyle : 'line' ,
automaticLayout : false ,
theme : 'vs-dark' ,
scrollbar : {
// Subtle shadows to the left & top. Defaults to true.
useShadows : false ,
// Render vertical arrows. Defaults to false.
verticalHasArrows : true ,
// Render horizontal arrows. Defaults to false.
horizontalHasArrows : true ,
// Render vertical scrollbar.
// Accepted values: 'auto', 'visible', 'hidden'.
// Defaults to 'auto'
vertical : 'visible' ,
// Render horizontal scrollbar.
// Accepted values: 'auto', 'visible', 'hidden'.
// Defaults to 'auto'
horizontal : 'visible' ,
verticalScrollbarSize : 17 ,
horizontalScrollbarSize : 17 ,
arrowSize : 30 ,
} ,
} ;
return (
< MonacoEditor
height = "500px"
language = "javascript"
editorDidMount = { this . editorDidMount . bind ( this ) }
onChange = { this . onChange . bind ( this ) }
value = { code }
options = { options }
/>
) ;
}
}
render (
< App /> ,
document . getElementById ( 'root' )
) ;將摩納哥編輯器webpack加載程序插件monaco-editor-webpack-plugin添加到您的webpack.config.js :
const MonacoWebpackPlugin = require ( 'monaco-editor-webpack-plugin' ) ;
module . exports = {
plugins : [
new MonacoWebpackPlugin ( )
]
} ; 如果指定value屬性,則組件以受控模式行為。否則,它以不受控制的模式行為。
width寬度。默認為100% 。height 。默認為100% 。value 。defaultValue在編輯器中創建的自動創建模型的初始值。language自動在編輯器中創建的模型的初始語言。theme編輯vs , vs-dark , hc-black的主題options請參閱摩納哥界面IEDitorConstructionoptions。editorDidMount(editor, monaco)安裝了編輯器時發出的事件(類似於React的componentDidMount )。onChange(newValue, event)發出了事件。autoComplete?: (model: monaco.editor.ITextModel, position: monaco.Position) => languages.CompletionItem[];用戶為自動完成提供了擴展功能提供商。 #47 請參閱摩納哥界面IEDITOR。
與往常一樣,感謝我們出色的貢獻者!
由github-action-contributor製成。
根據MIT許可獲得許可。