13 | %language ElabReflection
14 | %hide Text.HTML.Node.a
15 | %hide Types.SelectionMode.Select
17 | --------------------------------------------------------------------------------
18 | -- EditRes
19 | --------------------------------------------------------------------------------
21 | ||| Result of editing some kind of input element.
22 | |||
23 | ||| Input is either missing, invalid, or valid.
32 | export
37 | export
42 | export
47 | export
53 | export
60 | export
66 | --------------------------------------------------------------------------------
67 | -- Widgets
68 | --------------------------------------------------------------------------------
70 | ||| A `Widget e` is an interactive UI element that emits
71 | ||| events of type `e`.
78 | export
82 | ||| A dummy widget without a node representation that keeps
83 | ||| producing the given value.
84 | export
88 | ||| A dummy widget without a node representation that
89 | ||| never fires an event.
90 | export
94 | ||| A dummy widget without a node representation that
95 | ||| fires the given event exactly once.
96 | export
100 | ||| Adjusts a widget in such a way that its input streams ends
101 | ||| as soon as its node is removed from the DOM.
102 | |||
103 | ||| This is used in utilities such as `bindEd` or `Web.Async.List`, where
104 | ||| external events decide when a node is removed from the UI.
105 | export
115 | export
119 | ||| Sets the `disabled` attribute of the given element
120 | ||| if the given values is not a `Valid`.
121 | |||
122 | ||| This is useful for disabling components such as buttons
123 | ||| in the UI in case of invalid user input.
128 | --------------------------------------------------------------------------------
129 | -- Text Widgets
130 | --------------------------------------------------------------------------------
132 | export
140 | ||| Adds a unique ID to the given list of attributes if it does not yet
141 | ||| already have an ID attribute, and returns the updated list plus the ID.
142 | export
154 | ||| Adds a unique ID to the given HTML node if it does not yet
155 | ||| already have an ID and returns the updated node plus its ID.
156 | |||
157 | ||| Returns `Nothing` in case the node in question is a `Raw` node
158 | ||| or a `Text` node.
159 | export
178 | ||| An input element that emits `String` events.
179 | export
183 | ||| A validated input element that emits events of type
184 | ||| `EditRes e`.
185 | |||
186 | ||| A custom validity message is set in case of invalid input.
187 | export
209 | export
213 | export
219 | --------------------------------------------------------------------------------
220 | -- Select Widgets
221 | --------------------------------------------------------------------------------
235 | ||| A select element displaying the values of type `v`
236 | ||| shown in the given list.
237 | |||
238 | ||| It fires events of type `t`, and uses two functions, one for
239 | ||| converting elements to events and one for displaying elements.
240 | export
253 | ||| A select element displaying the values of type `v`
254 | ||| shown in the given list.
255 | |||
256 | ||| It fires events of type `t`, and uses two functions, one for
257 | ||| converting elements to events and one for displaying elements.
258 | export
269 | --------------------------------------------------------------------------------
270 | -- Editor
271 | --------------------------------------------------------------------------------
284 | ||| An `Editor` describes how to create new interactive DOM elements that
285 | ||| typically serve as a form of (validated) user input. It consists of an
286 | ||| `HTMLNode` for displaying the editing form plus a stream of validated
287 | ||| input data.
288 | |||
289 | ||| An editor and its corresponding widgets can be something simple like a
290 | ||| text input field or a `<select>` element, or it can be highly complex
291 | ||| like a canvas and a group of DOM elements for editing molecules.
292 | |||
293 | ||| A couple of notes about how an editor is supposed to behave:
294 | ||| * If the initial value used for creating the widget is a `Nothing`,
295 | ||| the stream of values produced by the widget *may* already hold
296 | ||| a valid default value. In case no sensible default is available,
297 | ||| the stream's initial value *should* be `Missing`.
298 | ||| * If the initial value used for creating the widget is a `Just`,
299 | ||| the stream of values produced by the widget *must* emit a `Valid`
300 | ||| wrapping the provided initial value as its first output.
301 | |||
302 | ||| The above two rules make sure an editor behaves as expected, especially
303 | ||| when combining several editors in a form, or using the experimental
304 | ||| `bindEd` combinator.
308 | ||| Create a node and stream of values from an optional initial value.
311 | export
322 | ||| Views an editor through an isomorphism.
323 | export
327 | ||| Views the `new` values of an editor through a prism.
328 | export
332 | ||| Refines an editor to produce values of a more restricted type.
333 | export
345 | ||| A dummy `Editor` for uneditable values.
346 | |||
347 | ||| The given value is fired exactly once.
370 | export
387 | where