0 | module Text.HTML.Attribute
2 | import Derive.Prelude
3 | import Data.Linear.Token
7 | import FS.Concurrent.Signal
8 | import Text.CSS.Class
9 | import Text.CSS.Declaration
10 | import Text.HTML.Event
11 | import Text.HTML.Ref
12 | import Text.HTML.Tag
15 | %language ElabReflection
22 | data Dir = LTR | RTL
30 | data LoadType = Lzy | Eager
35 | show Eager = "eager"
60 | Show InputType where
61 | show Button = "button"
62 | show CheckBox = "checkbox"
63 | show Color = "color"
65 | show DateTime = "datetime-local"
66 | show Email = "email"
68 | show Image = "image"
69 | show Month = "month"
70 | show Number = "number"
71 | show Password = "password"
72 | show Radio = "radio"
73 | show Range = "range"
86 | data Attribute : {0 k : Type} -> (t : k) -> Type where
87 | Id : {0 t : HTMLTag s} -> Ref t -> Attribute t
88 | Str : (name : String) -> (value : String) -> Attribute t
89 | Bool : (name : String) -> (value : Bool) -> Attribute t
92 | -> (preventDefault, stopPropagation : Bool)
93 | -> {auto sink : Sink event}
100 | attrID : List (Attribute t) -> Maybe (Ref t)
101 | attrID [] = Nothing
102 | attrID (Id r :: _) = Just r
103 | attrID (_ :: xs) = attrID xs
107 | attrIf : Bool -> Lazy (Attribute t) -> Attribute t
109 | attrIf False _ = Empty
112 | Attributes : {0 k : _} -> (t : k) -> Type
113 | Attributes t = List (Attribute t)
116 | Event : Sink ev => DOMEvent ev -> Attribute t
117 | Event = Event_ False False
120 | displayAttribute : Attribute t -> Maybe String
121 | displayAttribute (Id (Id va)) = Just #"id="\#{va}""#
122 | displayAttribute (Str nm va) = Just #"\#{nm}="\#{va}""#
123 | displayAttribute (Bool nm True) = Just nm
124 | displayAttribute (Bool _ False) = Nothing
125 | displayAttribute (Event_ _ _ _) = Nothing
126 | displayAttribute Empty = Nothing
129 | displayAttributes : Attributes t -> String
130 | displayAttributes = fastConcat . intersperse " " . mapMaybe displayAttribute
133 | dispAttr : String -> (a -> String) -> a -> Attribute t
134 | dispAttr nm f = Str nm . f
137 | showAttr : Show a => String -> a -> Attribute t
138 | showAttr nm = dispAttr nm show
141 | accept : String -> Attribute t
142 | accept = Str "accept"
145 | acceptAll : List String -> Attribute t
146 | acceptAll = accept . fastConcat . intersperse ","
149 | accesskey : String -> Attribute t
150 | accesskey = Str "accesskey"
153 | action : String -> Attribute t
154 | action = Str "action"
157 | alt : String -> Attribute t
161 | autocapitalize : Bool -> Attribute t
162 | autocapitalize = Bool "autocapitalize"
165 | autocomplete : Bool -> Attribute t
166 | autocomplete = Bool "autocomplete"
169 | autofocus : Bool -> Attribute t
170 | autofocus = Bool "autofocus"
173 | autoplay : Bool -> Attribute t
174 | autoplay = Bool "autoplay"
177 | checked : Bool -> Attribute t
178 | checked = Bool "checked"
181 | cite : String -> Attribute t
185 | class : Class -> Attribute t
186 | class = Str "class" . value
189 | classes : Classes -> Attribute t
190 | classes = dispAttr "class" (fastConcat . intersperse " " . map value)
193 | cols : Bits32 -> Attribute t
194 | cols = showAttr "cols"
197 | colspan : Bits32 -> Attribute t
198 | colspan = showAttr "colspan"
201 | contenteditable : Bool -> Attribute t
202 | contenteditable = Bool "contenteditable"
205 | controls : Bool -> Attribute t
206 | controls = Bool "controls"
209 | data_ : String -> Attribute t
213 | dir : Dir -> Attribute t
214 | dir = showAttr "dir"
217 | disabled : Bool -> Attribute t
218 | disabled = Bool "disabled"
221 | download : String -> Attribute t
222 | download = Str "download"
225 | draggable : Bool -> Attribute t
226 | draggable = Bool "draggable"
229 | for : String -> Attribute t
233 | form : String -> Attribute t
237 | height : Bits32 -> Attribute t
238 | height = showAttr "height"
241 | hidden : Bool -> Attribute t
242 | hidden = Bool "hidden"
245 | href : String -> Attribute t
249 | hreflang : String -> Attribute t
250 | hreflang = Str "hreflang"
253 | id : String -> Attribute t
257 | label : String -> Attribute t
258 | label = Str "label"
261 | lang : String -> Attribute t
265 | loading : LoadType -> Attribute t
266 | loading = showAttr "loading"
269 | list : String -> Attribute t
273 | loop : Bool -> Attribute t
277 | maxlength : Bits32 -> Attribute t
278 | maxlength = showAttr "maxlength"
281 | minlength : Bits32 -> Attribute t
282 | minlength = showAttr "minlength"
285 | multiple : Bool -> Attribute t
286 | multiple = Bool "multiple"
289 | muted : Bool -> Attribute t
290 | muted = Bool "muted"
293 | name : String -> Attribute t
297 | placeholder : String -> Attribute t
298 | placeholder = Str "placeholder"
301 | readonly : Bool -> Attribute t
302 | readonly = Bool "readonly"
305 | required : Bool -> Attribute t
306 | required = Bool "required"
309 | reverse : Bool -> Attribute t
310 | reverse = Bool "reverse"
313 | rows : Bits32 -> Attribute t
314 | rows = showAttr "rows"
317 | rowspan : Bits32 -> Attribute t
318 | rowspan = showAttr "rowspan"
321 | selected : Bool -> Attribute t
322 | selected = Bool "selected"
325 | spellcheck : Bool -> Attribute t
326 | spellcheck = Bool "spellcheck"
329 | src : String -> Attribute t
333 | style : List Declaration -> Attribute t
334 | style = Str "style" . fastConcat . map interpolate
337 | tabindex : Int32 -> Attribute t
338 | tabindex = showAttr "tabindex"
341 | target : String -> Attribute t
342 | target = Str "target"
345 | title : String -> Attribute t
346 | title = Str "title"
349 | type : InputType -> Attribute t
350 | type = showAttr "type"
353 | value : String -> Attribute t
354 | value = Str "value"
357 | width : Bits32 -> Attribute t
358 | width = showAttr "width"
361 | wrap : Bool -> Attribute t
368 | parameters {auto sink : Sink ev}
371 | click : (MouseInfo -> Maybe ev) -> Attribute t
372 | click = Event . Click
375 | mouseDown : (MouseInfo -> Maybe ev) -> Attribute t
376 | mouseDown = Event . MouseDown
379 | mouseUp : (MouseInfo -> Maybe ev) -> Attribute t
380 | mouseUp = Event . MouseUp
383 | mouseMove : (MouseInfo -> Maybe ev) -> Attribute t
384 | mouseMove = Event . MouseMove
387 | leftDown : (MouseInfo -> Maybe ev) -> Attribute t
388 | leftDown f = mouseDown (\mi => guard (mi.button == 0) >> f mi)
391 | leftUp : (MouseInfo -> Maybe ev) -> Attribute t
392 | leftUp f = mouseUp (\mi => guard (mi.button == 0) >> f mi)
395 | rightDown : (MouseInfo -> Maybe ev) -> Attribute t
396 | rightDown f = mouseDown (\mi => guard (mi.button == 2) >> f mi)
399 | rightUp : (MouseInfo -> Maybe ev) -> Attribute t
400 | rightUp f = mouseUp (\mi => guard (mi.button == 2) >> f mi)
403 | middleDown : (MouseInfo -> Maybe ev) -> Attribute t
404 | middleDown f = mouseDown (\mi => guard (mi.button == 1) >> f mi)
407 | middleUp : (MouseInfo -> Maybe ev) -> Attribute t
408 | middleUp f = mouseUp (\mi => guard (mi.button == 1) >> f mi)
411 | onLeftDown : ev -> Attribute t
412 | onLeftDown = leftDown . const . Just
415 | onLeftUp : ev -> Attribute t
416 | onLeftUp = leftUp . const . Just
419 | onRightDown : ev -> Attribute t
420 | onRightDown = rightDown . const . Just
423 | onRightUp : ev -> Attribute t
424 | onRightUp = rightUp . const . Just
427 | onMiddleDown : ev -> Attribute t
428 | onMiddleDown = middleDown . const . Just
431 | onMiddleUp : ev -> Attribute t
432 | onMiddleUp = middleUp . const . Just
435 | onClick : ev -> Attribute t
436 | onClick = click . const . Just
439 | onLeftClick : ev -> Attribute t
440 | onLeftClick va = click $
\mi => toMaybe (mi.button == 0) va
443 | onRightClick : ev -> Attribute t
444 | onRightClick va = click $
\mi => toMaybe (mi.button == 2) va
447 | onMiddleClick : ev -> Attribute t
448 | onMiddleClick va = click $
\mi => toMaybe (mi.button == 1) va
451 | dblClick : (MouseInfo -> Maybe ev) -> Attribute t
452 | dblClick = Event . DblClick
455 | onDblClick : ev -> Attribute t
456 | onDblClick = dblClick . const . Just
459 | onMouseEnter : ev -> Attribute t
460 | onMouseEnter = Event . MouseEnter . const . Just
463 | onMouseLeave : ev -> Attribute t
464 | onMouseLeave = Event . MouseLeave . const . Just
467 | onMouseOver : ev -> Attribute t
468 | onMouseOver = Event . MouseOver . const . Just
471 | onMouseOut : ev -> Attribute t
472 | onMouseOut = Event . MouseOut . const . Just
475 | onResize : (Rect -> ev) -> Attribute t
476 | onResize f = Event . Resize $
Just . f
479 | onChange : (String -> ev) -> Attribute t
480 | onChange f = Event . Change $
Just . f . value
483 | onChangeMaybe : (String -> Maybe ev) -> Attribute t
484 | onChangeMaybe f = Event . Change $
f . value
487 | onChecked : (Bool -> ev) -> Attribute t
488 | onChecked f = Event . Change $
Just . f . checked
491 | onInput : (String -> ev) -> Attribute t
492 | onInput f = Event . Input $
Just . f . value
495 | onScroll : (ScrollInfo -> ev) -> Attribute t
496 | onScroll f = Event . Scroll $
Just . f
499 | onEnterDown : ev -> Attribute t
500 | onEnterDown va = Event . KeyDown $
\k => toMaybe (k.key == "Enter") va
503 | onEscDown : ev -> Attribute t
504 | onEscDown va = Event . KeyDown $
\k => toMaybe (k.key == "Escape") va
507 | onKeyUp : (KeyInfo -> ev) -> Attribute t
508 | onKeyUp f = Event . KeyUp $
Just . f
511 | onBlur : ev -> Attribute t
512 | onBlur = Event . Blur
515 | onFocus : ev -> Attribute t
516 | onFocus = Event . Focus
519 | onRemove : ev -> Attribute t
520 | onRemove = Event . Remove
523 | onClose : ev -> Attribute t
524 | onClose = Event . Close