-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Native.X.Element.Input.Event
-- Copyright   :  (C) 2016-2026 David M. Johnson
-- License     :  BSD3-style (see the file LICENSE)
-- Maintainer  :  David M. Johnson <code@dmj.io>
-- Stability   :  experimental
-- Portability :  non-portable
----------------------------------------------------------------------------
module Miso.Native.X.Element.Input.Event
  ( -- *** Events
    onBlur
  , onBlurWith
  , onBlurMain
  , onBlurMainWith
  , onConfirm
  , onConfirmWith
  , onConfirmMain
  , onConfirmMainWith
  , onFocus
  , onFocusWith
  , onFocusMain
  , onFocusMainWith
  , onInput
  , onInputWith
  , onInputMain
  , onInputMainWith
  , onSelection
  , onSelectionWith
  , onSelectionMain
  , onSelectionMainWith
    -- *** Types
  , InputEvent (..)
  , SelectionEvent (..)
    -- *** Decoders
  , inputValueDecoder
  , inputDecoder
  , selectionDecoder
    -- *** Event Map
  , inputEvents
  ) where
-----------------------------------------------------------------------------
import qualified Data.Map as M
-----------------------------------------------------------------------------
import           Miso.Event
import           Miso.JSON
import           Miso.String (MisoString)
import           Miso.Types (Attribute, EventHandler, DOMRef)
-----------------------------------------------------------------------------
inputEvents :: Events
inputEvents :: Events
inputEvents
  = [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ (MisoString
"blur", Phase
BUBBLE)
  , (MisoString
"confirm", Phase
BUBBLE)
  , (MisoString
"focus", Phase
BUBBLE)
  , (MisoString
"input", Phase
BUBBLE)
  , (MisoString
"selection", Phase
BUBBLE)
  ]
-----------------------------------------------------------------------------
-- | Payload of the @bindinput@ event.
data InputEvent
  = InputEvent
  { InputEvent -> MisoString
inputValue :: MisoString
    -- ^ The current input content
  , InputEvent -> Int
inputSelectionStart :: Int
    -- ^ Start position of the selection
  , InputEvent -> Int
inputSelectionEnd :: Int
    -- ^ End position of the selection
  , InputEvent -> Bool
inputIsComposing :: Bool
    -- ^ Whether the input is mid-composition (IME)
  } deriving (Int -> InputEvent -> ShowS
[InputEvent] -> ShowS
InputEvent -> String
(Int -> InputEvent -> ShowS)
-> (InputEvent -> String)
-> ([InputEvent] -> ShowS)
-> Show InputEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputEvent -> ShowS
showsPrec :: Int -> InputEvent -> ShowS
$cshow :: InputEvent -> String
show :: InputEvent -> String
$cshowList :: [InputEvent] -> ShowS
showList :: [InputEvent] -> ShowS
Show, InputEvent -> InputEvent -> Bool
(InputEvent -> InputEvent -> Bool)
-> (InputEvent -> InputEvent -> Bool) -> Eq InputEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputEvent -> InputEvent -> Bool
== :: InputEvent -> InputEvent -> Bool
$c/= :: InputEvent -> InputEvent -> Bool
/= :: InputEvent -> InputEvent -> Bool
Eq)
-----------------------------------------------------------------------------
-- | Payload of the @bindselection@ event.
data SelectionEvent
  = SelectionEvent
  { SelectionEvent -> Int
selStart :: Int
    -- ^ Start position of the selection
  , SelectionEvent -> Int
selEnd :: Int
    -- ^ End position of the selection
  } deriving (Int -> SelectionEvent -> ShowS
[SelectionEvent] -> ShowS
SelectionEvent -> String
(Int -> SelectionEvent -> ShowS)
-> (SelectionEvent -> String)
-> ([SelectionEvent] -> ShowS)
-> Show SelectionEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SelectionEvent -> ShowS
showsPrec :: Int -> SelectionEvent -> ShowS
$cshow :: SelectionEvent -> String
show :: SelectionEvent -> String
$cshowList :: [SelectionEvent] -> ShowS
showList :: [SelectionEvent] -> ShowS
Show, SelectionEvent -> SelectionEvent -> Bool
(SelectionEvent -> SelectionEvent -> Bool)
-> (SelectionEvent -> SelectionEvent -> Bool) -> Eq SelectionEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SelectionEvent -> SelectionEvent -> Bool
== :: SelectionEvent -> SelectionEvent -> Bool
$c/= :: SelectionEvent -> SelectionEvent -> Bool
/= :: SelectionEvent -> SelectionEvent -> Bool
Eq)
-----------------------------------------------------------------------------
-- | Decodes the @value@ field shared by @bindblur@, @bindconfirm@ and @bindfocus@.
inputValueDecoder :: Decoder MisoString
inputValueDecoder :: Decoder MisoString
inputValueDecoder = [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
"value"
-----------------------------------------------------------------------------
inputDecoder :: Decoder InputEvent
inputDecoder :: Decoder InputEvent
inputDecoder = [MisoString
"detail"] [MisoString] -> (Value -> Parser InputEvent) -> Decoder InputEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser InputEvent
details
  where
    details :: Value -> Parser InputEvent
details = MisoString
-> (Object -> Parser InputEvent) -> Value -> Parser InputEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser InputEvent) -> Value -> Parser InputEvent)
-> (Object -> Parser InputEvent) -> Value -> Parser InputEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      MisoString -> Int -> Int -> Bool -> InputEvent
InputEvent
        (MisoString -> Int -> Int -> Bool -> InputEvent)
