@@ -22,7 +22,7 @@ open CompilerManagerHook
2222module Api = RescriptCompilerApi
2323
2424type layout = Column | Row
25- type tab = JavaScript | Problems | Settings
25+ type tab = JavaScript | Problems | Settings | Console
2626let breakingPoint = 1024
2727
2828module DropdownSelect = {
@@ -1054,6 +1054,20 @@ module Settings = {
10541054}
10551055
10561056module ControlPanel = {
1057+ let codeFromResult = (result : FinalResult .t ): string => {
1058+ open Api
1059+ switch result {
1060+ | FinalResult .Comp (comp ) =>
1061+ switch comp {
1062+ | CompilationResult .Success ({js_code }) => js_code
1063+ | UnexpectedError (_ )
1064+ | Unknown (_ , _ )
1065+ | Fail (_ ) => "/* No JS code generated */"
1066+ }
1067+ | Nothing
1068+ | Conv (_ ) => "/* No JS code generated */"
1069+ }
1070+ }
10571071 module Button = {
10581072 @react.component
10591073 let make = (~children , ~onClick = ?) =>
@@ -1134,8 +1148,11 @@ module ControlPanel = {
11341148 ~state : CompilerManagerHook .state ,
11351149 ~dispatch : CompilerManagerHook .action => unit ,
11361150 ~editorCode : React .ref <string >,
1151+ ~runOutput ,
1152+ ~toggleRunOutput ,
11371153 ) => {
11381154 let router = Next .Router .useRouter ()
1155+
11391156 let children = switch state {
11401157 | Init => React .string ("Initializing..." )
11411158 | SwitchingCompiler (_ready , _version ) => React .string ("Switching Compiler..." )
@@ -1168,12 +1185,14 @@ module ControlPanel = {
11681185 Next .Router .replace (router , url )
11691186 url
11701187 }
1171- <>
1172- <div className = "mr-2" >
1173- <Button onClick = onFormatClick > {React .string ("Format" )} </Button >
1174- </div >
1188+
1189+ <div className = "flex flex-row gap-x-2" >
1190+ <ToggleButton checked = runOutput onChange = {_ => toggleRunOutput ()}>
1191+ {React .string ("Auto-run" )}
1192+ </ToggleButton >
1193+ <Button onClick = onFormatClick > {React .string ("Format" )} </Button >
11751194 <ShareButton actionIndicatorKey createShareLink />
1176- </>
1195+ </div >
11771196 | _ => React .null
11781197 }
11791198
@@ -1193,28 +1212,75 @@ let locMsgToCmError = (~kind: CodeMirror.Error.kind, locMsg: Api.LocMsg.t): Code
11931212 }
11941213}
11951214
1196- module OutputPanel = {
1197- let codeFromResult = (result : FinalResult .t ): string => {
1198- open Api
1199- switch result {
1200- | FinalResult .Comp (comp ) =>
1201- switch comp {
1202- | CompilationResult .Success ({js_code }) => js_code
1203- | UnexpectedError (_ )
1204- | Unknown (_ , _ )
1205- | Fail (_ ) => "/* No JS code generated */"
1206- }
1207- | Nothing
1208- | Conv (_ ) => "/* No JS code generated */"
1209- }
1210- }
1215+ // module RenderOutput = {
1216+ // @react.component
1217+ // let make = (~compilerState: CompilerManagerHook.state) => {
1218+ // React.useEffect(() => {
1219+ // let code = switch compilerState {
1220+ // | Ready(ready) =>
1221+ // switch ready.result {
1222+ // | Comp(Success(_)) => ControlPanel.codeFromResult(ready.result)->Some
1223+ // | _ => None
1224+ // }
1225+ // | _ => None
1226+ // }
1227+
1228+ // let _valid = switch code {
1229+ // | Some(code) =>
1230+ // switch RenderOutputManager.renderOutput(code) {
1231+ // | Ok(_) => true
1232+ // | Error(_) => false
1233+ // }
1234+ // | None => false
1235+ // }
1236+ // None
1237+ // }, [compilerState])
1238+
1239+ // <div className={""}>
1240+ // <iframe
1241+ // width="100%"
1242+ // id="iframe-eval"
1243+ // className="relative w-full text-gray-20"
1244+ // srcDoc=RenderOutputManager.Frame.srcdoc
1245+ // />
1246+ // </div>
1247+
1248+ // // switch code {
1249+ // // | Some(code) =>
1250+ // // switch RenderOutputManager.renderOutput(code) {
1251+ // // | Ok() =>
1252+ // // <iframe
1253+ // // width="100%"
1254+ // // id="iframe-eval"
1255+ // // className="relative w-full text-gray-20"
1256+ // // srcDoc=RenderOutputManager.Frame.srcdoc
1257+ // // />
1258+ // // | Error() =>
1259+ // // let code = `module App = {
1260+ // // @react.component
1261+ // // let make = () => {
1262+ // // <ModuleName />
1263+ // // }
1264+ // // }`
1265+ // // <div className={"whitespace-pre-wrap p-4 block"}>
1266+ // // <p className={"mb-2"}> {React.string("To render element create a module App")} </p>
1267+ // // <pre> {HighlightJs.renderHLJS(~code, ~darkmode=true, ~lang="rescript", ())} </pre>
1268+ // // </div>
1269+ // // }
1270+
1271+ // // | _ => React.null
1272+ // // }
1273+ // }
1274+ // }
12111275
1276+ module OutputPanel = {
12121277 @react.component
12131278 let make = (
12141279 ~compilerDispatch ,
12151280 ~compilerState : CompilerManagerHook .state ,
12161281 ~editorCode : React .ref <string >,
12171282 ~currentTab : tab ,
1283+ ~runOutput ,
12181284 ) => {
12191285 /*
12201286 We need the prevState to understand different
@@ -1232,17 +1298,18 @@ module OutputPanel = {
12321298 | (_ , Ready ({result : Nothing })) => None
12331299 | (Ready (prevReady ), Ready (ready )) =>
12341300 switch (prevReady .result , ready .result ) {
1235- | (_ , Comp (Success (_ ))) => codeFromResult (ready .result )-> Some
1301+ | (_ , Comp (Success (_ ))) => ControlPanel . codeFromResult (ready .result )-> Some
12361302 | _ => None
12371303 }
1238- | (_ , Ready ({result : Comp (Success (_ )) as result })) => codeFromResult (result )-> Some
1304+ | (_ , Ready ({result : Comp (Success (_ )) as result })) =>
1305+ ControlPanel .codeFromResult (result )-> Some
12391306 | (Ready ({result : Comp (Success (_ )) as result }), Compiling (_ , _ )) =>
1240- codeFromResult (result )-> Some
1307+ ControlPanel . codeFromResult (result )-> Some
12411308 | _ => None
12421309 }
12431310 | None =>
12441311 switch compilerState {
1245- | Ready (ready ) => codeFromResult (ready .result )-> Some
1312+ | Ready (ready ) => ControlPanel . codeFromResult (ready .result )-> Some
12461313 | _ => None
12471314 }
12481315 }
@@ -1322,7 +1389,12 @@ module OutputPanel = {
13221389
13231390 prevSelected .current = selected
13241391
1325- let tabs = [(JavaScript , output ), (Problems , errorPane ), (Settings , settingsPane )]
1392+ let tabs = [
1393+ (Console , <ConsolePanel compilerState runOutput />),
1394+ (JavaScript , output ),
1395+ (Problems , errorPane ),
1396+ (Settings , settingsPane ),
1397+ ]
13261398
13271399 let body = Belt .Array .mapWithIndex (tabs , (i , (tab , content )) => {
13281400 let className = currentTab == tab ? "block h-inherit" : "hidden"
@@ -1700,10 +1772,12 @@ let make = (~versions: array<string>) => {
17001772 "flex-1 items-center p-4 border-t-4 border-transparent " ++ activeClass
17011773 }
17021774
1703- let tabs = [JavaScript , Problems , Settings ]
1775+ let tabs = [JavaScript , Console , Problems , Settings ]
17041776
17051777 let headers = Belt .Array .mapWithIndex (tabs , (i , tab ) => {
17061778 let title = switch tab {
1779+ // | RenderOutput => "Render Output"
1780+ | Console => "Console"
17071781 | JavaScript => "JavaScript"
17081782 | Problems => "Problems"
17091783 | Settings => "Settings"
@@ -1722,12 +1796,17 @@ let make = (~versions: array<string>) => {
17221796 </button >
17231797 })
17241798
1799+ let (runOutput , setRunOutput ) = React .useState (() => false )
1800+ let toggleRunOutput = () => setRunOutput (prev => ! prev )
1801+
17251802 <main className = {"flex flex-col bg-gray-100 overflow-hidden" }>
17261803 <ControlPanel
17271804 actionIndicatorKey = {Belt .Int .toString (actionCount )}
17281805 state = compilerState
17291806 dispatch = compilerDispatch
17301807 editorCode
1808+ runOutput
1809+ toggleRunOutput
17311810 />
17321811 <div
17331812 className = {` flex ${layout == Column ? "flex-col" : "flex-row" }` }
@@ -1782,7 +1861,7 @@ let make = (~versions: array<string>) => {
17821861 {React .array (headers )}
17831862 </div >
17841863 <div ref = {ReactDOM .Ref .domRef (subPanelRef )} className = "overflow-auto" >
1785- <OutputPanel currentTab compilerDispatch compilerState editorCode />
1864+ <OutputPanel currentTab compilerDispatch compilerState editorCode runOutput />
17861865 </div >
17871866 </div >
17881867 </div >
0 commit comments