diff --git a/src/React.js b/src/React.js index b4782ab..6e4ec51 100644 --- a/src/React.js +++ b/src/React.js @@ -149,17 +149,3 @@ function createElementDynamic(class_) { }; exports.createElementDynamicImpl = createElementDynamic; exports.createElementTagNameDynamic = createElementDynamic; - -function preventDefault(event) { - return function() { - event.preventDefault(); - }; -}; -exports.preventDefault = preventDefault; - -function stopPropagation(event) { - return function() { - event.stopPropagation(); - }; -}; -exports.stopPropagation = stopPropagation; diff --git a/src/React.purs b/src/React.purs index bc3d3ba..2fec580 100644 --- a/src/React.purs +++ b/src/React.purs @@ -6,8 +6,6 @@ module React , ReactThis , TagName - , EventHandler - , Read , Write , Disallowed @@ -30,18 +28,11 @@ module React , ReactClass , Ref - , Event - , MouseEvent - , KeyboardEvent - - , EventHandlerContext - , component , pureComponent , statelessComponent , getProps - , readState , writeState , writeStateWithCallback @@ -50,16 +41,16 @@ module React , forceUpdate , forceUpdateCb - , handle - , preventDefault - , stopPropagation - , createElement , createElementDynamic , createElementTagName , createElementTagNameDynamic , createLeafElement + , SyntheticEventHandler + , SyntheticEventHandlerContext + , handle + , Children , childrenToArray , childrenCount @@ -68,6 +59,8 @@ module React , class IsReactElement , toElement , fragmentWithKey + + , module SyntheticEvent ) where import Prelude @@ -75,7 +68,11 @@ import Prelude import Control.Monad.Eff (kind Effect, Eff) import Control.Monad.Eff.Exception (Error) import Control.Monad.Eff.Uncurried (EffFn2, runEffFn2) + import Data.Nullable (Nullable) + +import React.SyntheticEvent (preventDefault, isDefaultPrevented, stopPropagation, isPropagationStopped, persist) as SyntheticEvent + import Unsafe.Coerce (unsafeCoerce) -- | Name of a tag. @@ -91,7 +88,7 @@ foreign import data ReactComponent :: Type foreign import data ReactThis :: Type -> Type -> Type -- | An event handler. The type argument represents the type of the event. -foreign import data EventHandler :: Type -> Type +foreign import data SyntheticEventHandler :: Type -> Type -- | This phantom type indicates that read access to a resource is allowed. foreign import data Read :: Effect @@ -116,32 +113,8 @@ foreign import data ReactState :: # Effect -> Effect -- | This effect indicates that a computation may read the component props. foreign import data ReactProps :: Effect --- | The type of DOM events. -foreign import data Event :: Type - --- | The type of mouse events. -type MouseEvent = - { pageX :: Number - , pageY :: Number - } - --- | The type of keyboard events. -type KeyboardEvent = - { altKey :: Boolean - , ctrlKey :: Boolean - , charCode :: Int - , key :: String - , keyCode :: Int - , locale :: String - , location :: Int - , metaKey :: Boolean - , repeat :: Boolean - , shiftKey :: Boolean - , which :: Int - } - -- | A function which handles events. -type EventHandlerContext eff props state result = +type SyntheticEventHandlerContext eff props state result = Eff ( props :: ReactProps , state :: ReactState ReadWrite @@ -355,13 +328,13 @@ forceUpdateCb this m = runEffFn2 forceUpdateCbImpl this m -- | Create an event handler. foreign import handle :: forall eff ev props state result. - (ev -> EventHandlerContext eff props state result) -> EventHandler ev + (ev -> SyntheticEventHandlerContext eff props state result) -> SyntheticEventHandler ev class ReactPropFields (required :: # Type) (given :: # Type) type ReservedReactPropFields r = ( key :: String - , ref :: EventHandler (Nullable Ref) + , ref :: SyntheticEventHandler (Nullable Ref) | r ) @@ -423,10 +396,6 @@ foreign import childrenToArray :: Children -> Array ReactElement -- | Returns the number of children. foreign import childrenCount :: Children -> Int -foreign import preventDefault :: forall eff. Event -> Eff eff Unit - -foreign import stopPropagation :: forall eff. Event -> Eff eff Unit - class IsReactElement a where toElement :: a -> ReactElement diff --git a/src/React/DOM/Props.purs b/src/React/DOM/Props.purs index 3375435..8024314 100644 --- a/src/React/DOM/Props.purs +++ b/src/React/DOM/Props.purs @@ -1,7 +1,23 @@ module React.DOM.Props where import Data.Nullable (Nullable) -import React (Event, EventHandlerContext, KeyboardEvent, MouseEvent, Ref, handle) + +import React (SyntheticEventHandlerContext, Ref, handle) + +import React.SyntheticEvent + ( SyntheticEvent + , SyntheticAnimationEvent + , SyntheticClipboardEvent + , SyntheticCompositionEvent + , SyntheticInputEvent + , SyntheticKeyboardEvent + , SyntheticFocusEvent + , SyntheticMouseEvent + , SyntheticTouchEvent + , SyntheticTransitionEvent + , SyntheticUIEvent + , SyntheticWheelEvent + ) foreign import data Props :: Type @@ -463,171 +479,559 @@ unselectable :: Boolean -> Props unselectable = unsafeMkProps "unselectable" onAnimationStart :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticAnimationEvent -> SyntheticEventHandlerContext eff props state result) -> Props onAnimationStart f = unsafeMkProps "onAnimationStart" (handle f) onAnimationEnd :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticAnimationEvent -> SyntheticEventHandlerContext eff props state result) -> Props onAnimationEnd f = unsafeMkProps "onAnimationEnd" (handle f) onAnimationIteration :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticAnimationEvent -> SyntheticEventHandlerContext eff props state result) -> Props onAnimationIteration f = unsafeMkProps "onAnimationIteration" (handle f) onTransitionEnd :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticTransitionEvent -> SyntheticEventHandlerContext eff props state result) -> Props onTransitionEnd f = unsafeMkProps "onTransitionEnd" (handle f) +onToggle :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onToggle f = unsafeMkProps "onToggle" (handle f) + onError :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props onError f = unsafeMkProps "onError" (handle f) onLoad :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props onLoad f = unsafeMkProps "onLoad" (handle f) +onAbort :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onAbort f = unsafeMkProps "onAbort" (handle f) + +onCanPlay :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCanPlay f = unsafeMkProps "onCanPlay" (handle f) + +onCanPlayThrough :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCanPlayThrough f = unsafeMkProps "onCanPlayThrough" (handle f) + +onDurationChange :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDurationChange f = unsafeMkProps "onDurationChange" (handle f) + +onEmptied :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onEmptied f = unsafeMkProps "onEmptied" (handle f) + +onEncrypted :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onEncrypted f = unsafeMkProps "onEncrypted" (handle f) + +onEnded :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onEnded f = unsafeMkProps "onEnded" (handle f) + +onLoadedData :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadedData f = unsafeMkProps "onLoadedData" (handle f) + +onLoadedMetadata :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadedMetadata f = unsafeMkProps "onLoadedMetadata" (handle f) + +onLoadStart :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadStart f = unsafeMkProps "onLoadStart" (handle f) + +onPause :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPause f = unsafeMkProps "onPause" (handle f) + +onPlay :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPlay f = unsafeMkProps "onPlay" (handle f) + +onPlaying :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPlaying f = unsafeMkProps "onPlaying" (handle f) + +onProgress :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onProgress f = unsafeMkProps "onProgress" (handle f) + +onRateChange :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onRateChange f = unsafeMkProps "onRateChange" (handle f) + +onSeeked :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSeeked f = unsafeMkProps "onSeeked" (handle f) + +onSeeking :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSeeking f = unsafeMkProps "onSeeking" (handle f) + +onStalled :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onStalled f = unsafeMkProps "onStalled" (handle f) + +onSuspend :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSuspend f = unsafeMkProps "onSuspend" (handle f) + +onTimeUpdate :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTimeUpdate f = unsafeMkProps "onTimeUpdate" (handle f) + +onVolumeChange :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onVolumeChange f = unsafeMkProps "onVolumeChange" (handle f) + +onWaiting :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onWaiting f = unsafeMkProps "onWaiting" (handle f) + onCopy :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticClipboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props onCopy f = unsafeMkProps "onCopy" (handle f) onCut :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticClipboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props onCut f = unsafeMkProps "onCut" (handle f) onPaste :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticClipboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props onPaste f = unsafeMkProps "onPaste" (handle f) +onCompositionEnd :: forall eff props state result. + (SyntheticCompositionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCompositionEnd f = unsafeMkProps "onCompositionEnd" (handle f) + +onCompositionStart :: forall eff props state result. + (SyntheticCompositionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCompositionStart f = unsafeMkProps "onCompositionStart" (handle f) + +onCompositionUpdate :: forall eff props state result. + (SyntheticCompositionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCompositionUpdate f = unsafeMkProps "onCompositionUpdate" (handle f) + onKeyDown :: forall eff props state result. - (KeyboardEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticKeyboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props onKeyDown f = unsafeMkProps "onKeyDown" (handle f) onKeyPress :: forall eff props state result. - (KeyboardEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticKeyboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props onKeyPress f = unsafeMkProps "onKeyPress" (handle f) onKeyUp :: forall eff props state result. - (KeyboardEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticKeyboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props onKeyUp f = unsafeMkProps "onKeyUp" (handle f) onFocus :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticFocusEvent -> SyntheticEventHandlerContext eff props state result) -> Props onFocus f = unsafeMkProps "onFocus" (handle f) onBlur :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticFocusEvent -> SyntheticEventHandlerContext eff props state result) -> Props onBlur f = unsafeMkProps "onBlur" (handle f) onChange :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props onChange f = unsafeMkProps "onChange" (handle f) onInput :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props onInput f = unsafeMkProps "onInput" (handle f) onInvalid :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props onInvalid f = unsafeMkProps "onInvalid" (handle f) onSubmit :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props onSubmit f = unsafeMkProps "onSubmit" (handle f) onClick :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onClick f = unsafeMkProps "onClick" (handle f) +onContextMenu :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onContextMenu f = unsafeMkProps "onContextMenu" (handle f) + onDoubleClick :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDoubleClick f = unsafeMkProps "onDoubleClick" (handle f) onDrag :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDrag f = unsafeMkProps "onDrag" (handle f) onDragEnd :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDragEnd f = unsafeMkProps "onDragEnd" (handle f) onDragEnter :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDragEnter f = unsafeMkProps "onDragEnter" (handle f) onDragExit :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDragExit f = unsafeMkProps "onDragExit" (handle f) onDragLeave :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDragLeave f = unsafeMkProps "onDragLeave" (handle f) onDragOver :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDragOver f = unsafeMkProps "onDragOver" (handle f) onDragStart :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDragStart f = unsafeMkProps "onDragStart" (handle f) onDrop :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onDrop f = unsafeMkProps "onDrop" (handle f) onMouseDown :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseDown f = unsafeMkProps "onMouseDown" (handle f) onMouseEnter :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseEnter f = unsafeMkProps "onMouseEnter" (handle f) onMouseLeave :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseLeave f = unsafeMkProps "onMouseLeave" (handle f) onMouseMove :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseMove f = unsafeMkProps "onMouseMove" (handle f) onMouseOut :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseOut f = unsafeMkProps "onMouseOut" (handle f) onMouseOver :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseOver f = unsafeMkProps "onMouseOver" (handle f) onMouseUp :: forall eff props state result. - (MouseEvent -> EventHandlerContext eff props state result) -> Props + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props onMouseUp f = unsafeMkProps "onMouseUp" (handle f) +onSelect :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSelect f = unsafeMkProps "onSelect" (handle f) + onTouchCancel :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props onTouchCancel f = unsafeMkProps "onTouchCancel" (handle f) onTouchEnd :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props onTouchEnd f = unsafeMkProps "onTouchEnd" (handle f) onTouchMove :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props onTouchMove f = unsafeMkProps "onTouchMove" (handle f) onTouchStart :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props onTouchStart f = unsafeMkProps "onTouchStart" (handle f) onScroll :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticUIEvent -> SyntheticEventHandlerContext eff props state result) -> Props onScroll f = unsafeMkProps "onScroll" (handle f) onWheel :: forall eff props state result. - (Event -> EventHandlerContext eff props state result) -> Props + (SyntheticWheelEvent -> SyntheticEventHandlerContext eff props state result) -> Props onWheel f = unsafeMkProps "onWheel" (handle f) +onAnimationStartCapture :: forall eff props state result. + (SyntheticAnimationEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onAnimationStartCapture f = unsafeMkProps "onAnimationStartCapture" (handle f) + +onAnimationEndCapture :: forall eff props state result. + (SyntheticAnimationEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onAnimationEndCapture f = unsafeMkProps "onAnimationEndCapture" (handle f) + +onAnimationIterationCapture :: forall eff props state result. + (SyntheticAnimationEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onAnimationIterationCapture f = unsafeMkProps "onAnimationIterationCapture" (handle f) + +onTransitionEndCapture :: forall eff props state result. + (SyntheticTransitionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTransitionEndCapture f = unsafeMkProps "onTransitionEndCapture" (handle f) + +onToggleCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onToggleCapture f = unsafeMkProps "onToggleCapture" (handle f) + +onErrorCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onErrorCapture f = unsafeMkProps "onErrorCapture" (handle f) + +onLoadCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadCapture f = unsafeMkProps "onLoadCapture" (handle f) + +onAbortCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onAbortCapture f = unsafeMkProps "onAbortCapture" (handle f) + +onCanPlayCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCanPlayCapture f = unsafeMkProps "onCanPlayCapture" (handle f) + +onCanPlayThroughCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCanPlayThroughCapture f = unsafeMkProps "onCanPlayThroughCapture" (handle f) + +onDurationChangeCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDurationChangeCapture f = unsafeMkProps "onDurationChangeCapture" (handle f) + +onEmptiedCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onEmptiedCapture f = unsafeMkProps "onEmptiedCapture" (handle f) + +onEncryptedCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onEncryptedCapture f = unsafeMkProps "onEncryptedCapture" (handle f) + +onEndedCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onEndedCapture f = unsafeMkProps "onEndedCapture" (handle f) + +onLoadedDataCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadedDataCapture f = unsafeMkProps "onLoadedDataCapture" (handle f) + +onLoadedMetadataCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadedMetadataCapture f = unsafeMkProps "onLoadedMetadataCapture" (handle f) + +onLoadStartCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onLoadStartCapture f = unsafeMkProps "onLoadStartCapture" (handle f) + +onPauseCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPauseCapture f = unsafeMkProps "onPauseCapture" (handle f) + +onPlayCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPlayCapture f = unsafeMkProps "onPlayCapture" (handle f) + +onPlayingCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPlayingCapture f = unsafeMkProps "onPlayingCapture" (handle f) + +onProgressCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onProgressCapture f = unsafeMkProps "onProgressCapture" (handle f) + +onRateChangeCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onRateChangeCapture f = unsafeMkProps "onRateChangeCapture" (handle f) + +onSeekedCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSeekedCapture f = unsafeMkProps "onSeekedCapture" (handle f) + +onSeekingCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSeekingCapture f = unsafeMkProps "onSeekingCapture" (handle f) + +onStalledCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onStalledCapture f = unsafeMkProps "onStalledCapture" (handle f) + +onSuspendCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSuspendCapture f = unsafeMkProps "onSuspendCapture" (handle f) + +onTimeUpdateCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTimeUpdateCapture f = unsafeMkProps "onTimeUpdateCapture" (handle f) + +onVolumeChangeCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onVolumeChangeCapture f = unsafeMkProps "onVolumeChangeCapture" (handle f) + +onWaitingCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onWaitingCapture f = unsafeMkProps "onWaitingCapture" (handle f) + +onCopyCapture :: forall eff props state result. + (SyntheticClipboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCopyCapture f = unsafeMkProps "onCopyCapture" (handle f) + +onCutCapture :: forall eff props state result. + (SyntheticClipboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCutCapture f = unsafeMkProps "onCutCapture" (handle f) + +onPasteCapture :: forall eff props state result. + (SyntheticClipboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onPasteCapture f = unsafeMkProps "onPasteCapture" (handle f) + +onCompositionEndCapture :: forall eff props state result. + (SyntheticCompositionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCompositionEndCapture f = unsafeMkProps "onCompositionEndCapture" (handle f) + +onCompositionStartCapture :: forall eff props state result. + (SyntheticCompositionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCompositionStartCapture f = unsafeMkProps "onCompositionStartCapture" (handle f) + +onCompositionUpdateCapture :: forall eff props state result. + (SyntheticCompositionEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onCompositionUpdateCapture f = unsafeMkProps "onCompositionUpdateCapture" (handle f) + +onKeyDownCapture :: forall eff props state result. + (SyntheticKeyboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onKeyDownCapture f = unsafeMkProps "onKeyDownCapture" (handle f) + +onKeyPressCapture :: forall eff props state result. + (SyntheticKeyboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onKeyPressCapture f = unsafeMkProps "onKeyPressCapture" (handle f) + +onKeyUpCapture :: forall eff props state result. + (SyntheticKeyboardEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onKeyUpCapture f = unsafeMkProps "onKeyUpCapture" (handle f) + +onFocusCapture :: forall eff props state result. + (SyntheticFocusEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onFocusCapture f = unsafeMkProps "onFocusCapture" (handle f) + +onBlurCapture :: forall eff props state result. + (SyntheticFocusEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onBlurCapture f = unsafeMkProps "onBlurCapture" (handle f) + +onChangeCapture :: forall eff props state result. + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onChangeCapture f = unsafeMkProps "onChangeCapture" (handle f) + +onInputCapture :: forall eff props state result. + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onInputCapture f = unsafeMkProps "onInputCapture" (handle f) + +onInvalidCapture :: forall eff props state result. + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onInvalidCapture f = unsafeMkProps "onInvalidCapture" (handle f) + +onSubmitCapture :: forall eff props state result. + (SyntheticInputEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSubmitCapture f = unsafeMkProps "onSubmitCapture" (handle f) + +onClickCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onClickCapture f = unsafeMkProps "onClickCapture" (handle f) + +onContextMenuCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onContextMenuCapture f = unsafeMkProps "onContextMenuCapture" (handle f) + +onDoubleClickCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDoubleClickCapture f = unsafeMkProps "onDoubleClickCapture" (handle f) + +onDragCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragCapture f = unsafeMkProps "onDragCapture" (handle f) + +onDragEndCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragEndCapture f = unsafeMkProps "onDragEndCapture" (handle f) + +onDragEnterCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragEnterCapture f = unsafeMkProps "onDragEnterCapture" (handle f) + +onDragExitCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragExitCapture f = unsafeMkProps "onDragExitCapture" (handle f) + +onDragLeaveCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragLeaveCapture f = unsafeMkProps "onDragLeaveCapture" (handle f) + +onDragOverCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragOverCapture f = unsafeMkProps "onDragOverCapture" (handle f) + +onDragStartCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDragStartCapture f = unsafeMkProps "onDragStartCapture" (handle f) + +onDropCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onDropCapture f = unsafeMkProps "onDropCapture" (handle f) + +onMouseDownCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseDownCapture f = unsafeMkProps "onMouseDownCapture" (handle f) + +onMouseEnterCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseEnterCapture f = unsafeMkProps "onMouseEnterCapture" (handle f) + +onMouseLeaveCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseLeaveCapture f = unsafeMkProps "onMouseLeaveCapture" (handle f) + +onMouseMoveCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseMoveCapture f = unsafeMkProps "onMouseMoveCapture" (handle f) + +onMouseOutCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseOutCapture f = unsafeMkProps "onMouseOutCapture" (handle f) + +onMouseOverCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseOverCapture f = unsafeMkProps "onMouseOverCapture" (handle f) + +onMouseUpCapture :: forall eff props state result. + (SyntheticMouseEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onMouseUpCapture f = unsafeMkProps "onMouseUpCapture" (handle f) + +onSelectCapture :: forall eff props state result. + (SyntheticEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onSelectCapture f = unsafeMkProps "onSelectCapture" (handle f) + +onTouchCancelCapture :: forall eff props state result. + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTouchCancelCapture f = unsafeMkProps "onTouchCancelCapture" (handle f) + +onTouchEndCapture :: forall eff props state result. + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTouchEndCapture f = unsafeMkProps "onTouchEndCapture" (handle f) + +onTouchMoveCapture :: forall eff props state result. + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTouchMoveCapture f = unsafeMkProps "onTouchMoveCapture" (handle f) + +onTouchStartCapture :: forall eff props state result. + (SyntheticTouchEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onTouchStartCapture f = unsafeMkProps "onTouchStartCapture" (handle f) + +onScrollCapture :: forall eff props state result. + (SyntheticUIEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onScrollCapture f = unsafeMkProps "onScrollCapture" (handle f) + +onWheelCapture :: forall eff props state result. + (SyntheticWheelEvent -> SyntheticEventHandlerContext eff props state result) -> Props +onWheelCapture f = unsafeMkProps "onWheelCapture" (handle f) + ref :: forall eff props state result. - (Nullable Ref -> EventHandlerContext eff props state result) -> Props + (Nullable Ref -> SyntheticEventHandlerContext eff props state result) -> Props ref f = unsafeMkProps "ref" (handle f) suppressContentEditableWarning :: Boolean -> Props diff --git a/src/React/SyntheticEvent.js b/src/React/SyntheticEvent.js new file mode 100644 index 0000000..4384b90 --- /dev/null +++ b/src/React/SyntheticEvent.js @@ -0,0 +1,31 @@ +'use strict'; + +exports.preventDefault = function preventDefault(event) { + return function() { + return event.preventDefault(); + }; +}; + +exports.isDefaultPrevented = function isDefaultPrevented(event) { + return function() { + return event.isDefaultPrevented(); + }; +}; + +exports.stopPropagation = function stopPropagation(event) { + return function() { + return event.stopPropagation(); + }; +}; + +exports.isPropagationStopped = function isPropagationStopped(event) { + return function() { + return event.isPropagationStopped(); + }; +}; + +exports.persist = function persist(event) { + return function() { + return event.persist(); + }; +}; diff --git a/src/React/SyntheticEvent.purs b/src/React/SyntheticEvent.purs new file mode 100644 index 0000000..d4650e3 --- /dev/null +++ b/src/React/SyntheticEvent.purs @@ -0,0 +1,195 @@ +-- | Synthethic event representation for React. +-- | +-- | https://reactjs.org/docs/events.html +-- | https://reactjs.org/docs/handling-events.html +-- | https://flow.org/en/docs/react/events/ +-- | +module React.SyntheticEvent + ( SyntheticEvent + , SyntheticAnimationEvent + , SyntheticClipboardEvent + , SyntheticCompositionEvent + , SyntheticInputEvent + , SyntheticKeyboardEvent + , SyntheticFocusEvent + , SyntheticMouseEvent + , SyntheticTouchEvent + , SyntheticTransitionEvent + , SyntheticUIEvent + , SyntheticWheelEvent + + , SyntheticEvent' + , SyntheticAnimationEvent' + , SyntheticClipboardEvent' + , SyntheticCompositionEvent' + , SyntheticKeyboardEvent' + , SyntheticFocusEvent' + , SyntheticMouseEvent' + , SyntheticTouchEvent' + , SyntheticTransitionEvent' + , SyntheticUIEvent' + , SyntheticWheelEvent' + + , NativeEventTarget + , NativeEvent + , NativeDataTransfer + , NativeAbstractView + , NativeTouchList + + , preventDefault + , isDefaultPrevented + , stopPropagation + , isPropagationStopped + , persist + ) where + +import Prelude + +import Control.Monad.Eff (Eff) + +type SyntheticEvent = Record (SyntheticEvent' ()) + +type SyntheticAnimationEvent = Record (SyntheticAnimationEvent' (SyntheticEvent' ())) + +type SyntheticClipboardEvent = Record (SyntheticClipboardEvent' (SyntheticEvent' ())) + +type SyntheticCompositionEvent = Record (SyntheticCompositionEvent' (SyntheticUIEvent' (SyntheticEvent' ()))) + +type SyntheticInputEvent = Record (SyntheticUIEvent' (SyntheticEvent' ())) + +type SyntheticKeyboardEvent = Record (SyntheticKeyboardEvent' (SyntheticUIEvent' (SyntheticEvent' ()))) + +type SyntheticFocusEvent = Record (SyntheticFocusEvent' (SyntheticUIEvent' (SyntheticEvent' ()))) + +type SyntheticMouseEvent = Record (SyntheticMouseEvent' (SyntheticUIEvent' (SyntheticEvent' ()))) + +type SyntheticTouchEvent = Record (SyntheticTouchEvent' (SyntheticUIEvent' (SyntheticEvent' ()))) + +type SyntheticTransitionEvent = Record (SyntheticTransitionEvent' (SyntheticEvent' ())) + +type SyntheticUIEvent = Record (SyntheticUIEvent' (SyntheticEvent' ())) + +type SyntheticWheelEvent = Record (SyntheticWheelEvent' (SyntheticMouseEvent' (SyntheticEvent' ()))) + +foreign import data NativeEventTarget :: Type + +foreign import data NativeEvent :: Type + +foreign import data NativeDataTransfer :: Type + +foreign import data NativeAbstractView :: Type + +foreign import data NativeTouchList :: Type + +foreign import preventDefault :: forall eff r. Record (SyntheticEvent' r) -> Eff eff Unit + +foreign import isDefaultPrevented :: forall eff r. Record (SyntheticEvent' r) -> Eff eff Boolean + +foreign import stopPropagation :: forall eff r. Record (SyntheticEvent' r) -> Eff eff Unit + +foreign import isPropagationStopped :: forall eff r. Record (SyntheticEvent' r) -> Eff eff Boolean + +foreign import persist :: forall eff r. Record (SyntheticEvent' r) -> Eff eff Unit + +type SyntheticEvent' r + = ( bubbles :: Boolean + , cancelable :: Boolean + , currentTarget :: NativeEventTarget + , defaultPrevented :: Boolean + , eventPhase :: Number + , isTrusted :: Boolean + , nativeEvent :: NativeEvent + , target :: NativeEventTarget + , timeStamp :: Number + , type :: String + | r + ) + +type SyntheticAnimationEvent' r + = ( animationName :: String + , pseudoElement :: String + , elapsedTime :: Number + | r + ) + +type SyntheticClipboardEvent' r + = ( clipboardData :: NativeDataTransfer + | r + ) + +type SyntheticCompositionEvent' r + = ( data :: String + | r + ) + +type SyntheticFocusEvent' r + = ( relatedTarget :: NativeEventTarget + | r + ) + +type SyntheticKeyboardEvent' r + = ( altKey :: Boolean + , charCode :: Int + , ctrlKey :: Boolean + , getModifierState :: String -> Boolean + , key :: String + , keyCode :: Number + , locale :: String + , location :: Number + , metaKey :: Boolean + , repeat :: Boolean + , shiftKey :: Boolean + , which :: Number + | r + ) + +type SyntheticMouseEvent' r + = ( altKey :: Boolean + , button :: Number + , buttons :: Number + , clientX :: Number + , clientY :: Number + , ctrlKey :: Boolean + , getModifierState :: String -> Boolean + , metaKey :: Boolean + , pageX :: Number + , pageY :: Number + , relatedTarget :: NativeEventTarget + , screenX :: Number + , screenY :: Number + , shiftKey :: Boolean + | r + ) + +type SyntheticTouchEvent' r + = ( altKey :: Boolean + , changedTouches :: NativeTouchList + , ctrlKey :: Boolean + , getModifierState :: String -> Boolean + , metaKey :: Boolean + , shiftKey :: Boolean + , targetTouches :: NativeTouchList + , touches :: NativeTouchList + | r + ) + +type SyntheticTransitionEvent' r + = ( propertyName :: String + , pseudoElement :: String + , elapsedTime :: Number + | r + ) + +type SyntheticUIEvent' r + = ( detail :: Number + , view :: NativeAbstractView + | r + ) + +type SyntheticWheelEvent' r + = ( deltaMode :: Number + , deltaX :: Number + , deltaY :: Number + , deltaZ :: Number + | r + )