-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Html.Event
-- Copyright   :  (C) 2016-2025 David M. Johnson
-- License     :  BSD3-style (see the file LICENSE)
-- Maintainer  :  David M. Johnson <code@dmj.io>
-- Stability   :  experimental
-- Portability :  non-portable
--
----------------------------------------------------------------------------
module Miso.Html.Event
  ( -- *** Smart constructors
    on
  , onWithOptions
  -- *** Lifecycle events
  , onMounted
  , onBeforeMounted
  , onUnmounted
  , onBeforeUnmounted
  , onCreated
  , onBeforeCreated
  , onDestroyed
  , onBeforeDestroyed
   -- *** Mouse
  , onClick
  , onDoubleClick
  , onMouseDown
  , onMouseUp
  , onMouseEnter
  , onMouseLeave
  , onMouseOver
  , onMouseOut
  -- *** Keyboard
  , onKeyDown
  , onKeyDownWithInfo
  , onKeyPress
  , onKeyUp
  -- *** Form
  , onInput
  , onChange
  , onChecked
  , onSubmit
  -- *** Focus
  , onBlur
  , onFocus
  -- *** Drag
  , onDrag
  , onDragLeave
  , onDragEnter
  , onDragEnd
  , onDragStart
  , onDragOver
  -- *** Drop
  , onDrop
  -- *** Select
  , onSelect
  -- *** Pointer
  , onPointerDown
  , onPointerUp
  , onPointerEnter
  , onPointerLeave
  , onPointerOver
  , onPointerOut
  , onPointerCancel
  , onPointerMove
  ) where
-----------------------------------------------------------------------------
import           Control.Monad (when)
import qualified Data.Map.Strict as M
import           Data.Aeson.Types (parseEither)
import           Language.Javascript.JSaddle
-----------------------------------------------------------------------------
import           Miso.Event
import qualified Miso.FFI.Internal as FFI
import           Miso.Types ( Attribute (Event), LogLevel(..) )
import           Miso.String (MisoString, unpack)
-----------------------------------------------------------------------------
-- | Convenience wrapper for @onWithOptions defaultOptions@.
--
-- > let clickHandler = on "click" emptyDecoder $ \() -> Action
-- > in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]
--
on :: MisoString
   -> Decoder r
   -> (r -> action)
   -> Attribute action
on :: forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on = Options
-> MisoString -> Decoder r -> (r -> action) -> Attribute action
forall r action.
Options
-> MisoString -> Decoder r -> (r -> action) -> Attribute action
onWithOptions Options
defaultOptions
-----------------------------------------------------------------------------
-- | @onWithOptions opts eventName decoder toAction@ is an attribute
-- that will set the event handler of the associated DOM node to a function that
-- decodes its argument using @decoder@, converts it to an action
-- using @toAction@ and then feeds that action back to the @update@ function.
--
-- @opts@ can be used to disable further event propagation.
--
-- > let clickHandler = onWithOptions defaultOptions "click" emptyDecoder $ \() -> Action
-- > in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]
--
onWithOptions
  :: Options
  -> MisoString
  -> Decoder r
  -> (r -> action)
  -> Attribute action
onWithOptions :: forall r action.
Options
-> MisoString -> Decoder r -> (r -> action) -> Attribute action
onWithOptions Options
options MisoString
eventName Decoder{DecodeTarget
Value -> Parser r
decoder :: Value -> Parser r
decodeAt :: DecodeTarget
decodeAt :: forall a. Decoder a -> DecodeTarget
decoder :: forall a. Decoder a -> Value -> Parser a
..} r -> action
toAction =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
n LogLevel
logLevel Events
events ->
    case MisoString -> Events -> Maybe Capture
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup MisoString
eventName Events
events of
      Maybe Capture
Nothing ->
        Capture -> JSM () -> JSM ()
forall (f :: * -> *). Applicative f => Capture -> f () -> f ()
when (LogLevel
logLevel LogLevel -> [LogLevel] -> Capture
forall a. Eq a => a -> [a] -> Capture
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Capture
`elem` [ LogLevel
DebugAll, LogLevel
DebugEvents ]) (JSM () -> JSM ()) -> JSM () -> JSM ()
forall a b. (a -> b) -> a -> b
$
          MisoString -> JSM ()
