Gathering detailed insights and metrics for react-monaco-editor-plus
Gathering detailed insights and metrics for react-monaco-editor-plus
Gathering detailed insights and metrics for react-monaco-editor-plus
Gathering detailed insights and metrics for react-monaco-editor-plus
modified react monaco editor for jlove29/vega-editor
npm install react-monaco-editor-plus
Typescript
Module System
Node Version
NPM Version
39.9
Supply Chain
92.6
Quality
73.9
Maintenance
50
Vulnerability
98.6
License
JavaScript (100%)
Total Downloads
1,450
Last Day
4
Last Week
5
Last Month
12
Last Year
110
118 Commits
5 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.5
Package Id
react-monaco-editor-plus@1.0.5
Size
5.92 kB
NPM Version
5.3.0
Node Version
8.2.1
Cumulative downloads
Total Downloads
Last day
0%
4
Compared to previous day
Last week
-16.7%
5
Compared to previous week
Last month
140%
12
Compared to previous month
Last year
-5.2%
110
Compared to previous year
Monaco Editor for React.
To build the examples locally, run:
npm install
cd examples && npm install
npm start
Then open http://localhost:8886
in a browser.
npm install react-monaco-editor
1import React from 'react'; 2import { render } from 'react-dom'; 3import MonacoEditor from 'react-monaco-editor'; 4 5class App extends React.Component { 6 constructor(props) { 7 super(props); 8 this.state = { 9 code: '// type your code...', 10 } 11 } 12 editorDidMount(editor, monaco) { 13 console.log('editorDidMount', editor); 14 editor.focus(); 15 } 16 onChange(newValue, e) { 17 console.log('onChange', newValue, e); 18 } 19 render() { 20 const code = this.state.code; 21 const options = { 22 selectOnLineNumbers: true 23 }; 24 return ( 25 <MonacoEditor 26 width="800" 27 height="600" 28 language="javascript" 29 theme="vs-dark" 30 value={code} 31 options={options} 32 onChange={::this.onChange} 33 editorDidMount={::this.editorDidMount} 34 /> 35 ); 36 } 37} 38 39render( 40 <App />, 41 document.getElementById('root') 42);
Add a Webpack plugin copy-webpack-plugin
to your webpack.config.js
:
1const CopyWebpackPlugin = require('copy-webpack-plugin'); 2module.exports = { 3 plugins: [ 4 new CopyWebpackPlugin([ 5 { 6 from: 'node_modules/monaco-editor/min/vs', 7 to: 'vs', 8 } 9 ]) 10 ] 11};
Fill from
field with the actual path of monaco-editor
package in node_modules.
1class App extends React.Component { 2 render() { 3 const requireConfig = { 4 url: 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.1/require.min.js', 5 paths: { 6 'vs': 'https://www.mycdn.com/monaco-editor/0.6.1/min/vs' 7 } 8 }; 9 return ( 10 <MonacoEditor 11 width="800" 12 height="600" 13 language="javascript" 14 value="// type your code..." 15 requireConfig={requireConfig} 16 /> 17 ); 18 } 19}
requireConfig
is optional, equal to:
1<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.1/require.min.js"></script> 2<script> 3 require.config({ paths: { 'vs': 'https://www.mycdn.com/monaco-editor/0.6.1/min/vs' }}); 4</script>
Both them are valid ways to config loader url and relative path of module.
The default value for requriedConfig.url
is vs/loader.js
.
You may need to note the cross domain case.
If you specify value
property, the component behaves in controlled mode.
Otherwise, it behaves in uncontrolled mode.
width
width of editor. Defaults to 100%
.height
height of editor. Defaults to 100%
.value
value of the auto created model in the editor.defaultValue
the initial value of the auto created model in the editor.language
the initial language of the auto created model in the editor.theme
the theme of the editoroptions
refer to Monaco interface IEditorConstructionOptions.onChange(newValue, event)
an event emitted when the content of the current model has changed.editorWillMount(monaco)
an event emitted before the editor mounted (similar to componentWillMount
of React).editorDidMount(editor, monaco)
an event emitted when the editor has been mounted (similar to componentDidMount
of React).requireConfig
optional, allow to config loader url and relative path of module, refer to require.config.context
optional, allow to pass a different context then the global window onto which the monaco instance will be loaded. Useful if you want to load the editor in an iframe.Refer to Monaco interface IEditor.
Using the first parameter of editorDidMount
, or using a ref
(e.g. <MonacoEditor ref="monaco">
) after editorDidMount
event has fired.
Then you can invoke instance methods via this.refs.monaco.editor
, e.g. this.refs.monaco.editor.focus()
to focuses the MonacoEditor instance.
Using this.refs.monaco.editor.getValue()
or via method of Model
instance:
1const model = this.refs.monaco.editor.getModel(); 2const value = model.getValue();
For example, you may want to configure some JSON schemas before editor mounted, then you can go with editorWillMount(monaco)
:
1class App extends React.Component { 2 editorWillMount(monaco) { 3 monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ 4 schemas: [{ 5 uri: "http://myserver/foo-schema.json", 6 schema: { 7 type: "object", 8 properties: { 9 p1: { 10 enum: [ "v1", "v2"] 11 }, 12 p2: { 13 $ref: "http://myserver/bar-schema.json" 14 } 15 } 16 } 17 }] 18 }); 19 } 20 render() { 21 return ( 22 <MonacoEditor language="json" editorWillMount={this.editorWillMount} /> 23 ); 24 } 25}
Monaco only supports one theme.
MIT, see the LICENSE file for detail.
No vulnerabilities found.
No security vulnerabilities found.