@@ -30,17 +30,18 @@ import React.Basic.Helpers (jsx)
3030import React.Basic.Hooks (component, useState)
3131import React.Basic.Hooks as React
3232import React.Basic.Hooks.Spring (useTransition)
33+import React.Basic.SyntaxHighlighter.Component (HighlighterTheme, syntaxHighlighterImpl)
3334import Shared.Models.Body (CompileResult, RunResult)
34−import Type.Row (type (+))
3535import Yoga.Button.Component (ButtonType(..), mkButton)
3636import Yoga.ClickAway.Component as ClickAway
3737import Yoga.CloseIcon.Component as CloseIcon
3838import Yoga.Cluster.Component as Cluster
3939import Yoga.Compiler.Types (Compiler)
4040import Yoga.Helpers ((?||))
41−import Yoga.Highlighter.Types (Highlighter)
4241import Yoga.InlineCode.Component as InlineCode
4342import Yoga.Modal.Component as Modal
43+import Yoga.Theme.Styles (useTheme)
44+import Yoga.Theme.Syntax (mkHighlighterTheme)
4445
4546data Segment
4647 = ExpectedResult String
@@ -82,14 +83,14 @@ visibleRange arr = { start, end }
8283 start = A.findIndex (_ == [ Start ]) arr ?|| 0
8384 end = A.findIndex (_ == [ End ]) arr ?|| A.length arr
8485
85−renderSegments ∷ ReactComponent InlineCode.Props -> ((Array (Array Segment) -> Array (Array Segment)) -> Effect Unit) -> Array (Array Segment) -> JSX
86−renderSegments ic update arrs = R.div_ (A.mapWithIndex renderLine arrs)
86+renderSegments ∷ HighlighterTheme -> ReactComponent InlineCode.Props -> ((Array (Array Segment) -> Array (Array Segment)) -> Effect Unit) -> Array (Array Segment) -> JSX
87+renderSegments highlighterTheme ic update arrs = R.div_ (A.mapWithIndex renderLine arrs)
8788 where
8889 { start, end } = visibleRange arrs
8990 renderLine i l = R.div_ (A.mapWithIndex (renderSegment i) l)
9091 renderSegment i j s =
9192 if between start end i then case s of
92− Filler s' -> R.code_ [ R.text s' ]
93+ Filler s' -> element syntaxHighlighterImpl { style: highlighterTheme, language: "purescript", children: s' }
9394 Hole width _ ->
9495 element ic
9596 $ justifill
@@ -135,10 +136,10 @@ toSegment = case _ of
135136 other -> Filler other
136137
137138type Ctx r
138− = (Compiler + Highlighter r)
139+ = (Compiler r)
139140
140141makeComponent ∷ { | Ctx () } -> Effect (ReactComponent { code ∷ String })
141−makeComponent { compileAndRun, highlight } = do
142+makeComponent { compileAndRun } = do
142143 ic <- InlineCode.makeComponent
143144 modal <- Modal.makeComponent
144145 closeIcon <- CloseIcon.makeComponent
@@ -152,6 +153,9 @@ makeComponent { compileAndRun, highlight } = do
152153 initialSegments = lines <#> \line -> rawSegments line <#> toSegment
153154 segments /\ modifySegments <- useState initialSegments
154155 result /\ modifyResult <- useState Nothing
156+ cssTheme <- useTheme
157+ let
158+ highlighterTheme = mkHighlighterTheme cssTheme
155159 modalTransitions <-
156160 useTransition [ result ] (Just show)
157161 $ css
@@ -184,7 +188,7 @@ makeComponent { compileAndRun, highlight } = do
184188 modifyResult (const (Just $ res)) # liftEffect
185189 pure
186190 $ fragment
187− $ [ renderSegments ic (modifySegments) segments
191+ $ [ renderSegments highlighterTheme ic (modifySegments) segments
188192 , jsx cluster {}
189193 [ R.div_
190194 [ jsx button