FFI.consoleError (MisoString -> JSM ()) -> MisoString -> JSM ()
forall a b. (a -> b) -> a -> b
$ [MisoString] -> MisoString
forall a. Monoid a => [a] -> a
mconcat
            [ MisoString
"Event \""
            , MisoString
eventName
            , MisoString
"\" is not being listened on. To use this event, "
            , MisoString
"add to the 'events' Map in 'App'"
            ]
      Just Capture
_ -> do
        eventObj <- JSString -> Object -> JSM JSVal
getProp JSString
"events" Object
n
        eventHandlerObject@(Object eo) <- create
        jsOptions <- toJSVal options
        decodeAtVal <- toJSVal decodeAt
        cb <- FFI.asyncCallback1 $ \JSVal
e -> do
            Just v <- JSVal -> JSM (Maybe Value)
forall a. FromJSVal a => JSVal -> JSM (Maybe a)
fromJSVal (JSVal -> JSM (Maybe Value)) -> JSM JSVal -> JSM (Maybe Value)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< JSVal -> JSVal -> JSM JSVal
FFI.eventJSON JSVal
decodeAtVal JSVal
e
            case parseEither decoder v of
              Left [Char]
s -> [Char] -> JSM ()
forall a. HasCallStack => [Char] -> a
error ([Char] -> JSM ()) -> [Char] -> JSM ()
forall a b. (a -> b) -> a -> b
$ [Char]
"Parse error on " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> MisoString -> [Char]
unpack MisoString
eventName [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
": " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
s
              Right r
r -> Sink action
sink (r -> action
toAction r
r)
        FFI.set "runEvent" cb eventHandlerObject
        FFI.set "options" jsOptions eventHandlerObject
        FFI.set eventName eo (Object eventObj)
-----------------------------------------------------------------------------
-- | @onMounted action@ is an event that gets called after the actual DOM
-- element is created.
--
onMounted :: action -> Attribute action
onMounted :: forall action. action -> Attribute action
onMounted action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onMounted" callback object
-----------------------------------------------------------------------------
-- | @onBeforeMounted action@ is an event that gets called before the actual DOM
-- element is created.
--
onBeforeMounted :: action -> Attribute action
onBeforeMounted :: forall action. action -> Attribute action
onBeforeMounted action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onBeforeMounted" callback object
-----------------------------------------------------------------------------
-- | @onCreated action@ is an event that gets called after the actual DOM
-- element is created.
--
onCreated :: action -> Attribute action
onCreated :: forall action. action -> Attribute action
onCreated action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onCreated" callback object
-----------------------------------------------------------------------------
-- | @onDestroyed action@ is an event that gets called after the DOM element
-- is removed from the DOM. The @action@ is given the DOM element that was
-- removed from the DOM tree.
--
onDestroyed :: action -> Attribute action
onDestroyed :: forall action. action -> Attribute action
onDestroyed action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onDestroyed" callback object
-----------------------------------------------------------------------------
-- | @onUnmounted action@ is an event that gets called after the DOM element
-- is removed from the DOM.
--
onUnmounted :: action -> Attribute action
onUnmounted :: forall action. action -> Attribute action
onUnmounted action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onUnmounted" callback object
-----------------------------------------------------------------------------
-- | @onBeforeUnmounted action@ is an event that gets called before the DOM element
-- is removed from the DOM.
--
onBeforeUnmounted :: action -> Attribute action
onBeforeUnmounted :: forall action. action -> Attribute action
onBeforeUnmounted action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onBeforeUnmounted" callback object
-----------------------------------------------------------------------------
-- | @onBeforeDestroyed action@ is an event that gets called before the DOM element
-- is removed from the DOM. The @action@ is given the DOM element that was
-- removed from the DOM tree.
--
onBeforeDestroyed :: action -> Attribute action
onBeforeDestroyed :: forall action. action -> Attribute action
onBeforeDestroyed action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onBeforeDestroyed" callback object
-----------------------------------------------------------------------------
-- | @onBeforeCreated action@ is an event that gets called before the DOM element
-- is created on the DOM. The @action@ is given the DOM element that was
-- removed from the DOM tree.
--
onBeforeCreated :: action -> Attribute action
onBeforeCreated :: forall action. action -> Attribute action
onBeforeCreated action
action =
  (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall action.
(Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
Event ((Sink action -> Object -> LogLevel -> Events -> JSM ())
 -> Attribute action)
-> (Sink action -> Object -> LogLevel -> Events -> JSM ())
-> Attribute action
forall a b. (a -> b) -> a -> b
$ \Sink action
sink Object
object LogLevel
_ Events
_ -> do
    callback <- JSM () -> JSM Function
FFI.syncCallback (Sink action
sink action
action)
    FFI.set "onBeforeCreated" callback object
-----------------------------------------------------------------------------
-- | blur event defined with custom options
--
-- <https://developer.mozilla.org/en-US/docs/Web/Events/blur>
--
onBlur :: action -> Attribute action
onBlur :: forall action. action -> Attribute action
onBlur action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"blur" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/change
onChecked :: (Checked -> action) -> Attribute action
onChecked :: forall action. (Checked -> action) -> Attribute action
onChecked = MisoString
-> Decoder Checked -> (Checked -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"change" Decoder Checked
checkedDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/click
onClick :: action -> Attribute action
onClick :: forall action. action -> Attribute action
onClick action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"click" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/focus
onFocus :: action -> Attribute action
onFocus :: forall action. action -> Attribute action
onFocus action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"focus" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/dblclick
onDoubleClick :: action -> Attribute action
onDoubleClick :: forall action. action -> Attribute action
onDoubleClick action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"dblclick" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/input
onInput :: (MisoString -> action) -> Attribute action
onInput :: forall action. (MisoString -> action) -> Attribute action
onInput = MisoString
-> Decoder MisoString -> (MisoString -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"input" Decoder MisoString
valueDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/change
onChange :: (MisoString -> action) -> Attribute action
onChange :: forall action. (MisoString -> action) -> Attribute action
onChange = MisoString
-> Decoder MisoString -> (MisoString -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"change" Decoder MisoString
valueDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/select
onSelect :: (MisoString -> action) -> Attribute action
onSelect :: forall action. (MisoString -> action) -> Attribute action
onSelect = MisoString
-> Decoder MisoString -> (MisoString -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"select" Decoder MisoString
valueDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/keydown
onKeyDownWithInfo :: (KeyInfo -> action) -> Attribute action
onKeyDownWithInfo :: forall action. (KeyInfo -> action) -> Attribute action
onKeyDownWithInfo = MisoString
-> Decoder KeyInfo -> (KeyInfo -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"keydown" Decoder KeyInfo
keyInfoDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/keydown
onKeyDown :: (KeyCode -> action) -> Attribute action
onKeyDown :: forall action. (KeyCode -> action) -> Attribute action
onKeyDown = MisoString
-> Decoder KeyCode -> (KeyCode -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"keydown" Decoder KeyCode
keycodeDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/keypress
onKeyPress :: (KeyCode -> action) -> Attribute action
onKeyPress :: forall action. (KeyCode -> action) -> Attribute action
onKeyPress = MisoString
-> Decoder KeyCode -> (KeyCode -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"keypress" Decoder KeyCode
keycodeDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/keyup
onKeyUp :: (KeyCode -> action) -> Attribute action
onKeyUp :: forall action. (KeyCode -> action) -> Attribute action
onKeyUp = MisoString
-> Decoder KeyCode -> (KeyCode -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"keyup" Decoder KeyCode
keycodeDecoder
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/mouseup
onMouseUp :: action -> Attribute action
onMouseUp :: forall action. action -> Attribute action
onMouseUp action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"mouseup" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/mousedown
onMouseDown :: action -> Attribute action
onMouseDown :: forall action. action -> Attribute action
onMouseDown action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"mousedown" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/mouseenter
onMouseEnter :: action -> Attribute action
onMouseEnter :: forall action. action -> Attribute action
onMouseEnter action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"mouseenter" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/mouseleave
onMouseLeave :: action -> Attribute action
onMouseLeave :: forall action. action -> Attribute action
onMouseLeave action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"mouseleave" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/mouseover
onMouseOver :: action -> Attribute action
onMouseOver :: forall action. action -> Attribute action
onMouseOver action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"mouseover" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/mouseout
onMouseOut :: action -> Attribute action
onMouseOut :: forall action. action -> Attribute action
onMouseOut action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"mouseout" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/dragstart
onDragStart :: action -> Attribute action
onDragStart :: forall action. action -> Attribute action
onDragStart action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"dragstart" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/dragover
onDragOver :: action -> Attribute action
onDragOver :: forall action. action -> Attribute action
onDragOver action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"dragover" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/dragend
onDragEnd :: action -> Attribute action
onDragEnd :: forall action. action -> Attribute action
onDragEnd action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"dragend" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/dragenter
onDragEnter :: action -> Attribute action
onDragEnter :: forall action. action -> Attribute action
onDragEnter action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"dragenter" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/dragleave
onDragLeave :: action -> Attribute action
onDragLeave :: forall action. action -> Attribute action
onDragLeave action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"dragleave" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/drag
onDrag :: action -> Attribute action
onDrag :: forall action. action -> Attribute action
onDrag action
action = MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"drag" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/drop
onDrop :: AllowDrop -> action -> Attribute action
onDrop :: forall action. AllowDrop -> action -> Attribute action
onDrop (AllowDrop Capture
allowDrop) action
action =
  Options
-> MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
Options
-> MisoString -> Decoder r -> (r -> action) -> Attribute action
onWithOptions Options
defaultOptions { preventDefault = allowDrop }
    MisoString
"drop" Decoder ()
emptyDecoder (\() -> action
action)
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/submit
onSubmit :: action -> Attribute action
onSubmit :: forall action. action -> Attribute action
onSubmit action
action =
  Options
-> MisoString -> Decoder () -> (() -> action) -> Attribute action
forall r action.
Options
-> MisoString -> Decoder r -> (r -> action) -> Attribute action
onWithOptions Options
defaultOptions { preventDefault = True }
    MisoString
"submit" Decoder ()
emptyDecoder ((() -> action) -> Attribute action)
-> (() -> action) -> Attribute action
forall a b. (a -> b) -> a -> b
$ \() -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointerup
onPointerUp :: (PointerEvent -> action) -> Attribute action
onPointerUp :: forall action. (PointerEvent -> action) -> Attribute action
onPointerUp PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointerup" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointerdown
onPointerDown :: (PointerEvent -> action) -> Attribute action
onPointerDown :: forall action. (PointerEvent -> action) -> Attribute action
onPointerDown PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointerdown" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointerenter
onPointerEnter :: (PointerEvent -> action) -> Attribute action
onPointerEnter :: forall action. (PointerEvent -> action) -> Attribute action
onPointerEnter PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointerenter" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointerleave
onPointerLeave :: (PointerEvent -> action) -> Attribute action
onPointerLeave :: forall action. (PointerEvent -> action) -> Attribute action
onPointerLeave PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointerleave" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointerover
onPointerOver :: (PointerEvent -> action) -> Attribute action
onPointerOver :: forall action. (PointerEvent -> action) -> Attribute action
onPointerOver PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointerover" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointerout
onPointerOut :: (PointerEvent -> action) -> Attribute action
onPointerOut :: forall action. (PointerEvent -> action) -> Attribute action
onPointerOut PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointerout" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointercancel
onPointerCancel :: (PointerEvent -> action) -> Attribute action
onPointerCancel :: forall action. (PointerEvent -> action) -> Attribute action
onPointerCancel PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointercancel" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------
-- | https://developer.mozilla.org/en-US/docs/Web/Events/pointermove
onPointerMove :: (PointerEvent -> action) -> Attribute action
onPointerMove :: forall action. (PointerEvent -> action) -> Attribute action
onPointerMove PointerEvent -> action
action = MisoString
-> Decoder PointerEvent
-> (PointerEvent -> action)
-> Attribute action
forall r action.
MisoString -> Decoder r -> (r -> action) -> Attribute action
on MisoString
"pointermove" Decoder PointerEvent
pointerDecoder PointerEvent -> action
action
-----------------------------------------------------------------------------