@@ -0,0 +1,77 @@
1+module Editor.Component where
2+
3+import Prelude
4+import CSS.Safer (cssSafer)
5+import Data.Nullable (Nullable, notNull)
6+import Editor (defineThemeImpl, editor, initMonaco, nightOwlTheme, purescriptSyntax, registerLanguageImpl, setMonarchTokensProviderImpl, vsCodeTheme)
7+import Effect (Effect)
8+import Effect.Aff (Aff)
9+import Effect.Class (liftEffect)
10+import Effect.Uncurried (mkEffectFn2)
11+import Foreign (unsafeToForeign)
12+import React.Basic (ReactComponent, element, fragment)
13+import React.Basic.Hooks (Ref, component, writeRef)
14+import React.Basic.Hooks as React
15+import React.Basic.Hooks.Aff (useAff)
16+import React.Helpers (wrapperDiv)
17+import Theme.Styles (makeStyles, useTheme)
18+import Theme.Types (CSSTheme)
19+
20+darkThemeName ∷ String
21+darkThemeName = "NightOwl"
22+
23+lightThemeName ∷ String
24+lightThemeName = "VSCode"
25+
26+initEditor ∷ Aff Unit
27+initEditor = do
28+ monaco <- initMonaco
29+ defineThemeImpl monaco darkThemeName nightOwlTheme # liftEffect
30+ defineThemeImpl monaco lightThemeName vsCodeTheme # liftEffect
31+ registerLanguageImpl monaco "purescript" # liftEffect
32+ setMonarchTokensProviderImpl monaco "purescript" purescriptSyntax # liftEffect
33+
34+mkEditor ∷ Effect (ReactComponent { editorRef ∷ Ref (Nullable _) })
35+mkEditor = do
36+ useStyles <-
37+ makeStyles \(theme ∷ CSSTheme) ->
38+ { wrapper:
39+ cssSafer
40+ { margin: "0"
41+ , boxSizing: "border-box"
42+ , padding: "35px 40px"
43+ , width: "100%"
44+ , height: "100%"
45+ , borderRadius: "32px"
46+ , backgroundColor: theme.backgroundColour
47+ }
48+ }
49+ component "Editor" \{ editorRef } -> React.do
50+ classes <- useStyles
51+ useAff unit initEditor
52+ theme <- useTheme
53+ let
54+ themeName = if theme.isLight then lightThemeName else darkThemeName
55+ pure
56+ $ fragment
57+ [ wrapperDiv { className: classes.wrapper }
58+ $ element editor
59+ { theme: themeName
60+ , options:
61+ unsafeToForeign
62+ { fontFamily: "PragmataPro"
63+ , fontLigatures: true
64+ , fontSize: "16pt"
65+ , lineNumbers: "off"
66+ , glyphMargin: false
67+ , folding: false
68+ , lineDecorationsWidth: 0
69+ , lineNumbersMinChars: 0
70+ , minimap: { enabled: false }
71+ }
72+ , language: "purescript"
73+ -- https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-custom-languages
74+ , editorDidMount:
75+ mkEffectFn2 \_ -> notNull >>> writeRef editorRef
76+ }
77+ ]