Skip to content

Instantly share code, notes, and snippets.

@anztrax
Created April 7, 2017 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anztrax/0343af2da3f87404d540339684b3132d to your computer and use it in GitHub Desktop.
Save anztrax/0343af2da3f87404d540339684b3132d to your computer and use it in GitHub Desktop.
just want to test the monaco editor
import React from 'react';
import Head from 'next/head';
import {stylesheet, classNames} from './index.css';
import ComponentA from './Component/ComponentA/ComponentA';
// import ComponentB from './Component/ComponentB/ComponentB';
export default class TestMonacoEditorPage extends React.Component{
constructor(props){
super(props);
this.state = {
current_scenario_script : [
'function x() {',
'\tconsole.log("Hello world!");',
'}'
].join('\n')
}
}
componentDidMount(){
window.require.config({ paths: { 'vs': '/vs' }});
window.require(['vs/editor/editor.main'], () => {
if(typeof monaco != "undefined") {
this.editor = monaco.editor.create(document.getElementById('container'), {
value: this.state.current_scenario_script,
language: 'javascript'
});
this.editor.onDidChangeModelContent((e)=> {
this.setState({page_edited: true, current_scenario_script: event.target.value})
});
}
});
}
componentDidUpdate(){
//no op
}
componentWillUnmount(){
if(typeof this.editor != "undefined")
this.editor.destroy();
}
render(){
return (
<div>
<h1>Blurry eyes</h1>
<div id="container" style={{width : '100%', height: '500px'}}></div>
<Head>
<style dangerouslySetInnerHTML={{__html: stylesheet}} />
<script src="/vs/loader.js"></script>
<script src="/vs/editor/editor.main.js"></script>
</Head>
<ComponentA />
<img src="/assets/images/logo.jpg" />
{/*<ComponentB />*/}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment