@@ -1183,27 +1183,10 @@ module ControlPanel = {
1183
1183
url
1184
1184
}
1185
1185
1186
- let compiledCode = switch state {
1187
- | Ready (ready ) =>
1188
- switch ready .result {
1189
- | Comp (Success (_ )) => codeFromResult (ready .result )-> Some
1190
- | _ => None
1191
- }
1192
- | _ => None
1193
- }
1194
-
1195
- let onRunOutputClick = evt => {
1196
- ReactEvent .Mouse .preventDefault (evt )
1197
- RenderOutputManager .renderOutput (compiledCode )
1198
- }
1199
-
1200
1186
<>
1201
1187
<div className = "mr-2" >
1202
1188
<Button onClick = onFormatClick > {React .string ("Format" )} </Button >
1203
1189
</div >
1204
- <div className = "mr-2" >
1205
- <Button onClick = {onRunOutputClick }> {React .string ("Run" )} </Button >
1206
- </div >
1207
1190
<ShareButton actionIndicatorKey createShareLink />
1208
1191
</>
1209
1192
| _ => React .null
@@ -1225,6 +1208,67 @@ let locMsgToCmError = (~kind: CodeMirror.Error.kind, locMsg: Api.LocMsg.t): Code
1225
1208
}
1226
1209
}
1227
1210
1211
+ module RenderOutput = {
1212
+ @react.component
1213
+ let make = (~compilerState : CompilerManagerHook .state ) => {
1214
+ let code = switch compilerState {
1215
+ | Ready (ready ) =>
1216
+ switch ready .result {
1217
+ | Comp (Success (_ )) => ControlPanel .codeFromResult (ready .result )-> Some
1218
+ | _ => None
1219
+ }
1220
+ | _ => None
1221
+ }
1222
+
1223
+ let valid = switch code {
1224
+ | Some (code ) =>
1225
+ switch RenderOutputManager .renderOutput (code ) {
1226
+ | Ok (_ ) => true
1227
+ | Error (_ ) => false
1228
+ }
1229
+ | None => false
1230
+ }
1231
+
1232
+ let a =
1233
+ <div className = {"" }>
1234
+ <iframe
1235
+ width = "100%"
1236
+ id = "iframe-eval"
1237
+ className = "relative w-full text-gray-20"
1238
+ srcDoc = RenderOutputManager .Frame .srcdoc
1239
+ />
1240
+ </div >
1241
+
1242
+ a
1243
+
1244
+ // switch code {
1245
+ // | Some(code) =>
1246
+ // switch RenderOutputManager.renderOutput(code) {
1247
+ // | Ok() =>
1248
+ // <iframe
1249
+ // width="100%"
1250
+ // id="iframe-eval"
1251
+ // className="relative w-full text-gray-20"
1252
+ // srcDoc=RenderOutputManager.Frame.srcdoc
1253
+ // />
1254
+ // | Error() =>
1255
+ // let code = `module App = {
1256
+ // @react.component
1257
+ // let make = () => {
1258
+ // <ModuleName />
1259
+ // }
1260
+ // }`
1261
+ // <div className={"whitespace-pre-wrap p-4 block"}>
1262
+ // <p className={"mb-2"}> {React.string("To render element create a module App")} </p>
1263
+ // <pre> {HighlightJs.renderHLJS(~code, ~darkmode=true, ~lang="rescript", ())} </pre>
1264
+ // </div>
1265
+ // }
1266
+
1267
+ // | _ => React.null
1268
+ // }
1269
+ }
1270
+ }
1271
+
1228
1272
module OutputPanel = {
1229
1273
@react.component
1230
1274
let make = (
@@ -1253,13 +1297,13 @@ module OutputPanel = {
1253
1297
if type_ === "log" {
1254
1298
let args : array <string > = data ["args" ]
1255
1299
1256
- setLogs (
1257
- previousLogs =>
1258
- previousLogs
1259
- -> Belt .Option .getWithDefault ([])
1260
- -> Js .Array2 .concat ([args ])
1261
- -> Some ,
1262
- )
1300
+ // setLogs(
1301
+ // previousLogs =>
1302
+ // logs
1303
+ // ->Belt.Option.getWithDefault([])
1304
+ // ->Js.Array2.concat([args])
1305
+ // ->Some,
1306
+ // )
1263
1307
}
1264
1308
})
1265
1309
None
@@ -1316,22 +1360,6 @@ module OutputPanel = {
1316
1360
{HighlightJs .renderHLJS (~code , ~darkmode = true , ~lang = "js" , ())}
1317
1361
</pre >
1318
1362
1319
- let renderOutputPane : React .element = switch compilerState {
1320
- | Compiling (ready , _ )
1321
- | Ready (ready ) =>
1322
- switch ready .result {
1323
- | Comp (Success (_ )) =>
1324
- <iframe
1325
- width = "100%"
1326
- id = "iframe-eval"
1327
- className = "relative w-full text-gray-20"
1328
- srcDoc = RenderOutputManager .Frame .srcdoc
1329
- />
1330
- | _ => React .null
1331
- }
1332
- | _ => React .null
1333
- }
1334
-
1335
1363
let consolePanel = switch logs {
1336
1364
| Some (logs ) =>
1337
1365
let content =
@@ -1397,7 +1425,7 @@ module OutputPanel = {
1397
1425
prevSelected .current = selected
1398
1426
1399
1427
let tabs = [
1400
- (RenderOutput , renderOutputPane ),
1428
+ (RenderOutput , < RenderOutput compilerState /> ),
1401
1429
(Console , consolePanel ),
1402
1430
(JavaScript , output ),
1403
1431
(Problems , errorPane ),
@@ -1445,60 +1473,30 @@ module App = {
1445
1473
}
1446
1474
`
1447
1475
1448
- let since_10_1 = ` @@jsxConfig({ version: 4, mode: "classic" })
1476
+ let since_10_1 = ` @@jsxConfig({version: 4, mode: "classic"})
1449
1477
1450
- module CounterMessage = {
1478
+ module Button = {
1451
1479
@react.component
1452
- let make = (~count, ~username=?) => {
1480
+ let make = () => {
1481
+ let (count, setCount) = React.useState(_ => 0)
1453
1482
let times = switch count {
1454
1483
| 1 => "once"
1455
1484
| 2 => "twice"
1456
- | n => Belt.Int.toString(n) ++ " times"
1457
- }
1458
-
1459
- let name = switch username {
1460
- | Some("") => "Anonymous"
1461
- | Some(name) => name
1462
- | None => "Anonymous"
1485
+ | n => n->Int.toString ++ " times"
1463
1486
}
1487
+ let msg = \` Click me $\{ times\}\`
1464
1488
1465
- <div> {React.string( \` Hello \$\{ name \} , you clicked me \` ++ times)} </div >
1489
+ <button onClick={_ => setCount(c => c + 1)}> {msg->React.string} </button >
1466
1490
}
1467
1491
}
1468
1492
1469
- module Form = {
1493
+ module App = {
1470
1494
@react.component
1471
1495
let make = () => {
1472
- let (count, setCount) = React.useState(() => 0)
1473
- let (username, setUsername) = React.useState(() => "Anonymous")
1474
-
1475
- <div>
1476
- {React.string("Username: ")}
1477
- <input
1478
- type_="text"
1479
- value={username}
1480
- onChange={evt => {
1481
- evt->ReactEvent.Form.preventDefault
1482
- let username = (evt->ReactEvent.Form.target)["value"]
1483
- setUsername(_prev => username)
1484
- }}
1485
- />
1486
- <button
1487
- onClick={_evt => {
1488
- setCount(prev => prev + 1)
1489
- }}>
1490
- {React.string("Click me")}
1491
- </button>
1492
- <button onClick={_evt => setCount(_ => 0)}> {React.string("Reset")} </button>
1493
- <CounterMessage count username />
1494
- </div>
1496
+ <Button />
1495
1497
}
1496
1498
}
1497
1499
1498
- module App = {
1499
- @react.component
1500
- let make = () => <Form/>
1501
- }
1502
1500
`
1503
1501
}
1504
1502
@@ -1783,7 +1781,7 @@ let make = (~versions: array<string>) => {
1783
1781
| _ => "rescript"
1784
1782
}
1785
1783
1786
- let (currentTab , setCurrentTab ) = React .useState (_ => RenderOutput )
1784
+ let (currentTab , setCurrentTab ) = React .useState (_ => JavaScript )
1787
1785
1788
1786
let disabled = false
1789
1787
@@ -1793,7 +1791,7 @@ let make = (~versions: array<string>) => {
1793
1791
"flex-1 items-center p-4 border-t-4 border-transparent " ++ activeClass
1794
1792
}
1795
1793
1796
- let tabs = [RenderOutput , Console , JavaScript , Problems , Settings ]
1794
+ let tabs = [JavaScript , RenderOutput , Console , Problems , Settings ]
1797
1795
1798
1796
let headers = Belt .Array .mapWithIndex (tabs , (i , tab ) => {
1799
1797
let title = switch tab {
0 commit comments