{-# 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
= [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (MisoString
"error", Phase
BUBBLE)
, (MisoString
"load", Phase
BUBBLE)
, (MisoString
"locationchange", Phase
BUBBLE)
, (MisoString
"message", Phase
BUBBLE)
, (MisoString
"openwindow", Phase
BUBBLE)
]
data WebviewErrorEvent
= WebviewErrorEvent
{ WebviewErrorEvent -> Int
errorCode :: Int
, WebviewErrorEvent -> MisoString
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 = [MisoString
"detail"] [MisoString]
-> (Value -> Parser WebviewErrorEvent) -> Decoder WebviewErrorEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser WebviewErrorEvent
details
where
details :: Value -> Parser WebviewErrorEvent
details = MisoString
-> (Object -> Parser WebviewErrorEvent)
-> Value
-> Parser WebviewErrorEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser WebviewErrorEvent)
-> Value -> Parser WebviewErrorEvent)
-> (Object -> Parser WebviewErrorEvent)
-> Value
-> Parser WebviewErrorEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Int -> MisoString -> WebviewErrorEvent
WebviewErrorEvent
(Int -> MisoString -> WebviewErrorEvent)
-> Parser Int -> Parser (MisoString -> WebviewErrorEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"errorCode"
Parser (MisoString -> WebviewErrorEvent)
-> Parser MisoString -> 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 -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"errorMsg"
urlDecoder :: Decoder MisoString
urlDecoder :: Decoder MisoString
urlDecoder = [MisoString
"detail"] [MisoString] -> (Value -> Parser MisoString) -> Decoder MisoString
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser MisoString
details
where
details :: Value -> Parser MisoString
details = MisoString
-> (Object -> Parser MisoString) -> Value -> Parser MisoString
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser MisoString) -> Value -> Parser MisoString)
-> (Object -> Parser MisoString) -> Value -> Parser MisoString
forall a b. (a -> b) -> a -> b
$ \Object
o -> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"url"
messageDecoder :: Decoder MisoString
messageDecoder :: Decoder MisoString
messageDecoder = [MisoString
"detail"] [MisoString] -> (Value -> Parser MisoString) -> Decoder MisoString
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser MisoString
details
where
details :: Value -> Parser MisoString
details = MisoString
-> (Object -> Parser MisoString) -> Value -> Parser MisoString
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser MisoString) -> Value -> Parser MisoString)
-> (Object -> Parser MisoString) -> Value -> Parser MisoString
forall a b. (a -> b) -> a -> b
$ \Object
o -> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"msg"
onError :: (WebviewErrorEvent -> action) -> Attribute model action
onError :: forall action model.
(WebviewErrorEvent -> action) -> Attribute model action
onError WebviewErrorEvent -> action
action = MisoString
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"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 = MisoString
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"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 = MisoString
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"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 = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onLoadMain :: action -> EventHandler model action
onLoadMain :: forall action model. action -> EventHandler model action
onLoadMain 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
"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 = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"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.
(MisoString -> action) -> Attribute model action
onLocationChange MisoString -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"locationchange" Decoder MisoString
urlDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
onLocationChangeMain :: (MisoString -> action) -> EventHandler model action
onLocationChangeMain :: forall action model.
(MisoString -> action) -> EventHandler model action
onLocationChangeMain MisoString -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"locationchange" Decoder MisoString
urlDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
onLocationChangeMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onLocationChangeMainWith :: forall model action.
(MisoString -> model -> DOMRef -> action)
-> EventHandler model action
onLocationChangeMainWith MisoString -> model -> DOMRef -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"locationchange" Decoder MisoString
urlDecoder MisoString -> model -> DOMRef -> action
action
onMessage :: (MisoString -> action) -> Attribute model action
onMessage :: forall action model.
(MisoString -> action) -> Attribute model action
onMessage MisoString -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"message" Decoder MisoString
messageDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
onMessageMain :: (MisoString -> action) -> EventHandler model action
onMessageMain :: forall action model.
(MisoString -> action) -> EventHandler model action
onMessageMain MisoString -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"message" Decoder MisoString
messageDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
onMessageMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onMessageMainWith :: forall model action.
(MisoString -> model -> DOMRef -> action)
-> EventHandler model action
onMessageMainWith MisoString -> model -> DOMRef -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"message" Decoder MisoString
messageDecoder MisoString -> model -> DOMRef -> action
action
onOpenWindow :: (MisoString -> action) -> Attribute model action
onOpenWindow :: forall action model.
(MisoString -> action) -> Attribute model action
onOpenWindow MisoString -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"openwindow" Decoder MisoString
urlDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
onOpenWindowMain :: (MisoString -> action) -> EventHandler model action
onOpenWindowMain :: forall action model.
(MisoString -> action) -> EventHandler model action
onOpenWindowMain MisoString -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"openwindow" Decoder MisoString
urlDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
onOpenWindowMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onOpenWindowMainWith :: forall model action.
(MisoString -> model -> DOMRef -> action)
-> EventHandler model action
onOpenWindowMainWith MisoString -> model -> DOMRef -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"openwindow" Decoder MisoString
urlDecoder MisoString -> 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 = MisoString
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"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 = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
onLocationChangeWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onLocationChangeWith :: forall action model.
(MisoString -> DOMRef -> action) -> Attribute model action
onLocationChangeWith MisoString -> DOMRef -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"locationchange" Decoder MisoString
urlDecoder ((MisoString -> model -> DOMRef -> action)
-> Attribute model action)
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \MisoString
v model
_ DOMRef
domRef -> MisoString -> DOMRef -> action
action MisoString
v DOMRef
domRef
onMessageWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onMessageWith :: forall action model.
(MisoString -> DOMRef -> action) -> Attribute model action
onMessageWith MisoString -> DOMRef -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"message" Decoder MisoString
messageDecoder ((MisoString -> model -> DOMRef -> action)
-> Attribute model action)
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \MisoString
v model
_ DOMRef
domRef -> MisoString -> DOMRef -> action
action MisoString
v DOMRef
domRef
onOpenWindowWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onOpenWindowWith :: forall action model.
(MisoString -> DOMRef -> action) -> Attribute model action
onOpenWindowWith MisoString -> DOMRef -> action
action = MisoString
-> Decoder MisoString
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"openwindow" Decoder MisoString
urlDecoder ((MisoString -> model -> DOMRef -> action)
-> Attribute model action)
-> (MisoString -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \MisoString
v model
_ DOMRef
domRef -> MisoString -> DOMRef -> action
action MisoString
v DOMRef
domRef