-> Parser MisoString -> Parser (Int -> Int -> Bool -> InputEvent)
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
"value"
        Parser (Int -> Int -> Bool -> InputEvent)
-> Parser Int -> Parser (Int -> Bool -> InputEvent)
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 Int)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"selectionStart" Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= Int
0
        Parser (Int -> Bool -> InputEvent)
-> Parser Int -> Parser (Bool -> InputEvent)
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 Int)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"selectionEnd" Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= Int
0
        -- Lynx's native input sends @isComposing@ as a number (0/1), bridged
        -- from an ObjC @BOOL@ — not a JSON boolean — so decode it as an 'Int'
        -- and coerce. Absent (e.g. on the simulator's non-composing path) is
        -- 'False'. Decoding it as 'Bool' fails the whole decoder on device.
        Parser (Bool -> InputEvent) -> Parser Bool -> Parser InputEvent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> (Int -> Bool) -> Maybe Int -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= (Int
0 :: Int)) (Maybe Int -> Bool) -> Parser (Maybe Int) -> Parser Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser (Maybe Int)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"isComposing")
-----------------------------------------------------------------------------
-- Note: the JS keys stay @selectionStart@/@selectionEnd@; the record fields are
-- 'selStart'/'selEnd' to avoid clashing with 'InputValue' when the hub module
-- re-exports Event and Method together.
selectionDecoder :: Decoder SelectionEvent
selectionDecoder :: Decoder SelectionEvent
selectionDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser SelectionEvent) -> Decoder SelectionEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser SelectionEvent
details
  where
    details :: Value -> Parser SelectionEvent
details = MisoString
-> (Object -> Parser SelectionEvent)
-> Value
-> Parser SelectionEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser SelectionEvent)
 -> Value -> Parser SelectionEvent)
-> (Object -> Parser SelectionEvent)
-> Value
-> Parser SelectionEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      Int -> Int -> SelectionEvent
SelectionEvent
        (Int -> Int -> SelectionEvent)
-> Parser Int -> Parser (Int -> SelectionEvent)
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
"selectionStart"
        Parser (Int -> SelectionEvent)
