{-# LANGUAGE OverloadedStrings #-}
module Miso.Native.X.Element.Textarea.Event
(
onBlur
, onBlurWith
, onBlurMain
, onBlurMainWith
, onConfirm
, onConfirmWith
, onConfirmMain
, onConfirmMainWith
, onFocus
, onFocusWith
, onFocusMain
, onFocusMainWith
, onInput
, onInputWith
, onInputMain
, onInputMainWith
, onSelection
, onSelectionWith
, onSelectionMain
, onSelectionMainWith
, TextareaEvent (..)
, SelectionEvent (..)
, textareaValueDecoder
, textareaDecoder
, selectionDecoder
, 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)
]
data TextareaEvent
= TextareaEvent
{ TextareaEvent -> MisoString
textareaValue :: MisoString
, TextareaEvent -> Int
textareaSelectionStart :: Int
, TextareaEvent -> Int
textareaSelectionEnd :: Int
, TextareaEvent -> Bool
textareaIsComposing :: Bool
} 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)
data SelectionEvent
= SelectionEvent
{ SelectionEvent -> Int
selStart :: Int
, SelectionEvent -> Int
selEnd :: Int
} 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)
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
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")
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"
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)
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)
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
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)
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)
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
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)
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)
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
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)
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)
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
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)
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)
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
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
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
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
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
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