-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Native.X.Element.Textarea.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.Textarea.Event
  ( -- *** Events
    onBlur
  , onBlurWith
  , onBlurMain
  , onBlurMainWith
  , onConfirm
  , onConfirmWith
  , onConfirmMain
  , onConfirmMainWith
  , onFocus
  , onFocusWith
  , onFocusMain
  , onFocusMainWith
  , onInput
  , onInputWith
  , onInputMain
  , onInputMainWith
  , onSelection
  , onSelectionWith
  , onSelectionMain
  , onSelectionMainWith
    -- *** Types
  , TextareaEvent (..)
  , SelectionEvent (..)
    -- *** Decoders
  , textareaValueDecoder
  , textareaDecoder
  , selectionDecoder
    -- *** Event Map
  , textareaEvents
  ) where
-----------------------------------------------------------------------------
import qualified Data.Map as M
-----------------------------------------------------------------------------
import           Miso.Event
import           Miso.JSON
import           Miso.String (MisoString)
import           Miso.Types (Attribute, EventHandler, DOMRef)
-----------------------------------------------------------------------------
textareaEvents :: Events
textareaEvents :: Events
textareaEvents = [(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 TextareaEvent
  = TextareaEvent
  { TextareaEvent -> MisoString
textareaValue :: MisoString
    -- ^ The current input content
  , TextareaEvent -> Int
textareaSelectionStart :: Int
    -- ^ Start position of the selection
  , TextareaEvent -> Int
textareaSelectionEnd :: Int
    -- ^ End position of the selection
  , TextareaEvent -> Bool
textareaIsComposing :: Bool
    -- ^ Whether the input is mid-composition (IME)
  } deriving (Int -> TextareaEvent -> ShowS
[TextareaEvent] -> ShowS
TextareaEvent -> String
(Int -> TextareaEvent -> ShowS)
-> (TextareaEvent -> String)
-> ([TextareaEvent] -> ShowS)
-> Show TextareaEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextareaEvent -> ShowS
showsPrec :: Int -> TextareaEvent -> ShowS
$cshow :: TextareaEvent -> String
show :: TextareaEvent -> String
$cshowList :: [TextareaEvent] -> ShowS
showList :: [TextareaEvent] -> ShowS
Show, TextareaEvent -> TextareaEvent -> Bool
(TextareaEvent -> TextareaEvent -> Bool)
-> (TextareaEvent -> TextareaEvent -> Bool) -> Eq TextareaEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextareaEvent -> TextareaEvent -> Bool
== :: TextareaEvent -> TextareaEvent -> Bool
$c/= :: TextareaEvent -> TextareaEvent -> Bool
/= :: TextareaEvent -> TextareaEvent -> 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@.
textareaValueDecoder :: Decoder MisoString
textareaValueDecoder :: Decoder MisoString
textareaValueDecoder = [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"
-----------------------------------------------------------------------------
textareaDecoder :: Decoder TextareaEvent
textareaDecoder :: Decoder TextareaEvent
textareaDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser TextareaEvent) -> Decoder TextareaEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser TextareaEvent
details
  where
    details :: Value -> Parser TextareaEvent
details = MisoString
-> (Object -> Parser TextareaEvent)
-> Value
-> Parser TextareaEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser TextareaEvent) -> Value -> Parser TextareaEvent)
-> (Object -> Parser TextareaEvent)
-> Value
-> Parser TextareaEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      MisoString -> Int -> Int -> Bool -> TextareaEvent
TextareaEvent
        (MisoString -> Int -> Int -> Bool -> TextareaEvent)
-> Parser MisoString
-> Parser (Int -> Int -> Bool -> TextareaEvent)
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 -> TextareaEvent)
-> Parser Int -> Parser (Int -> Bool -> TextareaEvent)
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 -> TextareaEvent)
-> Parser Int -> Parser (Bool -> TextareaEvent)
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
        -- See 'Miso.Native.X.Element.Input.Event': Lynx sends @isComposing@ as
        -- a number (0/1), not a JSON boolean, so decode as 'Int' and coerce.
        Parser (Bool -> TextareaEvent)
