1- import React , { useState , Dispatch , SetStateAction } from " react" ;
2- import { Button , Card , CardContent , CardHeader } from " @material-ui/core" ;
3- import MonacoEditor , { EditorDidMount } from " react-monaco-editor" ;
4- import * as monacoEditor from " monaco-editor/esm/vs/editor/editor.api" ;
5- import ResizeObserver from " react-resize-detector" ;
6- import { queryCache } from " react-query" ;
1+ import React , { useState , Dispatch , SetStateAction } from ' react' ;
2+ import { Button , Card , CardContent , CardHeader } from ' @material-ui/core' ;
3+ import MonacoEditor , { EditorDidMount } from ' react-monaco-editor' ;
4+ import * as monacoEditor from ' monaco-editor/esm/vs/editor/editor.api' ;
5+ import ResizeObserver from ' react-resize-detector' ;
6+ import { queryCache } from ' react-query' ;
77
8- const COMPILE_AND_RUN_BUTTON_ID = " compile-and-run-button-id" ;
8+ const COMPILE_AND_RUN_BUTTON_ID = ' compile-and-run-button-id' ;
99
1010interface YourCodeProps {
1111 handleCompileAndRun : ( event : React . MouseEvent ) => void ;
@@ -16,19 +16,16 @@ interface YourCodeProps {
1616
1717const YourCode : React . FC < YourCodeProps > = ( props : YourCodeProps ) => {
1818 const { handleCompileAndRun, loading, setSource, source } = props ;
19- const [
20- editor ,
21- setEditor ,
22- ] = useState < monacoEditor . editor . IStandaloneCodeEditor | null > ( null ) ;
19+ const [ editor , setEditor ] = useState < monacoEditor . editor . IStandaloneCodeEditor | null > ( null ) ;
2320 const [ monaco , setMonaco ] = useState < typeof monacoEditor | null > ( null ) ;
2421
2522 const handleUploadSource = ( v : string ) => {
2623 setSource ( v as string ) ;
2724 } ;
2825
2926 const options = {
30- wordWrap : "on" as const ,
31- scrollBeyondLastLine : false ,
27+ wordWrap : 'on' as const ,
28+ scrollBeyondLastLine : false
3229 } ;
3330
3431 const EditorDidMountHandle = (
@@ -37,20 +34,20 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
3734 ) => {
3835 editor . addAction ( {
3936 id : COMPILE_AND_RUN_BUTTON_ID ,
40- label : " compile-and-run-butt-label" ,
37+ label : ' compile-and-run-butt-label' ,
4138 keybindings : [ 2051 ] , // Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.Enter == 2051
4239 run : ( ) => {
4340 document . getElementById ( COMPILE_AND_RUN_BUTTON_ID ) ?. click ( ) ;
44- } ,
41+ }
4542 } ) ;
4643
4744 setEditor ( editor ) ;
4845 setMonaco ( monaco ) ;
4946 } ;
5047
5148 return (
52- < div style = { { height : " 100%" } } >
53- < Card className = { " your-code-card" } style = { { height : " 100%" } } >
49+ < div style = { { height : ' 100%' } } >
50+ < Card className = { ' your-code-card' } style = { { height : ' 100%' } } >
5451 < CardHeader
5552 action = {
5653 < div className = "run-button" >
@@ -59,19 +56,18 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
5956 variant = "contained"
6057 color = "secondary"
6158 style = { {
62- textTransform : " none" ,
63- width : 140 ,
59+ textTransform : ' none' ,
60+ width : 140
6461 } }
6562 onClick = { ( ) => {
6663 // stop the web-worker
67- queryCache . cancelQueries ( [ " compiler" ] ) ;
64+ queryCache . cancelQueries ( [ ' compiler' ] ) ;
6865 // set result to initial state
69- queryCache . setQueryData ( [ " compiler" , source ] , ( data ) => ( {
66+ queryCache . setQueryData ( [ ' compiler' , source ] , ( data ) => ( {
7067 outputItem : [ ] ,
71- outputString : "" ,
68+ outputString : ''
7269 } ) ) ;
73- } }
74- >
70+ } } >
7571 Stop
7672 </ Button >
7773 ) : (
@@ -81,9 +77,8 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
8177 color = "primary"
8278 onClick = { ( e ) => handleCompileAndRun ( e ) }
8379 style = { {
84- textTransform : "none" ,
85- } }
86- >
80+ textTransform : 'none'
81+ } } >
8782 Compile and run
8883 </ Button >
8984 ) }
@@ -98,13 +93,11 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
9893 if ( editor ) {
9994 editor . layout ( ) ;
10095 }
101- } }
102- >
96+ } } >
10397 < div
10498 style = { {
105- height : "calc(100vh - 174px)" ,
106- } }
107- >
99+ height : 'calc(100vh - 174px)'
100+ } } >
108101 < MonacoEditor
109102 language = "javascript"
110103 value = { source }
0 commit comments