@@ -92,42 +92,43 @@ addVoidAction = performEvent_
93type AttributeMap = Map Text Text
93type AttributeMap = Map Text Text
95−buildElement :: Attributes m attrs => Text -> attrs -> m a -> m (RawElement GhcjsDomSpace, a)
95+buildElement :: (MonadWidget t m, Attributes m attrs t) => Text -> attrs -> m a -> m (RawElement (DomBuilderSpace m), a)
96buildElement = buildElementNS Nothing
96buildElement = buildElementNS Nothing
98−buildEmptyElement :: Monad m => Attributes m attrs => Text -> attrs -> m (RawElement GhcjsDomSpace)
98+buildEmptyElement :: (MonadWidget t m, Attributes m attrs t) => Text -> attrs -> m (RawElement (DomBuilderSpace m))
99buildEmptyElement elementTag attrs = fst <$> buildElementNS Nothing elementTag attrs blank
99buildEmptyElement elementTag attrs = fst <$> buildElementNS Nothing elementTag attrs blank
101−buildEmptyElementNS :: Monad m => Attributes m attrs => Maybe Text -> Text -> attrs -> m (RawElement GhcjsDomSpace)
101+buildEmptyElementNS :: (MonadWidget t m, Attributes m attrs t) => Maybe Text -> Text -> attrs -> m (RawElement (DomBuilderSpace m))
102buildEmptyElementNS ns elementTag attrs = fst <$> buildElementNS ns elementTag attrs blank
102buildEmptyElementNS ns elementTag attrs = fst <$> buildElementNS ns elementTag attrs blank
104−class Attributes m attrs where
105− buildElementNS :: Maybe Text -> Text -> attrs -> m a -> m (RawElement GhcjsDomSpace, a)
104+buildElementNS :: (MonadWidget t m, Attributes m attrs t) => Maybe Text -> Text -> attrs -> m a -> m (RawElement (DomBuilderSpace m), a)
105+buildElementNS ns elementTag attrs child = fmap (first _element_raw) $ buildElementInternal ns elementTag attrs child
107+class Attributes m attrs t where
108+ buildElementInternal :: MonadWidget t m => Maybe Text -> Text -> attrs -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
107−instance MonadWidget t m => Attributes m (Map Text Text) where
110+instance Attributes m (Map Text Text) t where
108− buildElementNS ns elementTag attrs child = do
111+ buildElementInternal ns elementTag attrs child = do
109 let cfg = def & elementConfig_namespace .~ ns
112 let cfg = def & elementConfig_namespace .~ ns
110− buildElementInternal elementTag child =<< addStaticAttributes attrs cfg
113+ buildElementCommon elementTag child =<< addStaticAttributes attrs cfg
112addStaticAttributes :: Applicative m => Map Text Text -> ElementConfig er t m -> m (ElementConfig er t m)
115addStaticAttributes :: Applicative m => Map Text Text -> ElementConfig er t m -> m (ElementConfig er t m)
113addStaticAttributes attrs cfg = do
116addStaticAttributes attrs cfg = do
114 let initialAttrs = Map.fromList $ fmap (first ((,) Nothing)) $ Map.toList attrs
117 let initialAttrs = Map.fromList $ fmap (first ((,) Nothing)) $ Map.toList attrs
115 pure $ cfg & elementConfig_initialAttributes .~ initialAttrs
118 pure $ cfg & elementConfig_initialAttributes .~ initialAttrs
117−instance MonadWidget t m => Attributes m (Dynamic t (Map Text Text)) where
120+instance PostBuild t m => Attributes m (Dynamic t (Map Text Text)) t where
118− buildElementNS ns elementTag attrs child = do
121+ buildElementInternal ns elementTag attrs child = do
119 let cfg = def & elementConfig_namespace .~ ns
122 let cfg = def & elementConfig_namespace .~ ns
120− buildElementInternal elementTag child =<< addDynamicAttributes attrs cfg
123+ buildElementCommon elementTag child =<< addDynamicAttributes attrs cfg
122addDynamicAttributes :: PostBuild t m => Dynamic t (Map Text Text) -> ElementConfig er t m -> m (ElementConfig er t m)
125addDynamicAttributes :: PostBuild t m => Dynamic t (Map Text Text) -> ElementConfig er t m -> m (ElementConfig er t m)
123addDynamicAttributes attrs cfg = do
126addDynamicAttributes attrs cfg = do
124 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
127 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
125 return $ cfg & elementConfig_modifyAttributes .~ modifyAttrs
128 return $ cfg & elementConfig_modifyAttributes .~ modifyAttrs
127−buildElementInternal :: MonadWidget t m => Text -> m a -> ElementConfig en t m -> m (DOM.HTMLElement, a)
130+buildElementCommon :: MonadWidget t m => Text -> m a -> ElementConfig er t m -> m (Element er (DomBuilderSpace m) t, a)
128−buildElementInternal elementTag child cfg = do
129− (e, result) <- element elementTag cfg child
131+buildElementCommon elementTag child cfg = element elementTag cfg child
130− return (_element_raw e, result)
132-- | s and e must both be children of the same node and s must precede e
133-- | s and e must both be children of the same node and s must precede e
133deleteBetweenExclusive :: (IsNode start, IsNode end) => start -> end -> IO ()
134deleteBetweenExclusive :: (IsNode start, IsNode end) => start -> end -> IO ()
@@ -161,14 +162,14 @@ instance HasAttributes (ElConfig attrs) where
161instance HasNamespace (ElConfig attrs) where
162instance HasNamespace (ElConfig attrs) where
162 namespace = elConfig_namespace
163 namespace = elConfig_namespace
164−elWith :: (Functor m, Attributes m attrs) => Text -> ElConfig attrs -> m a -> m a
165+elWith :: (MonadWidget t m, Attributes m attrs t) => Text -> ElConfig attrs -> m a -> m a
165elWith elementTag cfg child = snd <$> elWith' elementTag cfg child
166elWith elementTag cfg child = snd <$> elWith' elementTag cfg child
167−elWith' :: Attributes m attrs => Text -> ElConfig attrs -> m a -> m (DOM.HTMLElement, a)
168+elWith' :: (MonadWidget t m, Attributes m attrs t) => Text -> ElConfig attrs -> m a -> m (Element EventResult (DomBuilderSpace m) t, a)
168−elWith' elementTag cfg child = buildElementNS (cfg ^. namespace) elementTag (cfg ^. attributes) child
169+elWith' elementTag cfg child = buildElementInternal (cfg ^. namespace) elementTag (cfg ^. attributes) child
170−emptyElWith :: (Monad m, Attributes m attrs) => Text -> ElConfig attrs -> m ()
171+emptyElWith :: (MonadWidget t m, Attributes m attrs t) => Text -> ElConfig attrs -> m ()
171emptyElWith elementTag cfg = void $ emptyElWith' elementTag cfg
172emptyElWith elementTag cfg = void $ emptyElWith' elementTag cfg
173−emptyElWith' :: (Monad m, Attributes m attrs) => Text -> ElConfig attrs -> m DOM.HTMLElement
174+emptyElWith' :: (MonadWidget t m, Attributes m attrs t) => Text -> ElConfig attrs -> m (Element EventResult (DomBuilderSpace m) t)
174−emptyElWith' elementTag cfg = liftM fst $ buildElementNS (cfg ^. namespace) elementTag (cfg ^. attributes) $ return ()
175+emptyElWith' elementTag cfg = liftM fst $ elWith' elementTag cfg $ return ()