Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose event target #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/GHCJS/VDOM/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

module GHCJS.VDOM.Event ( initEventDelegation
, defaultEvents
-- , target
, target
, stopPropagation
, stopImmediatePropagation
, preventDefault
Expand Down Expand Up @@ -69,6 +69,12 @@ module GHCJS.VDOM.Event ( initEventDelegation
, deltaY
, deltaZ
, deltaMode

-- * input
, InputEvent
, input
--
, inputValue

-- * generic
, Event
Expand Down Expand Up @@ -96,10 +102,12 @@ class Coercible a JSVal => Event_ a
class Event_ a => KeyModEvent_ a
class Event_ a => MouseEvent_ a
class Event_ a => FocusEvent_ a
class Event_ a => InputEvent_ a

mkEventTypes ''Event_ [ ("MouseEvent", [''MouseEvent_])
, ("KeyboardEvent", [''KeyModEvent_])
, ("FocusEvent", [''FocusEvent_])
, ("InputEvent", [''InputEvent_])
, ("DragEvent", [])
, ("WheelEvent", [])
, ("UIEvent", [])
Expand All @@ -113,6 +121,8 @@ mkEvents 'MouseEvent [ "click", "dblclick", "mousedown", "mouseenter"

mkEvents 'KeyboardEvent [ "keydown", "keypress", "keyup" ]

mkEvents 'InputEvent [ "input" ]

mkEvents 'DragEvent [ "drag", "dragend", "dragenter", "dragleave"
, "dragover", "dragstart" ]

Expand All @@ -137,6 +147,10 @@ defaultEvents = $(mkDefaultEvents)
-- target :: Event_ a => a -> VNode
-- target e = undefined

target :: Event_ a => a -> JSVal
target = er $ \e -> [jsu'| `e.target |]
{-# INLINE target #-}

stopPropagation :: Event_ a => a -> IO ()
stopPropagation = er $ \e -> [jsu_| `e.stopPropagation(); |]
{-# INLINE stopPropagation #-}
Expand Down Expand Up @@ -196,3 +210,7 @@ clientX = er $ \e -> [jsu'| `e.clientX|0 |]
clientY :: MouseEvent -> Int
clientY = er $ \e -> [jsu'| `e.clientY|0 |]
{-# INLINE clientY #-}

inputValue :: InputEvent -> JSString
inputValue = er $ \e -> [jsu'| String(`e.target.value||'') |]
{-# INLINE inputValue #-}