@@ -10,11 +10,9 @@
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeFamilies #-}
12module Reflex.Dom.Widget.Basic
12module Reflex.Dom.Widget.Basic
13− ( partitionMapBySetLT
13+ (
16 -- * Displaying Values
14 -- * Displaying Values
20 , dynComment
18 , dynComment
@@ -59,6 +57,7 @@ module Reflex.Dom.Widget.Basic
59 , module Data.Map.Misc
57 , module Data.Map.Misc
60 , module Reflex.Collection
58 , module Reflex.Collection
61 , module Reflex.Workflow
59 , module Reflex.Workflow
60+ , partitionMapBySetLT
64import Reflex.Class
63import Reflex.Class
@@ -95,6 +94,7 @@ import Prelude hiding (mapM, mapM_, sequence, sequence_)
95-- No empty pieces will be included in the output.
94-- No empty pieces will be included in the output.
97--TODO: This can probably be done more efficiently by dividing and conquering, re-using the structure of the Set instead of going through the Set linearally
96--TODO: This can probably be done more efficiently by dividing and conquering, re-using the structure of the Set instead of going through the Set linearally
97+{-# DEPRECATED partitionMapBySetLT "This will be removed in future releases." #-}
98partitionMapBySetLT :: forall k v. Ord k => Set k -> Map k v -> Map (Either k ()) (Map k v)
98partitionMapBySetLT :: forall k v. Ord k => Set k -> Map k v -> Map (Either k ()) (Map k v)
99partitionMapBySetLT s m0 = Map.fromDistinctAscList $ go (Set.toAscList s) m0
99partitionMapBySetLT s m0 = Map.fromDistinctAscList $ go (Set.toAscList s) m0
100 where go :: [k] -> Map k v -> [(Either k (), Map k v)]
100 where go :: [k] -> Map k v -> [(Either k (), Map k v)]
@@ -107,8 +107,7 @@ partitionMapBySetLT s m0 = Map.fromDistinctAscList $ go (Set.toAscList s) m0
107 then go t geq
107 then go t geq
108 else (Left h, lt) : go t geq
108 else (Left h, lt) : go t geq
110−newtype ChildResult t k a = ChildResult { unChildResult :: (a, Event t (Map k (Maybe (ChildResult t k a)))) }
110+{-# INLINABLE text #-}
112text :: DomBuilder t m => Text -> m ()
111text :: DomBuilder t m => Text -> m ()
113text t = void $ textNode $ def & textNodeConfig_initialContents .~ t
112text t = void $ textNode $ def & textNodeConfig_initialContents .~ t
@@ -146,7 +145,7 @@ button t = do
146--TODO: Should this be renamed to 'widgetView' for consistency with 'widgetHold'?
145--TODO: Should this be renamed to 'widgetView' for consistency with 'widgetHold'?
147-- | Given a Dynamic of widget-creating actions, create a widget that is recreated whenever the Dynamic updates.
146-- | Given a Dynamic of widget-creating actions, create a widget that is recreated whenever the Dynamic updates.
148-- The returned Event of widget results occurs when the Dynamic does.
147-- The returned Event of widget results occurs when the Dynamic does.
149−-- Note: Often, the type 'a' is an Event, in which case the return value is an Event-of-Events that would typically be flattened (via 'switchPromptly').
148+-- Note: Often, the type @a@ is an 'Event', in which case the return value is an Event-of-Events that would typically be flattened (via 'switchHold').
150dyn :: (DomBuilder t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
149dyn :: (DomBuilder t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
151dyn = networkView
150dyn = networkView
@@ -156,7 +155,7 @@ dyn_ = void . dyn
157-- | Given an initial widget and an Event of widget-creating actions, create a widget that is recreated whenever the Event fires.
156-- | Given an initial widget and an Event of widget-creating actions, create a widget that is recreated whenever the Event fires.
158-- The returned Dynamic of widget results occurs when the Event does.
157-- The returned Dynamic of widget results occurs when the Event does.
159−-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened.
158+-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened (via 'switchDyn').
160widgetHold :: (DomBuilder t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
159widgetHold :: (DomBuilder t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
161widgetHold = networkHold
160widgetHold = networkHold
@@ -165,43 +164,51 @@ widgetHold_ :: (DomBuilder t m, MonadHold t m) => m a -> Event t (m a) -> m ()
165widgetHold_ z = void . widgetHold z
164widgetHold_ z = void . widgetHold z
167-- | Create a DOM element
166-- | Create a DOM element
168−-- > el "div" (text "Hello World")
168+-- >>> el "div" (text "Hello World")
169-- <div>Hello World</div>
169-- <div>Hello World</div>
170{-# INLINABLE el #-}
170{-# INLINABLE el #-}
171el :: forall t m a. DomBuilder t m => Text -> m a -> m a
171el :: forall t m a. DomBuilder t m => Text -> m a -> m a
172el elementTag child = snd <$> el' elementTag child
172el elementTag child = snd <$> el' elementTag child
174-- | Create a DOM element with attributes
174-- | Create a DOM element with attributes
175−-- > elAttr "a" ("href" =: "http://google.com") (text "Google!")
176+-- >>> elAttr "a" ("href" =: "https://reflex-frp.org") (text "Reflex-FRP!")
176−-- <a href="http://google.com">Google!</a>
177+-- <a href="https://reflex-frp.org">Reflex-FRP!</a>
177{-# INLINABLE elAttr #-}
178{-# INLINABLE elAttr #-}
178elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
179elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
179elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
180elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
181-- | Create a DOM element with classes
182-- | Create a DOM element with classes
182−-- > elClass "div" "row" (return ())
184+-- >>> elClass "div" "row" (return ())
183-- <div class="row"></div>
185-- <div class="row"></div>
184{-# INLINABLE elClass #-}
186{-# INLINABLE elClass #-}
185elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
187elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
186elClass elementTag c child = snd <$> elClass' elementTag c child
188elClass elementTag c child = snd <$> elClass' elementTag c child
188-- | Create a DOM element with Dynamic Attributes
190-- | Create a DOM element with Dynamic Attributes
189−-- > elClass "div" (constDyn ("class" =: "row")) (return ())
192+-- >>> elClass "div" (constDyn ("class" =: "row")) (return ())
190-- <div class="row"></div>
193-- <div class="row"></div>
191{-# INLINABLE elDynAttr #-}
194{-# INLINABLE elDynAttr #-}
192elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
195elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
193elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
196elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
195-- | Create a DOM element with a Dynamic Class
198-- | Create a DOM element with a Dynamic Class
196−-- > elDynClass "div" (constDyn "row") (return ())
200+-- >>> elDynClass "div" (constDyn "row") (return ())
197-- <div class="row"></div>
201-- <div class="row"></div>
198{-# INLINABLE elDynClass #-}
202{-# INLINABLE elDynClass #-}
199elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
203elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
200elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
204elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
202-- | Create a DOM element and return the element
206-- | Create a DOM element and return the element
203−-- > do (e, _) <- el' "div" (text "Click")
209+-- do (e, _) <- el' "div" (text "Click")
204−-- > return $ domEvent Click e
210+-- return $ domEvent Click e
205{-# INLINABLE el' #-}
212{-# INLINABLE el' #-}
206el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
213el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
207el' elementTag = element elementTag def
214el' elementTag = element elementTag def
@@ -287,6 +294,8 @@ newtype Link t
287 = Link { _link_clicked :: Event t ()
294 = Link { _link_clicked :: Event t ()
297+-- | >>> linkClass "Click here" "link-class"
298+-- > <a class="link-class">Click here</a>
290linkClass :: DomBuilder t m => Text -> Text -> m (Link t)
299linkClass :: DomBuilder t m => Text -> Text -> m (Link t)
291linkClass s c = do
300linkClass s c = do
292 (l,_) <- elAttr' "a" ("class" =: c) $ text s
301 (l,_) <- elAttr' "a" ("class" =: c) $ text s