-> Parser Int -> Parser SelectionEvent
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 Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"selectionEnd"
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/input.html#bindblur
--
-- Triggered when the input is blurred, outputting the current value.
--
onBlur :: (MisoString -> action) -> Attribute model action
onBlur :: forall action model.
(MisoString -> action) -> Attribute model action
onBlur 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
"blur" Decoder MisoString
inputValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | Like 'onBlur', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Blurred MisoString
--
-- view_ [ event (static (onBlurMain Blurred)) ] [ "some view" ]
-- @
--
onBlurMain :: (MisoString -> action) -> EventHandler model action
onBlurMain :: forall action model.
(MisoString -> action) -> EventHandler model action
onBlurMain 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
"blur" Decoder MisoString
inputValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | Like 'onBlurMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Blurred MisoString Model DOMRef
--
-- view_ [ event (static (onBlurMainWith Blurred)) ] [ "some view" ]
-- @
--
onBlurMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onBlurMainWith :: forall model action.
(MisoString -> model -> DOMRef -> action)
-> EventHandler model action
onBlurMainWith 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
"blur" Decoder MisoString
inputValueDecoder MisoString -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/input.html#bindconfirm
--
-- Triggered when the confirm button is clicked, outputting the current value.
--
onConfirm :: (MisoString -> action) -> Attribute model action
onConfirm :: forall action model.
(MisoString -> action) -> Attribute model action
onConfirm 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
"confirm" Decoder MisoString
inputValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | Like 'onConfirm', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Confirmed MisoString
--
-- view_ [ event (static (onConfirmMain Confirmed)) ] [ "some view" ]
-- @
--
onConfirmMain :: (MisoString -> action) -> EventHandler model action
onConfirmMain :: forall action model.
(MisoString -> action) -> EventHandler model action
onConfirmMain 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
"confirm" Decoder MisoString
inputValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | Like 'onConfirmMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Confirmed MisoString Model DOMRef
--
-- view_ [ event (static (onConfirmMainWith Confirmed)) ] [ "some view" ]
-- @
--
onConfirmMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onConfirmMainWith :: forall model action.
(MisoString -> model -> DOMRef -> action)
-> EventHandler model action
onConfirmMainWith 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
"confirm" Decoder MisoString
inputValueDecoder MisoString -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/input.html#bindfocus
--
-- Triggered when the input is focused, outputting the current value.
--
onFocus :: (MisoString -> action) -> Attribute model action
onFocus :: forall action model.
(MisoString -> action) -> Attribute model action
onFocus 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
"focus" Decoder MisoString
inputValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | Like 'onFocus', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Focused MisoString
--
-- view_ [ event (static (onFocusMain Focused)) ] [ "some view" ]
-- @
--
onFocusMain :: (MisoString -> action) -> EventHandler model action
onFocusMain :: forall action model.
(MisoString -> action) -> EventHandler model action
onFocusMain 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
"focus" Decoder MisoString
inputValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | Like 'onFocusMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Focused MisoString Model DOMRef
--
-- view_ [ event (static (onFocusMainWith Focused)) ] [ "some view" ]
-- @
--
onFocusMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onFocusMainWith :: forall model action.
(MisoString -> model -> DOMRef -> action)
-> EventHandler model action
onFocusMainWith 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
"focus" Decoder MisoString
inputValueDecoder MisoString -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/input.html#bindinput
--
-- Triggered when the input content changes.
--
onInput :: (InputEvent -> action) -> Attribute model action
onInput :: forall action model.
(InputEvent -> action) -> Attribute model action
onInput InputEvent -> action
action = MisoString
-> Decoder InputEvent
-> (InputEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"input" Decoder InputEvent
inputDecoder (\InputEvent
e model
_ DOMRef
_ -> InputEvent -> action
action InputEvent
e)
-----------------------------------------------------------------------------
-- | Like 'onInput', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Changed InputEvent
--
-- view_ [ event (static (onInputMain Changed)) ] [ "some view" ]
-- @
--
onInputMain :: (InputEvent -> action) -> EventHandler model action
onInputMain :: forall action model.
(InputEvent -> action) -> EventHandler model action
onInputMain InputEvent -> action
action = MisoString
-> Decoder InputEvent
-> (InputEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"input" Decoder InputEvent
inputDecoder (\InputEvent
e model
_ DOMRef
_ -> InputEvent -> action
action InputEvent
e)
-----------------------------------------------------------------------------
-- | Like 'onInputMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Changed InputEvent Model DOMRef
--
-- view_ [ event (static (onInputMainWith Changed)) ] [ "some view" ]
-- @
--
onInputMainWith :: (InputEvent -> model -> DOMRef -> action) -> EventHandler model action
onInputMainWith :: forall model action.
(InputEvent -> model -> DOMRef -> action)
-> EventHandler model action
onInputMainWith InputEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder InputEvent
-> (InputEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"input" Decoder InputEvent
inputDecoder InputEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/input.html#bindselection
--
-- Triggered when the input selection changes.
--
onSelection :: (SelectionEvent -> action) -> Attribute model action
onSelection :: forall action model.
(SelectionEvent -> action) -> Attribute model action
onSelection SelectionEvent -> action
action = MisoString
-> Decoder SelectionEvent
-> (SelectionEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"selection" Decoder SelectionEvent
selectionDecoder (\SelectionEvent
e model
_ DOMRef
_ -> SelectionEvent -> action
action SelectionEvent
e)
-----------------------------------------------------------------------------
-- | Like 'onSelection', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Selected SelectionEvent
--
-- view_ [ event (static (onSelectionMain Selected)) ] [ "some view" ]
-- @
--
onSelectionMain :: (SelectionEvent -> action) -> EventHandler model action
onSelectionMain :: forall action model.
(SelectionEvent -> action) -> EventHandler model action
onSelectionMain SelectionEvent -> action
action = MisoString
-> Decoder SelectionEvent
-> (SelectionEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"selection" Decoder SelectionEvent
selectionDecoder (\SelectionEvent
e model
_ DOMRef
_ -> SelectionEvent -> action
action SelectionEvent
e)
-----------------------------------------------------------------------------
-- | Like 'onSelectionMain', but the handler also receives read-only access to
-- the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Selected SelectionEvent Model DOMRef
--
-- view_ [ event (static (onSelectionMainWith Selected)) ] [ "some view" ]
-- @
--
onSelectionMainWith :: (SelectionEvent -> model -> DOMRef -> action) -> EventHandler model action
onSelectionMainWith :: forall model action.
(SelectionEvent -> model -> DOMRef -> action)
-> EventHandler model action
onSelectionMainWith SelectionEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder SelectionEvent
-> (SelectionEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"selection" Decoder SelectionEvent
selectionDecoder SelectionEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | Like 'onBlur', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onBlurWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onBlurWith :: forall action model.
(MisoString -> DOMRef -> action) -> Attribute model action
onBlurWith 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
"blur" Decoder MisoString
inputValueDecoder ((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
-----------------------------------------------------------------------------
-- | Like 'onConfirm', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onConfirmWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onConfirmWith :: forall action model.
(MisoString -> DOMRef -> action) -> Attribute model action
onConfirmWith 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
"confirm" Decoder MisoString
inputValueDecoder ((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
-----------------------------------------------------------------------------
-- | Like 'onFocus', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onFocusWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onFocusWith :: forall action model.
(MisoString -> DOMRef -> action) -> Attribute model action
onFocusWith 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
"focus" Decoder MisoString
inputValueDecoder ((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
-----------------------------------------------------------------------------
-- | Like 'onInput', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onInputWith :: (InputEvent -> DOMRef -> action) -> Attribute model action
onInputWith :: forall action model.
(InputEvent -> DOMRef -> action) -> Attribute model action
onInputWith InputEvent -> DOMRef -> action
action = MisoString
-> Decoder InputEvent
-> (InputEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"input" Decoder InputEvent
inputDecoder ((InputEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (InputEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \InputEvent
v model
_ DOMRef
domRef -> InputEvent -> DOMRef -> action
action InputEvent
v DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onSelection', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onSelectionWith :: (SelectionEvent -> DOMRef -> action) -> Attribute model action
onSelectionWith :: forall action model.
(SelectionEvent -> DOMRef -> action) -> Attribute model action
onSelectionWith SelectionEvent -> DOMRef -> action
action = MisoString
-> Decoder SelectionEvent
-> (SelectionEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"selection" Decoder SelectionEvent
selectionDecoder ((SelectionEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (SelectionEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \SelectionEvent
v model
_ DOMRef
domRef -> SelectionEvent -> DOMRef -> action
action SelectionEvent
v DOMRef
domRef
-----------------------------------------------------------------------------