@@ -1203,6 +1203,10 @@ module ControlPanel = {
1203
1203
| lang => [("ext" , Api .Lang .toExt (lang ))]
1204
1204
}
1205
1205
1206
+ let version = ready .selected .compilerVersion
1207
+
1208
+ Js .Array2 .push (params , ("version" , "v" ++ version ))-> ignore
1209
+
1206
1210
Js .Array2 .push (
1207
1211
params ,
1208
1212
("code" , editorCode .current -> LzString .compressToEncodedURIComponent ),
@@ -1396,7 +1400,15 @@ module OutputPanel = {
1396
1400
}
1397
1401
}
1398
1402
1399
- let initialResContent = ` module Button = {
1403
+ /**
1404
+ The initial content is somewhat based on the compiler version.
1405
+ If we are handling a version that's beyond 10.1, we want to make
1406
+ sure we are using an example that includes a JSX pragma to
1407
+ inform the user that you are able to switch between jsx 3 / jsx 4
1408
+ and the different jsx modes (classic and automatic).
1409
+ */
1410
+ module InitialContent = {
1411
+ let original = ` module Button = {
1400
1412
@react.component
1401
1413
let make = (~count: int) => {
1402
1414
let times = switch count {
@@ -1409,7 +1421,61 @@ let initialResContent = `module Button = {
1409
1421
<button> {msg->React.string} </button>
1410
1422
}
1411
1423
}
1412
- ` // Please note:
1424
+ `
1425
+
1426
+ let since_10_1 = ` @@jsxConfig({ version: 4, mode: "automatic" })
1427
+
1428
+ module CounterMessage = {
1429
+ @react.component
1430
+ let make = (~count, ~username=?) => {
1431
+ let times = switch count {
1432
+ | 1 => "once"
1433
+ | 2 => "twice"
1434
+ | n => Belt.Int.toString(n) ++ " times"
1435
+ }
1436
+
1437
+ let name = switch username {
1438
+ | Some("") => "Anonymous"
1439
+ | Some(name) => name
1440
+ | None => "Anonymous"
1441
+ }
1442
+
1443
+ <div> {React.string(\` Hello \$\{ name\} , you clicked me \` ++ times)} </div>
1444
+ }
1445
+ }
1446
+
1447
+ module App = {
1448
+ @react.component
1449
+ let make = () => {
1450
+ let (count, setCount) = React.useState(() => 0)
1451
+ let (username, setUsername) = React.useState(() => "Anonymous")
1452
+
1453
+ <div>
1454
+ {React.string("Username: ")}
1455
+ <input
1456
+ type_="text"
1457
+ value={username}
1458
+ onChange={evt => {
1459
+ evt->ReactEvent.Form.preventDefault
1460
+ let username = (evt->ReactEvent.Form.target)["value"]
1461
+ setUsername(_prev => username)
1462
+ }}
1463
+ />
1464
+ <button
1465
+ onClick={_evt => {
1466
+ setCount(prev => prev + 1)
1467
+ }}>
1468
+ {React.string("Click me")}
1469
+ </button>
1470
+ <button onClick={_evt => setCount(_ => 0)}> {React.string("Reset")} </button>
1471
+ <CounterMessage count username />
1472
+ </div>
1473
+ }
1474
+ }
1475
+ `
1476
+ }
1477
+
1478
+ // Please note:
1413
1479
// ---
1414
1480
// The Playground is still a work in progress
1415
1481
// ReScript / old Reason syntax should parse just
@@ -1420,10 +1486,31 @@ let initialResContent = `module Button = {
1420
1486
1421
1487
let initialReContent = j ` Js.log("Hello Reason 3.6!");`
1422
1488
1489
+ /**
1490
+ Takes a `versionStr` starting with a "v" and ending in major.minor.patch (e.g.
1491
+ "v10.1.0") returns major, minor, patch as an integer tuple if it's actually in
1492
+ a x.y.z format, otherwise will return `None`.
1493
+ */
1494
+ let parseVersion = (versionStr : string ): option <(int , int , int )> => {
1495
+ switch versionStr -> Js .String2 .replace ("v" , "" )-> Js .String2 .split ("." ) {
1496
+ | [major , minor , patch ] =>
1497
+ switch (major -> Belt .Int .fromString , minor -> Belt .Int .fromString , patch -> Belt .Int .fromString ) {
1498
+ | (Some (major ), Some (minor ), Some (patch )) => Some ((major , minor , patch ))
1499
+ | _ => None
1500
+ }
1501
+ | _ => None
1502
+ }
1503
+ }
1504
+
1423
1505
@react.component
1424
1506
let default = () => {
1425
1507
let router = Next .Router .useRouter ()
1426
1508
1509
+ let initialVersion = switch Js .Dict .get (router .query , "version" ) {
1510
+ | Some (version ) => Some (version )
1511
+ | None => CompilerManagerHook .CdnMeta .versions -> Belt .Array .get (0 )
1512
+ }
1513
+
1427
1514
let initialLang = switch Js .Dict .get (router .query , "ext" ) {
1428
1515
| Some ("re" ) => Api .Lang .Reason
1429
1516
| _ => Api .Lang .Res
@@ -1433,14 +1520,32 @@ let default = () => {
1433
1520
| (Some (compressedCode ), _ ) => LzString .decompressToEncodedURIComponent (compressedCode )
1434
1521
| (None , Reason ) => initialReContent
1435
1522
| (None , Res )
1436
- | (None , _ ) => initialResContent
1523
+ | (None , _ ) =>
1524
+ switch initialVersion {
1525
+ | Some (initialVersion ) =>
1526
+ switch parseVersion (initialVersion ) {
1527
+ | Some ((major , minor , _ )) =>
1528
+ if major >= 10 && minor >= 1 {
1529
+ InitialContent .since_10_1
1530
+ } else {
1531
+ InitialContent .original
1532
+ }
1533
+ | None => InitialContent .original
1534
+ }
1535
+ | None => InitialContent .original
1536
+ }
1437
1537
}
1438
1538
1439
1539
// We don't count to infinity. This value is only required to trigger
1440
1540
// rerenders for specific components (ActivityIndicator)
1441
1541
let (actionCount , setActionCount ) = React .useState (_ => 0 )
1442
1542
let onAction = _ => setActionCount (prev => prev > 1000000 ? 0 : prev + 1 )
1443
- let (compilerState , compilerDispatch ) = useCompilerManager (~initialLang , ~onAction , ())
1543
+ let (compilerState , compilerDispatch ) = useCompilerManager (
1544
+ ~initialVersion ?,
1545
+ ~initialLang ,
1546
+ ~onAction ,
1547
+ (),
1548
+ )
1444
1549
1445
1550
let overlayState = React .useState (() => false )
1446
1551
0 commit comments