{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE ScopedTypeVariables #-}
#ifdef USE_TEMPLATE_HASKELL
{-# LANGUAGE TemplateHaskell #-}
#endif
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Reflex.Dom.Widget.Input (module Reflex.Dom.Widget.Input, def, (&), (.~)) where

import Prelude

import Control.Lens hiding (element, ix)
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Reader
import qualified Data.Bimap as Bimap
import Data.Default
import Data.Dependent.Map (DMap)
import qualified Data.Dependent.Map as DMap
import Data.Functor.Misc
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import Data.Semigroup
import Data.Text (Text)
import qualified Data.Text as T
import qualified GHCJS.DOM.GlobalEventHandlers as Events
import GHCJS.DOM.EventM (on)
import qualified GHCJS.DOM.FileList as FileList
import GHCJS.DOM.HTMLInputElement (HTMLInputElement)
import GHCJS.DOM.HTMLTextAreaElement (HTMLTextAreaElement)
import GHCJS.DOM.Types (MonadJSM, File, uncheckedCastTo)
import qualified GHCJS.DOM.Types as DOM (HTMLElement(..), EventTarget(..))
import Reflex.Class
import Reflex.Collection
import Reflex.Dom.Builder.Class
import Reflex.Dom.Builder.Immediate
import Reflex.Dom.Class
import Reflex.Dom.Widget.Basic
import Reflex.Dynamic
import Reflex.PostBuild.Class
import Reflex.TriggerEvent.Class
import qualified Text.Read as T

import qualified GHCJS.DOM.Event as Event
import qualified GHCJS.DOM.HTMLInputElement as Input

{-# DEPRECATED TextInput, _textInput_element, TextInputConfig, textInput "Use 'inputElement' directly" #-}
data TextInput t
   = TextInput { TextInput t -> Dynamic t Text
_textInput_value :: Dynamic t Text
               , TextInput t -> Event t Text
_textInput_input :: Event t Text
               , TextInput t -> Event t Word
_textInput_keypress :: Event t Word
               , TextInput t -> Event t Word
_textInput_keydown :: Event t Word
               , TextInput t -> Event t Word
_textInput_keyup :: Event t Word
               , TextInput t -> Dynamic t Bool
_textInput_hasFocus :: Dynamic t Bool
               , TextInput t -> InputElement EventResult GhcjsDomSpace t
_textInput_builderElement :: InputElement EventResult GhcjsDomSpace t
               }

_textInput_element :: TextInput t -> HTMLInputElement
_textInput_element :: TextInput t -> HTMLInputElement
_textInput_element = InputElement EventResult GhcjsDomSpace t -> HTMLInputElement
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> RawInputElement d
_inputElement_raw (InputElement EventResult GhcjsDomSpace t -> HTMLInputElement)
-> (TextInput t -> InputElement EventResult GhcjsDomSpace t)
-> TextInput t
-> HTMLInputElement
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextInput t -> InputElement EventResult GhcjsDomSpace t
forall k (t :: k).
TextInput t -> InputElement EventResult GhcjsDomSpace t
_textInput_builderElement

instance Reflex t => HasDomEvent t (TextInput t) en where
  type DomEventType (TextInput t) en = DomEventType (InputElement EventResult GhcjsDomSpace t) en
  domEvent :: EventName en
-> TextInput t -> Event t (DomEventType (TextInput t) en)
domEvent en :: EventName en
en = EventName en
-> InputElement EventResult GhcjsDomSpace t
-> Event
     t (DomEventType (InputElement EventResult GhcjsDomSpace t) en)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName en
en (InputElement EventResult GhcjsDomSpace t
 -> Event t (EventResultType en))
-> (TextInput t -> InputElement EventResult GhcjsDomSpace t)
-> TextInput t
-> Event t (EventResultType en)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextInput t -> InputElement EventResult GhcjsDomSpace t
forall k (t :: k).
TextInput t -> InputElement EventResult GhcjsDomSpace t
_textInput_builderElement

data TextInputConfig t
   = TextInputConfig { TextInputConfig t -> Text
_textInputConfig_inputType :: Text
                     , TextInputConfig t -> Text
_textInputConfig_initialValue :: Text
                     , TextInputConfig t -> Event t Text
_textInputConfig_setValue :: Event t Text
                     , TextInputConfig t -> Dynamic t (Map Text Text)
_textInputConfig_attributes :: Dynamic t (Map Text Text)
                     }

instance Reflex t => Default (TextInputConfig t) where
  {-# INLINABLE def #-}
  def :: TextInputConfig t
def = TextInputConfig :: forall k (t :: k).
Text
-> Text
-> Event t Text
-> Dynamic t (Map Text Text)
-> TextInputConfig t
TextInputConfig { _textInputConfig_inputType :: Text
_textInputConfig_inputType = "text"
                        , _textInputConfig_initialValue :: Text
_textInputConfig_initialValue = ""
                        , _textInputConfig_setValue :: Event t Text
_textInputConfig_setValue = Event t Text
forall k (t :: k) a. Reflex t => Event t a
never
                        , _textInputConfig_attributes :: Dynamic t (Map Text Text)
_textInputConfig_attributes = Map Text Text -> Dynamic t (Map Text Text)
forall k (t :: k) a. Reflex t => a -> Dynamic t a
constDyn Map Text Text
forall a. Monoid a => a
mempty
                        }

-- | Create an input whose value is a string.  By default, the "type" attribute is set to "text", but it can be changed using the _textInputConfig_inputType field.  Note that only types for which the value is always a string will work - types whose value may be null will not work properly with this widget.
{-# INLINABLE textInput #-}
textInput :: (DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace) => TextInputConfig t -> m (TextInput t)
textInput :: TextInputConfig t -> m (TextInput t)
textInput (TextInputConfig inputType :: Text
inputType initial :: Text
initial eSetValue :: Event t Text
eSetValue dAttrs :: Dynamic t (Map Text Text)
dAttrs) = do
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes (Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text))))
-> Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall a b. (a -> b) -> a -> b
$ (Map Text Text -> Map Text Text)
-> Dynamic t (Map Text Text) -> Dynamic t (Map Text Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Text -> Map Text Text -> Map Text Text
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert "type" Text
inputType) Dynamic t (Map Text Text)
dAttrs
  InputElement EventResult GhcjsDomSpace t
i <- InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult GhcjsDomSpace t)
forall t (m :: * -> *) (er :: EventTag -> *).
DomBuilder t m =>
InputElementConfig er t (DomBuilderSpace m)
-> m (InputElement er (DomBuilderSpace m) t)
inputElement (InputElementConfig EventResult t (DomBuilderSpace m)
 -> m (InputElement EventResult GhcjsDomSpace t))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult GhcjsDomSpace t)
forall a b. (a -> b) -> a -> b
$ InputElementConfig EventResult t GhcjsDomSpace
forall a. Default a => a
def
    InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Text -> Identity Text)
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (er :: EventTag -> *) (t :: k1) (s :: k2).
Lens' (InputElementConfig er t s) Text
inputElementConfig_initialValue ((Text -> Identity Text)
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Text
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Text
initial
    InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Event t Text -> Identity (Event t Text))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens' (InputElementConfig er t m) (Event t Text)
