@@ -36,17 +36,17 @@ import Yoga.FillInTheGaps.Logic (Segment, findResult, parseSegments, toCode)
36import Yoga.Helpers ((?||))
36import Yoga.Helpers ((?||))
37import Yoga as Y
37import Yoga as Y
39−type PreProps
39+type PreProps =
40− = { children ∷
40+ { children ∷
44− { mdxType ∷ Nullable String
44+ { mdxType ∷ Nullable String
45− , children ∷ Nullable String
45+ , children ∷ Nullable String
46− , className ∷ Nullable String
46+ , className ∷ Nullable String
51isQuiz ∷ MDX -> Boolean
51isQuiz ∷ MDX -> Boolean
52isQuiz (MDX a) =
52isQuiz (MDX a) =
@@ -55,9 +55,9 @@ isQuiz (MDX a) =
55 && ((unsafeCoerce a).props.children.props.mdxType == "code")
55 && ((unsafeCoerce a).props.children.props.mdxType == "code")
56 && ((unsafeCoerce a).props.children.props.children # parseSegments # isJust)
56 && ((unsafeCoerce a).props.children.props.children # parseSegments # isJust)
58−type MdxProviderProps
58+type MdxProviderProps =
59− = { children ∷ ReactChildren MDX
59+ { children ∷ ReactChildren MDX
62mkLiveMdxProviderComponent ∷ FetchImpl -> Effect (ReactComponent MdxProviderProps)
62mkLiveMdxProviderComponent ∷ FetchImpl -> Effect (ReactComponent MdxProviderProps)
63mkLiveMdxProviderComponent fetchImpl = mkMdxProviderComponent (apiCompiler fetchImpl)
63mkLiveMdxProviderComponent fetchImpl = mkMdxProviderComponent (apiCompiler fetchImpl)
@@ -75,38 +75,33 @@ mkMdxProviderComponent compiler = do
75 visibleUntil /\ updateVisible <- useState 1
75 visibleUntil /\ updateVisible <- useState 1
77 onFailure title kids = log "Oopsie daisy"
77 onFailure title kids = log "Oopsie daisy"
79 onSuccess = updateVisible (_ + one)
78 onSuccess = updateVisible (_ + one)
81 mapVisible ∷ Int -> MDX -> _
79 mapVisible ∷ Int -> MDX -> _
82 mapVisible i kid =
80 mapVisible i kid =
83 { accum: i + if isQuiz kid then one else zero
81 { accum: i + if isQuiz kid then one else zero
84 , value: if (i < visibleUntil) then Just kid else Nothing
82 , value: if (i < visibleUntil) then Just kid else Nothing
87 visibleKids ∷ Array MDX
84 visibleKids ∷ Array MDX
88 visibleKids =
85 visibleKids =
89 reactChildrenToArray children
86 reactChildrenToArray children
90 # mapAccumL mapVisible zero
87 # mapAccumL mapVisible zero
92 # Array.catMaybes
89 # Array.catMaybes
94 contentMDX ∷ ReactChildren MDX
90 contentMDX ∷ ReactChildren MDX
95 contentMDX = reactChildrenFromArray visibleKids
91 contentMDX = reactChildrenFromArray visibleKids
97 paragraph parChildren =
92 paragraph parChildren =
98 E.element M.p
93 E.element M.p
99 ( { layout: M.layout true
94 ( { layout: M.layout true
102− { fontFamily: E.str "Cormorant Garamond"
97+ { fontFamily: E.str "Cormorant Garamond"
103− , fontSize: E.str "min(calc(var(--s-1) + 2.4vw), var(--s1))"
98+ , fontSize: E.str "min(calc(var(--s-1) + 2.4vw), var(--s1))"
104− , lineHeight: E.var "--line-height-small"
99+ , lineHeight: E.var "--line-height-small"
105− , "-ms-hyphens": E.str "auto"
100+ , "-msHyphens": E.str "auto"
106− , "-webkit-hyphens": E.str "auto"
101+ , "-webkitHyphens": E.str "auto"
107− , hyphens: E.str "auto"
102+ , hyphens: E.str "auto"
108− , overflow: E.str "hidden"
103+ , overflow: E.str "hidden"
110 , className: "blog-p"
105 , className: "blog-p"
111 , children: parChildren
106 , children: parChildren
@@ -114,65 +109,56 @@ mkMdxProviderComponent compiler = do
115 mdxComponents =
110 mdxComponents =
117− \(props :: { children :: String }) ->
112+ \(props ∷ { children ∷ String }) ->
118− smallCaps props.children
113+ smallCaps props.children
120− \(props ∷ { | M.MotionProps Props_h1 }) ->
115+ \(props ∷ { | M.MotionProps Props_h1 }) ->
121− React.element M.h1 (props { layout = M.layout true })
116+ React.element M.h1 (props { layout = M.layout true })
123− \(props ∷ { | M.MotionProps Props_h2 }) ->
118+ \(props ∷ { | M.MotionProps Props_h2 }) ->
124− React.element M.h2 (props { layout = M.layout true })
119+ React.element M.h2 (props { layout = M.layout true })
126− \(props ∷ { | M.MotionProps Props_h3 }) ->
121+ \(props ∷ { | M.MotionProps Props_h3 }) ->
127− React.element M.h3 (props { layout = M.layout true })
122+ React.element M.h3 (props { layout = M.layout true })
129− \(props ∷ { | M.MotionProps Props_h4 }) ->
124+ \(props ∷ { | M.MotionProps Props_h4 }) ->
130− React.element M.h4 (props { layout = M.layout true })
125+ React.element M.h4 (props { layout = M.layout true })
131 , hr: (const $ R.hr {})
126 , hr: (const $ R.hr {})
133− \(props ∷ { children :: Array JSX }) ->
128+ \(props ∷ { children ∷ Array JSX }) ->
134− paragraph props.children
129+ paragraph props.children
135 , inlineCode:
130 , inlineCode:
136− \props -> do
131+ \props -> do
137− R.span { children: props.children }
132+ R.span { children: props.children }
139− mkFn2 \(props ∷ PreProps) other -> do
134+ mkFn2 \(props ∷ PreProps) other -> do
141− childrenQ = Nullable.toMaybe props.children
136+ childrenQ = Nullable.toMaybe props.children
143− propsQ = (_.props >>> Nullable.toMaybe) =<< childrenQ
137+ propsQ = (_.props >>> Nullable.toMaybe) =<< childrenQ
145− mdxTypeQ = (_.mdxType >>> Nullable.toMaybe) =<< propsQ
138+ mdxTypeQ = (_.mdxType >>> Nullable.toMaybe) =<< propsQ
147− childrenQ2 = (_.children >>> Nullable.toMaybe) =<< propsQ
139+ childrenQ2 = (_.children >>> Nullable.toMaybe) =<< propsQ
149− classNameQ = (_.className >>> Nullable.toMaybe) =<< propsQ
140+ classNameQ = (_.className >>> Nullable.toMaybe) =<< propsQ
151− isCode = fromMaybe false (mdxTypeQ <#> eq "code")
141+ isCode = fromMaybe false (mdxTypeQ <#> eq "code")
153− codeQ = childrenQ2
142+ codeQ = childrenQ2
155− height =
143+ height =
156− (fromMaybe 200 >>> show >>> (_ <> "px")) do
144+ (fromMaybe 200 >>> show >>> (_ <> "px")) do
157− code <- codeQ
145+ code <- codeQ
159− ( String.split (String.Pattern "\n") code
147+ ( String.split (String.Pattern "\n") code
160− # Array.length
148+ # Array.length
161− # \x -> (x * 12) + 100
149+ # \x -> (x * 12) + 100
164− language = fromMaybe "" (classNameQ >>= String.stripPrefix (String.Pattern "language-"))
151+ language = fromMaybe "" (classNameQ >>= String.stripPrefix (String.Pattern "language-"))
166− segmentsQ = parseSegments (codeQ ?|| "")
152+ segmentsQ = parseSegments (codeQ ?|| "")
167− case isCode, language, segmentsQ of
153+ case isCode, language, segmentsQ of
168− true, "purescript", Just initialSegments -> element quiz { initialSegments, onFailure, onSuccess }
154+ true, "purescript", Just initialSegments -> element quiz { initialSegments, onFailure, onSuccess }
169− true, _, _ ->
155+ true, _, _ ->
170− element editor
156+ element editor
171− { initialCode: fromMaybe "" codeQ
157+ { initialCode: fromMaybe "" codeQ
172− , height
158+ , height
173− , language
159+ , language
175− false, _, _ -> element (unsafePerformEffect $ unsafeCreateDOMComponent "pre") props
161+ false, _, _ -> element (unsafePerformEffect $ unsafeCreateDOMComponent "pre") props
178 $ element mdxProvider
164 $ element mdxProvider
@@ -180,11 +166,11 @@ mkMdxProviderComponent compiler = do
180 , components: mdxComponents
166 , components: mdxComponents
183−type QuizProps
169+type QuizProps =
184− = { initialSegments ∷ Array (Array Segment)
170+ { initialSegments ∷ Array (Array Segment)
185− , onFailure ∷ String -> Array JSX -> Effect Unit
171+ , onFailure ∷ String -> Array JSX -> Effect Unit
186− , onSuccess ∷ Effect Unit
172+ , onSuccess ∷ Effect Unit
189mkQuiz ∷ ∀ r. { | Compiler r } -> Effect (ReactComponent QuizProps)
175mkQuiz ∷ ∀ r. { | Compiler r } -> Effect (ReactComponent QuizProps)
190mkQuiz compiler = do
176mkQuiz compiler = do
@@ -196,24 +182,22 @@ mkQuiz compiler = do
196 $ element fillInTheGaps
182 $ element fillInTheGaps
197 { segments
183 { segments
199− launchAff_ do
185+ launchAff_ do
201− code = toCode segments
186+ let code = toCode segments
202− result <- compiler.compileAndRun { code }
187+ result <- compiler.compileAndRun { code }
203− liftEffect case result of
188+ liftEffect case result of
205− | String.stripSuffix (String.Pattern "\n") r.stdout == (findResult $ join segments) -> do
190+ | String.stripSuffix (String.Pattern "\n") r.stdout == (findResult $ join segments) -> do
206− updateSolvedWith (const $ String.stripSuffix (String.Pattern "\n") r.stdout)
191+ updateSolvedWith (const $ String.stripSuffix (String.Pattern "\n") r.stdout)
207− onSuccess
192+ onSuccess
209− | r.stdout /= "\n" -> onFailure "Oh shit!" [ R.text r.stdout ]
194+ | r.stdout /= "\n" -> onFailure "Oh shit!" [ R.text r.stdout ]
210− Right r -> onFailure "Oh shit!" [ R.text r.stderr ]
195+ Right r -> onFailure "Oh shit!" [ R.text r.stderr ]
211− Left (cr ∷ CompileResult) -> onFailure "Oh shit!" [ R.text (intercalate ", " (cr.result <#> _.message)) ]
196+ Left (cr ∷ CompileResult) -> onFailure "Oh shit!" [ R.text (intercalate ", " (cr.result <#> _.message)) ]
212 , updateSegments:
197 , updateSegments:
213− \update -> do
198+ \update -> do
215− updated = update segments
199+ let updated = update segments
216− unless (segments == updated) do updateSegments (const updated)
200+ unless (segments == updated) do updateSegments (const updated)
217 , solvedWith
201 , solvedWith