@@ -13,6 +13,38 @@ module Api = RescriptCompilerApi
1313
1414type layout = Column | Row
1515type tab = JavaScript | Output | Problems | Settings
16+
17+ module JsxCompilation = {
18+ type t =
19+ | Plain
20+ | PreserveJsx
21+
22+ let getLabel = (mode : t ): string =>
23+ switch mode {
24+ | Plain => "Plain JS functions"
25+ | PreserveJsx => "Preserve JSX"
26+ }
27+
28+ let toBool = (mode : t ): bool =>
29+ switch mode {
30+ | Plain => false
31+ | PreserveJsx => true
32+ }
33+
34+ let fromBool = (bool ): t => bool ? PreserveJsx : Plain
35+ }
36+
37+ module ExperimentalFeatures = {
38+ type t = LetUnwrap
39+
40+ let getLabel = (feature : t ): string =>
41+ switch feature {
42+ | LetUnwrap => "let?"
43+ }
44+
45+ let list = [LetUnwrap ]
46+ }
47+
1648let breakingPoint = 1024
1749
1850module DropdownSelect = {
@@ -31,23 +63,23 @@ module DropdownSelect = {
3163 }
3264}
3365
34- module ToggleSelection = {
35- module SelectionOption = {
36- @react.component
37- let make = (~label , ~isActive , ~disabled , ~onClick ) => {
38- <button
39- className = {"mr-1 px-2 py-1 rounded inline-block " ++ if isActive {
40- "bg-fire text-white font-bold"
41- } else {
42- "bg-gray-80 opacity-50 hover:opacity-80"
43- }}
44- onClick
45- disabled >
46- {React .string (label )}
47- </button >
48- }
66+ module SelectionOption = {
67+ @react.component
68+ let make = (~label , ~isActive , ~disabled , ~onClick ) => {
69+ <button
70+ className = {"mr-1 px-2 py-1 rounded inline-block " ++ if isActive {
71+ "bg-fire text-white font-bold"
72+ } else {
73+ "bg-gray-80 opacity-50 hover:opacity-80"
74+ }}
75+ onClick
76+ disabled >
77+ {React .string (label )}
78+ </button >
4979 }
80+ }
5081
82+ module ToggleSelection = {
5183 @react.component
5284 let make = (
5385 ~onChange : 'a => unit ,
@@ -867,6 +899,25 @@ module Settings = {
867899 setConfig (config )
868900 }
869901
902+ let onJsxPreserveModeUpdate = compilation => {
903+ let jsx_preserve_mode = JsxCompilation .toBool (compilation )
904+ let config = {... config , jsx_preserve_mode }
905+ setConfig (config )
906+ }
907+
908+ let onExperimentalFeaturesUpdate = feature => {
909+ let features = config .experimental_features -> Option .getOr ([])
910+
911+ let experimental_features = if features -> Array .includes (feature ) {
912+ features -> Array .filter (x => x !== feature )
913+ } else {
914+ [... features , feature ]
915+ }
916+
917+ let config = {... config , experimental_features }
918+ setConfig (config )
919+ }
920+
870921 let warnFlagTokens = WarningFlagDescription .Parser .parse (warn_flags )-> Result .getOr ([])
871922
872923 let onWarningFlagsResetClick = _evt => {
@@ -1000,6 +1051,40 @@ module Settings = {
10001051 onChange = onModuleSystemUpdate
10011052 />
10021053 </div >
1054+ {switch readyState .selected .apiVersion {
1055+ | V1 | V2 | V3 | V4 | V5 | UnknownVersion (_ ) => React .null
1056+ | V6 =>
1057+ <>
1058+ <div className = "mt-6" >
1059+ <div className = titleClass > {React .string ("JSX" )} </div >
1060+ <ToggleSelection
1061+ values = [JsxCompilation .Plain , PreserveJsx ]
1062+ toLabel = JsxCompilation .getLabel
1063+ selected = {config .jsx_preserve_mode -> Option .getOr (false )-> JsxCompilation .fromBool }
1064+ onChange = onJsxPreserveModeUpdate
1065+ />
1066+ </div >
1067+ <div className = "mt-6" >
1068+ <div className = titleClass > {React .string ("Experimental Features" )} </div >
1069+ {ExperimentalFeatures .list
1070+ -> Array .map (feature => {
1071+ let key = (feature :> string )
1072+
1073+ <SelectionOption
1074+ key
1075+ disabled = false
1076+ label = {feature -> ExperimentalFeatures .getLabel }
1077+ isActive = {config .experimental_features
1078+ -> Option .getOr ([])
1079+ -> Array .includes (key )}
1080+ onClick = {_evt => onExperimentalFeaturesUpdate (key )}
1081+ />
1082+ })
1083+ -> React .array }
1084+ </div >
1085+ </>
1086+ }}
1087+
10031088 <div className = "mt-6" >
10041089 <div className = titleClass > {React .string ("Loaded Libraries" )} </div >
10051090 <ul >
@@ -1440,7 +1525,7 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14401525 | [v ] => Some (v ) // only single version available. maybe local dev.
14411526 | versions => {
14421527 let lastStableVersion = versions -> Array .find (version => version .preRelease -> Option .isNone )
1443- switch Dict .get (router .query , "version" ) {
1528+ switch Dict .get (router .query , ( CompilerManagerHook . Version :> string ) ) {
14441529 | Some (version ) => version -> Semver .parse
14451530 | None =>
14461531 switch Url .getVersionFromStorage (Playground ) {
@@ -1451,14 +1536,20 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14511536 }
14521537 }
14531538
1454- let initialLang = switch Dict .get (router .query , "ext" ) {
1539+ let initialLang = switch Dict .get (router .query , ( CompilerManagerHook . Ext :> string ) ) {
14551540 | Some ("re" ) => Api .Lang .Reason
14561541 | _ => Api .Lang .Res
14571542 }
14581543
1459- let initialModuleSystem = Dict .get (router .query , "module" )
1544+ let initialModuleSystem = Dict .get (router .query , (Module :> string ))
1545+ let initialJsxPreserveMode = Dict .get (router .query , (JsxPreserve :> string ))-> Option .isSome
1546+
1547+ let initialExperimentalFeatures =
1548+ Dict .get (router .query , (Experiments :> string ))-> Option .mapOr ([], str =>
1549+ str -> String .split ("," )-> Array .map (String .trim )
1550+ )
14601551
1461- let initialContent = switch (Dict .get (router .query , "code" ), initialLang ) {
1552+ let initialContent = switch (Dict .get (router .query , ( Code :> string ) ), initialLang ) {
14621553 | (Some (compressedCode ), _ ) => LzString .decompressToEncodedURIComponent (compressedCode )
14631554 | (None , Reason ) => initialReContent
14641555 | (None , Res ) =>
@@ -1477,6 +1568,8 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14771568 ~bundleBaseUrl ,
14781569 ~initialVersion ?,
14791570 ~initialModuleSystem ?,
1571+ ~initialJsxPreserveMode ,
1572+ ~initialExperimentalFeatures ,
14801573 ~initialLang ,
14811574 ~onAction ,
14821575 ~versions ,
0 commit comments