-
Notifications
You must be signed in to change notification settings - Fork 4
/
Attribute.purs
453 lines (247 loc) · 11.8 KB
/
Attribute.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
module Oak.Html.Attribute where
import Prelude
( (<>)
, (>>>)
)
import Data.Functor ( class Functor )
import Oak.Css ( StyleAttribute )
import Oak.Html.Present
type KeyPressEvent =
{ altKey :: Boolean
, charCode :: Int
, code :: String
, ctrlKey :: Boolean
, isComposing :: Boolean
, key :: String
, keyCode :: Int
, location :: Int
, metaKey :: Boolean
, repeat :: Boolean
, shiftKey :: Boolean
, which :: Boolean
}
data Attribute msg
= BooleanAttribute String Boolean
| DataAttribute String String
| EventHandler String msg
| KeyPressEventHandler String (KeyPressEvent -> msg)
| SimpleAttribute String String
| StringEventHandler String (String -> msg)
| Style (Array StyleAttribute)
instance attributeFunctor :: Functor Attribute where
map :: ∀ msg1 msg2. (msg1 -> msg2) -> Attribute msg1 -> Attribute msg2
map f attr =
case attr of
StringEventHandler n ctor -> StringEventHandler n (ctor >>> f)
EventHandler n msg -> EventHandler n (f msg)
KeyPressEventHandler n ctor -> KeyPressEventHandler n (ctor >>> f)
BooleanAttribute n bool -> BooleanAttribute n bool
DataAttribute n dat -> DataAttribute n dat
SimpleAttribute a b -> SimpleAttribute a b
Style a -> Style a
-- special attrs
----------------
style :: ∀ msg. Array StyleAttribute -> Attribute msg
style attrs = Style attrs
-- data-*
data_ :: ∀ msg v. Present v => String -> v -> Attribute msg
data_ attrName val = DataAttribute ("data-" <> attrName) (present val)
-- boolean attrs
----------------
checked :: ∀ msg. Boolean -> Attribute msg
checked b = BooleanAttribute "checked" b
contenteditable :: ∀ msg. Boolean -> Attribute msg
contenteditable b = BooleanAttribute "contenteditable" b
disabled :: ∀ msg. Boolean -> Attribute msg
disabled b = BooleanAttribute "disabled" b
hidden :: ∀ msg. Boolean -> Attribute msg
hidden b = BooleanAttribute "hidden" b
-- regular string attributes
----------------------------
accept :: ∀ msg v. Present v => v -> Attribute msg
accept val = SimpleAttribute "accept" (present val)
acceptCharset :: ∀ msg v. Present v => v -> Attribute msg
acceptCharset val = SimpleAttribute "accept-charset" (present val)
accesskey :: ∀ msg v. Present v => v -> Attribute msg
accesskey val = SimpleAttribute "accesskey" (present val)
action :: ∀ msg v. Present v => v -> Attribute msg
action val = SimpleAttribute "action" (present val)
align :: ∀ msg v. Present v => v -> Attribute msg
align val = SimpleAttribute "align" (present val)
alt :: ∀ msg v. Present v => v -> Attribute msg
alt val = SimpleAttribute "alt" (present val)
async :: ∀ msg v. Present v => v -> Attribute msg
async val = SimpleAttribute "async" (present val)
autocomplete :: ∀ msg v. Present v => v -> Attribute msg
autocomplete val = SimpleAttribute "autocomplete" (present val)
autofocus :: ∀ msg v. Present v => v -> Attribute msg
autofocus val = SimpleAttribute "autofocus" (present val)
autoplay :: ∀ msg v. Present v => v -> Attribute msg
autoplay val = SimpleAttribute "autoplay" (present val)
bgcolor :: ∀ msg v. Present v => v -> Attribute msg
bgcolor val = SimpleAttribute "bgcolor" (present val)
border :: ∀ msg v. Present v => v -> Attribute msg
border val = SimpleAttribute "border" (present val)
charset :: ∀ msg v. Present v => v -> Attribute msg
charset val = SimpleAttribute "charset" (present val)
cite :: ∀ msg v. Present v => v -> Attribute msg
cite val = SimpleAttribute "cite" (present val)
class_ :: ∀ msg v. Present v => v -> Attribute msg
class_ val = SimpleAttribute "className" (present val)
color :: ∀ msg v. Present v => v -> Attribute msg
color val = SimpleAttribute "color" (present val)
cols :: ∀ msg v. Present v => v -> Attribute msg
cols val = SimpleAttribute "cols" (present val)
colspan :: ∀ msg v. Present v => v -> Attribute msg
colspan val = SimpleAttribute "colspan" (present val)
content :: ∀ msg v. Present v => v -> Attribute msg
content val = SimpleAttribute "content" (present val)
controls :: ∀ msg v. Present v => v -> Attribute msg
controls val = SimpleAttribute "controls" (present val)
coords :: ∀ msg v. Present v => v -> Attribute msg
coords val = SimpleAttribute "coords" (present val)
-- using data_ for the more common data-* attr use case
-- naming this data__ (note two underscores) for lack
-- of a better idea. I'm open to suggestions
data__ :: ∀ msg v. Present v => v -> Attribute msg
data__ val = SimpleAttribute "data" (present val)
datetime :: ∀ msg v. Present v => v -> Attribute msg
datetime val = SimpleAttribute "datetime" (present val)
default :: ∀ msg v. Present v => v -> Attribute msg
default val = SimpleAttribute "default" (present val)
defer :: ∀ msg v. Present v => v -> Attribute msg
defer val = SimpleAttribute "defer" (present val)
dir :: ∀ msg v. Present v => v -> Attribute msg
dir val = SimpleAttribute "dir" (present val)
dirname :: ∀ msg v. Present v => v -> Attribute msg
dirname val = SimpleAttribute "dirname" (present val)
download :: ∀ msg v. Present v => v -> Attribute msg
download val = SimpleAttribute "download" (present val)
draggable :: ∀ msg v. Present v => v -> Attribute msg
draggable val = SimpleAttribute "draggable" (present val)
dropzone :: ∀ msg v. Present v => v -> Attribute msg
dropzone val = SimpleAttribute "dropzone" (present val)
enctype :: ∀ msg v. Present v => v -> Attribute msg
enctype val = SimpleAttribute "enctype" (present val)
for :: ∀ msg v. Present v => v -> Attribute msg
for val = SimpleAttribute "for" (present val)
form :: ∀ msg v. Present v => v -> Attribute msg
form val = SimpleAttribute "form" (present val)
formaction :: ∀ msg v. Present v => v -> Attribute msg
formaction val = SimpleAttribute "formaction" (present val)
headers :: ∀ msg v. Present v => v -> Attribute msg
headers val = SimpleAttribute "headers" (present val)
height :: ∀ msg v. Present v => v -> Attribute msg
height val = SimpleAttribute "height" (present val)
high :: ∀ msg v. Present v => v -> Attribute msg
high val = SimpleAttribute "high" (present val)
href :: ∀ msg v. Present v => v -> Attribute msg
href val = SimpleAttribute "href" (present val)
hreflang :: ∀ msg v. Present v => v -> Attribute msg
hreflang val = SimpleAttribute "hreflang" (present val)
httpEquiv :: ∀ msg v. Present v => v -> Attribute msg
httpEquiv val = SimpleAttribute "http-equiv" (present val)
id_ :: ∀ msg v. Present v => v -> Attribute msg
id_ val = SimpleAttribute "id" (present val)
ismap :: ∀ msg v. Present v => v -> Attribute msg
ismap val = SimpleAttribute "ismap" (present val)
kind_ :: ∀ msg v. Present v => v -> Attribute msg
kind_ val = SimpleAttribute "kind" (present val)
label :: ∀ msg v. Present v => v -> Attribute msg
label val = SimpleAttribute "label" (present val)
lang :: ∀ msg v. Present v => v -> Attribute msg
lang val = SimpleAttribute "lang" (present val)
list :: ∀ msg v. Present v => v -> Attribute msg
list val = SimpleAttribute "list" (present val)
loop :: ∀ msg v. Present v => v -> Attribute msg
loop val = SimpleAttribute "loop" (present val)
low :: ∀ msg v. Present v => v -> Attribute msg
low val = SimpleAttribute "low" (present val)
max :: ∀ msg v. Present v => v -> Attribute msg
max val = SimpleAttribute "max" (present val)
maxlength :: ∀ msg v. Present v => v -> Attribute msg
maxlength val = SimpleAttribute "maxlength" (present val)
media :: ∀ msg v. Present v => v -> Attribute msg
media val = SimpleAttribute "media" (present val)
method :: ∀ msg v. Present v => v -> Attribute msg
method val = SimpleAttribute "method" (present val)
min :: ∀ msg v. Present v => v -> Attribute msg
min val = SimpleAttribute "min" (present val)
multiple :: ∀ msg v. Present v => v -> Attribute msg
multiple val = SimpleAttribute "multiple" (present val)
muted :: ∀ msg v. Present v => v -> Attribute msg
muted val = SimpleAttribute "muted" (present val)
name :: ∀ msg v. Present v => v -> Attribute msg
name val = SimpleAttribute "name" (present val)
novalidate :: ∀ msg v. Present v => v -> Attribute msg
novalidate val = SimpleAttribute "novalidate" (present val)
open :: ∀ msg v. Present v => v -> Attribute msg
open val = SimpleAttribute "open" (present val)
optimum :: ∀ msg v. Present v => v -> Attribute msg
optimum val = SimpleAttribute "optimum" (present val)
pattern :: ∀ msg v. Present v => v -> Attribute msg
pattern val = SimpleAttribute "pattern" (present val)
placeholder :: ∀ msg v. Present v => v -> Attribute msg
placeholder val = SimpleAttribute "placeholder" (present val)
poster :: ∀ msg v. Present v => v -> Attribute msg
poster val = SimpleAttribute "poster" (present val)
preload :: ∀ msg v. Present v => v -> Attribute msg
preload val = SimpleAttribute "preload" (present val)
readonly :: ∀ msg v. Present v => v -> Attribute msg
readonly val = SimpleAttribute "readonly" (present val)
rel :: ∀ msg v. Present v => v -> Attribute msg
rel val = SimpleAttribute "rel" (present val)
required :: ∀ msg v. Present v => v -> Attribute msg
required val = SimpleAttribute "required" (present val)
reversed :: ∀ msg v. Present v => v -> Attribute msg
reversed val = SimpleAttribute "reversed" (present val)
rows :: ∀ msg v. Present v => v -> Attribute msg
rows val = SimpleAttribute "rows" (present val)
rowspan :: ∀ msg v. Present v => v -> Attribute msg
rowspan val = SimpleAttribute "rowspan" (present val)
sandbox :: ∀ msg v. Present v => v -> Attribute msg
sandbox val = SimpleAttribute "sandbox" (present val)
scope :: ∀ msg v. Present v => v -> Attribute msg
scope val = SimpleAttribute "scope" (present val)
selected :: ∀ msg v. Present v => v -> Attribute msg
selected val = SimpleAttribute "selected" (present val)
shape :: ∀ msg v. Present v => v -> Attribute msg
shape val = SimpleAttribute "shape" (present val)
size :: ∀ msg v. Present v => v -> Attribute msg
size val = SimpleAttribute "size" (present val)
sizes :: ∀ msg v. Present v => v -> Attribute msg
sizes val = SimpleAttribute "sizes" (present val)
span :: ∀ msg v. Present v => v -> Attribute msg
span val = SimpleAttribute "span" (present val)
spellcheck :: ∀ msg v. Present v => v -> Attribute msg
spellcheck val = SimpleAttribute "spellcheck" (present val)
src :: ∀ msg v. Present v => v -> Attribute msg
src val = SimpleAttribute "src" (present val)
srcdoc :: ∀ msg v. Present v => v -> Attribute msg
srcdoc val = SimpleAttribute "srcdoc" (present val)
srclang :: ∀ msg v. Present v => v -> Attribute msg
srclang val = SimpleAttribute "srclang" (present val)
srcset :: ∀ msg v. Present v => v -> Attribute msg
srcset val = SimpleAttribute "srcset" (present val)
start :: ∀ msg v. Present v => v -> Attribute msg
start val = SimpleAttribute "start" (present val)
step :: ∀ msg v. Present v => v -> Attribute msg
step val = SimpleAttribute "step" (present val)
tabindex :: ∀ msg v. Present v => v -> Attribute msg
tabindex val = SimpleAttribute "tabindex" (present val)
target :: ∀ msg v. Present v => v -> Attribute msg
target val = SimpleAttribute "target" (present val)
title :: ∀ msg v. Present v => v -> Attribute msg
title val = SimpleAttribute "title" (present val)
translate :: ∀ msg v. Present v => v -> Attribute msg
translate val = SimpleAttribute "translate" (present val)
type_ :: ∀ msg v. Present v => v -> Attribute msg
type_ val = SimpleAttribute "type" (present val)
usemap :: ∀ msg v. Present v => v -> Attribute msg
usemap val = SimpleAttribute "usemap" (present val)
value :: ∀ msg v. Present v => Present v => v -> Attribute msg
value val = SimpleAttribute "value" (present val)
width :: ∀ msg v. Present v => v -> Attribute msg
width val = SimpleAttribute "width" (present val)
wrap :: ∀ msg v. Present v => v -> Attribute msg
wrap val = SimpleAttribute "wrap" (present val)