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