0 | module Text.HTML.Event
  1 |
  2 | import Data.Contravariant
  3 | import Data.Maybe
  4 | import Web.Internal.FileTypes
  5 |
  6 | %default total
  7 |
  8 | --------------------------------------------------------------------------------
  9 | --          Event Info Types
 10 | --------------------------------------------------------------------------------
 11 |
 12 | public export
 13 | record WheelInfo where
 14 |   constructor MkWheelInfo
 15 |   deltaMode : Bits32
 16 |   deltaX    : Double
 17 |   deltaY    : Double
 18 |   deltaZ    : Double
 19 |
 20 | public export
 21 | record MouseInfo where
 22 |   constructor MkMouseInfo
 23 |   -- buttons
 24 |   button  : Int16
 25 |   buttons : Bits16
 26 |
 27 |   -- coordinates
 28 |   clientX : Double
 29 |   clientY : Double
 30 |   offsetX : Double
 31 |   offsetY : Double
 32 |   pageX   : Double
 33 |   pageY   : Double
 34 |   screenX : Double
 35 |   screenY : Double
 36 |
 37 |   -- keys
 38 |   alt     : Bool
 39 |   ctrl    : Bool
 40 |   meta    : Bool
 41 |   shift   : Bool
 42 |
 43 | public export
 44 | record InputInfo where
 45 |   constructor MkInputInfo
 46 |   value   : String
 47 |   files   : List File
 48 |   checked : Bool
 49 |
 50 | public export
 51 | record KeyInfo where
 52 |   constructor MkKeyInfo
 53 |   key         : String
 54 |   code        : String
 55 |   location    : Bits32
 56 |   isComposing : Bool
 57 |
 58 |   -- control keys
 59 |   alt         : Bool
 60 |   ctrl        : Bool
 61 |   meta        : Bool
 62 |   shift       : Bool
 63 |
 64 | public export
 65 | record ScrollInfo where
 66 |   constructor MkScrollInfo
 67 |   scrollTop    : Double
 68 |   scrollHeight : Int32
 69 |   clientHeight : Int32
 70 |
 71 | public export
 72 | record Rect where
 73 |   constructor MkRect
 74 |   rectX  : Double
 75 |   rectY  : Double
 76 |   height : Double
 77 |   width  : Double
 78 |   top    : Double
 79 |   bottom : Double
 80 |   left   : Double
 81 |   right  : Double
 82 |
 83 | --------------------------------------------------------------------------------
 84 | --          Events
 85 | --------------------------------------------------------------------------------
 86 |
 87 | public export
 88 | data DOMEvent : Type -> Type where
 89 |   -- Mouse clicks
 90 |   Click      : (MouseInfo -> Maybe a) -> DOMEvent a
 91 |   DblClick   : (MouseInfo -> Maybe a) -> DOMEvent a
 92 |   MouseDown  : (MouseInfo -> Maybe a) -> DOMEvent a
 93 |   MouseUp    : (MouseInfo -> Maybe a) -> DOMEvent a
 94 |
 95 |   -- Mouse movement
 96 |   MouseEnter : (MouseInfo -> Maybe a) -> DOMEvent a
 97 |   MouseLeave : (MouseInfo -> Maybe a) -> DOMEvent a
 98 |   MouseOver  : (MouseInfo -> Maybe a) -> DOMEvent a
 99 |   MouseOut   : (MouseInfo -> Maybe a) -> DOMEvent a
100 |   MouseMove  : (MouseInfo -> Maybe a) -> DOMEvent a
101 |
102 |   -- Focus
103 |   Blur       : a -> DOMEvent a
104 |   Focus      : a -> DOMEvent a
105 |
106 |   -- Keyboard
107 |   KeyDown    : (KeyInfo -> Maybe a) -> DOMEvent a
108 |   KeyUp      : (KeyInfo -> Maybe a) -> DOMEvent a
109 |
110 |   -- Input
111 |   Change     : (InputInfo -> Maybe a) -> DOMEvent a
112 |   Input      : (InputInfo -> Maybe a) -> DOMEvent a
113 |
114 |   -- Routing
115 |   HashChange : a -> DOMEvent a
116 |
117 |   -- Scrolling
118 |   Scroll     : (ScrollInfo -> Maybe a) -> DOMEvent a
119 |
120 |   -- Wheel
121 |   Wheel      : (WheelInfo -> Maybe a)  -> DOMEvent a
122 |
123 |   -- Resize Events
124 |   Resize     : (Rect -> Maybe a)  -> DOMEvent a
125 |
126 | export
127 | Functor DOMEvent where
128 |   map f (Click g)      = Click (map f . g)
129 |   map f (DblClick g)   = DblClick (map f . g)
130 |   map f (MouseDown g)  = MouseDown (map f . g)
131 |   map f (MouseUp g)    = MouseUp (map f . g)
132 |   map f (MouseEnter g) = MouseEnter (map f . g)
133 |   map f (MouseLeave g) = MouseLeave (map f . g)
134 |   map f (MouseOver g)  = MouseOver (map f . g)
135 |   map f (MouseOut g)   = MouseOut (map f . g)
136 |   map f (MouseMove g)  = MouseMove (map f . g)
137 |   map f (Blur x)       = Blur (f x)
138 |   map f (Focus x)      = Focus (f x)
139 |   map f (KeyDown g)    = KeyDown (map f . g)
140 |   map f (KeyUp g)      = KeyUp (map f . g)
141 |   map f (Change g)     = Change (map f . g)
142 |   map f (Input g)      = Input (map f . g)
143 |   map f (HashChange x) = HashChange (f x)
144 |   map f (Scroll g)     = Scroll (map f . g)
145 |   map f (Wheel g)      = Wheel (map f . g)
146 |   map f (Resize g)     = Resize (map f . g)
147 |