{-# LANGUAGE OverloadedStrings #-}
module Miso.Native.X.Element.Webview.Event
(
onError
, onErrorWith
, onErrorMain
, onErrorMainWith
, onLoad
, onLoadWith
, onLoadMain
, onLoadMainWith
, onLocationChange
, onLocationChangeWith
, onLocationChangeMain
, onLocationChangeMainWith
, onMessage
, onMessageWith
, onMessageMain
, onMessageMainWith
, onOpenWindow
, onOpenWindowWith
, onOpenWindowMain
, onOpenWindowMainWith
, WebviewErrorEvent (..)
, webviewErrorDecoder
, urlDecoder
, messageDecoder
, webviewEvents
) where
import qualified Data.Map as M
import Miso.Event
import Miso.JSON
import Miso.String (MisoString)
import Miso.Types (Attribute, EventHandler, DOMRef)
webviewEvents :: Events
webviewEvents :: Events
webviewEvents
= [(Text, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (Text
"error", Phase
BUBBLE)
, (Text
"load", Phase
BUBBLE)
, (Text
"locationchange", Phase
BUBBLE)
, (Text
"message", Phase
BUBBLE)
, (Text
"openwindow", Phase
BUBBLE)
]
data WebviewErrorEvent
= WebviewErrorEvent
{ WebviewErrorEvent -> Int
errorCode :: Int
, WebviewErrorEvent -> Text
errorMsg :: MisoString
} deriving (Int -> WebviewErrorEvent -> ShowS
[WebviewErrorEvent] -> ShowS
WebviewErrorEvent -> String
(Int -> WebviewErrorEvent -> ShowS)
-> (WebviewErrorEvent -> String)
-> ([WebviewErrorEvent] -> ShowS)
-> Show WebviewErrorEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WebviewErrorEvent -> ShowS
showsPrec :: Int -> WebviewErrorEvent -> ShowS
$cshow :: WebviewErrorEvent -> String
show :: WebviewErrorEvent -> String
$cshowList :: [WebviewErrorEvent] -> ShowS
showList :: [WebviewErrorEvent] -> ShowS
Show, WebviewErrorEvent -> WebviewErrorEvent -> Bool
(WebviewErrorEvent -> WebviewErrorEvent -> Bool)
-> (WebviewErrorEvent -> WebviewErrorEvent -> Bool)
-> Eq WebviewErrorEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
== :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
$c/= :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
/= :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
Eq)
webviewErrorDecoder :: Decoder WebviewErrorEvent
webviewErrorDecoder :: Decoder WebviewErrorEvent
webviewErrorDecoder = [Text
"detail"] [Text]
-> (Value -> Parser WebviewErrorEvent) -> Decoder WebviewErrorEvent
forall a. [Text] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser WebviewErrorEvent
details
where
details :: Value -> Parser WebviewErrorEvent
details = Text
-> (Object -> Parser WebviewErrorEvent)
-> Value
-> Parser WebviewErrorEvent
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withObject Text
"detail" ((Object -> Parser WebviewErrorEvent)
-> Value -> Parser WebviewErrorEvent)
-> (Object -> Parser WebviewErrorEvent)
-> Value
-> Parser WebviewErrorEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Int -> Text -> WebviewErrorEvent
WebviewErrorEvent
(Int -> Text -> WebviewErrorEvent)
-> Parser Int -> Parser (Text -> WebviewErrorEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"errorCode"
Parser (Text -> WebviewErrorEvent)
-> Parser Text -> Parser WebviewErrorEvent
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 -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"errorMsg"
urlDecoder :: Decoder MisoString
urlDecoder :: Decoder Text
urlDecoder = [Text
"detail"] [Text] -> (Value -> Parser Text) -> Decoder Text
forall a. [Text] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser Text
details
where
details :: Value -> Parser Text
details = Text -> (Object -> Parser Text) -> Value -> Parser Text
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withObject Text
"detail" ((Object -> Parser Text) -> Value -> Parser Text)
-> (Object -> Parser Text) -> Value -> Parser Text
forall a b. (a -> b) -> a -> b
$ \Object
o -> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"url"
messageDecoder :: Decoder MisoString
messageDecoder :: Decoder Text
messageDecoder = [Text
"detail"] [Text] -> (Value -> Parser Text) -> Decoder Text
forall a. [Text] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser Text
details
where
details :: Value -> Parser Text
details = Text -> (Object -> Parser Text) -> Value -> Parser Text
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withObject Text
"detail" ((Object -> Parser Text) -> Value -> Parser Text)
-> (Object -> Parser Text) -> Value -> Parser Text
forall a b. (a -> b) -> a -> b
$ \Object
o -> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"msg"
onError :: (WebviewErrorEvent -> action) -> Attribute model action
onError :: forall action model.
(WebviewErrorEvent -> action) -> Attribute model action
onError WebviewErrorEvent -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder (\WebviewErrorEvent
e model
_ DOMRef
_ -> WebviewErrorEvent -> action
action WebviewErrorEvent
e)
onErrorMain :: (WebviewErrorEvent -> action) -> EventHandler model action
onErrorMain :: forall action model.
(WebviewErrorEvent -> action) -> EventHandler model action
onErrorMain WebviewErrorEvent -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder (\WebviewErrorEvent
e model
_ DOMRef
_ -> WebviewErrorEvent -> action
action WebviewErrorEvent
e)
onErrorMainWith :: (WebviewErrorEvent -> model -> DOMRef -> action) -> EventHandler model action
onErrorMainWith :: forall model action.
(WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
onErrorMainWith WebviewErrorEvent -> model -> DOMRef -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder WebviewErrorEvent -> model -> DOMRef -> action
action
onLoad :: action -> Attribute model action
onLoad :: forall action model. action -> Attribute model action
onLoad action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onLoadMain :: action -> EventHandler model action
onLoadMain :: forall action model. action -> EventHandler model action
onLoadMain action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onLoadMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onLoadMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onLoadMainWith model -> DOMRef -> action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"load" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
onLocationChange :: (MisoString -> action) -> Attribute model action
onLocationChange :: forall action model. (Text -> action) -> Attribute model action
onLocationChange Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"locationchange" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
onLocationChangeMain :: (MisoString -> action) -> EventHandler model action
onLocationChangeMain :: forall action model. (Text -> action) -> EventHandler model action
onLocationChangeMain Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"locationchange" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
onLocationChangeMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onLocationChangeMainWith :: forall model action.
(Text -> model -> DOMRef -> action) -> EventHandler model action
onLocationChangeMainWith Text -> model -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"locationchange" Decoder Text
urlDecoder Text -> model -> DOMRef -> action
action
onMessage :: (MisoString -> action) -> Attribute model action
onMessage :: forall action model. (Text -> action) -> Attribute model action
onMessage Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"message" Decoder Text
messageDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
onMessageMain :: (MisoString -> action) -> EventHandler model action
onMessageMain :: forall action model. (Text -> action) -> EventHandler model action
onMessageMain Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"message" Decoder Text
messageDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
onMessageMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onMessageMainWith :: forall model action.
(Text -> model -> DOMRef -> action) -> EventHandler model action
onMessageMainWith Text -> model -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"message" Decoder Text
messageDecoder Text -> model -> DOMRef -> action
action
onOpenWindow :: (MisoString -> action) -> Attribute model action
onOpenWindow :: forall action model. (Text -> action) -> Attribute model action
onOpenWindow Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"openwindow" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
onOpenWindowMain :: (MisoString -> action) -> EventHandler model action
onOpenWindowMain :: forall action model. (Text -> action) -> EventHandler model action
onOpenWindowMain Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"openwindow" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
onOpenWindowMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onOpenWindowMainWith :: forall model action.
(Text -> model -> DOMRef -> action) -> EventHandler model action
onOpenWindowMainWith Text -> model -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"openwindow" Decoder Text
urlDecoder Text -> model -> DOMRef -> action
action
onErrorWith :: (WebviewErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith :: forall action model.
(WebviewErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith WebviewErrorEvent -> DOMRef -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder ((WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \WebviewErrorEvent
v model
_ DOMRef
domRef -> WebviewErrorEvent -> DOMRef -> action
action WebviewErrorEvent
v DOMRef
domRef
onLoadWith :: (DOMRef -> action) -> Attribute model action
onLoadWith :: forall action model. (DOMRef -> action) -> Attribute model action
onLoadWith DOMRef -> action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
onLocationChangeWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onLocationChangeWith :: forall action model.
(Text -> DOMRef -> action) -> Attribute model action
onLocationChangeWith Text -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"locationchange" Decoder Text
urlDecoder ((Text -> model -> DOMRef -> action) -> Attribute model action)
-> (Text -> model -> DOMRef -> action) -> Attribute model action
forall a b. (a -> b) -> a -> b
$ \Text
v model
_ DOMRef
domRef -> Text -> DOMRef -> action
action Text
v DOMRef
domRef
onMessageWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onMessageWith :: forall action model.
(Text -> DOMRef -> action) -> Attribute model action
onMessageWith Text -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"message" Decoder Text
messageDecoder ((Text -> model -> DOMRef -> action) -> Attribute model action)
-> (Text -> model -> DOMRef -> action) -> Attribute model action
forall a b. (a -> b) -> a -> b
$ \Text
v model
_ DOMRef
domRef -> Text -> DOMRef -> action
action Text
v DOMRef
domRef
onOpenWindowWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onOpenWindowWith :: forall action model.
(Text -> DOMRef -> action) -> Attribute model action
onOpenWindowWith Text -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"openwindow" Decoder Text
urlDecoder ((Text -> model -> DOMRef -> action) -> Attribute model action)
-> (Text -> model -> DOMRef -> action) -> Attribute model action
forall a b. (a -> b) -> a -> b
$ \Text
v model
_ DOMRef
domRef -> Text -> DOMRef -> action
action Text
v DOMRef
domRef