@@ -0,0 +1,59 @@
1+module TipTap.React where
2+
3+import Prelude
4+
5+import Data.Maybe (Maybe)
6+import Data.Nullable (Nullable)
7+import Data.Nullable as Nullable
8+import Effect (Effect)
9+import Effect.Aff.Compat (EffectFn1, runEffectFn1)
10+import React.Basic.Hooks (Hook, JSX, ReactComponent, unsafeHook)
11+import TipTap.TipTap (Extension)
12+
13+foreign import data Editor :: Type
14+
15+type Props = { extensions :: Array Extension }
16+
17+foreign import useEditorImpl :: EffectFn1 Props (Nullable Editor)
18+
19+foreign import data UseEditor :: Type -> Type
20+
21+useEditor ∷ Props -> Hook (UseEditor) (Maybe Editor)
22+useEditor props = unsafeHook $ runEffectFn1 useEditorImpl props <#> Nullable.toMaybe
23+
24+foreign import editorContent :: ReactComponent { editor :: Editor }
25+
26+type TippyOptions = { duration :: Int }
27+
28+foreign import bubbleMenu :: ReactComponent { children :: Array JSX, editor :: Editor, tippyOptions :: TippyOptions }
29+
30+foreign import data ChainedCommands :: Type
31+
32+class ChainedCommandsBuilder input output | input -> output where
33+ chain :: input -> Effect output
34+ focus :: input -> Effect output
35+ toggleBold :: input -> Effect output
36+ toggleItalic :: input -> Effect output
37+ toggleStrike :: input -> Effect output
38+
39+foreign import chainImpl :: forall input output. EffectFn1 input output
40+foreign import focusImpl :: forall input output. EffectFn1 input output
41+foreign import toggleBoldImpl :: forall input output. EffectFn1 input output
42+foreign import toggleItalicImpl :: forall input output. EffectFn1 input output
43+foreign import toggleStrikeImpl :: forall input output. EffectFn1 input output
44+
45+instance ChainedCommandsBuilder Editor ChainedCommands where
46+ chain = runEffectFn1 chainImpl
47+ focus = runEffectFn1 focusImpl
48+ toggleBold = runEffectFn1 toggleBoldImpl
49+ toggleItalic = runEffectFn1 toggleItalicImpl
50+ toggleStrike = runEffectFn1 toggleStrikeImpl
51+
52+instance ChainedCommandsBuilder ChainedCommands ChainedCommands where
53+ chain = runEffectFn1 chainImpl
54+ focus = runEffectFn1 focusImpl
55+ toggleBold = runEffectFn1 toggleBoldImpl
56+ toggleItalic = runEffectFn1 toggleItalicImpl
57+ toggleStrike = runEffectFn1 toggleStrikeImpl
58+
59+foreign import run :: ChainedCommands -> Effect Boolean