inputElementConfig_setValue ((Event t Text -> Identity (Event t Text))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Event t Text
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Event t Text
eSetValue
    InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (InputElementConfig er t s)
  (InputElementConfig er2 t s2)
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
inputElementConfig_elementConfig ((ElementConfig EventResult t GhcjsDomSpace
  -> Identity (ElementConfig EventResult t GhcjsDomSpace))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> ((Event t (Map AttributeName (Maybe Text))
     -> Identity (Event t (Map AttributeName (Maybe Text))))
    -> ElementConfig EventResult t GhcjsDomSpace
    -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> (Event t (Map AttributeName (Maybe Text))
    -> Identity (Event t (Map AttributeName (Maybe Text))))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Event t (Map AttributeName (Maybe Text))
 -> Identity (Event t (Map AttributeName (Maybe Text))))
-> ElementConfig EventResult t GhcjsDomSpace
-> Identity (ElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens'
  (ElementConfig er t m) (Event t (Map AttributeName (Maybe Text)))
elementConfig_modifyAttributes ((Event t (Map AttributeName (Maybe Text))
  -> Identity (Event t (Map AttributeName (Maybe Text))))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Event t (Map AttributeName (Maybe Text))
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
  TextInput t -> m (TextInput t)
forall (m :: * -> *) a. Monad m => a -> m a
return (TextInput t -> m (TextInput t)) -> TextInput t -> m (TextInput t)
forall a b. (a -> b) -> a -> b
$ TextInput :: forall k (t :: k).
Dynamic t Text
-> Event t Text
-> Event t Word
-> Event t Word
-> Event t Word
-> Dynamic t Bool
-> InputElement EventResult GhcjsDomSpace t
-> TextInput t
TextInput
    { _textInput_value :: Dynamic t Text
_textInput_value = InputElement EventResult GhcjsDomSpace t -> Dynamic t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t Text
_inputElement_value InputElement EventResult GhcjsDomSpace t
i
    , _textInput_input :: Event t Text
_textInput_input = InputElement EventResult GhcjsDomSpace t -> Event t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Event t Text
_inputElement_input InputElement EventResult GhcjsDomSpace t
i
    , _textInput_keypress :: Event t Word
_textInput_keypress = EventName 'KeypressTag
-> InputElement EventResult GhcjsDomSpace t
-> Event
     t
     (DomEventType
        (InputElement EventResult GhcjsDomSpace t) 'KeypressTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeypressTag
Keypress InputElement EventResult GhcjsDomSpace t
i
    , _textInput_keydown :: Event t Word
_textInput_keydown = EventName 'KeydownTag
-> InputElement EventResult GhcjsDomSpace t
-> Event
     t
     (DomEventType
        (InputElement EventResult GhcjsDomSpace t) 'KeydownTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeydownTag
Keydown InputElement EventResult GhcjsDomSpace t
i
    , _textInput_keyup :: Event t Word
_textInput_keyup = EventName 'KeyupTag
-> InputElement EventResult GhcjsDomSpace t
-> Event
     t
     (DomEventType (InputElement EventResult GhcjsDomSpace t) 'KeyupTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeyupTag
Keyup InputElement EventResult GhcjsDomSpace t
i
    , _textInput_hasFocus :: Dynamic t Bool
_textInput_hasFocus = InputElement EventResult GhcjsDomSpace t -> Dynamic t Bool
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t Bool
_inputElement_hasFocus InputElement EventResult GhcjsDomSpace t
i
    , _textInput_builderElement :: InputElement EventResult GhcjsDomSpace t
_textInput_builderElement = InputElement EventResult GhcjsDomSpace t
i
    }

{-# INLINE textInputGetEnter #-}
{-# DEPRECATED textInputGetEnter "Use 'keypress Enter' instead" #-}
textInputGetEnter :: Reflex t => TextInput t -> Event t ()
textInputGetEnter :: TextInput t -> Event t ()
textInputGetEnter = Key -> TextInput t -> Event t ()
forall k (t :: k) e.
(Reflex t, HasDomEvent t e 'KeypressTag,
 DomEventType e 'KeypressTag ~ Word) =>
Key -> e -> Event t ()
keypress Key
Enter

{-# INLINABLE keypress #-}
keypress :: (Reflex t, HasDomEvent t e 'KeypressTag, DomEventType e 'KeypressTag ~ Word) => Key -> e -> Event t ()
keypress :: Key -> e -> Event t ()
keypress key :: Key
key = (Word -> Maybe ()) -> Event t Word -> Event t ()
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
fmapMaybe (\n :: Word
n -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ KeyCode -> Key
keyCodeLookup (Word -> KeyCode
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n) Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
key) (Event t Word -> Event t ())
-> (e -> Event t Word) -> e -> Event t ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EventName 'KeypressTag
-> e -> Event t (DomEventType e 'KeypressTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeypressTag
Keypress

{-# INLINABLE keydown #-}
keydown :: (Reflex t, HasDomEvent t e 'KeydownTag, DomEventType e 'KeydownTag ~ Word) => Key -> e -> Event t ()
keydown :: Key -> e -> Event t ()
keydown key :: Key
key = (Word -> Maybe ()) -> Event t Word -> Event t ()
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
fmapMaybe (\n :: Word
n -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ KeyCode -> Key
keyCodeLookup (Word -> KeyCode
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n) Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
key) (Event t Word -> Event t ())
-> (e -> Event t Word) -> e -> Event t ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EventName 'KeydownTag -> e -> Event t (DomEventType e 'KeydownTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeydownTag
Keydown

{-# INLINABLE keyup #-}
keyup :: (Reflex t, HasDomEvent t e 'KeyupTag, DomEventType e 'KeyupTag ~ Word) => Key -> e -> Event t ()
keyup :: Key -> e -> Event t ()
keyup key :: Key
key = (Word -> Maybe ()) -> Event t Word -> Event t ()
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
fmapMaybe (\n :: Word
n -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ KeyCode -> Key
keyCodeLookup (Word -> KeyCode
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
n) Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
key) (Event t Word -> Event t ())
-> (e -> Event t Word) -> e -> Event t ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EventName 'KeyupTag -> e -> Event t (DomEventType e 'KeyupTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeyupTag
Keyup

data RangeInputConfig t
   = RangeInputConfig { RangeInputConfig t -> Float
_rangeInputConfig_initialValue :: Float
                      , RangeInputConfig t -> Event t Float
_rangeInputConfig_setValue :: Event t Float
                      , RangeInputConfig t -> Dynamic t (Map Text Text)
_rangeInputConfig_attributes :: Dynamic t (Map Text Text)
                      }

instance Reflex t => Default (RangeInputConfig t) where
  {-# INLINABLE def #-}
  def :: RangeInputConfig t
def = RangeInputConfig :: forall k (t :: k).
Float
-> Event t Float -> Dynamic t (Map Text Text) -> RangeInputConfig t
RangeInputConfig { _rangeInputConfig_initialValue :: Float
_rangeInputConfig_initialValue = 0
                        , _rangeInputConfig_setValue :: Event t Float
_rangeInputConfig_setValue = Event t Float
forall k (t :: k) a. Reflex t => Event t a
never
                        , _rangeInputConfig_attributes :: Dynamic t (Map Text Text)
_rangeInputConfig_attributes = Map Text Text -> Dynamic t (Map Text Text)
forall k (t :: k) a. Reflex t => a -> Dynamic t a
constDyn Map Text Text
forall a. Monoid a => a
mempty
                        }

data RangeInput t
   = RangeInput { RangeInput t -> Dynamic t Float
_rangeInput_value :: Dynamic t Float
                , RangeInput t -> Event t Float
_rangeInput_input :: Event t Float
                , RangeInput t -> Event t (KeyCode, KeyCode)
_rangeInput_mouseup :: Event t (Int, Int)
                , RangeInput t -> Dynamic t Bool
_rangeInput_hasFocus :: Dynamic t Bool
                , RangeInput t -> HTMLInputElement
_rangeInput_element :: HTMLInputElement
                }

-- | Create an input whose value is a float.
--   https://www.w3.org/wiki/HTML/Elements/input/range
{-# INLINABLE rangeInput #-}
rangeInput :: (DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace) => RangeInputConfig t -> m (RangeInput t)
rangeInput :: RangeInputConfig t -> m (RangeInput t)
rangeInput (RangeInputConfig initial :: Float
initial eSetValue :: Event t Float
eSetValue dAttrs :: Dynamic t (Map Text Text)
dAttrs) = do
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes (Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text))))
-> Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall a b. (a -> b) -> a -> b
$ (Map Text Text -> Map Text Text)
-> Dynamic t (Map Text Text) -> Dynamic t (Map Text Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Text -> Map Text Text -> Map Text Text
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert "type" "range") Dynamic t (Map Text Text)
dAttrs
  InputElement EventResult GhcjsDomSpace t
i <- InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult GhcjsDomSpace t)
forall t (m :: * -> *) (er :: EventTag -> *).
DomBuilder t m =>
InputElementConfig er t (DomBuilderSpace m)
-> m (InputElement er (DomBuilderSpace m) t)
inputElement (InputElementConfig EventResult t (DomBuilderSpace m)
 -> m (InputElement EventResult GhcjsDomSpace t))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult GhcjsDomSpace t)
forall a b. (a -> b) -> a -> b
$ InputElementConfig EventResult t GhcjsDomSpace
forall a. Default a => a
def
    InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Text -> Identity Text)
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (er :: EventTag -> *) (t :: k1) (s :: k2).
Lens' (InputElementConfig er t s) Text
inputElementConfig_initialValue ((Text -> Identity Text)
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Text
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (String -> Text
T.pack (String -> Text) -> (Float -> String) -> Float -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> String
forall a. Show a => a -> String
show (Float -> Text) -> Float -> Text
forall a b. (a -> b) -> a -> b
$ Float
initial)
    InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Event t Text -> Identity (Event t Text))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens' (InputElementConfig er t m) (Event t Text)
inputElementConfig_setValue ((Event t Text -> Identity (Event t Text))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Event t Text
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (String -> Text
T.pack (String -> Text) -> (Float -> String) -> Float -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> String
forall a. Show a => a -> String
show (Float -> Text) -> Event t Float -> Event t Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Event t Float
eSetValue)
    InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (InputElementConfig er t s)
  (InputElementConfig er2 t s2)
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
inputElementConfig_elementConfig ((ElementConfig EventResult t GhcjsDomSpace
  -> Identity (ElementConfig EventResult t GhcjsDomSpace))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> ((Event t (Map AttributeName (Maybe Text))
     -> Identity (Event t (Map AttributeName (Maybe Text))))
    -> ElementConfig EventResult t GhcjsDomSpace
    -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> (Event t (Map AttributeName (Maybe Text))
    -> Identity (Event t (Map AttributeName (Maybe Text))))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Event t (Map AttributeName (Maybe Text))
 -> Identity (Event t (Map AttributeName (Maybe Text))))
-> ElementConfig EventResult t GhcjsDomSpace
-> Identity (ElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens'
  (ElementConfig er t m) (Event t (Map AttributeName (Maybe Text)))
elementConfig_modifyAttributes ((Event t (Map AttributeName (Maybe Text))
  -> Identity (Event t (Map AttributeName (Maybe Text))))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Event t (Map AttributeName (Maybe Text))
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
  RangeInput t -> m (RangeInput t)
forall (m :: * -> *) a. Monad m => a -> m a
return (RangeInput t -> m (RangeInput t))
-> RangeInput t -> m (RangeInput t)
forall a b. (a -> b) -> a -> b
$ RangeInput :: forall k (t :: k).
Dynamic t Float
-> Event t Float
-> Event t (KeyCode, KeyCode)
-> Dynamic t Bool
-> HTMLInputElement
-> RangeInput t
RangeInput
    { _rangeInput_value :: Dynamic t Float
_rangeInput_value = String -> Float
forall a. Read a => String -> a
read (String -> Float) -> (Text -> String) -> Text -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> Float) -> Dynamic t Text -> Dynamic t Float
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InputElement EventResult GhcjsDomSpace t -> Dynamic t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t Text
_inputElement_value InputElement EventResult GhcjsDomSpace t
i
    , _rangeInput_input :: Event t Float
_rangeInput_input = String -> Float
forall a. Read a => String -> a
read (String -> Float) -> (Text -> String) -> Text -> Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> Float) -> Event t Text -> Event t Float
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InputElement EventResult GhcjsDomSpace t -> Event t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Event t Text
_inputElement_input InputElement EventResult GhcjsDomSpace t
i
    , _rangeInput_mouseup :: Event t (KeyCode, KeyCode)
_rangeInput_mouseup = EventName 'MouseupTag
-> InputElement EventResult GhcjsDomSpace t
-> Event
     t
     (DomEventType
        (InputElement EventResult GhcjsDomSpace t) 'MouseupTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'MouseupTag
Mouseup InputElement EventResult GhcjsDomSpace t
i
    , _rangeInput_hasFocus :: Dynamic t Bool
_rangeInput_hasFocus = InputElement EventResult GhcjsDomSpace t -> Dynamic t Bool
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t Bool
_inputElement_hasFocus InputElement EventResult GhcjsDomSpace t
i
    , _rangeInput_element :: HTMLInputElement
_rangeInput_element = InputElement EventResult GhcjsDomSpace t
-> RawInputElement GhcjsDomSpace
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> RawInputElement d
_inputElement_raw InputElement EventResult GhcjsDomSpace t
i
    }

{-# DEPRECATED TextAreaConfig, TextArea, textArea "Use 'textAreaElement' directly" #-}
data TextAreaConfig t
   = TextAreaConfig { TextAreaConfig t -> Text
_textAreaConfig_initialValue :: Text
                    , TextAreaConfig t -> Event t Text
_textAreaConfig_setValue :: Event t Text
                    , TextAreaConfig t -> Dynamic t (Map Text Text)
_textAreaConfig_attributes :: Dynamic t (Map Text Text)
                    }

instance Reflex t => Default (TextAreaConfig t) where
  {-# INLINABLE def #-}
  def :: TextAreaConfig t
def = TextAreaConfig :: forall k (t :: k).
Text
-> Event t Text -> Dynamic t (Map Text Text) -> TextAreaConfig t
TextAreaConfig { _textAreaConfig_initialValue :: Text
_textAreaConfig_initialValue = ""
                       , _textAreaConfig_setValue :: Event t Text
_textAreaConfig_setValue = Event t Text
forall k (t :: k) a. Reflex t => Event t a
never
                       , _textAreaConfig_attributes :: Dynamic t (Map Text Text)
_textAreaConfig_attributes = Map Text Text -> Dynamic t (Map Text Text)
forall k (t :: k) a. Reflex t => a -> Dynamic t a
constDyn Map Text Text
forall a. Monoid a => a
mempty
                       }

data TextArea t
   = TextArea { TextArea t -> Dynamic t Text
_textArea_value :: Dynamic t Text
              , TextArea t -> Event t Text
_textArea_input :: Event t Text
              , TextArea t -> Dynamic t Bool
_textArea_hasFocus :: Dynamic t Bool
              , TextArea t -> Event t Word
_textArea_keypress :: Event t Word
              , TextArea t -> HTMLTextAreaElement
_textArea_element :: HTMLTextAreaElement
              }

{-# INLINABLE textArea #-}
textArea :: (DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace) => TextAreaConfig t -> m (TextArea t)
textArea :: TextAreaConfig t -> m (TextArea t)
textArea (TextAreaConfig initial :: Text
initial eSet :: Event t Text
eSet attrs :: Dynamic t (Map Text Text)
attrs) = do
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes Dynamic t (Map Text Text)
attrs
  TextAreaElement EventResult GhcjsDomSpace t
i <- TextAreaElementConfig EventResult t (DomBuilderSpace m)
-> m (TextAreaElement EventResult GhcjsDomSpace t)
forall t (m :: * -> *) (er :: EventTag -> *).
DomBuilder t m =>
TextAreaElementConfig er t (DomBuilderSpace m)
-> m (TextAreaElement er (DomBuilderSpace m) t)
textAreaElement (TextAreaElementConfig EventResult t (DomBuilderSpace m)
 -> m (TextAreaElement EventResult GhcjsDomSpace t))
-> TextAreaElementConfig EventResult t (DomBuilderSpace m)
-> m (TextAreaElement EventResult GhcjsDomSpace t)
forall a b. (a -> b) -> a -> b
$ TextAreaElementConfig EventResult t GhcjsDomSpace
forall a. Default a => a
def
    TextAreaElementConfig EventResult t GhcjsDomSpace
-> (TextAreaElementConfig EventResult t GhcjsDomSpace
    -> TextAreaElementConfig EventResult t GhcjsDomSpace)
-> TextAreaElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Text -> Identity Text)
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (er :: EventTag -> *) (t :: k1) (m :: k2).
Lens' (TextAreaElementConfig er t m) Text
textAreaElementConfig_initialValue ((Text -> Identity Text)
 -> TextAreaElementConfig EventResult t GhcjsDomSpace
 -> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace))
-> Text
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> TextAreaElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Text
initial
    TextAreaElementConfig EventResult t GhcjsDomSpace
-> (TextAreaElementConfig EventResult t GhcjsDomSpace
    -> TextAreaElementConfig EventResult t GhcjsDomSpace)
-> TextAreaElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Event t Text -> Identity (Event t Text))
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens' (TextAreaElementConfig er t m) (Event t Text)
textAreaElementConfig_setValue ((Event t Text -> Identity (Event t Text))
 -> TextAreaElementConfig EventResult t GhcjsDomSpace
 -> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace))
-> Event t Text
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> TextAreaElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Event t Text
eSet
    TextAreaElementConfig EventResult t GhcjsDomSpace
-> (TextAreaElementConfig EventResult t GhcjsDomSpace
    -> TextAreaElementConfig EventResult t GhcjsDomSpace)
-> TextAreaElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (m :: k2)
       (er2 :: EventTag -> *) (m2 :: k3).
Lens
  (TextAreaElementConfig er t m)
  (TextAreaElementConfig er2 t m2)
  (ElementConfig er t m)
  (ElementConfig er2 t m2)
textAreaElementConfig_elementConfig ((ElementConfig EventResult t GhcjsDomSpace
  -> Identity (ElementConfig EventResult t GhcjsDomSpace))
 -> TextAreaElementConfig EventResult t GhcjsDomSpace
 -> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace))
-> ((Event t (Map AttributeName (Maybe Text))
     -> Identity (Event t (Map AttributeName (Maybe Text))))
    -> ElementConfig EventResult t GhcjsDomSpace
    -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> (Event t (Map AttributeName (Maybe Text))
    -> Identity (Event t (Map AttributeName (Maybe Text))))
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Event t (Map AttributeName (Maybe Text))
 -> Identity (Event t (Map AttributeName (Maybe Text))))
-> ElementConfig EventResult t GhcjsDomSpace
-> Identity (ElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens'
  (ElementConfig er t m) (Event t (Map AttributeName (Maybe Text)))
elementConfig_modifyAttributes ((Event t (Map AttributeName (Maybe Text))
  -> Identity (Event t (Map AttributeName (Maybe Text))))
 -> TextAreaElementConfig EventResult t GhcjsDomSpace
 -> Identity (TextAreaElementConfig EventResult t GhcjsDomSpace))
-> Event t (Map AttributeName (Maybe Text))
-> TextAreaElementConfig EventResult t GhcjsDomSpace
-> TextAreaElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
  TextArea t -> m (TextArea t)
forall (m :: * -> *) a. Monad m => a -> m a
return (TextArea t -> m (TextArea t)) -> TextArea t -> m (TextArea t)
forall a b. (a -> b) -> a -> b
$ TextArea :: forall k (t :: k).
Dynamic t Text
-> Event t Text
-> Dynamic t Bool
-> Event t Word
-> HTMLTextAreaElement
-> TextArea t
TextArea
    { _textArea_value :: Dynamic t Text
_textArea_value = TextAreaElement EventResult GhcjsDomSpace t -> Dynamic t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
TextAreaElement er d t -> Dynamic t Text
_textAreaElement_value TextAreaElement EventResult GhcjsDomSpace t
i
    , _textArea_input :: Event t Text
_textArea_input = TextAreaElement EventResult GhcjsDomSpace t -> Event t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
TextAreaElement er d t -> Event t Text
_textAreaElement_input TextAreaElement EventResult GhcjsDomSpace t
i
    , _textArea_keypress :: Event t Word
_textArea_keypress = EventName 'KeypressTag
-> TextAreaElement EventResult GhcjsDomSpace t
-> Event
     t
     (DomEventType
        (TextAreaElement EventResult GhcjsDomSpace t) 'KeypressTag)
forall k (t :: k) target (eventName :: EventTag).
HasDomEvent t target eventName =>
EventName eventName
-> target -> Event t (DomEventType target eventName)
domEvent EventName 'KeypressTag
Keypress TextAreaElement EventResult GhcjsDomSpace t
i
    , _textArea_hasFocus :: Dynamic t Bool
_textArea_hasFocus = TextAreaElement EventResult GhcjsDomSpace t -> Dynamic t Bool
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
TextAreaElement er d t -> Dynamic t Bool
_textAreaElement_hasFocus TextAreaElement EventResult GhcjsDomSpace t
i
    , _textArea_element :: HTMLTextAreaElement
_textArea_element = TextAreaElement EventResult GhcjsDomSpace t
-> RawTextAreaElement GhcjsDomSpace
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
TextAreaElement er d t -> RawTextAreaElement d
_textAreaElement_raw TextAreaElement EventResult GhcjsDomSpace t
i
    }

{-# DEPRECATED CheckboxConfig, Checkbox, checkbox, checkboxView, CheckboxViewEventResultType, regularToCheckboxViewEventType, CheckboxViewEventResult "Use 'inputElement' directly" #-}
data CheckboxConfig t
    = CheckboxConfig { CheckboxConfig t -> Event t Bool
_checkboxConfig_setValue :: Event t Bool
                     , CheckboxConfig t -> Dynamic t (Map Text Text)
_checkboxConfig_attributes :: Dynamic t (Map Text Text)
                     }

instance Reflex t => Default (CheckboxConfig t) where
  {-# INLINABLE def #-}
  def :: CheckboxConfig t
def = CheckboxConfig :: forall k (t :: k).
Event t Bool -> Dynamic t (Map Text Text) -> CheckboxConfig t
CheckboxConfig { _checkboxConfig_setValue :: Event t Bool
_checkboxConfig_setValue = Event t Bool
forall k (t :: k) a. Reflex t => Event t a
never
                       , _checkboxConfig_attributes :: Dynamic t (Map Text Text)
_checkboxConfig_attributes = Map Text Text -> Dynamic t (Map Text Text)
forall k (t :: k) a. Reflex t => a -> Dynamic t a
constDyn Map Text Text
forall a. Monoid a => a
mempty
                       }

data Checkbox t
   = Checkbox { Checkbox t -> Dynamic t Bool
_checkbox_value :: Dynamic t Bool
              , Checkbox t -> Event t Bool
_checkbox_change :: Event t Bool
              }

-- | Create an editable checkbox
--   Note: if the "type" or "checked" attributes are provided as attributes, they will be ignored
{-# INLINABLE checkbox #-}
checkbox :: (DomBuilder t m, PostBuild t m) => Bool -> CheckboxConfig t -> m (Checkbox t)
checkbox :: Bool -> CheckboxConfig t -> m (Checkbox t)
checkbox checked :: Bool
checked config :: CheckboxConfig t
config = do
  let permanentAttrs :: Map Text Text
permanentAttrs = "type" Index (Map Text Text) -> IxValue (Map Text Text) -> Map Text Text
forall m. (At m, Monoid m) => Index m -> IxValue m -> m
=: "checkbox"
      dAttrs :: Dynamic t (Map Text Text)
dAttrs = Text -> Map Text Text -> Map Text Text
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete "checked" (Map Text Text -> Map Text Text)
-> (Map Text Text -> Map Text Text)
-> Map Text Text
-> Map Text Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Text Text -> Map Text Text -> Map Text Text
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union Map Text Text
permanentAttrs (Map Text Text -> Map Text Text)
-> Dynamic t (Map Text Text) -> Dynamic t (Map Text Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CheckboxConfig t -> Dynamic t (Map Text Text)
forall k (t :: k). CheckboxConfig t -> Dynamic t (Map Text Text)
_checkboxConfig_attributes CheckboxConfig t
config
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes Dynamic t (Map Text Text)
dAttrs
  InputElement EventResult (DomBuilderSpace m) t
i <- InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult (DomBuilderSpace m) t)
forall t (m :: * -> *) (er :: EventTag -> *).
DomBuilder t m =>
InputElementConfig er t (DomBuilderSpace m)
-> m (InputElement er (DomBuilderSpace m) t)
inputElement (InputElementConfig EventResult t (DomBuilderSpace m)
 -> m (InputElement EventResult (DomBuilderSpace m) t))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult (DomBuilderSpace m) t)
forall a b. (a -> b) -> a -> b
$ InputElementConfig EventResult t (DomBuilderSpace m)
forall a. Default a => a
def
    InputElementConfig EventResult t (DomBuilderSpace m)
-> (InputElementConfig EventResult t (DomBuilderSpace m)
    -> InputElementConfig EventResult t (DomBuilderSpace m))
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall a b. a -> (a -> b) -> b
& (Bool -> Identity Bool)
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> Identity (InputElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 (er :: EventTag -> *) (t :: k1) (s :: k2).
Lens' (InputElementConfig er t s) Bool
inputElementConfig_initialChecked ((Bool -> Identity Bool)
 -> InputElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (InputElementConfig EventResult t (DomBuilderSpace m)))
-> Bool
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
checked
    InputElementConfig EventResult t (DomBuilderSpace m)
-> (InputElementConfig EventResult t (DomBuilderSpace m)
    -> InputElementConfig EventResult t (DomBuilderSpace m))
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall a b. a -> (a -> b) -> b
& (Event t Bool -> Identity (Event t Bool))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> Identity (InputElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens' (InputElementConfig er t m) (Event t Bool)
inputElementConfig_setChecked ((Event t Bool -> Identity (Event t Bool))
 -> InputElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (InputElementConfig EventResult t (DomBuilderSpace m)))
-> Event t Bool
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ CheckboxConfig t -> Event t Bool
forall k (t :: k). CheckboxConfig t -> Event t Bool
_checkboxConfig_setValue CheckboxConfig t
config
    InputElementConfig EventResult t (DomBuilderSpace m)
-> (InputElementConfig EventResult t (DomBuilderSpace m)
    -> InputElementConfig EventResult t (DomBuilderSpace m))
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> Identity (InputElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (InputElementConfig er t s)
  (InputElementConfig er2 t s2)
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
inputElementConfig_elementConfig ((ElementConfig EventResult t (DomBuilderSpace m)
  -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
 -> InputElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (InputElementConfig EventResult t (DomBuilderSpace m)))
-> ((Map AttributeName Text -> Identity (Map AttributeName Text))
    -> ElementConfig EventResult t (DomBuilderSpace m)
    -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
-> (Map AttributeName Text -> Identity (Map AttributeName Text))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> Identity (InputElementConfig EventResult t (DomBuilderSpace m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map AttributeName Text -> Identity (Map AttributeName Text))
-> ElementConfig EventResult t (DomBuilderSpace m)
-> Identity (ElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 (er :: EventTag -> *) (t :: k1) (s :: k2).
Lens' (ElementConfig er t s) (Map AttributeName Text)
elementConfig_initialAttributes ((Map AttributeName Text -> Identity (Map AttributeName Text))
 -> InputElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (InputElementConfig EventResult t (DomBuilderSpace m)))
-> Map AttributeName Text
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Text -> AttributeName) -> Map Text Text -> Map AttributeName Text
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys (Maybe Text -> Text -> AttributeName
AttributeName Maybe Text
forall a. Maybe a
Nothing) Map Text Text
permanentAttrs
    InputElementConfig EventResult t (DomBuilderSpace m)
-> (InputElementConfig EventResult t (DomBuilderSpace m)
    -> InputElementConfig EventResult t (DomBuilderSpace m))
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> Identity (InputElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (InputElementConfig er t s)
  (InputElementConfig er2 t s2)
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
inputElementConfig_elementConfig ((ElementConfig EventResult t (DomBuilderSpace m)
  -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
 -> InputElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (InputElementConfig EventResult t (DomBuilderSpace m)))
-> ((Event t (Map AttributeName (Maybe Text))
     -> Identity (Event t (Map AttributeName (Maybe Text))))
    -> ElementConfig EventResult t (DomBuilderSpace m)
    -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
-> (Event t (Map AttributeName (Maybe Text))
    -> Identity (Event t (Map AttributeName (Maybe Text))))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> Identity (InputElementConfig EventResult t (DomBuilderSpace m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Event t (Map AttributeName (Maybe Text))
 -> Identity (Event t (Map AttributeName (Maybe Text))))
-> ElementConfig EventResult t (DomBuilderSpace m)
-> Identity (ElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens'
  (ElementConfig er t m) (Event t (Map AttributeName (Maybe Text)))
elementConfig_modifyAttributes ((Event t (Map AttributeName (Maybe Text))
  -> Identity (Event t (Map AttributeName (Maybe Text))))
 -> InputElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (InputElementConfig EventResult t (DomBuilderSpace m)))
-> Event t (Map AttributeName (Maybe Text))
-> InputElementConfig EventResult t (DomBuilderSpace m)
-> InputElementConfig EventResult t (DomBuilderSpace m)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
  Checkbox t -> m (Checkbox t)
forall (m :: * -> *) a. Monad m => a -> m a
return (Checkbox t -> m (Checkbox t)) -> Checkbox t -> m (Checkbox t)
forall a b. (a -> b) -> a -> b
$ Checkbox :: forall k (t :: k). Dynamic t Bool -> Event t Bool -> Checkbox t
Checkbox
    { _checkbox_value :: Dynamic t Bool
_checkbox_value = InputElement EventResult (DomBuilderSpace m) t -> Dynamic t Bool
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t Bool
_inputElement_checked InputElement EventResult (DomBuilderSpace m) t
i
    , _checkbox_change :: Event t Bool
_checkbox_change = InputElement EventResult (DomBuilderSpace m) t -> Event t Bool
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Event t Bool
_inputElement_checkedChange InputElement EventResult (DomBuilderSpace m) t
i
    }

type family CheckboxViewEventResultType (en :: EventTag) :: * where
  CheckboxViewEventResultType 'ClickTag = Bool
  CheckboxViewEventResultType t = EventResultType t

regularToCheckboxViewEventType :: EventName t -> EventResultType t -> CheckboxViewEventResultType t
regularToCheckboxViewEventType :: EventName t -> EventResultType t -> CheckboxViewEventResultType t
regularToCheckboxViewEventType en :: EventName t
en r :: EventResultType t
r = case EventName t
en of
  Click -> String -> Bool
forall a. HasCallStack => String -> a
error "regularToCheckboxViewEventType: EventName Click should never be encountered"
  Abort -> EventResultType t
CheckboxViewEventResultType t
r
  Blur -> EventResultType t
CheckboxViewEventResultType t
r
  Change -> EventResultType t
CheckboxViewEventResultType t
r
  Contextmenu -> EventResultType t
CheckboxViewEventResultType t
r
  Dblclick -> EventResultType t
CheckboxViewEventResultType t
r
  Drag -> EventResultType t
CheckboxViewEventResultType t
r
  Dragend -> EventResultType t
CheckboxViewEventResultType t
r
  Dragenter -> EventResultType t
CheckboxViewEventResultType t
r
  Dragleave -> EventResultType t
CheckboxViewEventResultType t
r
  Dragover -> EventResultType t
CheckboxViewEventResultType t
r
  Dragstart -> EventResultType t
CheckboxViewEventResultType t
r
  Drop -> EventResultType t
CheckboxViewEventResultType t
r
  Error -> EventResultType t
CheckboxViewEventResultType t
r
  Focus -> EventResultType t
CheckboxViewEventResultType t
r
  Input -> EventResultType t
CheckboxViewEventResultType t
r
  Invalid -> EventResultType t
CheckboxViewEventResultType t
r
  Keydown -> EventResultType t
CheckboxViewEventResultType t
r
  Keypress -> EventResultType t
CheckboxViewEventResultType t
r
  Keyup -> EventResultType t
CheckboxViewEventResultType t
r
  Load -> EventResultType t
CheckboxViewEventResultType t
r
  Mousedown -> EventResultType t
CheckboxViewEventResultType t
r
  Mouseenter -> EventResultType t
CheckboxViewEventResultType t
r
  Mouseleave -> EventResultType t
CheckboxViewEventResultType t
r
  Mousemove -> EventResultType t
CheckboxViewEventResultType t
r
  Mouseout -> EventResultType t
CheckboxViewEventResultType t
r
  Mouseover -> EventResultType t
CheckboxViewEventResultType t
r
  Mouseup -> EventResultType t
CheckboxViewEventResultType t
r
  Mousewheel -> EventResultType t
CheckboxViewEventResultType t
r
  Scroll -> EventResultType t
CheckboxViewEventResultType t
r
  Select -> EventResultType t
CheckboxViewEventResultType t
r
  Submit -> EventResultType t
CheckboxViewEventResultType t
r
  Wheel -> EventResultType t
CheckboxViewEventResultType t
r
  Beforecut -> EventResultType t
CheckboxViewEventResultType t
r
  Cut -> EventResultType t
CheckboxViewEventResultType t
r
  Beforecopy -> EventResultType t
CheckboxViewEventResultType t
r
  Copy -> EventResultType t
CheckboxViewEventResultType t
r
  Beforepaste -> EventResultType t
CheckboxViewEventResultType t
r
  Paste -> EventResultType t
CheckboxViewEventResultType t
r
  Reset -> EventResultType t
CheckboxViewEventResultType t
r
  Search -> EventResultType t
CheckboxViewEventResultType t
r
  Selectstart -> EventResultType t
CheckboxViewEventResultType t
r
  Touchstart -> EventResultType t
CheckboxViewEventResultType t
r
  Touchmove -> EventResultType t
CheckboxViewEventResultType t
r
  Touchend -> EventResultType t
CheckboxViewEventResultType t
r
  Touchcancel -> EventResultType t
CheckboxViewEventResultType t
r

newtype CheckboxViewEventResult en = CheckboxViewEventResult { CheckboxViewEventResult en -> CheckboxViewEventResultType en
unCheckboxViewEventResult :: CheckboxViewEventResultType en }

-- | Create a view only checkbox
{-# INLINABLE checkboxView #-}
checkboxView :: forall t m. (DomBuilder t m, DomBuilderSpace m ~ GhcjsDomSpace, PostBuild t m, MonadHold t m) => Dynamic t (Map Text Text) -> Dynamic t Bool -> m (Event t Bool)
checkboxView :: Dynamic t (Map Text Text) -> Dynamic t Bool -> m (Event t Bool)
checkboxView dAttrs :: Dynamic t (Map Text Text)
dAttrs dValue :: Dynamic t Bool
dValue = do
  let permanentAttrs :: Map Text Text
permanentAttrs = "type" Index (Map Text Text) -> IxValue (Map Text Text) -> Map Text Text
forall m. (At m, Monoid m) => Index m -> IxValue m -> m
=: "checkbox"
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes (Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text))))
-> Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall a b. (a -> b) -> a -> b
$ (Map Text Text -> Map Text Text)
-> Dynamic t (Map Text Text) -> Dynamic t (Map Text Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map Text Text -> Map Text Text -> Map Text Text
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union Map Text Text
permanentAttrs) Dynamic t (Map Text Text)
dAttrs
  Event t ()
postBuild <- m (Event t ())
forall t (m :: * -> *). PostBuild t m => m (Event t ())
getPostBuild
  let filters :: DMap EventName (GhcjsEventFilter CheckboxViewEventResult)
      filters :: DMap EventName (GhcjsEventFilter CheckboxViewEventResult)
filters = EventName 'ClickTag
-> GhcjsEventFilter CheckboxViewEventResult 'ClickTag
-> DMap EventName (GhcjsEventFilter CheckboxViewEventResult)
forall k1 (k2 :: k1 -> *) (v :: k1) (f :: k1 -> *).
k2 v -> f v -> DMap k2 f
DMap.singleton EventName 'ClickTag
Click (GhcjsEventFilter CheckboxViewEventResult 'ClickTag
 -> DMap EventName (GhcjsEventFilter CheckboxViewEventResult))
-> GhcjsEventFilter CheckboxViewEventResult 'ClickTag
-> DMap EventName (GhcjsEventFilter CheckboxViewEventResult)
forall a b. (a -> b) -> a -> b
$ (GhcjsDomEvent 'ClickTag
 -> JSM
      (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag))))
-> GhcjsEventFilter CheckboxViewEventResult 'ClickTag
forall (er :: EventTag -> *) (en :: EventTag).
(GhcjsDomEvent en -> JSM (EventFlags, JSM (Maybe (er en))))
-> GhcjsEventFilter er en
GhcjsEventFilter ((GhcjsDomEvent 'ClickTag
  -> JSM
       (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag))))
 -> GhcjsEventFilter CheckboxViewEventResult 'ClickTag)
-> (GhcjsDomEvent 'ClickTag
    -> JSM
         (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag))))
-> GhcjsEventFilter CheckboxViewEventResult 'ClickTag
forall a b. (a -> b) -> a -> b
$ \(GhcjsDomEvent evt :: EventType 'ClickTag
evt) -> do
        EventTarget
t <- MouseEvent -> JSM EventTarget
forall (m :: * -> *) self.
(MonadDOM m, IsEvent self) =>
self -> m EventTarget
Event.getTargetUnchecked MouseEvent
EventType 'ClickTag
evt
        Bool
b <- HTMLInputElement -> JSM Bool
forall (m :: * -> *). MonadDOM m => HTMLInputElement -> m Bool
Input.getChecked (HTMLInputElement -> JSM Bool) -> HTMLInputElement -> JSM Bool
forall a b. (a -> b) -> a -> b
$ (JSVal -> HTMLInputElement) -> EventTarget -> HTMLInputElement
forall obj obj'.
(Coercible obj JSVal, IsGObject obj') =>
(JSVal -> obj') -> obj -> obj'
uncheckedCastTo JSVal -> HTMLInputElement
Input.HTMLInputElement EventTarget
t
        (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
-> JSM
     (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
forall (m :: * -> *) a. Monad m => a -> m a
return ((EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
 -> JSM
      (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag))))
-> (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
-> JSM
     (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
forall a b. (a -> b) -> a -> b
$ (,) EventFlags
preventDefault (JSM (Maybe (CheckboxViewEventResult 'ClickTag))
 -> (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag))))
-> JSM (Maybe (CheckboxViewEventResult 'ClickTag))
-> (EventFlags, JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
forall a b. (a -> b) -> a -> b
$ Maybe (CheckboxViewEventResult 'ClickTag)
-> JSM (Maybe (CheckboxViewEventResult 'ClickTag))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (CheckboxViewEventResult 'ClickTag)
 -> JSM (Maybe (CheckboxViewEventResult 'ClickTag)))
-> Maybe (CheckboxViewEventResult 'ClickTag)
-> JSM (Maybe (CheckboxViewEventResult 'ClickTag))
forall a b. (a -> b) -> a -> b
$ CheckboxViewEventResult 'ClickTag
-> Maybe (CheckboxViewEventResult 'ClickTag)
forall a. a -> Maybe a
Just (CheckboxViewEventResult 'ClickTag
 -> Maybe (CheckboxViewEventResult 'ClickTag))
-> CheckboxViewEventResult 'ClickTag
-> Maybe (CheckboxViewEventResult 'ClickTag)
forall a b. (a -> b) -> a -> b
$ CheckboxViewEventResultType 'ClickTag
-> CheckboxViewEventResult 'ClickTag
forall (en :: EventTag).
CheckboxViewEventResultType en -> CheckboxViewEventResult en
CheckboxViewEventResult Bool
CheckboxViewEventResultType 'ClickTag
b
      elementConfig :: ElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
      elementConfig :: ElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
elementConfig = (ElementConfig EventResult t (DomBuilderSpace m)
forall a. Default a => a
def :: ElementConfig EventResult t (DomBuilderSpace m))
        { _elementConfig_modifyAttributes :: Maybe (Event t (Map AttributeName (Maybe Text)))
_elementConfig_modifyAttributes = Event t (Map AttributeName (Maybe Text))
-> Maybe (Event t (Map AttributeName (Maybe Text)))
forall a. a -> Maybe a
Just (Event t (Map AttributeName (Maybe Text))
 -> Maybe (Event t (Map AttributeName (Maybe Text))))
-> Event t (Map AttributeName (Maybe Text))
-> Maybe (Event t (Map AttributeName (Maybe Text)))
forall a b. (a -> b) -> a -> b
$ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
        , _elementConfig_initialAttributes :: Map AttributeName Text
_elementConfig_initialAttributes = (Text -> AttributeName) -> Map Text Text -> Map AttributeName Text
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys (Maybe Text -> Text -> AttributeName
AttributeName Maybe Text
forall a. Maybe a
Nothing) Map Text Text
permanentAttrs
        , _elementConfig_eventSpec :: EventSpec GhcjsDomSpace CheckboxViewEventResult
_elementConfig_eventSpec = GhcjsEventSpec :: forall (er :: EventTag -> *).
DMap EventName (GhcjsEventFilter er)
-> GhcjsEventHandler er -> GhcjsEventSpec er
GhcjsEventSpec
            { _ghcjsEventSpec_filters :: DMap EventName (GhcjsEventFilter CheckboxViewEventResult)
_ghcjsEventSpec_filters = DMap EventName (GhcjsEventFilter CheckboxViewEventResult)
filters
            , _ghcjsEventSpec_handler :: GhcjsEventHandler CheckboxViewEventResult
_ghcjsEventSpec_handler = (forall (en :: EventTag).
 (EventName en, GhcjsDomEvent en)
 -> JSM (Maybe (CheckboxViewEventResult en)))
-> GhcjsEventHandler CheckboxViewEventResult
forall (er :: EventTag -> *).
(forall (en :: EventTag).
 (EventName en, GhcjsDomEvent en) -> JSM (Maybe (er en)))
-> GhcjsEventHandler er
GhcjsEventHandler ((forall (en :: EventTag).
  (EventName en, GhcjsDomEvent en)
  -> JSM (Maybe (CheckboxViewEventResult en)))
 -> GhcjsEventHandler CheckboxViewEventResult)
-> (forall (en :: EventTag).
    (EventName en, GhcjsDomEvent en)
    -> JSM (Maybe (CheckboxViewEventResult en)))
-> GhcjsEventHandler CheckboxViewEventResult
forall a b. (a -> b) -> a -> b
$ \(en :: EventName en
en, GhcjsDomEvent evt :: EventType en
evt) -> case EventName en
en of
                Click -> String -> JSM (Maybe (CheckboxViewEventResult en))
forall a. HasCallStack => String -> a
error "impossible"
                _ -> do
                  EventTarget
e :: DOM.EventTarget <- EventName en
-> (IsEvent (EventType en) => JSM EventTarget) -> JSM EventTarget
forall (en :: EventTag) r.
EventName en -> (IsEvent (EventType en) => r) -> r
withIsEvent EventName en
en ((IsEvent (EventType en) => JSM EventTarget) -> JSM EventTarget)
-> (IsEvent (EventType en) => JSM EventTarget) -> JSM EventTarget
forall a b. (a -> b) -> a -> b
$ EventType en -> JSM EventTarget
forall (m :: * -> *) self.
(MonadDOM m, IsEvent self) =>
self -> m EventTarget
Event.getTargetUnchecked EventType en
evt
                  let myElement :: HTMLElement
myElement = (JSVal -> HTMLElement) -> EventTarget -> HTMLElement
forall obj obj'.
(Coercible obj JSVal, IsGObject obj') =>
(JSVal -> obj') -> obj -> obj'
uncheckedCastTo JSVal -> HTMLElement
DOM.HTMLElement EventTarget
e
                  Maybe (EventResult en)
mr <- ReaderT (EventType en) DOM (Maybe (EventResult en))
-> EventType en -> DOM (Maybe (EventResult en))
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (HTMLElement
-> EventName en
-> ReaderT (EventType en) DOM (Maybe (EventResult en))
forall e (en :: EventTag).
IsElement e =>
e
-> EventName en -> EventM e (EventType en) (Maybe (EventResult en))
defaultDomEventHandler HTMLElement
myElement EventName en
en) EventType en
evt
                  Maybe (CheckboxViewEventResult en)
-> JSM (Maybe (CheckboxViewEventResult en))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (CheckboxViewEventResult en)
 -> JSM (Maybe (CheckboxViewEventResult en)))
-> Maybe (CheckboxViewEventResult en)
-> JSM (Maybe (CheckboxViewEventResult en))
forall a b. (a -> b) -> a -> b
$ Maybe (EventResult en)
-> (EventResult en -> CheckboxViewEventResult en)
-> Maybe (CheckboxViewEventResult en)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Maybe (EventResult en)
mr ((EventResult en -> CheckboxViewEventResult en)
 -> Maybe (CheckboxViewEventResult en))
-> (EventResult en -> CheckboxViewEventResult en)
-> Maybe (CheckboxViewEventResult en)
forall a b. (a -> b) -> a -> b
$ \(EventResult r :: EventResultType en
r) -> CheckboxViewEventResultType en -> CheckboxViewEventResult en
forall (en :: EventTag).
CheckboxViewEventResultType en -> CheckboxViewEventResult en
CheckboxViewEventResult (CheckboxViewEventResultType en -> CheckboxViewEventResult en)
-> CheckboxViewEventResultType en -> CheckboxViewEventResult en
forall a b. (a -> b) -> a -> b
$ EventName en
-> EventResultType en -> CheckboxViewEventResultType en
forall (t :: EventTag).
EventName t -> EventResultType t -> CheckboxViewEventResultType t
regularToCheckboxViewEventType EventName en
en EventResultType en
r
            }
        }
      inputElementConfig :: InputElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
      inputElementConfig :: InputElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
inputElementConfig = (InputElementConfig EventResult t (DomBuilderSpace m)
forall a. Default a => a
def :: InputElementConfig EventResult t (DomBuilderSpace m))
        InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Event t Bool -> Identity (Event t Bool))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens' (InputElementConfig er t m) (Event t Bool)
inputElementConfig_setChecked ((Event t Bool -> Identity (Event t Bool))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> Event t Bool
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ [Event t Bool] -> Event t Bool
forall k (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [Dynamic t Bool -> Event t Bool
forall k (t :: k) a. Reflex t => Dynamic t a -> Event t a
updated Dynamic t Bool
dValue, Behavior t Bool -> Event t () -> Event t Bool
forall k (t :: k) b a.
Reflex t =>
Behavior t b -> Event t a -> Event t b
tag (Dynamic t Bool -> Behavior t Bool
forall k (t :: k) a. Reflex t => Dynamic t a -> Behavior t a
current Dynamic t Bool
dValue) Event t ()
postBuild]
        InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig CheckboxViewEventResult t GhcjsDomSpace)
-> InputElementConfig CheckboxViewEventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t GhcjsDomSpace
 -> Identity
      (ElementConfig CheckboxViewEventResult t GhcjsDomSpace))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity
     (InputElementConfig CheckboxViewEventResult t GhcjsDomSpace)
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (InputElementConfig er t s)
  (InputElementConfig er2 t s2)
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
inputElementConfig_elementConfig ((ElementConfig EventResult t GhcjsDomSpace
  -> Identity
       (ElementConfig CheckboxViewEventResult t GhcjsDomSpace))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity
      (InputElementConfig CheckboxViewEventResult t GhcjsDomSpace))
-> ElementConfig CheckboxViewEventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig CheckboxViewEventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
ElementConfig CheckboxViewEventResult t GhcjsDomSpace
elementConfig
  InputElement CheckboxViewEventResult GhcjsDomSpace t
i <- InputElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
-> m (InputElement CheckboxViewEventResult (DomBuilderSpace m) t)
forall t (m :: * -> *) (er :: EventTag -> *).
DomBuilder t m =>
InputElementConfig er t (DomBuilderSpace m)
-> m (InputElement er (DomBuilderSpace m) t)
inputElement InputElementConfig CheckboxViewEventResult t (DomBuilderSpace m)
inputElementConfig
  Event t Bool -> m (Event t Bool)
forall (m :: * -> *) a. Monad m => a -> m a
return (Event t Bool -> m (Event t Bool))
-> Event t Bool -> m (Event t Bool)
forall a b. (a -> b) -> a -> b
$ CheckboxViewEventResult 'ClickTag -> Bool
forall (en :: EventTag).
CheckboxViewEventResult en -> CheckboxViewEventResultType en
unCheckboxViewEventResult (CheckboxViewEventResult 'ClickTag -> Bool)
-> Event t (CheckboxViewEventResult 'ClickTag) -> Event t Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> EventSelector t (WrapArg CheckboxViewEventResult EventName)
-> WrapArg
     CheckboxViewEventResult
     EventName
     (CheckboxViewEventResult 'ClickTag)
-> Event t (CheckboxViewEventResult 'ClickTag)
forall k1 (t :: k1) (k2 :: * -> *).
EventSelector t k2 -> forall a. k2 a -> Event t a
select (Element CheckboxViewEventResult GhcjsDomSpace t
-> EventSelector t (WrapArg CheckboxViewEventResult EventName)
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
Element er d t -> EventSelector t (WrapArg er EventName)
_element_events (Element CheckboxViewEventResult GhcjsDomSpace t
 -> EventSelector t (WrapArg CheckboxViewEventResult EventName))
-> Element CheckboxViewEventResult GhcjsDomSpace t
-> EventSelector t (WrapArg CheckboxViewEventResult EventName)
forall a b. (a -> b) -> a -> b
$ InputElement CheckboxViewEventResult GhcjsDomSpace t
-> Element CheckboxViewEventResult GhcjsDomSpace t
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Element er d t
_inputElement_element InputElement CheckboxViewEventResult GhcjsDomSpace t
i) (EventName 'ClickTag
-> WrapArg
     CheckboxViewEventResult
     EventName
     (CheckboxViewEventResult 'ClickTag)
forall k (b :: k -> *) (a1 :: k) (a :: k -> *).
b a1 -> WrapArg a b (a a1)
WrapArg EventName 'ClickTag
Click)

{-# DEPRECATED FileInput, FileInputConfig, fileInput "Use 'inputElement' directly" #-}
data FileInput d t
   = FileInput { FileInput d t -> Dynamic t [File]
_fileInput_value :: Dynamic t [File]
               , FileInput d t -> RawInputElement d
_fileInput_element :: RawInputElement d
               }

newtype FileInputConfig t
   = FileInputConfig { FileInputConfig t -> Dynamic t (Map Text Text)
_fileInputConfig_attributes :: Dynamic t (Map Text Text)
                     }

instance Reflex t => Default (FileInputConfig t) where
  def :: FileInputConfig t
def = FileInputConfig :: forall k (t :: k). Dynamic t (Map Text Text) -> FileInputConfig t
FileInputConfig { _fileInputConfig_attributes :: Dynamic t (Map Text Text)
_fileInputConfig_attributes = Map Text Text -> Dynamic t (Map Text Text)
forall k (t :: k) a. Reflex t => a -> Dynamic t a
constDyn Map Text Text
forall a. Monoid a => a
mempty
                        }

fileInput :: forall t m. (MonadIO m, MonadJSM m, MonadFix m, MonadHold t m, TriggerEvent t m, DomBuilder t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace)
          => FileInputConfig t -> m (FileInput (DomBuilderSpace m) t)
fileInput :: FileInputConfig t -> m (FileInput (DomBuilderSpace m) t)
fileInput config :: FileInputConfig t
config = do
  let insertType :: Map Text Text -> Map Text Text
insertType = Text -> Text -> Map Text Text -> Map Text Text
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert "type" "file"
      dAttrs :: Dynamic t (Map Text Text)
dAttrs = Map Text Text -> Map Text Text
insertType (Map Text Text -> Map Text Text)
-> Dynamic t (Map Text Text) -> Dynamic t (Map Text Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FileInputConfig t -> Dynamic t (Map Text Text)
forall k (t :: k). FileInputConfig t -> Dynamic t (Map Text Text)
_fileInputConfig_attributes FileInputConfig t
config
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes Dynamic t (Map Text Text)
dAttrs
  let filters :: DMap EventName (GhcjsEventFilter EventResult)
filters = EventName 'ChangeTag
-> GhcjsEventFilter EventResult 'ChangeTag
-> DMap EventName (GhcjsEventFilter EventResult)
forall k1 (k2 :: k1 -> *) (v :: k1) (f :: k1 -> *).
k2 v -> f v -> DMap k2 f
DMap.singleton EventName 'ChangeTag
Change (GhcjsEventFilter EventResult 'ChangeTag
 -> DMap EventName (GhcjsEventFilter EventResult))
-> ((GhcjsDomEvent 'ChangeTag
     -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
    -> GhcjsEventFilter EventResult 'ChangeTag)
-> (GhcjsDomEvent 'ChangeTag
    -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
-> DMap EventName (GhcjsEventFilter EventResult)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GhcjsDomEvent 'ChangeTag
 -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
-> GhcjsEventFilter EventResult 'ChangeTag
forall (er :: EventTag -> *) (en :: EventTag).
(GhcjsDomEvent en -> JSM (EventFlags, JSM (Maybe (er en))))
-> GhcjsEventFilter er en
GhcjsEventFilter ((GhcjsDomEvent 'ChangeTag
  -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
 -> DMap EventName (GhcjsEventFilter EventResult))
-> (GhcjsDomEvent 'ChangeTag
    -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
-> DMap EventName (GhcjsEventFilter EventResult)
forall a b. (a -> b) -> a -> b
$ \_ -> do
        (EventFlags, JSM (Maybe (EventResult 'ChangeTag)))
-> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag)))
forall (m :: * -> *) a. Monad m => a -> m a
return ((EventFlags, JSM (Maybe (EventResult 'ChangeTag)))
 -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
-> (JSM (Maybe (EventResult 'ChangeTag))
    -> (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
-> JSM (Maybe (EventResult 'ChangeTag))
-> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) EventFlags
forall a. Monoid a => a
mempty (JSM (Maybe (EventResult 'ChangeTag))
 -> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag))))
-> JSM (Maybe (EventResult 'ChangeTag))
-> JSM (EventFlags, JSM (Maybe (EventResult 'ChangeTag)))
forall a b. (a -> b) -> a -> b
$ Maybe (EventResult 'ChangeTag)
-> JSM (Maybe (EventResult 'ChangeTag))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (EventResult 'ChangeTag)
 -> JSM (Maybe (EventResult 'ChangeTag)))
-> (EventResult 'ChangeTag -> Maybe (EventResult 'ChangeTag))
-> EventResult 'ChangeTag
-> JSM (Maybe (EventResult 'ChangeTag))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EventResult 'ChangeTag -> Maybe (EventResult 'ChangeTag)
forall a. a -> Maybe a
Just (EventResult 'ChangeTag -> JSM (Maybe (EventResult 'ChangeTag)))
-> EventResult 'ChangeTag -> JSM (Maybe (EventResult 'ChangeTag))
forall a b. (a -> b) -> a -> b
$ EventResultType 'ChangeTag -> EventResult 'ChangeTag
forall (en :: EventTag). EventResultType en -> EventResult en
EventResult ()
      elCfg :: ElementConfig EventResult t GhcjsDomSpace
elCfg = (ElementConfig EventResult t (DomBuilderSpace m)
forall a. Default a => a
def :: ElementConfig EventResult t (DomBuilderSpace m))
        ElementConfig EventResult t GhcjsDomSpace
-> (ElementConfig EventResult t GhcjsDomSpace
    -> ElementConfig EventResult t GhcjsDomSpace)
-> ElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (Event t (Map AttributeName (Maybe Text))
 -> Identity (Event t (Map AttributeName (Maybe Text))))
-> ElementConfig EventResult t GhcjsDomSpace
-> Identity (ElementConfig EventResult t GhcjsDomSpace)
forall k (t :: k) a.
(ModifyAttributes t a, Reflex t) =>
Lens' a (Event t (Map AttributeName (Maybe Text)))
modifyAttributes ((Event t (Map AttributeName (Maybe Text))
  -> Identity (Event t (Map AttributeName (Maybe Text))))
 -> ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> Event t (Map AttributeName (Maybe Text))
-> ElementConfig EventResult t GhcjsDomSpace
-> ElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
        ElementConfig EventResult t GhcjsDomSpace
-> (ElementConfig EventResult t GhcjsDomSpace
    -> ElementConfig EventResult t GhcjsDomSpace)
-> ElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (GhcjsEventSpec EventResult
 -> Identity (GhcjsEventSpec EventResult))
-> ElementConfig EventResult t GhcjsDomSpace
-> Identity (ElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
  (EventSpec s er)
  (EventSpec s2 er2)
elementConfig_eventSpec ((GhcjsEventSpec EventResult
  -> Identity (GhcjsEventSpec EventResult))
 -> ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> ((DMap EventName (GhcjsEventFilter EventResult)
     -> Identity (DMap EventName (GhcjsEventFilter EventResult)))
    -> GhcjsEventSpec EventResult
    -> Identity (GhcjsEventSpec EventResult))
-> (DMap EventName (GhcjsEventFilter EventResult)
    -> Identity (DMap EventName (GhcjsEventFilter EventResult)))
-> ElementConfig EventResult t GhcjsDomSpace
-> Identity (ElementConfig EventResult t GhcjsDomSpace)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DMap EventName (GhcjsEventFilter EventResult)
 -> Identity (DMap EventName (GhcjsEventFilter EventResult)))
-> GhcjsEventSpec EventResult
-> Identity (GhcjsEventSpec EventResult)
forall (er :: EventTag -> *).
Lens' (GhcjsEventSpec er) (DMap EventName (GhcjsEventFilter er))
ghcjsEventSpec_filters ((DMap EventName (GhcjsEventFilter EventResult)
  -> Identity (DMap EventName (GhcjsEventFilter EventResult)))
 -> ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> DMap EventName (GhcjsEventFilter EventResult)
-> ElementConfig EventResult t GhcjsDomSpace
-> ElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ DMap EventName (GhcjsEventFilter EventResult)
filters
      cfg :: InputElementConfig EventResult t GhcjsDomSpace
cfg = (InputElementConfig EventResult t (DomBuilderSpace m)
forall a. Default a => a
def :: InputElementConfig EventResult t (DomBuilderSpace m)) InputElementConfig EventResult t GhcjsDomSpace
-> (InputElementConfig EventResult t GhcjsDomSpace
    -> InputElementConfig EventResult t GhcjsDomSpace)
-> InputElementConfig EventResult t GhcjsDomSpace
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t GhcjsDomSpace
 -> Identity (ElementConfig EventResult t GhcjsDomSpace))
-> InputElementConfig EventResult t GhcjsDomSpace
-> Identity (InputElementConfig EventResult t GhcjsDomSpace)
forall k1 k2 k3 (er :: EventTag -> *) (t :: k1) (s :: k2)
       (er2 :: EventTag -> *) (s2 :: k3).
Lens
  (InputElementConfig er t s)
  (InputElementConfig er2 t s2)
  (ElementConfig er t s)
  (ElementConfig er2 t s2)
inputElementConfig_elementConfig ((ElementConfig EventResult t GhcjsDomSpace
  -> Identity (ElementConfig EventResult t GhcjsDomSpace))
 -> InputElementConfig EventResult t GhcjsDomSpace
 -> Identity (InputElementConfig EventResult t GhcjsDomSpace))
-> ElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
-> InputElementConfig EventResult t GhcjsDomSpace
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ElementConfig EventResult t GhcjsDomSpace
elCfg
  InputElement EventResult GhcjsDomSpace t
input <- InputElementConfig EventResult t (DomBuilderSpace m)
-> m (InputElement EventResult (DomBuilderSpace m) t)
forall t (m :: * -> *) (er :: EventTag -> *).
DomBuilder t m =>
InputElementConfig er t (DomBuilderSpace m)
-> m (InputElement er (DomBuilderSpace m) t)
inputElement InputElementConfig EventResult t (DomBuilderSpace m)
InputElementConfig EventResult t GhcjsDomSpace
cfg
  FileInput GhcjsDomSpace t -> m (FileInput GhcjsDomSpace t)
forall (m :: * -> *) a. Monad m => a -> m a
return (FileInput GhcjsDomSpace t -> m (FileInput GhcjsDomSpace t))
-> FileInput GhcjsDomSpace t -> m (FileInput GhcjsDomSpace t)
forall a b. (a -> b) -> a -> b
$ FileInput :: forall k k (d :: k) (t :: k).
Dynamic t [File] -> RawInputElement d -> FileInput d t
FileInput
    { _fileInput_value :: Dynamic t [File]
_fileInput_value = InputElement EventResult GhcjsDomSpace t -> Dynamic t [File]
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t [File]
_inputElement_files InputElement EventResult GhcjsDomSpace t
input
    , _fileInput_element :: RawInputElement GhcjsDomSpace
_fileInput_element = InputElement EventResult GhcjsDomSpace t
-> RawInputElement GhcjsDomSpace
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> RawInputElement d
_inputElement_raw InputElement EventResult GhcjsDomSpace t
input
    }

data Dropdown t k
    = Dropdown { Dropdown t k -> Dynamic t k
_dropdown_value :: Dynamic t k
               , Dropdown t k -> Event t k
_dropdown_change :: Event t k
               }

data DropdownConfig t k
   = DropdownConfig { DropdownConfig t k -> Event t k
_dropdownConfig_setValue :: Event t k
                    , DropdownConfig t k -> Dynamic t (Map Text Text)
_dropdownConfig_attributes :: Dynamic t (Map Text Text)
                    }

instance Reflex t => Default (DropdownConfig t k) where
  def :: DropdownConfig t k
def = DropdownConfig :: forall k (t :: k) k.
Event t k -> Dynamic t (Map Text Text) -> DropdownConfig t k
DropdownConfig { _dropdownConfig_setValue :: Event t k
_dropdownConfig_setValue = Event t k
forall k (t :: k) a. Reflex t => Event t a
never
                       , _dropdownConfig_attributes :: Dynamic t (Map Text Text)
_dropdownConfig_attributes = Map Text Text -> Dynamic t (Map Text Text)
forall k (t :: k) a. Reflex t => a -> Dynamic t a
constDyn Map Text Text
forall a. Monoid a => a
mempty
                       }

type family DropdownViewEventResultType (en :: EventTag) :: * where
  DropdownViewEventResultType 'ChangeTag = Text
  DropdownViewEventResultType t = EventResultType t

newtype DropdownViewEventResult en = DropdownViewEventResult { DropdownViewEventResult en -> DropdownViewEventResultType en
unDropdownViewEventResult :: DropdownViewEventResultType en }

regularToDropdownViewEventType :: EventName t -> EventResultType t -> DropdownViewEventResultType t
regularToDropdownViewEventType :: EventName t -> EventResultType t -> DropdownViewEventResultType t
regularToDropdownViewEventType en :: EventName t
en r :: EventResultType t
r = case EventName t
en of
  Change -> String -> Text
forall a. HasCallStack => String -> a
error "regularToDropdownViewEventType: EventName Change should never be encountered"
  Abort -> EventResultType t
DropdownViewEventResultType t
r
  Blur -> EventResultType t
DropdownViewEventResultType t
r
  Click -> EventResultType t
DropdownViewEventResultType t
r
  Contextmenu -> EventResultType t
DropdownViewEventResultType t
r
  Dblclick -> EventResultType t
DropdownViewEventResultType t
r
  Drag -> EventResultType t
DropdownViewEventResultType t
r
  Dragend -> EventResultType t
DropdownViewEventResultType t
r
  Dragenter -> EventResultType t
DropdownViewEventResultType t
r
  Dragleave -> EventResultType t
DropdownViewEventResultType t
r
  Dragover -> EventResultType t
DropdownViewEventResultType t
r
  Dragstart -> EventResultType t
DropdownViewEventResultType t
r
  Drop -> EventResultType t
DropdownViewEventResultType t
r
  Error -> EventResultType t
DropdownViewEventResultType t
r
  Focus -> EventResultType t
DropdownViewEventResultType t
r
  Input -> EventResultType t
DropdownViewEventResultType t
r
  Invalid -> EventResultType t
DropdownViewEventResultType t
r
  Keydown -> EventResultType t
DropdownViewEventResultType t
r
  Keypress -> EventResultType t
DropdownViewEventResultType t
r
  Keyup -> EventResultType t
DropdownViewEventResultType t
r
  Load -> EventResultType t
DropdownViewEventResultType t
r
  Mousedown -> EventResultType t
DropdownViewEventResultType t
r
  Mouseenter -> EventResultType t
DropdownViewEventResultType t
r
  Mouseleave -> EventResultType t
DropdownViewEventResultType t
r
  Mousemove -> EventResultType t
DropdownViewEventResultType t
r
  Mouseout -> EventResultType t
DropdownViewEventResultType t
r
  Mouseover -> EventResultType t
DropdownViewEventResultType t
r
  Mouseup -> EventResultType t
DropdownViewEventResultType t
r
  Mousewheel -> EventResultType t
DropdownViewEventResultType t
r
  Scroll -> EventResultType t
DropdownViewEventResultType t
r
  Select -> EventResultType t
DropdownViewEventResultType t
r
  Submit -> EventResultType t
DropdownViewEventResultType t
r
  Wheel -> EventResultType t
DropdownViewEventResultType t
r
  Beforecut -> EventResultType t
DropdownViewEventResultType t
r
  Cut -> EventResultType t
DropdownViewEventResultType t
r
  Beforecopy -> EventResultType t
DropdownViewEventResultType t
r
  Copy -> EventResultType t
DropdownViewEventResultType t
r
  Beforepaste -> EventResultType t
DropdownViewEventResultType t
r
  Paste -> EventResultType t
DropdownViewEventResultType t
r
  Reset -> EventResultType t
DropdownViewEventResultType t
r
  Search -> EventResultType t
DropdownViewEventResultType t
r
  Selectstart -> EventResultType t
DropdownViewEventResultType t
r
  Touchstart -> EventResultType t
DropdownViewEventResultType t
r
  Touchmove -> EventResultType t
DropdownViewEventResultType t
r
  Touchend -> EventResultType t
DropdownViewEventResultType t
r
  Touchcancel -> EventResultType t
DropdownViewEventResultType t
r

--TODO: We should allow the user to specify an ordering instead of relying on the ordering of the Map
-- | Create a dropdown box
--   The first argument gives the initial value of the dropdown; if it is not present in the map of options provided, it will be added with an empty string as its text
dropdown :: forall k t m. (DomBuilder t m, MonadFix m, MonadHold t m, PostBuild t m, Ord k) => k -> Dynamic t (Map k Text) -> DropdownConfig t k -> m (Dropdown t k)
dropdown :: k
-> Dynamic t (Map k Text) -> DropdownConfig t k -> m (Dropdown t k)
dropdown k0 :: k
k0 options :: Dynamic t (Map k Text)
options (DropdownConfig setK :: Event t k
setK attrs :: Dynamic t (Map Text Text)
attrs) = do
  Dynamic t (Map k Text)
optionsWithAddedKeys <- (Dynamic t (Map k Text) -> Dynamic t (Map k Text))
-> m (Dynamic t (Map k Text)) -> m (Dynamic t (Map k Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Map k Text -> Map k Text -> Map k Text)
-> Dynamic t (Map k Text)
-> Dynamic t (Map k Text)
-> Dynamic t (Map k Text)
forall k (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith Map k Text -> Map k Text -> Map k Text
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union Dynamic t (Map k Text)
options) (m (Dynamic t (Map k Text)) -> m (Dynamic t (Map k Text)))
-> m (Dynamic t (Map k Text)) -> m (Dynamic t (Map k Text))
forall a b. (a -> b) -> a -> b
$ (Map k Text -> Map k Text -> Map k Text)
-> Map k Text -> Event t (Map k Text) -> m (Dynamic t (Map k Text))
forall k (t :: k) (m :: * -> *) a b.
(Reflex t, MonadHold t m, MonadFix m) =>
(a -> b -> b) -> b -> Event t a -> m (Dynamic t b)
foldDyn Map k Text -> Map k Text -> Map k Text
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union (k
Index (Map k Text)
k0 Index (Map k Text) -> IxValue (Map k Text) -> Map k Text
forall m. (At m, Monoid m) => Index m -> IxValue m -> m
=: "") (Event t (Map k Text) -> m (Dynamic t (Map k Text)))
-> Event t (Map k Text) -> m (Dynamic t (Map k Text))
forall a b. (a -> b) -> a -> b
$ (k -> Map k Text) -> Event t k -> Event t (Map k Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Index (Map k Text) -> IxValue (Map k Text) -> Map k Text
forall m. (At m, Monoid m) => Index m -> IxValue m -> m
=: "") Event t k
setK
  Dynamic t k
defaultKey <- k -> Event t k -> m (Dynamic t k)
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn k
k0 Event t k
setK
  let (indexedOptions :: Dynamic t (Map (KeyCode, k) Text)
indexedOptions, ixKeys :: Dynamic t (Bimap KeyCode k)
ixKeys) = Dynamic t (Map (KeyCode, k) Text, Bimap KeyCode k)
-> (Dynamic t (Map (KeyCode, k) Text), Dynamic t (Bimap KeyCode k))
forall k (t :: k) a b.
Reflex t =>
Dynamic t (a, b) -> (Dynamic t a, Dynamic t b)
splitDynPure (Dynamic t (Map (KeyCode, k) Text, Bimap KeyCode k)
 -> (Dynamic t (Map (KeyCode, k) Text),
     Dynamic t (Bimap KeyCode k)))
-> Dynamic t (Map (KeyCode, k) Text, Bimap KeyCode k)
-> (Dynamic t (Map (KeyCode, k) Text), Dynamic t (Bimap KeyCode k))
forall a b. (a -> b) -> a -> b
$ Dynamic t (Map k Text)
-> (Map k Text -> (Map (KeyCode, k) Text, Bimap KeyCode k))
-> Dynamic t (Map (KeyCode, k) Text, Bimap KeyCode k)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Dynamic t (Map k Text)
optionsWithAddedKeys ((Map k Text -> (Map (KeyCode, k) Text, Bimap KeyCode k))
 -> Dynamic t (Map (KeyCode, k) Text, Bimap KeyCode k))
-> (Map k Text -> (Map (KeyCode, k) Text, Bimap KeyCode k))
-> Dynamic t (Map (KeyCode, k) Text, Bimap KeyCode k)
forall a b. (a -> b) -> a -> b
$ \os :: Map k Text
os ->
        let xs :: [((KeyCode, k), ((KeyCode, k), Text))]
xs = ((KeyCode, (k, Text)) -> ((KeyCode, k), ((KeyCode, k), Text)))
-> [(KeyCode, (k, Text))] -> [((KeyCode, k), ((KeyCode, k), Text))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(ix :: KeyCode
ix, (k :: k
k, v :: Text
v)) -> ((KeyCode
ix, k
k), ((KeyCode
ix, k
k), Text
v))) ([(KeyCode, (k, Text))] -> [((KeyCode, k), ((KeyCode, k), Text))])
-> [(KeyCode, (k, Text))] -> [((KeyCode, k), ((KeyCode, k), Text))]
forall a b. (a -> b) -> a -> b
$ [KeyCode] -> [(k, Text)] -> [(KeyCode, (k, Text))]
forall a b. [a] -> [b] -> [(a, b)]
zip [0::Int ..] ([(k, Text)] -> [(KeyCode, (k, Text))])
-> [(k, Text)] -> [(KeyCode, (k, Text))]
forall a b. (a -> b) -> a -> b
$ Map k Text -> [(k, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map k Text
os
        in ([((KeyCode, k), Text)] -> Map (KeyCode, k) Text
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([((KeyCode, k), Text)] -> Map (KeyCode, k) Text)
-> [((KeyCode, k), Text)] -> Map (KeyCode, k) Text
forall a b. (a -> b) -> a -> b
$ (((KeyCode, k), ((KeyCode, k), Text)) -> ((KeyCode, k), Text))
-> [((KeyCode, k), ((KeyCode, k), Text))] -> [((KeyCode, k), Text)]
forall a b. (a -> b) -> [a] -> [b]
map ((KeyCode, k), ((KeyCode, k), Text)) -> ((KeyCode, k), Text)
forall a b. (a, b) -> b
snd [((KeyCode, k), ((KeyCode, k), Text))]
xs, [(KeyCode, k)] -> Bimap KeyCode k
forall a b. (Ord a, Ord b) => [(a, b)] -> Bimap a b
Bimap.fromList ([(KeyCode, k)] -> Bimap KeyCode k)
-> [(KeyCode, k)] -> Bimap KeyCode k
forall a b. (a -> b) -> a -> b
$ (((KeyCode, k), ((KeyCode, k), Text)) -> (KeyCode, k))
-> [((KeyCode, k), ((KeyCode, k), Text))] -> [(KeyCode, k)]
forall a b. (a -> b) -> [a] -> [b]
map ((KeyCode, k), ((KeyCode, k), Text)) -> (KeyCode, k)
forall a b. (a, b) -> a
fst [((KeyCode, k), ((KeyCode, k), Text))]
xs)
  Event t (Map Text (Maybe Text))
modifyAttrs <- Dynamic t (Map Text Text) -> m (Event t (Map Text (Maybe Text)))
forall k t (m :: * -> *).
(Ord k, PostBuild t m) =>
Dynamic t (Map k Text) -> m (Event t (Map k (Maybe Text)))
dynamicAttributesToModifyAttributes Dynamic t (Map Text Text)
attrs
  Event t ()
postBuild <- m (Event t ())
forall t (m :: * -> *). PostBuild t m => m (Event t ())
getPostBuild
  let setSelection :: Event t KeyCode
setSelection = (Bimap KeyCode k -> k -> Maybe KeyCode)
-> Dynamic t (Bimap KeyCode k) -> Event t k -> Event t KeyCode
forall k (t :: k) a b c.
Reflex t =>
(a -> b -> Maybe c) -> Dynamic t a -> Event t b -> Event t c
attachPromptlyDynWithMaybe ((k -> Bimap KeyCode k -> Maybe KeyCode)
-> Bimap KeyCode k -> k -> Maybe KeyCode
forall a b c. (a -> b -> c) -> b -> a -> c
flip k -> Bimap KeyCode k -> Maybe KeyCode
forall a b (m :: * -> *).
(Ord a, Ord b, MonadThrow m) =>
b -> Bimap a b -> m a
Bimap.lookupR) Dynamic t (Bimap KeyCode k)
ixKeys (Event t k -> Event t KeyCode) -> Event t k -> Event t KeyCode
forall a b. (a -> b) -> a -> b
$
        [Event t k] -> Event t k
forall k (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [Event t k
setK, k
k0 k -> Event t () -> Event t k
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Event t ()
postBuild]
  let cfg :: SelectElementConfig EventResult t (DomBuilderSpace m)
cfg = SelectElementConfig EventResult t (DomBuilderSpace m)
forall a. Default a => a
def
        SelectElementConfig EventResult t (DomBuilderSpace m)
-> (SelectElementConfig EventResult t (DomBuilderSpace m)
    -> SelectElementConfig EventResult t (DomBuilderSpace m))
-> SelectElementConfig EventResult t (DomBuilderSpace m)
forall a b. a -> (a -> b) -> b
& (ElementConfig EventResult t (DomBuilderSpace m)
 -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
-> SelectElementConfig EventResult t (DomBuilderSpace m)
-> Identity (SelectElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 k3 (er1 :: EventTag -> *) (t :: k1) (m1 :: k2)
       (er2 :: EventTag -> *) (m2 :: k3).
Lens
  (SelectElementConfig er1 t m1)
  (SelectElementConfig er2 t m2)
  (ElementConfig er1 t m1)
  (ElementConfig er2 t m2)
selectElementConfig_elementConfig ((ElementConfig EventResult t (DomBuilderSpace m)
  -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
 -> SelectElementConfig EventResult t (DomBuilderSpace m)
 -> Identity
      (SelectElementConfig EventResult t (DomBuilderSpace m)))
-> ((Event t (Map AttributeName (Maybe Text))
     -> Identity (Event t (Map AttributeName (Maybe Text))))
    -> ElementConfig EventResult t (DomBuilderSpace m)
    -> Identity (ElementConfig EventResult t (DomBuilderSpace m)))
-> (Event t (Map AttributeName (Maybe Text))
    -> Identity (Event t (Map AttributeName (Maybe Text))))
-> SelectElementConfig EventResult t (DomBuilderSpace m)
-> Identity (SelectElementConfig EventResult t (DomBuilderSpace m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Event t (Map AttributeName (Maybe Text))
 -> Identity (Event t (Map AttributeName (Maybe Text))))
-> ElementConfig EventResult t (DomBuilderSpace m)
-> Identity (ElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens'
  (ElementConfig er t m) (Event t (Map AttributeName (Maybe Text)))
elementConfig_modifyAttributes ((Event t (Map AttributeName (Maybe Text))
  -> Identity (Event t (Map AttributeName (Maybe Text))))
 -> SelectElementConfig EventResult t (DomBuilderSpace m)
 -> Identity
      (SelectElementConfig EventResult t (DomBuilderSpace m)))
-> Event t (Map AttributeName (Maybe Text))
-> SelectElementConfig EventResult t (DomBuilderSpace m)
-> SelectElementConfig EventResult t (DomBuilderSpace m)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Map Text (Maybe Text) -> Map AttributeName (Maybe Text))
-> Event t (Map Text (Maybe Text))
-> Event t (Map AttributeName (Maybe Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map Text (Maybe Text) -> Map AttributeName (Maybe Text)
forall v. Map Text v -> Map AttributeName v
mapKeysToAttributeName Event t (Map Text (Maybe Text))
modifyAttrs
        SelectElementConfig EventResult t (DomBuilderSpace m)
-> (SelectElementConfig EventResult t (DomBuilderSpace m)
    -> SelectElementConfig EventResult t (DomBuilderSpace m))
-> SelectElementConfig EventResult t (DomBuilderSpace m)
forall a b. a -> (a -> b) -> b
& (Event t Text -> Identity (Event t Text))
-> SelectElementConfig EventResult t (DomBuilderSpace m)
-> Identity (SelectElementConfig EventResult t (DomBuilderSpace m))
forall k1 k2 (t :: k1) (er :: EventTag -> *) (m :: k2).
Reflex t =>
Lens' (SelectElementConfig er t m) (Event t Text)
selectElementConfig_setValue ((Event t Text -> Identity (Event t Text))
 -> SelectElementConfig EventResult t (DomBuilderSpace m)
 -> Identity
      (SelectElementConfig EventResult t (DomBuilderSpace m)))
-> Event t Text
-> SelectElementConfig EventResult t (DomBuilderSpace m)
-> SelectElementConfig EventResult t (DomBuilderSpace m)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (KeyCode -> Text) -> Event t KeyCode -> Event t Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (String -> Text
T.pack (String -> Text) -> (KeyCode -> String) -> KeyCode -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KeyCode -> String
forall a. Show a => a -> String
show) Event t KeyCode
setSelection
  (eRaw :: SelectElement EventResult (DomBuilderSpace m) t
eRaw, _) <- SelectElementConfig EventResult t (DomBuilderSpace m)
-> m (Dynamic t (Map (KeyCode, k) ()))
-> m (SelectElement EventResult (DomBuilderSpace m) t,
      Dynamic t (Map (KeyCode, k) ()))
forall t (m :: * -> *) (er :: EventTag -> *) a.
DomBuilder t m =>
SelectElementConfig er t (DomBuilderSpace m)
-> m a -> m (SelectElement er (DomBuilderSpace m) t, a)
selectElement SelectElementConfig EventResult t (DomBuilderSpace m)
cfg (m (Dynamic t (Map (KeyCode, k) ()))
 -> m (SelectElement EventResult (DomBuilderSpace m) t,
       Dynamic t (Map (KeyCode, k) ())))
-> m (Dynamic t (Map (KeyCode, k) ()))
-> m (SelectElement EventResult (DomBuilderSpace m) t,
      Dynamic t (Map (KeyCode, k) ()))
forall a b. (a -> b) -> a -> b
$ Dynamic t (Map (KeyCode, k) Text)
-> ((KeyCode, k) -> Dynamic t Text -> m ())
-> m (Dynamic t (Map (KeyCode, k) ()))
forall t k v (m :: * -> *) a.
(Ord k, Adjustable t m, PostBuild t m, MonadFix m,
 MonadHold t m) =>
Dynamic t (Map k v)
-> (k -> Dynamic t v -> m a) -> m (Dynamic t (Map k a))
listWithKey Dynamic t (Map (KeyCode, k) Text)
indexedOptions (((KeyCode, k) -> Dynamic t Text -> m ())
 -> m (Dynamic t (Map (KeyCode, k) ())))
-> ((KeyCode, k) -> Dynamic t Text -> m ())
-> m (Dynamic t (Map (KeyCode, k) ()))
forall a b. (a -> b) -> a -> b
$ \(ix :: KeyCode
ix, k :: k
k) v :: Dynamic t Text
v -> do
    let optionAttrs :: Dynamic t (Map Text Text)
optionAttrs = (k -> Map Text Text) -> Dynamic t k -> Dynamic t (Map Text Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\dk :: k
dk -> "value" Index (Map Text Text) -> IxValue (Map Text Text) -> Map Text Text
forall m. (At m, Monoid m) => Index m -> IxValue m -> m
=: String -> Text
T.pack (KeyCode -> String
forall a. Show a => a -> String
show KeyCode
ix) Map Text Text -> Map Text Text -> Map Text Text
forall a. Semigroup a => a -> a -> a
<> if k
dk k -> k -> Bool
forall a. Eq a => a -> a -> Bool
== k
k then "selected" Index (Map Text Text) -> IxValue (Map Text Text) -> Map Text Text
forall m. (At m, Monoid m) => Index m -> IxValue m -> m
=: "selected" else Map Text Text
forall a. Monoid a => a
mempty) Dynamic t k
defaultKey
    Text -> Dynamic t (Map Text Text) -> m () -> m ()
forall t (m :: * -> *) a.
(DomBuilder t m, PostBuild t m) =>
Text -> Dynamic t (Map Text Text) -> m a -> m a
elDynAttr "option" Dynamic t (Map Text Text)
optionAttrs (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ Dynamic t Text -> m ()
forall t (m :: * -> *).
(PostBuild t m, DomBuilder t m) =>
Dynamic t Text -> m ()
dynText Dynamic t Text
v
  let lookupSelected :: Bimap a b -> Text -> Maybe b
lookupSelected ks :: Bimap a b
ks v :: Text
v = do
        a
key <- String -> Maybe a
forall a. Read a => String -> Maybe a
T.readMaybe (String -> Maybe a) -> String -> Maybe a
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
v
        a -> Bimap a b -> Maybe b
forall a b (m :: * -> *).
(Ord a, Ord b, MonadThrow m) =>
a -> Bimap a b -> m b
Bimap.lookup a
key Bimap a b
ks
  let eChange :: Event t (Maybe k)
eChange = (Bimap KeyCode k -> Text -> Maybe k)
-> Dynamic t (Bimap KeyCode k) -> Event t Text -> Event t (Maybe k)
forall k (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Event t b -> Event t c
attachPromptlyDynWith Bimap KeyCode k -> Text -> Maybe k
forall a b. (Read a, Ord a, Ord b) => Bimap a b -> Text -> Maybe b
lookupSelected Dynamic t (Bimap KeyCode k)
ixKeys (Event t Text -> Event t (Maybe k))
-> Event t Text -> Event t (Maybe k)
forall a b. (a -> b) -> a -> b
$ SelectElement EventResult (DomBuilderSpace m) t -> Event t Text
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
SelectElement er d t -> Event t Text
_selectElement_change SelectElement EventResult (DomBuilderSpace m) t
eRaw
  let readKey :: Bimap KeyCode k -> Maybe k -> k
readKey keys :: Bimap KeyCode k
keys mk :: Maybe k
mk = k -> Maybe k -> k
forall a. a -> Maybe a -> a
fromMaybe k
k0 (Maybe k -> k) -> Maybe k -> k
forall a b. (a -> b) -> a -> b
$ do
        k
k <- Maybe k
mk
        Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ k -> Bimap KeyCode k -> Bool
forall a b. (Ord a, Ord b) => b -> Bimap a b -> Bool
Bimap.memberR k
k Bimap KeyCode k
keys
        k -> Maybe k
forall (m :: * -> *) a. Monad m => a -> m a
return k
k
  Dynamic t k
dValue <- (Dynamic t (Maybe k) -> Dynamic t k)
-> m (Dynamic t (Maybe k)) -> m (Dynamic t k)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Bimap KeyCode k -> Maybe k -> k)
-> Dynamic t (Bimap KeyCode k)
-> Dynamic t (Maybe k)
-> Dynamic t k
forall k (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Dynamic t b -> Dynamic t c
zipDynWith Bimap KeyCode k -> Maybe k -> k
readKey Dynamic t (Bimap KeyCode k)
ixKeys) (m (Dynamic t (Maybe k)) -> m (Dynamic t k))
-> m (Dynamic t (Maybe k)) -> m (Dynamic t k)
forall a b. (a -> b) -> a -> b
$ Maybe k -> Event t (Maybe k) -> m (Dynamic t (Maybe k))
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn (k -> Maybe k
forall a. a -> Maybe a
Just k
k0) (Event t (Maybe k) -> m (Dynamic t (Maybe k)))
-> Event t (Maybe k) -> m (Dynamic t (Maybe k))
forall a b. (a -> b) -> a -> b
$ [Event t (Maybe k)] -> Event t (Maybe k)
forall k (t :: k) a. Reflex t => [Event t a] -> Event t a
leftmost [Event t (Maybe k)
eChange, (k -> Maybe k) -> Event t k -> Event t (Maybe k)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap k -> Maybe k
forall a. a -> Maybe a
Just Event t k
setK]
  Dropdown t k -> m (Dropdown t k)
forall (m :: * -> *) a. Monad m => a -> m a
return (Dropdown t k -> m (Dropdown t k))
-> Dropdown t k -> m (Dropdown t k)
forall a b. (a -> b) -> a -> b
$ Dynamic t k -> Event t k -> Dropdown t k
forall k (t :: k) k. Dynamic t k -> Event t k -> Dropdown t k
Dropdown Dynamic t k
dValue ((Bimap KeyCode k -> Maybe k -> k)
-> Dynamic t (Bimap KeyCode k) -> Event t (Maybe k) -> Event t k
forall k (t :: k) a b c.
Reflex t =>
(a -> b -> c) -> Dynamic t a -> Event t b -> Event t c
attachPromptlyDynWith Bimap KeyCode k -> Maybe k -> k
readKey Dynamic t (Bimap KeyCode k)
ixKeys Event t (Maybe k)
eChange)

#ifdef USE_TEMPLATE_HASKELL
concat <$> mapM makeLenses
  [ ''TextAreaConfig
  , ''TextArea
  , ''TextInputConfig
  , ''TextInput
  , ''RangeInputConfig
  , ''RangeInput
  , ''FileInputConfig
  , ''FileInput
  , ''DropdownConfig
  , ''Dropdown
  , ''CheckboxConfig
  , ''Checkbox
  ]
#else
textAreaConfig_attributes :: Lens' (TextAreaConfig t) (Dynamic t (Map Text Text))
textAreaConfig_attributes f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig x1 x2 y) <$> f x3
{-# INLINE textAreaConfig_attributes #-}
textAreaConfig_initialValue :: Lens' (TextAreaConfig t) Text
textAreaConfig_initialValue f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig y x2 x3) <$> f x1
{-# INLINE textAreaConfig_initialValue #-}
textAreaConfig_setValue :: Lens' (TextAreaConfig t) (Event t Text)
textAreaConfig_setValue f (TextAreaConfig x1 x2 x3) = (\y -> TextAreaConfig x1 y x3) <$> f x2
{-# INLINE textAreaConfig_setValue #-}
textArea_element :: Lens' (TextArea t) HTMLTextAreaElement
textArea_element f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 x2 x3 x4 y) <$> f x5
{-# INLINE textArea_element #-}
textArea_hasFocus :: Lens' (TextArea t) (Dynamic t Bool)
textArea_hasFocus f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 x2 y x4 x5) <$> f x3
{-# INLINE textArea_hasFocus #-}
textArea_input :: Lens' (TextArea t) (Event t Text)
textArea_input f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 y x3 x4 x5) <$> f x2
{-# INLINE textArea_input #-}
textArea_keypress :: Lens' (TextArea t) (Event t Word)
textArea_keypress f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea x1 x2 x3 y x5) <$> f x4
{-# INLINE textArea_keypress #-}
textArea_value :: Lens' (TextArea t) (Dynamic t Text)
textArea_value f (TextArea x1 x2 x3 x4 x5) = (\y -> TextArea y x2 x3 x4 x5) <$> f x1
{-# INLINE textArea_value #-}
textInputConfig_attributes :: Lens' (TextInputConfig t) (Dynamic t (Map Text Text))
textInputConfig_attributes f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig x1 x2 x3 y) <$> f x4
{-# INLINE textInputConfig_attributes #-}
textInputConfig_initialValue :: Lens' (TextInputConfig t) Text
textInputConfig_initialValue f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig x1 y x3 x4) <$> f x2
{-# INLINE textInputConfig_initialValue #-}
textInputConfig_inputType :: Lens' (TextInputConfig t) Text
textInputConfig_inputType f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig y x2 x3 x4) <$> f x1
{-# INLINE textInputConfig_inputType #-}
textInputConfig_setValue :: Lens' (TextInputConfig t) (Event t Text)
textInputConfig_setValue f (TextInputConfig x1 x2 x3 x4) = (\y -> TextInputConfig x1 x2 y x4) <$> f x3
{-# INLINE textInputConfig_setValue #-}
textInput_builderElement :: Lens' (TextInput t) (InputElement EventResult GhcjsDomSpace t)
textInput_builderElement f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 x4 x5 x6 y) <$> f x7
{-# INLINE textInput_builderElement #-}
textInput_hasFocus :: Lens' (TextInput t) (Dynamic t Bool)
textInput_hasFocus f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 x4 x5 y x7) <$> f x6
{-# INLINE textInput_hasFocus #-}
textInput_input :: Lens' (TextInput t) (Event t Text)
textInput_input f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 y x3 x4 x5 x6 x7) <$> f x2
{-# INLINE textInput_input #-}
textInput_keydown :: Lens' (TextInput t) (Event t Word)
textInput_keydown f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 y x5 x6 x7) <$> f x4
{-# INLINE textInput_keydown #-}
textInput_keypress :: Lens' (TextInput t) (Event t Word)
textInput_keypress f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 y x4 x5 x6 x7) <$> f x3
{-# INLINE textInput_keypress #-}
textInput_keyup :: Lens' (TextInput t) (Event t Word)
textInput_keyup f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput x1 x2 x3 x4 y x6 x7) <$> f x5
{-# INLINE textInput_keyup #-}
textInput_value :: Lens' (TextInput t) (Dynamic t Text)
textInput_value f (TextInput x1 x2 x3 x4 x5 x6 x7) = (\y -> TextInput y x2 x3 x4 x5 x6 x7) <$> f x1
{-# INLINE textInput_value #-}
rangeInputConfig_attributes :: Lens' (RangeInputConfig t) (Dynamic t (Map Text Text))
rangeInputConfig_attributes f (RangeInputConfig x1 x2 x3) = (\y -> RangeInputConfig x1 x2 y) <$> f x3
{-# INLINE rangeInputConfig_attributes #-}
rangeInputConfig_initialValue :: Lens' (RangeInputConfig t) Float
rangeInputConfig_initialValue f (RangeInputConfig x1 x2 x3) = (\y -> RangeInputConfig y x2 x3) <$> f x1
{-# INLINE rangeInputConfig_initialValue #-}
rangeInputConfig_setValue :: Lens' (RangeInputConfig t) (Event t Float)
rangeInputConfig_setValue f (RangeInputConfig x1 x2 x3) = (\y -> RangeInputConfig x1 y x3) <$> f x2
{-# INLINE rangeInputConfig_setValue #-}
rangeInput_element :: Lens' (RangeInput t) HTMLInputElement
rangeInput_element f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 x2 x3 x4 y) <$> f x5
{-# INLINE rangeInput_element #-}
rangeInput_hasFocus :: Lens' (RangeInput t) (Dynamic t Bool)
rangeInput_hasFocus f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 x2 x3 y x5) <$> f x4
{-# INLINE rangeInput_hasFocus #-}
rangeInput_input :: Lens' (RangeInput t) (Event t Float)
rangeInput_input f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 y x3 x4 x5) <$> f x2
{-# INLINE rangeInput_input #-}
rangeInput_mouseup :: Lens' (RangeInput t) (Event t (Int, Int))
rangeInput_mouseup f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput x1 x2 y x4 x5) <$> f x3
{-# INLINE rangeInput_mouseup #-}
rangeInput_value :: Lens' (RangeInput t) (Dynamic t Float)
rangeInput_value f (RangeInput x1 x2 x3 x4 x5) = (\y -> RangeInput y x2 x3 x4 x5) <$> f x1
{-# INLINE rangeInput_value #-}
fileInputConfig_attributes :: Iso
    (FileInputConfig t1)
    (FileInputConfig t2)
    (Dynamic t1 (Map Text Text))
    (Dynamic t2 (Map Text Text))
fileInputConfig_attributes = iso (\(FileInputConfig x) -> x) FileInputConfig
{-# INLINE fileInputConfig_attributes #-}
fileInput_element :: Lens
    (FileInput d1 t)
    (FileInput d2 t)
    (RawInputElement d1)
    (RawInputElement d2)
fileInput_element f (FileInput x1 x2) = (\y -> FileInput x1 y) <$> f x2
{-# INLINE fileInput_element #-}
fileInput_value :: Lens
    (FileInput d t1)
    (FileInput d t2)
    (Dynamic t1 [File])
    (Dynamic t2 [File])
fileInput_value f (FileInput x1 x2) = (\y -> FileInput y x2) <$> f x1
{-# INLINE fileInput_value #-}
dropdownConfig_attributes :: Lens' (DropdownConfig t k) (Dynamic t (Map Text Text))
dropdownConfig_attributes f (DropdownConfig x1 x2) = (\y -> DropdownConfig x1 y) <$> f x2
{-# INLINE dropdownConfig_attributes #-}
dropdownConfig_setValue :: Lens
    (DropdownConfig t k1)
    (DropdownConfig t k2)
    (Event t k1)
    (Event t k2)
dropdownConfig_setValue f (DropdownConfig x1 x2) = (\y -> DropdownConfig y x2) <$> f x1
{-# INLINE dropdownConfig_setValue #-}
dropdown_change :: Lens' (Dropdown t k) (Event t k)
dropdown_change f (Dropdown x1 x2) = (\y -> Dropdown x1 y) <$> f x2
{-# INLINE dropdown_change #-}
dropdown_value :: Lens' (Dropdown t k) (Dynamic t k)
dropdown_value f (Dropdown x1 x2) = (\y -> Dropdown y x2) <$> f x1
{-# INLINE dropdown_value #-}
checkboxConfig_attributes :: Lens' (CheckboxConfig t) (Dynamic t (Map Text Text))
checkboxConfig_attributes f (CheckboxConfig x1 x2) = (\y -> CheckboxConfig x1 y) <$> f x2
{-# INLINE checkboxConfig_attributes #-}
checkboxConfig_setValue :: Lens' (CheckboxConfig t) (Event t Bool)
checkboxConfig_setValue f (CheckboxConfig x1 x2) = (\y -> CheckboxConfig y x2) <$> f x1
{-# INLINE checkboxConfig_setValue #-}
checkbox_change :: Lens' (Checkbox t) (Event t Bool)
checkbox_change f (Checkbox x1 x2) = (\y -> Checkbox x1 y) <$> f x2
{-# INLINE checkbox_change #-}
checkbox_value :: Lens' (Checkbox t) (Dynamic t Bool)
checkbox_value f (Checkbox x1 x2) = (\y -> Checkbox y x2) <$> f x1
{-# INLINE checkbox_value #-}
#endif

instance HasAttributes (TextAreaConfig t) where
  type Attrs (TextAreaConfig t) = Dynamic t (Map Text Text)
  attributes :: (Attrs (TextAreaConfig t) -> f (Attrs (TextAreaConfig t)))
-> TextAreaConfig t -> f (TextAreaConfig t)
attributes = (Attrs (TextAreaConfig t) -> f (Attrs (TextAreaConfig t)))
-> TextAreaConfig t -> f (TextAreaConfig t)
forall k (t :: k).
Lens' (TextAreaConfig t) (Dynamic t (Map Text Text))
textAreaConfig_attributes

instance HasAttributes (TextInputConfig t) where
  type Attrs (TextInputConfig t) = Dynamic t (Map Text Text)
  attributes :: (Attrs (TextInputConfig t) -> f (Attrs (TextInputConfig t)))
-> TextInputConfig t -> f (TextInputConfig t)
attributes = (Attrs (TextInputConfig t) -> f (Attrs (TextInputConfig t)))
-> TextInputConfig t -> f (TextInputConfig t)
forall k (t :: k).
Lens' (TextInputConfig t) (Dynamic t (Map Text Text))
textInputConfig_attributes

instance HasAttributes (RangeInputConfig t) where
  type Attrs (RangeInputConfig t) = Dynamic t (Map Text Text)
  attributes :: (Attrs (RangeInputConfig t) -> f (Attrs (RangeInputConfig t)))
-> RangeInputConfig t -> f (RangeInputConfig t)
attributes = (Attrs (RangeInputConfig t) -> f (Attrs (RangeInputConfig t)))
-> RangeInputConfig t -> f (RangeInputConfig t)
forall k (t :: k).
Lens' (RangeInputConfig t) (Dynamic t (Map Text Text))
rangeInputConfig_attributes

instance HasAttributes (DropdownConfig t k) where
  type Attrs (DropdownConfig t k) = Dynamic t (Map Text Text)
  attributes :: (Attrs (DropdownConfig t k) -> f (Attrs (DropdownConfig t k)))
-> DropdownConfig t k -> f (DropdownConfig t k)
attributes = (Attrs (DropdownConfig t k) -> f (Attrs (DropdownConfig t k)))
-> DropdownConfig t k -> f (DropdownConfig t k)
forall k (t :: k) k.
Lens' (DropdownConfig t k) (Dynamic t (Map Text Text))
dropdownConfig_attributes

instance HasAttributes (CheckboxConfig t) where
  type Attrs (CheckboxConfig t) = Dynamic t (Map Text Text)
  attributes :: (Attrs (CheckboxConfig t) -> f (Attrs (CheckboxConfig t)))
-> CheckboxConfig t -> f (CheckboxConfig t)
attributes = (Attrs (CheckboxConfig t) -> f (Attrs (CheckboxConfig t)))
-> CheckboxConfig t -> f (CheckboxConfig t)
forall k (t :: k).
Lens' (CheckboxConfig t) (Dynamic t (Map Text Text))
checkboxConfig_attributes

instance HasAttributes (FileInputConfig t) where
  type Attrs (FileInputConfig t) = Dynamic t (Map Text Text)
  attributes :: (Attrs (FileInputConfig t) -> f (Attrs (FileInputConfig t)))
-> FileInputConfig t -> f (FileInputConfig t)
attributes = (Attrs (FileInputConfig t) -> f (Attrs (FileInputConfig t)))
-> FileInputConfig t -> f (FileInputConfig t)
forall k k (t :: k) (t :: k).
Iso
  (FileInputConfig t)
  (FileInputConfig t)
  (Dynamic t (Map Text Text))
  (Dynamic t (Map Text Text))
fileInputConfig_attributes

class HasSetValue a where
  type SetValue a :: *
  setValue :: Lens' a (SetValue a)

instance HasSetValue (TextAreaConfig t) where
  type SetValue (TextAreaConfig t) = Event t Text
  setValue :: (SetValue (TextAreaConfig t) -> f (SetValue (TextAreaConfig t)))
-> TextAreaConfig t -> f (TextAreaConfig t)
setValue = (SetValue (TextAreaConfig t) -> f (SetValue (TextAreaConfig t)))
-> TextAreaConfig t -> f (TextAreaConfig t)
forall k (t :: k). Lens' (TextAreaConfig t) (Event t Text)
textAreaConfig_setValue

instance HasSetValue (TextInputConfig t) where
  type SetValue (TextInputConfig t) = Event t Text
  setValue :: (SetValue (TextInputConfig t) -> f (SetValue (TextInputConfig t)))
-> TextInputConfig t -> f (TextInputConfig t)
setValue = (SetValue (TextInputConfig t) -> f (SetValue (TextInputConfig t)))
-> TextInputConfig t -> f (TextInputConfig t)
forall k (t :: k). Lens' (TextInputConfig t) (Event t Text)
textInputConfig_setValue

instance HasSetValue (RangeInputConfig t) where
  type SetValue (RangeInputConfig t) = Event t Float
  setValue :: (SetValue (RangeInputConfig t)
 -> f (SetValue (RangeInputConfig t)))
-> RangeInputConfig t -> f (RangeInputConfig t)
setValue = (SetValue (RangeInputConfig t)
 -> f (SetValue (RangeInputConfig t)))
-> RangeInputConfig t -> f (RangeInputConfig t)
forall k (t :: k). Lens' (RangeInputConfig t) (Event t Float)
rangeInputConfig_setValue

instance HasSetValue (DropdownConfig t k) where
  type SetValue (DropdownConfig t k) = Event t k
  setValue :: (SetValue (DropdownConfig t k)
 -> f (SetValue (DropdownConfig t k)))
-> DropdownConfig t k -> f (DropdownConfig t k)
setValue = (SetValue (DropdownConfig t k)
 -> f (SetValue (DropdownConfig t k)))
-> DropdownConfig t k -> f (DropdownConfig t k)
forall k (t :: k) k k.
Lens
  (DropdownConfig t k) (DropdownConfig t k) (Event t k) (Event t k)
dropdownConfig_setValue

instance HasSetValue (CheckboxConfig t) where
  type SetValue (CheckboxConfig t) = Event t Bool
  setValue :: (SetValue (CheckboxConfig t) -> f (SetValue (CheckboxConfig t)))
-> CheckboxConfig t -> f (CheckboxConfig t)
setValue = (SetValue (CheckboxConfig t) -> f (SetValue (CheckboxConfig t)))
-> CheckboxConfig t -> f (CheckboxConfig t)
forall k (t :: k). Lens' (CheckboxConfig t) (Event t Bool)
checkboxConfig_setValue

class HasValue a where
  type Value a :: *
  value :: a -> Value a

instance HasValue (InputElement er d t) where
  type Value (InputElement er d t) = Dynamic t Text
  value :: InputElement er d t -> Value (InputElement er d t)
value = InputElement er d t -> Value (InputElement er d t)
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
InputElement er d t -> Dynamic t Text
_inputElement_value

instance HasValue (TextAreaElement er d t) where
  type Value (TextAreaElement er d t) = Dynamic t Text
  value :: TextAreaElement er d t -> Value (TextAreaElement er d t)
value = TextAreaElement er d t -> Value (TextAreaElement er d t)
forall (er :: EventTag -> *) k1 (d :: k1) k2 (t :: k2).
TextAreaElement er d t -> Dynamic t Text
_textAreaElement_value

instance HasValue (TextArea t) where
  type Value (TextArea t) = Dynamic t Text
  value :: TextArea t -> Value (TextArea t)
value = TextArea t -> Value (TextArea t)
forall k (t :: k). TextArea t -> Dynamic t Text
_textArea_value

instance HasValue (TextInput t) where
  type Value (TextInput t) = Dynamic t Text
  value :: TextInput t -> Value (TextInput t)
value = TextInput t -> Value (TextInput t)
forall k (t :: k). TextInput t -> Dynamic t Text
_textInput_value

instance HasValue (RangeInput t) where
  type Value (RangeInput t) = Dynamic t Float
  value :: RangeInput t -> Value (RangeInput t)
value = RangeInput t -> Value (RangeInput t)
forall k (t :: k). RangeInput t -> Dynamic t Float
_rangeInput_value

instance HasValue (FileInput d t) where
  type Value (FileInput d t) = Dynamic t [File]
  value :: FileInput d t -> Value (FileInput d t)
value = FileInput d t -> Value (FileInput d t)
forall k (d :: k) k (t :: k). FileInput d t -> Dynamic t [File]
_fileInput_value

instance HasValue (Dropdown t k) where
  type Value (Dropdown t k) = Dynamic t k
  value :: Dropdown t k -> Value (Dropdown t k)
value = Dropdown t k -> Value (Dropdown t k)
forall k (t :: k) k. Dropdown t k -> Dynamic t k
_dropdown_value

instance HasValue (Checkbox t) where
  type Value (Checkbox t) = Dynamic t Bool
  value :: Checkbox t -> Value (Checkbox t)
value = Checkbox t -> Value (Checkbox t)
forall k (t :: k). Checkbox t -> Dynamic t Bool
_checkbox_value