0 | module Text.Html.Attribute
5 | import Text.Html.Event
10 | data Dir = LTR | RTL
18 | data LoadType = Lzy | Eager
23 | show Eager = "eager"
47 | Show InputType where
48 | show Button = "button"
49 | show CheckBox = "checkbox"
50 | show Color = "color"
52 | show DateTime = "datetime-local"
53 | show Email = "email"
55 | show Image = "image"
56 | show Month = "month"
57 | show Number = "number"
58 | show Password = "password"
59 | show Radio = "radio"
60 | show Range = "range"
68 | data Attribute : (event : Type) -> Type where
69 | Id : (value : String) -> Attribute event
70 | Str : (name : String) -> (value : String) -> Attribute event
71 | Bool : (name : String) -> (value : Bool) -> Attribute event
72 | Event : DOMEvent event -> Attribute event
73 | Empty : Attribute event
76 | Attributes : Type -> Type
77 | Attributes = List . Attribute
80 | displayAttribute : Attribute ev -> Maybe String
81 | displayAttribute (Id va) = Just #"id="\#{va}""#
82 | displayAttribute (Str nm va) = Just #"\#{nm}="\#{va}""#
83 | displayAttribute (Bool nm True) = Just nm
84 | displayAttribute (Bool _ False) = Nothing
85 | displayAttribute (Event _) = Nothing
86 | displayAttribute Empty = Nothing
89 | displayAttributes : Attributes ev -> String
90 | displayAttributes = fastConcat . intersperse " " . mapMaybe displayAttribute
93 | getId : Attributes ev -> Maybe String
94 | getId (Id v :: _) = Just v
95 | getId (Str "id" v :: t) = Just v
96 | getId (_ :: t) = getId t
100 | getEvents : Attributes ev -> List (DOMEvent ev)
104 | go : List (DOMEvent ev) -> Attributes ev -> List (DOMEvent ev)
106 | go es (Event e :: xs) = go (e :: es) xs
107 | go es (_ :: xs) = go es xs
110 | dispAttr : String -> (a -> String) -> a -> Attribute ev
111 | dispAttr nm f = Str nm . f
114 | showAttr : Show a => String -> a -> Attribute ev
115 | showAttr nm = dispAttr nm show
118 | accesskey : String -> Attribute ev
119 | accesskey = Str "accesskey"
122 | action : String -> Attribute ev
123 | action = Str "action"
126 | alt : String -> Attribute ev
130 | autocapitalize : Bool -> Attribute ev
131 | autocapitalize = Bool "autocapitalize"
134 | autocomplete : Bool -> Attribute ev
135 | autocomplete = Bool "autocomplete"
138 | autofocus : Bool -> Attribute ev
139 | autofocus = Bool "autofocus"
142 | autoplay : Bool -> Attribute ev
143 | autoplay = Bool "autoplay"
146 | checked : Bool -> Attribute ev
147 | checked = Bool "checked"
150 | cite : String -> Attribute ev
154 | class : String -> Attribute ev
155 | class = Str "class"
158 | classes : List String -> Attribute ev
159 | classes = dispAttr "class" (fastConcat . intersperse " ")
162 | cols : Bits32 -> Attribute ev
163 | cols = showAttr "cols"
166 | colspan : Bits32 -> Attribute ev
167 | colspan = showAttr "colspan"
170 | contenteditable : Bool -> Attribute ev
171 | contenteditable = Bool "contenteditable"
174 | controls : Bool -> Attribute ev
175 | controls = Bool "controls"
178 | data_ : String -> Attribute ev
182 | dir : Dir -> Attribute ev
183 | dir = showAttr "dir"
186 | disabled : Bool -> Attribute ev
187 | disabled = Bool "disabled"
190 | download : String -> Attribute ev
191 | download = Str "download"
194 | draggable : Bool -> Attribute ev
195 | draggable = Bool "draggable"
198 | for : String -> Attribute ev
202 | form : String -> Attribute ev
206 | height : Bits32 -> Attribute ev
207 | height = showAttr "height"
210 | hidden : Bool -> Attribute ev
211 | hidden = Bool "hidden"
214 | href : String -> Attribute ev
218 | hreflang : String -> Attribute ev
219 | hreflang = Str "hreflang"
222 | id : String -> Attribute ev
226 | label : String -> Attribute ev
227 | label = Str "label"
230 | lang : String -> Attribute ev
234 | loading : LoadType -> Attribute ev
235 | loading = showAttr "loading"
238 | list : String -> Attribute ev
242 | loop : Bool -> Attribute ev
246 | maxlength : Bits32 -> Attribute ev
247 | maxlength = showAttr "maxlength"
250 | minlength : Bits32 -> Attribute ev
251 | minlength = showAttr "minlength"
254 | multiple : Bool -> Attribute ev
255 | multiple = Bool "multiple"
258 | muted : Bool -> Attribute ev
259 | muted = Bool "muted"
262 | name : String -> Attribute ev
266 | placeholder : String -> Attribute ev
267 | placeholder = Str "placeholder"
270 | readonly : Bool -> Attribute ev
271 | readonly = Bool "readonly"
274 | required : Bool -> Attribute ev
275 | required = Bool "required"
278 | reverse : Bool -> Attribute ev
279 | reverse = Bool "reverse"
282 | rows : Bits32 -> Attribute ev
283 | rows = showAttr "rows"
286 | rowspan : Bits32 -> Attribute ev
287 | rowspan = showAttr "rowspan"
290 | selected : Bool -> Attribute ev
291 | selected = Bool "selected"
294 | spellcheck : Bool -> Attribute ev
295 | spellcheck = Bool "spellcheck"
298 | src : String -> Attribute ev
302 | style : String -> Attribute ev
303 | style = Str "style"
306 | tabindex : Int32 -> Attribute ev
307 | tabindex = showAttr "tabindex"
310 | target : String -> Attribute ev
311 | target = Str "target"
314 | title : String -> Attribute ev
315 | title = Str "title"
318 | type : InputType -> Attribute ev
319 | type = showAttr "type"
322 | value : String -> Attribute ev
323 | value = Str "value"
326 | width : Bits32 -> Attribute ev
327 | width = showAttr "width"
330 | wrap : Bool -> Attribute ev
338 | click : (MouseInfo -> Maybe ev) -> Attribute ev
339 | click = Event . Click
342 | onClick : ev -> Attribute ev
343 | onClick = click . const . Just
346 | onLeftClick : ev -> Attribute ev
347 | onLeftClick va = click $
\mi => toMaybe (mi.button == 0) va
350 | onRightClick : ev -> Attribute ev
351 | onRightClick va = click $
\mi => toMaybe (mi.button == 2) va
354 | onMiddleClick : ev -> Attribute ev
355 | onMiddleClick va = click $
\mi => toMaybe (mi.button == 1) va
358 | dblClick : (MouseInfo -> Maybe ev) -> Attribute ev
359 | dblClick = Event . DblClick
362 | onDblClick : ev -> Attribute ev
363 | onDblClick = dblClick . const . Just
366 | onChange : (String -> ev) -> Attribute ev
367 | onChange f = Event . Change $
Just . f . value
370 | onChecked : (Bool -> ev) -> Attribute ev
371 | onChecked f = Event . Change $
Just . f . checked
374 | onInput : (String -> ev) -> Attribute ev
375 | onInput f = Event . Input $
Just . f . value
378 | onEnterDown : ev -> Attribute ev
379 | onEnterDown va = Event . KeyDown $
\k => toMaybe (k.key == "Enter") va
382 | onEscDown : ev -> Attribute ev
383 | onEscDown va = Event . KeyDown $
\k => toMaybe (k.key == "Escape") va
386 | onShiftDown : ev -> Attribute ev
387 | onShiftDown va = Event . KeyDown $
\k => toMaybe (k.key == "Shift") va
390 | onShiftUp : ev -> Attribute ev
391 | onShiftUp va = Event . KeyUp $
\k => toMaybe (k.key == "Shift") va
394 | onAltDown : ev -> Attribute ev
395 | onAltDown va = Event . KeyDown $
\k => toMaybe (k.key == "Alt") va
398 | onAltUp : ev -> Attribute ev
399 | onAltUp va = Event . KeyUp $
\k => toMaybe (k.key == "Alt") va
402 | onCtrlUp : ev -> Attribute ev
403 | onCtrlUp va = Event . KeyUp $
\k => toMaybe (k.key == "Control") va
406 | onCtrlDown : ev -> Attribute ev
407 | onCtrlDown va = Event . KeyDown $
\k => toMaybe (k.key == "Control") va
410 | onKeyUp : (KeyInfo -> ev) -> Attribute ev
411 | onKeyUp f = Event . KeyUp $
Just . f
414 | onBlur : ev -> Attribute ev
415 | onBlur = Event . Blur
418 | onFocus : ev -> Attribute ev
419 | onFocus = Event . Focus