on develop help sign in
Remove template haskell and update ghcjs-dom
commit36f45a4c6d674b2a4bbcacee801d54170baa780c authorHamish Mackenzie <Hamish.K.Mackenzie@googlemail.com> dateTue 15 Nov 2016, 01:11 (10 years ago) parente2ca32c
14 files changed+602−172
reflex-dom.cabal+7−16 src-ghc/Reflex/Dom/WebSocket/Foreign.hs−1 src-ghc/Reflex/Dom/Xhr/Foreign.hs−2 src-ghcjs/Reflex/Dom/Internal/Foreign.hs+1−2 src-ghcjs/Reflex/Dom/Xhr/Foreign.hs+1−2 src/Foreign/JavaScript/TH.hs+76−76 src/Reflex/Dom/Builder/Class.hs+106−11 src/Reflex/Dom/Builder/Class/Events.hs+205−4 src/Reflex/Dom/Builder/Immediate.hs+15−5 src/Reflex/Dom/Builder/InputDisabled.hs+3−3 src/Reflex/Dom/Internal.hs+35−22 src/Reflex/Dom/Location.hs−1 src/Reflex/Dom/Old.hs+9−12 src/Reflex/Dom/Widget/Input.hs+144−15
reflex-dom.cabal+7−16
@@ -11,8 +11,7 @@ Category: FRP, Web, GUI, HTML, Javascript, Reactive, Reactivity, User Interfaces
1111Build-type: Simple
1212Cabal-version: >=1.9.2
1313-- Deal with https://github.com/haskell/cabal/issues/2544 / https://github.com/haskell/cabal/issues/367
14−extra-source-files: src-ghc/Reflex/Dom/Internal/Foreign.hs
15− src-ghc/Reflex/Dom/Xhr/Foreign.hs
14+extra-source-files: src-ghc/Reflex/Dom/Xhr/Foreign.hs
1615 src-ghc/Reflex/Dom/WebSocket/Foreign.hs
1716 src-ghcjs/Reflex/Dom/Internal/Foreign.hs
1817 src-ghcjs/Reflex/Dom/Xhr/Foreign.hs
@@ -27,7 +26,7 @@ library
2726 template-haskell,
2827 stm == 2.4.*,
2928 reflex == 0.5.*,
30− dependent-sum == 0.3.*,
29+ dependent-sum == 0.4.*,
3130 dependent-map == 0.2.*,
3231 semigroups >= 0.16 && < 0.19,
3332 mtl >= 2.1 && < 2.3,
@@ -35,7 +34,7 @@ library
3534 these >= 0.4 && < 0.8,
3635 ref-tf == 0.4.*,
3736 random == 1.1.*,
38− ghcjs-dom >= 0.5.0.0 && < 0.6,
37+ ghcjs-dom >= 0.6.0.0 && < 0.7,
3938 transformers >= 0.3 && < 0.6,
4039 lens >= 4.7 && < 5,
4140 text == 1.2.*,
@@ -46,13 +45,13 @@ library
4645 time >= 1.4 && < 1.7,
4746 exception-transformers == 0.4.*,
4847 directory == 1.2.*,
49− dependent-sum-template >= 0.0.0.4 && < 0.1,
5048 zenc == 0.1.*,
5149 bifunctors >= 4.2 && < 6,
5250 bimap >= 0.3 && < 0.4,
5351 monad-control >= 1.0.1 && < 1.1,
5452 keycode == 0.2.*,
55− unbounded-delays >= 0.1.0.9 && < 0.2
53+ unbounded-delays >= 0.1.0.9 && < 0.2,
54+ contravariant >= 1.4 && < 1.5
5655
5756 if impl(ghcjs)
5857 hs-source-dirs: src-ghcjs
@@ -62,14 +61,7 @@ library
6261 else
6362 hs-source-dirs: src-ghc
6463 build-depends:
65− haskell-gi-base >=0.18 && <0.19,
66− gi-glib >=2.0.6 && <2.1,
67− gi-gtk >=3.0.6 && <3.1,
68− gi-webkit2 >=4.0.6 && <4.1,
69− jsaddle >=0.5.1.1 && <0.6,
70− raw-strings-qq
71− pkgconfig-depends:
72− webkit2gtk-4.0 >= 2.12
64+ jsaddle >=0.6.0.0 && <0.7
7365 if !os(windows)
7466 build-depends: unix == 2.7.*
7567
@@ -83,7 +75,7 @@ library
8375 Reflex.Dom.Builder.Static
8476 Reflex.Dom.Class
8577 Reflex.Dom.Internal
86− Reflex.Dom.Internal.Foreign
78+-- Reflex.Dom.Internal.Foreign
8779-- Reflex.Dom.Location
8880 Reflex.Dom.Old
8981 Reflex.Dom.Time
@@ -100,7 +92,6 @@ library
10092-- Reflex.Dom.Xhr.ResponseType
10193-- Reflex.Dom.Xhr.Exception
10294
103− other-extensions: TemplateHaskell
10495 ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -O2 -ferror-spans
10596
10697--test-suite hlint
src-ghc/Reflex/Dom/WebSocket/Foreign.hs−1
@@ -34,7 +34,6 @@ import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSValueRef
3434import Graphics.UI.Gtk.WebKit.WebView
3535
3636import Foreign.JavaScript.TH
37−import Reflex.Dom.Internal.Foreign
3837
3938data JSWebSocket = JSWebSocket { wsValue :: JSValueRef
4039 , wsContext :: JSContextRef
src-ghc/Reflex/Dom/Xhr/Foreign.hs−2
@@ -21,8 +21,6 @@ import Reflex.Dom.Xhr.Exception
2121import Reflex.Dom.Xhr.ResponseType
2222import System.Glib.FFI
2323
24−import Reflex.Dom.Internal.Foreign
25−
2624import Text.RawString.QQ
2725
2826data XMLHttpRequest
src-ghcjs/Reflex/Dom/Internal/Foreign.hs+1−2
@@ -1,7 +1,6 @@
11{-# LANGUAGE ForeignFunctionInterface #-}
22{-# LANGUAGE JavaScriptFFI #-}
3−module Reflex.Dom.Internal.Foreign ( module Reflex.Dom.Internal.Foreign
4− , runWebGUI
3+module Reflex.Dom.Internal.Foreign ( runWebGUI
54 , WebView
65 ) where
76
src-ghcjs/Reflex/Dom/Xhr/Foreign.hs+1−2
@@ -20,7 +20,6 @@ import GHCJS.DOM.Types hiding (Text)
2020import GHCJS.DOM.XMLHttpRequest
2121import GHCJS.Types
2222import Prelude hiding (error)
23−import Reflex.Dom.Internal.Foreign
2423import Reflex.Dom.Xhr.Exception
2524import Reflex.Dom.Xhr.ResponseType
2625
@@ -51,7 +50,7 @@ instance IsXhrPayload String where
5150
5251instance IsXhrPayload Text where
5352 sendXhrPayload = sendString
54−
53+
5554instance IsXhrPayload FormData where
5655 sendXhrPayload = sendFormData
5756
src/Foreign/JavaScript/TH.hs+76−76
@@ -9,7 +9,6 @@
99{-# LANGUAGE MultiParamTypeClasses #-}
1010{-# LANGUAGE RankNTypes #-}
1111{-# LANGUAGE StandaloneDeriving #-}
12−{-# LANGUAGE TemplateHaskell #-}
1312{-# LANGUAGE TypeFamilies #-}
1413{-# LANGUAGE TypeSynonymInstances #-}
1514{-# LANGUAGE UndecidableInstances #-}
@@ -55,11 +54,8 @@ import Data.Coerce (coerce)
5554import Foreign.C.Types
5655import Foreign.Ptr
5756import Text.Encoding.Z
58−
59−import Reflex.Dom.Internal.Foreign (WebView)
6057#else
6158import Data.Word (Word8)
62−import GI.WebKit2 (WebView)
6359import Control.Lens.Operators ((^.))
6460import Language.Javascript.JSaddle
6561 (eval, valMakeString, valToNumber, function,
@@ -84,58 +80,58 @@ import Data.Monoid
8480import Data.Text (Text)
8581import qualified Data.Text as T
8682
87−class Monad m => HasWebView m where
88− type WebViewPhantom m :: *
89− askWebView :: m (WebViewSingleton (WebViewPhantom m))
83+class Monad m => HasJSContext m where
84+ type JSContextPhantom m :: *
85+ askJSContext :: m (JSContextSingleton (JSContextPhantom m))
9086
91−instance HasWebView m => HasWebView (ReaderT r m) where
92− type WebViewPhantom (ReaderT r m) = WebViewPhantom m
93− askWebView = lift askWebView
87+instance HasJSContext m => HasJSContext (ReaderT r m) where
88+ type JSContextPhantom (ReaderT r m) = JSContextPhantom m
89+ askJSContext = lift askJSContext
9490
95−instance HasWebView m => HasWebView (StateT r m) where
96− type WebViewPhantom (StateT r m) = WebViewPhantom m
97− askWebView = lift askWebView
91+instance HasJSContext m => HasJSContext (StateT r m) where
92+ type JSContextPhantom (StateT r m) = JSContextPhantom m
93+ askJSContext = lift askJSContext
9894
99−instance HasWebView m => HasWebView (Strict.StateT r m) where
100− type WebViewPhantom (Strict.StateT r m) = WebViewPhantom m
101− askWebView = lift askWebView
95+instance HasJSContext m => HasJSContext (Strict.StateT r m) where
96+ type JSContextPhantom (Strict.StateT r m) = JSContextPhantom m
97+ askJSContext = lift askJSContext
10298
103−instance HasWebView m => HasWebView (PostBuildT t m) where
104− type WebViewPhantom (PostBuildT t m) = WebViewPhantom m
105− askWebView = lift askWebView
99+instance HasJSContext m => HasJSContext (PostBuildT t m) where
100+ type JSContextPhantom (PostBuildT t m) = JSContextPhantom m
101+ askJSContext = lift askJSContext
106102
107−instance (ReflexHost t, HasWebView (HostFrame t)) => HasWebView (PerformEventT t m) where
108− type WebViewPhantom (PerformEventT t m) = WebViewPhantom (HostFrame t)
109− askWebView = PerformEventT $ lift askWebView
103+instance (ReflexHost t, HasJSContext (HostFrame t)) => HasJSContext (PerformEventT t m) where
104+ type JSContextPhantom (PerformEventT t m) = JSContextPhantom (HostFrame t)
105+ askJSContext = PerformEventT $ lift askJSContext
110106
111−instance HasWebView m => HasWebView (DynamicWriterT t w m) where
112− type WebViewPhantom (DynamicWriterT t w m) = WebViewPhantom m
113− askWebView = lift askWebView
107+instance HasJSContext m => HasJSContext (DynamicWriterT t w m) where
108+ type JSContextPhantom (DynamicWriterT t w m) = JSContextPhantom m
109+ askJSContext = lift askJSContext
114110
115−newtype WithWebView x m a = WithWebView { unWithWebView :: ReaderT (WebViewSingleton x) m a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadTrans, MonadException, MonadAsyncException)
111+newtype WithJSContextSingleton x m a = WithJSContextSingleton { unWithJSContextSingleton :: ReaderT (JSContextSingleton x) m a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadTrans, MonadException, MonadAsyncException)
116112
117−instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (WithWebView x m) where
113+instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (WithJSContextSingleton x m) where
118114 {-# INLINABLE newEventWithTrigger #-}
119115 newEventWithTrigger = lift . newEventWithTrigger
120116 {-# INLINABLE newFanEventWithTrigger #-}
121117 newFanEventWithTrigger f = lift $ newFanEventWithTrigger f
122118
123−instance MonadSubscribeEvent t m => MonadSubscribeEvent t (WithWebView x m) where
119+instance MonadSubscribeEvent t m => MonadSubscribeEvent t (WithJSContextSingleton x m) where
124120 {-# INLINABLE subscribeEvent #-}
125121 subscribeEvent = lift . subscribeEvent
126122
127−instance MonadReflexHost t m => MonadReflexHost t (WithWebView x m) where
128− type ReadPhase (WithWebView x m) = ReadPhase m
123+instance MonadReflexHost t m => MonadReflexHost t (WithJSContextSingleton x m) where
124+ type ReadPhase (WithJSContextSingleton x m) = ReadPhase m
129125 {-# INLINABLE fireEventsAndRead #-}
130126 fireEventsAndRead dm a = lift $ fireEventsAndRead dm a
131127 {-# INLINABLE runHostFrame #-}
132128 runHostFrame = lift . runHostFrame
133129
134−instance MonadSample t m => MonadSample t (WithWebView x m) where
130+instance MonadSample t m => MonadSample t (WithJSContextSingleton x m) where
135131 {-# INLINABLE sample #-}
136132 sample = lift . sample
137133
138−instance MonadHold t m => MonadHold t (WithWebView x m) where
134+instance MonadHold t m => MonadHold t (WithJSContextSingleton x m) where
139135 {-# INLINABLE hold #-}
140136 hold v0 = lift . hold v0
141137 {-# INLINABLE holdDyn #-}
@@ -143,45 +139,45 @@ instance MonadHold t m => MonadHold t (WithWebView x m) where
143139 {-# INLINABLE holdIncremental #-}
144140 holdIncremental v0 = lift . holdIncremental v0
145141
146−instance MonadTransControl (WithWebView x) where
147− type StT (WithWebView x) a = StT (ReaderT (WebViewSingleton x)) a
142+instance MonadTransControl (WithJSContextSingleton x) where
143+ type StT (WithJSContextSingleton x) a = StT (ReaderT (JSContextSingleton x)) a
148144 {-# INLINABLE liftWith #-}
149− liftWith = defaultLiftWith WithWebView unWithWebView
145+ liftWith = defaultLiftWith WithJSContextSingleton unWithJSContextSingleton
150146 {-# INLINABLE restoreT #-}
151− restoreT = defaultRestoreT WithWebView
147+ restoreT = defaultRestoreT WithJSContextSingleton
152148
153−instance PerformEvent t m => PerformEvent t (WithWebView x m) where
154− type Performable (WithWebView x m) = WithWebView x (Performable m)
149+instance PerformEvent t m => PerformEvent t (WithJSContextSingleton x m) where
150+ type Performable (WithJSContextSingleton x m) = WithJSContextSingleton x (Performable m)
155151 {-# INLINABLE performEvent_ #-}
156152 performEvent_ e = liftWith $ \run -> performEvent_ $ fmap run e
157153 {-# INLINABLE performEvent #-}
158154 performEvent e = liftWith $ \run -> performEvent $ fmap run e
159155
160−instance Deletable t m => Deletable t (WithWebView x m) where
156+instance Deletable t m => Deletable t (WithJSContextSingleton x m) where
161157 {-# INLINABLE deletable #-}
162158 deletable = liftThrough . deletable
163159
164−runWithWebView :: WithWebView x m a -> WebViewSingleton x -> m a
165−runWithWebView = runReaderT . unWithWebView
160+runWithJSContextSingleton :: WithJSContextSingleton x m a -> JSContextSingleton x -> m a
161+runWithJSContextSingleton = runReaderT . unWithJSContextSingleton
166162
167−instance (Monad m) => HasWebView (WithWebView x m) where
168− type WebViewPhantom (WithWebView x m) = x
169− askWebView = WithWebView ask
163+instance (Monad m) => HasJSContext (WithJSContextSingleton x m) where
164+ type JSContextPhantom (WithJSContextSingleton x m) = x
165+ askJSContext = WithJSContextSingleton ask
170166
171−instance MonadRef m => MonadRef (WithWebView x m) where
172− type Ref (WithWebView x m) = Ref m
167+instance MonadRef m => MonadRef (WithJSContextSingleton x m) where
168+ type Ref (WithJSContextSingleton x m) = Ref m
173169 newRef = lift . newRef
174170 readRef = lift . readRef
175171 writeRef r = lift . writeRef r
176172
177−instance MonadAtomicRef m => MonadAtomicRef (WithWebView x m) where
173+instance MonadAtomicRef m => MonadAtomicRef (WithJSContextSingleton x m) where
178174 atomicModifyRef r = lift . atomicModifyRef r
179175
180−withWebViewSingleton :: (WebView, JSContextRef) -> (forall x. WebViewSingleton x -> r) -> r
181−withWebViewSingleton wv f = f $ WebViewSingleton wv
176+withJSContextSingleton :: MonadJSM m => (forall x. JSContextSingleton x -> m r) -> m r
177+withJSContextSingleton f = askJSM >>= f . JSContextSingleton
182178
183−-- | A singleton type for a given WebView; we use this to statically guarantee that different WebViews (and thus different javscript contexts) don't get mixed up
184−newtype WebViewSingleton x = WebViewSingleton { unWebViewSingleton :: (WebView, JSContextRef) }
179+-- | A singleton type for a given JS Context; we use this to statically guarantee that different JSContexts (and thus different javscript contexts) don't get mixed up
180+newtype JSContextSingleton x = JSContextSingleton { unJSContextSingleton :: JSContextRef }
185181
186182#ifdef __GHCJS__
187183type JSFFI_Internal = JS.MutableJSArray -> IO JS.JSVal
@@ -250,8 +246,8 @@ class Monad m => MonadJS x m | m -> x where
250246
251247data JSCtx_IO
252248
253−instance MonadIO m => HasJS JSCtx_IO (WithWebView x m) where
254− type JSX (WithWebView x m) = IO
249+instance MonadIO m => HasJS JSCtx_IO (WithJSContextSingleton x m) where
250+ type JSX (WithJSContextSingleton x m) = IO
255251 liftJS = liftIO
256252
257253instance IsJSContext JSCtx_IO where
@@ -305,21 +301,21 @@ data JSCtx_JavaScriptCore x
305301instance IsJSContext (JSCtx_JavaScriptCore x) where
306302 newtype JSRef (JSCtx_JavaScriptCore x) = JSRef_JavaScriptCore { unJSRef_JavaScriptCore :: JSVal }
307303
308−instance MonadIO m => HasJS (JSCtx_JavaScriptCore x) (WithWebView x m) where
309− type JSX (WithWebView x m) = WithWebView x IO
304+instance MonadIO m => HasJS (JSCtx_JavaScriptCore x) (WithJSContextSingleton x m) where
305+ type JSX (WithJSContextSingleton x m) = WithJSContextSingleton x IO
310306 liftJS a = do
311− wv <- askWebView
312− liftIO $ runWithWebView a wv
307+ wv <- askJSContext
308+ liftIO $ runWithJSContextSingleton a wv
313309
314310newtype WithJSContext x m a = WithJSContext { unWithJSContext :: ReaderT JSContextRef m a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadTrans, MonadException, MonadAsyncException)
315311
316312runWithJSContext :: WithJSContext x m a -> JSContextRef -> m a
317313runWithJSContext = runReaderT . unWithJSContext
318314
319−instance MonadIO m => MonadJSM (WithWebView x m) where
315+instance MonadIO m => MonadJSM (WithJSContextSingleton x m) where
320316 liftJSM' f = do
321− wv <- askWebView
322− runJSM f . snd $ unWebViewSingleton wv
317+ wv <- askJSContext
318+ runJSM f $ unJSContextSingleton wv
323319
324320instance MonadIO m => MonadJSM (WithJSContext x m) where
325321 liftJSM' f =
@@ -330,21 +326,21 @@ lowerWithJSContext a = do
330326 c <- askJSM
331327 liftIO $ runWithJSContext a c
332328
333−liftWithWebViewThroughWithJSContext :: (HasWebView m, MonadJSM m, MonadTrans t, Monad m1)
329+liftWithJSContextSingletonThroughWithJSContext :: (HasJSContext m, MonadJSM m, MonadTrans t, Monad m1)
334330 => ((t1 -> t m1 a) -> WithJSContext x IO b)
335− -> (t1 -> WithWebView (WebViewPhantom m) m1 a)
331+ -> (t1 -> WithJSContextSingleton (JSContextPhantom m) m1 a)
336332 -> m b
337−liftWithWebViewThroughWithJSContext f a = do
338− wv <- askWebView
339− lowerWithJSContext $ f $ \b' -> lift $ runWithWebView (a b') wv
333+liftWithJSContextSingletonThroughWithJSContext f a = do
334+ wv <- askJSContext
335+ lowerWithJSContext $ f $ \b' -> lift $ runWithJSContextSingleton (a b') wv
340336
341−instance MonadJS (JSCtx_JavaScriptCore x) (WithWebView x IO) where
337+instance MonadJS (JSCtx_JavaScriptCore x) (WithJSContextSingleton x IO) where
342338 forkJS a = do
343− wv <- askWebView
344− liftIO $ forkIO $ runWithWebView a wv
339+ wv <- askJSContext
340+ liftIO $ forkIO $ runWithJSContextSingleton a wv
345341 mkJSFun a = do
346− wv <- askWebView
347− lowerWithJSContext $ mkJSFun $ \args -> lift $ runWithWebView (a args) wv
342+ wv <- askJSContext
343+ lowerWithJSContext $ mkJSFun $ \args -> lift $ runWithJSContextSingleton (a args) wv
348344 runJS expr args = lowerWithJSContext $ runJS expr args
349345 mkJSUndefined = lowerWithJSContext mkJSUndefined
350346 isJSNull = lowerWithJSContext . isJSNull
@@ -355,12 +351,12 @@ instance MonadJS (JSCtx_JavaScriptCore x) (WithWebView x IO) where
355351 fromJSUint8Array = lowerWithJSContext . fromJSUint8Array
356352 fromJSNumber = lowerWithJSContext . fromJSNumber
357353 freeJSFun = lowerWithJSContext . freeJSFun
358− withJSBool = liftWithWebViewThroughWithJSContext . withJSBool
359− withJSString = liftWithWebViewThroughWithJSContext . withJSString
360− withJSNumber = liftWithWebViewThroughWithJSContext . withJSNumber
361− withJSArray = liftWithWebViewThroughWithJSContext . withJSArray
362− withJSUint8Array = liftWithWebViewThroughWithJSContext . withJSUint8Array
363− withJSNode = liftWithWebViewThroughWithJSContext . withJSNode
354+ withJSBool = liftWithJSContextSingletonThroughWithJSContext . withJSBool
355+ withJSString = liftWithJSContextSingletonThroughWithJSContext . withJSString
356+ withJSNumber = liftWithJSContextSingletonThroughWithJSContext . withJSNumber
357+ withJSArray = liftWithJSContextSingletonThroughWithJSContext . withJSArray
358+ withJSUint8Array = liftWithJSContextSingletonThroughWithJSContext . withJSUint8Array
359+ withJSNode = liftWithJSContextSingletonThroughWithJSContext . withJSNode
364360 setJSProp propName valRef objRef = lowerWithJSContext $ setJSProp propName valRef objRef
365361 getJSProp propName objRef = lowerWithJSContext $ getJSProp propName objRef
366362
@@ -485,6 +481,8 @@ instance ToJS x Node where
485481 withJS = withJSNode
486482
487483
484+#if 0
485+
488486importJS :: Safety -> String -> String -> Q Type -> Q [Dec]
489487importJS safety body name qt = do
490488 t <- qt
@@ -532,3 +530,5 @@ parseType (ForallT _ [AppT (AppT (ConT monadJs) (VarT _)) (VarT m)] funType)
532530 | m' == m -> ([], result)
533531 _ -> error $ "parseType: can't parse type " <> show t
534532parseType t = error $ "parseType: can't parse type " <> show t
533+
534+#endif
src/Reflex/Dom/Builder/Class.hs+106−11
@@ -12,7 +12,6 @@
1212{-# LANGUAGE RankNTypes #-}
1313{-# LANGUAGE RecursiveDo #-}
1414{-# LANGUAGE ScopedTypeVariables #-}
15−{-# LANGUAGE TemplateHaskell #-}
1615{-# LANGUAGE TypeFamilies #-}
1716{-# LANGUAGE UndecidableInstances #-}
1817module Reflex.Dom.Builder.Class
@@ -153,6 +152,17 @@ data TextNodeConfig t
153152 , _textNodeConfig_setContents :: Event t Text
154153 }
155154
155+textNodeConfig_initialContents :: Lens' (TextNodeConfig t) Text
156+textNodeConfig_initialContents f (TextNodeConfig a b) = (\a' -> TextNodeConfig a' b) <$> f a
157+{-# INLINE textNodeConfig_initialContents #-}
158+textNodeConfig_setContents :: Lens
159+ (TextNodeConfig t1)
160+ (TextNodeConfig t2)
161+ (Event t1 Text)
162+ (Event t2 Text)
163+textNodeConfig_setContents f (TextNodeConfig a b) = (\b' -> TextNodeConfig a b') <$> f b
164+{-# INLINE textNodeConfig_setContents #-}
165+
156166instance (Reflex t) => Default (TextNodeConfig t) where
157167 {-# INLINABLE def #-}
158168 def = TextNodeConfig
@@ -217,6 +227,27 @@ data ElementConfig er t m
217227 , _elementConfig_eventSpec :: EventSpec (DomBuilderSpace m) er
218228 }
219229
230+elementConfig_namespace :: Lens' (ElementConfig er t m) (Maybe Namespace)
231+elementConfig_namespace f (ElementConfig a b c d) = (\a' -> ElementConfig a' b c d) <$> f a
232+{-# INLINE elementConfig_namespace #-}
233+elementConfig_initialAttributes :: Lens' (ElementConfig er t m) (Map AttributeName Text)
234+elementConfig_initialAttributes f (ElementConfig a b c d) = (\b' -> ElementConfig a b' c d) <$> f b
235+{-# INLINE elementConfig_initialAttributes #-}
236+elementConfig_modifyAttributes :: Lens
237+ (ElementConfig er t1 m)
238+ (ElementConfig er t2 m)
239+ (Event t1 (Map AttributeName (Maybe Text)))
240+ (Event t2 (Map AttributeName (Maybe Text)))
241+elementConfig_modifyAttributes f (ElementConfig a b c d) = (\c' -> ElementConfig a b c' d) <$> f c
242+{-# INLINE elementConfig_modifyAttributes #-}
243+elementConfig_eventSpec :: Lens
244+ (ElementConfig er1 t m1)
245+ (ElementConfig er2 t m2)
246+ (EventSpec (DomBuilderSpace m1) er1)
247+ (EventSpec (DomBuilderSpace m2) er2)
248+elementConfig_eventSpec f (ElementConfig a b c d) = (\d' -> ElementConfig a b c d') <$> f d
249+{-# INLINE elementConfig_eventSpec #-}
250+
220251data Element er d t
221252 = Element { _element_events :: EventSelector t (WrapArg er EventName) --TODO: EventSelector should have two arguments
222253 , _element_raw :: RawElement d
@@ -227,6 +258,17 @@ data PlaceholderConfig above t m
227258 , _placeholderConfig_deleteSelf :: Event t ()
228259 }
229260
261+placeholderConfig_insertAbove :: Lens
262+ (PlaceholderConfig above1 t m1)
263+ (PlaceholderConfig above2 t m2)
264+ (Event t (m1 above1))
265+ (Event t (m2 above2))
266+placeholderConfig_insertAbove f (PlaceholderConfig a b) = (\a' -> PlaceholderConfig a' b) <$> f a
267+{-# INLINE placeholderConfig_insertAbove #-}
268+placeholderConfig_deleteSelf :: Lens' (PlaceholderConfig above t m) (Event t ())
269+placeholderConfig_deleteSelf f (PlaceholderConfig a b) = (\b' -> PlaceholderConfig a b') <$> f b
270+{-# INLINE placeholderConfig_deleteSelf #-}
271+
230272instance Reflex t => Default (PlaceholderConfig above t m) where
231273 {-# INLINABLE def #-}
232274 def = PlaceholderConfig
@@ -247,6 +289,26 @@ data InputElementConfig er t m
247289 , _inputElementConfig_elementConfig :: ElementConfig er t m
248290 }
249291
292+inputElementConfig_initialValue :: Lens' (InputElementConfig er t m) Text
293+inputElementConfig_initialValue f (InputElementConfig a b c d e) = (\a' -> InputElementConfig a' b c d e) <$> f a
294+{-# INLINE inputElementConfig_initialValue #-}
295+inputElementConfig_setValue :: Lens' (InputElementConfig er t m) (Event t Text)
296+inputElementConfig_setValue f (InputElementConfig a b c d e) = (\b' -> InputElementConfig a b' c d e) <$> f b
297+{-# INLINE inputElementConfig_setValue #-}
298+inputElementConfig_initialChecked :: Lens' (InputElementConfig er t m) Bool
299+inputElementConfig_initialChecked f (InputElementConfig a b c d e) = (\c' -> InputElementConfig a b c' d e) <$> f c
300+{-# INLINE inputElementConfig_initialChecked #-}
301+inputElementConfig_setChecked :: Lens' (InputElementConfig er t m) (Event t Bool)
302+inputElementConfig_setChecked f (InputElementConfig a b c d e) = (\d' -> InputElementConfig a b c d' e) <$> f d
303+{-# INLINE inputElementConfig_setChecked #-}
304+inputElementConfig_elementConfig :: Lens
305+ (InputElementConfig er1 t m1)
306+ (InputElementConfig er2 t m2)
307+ (ElementConfig er1 t m1)
308+ (ElementConfig er2 t m2)
309+inputElementConfig_elementConfig f (InputElementConfig a b c d e) = (\e' -> InputElementConfig a b c d e') <$> f e
310+{-# INLINE inputElementConfig_elementConfig #-}
311+
250312instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (InputElementConfig er t m) where
251313 {-# INLINABLE def #-}
252314 def = InputElementConfig
@@ -274,6 +336,20 @@ data TextAreaElementConfig er t m
274336 , _textAreaElementConfig_elementConfig :: ElementConfig er t m
275337 }
276338
339+textAreaElementConfig_initialValue :: Lens' (TextAreaElementConfig er t m) Text
340+textAreaElementConfig_initialValue f (TextAreaElementConfig a b c) = (\a' -> TextAreaElementConfig a' b c) <$> f a
341+{-# INLINE textAreaElementConfig_initialValue #-}
342+textAreaElementConfig_setValue :: Lens' (TextAreaElementConfig er t m) (Event t Text)
343+textAreaElementConfig_setValue f (TextAreaElementConfig a b c) = (\b' -> TextAreaElementConfig a b' c) <$> f b
344+{-# INLINE textAreaElementConfig_setValue #-}
345+textAreaElementConfig_elementConfig :: Lens
346+ (TextAreaElementConfig er1 t m1)
347+ (TextAreaElementConfig er2 t m2)
348+ (ElementConfig er1 t m1)
349+ (ElementConfig er2 t m2)
350+textAreaElementConfig_elementConfig f (TextAreaElementConfig a b c) = (\c' -> TextAreaElementConfig a b c') <$> f c
351+{-# INLINE textAreaElementConfig_elementConfig #-}
352+
277353instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (TextAreaElementConfig er t m) where
278354 {-# INLINABLE def #-}
279355 def = TextAreaElementConfig
@@ -301,6 +377,21 @@ data RawElementConfig er t m = RawElementConfig
301377 , _rawElementConfig_eventSpec :: EventSpec (DomBuilderSpace m) er
302378 }
303379
380+rawElementConfig_modifyAttributes :: Lens
381+ (RawElementConfig er t1 m)
382+ (RawElementConfig er t2 m)
383+ (Event t1 (Map AttributeName (Maybe Text)))
384+ (Event t2 (Map AttributeName (Maybe Text)))
385+rawElementConfig_modifyAttributes f (RawElementConfig a b) = (\a' -> RawElementConfig a' b) <$> f a
386+{-# INLINE rawElementConfig_modifyAttributes #-}
387+rawElementConfig_eventSpec :: Lens
388+ (RawElementConfig er1 t m1)
389+ (RawElementConfig er2 t m2)
390+ (EventSpec (DomBuilderSpace m1) er1)
391+ (EventSpec (DomBuilderSpace m2) er2)
392+rawElementConfig_eventSpec f (RawElementConfig a b) = (\b' -> RawElementConfig a b') <$> f b
393+{-# INLINE rawElementConfig_eventSpec #-}
394+
304395instance (Reflex t, DomSpace (DomBuilderSpace m)) => Default (RawElementConfig EventResult t m) where
305396 def = RawElementConfig
306397 { _rawElementConfig_modifyAttributes = never
@@ -313,6 +404,20 @@ data SelectElementConfig er t m = SelectElementConfig
313404 , _selectElementConfig_elementConfig :: ElementConfig er t m
314405 }
315406
407+selectElementConfig_initialValue :: Lens' (SelectElementConfig er t m) Text
408+selectElementConfig_initialValue f (SelectElementConfig a b c) = (\a' -> SelectElementConfig a' b c) <$> f a
409+{-# INLINE selectElementConfig_initialValue #-}
410+selectElementConfig_setValue :: Lens' (SelectElementConfig er t m) (Event t Text)
411+selectElementConfig_setValue f (SelectElementConfig a b c) = (\b' -> SelectElementConfig a b' c) <$> f b
412+{-# INLINE selectElementConfig_setValue #-}
413+selectElementConfig_elementConfig :: Lens
414+ (SelectElementConfig er1 t m1)
415+ (SelectElementConfig er2 t m2)
416+ (ElementConfig er1 t m1)
417+ (ElementConfig er2 t m2)
418+selectElementConfig_elementConfig f (SelectElementConfig a b c) = (\c' -> SelectElementConfig a b c') <$> f c
419+{-# INLINE selectElementConfig_elementConfig #-}
420+
316421instance (Reflex t, er ~ EventResult, DomBuilder t m) => Default (SelectElementConfig er t m) where
317422 def = SelectElementConfig
318423 { _selectElementConfig_initialValue = ""
@@ -328,16 +433,6 @@ data SelectElement er d t = SelectElement
328433 , _selectElement_raw :: RawSelectElement d
329434 }
330435
331−concat <$> mapM makeLenses
332− [ ''TextNodeConfig
333− , ''ElementConfig
334− , ''PlaceholderConfig
335− , ''InputElementConfig
336− , ''TextAreaElementConfig
337− , ''SelectElementConfig
338− , ''RawElementConfig
339− ]
340−
341436class CanDeleteSelf t a | a -> t where
342437 deleteSelf :: Lens' a (Event t ())
343438
src/Reflex/Dom/Builder/Class/Events.hs+205−4
@@ -2,11 +2,12 @@
22{-# LANGUAGE GADTs #-}
33{-# LANGUAGE KindSignatures #-}
44{-# LANGUAGE PolyKinds #-}
5−{-# LANGUAGE TemplateHaskell #-}
65{-# LANGUAGE TypeFamilies #-}
76module Reflex.Dom.Builder.Class.Events where
87
9−import Data.GADT.Compare.TH
8+import Data.GADT.Compare
9+ (GOrdering(..), (:~:)(..), GEq(..), GCompare(..))
10+import Control.Monad (ap)
1011
1112data EventTag
1213 = AbortTag
@@ -154,5 +155,205 @@ type family EventResultType (en :: EventTag) :: * where
154155 EventResultType 'TouchcancelTag = ()
155156 EventResultType 'WheelTag = ()
156157
157−deriveGEq ''EventName
158−deriveGCompare ''EventName
158+instance GEq EventName
159+ where geq Abort Abort = return Refl
160+ geq Blur Blur = return Refl
161+ geq Change Change = return Refl
162+ geq Click Click = return Refl
163+ geq Contextmenu Contextmenu = return Refl
164+ geq Dblclick Dblclick = return Refl
165+ geq Drag Drag = return Refl
166+ geq Dragend Dragend = return Refl
167+ geq Dragenter Dragenter = return Refl
168+ geq Dragleave Dragleave = return Refl
169+ geq Dragover Dragover = return Refl
170+ geq Dragstart Dragstart = return Refl
171+ geq Drop Drop = return Refl
172+ geq Error Error = return Refl
173+ geq Focus Focus = return Refl
174+ geq Input Input = return Refl
175+ geq Invalid Invalid = return Refl
176+ geq Keydown Keydown = return Refl
177+ geq Keypress Keypress = return Refl
178+ geq Keyup Keyup = return Refl
179+ geq Load Load = return Refl
180+ geq Mousedown Mousedown = return Refl
181+ geq Mouseenter Mouseenter = return Refl
182+ geq Mouseleave Mouseleave = return Refl
183+ geq Mousemove Mousemove = return Refl
184+ geq Mouseout Mouseout = return Refl
185+ geq Mouseover Mouseover = return Refl
186+ geq Mouseup Mouseup = return Refl
187+ geq Mousewheel Mousewheel = return Refl
188+ geq Scroll Scroll = return Refl
189+ geq Select Select = return Refl
190+ geq Submit Submit = return Refl
191+ geq Wheel Wheel = return Refl
192+ geq Beforecut Beforecut = return Refl
193+ geq Cut Cut = return Refl
194+ geq Beforecopy Beforecopy = return Refl
195+ geq Copy Copy = return Refl
196+ geq Beforepaste Beforepaste = return Refl
197+ geq Paste Paste = return Refl
198+ geq Reset Reset = return Refl
199+ geq Search Search = return Refl
200+ geq Selectstart Selectstart = return Refl
201+ geq Touchstart Touchstart = return Refl
202+ geq Touchmove Touchmove = return Refl
203+ geq Touchend Touchend = return Refl
204+ geq Touchcancel Touchcancel = return Refl
205+ geq _ _ = Nothing
206+
207+newtype GComparing a b t = GComparing (Either (GOrdering a b) t)
208+
209+instance Functor (GComparing a b) where fmap f (GComparing x) = GComparing (either Left (Right . f) x)
210+instance Monad (GComparing a b) where
211+ return = GComparing . Right
212+ GComparing (Left x) >>= f = GComparing (Left x)
213+ GComparing (Right x) >>= f = f x
214+instance Applicative (GComparing a b) where
215+ pure = return
216+ (<*>) = ap
217+
218+runGComparing (GComparing x) = either id id x
219+
220+instance GCompare EventName
221+ where gcompare Abort Abort = runGComparing $ return GEQ
222+ gcompare Abort _ = GLT
223+ gcompare _ Abort = GGT
224+ gcompare Blur Blur = runGComparing $ return GEQ
225+ gcompare Blur _ = GLT
226+ gcompare _ Blur = GGT
227+ gcompare Change Change = runGComparing $ return GEQ
228+ gcompare Change _ = GLT
229+ gcompare _ Change = GGT
230+ gcompare Click Click = runGComparing $ return GEQ
231+ gcompare Click _ = GLT
232+ gcompare _ Click = GGT
233+ gcompare Contextmenu Contextmenu = runGComparing $ return GEQ
234+ gcompare Contextmenu _ = GLT
235+ gcompare _ Contextmenu = GGT
236+ gcompare Dblclick Dblclick = runGComparing $ return GEQ
237+ gcompare Dblclick _ = GLT
238+ gcompare _ Dblclick = GGT
239+ gcompare Drag Drag = runGComparing $ return GEQ
240+ gcompare Drag _ = GLT
241+ gcompare _ Drag = GGT
242+ gcompare Dragend Dragend = runGComparing $ return GEQ
243+ gcompare Dragend _ = GLT
244+ gcompare _ Dragend = GGT
245+ gcompare Dragenter Dragenter = runGComparing $ return GEQ
246+ gcompare Dragenter _ = GLT
247+ gcompare _ Dragenter = GGT
248+ gcompare Dragleave Dragleave = runGComparing $ return GEQ
249+ gcompare Dragleave _ = GLT
250+ gcompare _ Dragleave = GGT
251+ gcompare Dragover Dragover = runGComparing $ return GEQ
252+ gcompare Dragover _ = GLT
253+ gcompare _ Dragover = GGT
254+ gcompare Dragstart Dragstart = runGComparing $ return GEQ
255+ gcompare Dragstart _ = GLT
256+ gcompare _ Dragstart = GGT
257+ gcompare Drop Drop = runGComparing $ return GEQ
258+ gcompare Drop _ = GLT
259+ gcompare _ Drop = GGT
260+ gcompare Error Error = runGComparing $ return GEQ
261+ gcompare Error _ = GLT
262+ gcompare _ Error = GGT
263+ gcompare Focus Focus = runGComparing $ return GEQ
264+ gcompare Focus _ = GLT
265+ gcompare _ Focus = GGT
266+ gcompare Input Input = runGComparing $ return GEQ
267+ gcompare Input _ = GLT
268+ gcompare _ Input = GGT
269+ gcompare Invalid Invalid = runGComparing $ return GEQ
270+ gcompare Invalid _ = GLT
271+ gcompare _ Invalid = GGT
272+ gcompare Keydown Keydown = runGComparing $ return GEQ
273+ gcompare Keydown _ = GLT
274+ gcompare _ Keydown = GGT
275+ gcompare Keypress Keypress = runGComparing $ return GEQ
276+ gcompare Keypress _ = GLT
277+ gcompare _ Keypress = GGT
278+ gcompare Keyup Keyup = runGComparing $ return GEQ
279+ gcompare Keyup _ = GLT
280+ gcompare _ Keyup = GGT
281+ gcompare Load Load = runGComparing $ return GEQ
282+ gcompare Load _ = GLT
283+ gcompare _ Load = GGT
284+ gcompare Mousedown Mousedown = runGComparing $ return GEQ
285+ gcompare Mousedown _ = GLT
286+ gcompare _ Mousedown = GGT
287+ gcompare Mouseenter Mouseenter = runGComparing $ return GEQ
288+ gcompare Mouseenter _ = GLT
289+ gcompare _ Mouseenter = GGT
290+ gcompare Mouseleave Mouseleave = runGComparing $ return GEQ
291+ gcompare Mouseleave _ = GLT
292+ gcompare _ Mouseleave = GGT
293+ gcompare Mousemove Mousemove = runGComparing $ return GEQ
294+ gcompare Mousemove _ = GLT
295+ gcompare _ Mousemove = GGT
296+ gcompare Mouseout Mouseout = runGComparing $ return GEQ
297+ gcompare Mouseout _ = GLT
298+ gcompare _ Mouseout = GGT
299+ gcompare Mouseover Mouseover = runGComparing $ return GEQ
300+ gcompare Mouseover _ = GLT
301+ gcompare _ Mouseover = GGT
302+ gcompare Mouseup Mouseup = runGComparing $ return GEQ
303+ gcompare Mouseup _ = GLT
304+ gcompare _ Mouseup = GGT
305+ gcompare Mousewheel Mousewheel = runGComparing $ return GEQ
306+ gcompare Mousewheel _ = GLT
307+ gcompare _ Mousewheel = GGT
308+ gcompare Scroll Scroll = runGComparing $ return GEQ
309+ gcompare Scroll _ = GLT
310+ gcompare _ Scroll = GGT
311+ gcompare Select Select = runGComparing $ return GEQ
312+ gcompare Select _ = GLT
313+ gcompare _ Select = GGT
314+ gcompare Submit Submit = runGComparing $ return GEQ
315+ gcompare Submit _ = GLT
316+ gcompare _ Submit = GGT
317+ gcompare Wheel Wheel = runGComparing $ return GEQ
318+ gcompare Wheel _ = GLT
319+ gcompare _ Wheel = GGT
320+ gcompare Beforecut Beforecut = runGComparing $ return GEQ
321+ gcompare Beforecut _ = GLT
322+ gcompare _ Beforecut = GGT
323+ gcompare Cut Cut = runGComparing $ return GEQ
324+ gcompare Cut _ = GLT
325+ gcompare _ Cut = GGT
326+ gcompare Beforecopy Beforecopy = runGComparing $ return GEQ
327+ gcompare Beforecopy _ = GLT
328+ gcompare _ Beforecopy = GGT
329+ gcompare Copy Copy = runGComparing $ return GEQ
330+ gcompare Copy _ = GLT
331+ gcompare _ Copy = GGT
332+ gcompare Beforepaste Beforepaste = runGComparing $ return GEQ
333+ gcompare Beforepaste _ = GLT
334+ gcompare _ Beforepaste = GGT
335+ gcompare Paste Paste = runGComparing $ return GEQ
336+ gcompare Paste _ = GLT
337+ gcompare _ Paste = GGT
338+ gcompare Reset Reset = runGComparing $ return GEQ
339+ gcompare Reset _ = GLT
340+ gcompare _ Reset = GGT
341+ gcompare Search Search = runGComparing $ return GEQ
342+ gcompare Search _ = GLT
343+ gcompare _ Search = GGT
344+ gcompare Selectstart Selectstart = runGComparing $ return GEQ
345+ gcompare Selectstart _ = GLT
346+ gcompare _ Selectstart = GGT
347+ gcompare Touchstart Touchstart = runGComparing $ return GEQ
348+ gcompare Touchstart _ = GLT
349+ gcompare _ Touchstart = GGT
350+ gcompare Touchmove Touchmove = runGComparing $ return GEQ
351+ gcompare Touchmove _ = GLT
352+ gcompare _ Touchmove = GGT
353+ gcompare Touchend Touchend = runGComparing $ return GEQ
354+ gcompare Touchend _ = GLT
355+ gcompare _ Touchend = GGT
356+ gcompare Touchcancel Touchcancel = runGComparing $ return GEQ
357+ gcompare Touchcancel _ = GLT
358+ gcompare _ Touchcancel = GGT
359+
src/Reflex/Dom/Builder/Immediate.hs+15−5
@@ -11,7 +11,6 @@
1111{-# LANGUAGE PolyKinds #-}
1212{-# LANGUAGE RankNTypes #-}
1313{-# LANGUAGE ScopedTypeVariables #-}
14−{-# LANGUAGE TemplateHaskell #-}
1514{-# LANGUAGE TypeFamilies #-}
1615{-# LANGUAGE TypeOperators #-}
1716{-# LANGUAGE UndecidableInstances #-}
@@ -31,6 +30,7 @@ import Control.Monad.Exception
3130import Control.Monad.Reader
3231import Control.Monad.Ref
3332import Control.Monad.Trans.Control
33+import Data.Functor.Contravariant (phantom)
3434import Data.Bitraversable
3535import Data.Default
3636import Data.Dependent.Map (DMap)
@@ -242,6 +242,17 @@ data GhcjsEventSpec er = GhcjsEventSpec
242242 , _ghcjsEventSpec_handler :: forall en. (EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en))
243243 }
244244
245+phantom2 :: (Functor f, Contravariant f) => f a -> f b
246+phantom2 = phantom
247+{-# INLINE phantom2 #-}
248+
249+ghcjsEventSpec_filters :: forall er . Lens' (GhcjsEventSpec er) (DMap EventName (GhcjsEventFilter er))
250+ghcjsEventSpec_filters f (GhcjsEventSpec a b) = (\a' -> GhcjsEventSpec a' b) <$> f a
251+{-# INLINE ghcjsEventSpec_filters #-}
252+ghcjsEventSpec_handler :: forall er en . Getter (GhcjsEventSpec er) ((EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en)))
253+ghcjsEventSpec_handler f (GhcjsEventSpec _ b) = phantom2 (f b)
254+{-# INLINE ghcjsEventSpec_handler #-}
255+
245256instance er ~ EventResult => Default (GhcjsEventSpec er) where
246257 def = GhcjsEventSpec
247258 { _ghcjsEventSpec_filters = mempty
@@ -436,9 +447,9 @@ instance (Monad m, MonadRef m, Ref m ~ Ref IO, MonadReflexCreateTrigger t m) =>
436447 reResultTrigger <- newIORef $ Just t
437448 writeChan events [TriggerRef reResultTrigger :=> TriggerInvocation a (liftIO cb)]
438449
439−instance HasWebView m => HasWebView (ImmediateDomBuilderT t m) where
440− type WebViewPhantom (ImmediateDomBuilderT t m) = WebViewPhantom m
441− askWebView = lift askWebView
450+instance HasJSContext m => HasJSContext (ImmediateDomBuilderT t m) where
451+ type JSContextPhantom (ImmediateDomBuilderT t m) = JSContextPhantom m
452+ askJSContext = lift askJSContext
442453
443454instance MonadRef m => MonadRef (ImmediateDomBuilderT t m) where
444455 type Ref (ImmediateDomBuilderT t m) = Ref m
@@ -894,4 +905,3 @@ wrapWindow wv _ = do
894905 , _window_raw = wv
895906 }
896907
897−makeLenses ''GhcjsEventSpec
src/Reflex/Dom/Builder/InputDisabled.hs+3−3
@@ -81,9 +81,9 @@ instance DomBuilder t m => DomBuilder t (InputDisabledT m) where
8181 }
8282 lift $ selectElement cfg' $ runInputDisabledT child
8383
84−instance HasWebView m => HasWebView (InputDisabledT m) where
85− type WebViewPhantom (InputDisabledT m) = WebViewPhantom m
86− askWebView = lift askWebView
84+instance HasJSContext m => HasJSContext (InputDisabledT m) where
85+ type JSContextPhantom (InputDisabledT m) = JSContextPhantom m
86+ askJSContext = lift askJSContext
8787
8888instance HasJS js m => HasJS js (InputDisabledT m) where
8989 type JSX (InputDisabledT m) = JSX m
src/Reflex/Dom/Internal.hs+35−22
@@ -19,7 +19,6 @@ import Prelude hiding (concat, mapM, mapM_, sequence, sequence_)
1919
2020import Reflex.Dom.Builder.Immediate
2121import Reflex.Dom.Class
22−import Reflex.Dom.Internal.Foreign
2322import Reflex.PerformEvent.Base
2423import Reflex.PostBuild.Class
2524import Reflex.Host.Class
@@ -46,32 +45,41 @@ import qualified GHCJS.DOM.Types as DOM
4645import GHCJS.DOM.Types (MonadJSM(..), runJSM, askJSM, JSM)
4746
4847{-# INLINABLE mainWidget #-}
49−mainWidget :: (forall x. Widget x ()) -> IO ()
50−mainWidget w = runWebGUI $ \(webView, ctx) -> withWebViewSingleton (webView, ctx) $ \webViewSing -> (`runJSM` ctx) $ do
48+mainWidget :: (forall x. Widget x ()) -> JSM ()
49+mainWidget w = withJSContextSingleton $ \jsSing -> do
5150 Just doc <- currentDocument
5251 Just body <- getBody doc
53− attachWidget body webViewSing w
52+ attachWidget body jsSing w
53+ forever $ do
54+ liftIO $ threadDelay 100000
55+ syncPoint
5456
5557--TODO: The x's should be unified here
5658{-# INLINABLE mainWidgetWithHead #-}
57−mainWidgetWithHead :: (forall x. Widget x ()) -> (forall x. Widget x ()) -> IO ()
58−mainWidgetWithHead h b = runWebGUI $ \(webView, ctx) -> withWebViewSingleton (webView, ctx) $ \webViewSing -> (`runJSM` ctx) $ do
59+mainWidgetWithHead :: (forall x. Widget x ()) -> (forall x. Widget x ()) -> JSM ()
60+mainWidgetWithHead h b = withJSContextSingleton $ \jsSing -> do
5961 Just doc <- currentDocument
6062 Just headElement <- getHead doc
61− attachWidget headElement webViewSing h
63+ attachWidget headElement jsSing h
6264 Just body <- getBody doc
63− attachWidget body webViewSing b
65+ attachWidget body jsSing b
66+ forever $ do
67+ liftIO $ threadDelay 100000
68+ syncPoint
6469
6570{-# INLINABLE mainWidgetWithCss #-}
66−mainWidgetWithCss :: ByteString -> (forall x. Widget x ()) -> IO ()
67−mainWidgetWithCss css w = runWebGUI $ \(webView, ctx) -> withWebViewSingleton (webView, ctx) $ \webViewSing -> (`runJSM` ctx) $ do
71+mainWidgetWithCss :: ByteString -> (forall x. Widget x ()) -> JSM ()
72+mainWidgetWithCss css w = withJSContextSingleton $ \jsSing -> do
6873 Just doc <- currentDocument
6974 Just headElement <- getHead doc
7075 setInnerHTML headElement . Just $ "<style>" <> T.unpack (decodeUtf8 css) <> "</style>" --TODO: Fix this
7176 Just body <- getBody doc
72− attachWidget body webViewSing w
77+ attachWidget body jsSing w
78+ forever $ do
79+ liftIO $ threadDelay 100000
80+ syncPoint
7381
74−type Widget x = PostBuildT Spider (ImmediateDomBuilderT Spider (WithWebView x (PerformEventT Spider (SpiderHost Global)))) --TODO: Make this more abstract --TODO: Put the WithWebView underneath PerformEventT - I think this would perform better
82+type Widget x = PostBuildT Spider (ImmediateDomBuilderT Spider (WithJSContextSingleton x (PerformEventT Spider (SpiderHost Global)))) --TODO: Make this more abstract --TODO: Put the WithJSContext underneath PerformEventT - I think this would perform better
7583
7684#ifndef __GHCJS__
7785instance MonadJSM m => MonadJSM (PostBuildT t m) where
@@ -79,11 +87,11 @@ instance MonadJSM m => MonadJSM (PostBuildT t m) where
7987#endif
8088
8189{-# INLINABLE attachWidget #-}
82−attachWidget :: DOM.IsElement e => e -> WebViewSingleton x -> Widget x a -> JSM a
90+attachWidget :: DOM.IsElement e => e -> JSContextSingleton x -> Widget x a -> JSM a
8391attachWidget rootElement wv w = fst <$> attachWidget' rootElement wv w
8492
8593{-# INLINABLE attachWidget' #-}
86−attachWidget' :: DOM.IsElement e => e -> WebViewSingleton x -> Widget x a -> JSM (a, FireCommand Spider (SpiderHost Global))
94+attachWidget' :: DOM.IsElement e => e -> JSContextSingleton x -> Widget x a -> JSM (a, FireCommand Spider (SpiderHost Global))
8795attachWidget' rootElement wv w = do
8896 ctx <- askJSM
8997 Just doc <- getOwnerDocument rootElement
@@ -96,7 +104,7 @@ attachWidget' rootElement wv w = do
96104 , _immediateDomBuilderEnv_parent = toNode df
97105 , _immediateDomBuilderEnv_events = events
98106 }
99− results@(_, FireCommand fire) <- hostPerformEventT $ runWithWebView (runImmediateDomBuilderT (runPostBuildT w postBuild) builderEnv) wv
107+ results@(_, FireCommand fire) <- hostPerformEventT $ runWithJSContextSingleton (runImmediateDomBuilderT (runPostBuildT w postBuild) builderEnv) wv
100108 mPostBuildTrigger <- readRef postBuildTriggerRef
101109 forM_ mPostBuildTrigger $ \postBuildTrigger -> fire [postBuildTrigger :=> Identity ()] $ return ()
102110 return results
@@ -114,11 +122,14 @@ attachWidget' rootElement wv w = do
114122 return (result, fc)
115123
116124-- | Run a reflex-dom application inside of an existing DOM element with the given ID
117−mainWidgetInElementById :: Text -> (forall x. Widget x ()) -> IO ()
118−mainWidgetInElementById eid w = runWebGUI $ \(webView, ctx) -> withWebViewSingleton (webView, ctx) $ \webViewSing -> (`runJSM` ctx) $ do
125+mainWidgetInElementById :: Text -> (forall x. Widget x ()) -> JSM ()
126+mainWidgetInElementById eid w = withJSContextSingleton $ \jsSing -> do
119127 Just doc <- currentDocument
120128 Just root <- getElementById doc eid
121− attachWidget root webViewSing w
129+ attachWidget root jsSing w
130+ forever $ do
131+ liftIO $ threadDelay 100000
132+ syncPoint
122133
123134data AppInput t = AppInput
124135 { _appInput_window :: Window t
@@ -128,14 +139,16 @@ data AppOutput t = AppOutput --TODO: Add quit event
128139 { _appOutput_windowConfig :: WindowConfig t
129140 }
130141
131−runApp' :: (t ~ Spider) => (forall x. AppInput t -> Widget x (AppOutput t)) -> IO ()
132−runApp' app = runWebGUI $ \(webView, ctx) -> withWebViewSingleton (webView, ctx) $ \webViewSing -> (`runJSM` ctx) $ do
142+runApp' :: (t ~ Spider) => (forall x. AppInput t -> Widget x (AppOutput t)) -> JSM ()
143+runApp' app = withJSContextSingleton $ \jsSing -> do
133144 Just doc <- currentDocument
134145 Just body <- getBody doc
135146 Just win <- getDefaultView doc
136− rec o <- attachWidget body webViewSing $ do
147+ rec o <- attachWidget body jsSing $ do
137148 w <- lift $ wrapWindow win $ _appOutput_windowConfig o
138149 app $ AppInput
139150 { _appInput_window = w
140151 }
141− return ()
152+ forever $ do
153+ liftIO $ threadDelay 100000
154+ syncPoint
src/Reflex/Dom/Location.hs−1
@@ -2,7 +2,6 @@ module Reflex.Dom.Location (getLocationHost, getLocationProtocol) where
22
33import Data.Text (Text)
44import Reflex.Dom.Class
5−import qualified Reflex.Dom.Internal.Foreign as F
65
76import Control.Monad.IO.Class
87
src/Reflex/Dom/Old.hs+9−12
@@ -6,7 +6,6 @@
66{-# LANGUAGE MultiParamTypeClasses #-}
77{-# LANGUAGE Rank2Types #-}
88{-# LANGUAGE ScopedTypeVariables #-}
9−{-# LANGUAGE TemplateHaskell #-}
109{-# LANGUAGE TypeFamilies #-}
1110{-# LANGUAGE UndecidableInstances #-}
1211{-# LANGUAGE LambdaCase #-}
@@ -31,7 +30,6 @@ module Reflex.Dom.Old
3130 , elWith'
3231 , emptyElWith
3332 , emptyElWith'
34− , getQuitWidget
3533 , namedNodeMapGetNames
3634 , nodeClear
3735 , onEventName
@@ -43,7 +41,7 @@ module Reflex.Dom.Old
4341 ) where
4442
4543import Control.Arrow (first)
46−import Control.Lens (makeLenses, (%~), (&), (.~), (^.))
44+import Control.Lens (Lens, Lens', (%~), (&), (.~), (^.))
4745import Control.Monad
4846import Control.Monad.Exception
4947import Control.Monad.Fix
@@ -70,7 +68,6 @@ import qualified GHCJS.DOM.Types as DOM
7068import Reflex.Class
7169import Reflex.Dom.Builder.Class
7270import Reflex.Dom.Builder.Immediate
73−import Reflex.Dom.Internal.Foreign
7471import Reflex.PerformEvent.Class
7572import Reflex.PostBuild.Class
7673import Reflex.Dom.Widget.Basic
@@ -81,7 +78,12 @@ data ElConfig attrs = ElConfig
8178 , _elConfig_attributes :: attrs
8279 }
8380
84−makeLenses ''ElConfig
81+elConfig_namespace :: Lens' (ElConfig attrs1) (Maybe Text)
82+elConfig_namespace f (ElConfig a b) = (\a' -> ElConfig a' b) <$> f a
83+{-# INLINE elConfig_namespace #-}
84+elConfig_attributes :: Lens (ElConfig attrs1) (ElConfig attrs2) attrs1 attrs2
85+elConfig_attributes f (ElConfig a b) = (\b' -> ElConfig a b') <$> f b
86+{-# INLINE elConfig_attributes #-}
8587
8688--TODO: HasDocument is still not accounted for
8789type MonadWidgetConstraints t m =
@@ -100,8 +102,8 @@ type MonadWidgetConstraints t m =
100102 , MonadJSM (Performable m)
101103#endif
102104 , TriggerEvent t m
103− , HasWebView m
104− , HasWebView (Performable m)
105+ , HasJSContext m
106+ , HasJSContext (Performable m)
105107 , MonadAsyncException m
106108 , MonadAsyncException (Performable m)
107109 , MonadRef m
@@ -258,11 +260,6 @@ nodeClear n = do
258260 _ <- removeChild n $ Just fc
259261 nodeClear n
260262
261−getQuitWidget :: MonadWidget t m => m (WidgetHost m ())
262−getQuitWidget = return $ do
263− WebViewSingleton (wv, _) <- askWebView
264− liftIO $ quitWebView wv
265−
266263elStopPropagationNS :: forall t m en a. (MonadWidget t m) => Maybe Text -> Text -> EventName en -> m a -> m a
267264elStopPropagationNS ns elementTag en child = do
268265 let f = GhcjsEventFilter $ \_ -> do
src/Reflex/Dom/Widget/Input.hs+144−15
@@ -8,7 +8,6 @@
88{-# LANGUAGE PolyKinds #-}
99{-# LANGUAGE RecursiveDo #-}
1010{-# LANGUAGE ScopedTypeVariables #-}
11−{-# LANGUAGE TemplateHaskell #-}
1211{-# LANGUAGE TypeFamilies #-}
1312{-# LANGUAGE UndecidableInstances #-}
1413module Reflex.Dom.Widget.Input (module Reflex.Dom.Widget.Input, def, (&), (.~)) where
@@ -444,20 +443,150 @@ dropdown k0 options (DropdownConfig setK attrs) = do
444443 dValue <- fmap (zipDynWith readKey ixKeys) $ holdDyn (Just k0) $ leftmost [eChange, fmap Just setK]
445444 return $ Dropdown dValue (attachPromptlyDynWith readKey ixKeys eChange)
446445
447−concat <$> mapM makeLenses
448− [ ''TextAreaConfig
449− , ''TextArea
450− , ''TextInputConfig
451− , ''TextInput
452− , ''RangeInputConfig
453− , ''RangeInput
454− , ''FileInputConfig
455− , ''FileInput
456− , ''DropdownConfig
457− , ''Dropdown
458− , ''CheckboxConfig
459− , ''Checkbox
460− ]
446+--concat <$> mapM makeLenses
447+-- [ ''TextAreaConfig
448+-- , ''TextArea
449+-- , ''TextInputConfig
450+-- , ''TextInput
451+-- , ''RangeInputConfig
452+-- , ''RangeInput
453+-- , ''FileInputConfig
454+-- , ''FileInput
455+-- , ''DropdownConfig
456+-- , ''Dropdown
457+-- , ''CheckboxConfig
458+-- , ''Checkbox
459+-- ]
460+textAreaConfig_attributes :: Lens' (TextAreaConfig t) (Dynamic t (Map Text Text))
461+textAreaConfig_attributes f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig x1 x2 y) <$> f x3
462+{-# INLINE textAreaConfig_attributes #-}
463+textAreaConfig_initialValue :: Lens' (TextAreaConfig t) Text
464+textAreaConfig_initialValue f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig y x2 x3) <$> f x1
465+{-# INLINE textAreaConfig_initialValue #-}
466+textAreaConfig_setValue :: Lens' (TextAreaConfig t) (Event t Text)
467+textAreaConfig_setValue f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig x1 y x3) <$> f x2
468+{-# INLINE textAreaConfig_setValue #-}
469+textArea_element :: Lens' (TextArea t) HTMLTextAreaElement
470+textArea_element f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 x2 x3 x4 y) <$> f x5
471+{-# INLINE textArea_element #-}
472+textArea_hasFocus :: Lens' (TextArea t) (Dynamic t Bool)
473+textArea_hasFocus f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 x2 y x4 x5) <$> f x3
474+{-# INLINE textArea_hasFocus #-}
475+textArea_input :: Lens' (TextArea t) (Event t Text)
476+textArea_input f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 y x3 x4 x5) <$> f x2
477+{-# INLINE textArea_input #-}
478+textArea_keypress :: Lens' (TextArea t) (Event t Int)
479+textArea_keypress f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 x2 x3 y x5) <$> f x4
480+{-# INLINE textArea_keypress #-}
481+textArea_value :: Lens' (TextArea t) (Dynamic t Text)
482+textArea_value f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea y x2 x3 x4 x5) <$> f x1
483+{-# INLINE textArea_value #-}
484+textInputConfig_attributes :: Lens' (TextInputConfig t) (Dynamic t (Map Text Text))
485+textInputConfig_attributes f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig x1 x2 x3 y) <$> f x4
486+{-# INLINE textInputConfig_attributes #-}
487+textInputConfig_initialValue :: Lens' (TextInputConfig t) Text
488+textInputConfig_initialValue f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig x1 y x3 x4) <$> f x2
489+{-# INLINE textInputConfig_initialValue #-}
490+textInputConfig_inputType :: Lens' (TextInputConfig t) Text
491+textInputConfig_inputType f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig y x2 x3 x4) <$> f x1
492+{-# INLINE textInputConfig_inputType #-}
493+textInputConfig_setValue :: Lens' (TextInputConfig t) (Event t Text)
494+textInputConfig_setValue f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig x1 x2 y x4) <$> f x3
495+{-# INLINE textInputConfig_setValue #-}
496+textInput_builderElement :: Lens' (TextInput t) (InputElement EventResult GhcjsDomSpace t)
497+textInput_builderElement f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 x4 x5 x6 y) <$> f x7
498+{-# INLINE textInput_builderElement #-}
499+textInput_hasFocus :: Lens' (TextInput t) (Dynamic t Bool)
500+textInput_hasFocus f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 x4 x5 y x7) <$> f x6
501+{-# INLINE textInput_hasFocus #-}
502+textInput_input :: Lens' (TextInput t) (Event t Text)
503+textInput_input f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 y x3 x4 x5 x6 x7) <$> f x2
504+{-# INLINE textInput_input #-}
505+textInput_keydown :: Lens' (TextInput t) (Event t Int)
506+textInput_keydown f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 y x5 x6 x7) <$> f x4
507+{-# INLINE textInput_keydown #-}
508+textInput_keypress :: Lens' (TextInput t) (Event t Int)
509+textInput_keypress f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 y x4 x5 x6 x7) <$> f x3
510+{-# INLINE textInput_keypress #-}
511+textInput_keyup :: Lens' (TextInput t) (Event t Int)
512+textInput_keyup f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 x4 y x6 x7) <$> f x5
513+{-# INLINE textInput_keyup #-}
514+textInput_value :: Lens' (TextInput t) (Dynamic t Text)
515+textInput_value f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput y x2 x3 x4 x5 x6 x7) <$> f x1
516+{-# INLINE textInput_value #-}
517+rangeInputConfig_attributes :: Lens' (RangeInputConfig t) (Dynamic t (Map Text Text))
518+rangeInputConfig_attributes f (RangeInputConfig x1 x2 x3) = (\y -> RangeInputConfig x1 x2 y) <$> f x3
519+{-# INLINE rangeInputConfig_attributes #-}
520+rangeInputConfig_initialValue :: Lens' (RangeInputConfig t) Float
521+rangeInputConfig_initialValue f (RangeInputConfig x1 x2 x3) = (\y -> RangeInputConfig y x2 x3) <$> f x1
522+{-# INLINE rangeInputConfig_initialValue #-}
523+rangeInputConfig_setValue :: Lens' (RangeInputConfig t) (Event t Float)
524+rangeInputConfig_setValue f (RangeInputConfig x1 x2 x3) = (\y -> RangeInputConfig x1 y x3) <$> f x2
525+{-# INLINE rangeInputConfig_setValue #-}
526+rangeInput_element :: Lens' (RangeInput t) HTMLInputElement
527+rangeInput_element f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 x2 x3 x4 y) <$> f x5
528+{-# INLINE rangeInput_element #-}
529+rangeInput_hasFocus :: Lens' (RangeInput t) (Dynamic t Bool)
530+rangeInput_hasFocus f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 x2 x3 y x5) <$> f x4
531+{-# INLINE rangeInput_hasFocus #-}
532+rangeInput_input :: Lens' (RangeInput t) (Event t Float)
533+rangeInput_input f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 y x3 x4 x5) <$> f x2
534+{-# INLINE rangeInput_input #-}
535+rangeInput_mouseup :: Lens' (RangeInput t) (Event t (Int, Int))
536+rangeInput_mouseup f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 x2 y x4 x5) <$> f x3
537+{-# INLINE rangeInput_mouseup #-}
538+rangeInput_value :: Lens' (RangeInput t) (Dynamic t Float)
539+rangeInput_value f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput y x2 x3 x4 x5) <$> f x1
540+{-# INLINE rangeInput_value #-}
541+fileInputConfig_attributes :: Iso
542+ (FileInputConfig t1)
543+ (FileInputConfig t2)
544+ (Dynamic t1 (Map Text Text))
545+ (Dynamic t2 (Map Text Text))
546+fileInputConfig_attributes = iso (\(FileInputConfig x) -> x) FileInputConfig
547+{-# INLINE fileInputConfig_attributes #-}
548+fileInput_element :: Lens
549+ (FileInput d1 t)
550+ (FileInput d2 t)
551+ (RawInputElement d1)
552+ (RawInputElement d2)
553+fileInput_element f (FileInput x1 x2) = (\y -> FileInput x1 y) <$> f x2
554+{-# INLINE fileInput_element #-}
555+fileInput_value :: Lens
556+ (FileInput d t1)
557+ (FileInput d t2)
558+ (Dynamic t1 [File])
559+ (Dynamic t2 [File])
560+fileInput_value f (FileInput x1 x2) = (\y -> FileInput y x2) <$> f x1
561+{-# INLINE fileInput_value #-}
562+dropdownConfig_attributes :: Lens' (DropdownConfig t k) (Dynamic t (Map Text Text))
563+dropdownConfig_attributes f (DropdownConfig x1 x2) = (\y -> DropdownConfig x1 y) <$> f x2
564+{-# INLINE dropdownConfig_attributes #-}
565+dropdownConfig_setValue :: Lens
566+ (DropdownConfig t k1)
567+ (DropdownConfig t k2)
568+ (Event t k1)
569+ (Event t k2)
570+dropdownConfig_setValue f (DropdownConfig x1 x2) = (\y -> DropdownConfig y x2) <$> f x1
571+{-# INLINE dropdownConfig_setValue #-}
572+dropdown_change :: Lens' (Dropdown t k) (Event t k)
573+dropdown_change f (Dropdown x1 x2) = (\y -> Dropdown x1 y) <$> f x2
574+{-# INLINE dropdown_change #-}
575+dropdown_value :: Lens' (Dropdown t k) (Dynamic t k)
576+dropdown_value f (Dropdown x1 x2) = (\y -> Dropdown y x2) <$> f x1
577+{-# INLINE dropdown_value #-}
578+checkboxConfig_attributes :: Lens' (CheckboxConfig t) (Dynamic t (Map Text Text))
579+checkboxConfig_attributes f (CheckboxConfig x1 x2) = (\y -> CheckboxConfig x1 y) <$> f x2
580+{-# INLINE checkboxConfig_attributes #-}
581+checkboxConfig_setValue :: Lens' (CheckboxConfig t) (Event t Bool)
582+checkboxConfig_setValue f (CheckboxConfig x1 x2) = (\y -> CheckboxConfig y x2) <$> f x1
583+{-# INLINE checkboxConfig_setValue #-}
584+checkbox_change :: Lens' (Checkbox t) (Event t Bool)
585+checkbox_change f (Checkbox x1 x2) = (\y -> Checkbox x1 y) <$> f x2
586+{-# INLINE checkbox_change #-}
587+checkbox_value :: Lens' (Checkbox t) (Dynamic t Bool)
588+checkbox_value f (Checkbox x1 x2) = (\y -> Checkbox y x2) <$> f x1
589+{-# INLINE checkbox_value #-}
461590
462591instance HasAttributes (TextAreaConfig t) where
463592 type Attrs (TextAreaConfig t) = Dynamic t (Map Text Text)