@@ -240,34 +240,26 @@ emptyElWith' elementTag cfg = do
240 wrapElement defaultDomEventHandler =<< buildEmptyElementNS (cfg ^. namespace) elementTag (cfg ^. attributes)
240 wrapElement defaultDomEventHandler =<< buildEmptyElementNS (cfg ^. namespace) elementTag (cfg ^. attributes)
243−dynamicAttributesToModifyAttributes :: PostBuild t m => Dynamic t (Map Text Text) -> m (Event t (Map AttributeName (Maybe Text)))
243+{-# INLINABLE el #-}
244−dynamicAttributesToModifyAttributes d = do
244+el :: forall t m a. DomBuilder t m => Text -> m a -> m a
245− postBuild <- getPostBuild
246− let modificationsNeeded = flip pushAlways (align postBuild $ updated d) $ \case
247− This () -> fmap (fmap Just) $ sample $ current d
248− These () new -> return $ fmap Just new
250− old <- sample $ current d
251− return $ diffMap old new
252− return $ Map.fromList . fmap (\(k, v) -> ((Nothing, k), v)) . Map.toList <$> modificationsNeeded
254−{-# INLINABLE elDynAttrNS' #-}
255−elDynAttrNS' :: forall t m a. (DomBuilder t m, PostBuild t m) => Maybe Text -> Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
256−elDynAttrNS' mns elementTag attrs child = do
245+el elementTag child = snd <$> el' elementTag child
257− modifyAttrs <- dynamicAttributesToModifyAttributes attrs
259− & elementConfig_namespace .~ mns
260− & modifyAttributes .~ modifyAttrs
261− element elementTag cfg child
263−{-# INLINABLE elDynAttr' #-}
264−elDynAttr' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
265−elDynAttr' = elDynAttrNS' Nothing
267{-# INLINABLE elAttr #-}
247{-# INLINABLE elAttr #-}
268elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
248elAttr :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m a
269elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
249elAttr elementTag attrs child = snd <$> elAttr' elementTag attrs child
251+{-# INLINABLE elClass #-}
252+elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
253+elClass elementTag c child = snd <$> elClass' elementTag c child
255+{-# INLINABLE elDynAttr #-}
256+elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
257+elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
259+{-# INLINABLE elDynClass #-}
260+elDynClass :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m a
261+elDynClass elementTag c child = snd <$> elDynClass' elementTag c child
271{-# INLINABLE el' #-}
263{-# INLINABLE el' #-}
272el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
264el' :: forall t m a. DomBuilder t m => Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
273el' elementTag = element elementTag def
265el' elementTag = element elementTag def
@@ -277,16 +269,37 @@ elAttr' :: forall t m a. DomBuilder t m => Text -> Map Text Text -> m a -> m (El
277elAttr' elementTag attrs = element elementTag $ def
269elAttr' elementTag attrs = element elementTag $ def
278 & initialAttributes .~ Map.mapKeys (\k -> (Nothing, k)) attrs
270 & initialAttributes .~ Map.mapKeys (\k -> (Nothing, k)) attrs
280−{-# INLINABLE elDynAttr #-}
272+{-# INLINABLE elClass' #-}
281−elDynAttr :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m a
273+elClass' :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
282−elDynAttr elementTag attrs child = snd <$> elDynAttr' elementTag attrs child
274+elClass' elementTag c = elAttr' elementTag ("class" =: c)
284−{-# INLINABLE el #-}
276+{-# INLINABLE elDynAttr' #-}
285−el :: forall t m a. DomBuilder t m => Text -> m a -> m a
277+elDynAttr' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
286−el elementTag child = snd <$> el' elementTag child
278+elDynAttr' = elDynAttrNS' Nothing
280+{-# INLINABLE elDynClass' #-}
288−elClass :: forall t m a. DomBuilder t m => Text -> Text -> m a -> m a
281+elDynClass' :: forall t m a. (DomBuilder t m, PostBuild t m) => Text -> Dynamic t Text -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
289−elClass elementTag c child = snd <$> element elementTag (def & initialAttributes .~ (Nothing, "class") =: c) child
282+elDynClass' elementTag c = elDynAttr' elementTag (fmap ("class" =:) c)
284+{-# INLINABLE elDynAttrNS' #-}
285+elDynAttrNS' :: forall t m a. (DomBuilder t m, PostBuild t m) => Maybe Text -> Text -> Dynamic t (Map Text Text) -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
286+elDynAttrNS' mns elementTag attrs child = do
287+ modifyAttrs <- dynamicAttributesToModifyAttributes attrs
289+ & elementConfig_namespace .~ mns
290+ & modifyAttributes .~ modifyAttrs
291+ element elementTag cfg child
293+dynamicAttributesToModifyAttributes :: PostBuild t m => Dynamic t (Map Text Text) -> m (Event t (Map AttributeName (Maybe Text)))
294+dynamicAttributesToModifyAttributes d = do
295+ postBuild <- getPostBuild
296+ let modificationsNeeded = flip pushAlways (align postBuild $ updated d) $ \case
297+ This () -> fmap (fmap Just) $ sample $ current d
298+ These () new -> return $ fmap Just new
300+ old <- sample $ current d
301+ return $ diffMap old new
302+ return $ Map.fromList . fmap (\(k, v) -> ((Nothing, k), v)) . Map.toList <$> modificationsNeeded
291--------------------------------------------------------------------------------
304--------------------------------------------------------------------------------
292-- Copied and pasted from Reflex.Widget.Class
305-- Copied and pasted from Reflex.Widget.Class