{-# LANGUAGE OverloadedStrings #-}
module Miso.Native.X.Element.Overlay.Event
(
onDismissOverlay
, onDismissOverlayWith
, onDismissOverlayMain
, onDismissOverlayMainWith
, onError
, onErrorWith
, onErrorMain
, onErrorMainWith
, onOverlayTouch
, onOverlayTouchWith
, onOverlayTouchMain
, onOverlayTouchMainWith
, onRequestClose
, onRequestCloseWith
, onRequestCloseMain
, onRequestCloseMainWith
, onShowOverlay
, onShowOverlayWith
, onShowOverlayMain
, onShowOverlayMainWith
, OverlayErrorEvent (..)
, OverlayTouchEvent (..)
, overlayErrorDecoder
, overlayTouchDecoder
, overlayEvents
) where
import qualified Data.Map as M
import Miso.Event
import Miso.JSON
import Miso.String (MisoString)
import Miso.Types (Attribute, EventHandler, DOMRef)
overlayEvents :: Events
overlayEvents :: Events
overlayEvents
= [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (MisoString
"dismissoverlay", Phase
BUBBLE)
, (MisoString
"error", Phase
BUBBLE)
, (MisoString
"overlaytouch", Phase
BUBBLE)
, (MisoString
"requestclose", Phase
BUBBLE)
, (MisoString
"showoverlay", Phase
BUBBLE)
]
data OverlayErrorEvent
= OverlayErrorEvent
{ OverlayErrorEvent -> MisoString
errorCode :: MisoString
, OverlayErrorEvent -> MisoString
errorMsg :: MisoString
} deriving (Int -> OverlayErrorEvent -> ShowS
[OverlayErrorEvent] -> ShowS
OverlayErrorEvent -> String
(Int -> OverlayErrorEvent -> ShowS)
-> (OverlayErrorEvent -> String)
-> ([OverlayErrorEvent] -> ShowS)
-> Show OverlayErrorEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OverlayErrorEvent -> ShowS
showsPrec :: Int -> OverlayErrorEvent -> ShowS
$cshow :: OverlayErrorEvent -> String
show :: OverlayErrorEvent -> String
$cshowList :: [OverlayErrorEvent] -> ShowS
showList :: [OverlayErrorEvent] -> ShowS
Show, OverlayErrorEvent -> OverlayErrorEvent -> Bool
(OverlayErrorEvent -> OverlayErrorEvent -> Bool)
-> (OverlayErrorEvent -> OverlayErrorEvent -> Bool)
-> Eq OverlayErrorEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OverlayErrorEvent -> OverlayErrorEvent -> Bool
== :: OverlayErrorEvent -> OverlayErrorEvent -> Bool
$c/= :: OverlayErrorEvent -> OverlayErrorEvent -> Bool
/= :: OverlayErrorEvent -> OverlayErrorEvent -> Bool
Eq)
data OverlayTouchEvent
= OverlayTouchEvent
{ OverlayTouchEvent -> MisoString
touchState :: MisoString
, OverlayTouchEvent -> Double
touchX :: Double
, OverlayTouchEvent -> Double
touchY :: Double
} deriving (Int -> OverlayTouchEvent -> ShowS
[OverlayTouchEvent] -> ShowS
OverlayTouchEvent -> String
(Int -> OverlayTouchEvent -> ShowS)
-> (OverlayTouchEvent -> String)
-> ([OverlayTouchEvent] -> ShowS)
-> Show OverlayTouchEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OverlayTouchEvent -> ShowS
showsPrec :: Int -> OverlayTouchEvent -> ShowS
$cshow :: OverlayTouchEvent -> String
show :: OverlayTouchEvent -> String
$cshowList :: [OverlayTouchEvent] -> ShowS
showList :: [OverlayTouchEvent] -> ShowS
Show, OverlayTouchEvent -> OverlayTouchEvent -> Bool
(OverlayTouchEvent -> OverlayTouchEvent -> Bool)
-> (OverlayTouchEvent -> OverlayTouchEvent -> Bool)
-> Eq OverlayTouchEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OverlayTouchEvent -> OverlayTouchEvent -> Bool
== :: OverlayTouchEvent -> OverlayTouchEvent -> Bool
$c/= :: OverlayTouchEvent -> OverlayTouchEvent -> Bool
/= :: OverlayTouchEvent -> OverlayTouchEvent -> Bool
Eq)
overlayErrorDecoder :: Decoder OverlayErrorEvent
overlayErrorDecoder :: Decoder OverlayErrorEvent
overlayErrorDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser OverlayErrorEvent) -> Decoder OverlayErrorEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser OverlayErrorEvent
details
where
details :: Value -> Parser OverlayErrorEvent
details = MisoString
-> (Object -> Parser OverlayErrorEvent)
-> Value
-> Parser OverlayErrorEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser OverlayErrorEvent)
-> Value -> Parser OverlayErrorEvent)
-> (Object -> Parser OverlayErrorEvent)
-> Value
-> Parser OverlayErrorEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
MisoString -> MisoString -> OverlayErrorEvent
OverlayErrorEvent
(MisoString -> MisoString -> OverlayErrorEvent)
-> Parser MisoString -> Parser (MisoString -> OverlayErrorEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"errorCode"
Parser (MisoString -> OverlayErrorEvent)
-> Parser MisoString -> Parser OverlayErrorEvent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"errorMsg"
overlayTouchDecoder :: Decoder OverlayTouchEvent
overlayTouchDecoder :: Decoder OverlayTouchEvent
overlayTouchDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser OverlayTouchEvent) -> Decoder OverlayTouchEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser OverlayTouchEvent
details
where
details :: Value -> Parser OverlayTouchEvent
details = MisoString
-> (Object -> Parser OverlayTouchEvent)
-> Value
-> Parser OverlayTouchEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser OverlayTouchEvent)
-> Value -> Parser OverlayTouchEvent)
-> (Object -> Parser OverlayTouchEvent)
-> Value
-> Parser OverlayTouchEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
MisoString -> Double -> Double -> OverlayTouchEvent
OverlayTouchEvent
(MisoString -> Double -> Double -> OverlayTouchEvent)
-> Parser MisoString
-> Parser (Double -> Double -> OverlayTouchEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"state"
Parser (Double -> Double -> OverlayTouchEvent)
-> Parser Double -> Parser (Double -> OverlayTouchEvent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> MisoString -> Parser Double
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"x"
Parser (Double -> OverlayTouchEvent)
-> Parser Double -> Parser OverlayTouchEvent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> MisoString -> Parser Double
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"y"
onDismissOverlay :: action -> Attribute model action
onDismissOverlay :: forall action model. action -> Attribute model action
onDismissOverlay action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"dismissoverlay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onDismissOverlayMain :: action -> EventHandler model action
onDismissOverlayMain :: forall action model. action -> EventHandler model action
onDismissOverlayMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"dismissoverlay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onDismissOverlayMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onDismissOverlayMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onDismissOverlayMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"dismissoverlay" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
onError :: (OverlayErrorEvent -> action) -> Attribute model action
onError :: forall action model.
(OverlayErrorEvent -> action) -> Attribute model action
onError OverlayErrorEvent -> action
action = MisoString
-> Decoder OverlayErrorEvent
-> (OverlayErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"error" Decoder OverlayErrorEvent
overlayErrorDecoder (\OverlayErrorEvent
e model
_ DOMRef
_ -> OverlayErrorEvent -> action
action OverlayErrorEvent
e)
onErrorMain :: (OverlayErrorEvent -> action) -> EventHandler model action
onErrorMain :: forall action model.
(OverlayErrorEvent -> action) -> EventHandler model action
onErrorMain OverlayErrorEvent -> action
action = MisoString
-> Decoder OverlayErrorEvent
-> (OverlayErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"error" Decoder OverlayErrorEvent
overlayErrorDecoder (\OverlayErrorEvent
e model
_ DOMRef
_ -> OverlayErrorEvent -> action
action OverlayErrorEvent
e)
onErrorMainWith :: (OverlayErrorEvent -> model -> DOMRef -> action) -> EventHandler model action
onErrorMainWith :: forall model action.
(OverlayErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
onErrorMainWith OverlayErrorEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder OverlayErrorEvent
-> (OverlayErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"error" Decoder OverlayErrorEvent
overlayErrorDecoder OverlayErrorEvent -> model -> DOMRef -> action
action
onOverlayTouch :: (OverlayTouchEvent -> action) -> Attribute model action
onOverlayTouch :: forall action model.
(OverlayTouchEvent -> action) -> Attribute model action
onOverlayTouch OverlayTouchEvent -> action
action = MisoString
-> Decoder OverlayTouchEvent
-> (OverlayTouchEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"overlaytouch" Decoder OverlayTouchEvent
overlayTouchDecoder (\OverlayTouchEvent
e model
_ DOMRef
_ -> OverlayTouchEvent -> action
action OverlayTouchEvent
e)
onOverlayTouchMain :: (OverlayTouchEvent -> action) -> EventHandler model action
onOverlayTouchMain :: forall action model.
(OverlayTouchEvent -> action) -> EventHandler model action
onOverlayTouchMain OverlayTouchEvent -> action
action = MisoString
-> Decoder OverlayTouchEvent
-> (OverlayTouchEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"overlaytouch" Decoder OverlayTouchEvent
overlayTouchDecoder (\OverlayTouchEvent
e model
_ DOMRef
_ -> OverlayTouchEvent -> action
action OverlayTouchEvent
e)
onOverlayTouchMainWith :: (OverlayTouchEvent -> model -> DOMRef -> action) -> EventHandler model action
onOverlayTouchMainWith :: forall model action.
(OverlayTouchEvent -> model -> DOMRef -> action)
-> EventHandler model action
onOverlayTouchMainWith OverlayTouchEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder OverlayTouchEvent
-> (OverlayTouchEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"overlaytouch" Decoder OverlayTouchEvent
overlayTouchDecoder OverlayTouchEvent -> model -> DOMRef -> action
action
onRequestClose :: action -> Attribute model action
onRequestClose :: forall action model. action -> Attribute model action
onRequestClose action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"requestclose" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onRequestCloseMain :: action -> EventHandler model action
onRequestCloseMain :: forall action model. action -> EventHandler model action
onRequestCloseMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"requestclose" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onRequestCloseMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onRequestCloseMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onRequestCloseMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"requestclose" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
onShowOverlay :: action -> Attribute model action
onShowOverlay :: forall action model. action -> Attribute model action
onShowOverlay action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"showoverlay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onShowOverlayMain :: action -> EventHandler model action
onShowOverlayMain :: forall action model. action -> EventHandler model action
onShowOverlayMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"showoverlay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onShowOverlayMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onShowOverlayMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onShowOverlayMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"showoverlay" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
onDismissOverlayWith :: (DOMRef -> action) -> Attribute model action
onDismissOverlayWith :: forall action model. (DOMRef -> action) -> Attribute model action
onDismissOverlayWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"dismissoverlay" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
onErrorWith :: (OverlayErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith :: forall action model.
(OverlayErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith OverlayErrorEvent -> DOMRef -> action
action = MisoString
-> Decoder OverlayErrorEvent
-> (OverlayErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"error" Decoder OverlayErrorEvent
overlayErrorDecoder ((OverlayErrorEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (OverlayErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \OverlayErrorEvent
v model
_ DOMRef
domRef -> OverlayErrorEvent -> DOMRef -> action
action OverlayErrorEvent
v DOMRef
domRef
onOverlayTouchWith :: (OverlayTouchEvent -> DOMRef -> action) -> Attribute model action
onOverlayTouchWith :: forall action model.
(OverlayTouchEvent -> DOMRef -> action) -> Attribute model action
onOverlayTouchWith OverlayTouchEvent -> DOMRef -> action
action = MisoString
-> Decoder OverlayTouchEvent
-> (OverlayTouchEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"overlaytouch" Decoder OverlayTouchEvent
overlayTouchDecoder ((OverlayTouchEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (OverlayTouchEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \OverlayTouchEvent
v model
_ DOMRef
domRef -> OverlayTouchEvent -> DOMRef -> action
action OverlayTouchEvent
v DOMRef
domRef
onRequestCloseWith :: (DOMRef -> action) -> Attribute model action
onRequestCloseWith :: forall action model. (DOMRef -> action) -> Attribute model action
onRequestCloseWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"requestclose" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
onShowOverlayWith :: (DOMRef -> action) -> Attribute model action
onShowOverlayWith :: forall action model. (DOMRef -> action) -> Attribute model action
onShowOverlayWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"showoverlay" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)