{-# LANGUAGE OverloadedStrings #-}
module Miso.Native.Element.ScrollView.Event
(
onScroll
, onScrollWith
, onScrollMain
, onScrollMainWith
, onScrollToUpper
, onScrollToUpperWith
, onScrollToUpperMain
, onScrollToUpperMainWith
, onScrollToLower
, onScrollToLowerWith
, onScrollToLowerMain
, onScrollToLowerMainWith
, onScrollEnd
, onScrollEndWith
, onScrollEndMain
, onScrollEndMainWith
, onContentSizeChanged
, onContentSizeChangedWith
, onContentSizeChangedMain
, onContentSizeChangedMainWith
, scrollDecoder
, ScrollEvent (..)
, scrollViewEvents
) where
import qualified Data.Map as M
import Miso.Types (Attribute, EventHandler, DOMRef)
import Miso.Event
import Miso.JSON (withObject, (.:?), (.!=))
import Miso.String (MisoString)
scrollViewEvents :: Events
scrollViewEvents :: Events
scrollViewEvents
= [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (MisoString
"scroll", Phase
BUBBLE)
, (MisoString
"scrolltoupper", Phase
BUBBLE)
, (MisoString
"scrolltolower", Phase
BUBBLE)
, (MisoString
"scrollend", Phase
BUBBLE)
, (MisoString
"contentsizechanged", Phase
BUBBLE)
]
scrollDecoder :: Decoder ScrollEvent
scrollDecoder :: Decoder ScrollEvent
scrollDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser ScrollEvent) -> Decoder ScrollEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` do
MisoString
-> (Object -> Parser ScrollEvent) -> Value -> Parser ScrollEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"ScrollEvent" ((Object -> Parser ScrollEvent) -> Value -> Parser ScrollEvent)
-> (Object -> Parser ScrollEvent) -> Value -> Parser ScrollEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
MisoString
-> Double
-> Double
-> Double
-> Double
-> Double
-> Double
-> ScrollEvent
ScrollEvent
(MisoString
-> Double
-> Double
-> Double
-> Double
-> Double
-> Double
-> ScrollEvent)
-> Parser MisoString
-> Parser
(Double
-> Double -> Double -> Double -> Double -> Double -> ScrollEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser (Maybe MisoString)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"type" Parser (Maybe MisoString) -> MisoString -> Parser MisoString
forall a. Parser (Maybe a) -> a -> Parser a
.!= MisoString
""
Parser
(Double
-> Double -> Double -> Double -> Double -> Double -> ScrollEvent)
-> Parser Double
-> Parser
(Double -> Double -> Double -> Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"deltaX" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
Parser
(Double -> Double -> Double -> Double -> Double -> ScrollEvent)
-> Parser Double
-> Parser (Double -> Double -> Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"deltaY" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
Parser (Double -> Double -> Double -> Double -> ScrollEvent)
-> Parser Double
-> Parser (Double -> Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollLeft" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
Parser (Double -> Double -> Double -> ScrollEvent)
-> Parser Double -> Parser (Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollTop" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
Parser (Double -> Double -> ScrollEvent)
-> Parser Double -> Parser (Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollHeight" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
Parser (Double -> ScrollEvent)
-> Parser Double -> Parser ScrollEvent
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollWidth" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
data ScrollEvent
= ScrollEvent
{ ScrollEvent -> MisoString
scrollType :: MisoString
, ScrollEvent -> Double
deltaX, ScrollEvent -> Double
deltaY :: Double
, ScrollEvent -> Double
scrollLeft, ScrollEvent -> Double
scrollTop, ScrollEvent -> Double
scrollHeight, ScrollEvent -> Double
scrollWidth :: Double
} deriving (Int -> ScrollEvent -> ShowS
[ScrollEvent] -> ShowS
ScrollEvent -> String
(Int -> ScrollEvent -> ShowS)
-> (ScrollEvent -> String)
-> ([ScrollEvent] -> ShowS)
-> Show ScrollEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScrollEvent -> ShowS
showsPrec :: Int -> ScrollEvent -> ShowS
$cshow :: ScrollEvent -> String
show :: ScrollEvent -> String
$cshowList :: [ScrollEvent] -> ShowS
showList :: [ScrollEvent] -> ShowS
Show, ScrollEvent -> ScrollEvent -> Bool
(ScrollEvent -> ScrollEvent -> Bool)
-> (ScrollEvent -> ScrollEvent -> Bool) -> Eq ScrollEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScrollEvent -> ScrollEvent -> Bool
== :: ScrollEvent -> ScrollEvent -> Bool
$c/= :: ScrollEvent -> ScrollEvent -> Bool
/= :: ScrollEvent -> ScrollEvent -> Bool
Eq)
onScroll :: (ScrollEvent -> action) -> Attribute model action
onScroll :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScroll ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scroll" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scroll" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scroll" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
onScrollToUpper :: (ScrollEvent -> action) -> Attribute model action
onScrollToUpper :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScrollToUpper ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollToUpperMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollToUpperMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollToUpperMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollToUpperMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollToUpperMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollToUpperMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
onScrollToLower :: (ScrollEvent -> action) -> Attribute model action
onScrollToLower :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScrollToLower ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollToLowerMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollToLowerMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollToLowerMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollToLowerMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollToLowerMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollToLowerMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
onScrollEnd :: (ScrollEvent -> action) -> Attribute model action
onScrollEnd :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScrollEnd ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollEndMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollEndMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollEndMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onScrollEndMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollEndMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollEndMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
onContentSizeChanged :: (ScrollEvent -> action) -> Attribute model action
onContentSizeChanged :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onContentSizeChanged ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onContentSizeChangedMain :: (ScrollEvent -> action) -> EventHandler model action
onContentSizeChangedMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onContentSizeChangedMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
onContentSizeChangedMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onContentSizeChangedMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onContentSizeChangedMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
onScrollWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scroll" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
onScrollToUpperWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToUpperWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToUpperWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
onScrollToLowerWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToLowerWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToLowerWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
onScrollEndWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollEndWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollEndWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
onContentSizeChangedWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onContentSizeChangedWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onContentSizeChangedWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef