react monacoeditor
v3.6.0
Componente del editor de Mónaco para React. demostración @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' )
) ; Agregue el complemento del cargador de Webpack del editor de Monaco monaco-editor-webpack-plugin a su webpack.config.js :
const MonacoWebpackPlugin = require ( 'monaco-editor-webpack-plugin' ) ;
module . exports = {
plugins : [
new MonacoWebpackPlugin ( )
]
} ; Si especifica la propiedad value , el componente se comporta en modo controlado. De lo contrario, se comporta en modo no controlado.
width del editor. El valor predeterminado al 100% .height del editor. El valor predeterminado al 100% .value Valor del modelo creado automático en el editor.defaultValue el valor inicial del modelo creado automático en el editor.language El idioma inicial del modelo creado automático en el editor.theme El tema del editor vs , vs-dark , hc-blackoptions se refieren a la interfaz de Mónaco IEDIterConstructionOptions.editorDidMount(editor, monaco) Un evento emitido cuando el editor ha sido montado (similar a componentDidMount of React).onChange(newValue, event) un evento emitido cuando el contenido del modelo actual ha cambiado.autoComplete?: (model: monaco.editor.ITextModel, position: monaco.Position) => languages.CompletionItem[]; Proveedor de funciones de extensión proporcionada por el usuario para Auto-Complete. #47 Consulte el IEDitor de la interfaz Mónaco.
Como siempre, ¡gracias a nuestros increíbles contribuyentes!
Hecho con contribuyentes GitHub-Action.
Licenciado bajo la licencia del MIT.