Source file fmlib_browser.ml
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
module Random =
struct
include Random
end
module Time =
struct
include Time
end
module Task =
struct
include Task
end
module Value =
struct
include Fmlib_js.Base.Value
let record = _object
end
module Event_flag =
struct
include Event_flag
end
module Decoder =
struct
include Fmlib_js.Base.Decode
let run (decode: 'a t) (v: Value.t): 'a option =
decode v
end
module Command =
struct
include Command
end
module Subscription =
struct
include Subscription
end
let debug (str: string): unit =
let open Fmlib_js.Base.Main in
log_string str
let debug_value (v: Value.t): unit =
let open Fmlib_js.Base.Main in
log_value v
module Attribute =
struct
include Attribute
let on (key: string) (decode: 'msg Decoder.t): 'msg t =
handler
key
Event_flag.no_stop
Event_flag.no_prevent
decode
let on_click (msg: 'msg): 'msg t =
on "click" (Decoder.return msg)
let font_size (size: string): 'm t =
style "font-size" size
let color (color: string): 'm t =
style "color" color
let background_color (color: string): 'm t =
style "background-color" color
let height (value: string): 'm t =
style "height" value
let width (value: string): 'm t =
style "width" value
let margin (value: string): 'm t =
style "margin" value
let padding (value: string): 'm t =
style "padding" value
let border_style (value: string): 'm t =
style "border-style" value
let border_width (value: string): 'm t =
style "border-width" value
let border_color (value: string): 'm t =
style "border-color" value
let id (value: string): 'm t =
attribute "id" value
let class_ (value: string): 'm t =
attribute "class" value
let href (value: string): 'm t =
attribute "href" value
let src (value: string): 'm t =
attribute "src" value
let title (value: string): 'm t =
attribute "title" value
let value (value: string): 'm t =
property "value" Value.(string value)
let placeholder (value: string): 'm t =
attribute "placeholder" value
let on_input (f: string -> 'msg): 'msg t =
let decode =
let open Decoder in
field "target" (field "value" (map f string))
in
handler
"input"
Event_flag.stop
Event_flag.no_prevent
decode
end
module Html =
struct
include Vdom
let h1 attrs nodes = node "h1" attrs nodes
let h2 attrs nodes = node "h2" attrs nodes
let h3 attrs nodes = node "h3" attrs nodes
let h4 attrs nodes = node "h4" attrs nodes
let h5 attrs nodes = node "h5" attrs nodes
let h6 attrs nodes = node "h6" attrs nodes
let div attrs nodes = node "div" attrs nodes
let span attrs nodes = node "span" attrs nodes
let pre attrs nodes = node "pre" attrs nodes
let p attrs nodes = node "p" attrs nodes
let button attrs nodes = node "button" attrs nodes
let input attrs nodes = node "input" attrs nodes
let label attrs nodes = node "label" attrs nodes
let textarea attrs nodes = node "textarea" attrs nodes
let select attrs nodes = node "select" attrs nodes
let ol attrs nodes = node "ol" attrs nodes
let ul attrs nodes = node "ul" attrs nodes
let li attrs nodes = node "li" attrs nodes
let svg_node tag attrs nodes =
node_ns "http://www.w3.org/2000/svg" tag attrs nodes
end
include Browser