-> Parser Bool -> Parser TextareaEvent
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 'TextareaValue' 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/textarea.html#bindblur
--
-- Triggered when the textarea 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
textareaValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindblur
--
-- Triggered when the textarea is blurred, outputting the current value.
--
-- Called on main thread, provides read-only access to model.
-- Meant to be used with '-XStaticPointers'.
--
-- data Action = CurrentValue MisoString
--
-- @
-- view_ [ event (static (onBlurMain CurrentValue)) ] [ "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
textareaValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindblur
--
-- Triggered when the textarea is blurred, outputting the current value.
--
-- Called on main thread, provides read-only access to model.
-- Meant to be used with '-XStaticPointers'.
--
-- @
--
-- data Action = CurrentValue MisoString Model DOMRef
--
-- view_ [ event (static (onBlurMain CurrentValue)) ] [ "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
textareaValueDecoder MisoString -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindconfirm
--
-- Triggered when the confirm button is clicked (only when @confirm-type@ is
-- defined), 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
textareaValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindconfirm
--
-- Triggered when the confirm button is clicked (only when @confirm-type@ is
-- defined), outputting the current value.
--
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
textareaValueDecoder (\MisoString
e model
_ DOMRef
_ -> MisoString -> action
action MisoString
e)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindconfirm
--
-- Triggered when the confirm button is clicked (only when @confirm-type@ is
-- defined), outputting the current value.
--
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
textareaValueDecoder MisoString -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindfocus
--
-- Triggered when the textarea 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
textareaValueDecoder (\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
textareaValueDecoder (\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
textareaValueDecoder MisoString -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindinput
--
-- Triggered when the textarea content changes.
--
onInput :: (TextareaEvent -> action) -> Attribute model action
onInput :: forall action model.
(TextareaEvent -> action) -> Attribute model action
onInput TextareaEvent -> action
action = MisoString
-> Decoder TextareaEvent
-> (TextareaEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"input" Decoder TextareaEvent
textareaDecoder (\TextareaEvent
e model
_ DOMRef
_ -> TextareaEvent -> action
action TextareaEvent
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 TextareaEvent
--
-- view_ [ event (static (onInputMain Changed)) ] [ "some view" ]
-- @
--
onInputMain :: (TextareaEvent -> action) -> EventHandler model action
onInputMain :: forall action model.
(TextareaEvent -> action) -> EventHandler model action
onInputMain TextareaEvent -> action
action = MisoString
-> Decoder TextareaEvent
-> (TextareaEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"input" Decoder TextareaEvent
textareaDecoder (\TextareaEvent
e model
_ DOMRef
_ -> TextareaEvent -> action
action TextareaEvent
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 TextareaEvent Model DOMRef
--
-- view_ [ event (static (onInputMainWith Changed)) ] [ "some view" ]
-- @
--
onInputMainWith :: (TextareaEvent -> model -> DOMRef -> action) -> EventHandler model action
onInputMainWith :: forall model action.
(TextareaEvent -> model -> DOMRef -> action)
-> EventHandler model action
onInputMainWith TextareaEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder TextareaEvent
-> (TextareaEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"input" Decoder TextareaEvent
textareaDecoder TextareaEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/textarea.html#bindselection
--
-- Triggered when the textarea 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
textareaValueDecoder ((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
textareaValueDecoder ((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
textareaValueDecoder ((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 :: (TextareaEvent -> DOMRef -> action) -> Attribute model action
onInputWith :: forall action model.
(TextareaEvent -> DOMRef -> action) -> Attribute model action
onInputWith TextareaEvent -> DOMRef -> action
action = MisoString
-> Decoder TextareaEvent
-> (TextareaEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"input" Decoder TextareaEvent
textareaDecoder ((TextareaEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (TextareaEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \TextareaEvent
v model
_ DOMRef
domRef -> TextareaEvent -> DOMRef -> action
action TextareaEvent
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
-----------------------------------------------------------------------------