0 | module Text.HTML.Attribute
5 | import Text.CSS.Class
6 | import Text.HTML.Event
13 | data Dir = LTR | RTL
21 | data LoadType = Lzy | Eager
26 | show Eager = "eager"
51 | Show InputType where
52 | show Button = "button"
53 | show CheckBox = "checkbox"
54 | show Color = "color"
56 | show DateTime = "datetime-local"
57 | show Email = "email"
59 | show Image = "image"
60 | show Month = "month"
61 | show Number = "number"
62 | show Password = "password"
63 | show Radio = "radio"
64 | show Range = "range"
77 | data Attribute : {0 k : Type} -> (t : k) -> (event : Type) -> Type where
78 | Id : {0 t : HTMLTag s} -> Ref t -> Attribute t event
79 | Str : (name : String) -> (value : String) -> Attribute t event
80 | Bool : (name : String) -> (value : Bool) -> Attribute t event
82 | (preventDefault, stopPropagation : Bool)
84 | -> Attribute t event
85 | Empty : Attribute t event
88 | Functor (Attribute t) where
90 | map f (Str n v) = Str n v
91 | map f (Bool n v) = Bool n v
92 | map f (Event_ pd sp e) = Event_ pd sp $
map f e
97 | attrIf : Bool -> Lazy (Attribute t e) -> Attribute t e
99 | attrIf False _ = Empty
102 | Attributes : {0 k : _} -> (t : k) -> Type -> Type
103 | Attributes t e = List (Attribute t e)
106 | Event : DOMEvent ev -> Attribute t ev
107 | Event = Event_ False False
110 | displayAttribute : Attribute t ev -> Maybe String
111 | displayAttribute (Id (Id va)) = Just #"id="\#{va}""#
112 | displayAttribute (Str nm va) = Just #"\#{nm}="\#{va}""#
113 | displayAttribute (Bool nm True) = Just nm
114 | displayAttribute (Bool _ False) = Nothing
115 | displayAttribute (Event_ _ _ _) = Nothing
116 | displayAttribute Empty = Nothing
119 | displayAttributes : Attributes t ev -> String
120 | displayAttributes = fastConcat . intersperse " " . mapMaybe displayAttribute
123 | dispAttr : String -> (a -> String) -> a -> Attribute t ev
124 | dispAttr nm f = Str nm . f
127 | showAttr : Show a => String -> a -> Attribute t ev
128 | showAttr nm = dispAttr nm show
131 | accesskey : String -> Attribute t ev
132 | accesskey = Str "accesskey"
135 | action : String -> Attribute t ev
136 | action = Str "action"
139 | alt : String -> Attribute t ev
143 | autocapitalize : Bool -> Attribute t ev
144 | autocapitalize = Bool "autocapitalize"
147 | autocomplete : Bool -> Attribute t ev
148 | autocomplete = Bool "autocomplete"
151 | autofocus : Bool -> Attribute t ev
152 | autofocus = Bool "autofocus"
155 | autoplay : Bool -> Attribute t ev
156 | autoplay = Bool "autoplay"
159 | checked : Bool -> Attribute t ev
160 | checked = Bool "checked"
163 | cite : String -> Attribute t ev
167 | class : Class -> Attribute t ev
168 | class = Str "class" . value
171 | classes : List Class -> Attribute t ev
172 | classes = dispAttr "class" (fastConcat . intersperse " " . map value)
175 | cols : Bits32 -> Attribute t ev
176 | cols = showAttr "cols"
179 | colspan : Bits32 -> Attribute t ev
180 | colspan = showAttr "colspan"
183 | contenteditable : Bool -> Attribute t ev
184 | contenteditable = Bool "contenteditable"
187 | controls : Bool -> Attribute t ev
188 | controls = Bool "controls"
191 | data_ : String -> Attribute t ev
195 | dir : Dir -> Attribute t ev
196 | dir = showAttr "dir"
199 | disabled : Bool -> Attribute t ev
200 | disabled = Bool "disabled"
203 | download : String -> Attribute t ev
204 | download = Str "download"
207 | draggable : Bool -> Attribute t ev
208 | draggable = Bool "draggable"
211 | for : String -> Attribute t ev
215 | form : String -> Attribute t ev
219 | height : Bits32 -> Attribute t ev
220 | height = showAttr "height"
223 | hidden : Bool -> Attribute t ev
224 | hidden = Bool "hidden"
227 | href : String -> Attribute t ev
231 | hreflang : String -> Attribute t ev
232 | hreflang = Str "hreflang"
235 | id : String -> Attribute t ev
239 | label : String -> Attribute t ev
240 | label = Str "label"
243 | lang : String -> Attribute t ev
247 | loading : LoadType -> Attribute t ev
248 | loading = showAttr "loading"
251 | list : String -> Attribute t ev
255 | loop : Bool -> Attribute t ev
259 | maxlength : Bits32 -> Attribute t ev
260 | maxlength = showAttr "maxlength"
263 | minlength : Bits32 -> Attribute t ev
264 | minlength = showAttr "minlength"
267 | multiple : Bool -> Attribute t ev
268 | multiple = Bool "multiple"
271 | muted : Bool -> Attribute t ev
272 | muted = Bool "muted"
275 | name : String -> Attribute t ev
279 | placeholder : String -> Attribute t ev
280 | placeholder = Str "placeholder"
283 | readonly : Bool -> Attribute t ev
284 | readonly = Bool "readonly"
287 | required : Bool -> Attribute t ev
288 | required = Bool "required"
291 | reverse : Bool -> Attribute t ev
292 | reverse = Bool "reverse"
295 | rows : Bits32 -> Attribute t ev
296 | rows = showAttr "rows"
299 | rowspan : Bits32 -> Attribute t ev
300 | rowspan = showAttr "rowspan"
303 | selected : Bool -> Attribute t ev
304 | selected = Bool "selected"
307 | spellcheck : Bool -> Attribute t ev
308 | spellcheck = Bool "spellcheck"
311 | src : String -> Attribute t ev
315 | style : String -> Attribute t ev
316 | style = Str "style"
319 | tabindex : Int32 -> Attribute t ev
320 | tabindex = showAttr "tabindex"
323 | target : String -> Attribute t ev
324 | target = Str "target"
327 | title : String -> Attribute t ev
328 | title = Str "title"
331 | type : InputType -> Attribute t ev
332 | type = showAttr "type"
335 | value : String -> Attribute t ev
336 | value = Str "value"
339 | width : Bits32 -> Attribute t ev
340 | width = showAttr "width"
343 | wrap : Bool -> Attribute t ev
351 | click : (MouseInfo -> Maybe ev) -> Attribute t ev
352 | click = Event . Click
355 | onClick : ev -> Attribute t ev
356 | onClick = click . const . Just
359 | onLeftClick : ev -> Attribute t ev
360 | onLeftClick va = click $
\mi => toMaybe (mi.button == 0) va
363 | onRightClick : ev -> Attribute t ev
364 | onRightClick va = click $
\mi => toMaybe (mi.button == 2) va
367 | onMiddleClick : ev -> Attribute t ev
368 | onMiddleClick va = click $
\mi => toMaybe (mi.button == 1) va
371 | dblClick : (MouseInfo -> Maybe ev) -> Attribute t ev
372 | dblClick = Event . DblClick
375 | onDblClick : ev -> Attribute t ev
376 | onDblClick = dblClick . const . Just
379 | onMouseEnter : ev -> Attribute t ev
380 | onMouseEnter = Event . MouseEnter . const . Just
383 | onMouseLeave : ev -> Attribute t ev
384 | onMouseLeave = Event . MouseLeave . const . Just
387 | onMouseOver : ev -> Attribute t ev
388 | onMouseOver = Event . MouseOver . const . Just
391 | onMouseOut : ev -> Attribute t ev
392 | onMouseOut = Event . MouseOut . const . Just
395 | onResize : (Rect -> ev) -> Attribute t ev
396 | onResize f = Event . Resize $
Just . f
399 | onChange : (String -> ev) -> Attribute t ev
400 | onChange f = Event . Change $
Just . f . value
403 | onChangeMaybe : (String -> Maybe ev) -> Attribute t ev
404 | onChangeMaybe f = Event . Change $
f . value
407 | onChecked : (Bool -> ev) -> Attribute t ev
408 | onChecked f = Event . Change $
Just . f . checked
411 | onInput : (String -> ev) -> Attribute t ev
412 | onInput f = Event . Input $
Just . f . value
415 | onScroll : (ScrollInfo -> ev) -> Attribute t ev
416 | onScroll f = Event . Scroll $
Just . f
419 | onEnterDown : ev -> Attribute t ev
420 | onEnterDown va = Event . KeyDown $
\k => toMaybe (k.key == "Enter") va
423 | onEscDown : ev -> Attribute t ev
424 | onEscDown va = Event . KeyDown $
\k => toMaybe (k.key == "Escape") va
427 | onKeyUp : (KeyInfo -> ev) -> Attribute t ev
428 | onKeyUp f = Event . KeyUp $
Just . f
431 | onBlur : ev -> Attribute t ev
432 | onBlur = Event . Blur
435 | onFocus : ev -> Attribute t ev
436 | onFocus = Event . Focus