@lango-project/lango-client 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/NOTICE +5 -1
- package/README.md +570 -906
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +112 -19
- package/cli/.lango/vendor/i18next.LICENSE +21 -0
- package/cli/.lango/vendor/i18next.mjs +2434 -0
- package/cli/create.mjs +62 -0
- package/cli/create.mjs.map +1 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +112 -19
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/accordion.mjs +277 -0
- package/dist/accordion.mjs.map +1 -0
- package/dist/activities.mjs +185 -0
- package/dist/activities.mjs.map +1 -0
- package/dist/app.mjs +636 -0
- package/dist/app.mjs.map +1 -0
- package/dist/boot.mjs +24 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/bootstrap-LICENSE +21 -0
- package/dist/bootstrap.min.css +6 -0
- package/dist/bootstrap.min.css.map +1 -0
- package/dist/button.mjs +77 -0
- package/dist/button.mjs.map +1 -0
- package/dist/chip.mjs +134 -0
- package/dist/chip.mjs.map +1 -0
- package/dist/client.css +95 -0
- package/dist/collections.mjs +77 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/combo_box.mjs +408 -0
- package/dist/combo_box.mjs.map +1 -0
- package/dist/content.mjs +123 -0
- package/dist/content.mjs.map +1 -0
- package/dist/control.mjs +139 -0
- package/dist/control.mjs.map +1 -0
- package/dist/date_input.mjs +242 -0
- package/dist/date_input.mjs.map +1 -0
- package/dist/error_reporter.mjs +136 -0
- package/dist/error_reporter.mjs.map +1 -0
- package/dist/fields.mjs +454 -0
- package/dist/fields.mjs.map +1 -0
- package/dist/file_input.mjs +227 -0
- package/dist/file_input.mjs.map +1 -0
- package/dist/form.mjs +272 -0
- package/dist/form.mjs.map +1 -0
- package/dist/heartbeat.mjs +167 -254
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +18 -0
- package/dist/indicators.mjs +127 -0
- package/dist/indicators.mjs.map +1 -0
- package/dist/input_changes.mjs +58 -0
- package/dist/input_changes.mjs.map +1 -0
- package/dist/input_group.mjs +38 -0
- package/dist/input_group.mjs.map +1 -0
- package/dist/layouts.mjs +195 -0
- package/dist/layouts.mjs.map +1 -0
- package/dist/library.mjs +130 -807
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll.mjs +254 -0
- package/dist/longpoll.mjs.map +1 -0
- package/dist/main.mjs +138 -0
- package/dist/main.mjs.map +1 -0
- package/dist/markdown.mjs +61 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/menus.mjs +468 -0
- package/dist/menus.mjs.map +1 -0
- package/dist/navigation.mjs +260 -410
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +181 -0
- package/dist/numeric_input.mjs.map +1 -0
- package/dist/otp_input.mjs +113 -0
- package/dist/otp_input.mjs.map +1 -0
- package/dist/presentations.mjs +852 -0
- package/dist/presentations.mjs.map +1 -0
- package/dist/renderer.mjs +293 -0
- package/dist/renderer.mjs.map +1 -0
- package/dist/rich_content.mjs +99 -0
- package/dist/rich_content.mjs.map +1 -0
- package/dist/tables.mjs +369 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tabs.mjs +205 -0
- package/dist/tabs.mjs.map +1 -0
- package/dist/templates.mjs +46 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/vendor/DOMPurify-LICENSE +202 -0
- package/dist/vendor/dompurify.mjs +2540 -0
- package/dist/vendor/flatpickr-LICENSE.md +21 -0
- package/dist/vendor/flatpickr.min.css +13 -0
- package/dist/vendor/flatpickr.mjs +2340 -0
- package/dist/vendor/flatpickr.mjs.map +7 -0
- package/dist/vendor/marked-LICENSE.md +44 -0
- package/dist/vendor/marked.esm.js.map +7 -0
- package/dist/vendor/marked.mjs +85 -0
- package/dist/vendor/purify.es.mjs.map +1 -0
- package/dist/widgets.mjs +197 -0
- package/dist/widgets.mjs.map +1 -0
- package/docs/implementation.md +42 -0
- package/package.json +25 -43
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +508 -0
- package/src/boot.lango +12 -0
- package/src/button.lango +49 -0
- package/src/chip.lango +94 -0
- package/src/collections.lango +46 -0
- package/src/combo_box.lango +298 -0
- package/src/content.lango +75 -0
- package/src/control.lango +100 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -0
- package/src/error_reporter.lango +95 -0
- package/src/fields.lango +327 -0
- package/src/file_input.lango +175 -0
- package/src/form.lango +195 -0
- package/src/heartbeat.lango +136 -199
- package/src/indicators.lango +94 -0
- package/src/input_changes.lango +33 -0
- package/src/input_group.lango +22 -0
- package/src/layouts.lango +137 -0
- package/src/library.lango +194 -599
- package/src/longpoll.lango +187 -0
- package/src/main.lango +109 -0
- package/src/markdown.lango +48 -0
- package/src/menus.lango +336 -0
- package/src/navigation.lango +209 -299
- package/src/numeric_input.lango +131 -0
- package/src/otp_input.lango +83 -0
- package/src/presentations.lango +617 -0
- package/src/renderer.lango +288 -0
- package/src/rich_content.lango +66 -0
- package/src/tables.lango +271 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +95 -0
- package/web/index.html +18 -0
- package/dist/application.mjs +0 -429
- package/dist/application.mjs.map +0 -1
- package/dist/coordinator.mjs +0 -91
- package/dist/coordinator.mjs.map +0 -1
- package/dist/demo.mjs +0 -110
- package/dist/demo.mjs.map +0 -1
- package/dist/demo_controls.mjs +0 -59
- package/dist/demo_controls.mjs.map +0 -1
- package/dist/errors.mjs +0 -201
- package/dist/errors.mjs.map +0 -1
- package/dist/form_state.mjs +0 -266
- package/dist/form_state.mjs.map +0 -1
- package/dist/inheritance.mjs +0 -240
- package/dist/inheritance.mjs.map +0 -1
- package/dist/input_values.mjs +0 -65
- package/dist/input_values.mjs.map +0 -1
- package/dist/node/.lango/xmldom/conventions.js +0 -429
- package/dist/node/.lango/xmldom/dom-parser.js +0 -591
- package/dist/node/.lango/xmldom/dom.js +0 -3759
- package/dist/node/.lango/xmldom/entities.js +0 -2171
- package/dist/node/.lango/xmldom/errors.js +0 -205
- package/dist/node/.lango/xmldom/grammar.js +0 -559
- package/dist/node/.lango/xmldom/index.js +0 -41
- package/dist/node/.lango/xmldom/package.json +0 -1
- package/dist/node/.lango/xmldom/sax.js +0 -983
- package/dist/node/.lango/xmldom.LICENSE.md +0 -8
- package/dist/node/browser_host.mjs +0 -351
- package/dist/node/browser_host.mjs.map +0 -1
- package/dist/node/create_app.mjs +0 -118
- package/dist/node/create_app.mjs.map +0 -1
- package/dist/presentation.mjs +0 -89
- package/dist/presentation.mjs.map +0 -1
- package/dist/protocol.mjs +0 -706
- package/dist/protocol.mjs.map +0 -1
- package/dist/session.mjs +0 -471
- package/dist/session.mjs.map +0 -1
- package/dist/tokens.mjs +0 -298
- package/dist/tokens.mjs.map +0 -1
- package/examples/contacts.lango +0 -293
- package/examples/contacts_flow.lango +0 -174
- package/examples/contacts_store.lango +0 -109
- package/examples/contacts_store_test.lango +0 -65
- package/examples/demo.css +0 -87
- package/examples/demo_test.lango +0 -356
- package/examples/index.html +0 -32
- package/examples/pages.lango +0 -174
- package/examples/server.lango +0 -189
- package/examples/worker.lango +0 -142
- package/src/application.lango +0 -327
- package/src/browser_host.lango +0 -276
- package/src/coordinator.lango +0 -57
- package/src/demo.lango +0 -110
- package/src/demo_controls.lango +0 -53
- package/src/errors.lango +0 -149
- package/src/errors_test.lango +0 -157
- package/src/form_state.lango +0 -168
- package/src/heartbeat_test.lango +0 -479
- package/src/inheritance.lango +0 -167
- package/src/input_values.lango +0 -37
- package/src/logout_test.lango +0 -564
- package/src/navigation_test.lango +0 -556
- package/src/presentation.lango +0 -55
- package/src/protocol.lango +0 -787
- package/src/renderer_test.lango +0 -2047
- package/src/session.lango +0 -343
- package/src/session_test.lango +0 -455
- package/src/tabs_test.lango +0 -216
- package/src/tokens.lango +0 -215
- package/template/.vscode/extensions.json +0 -3
- package/template/.vscode/settings.json +0 -9
- package/template/README.md +0 -44
- package/template/gitignore +0 -4
- package/template/package.json +0 -22
- package/template/public/app.css +0 -10
- package/template/public/index.html +0 -24
- package/template/src/client.lango +0 -78
- package/template/src/pages.lango +0 -55
- package/template/src/server.lango +0 -24
- package/template/src/worker.lango +0 -77
- package/template/test/app.lango +0 -9
- package/tools/browser_runner.lango +0 -32
- package/tools/browser_test.lango +0 -343
- package/tools/create_app.lango +0 -88
- package/tools/create_app_test.lango +0 -43
- package/tools/starter_test.lango +0 -227
- /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
- /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
- /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
- /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
- /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
- /package/{dist → cli}/.lango/xmldom/index.js +0 -0
- /package/{dist → cli}/.lango/xmldom/package.json +0 -0
- /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
- /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import js global document
|
|
2
|
+
import "./fields"
|
|
3
|
+
class Field
|
|
4
|
+
sameValue(first, second)
|
|
5
|
+
import "./templates"
|
|
6
|
+
cloneMarkup(name, xml)
|
|
7
|
+
controlId()
|
|
8
|
+
import "./rich_content"
|
|
9
|
+
class RichContent
|
|
10
|
+
|
|
11
|
+
export comboSelection(options, value, multi)
|
|
12
|
+
|
|
13
|
+
comboSelection(options, value, multi)
|
|
14
|
+
requested = []
|
|
15
|
+
if value != null
|
|
16
|
+
if multi
|
|
17
|
+
if !is_array(value)
|
|
18
|
+
throw "Multi ComboBox value must be an array"
|
|
19
|
+
requested = value
|
|
20
|
+
else
|
|
21
|
+
requested.add(value)
|
|
22
|
+
selected = []
|
|
23
|
+
for requested as candidate
|
|
24
|
+
found = -1
|
|
25
|
+
index = 0
|
|
26
|
+
for options as option
|
|
27
|
+
if option.value != null and sameValue(option.value, candidate)
|
|
28
|
+
found = index
|
|
29
|
+
break
|
|
30
|
+
index = index + 1
|
|
31
|
+
if found < 0
|
|
32
|
+
throw "ComboBox value does not identify an option"
|
|
33
|
+
if !selected.includes(found)
|
|
34
|
+
selected.add(found)
|
|
35
|
+
return selected
|
|
36
|
+
|
|
37
|
+
export class ComboBox(form, props, renderer) : Field
|
|
38
|
+
methods
|
|
39
|
+
getValue()
|
|
40
|
+
setValue(value)
|
|
41
|
+
setDisabled(value)
|
|
42
|
+
open(last = false)
|
|
43
|
+
close(focus = false)
|
|
44
|
+
choose(index)
|
|
45
|
+
dispose()
|
|
46
|
+
|
|
47
|
+
ComboBox(form, props, renderer)
|
|
48
|
+
super(form, props, cloneMarkup("combo-button", <button type="button" class="form-select text-start" role="combobox" aria-haspopup="listbox" aria-expanded="false"></button>))
|
|
49
|
+
@locked = props.readonly == true
|
|
50
|
+
@multi = props.multi == true
|
|
51
|
+
@options = props.options
|
|
52
|
+
if @options == null
|
|
53
|
+
@options = []
|
|
54
|
+
@selected = []
|
|
55
|
+
@elements = []
|
|
56
|
+
@slots = []
|
|
57
|
+
@cursor = -1
|
|
58
|
+
@element.classList.add("lango-combo")
|
|
59
|
+
@panel = cloneMarkup("combo-panel", <div class="lango-combo-panel" hidden="hidden"><ul class="list-group" role="listbox"></ul></div>)
|
|
60
|
+
list = @panel.firstElementChild
|
|
61
|
+
list.id = controlId()
|
|
62
|
+
if props.aria != null and props.aria.label != null
|
|
63
|
+
list.setAttribute("aria-label", props.aria.label)
|
|
64
|
+
else
|
|
65
|
+
if props.label != null
|
|
66
|
+
list.setAttribute("aria-label", props.label)
|
|
67
|
+
if @multi
|
|
68
|
+
list.setAttribute("aria-multiselectable", "true")
|
|
69
|
+
@input.setAttribute("aria-controls", list.id)
|
|
70
|
+
@element.insertBefore(@panel, @input.nextSibling)
|
|
71
|
+
group = list
|
|
72
|
+
index = 0
|
|
73
|
+
for @options as option
|
|
74
|
+
if !is_object(option)
|
|
75
|
+
throw "ComboBox options require value/control maps"
|
|
76
|
+
if option.url != null
|
|
77
|
+
if option.value == null
|
|
78
|
+
throw "ComboBox group cannot have a URL"
|
|
79
|
+
form.app.checkUrl(option.url)
|
|
80
|
+
item = document/createElement("li")
|
|
81
|
+
slot = null
|
|
82
|
+
if option.value == null
|
|
83
|
+
item.setAttribute("role", "presentation")
|
|
84
|
+
heading = document/createElement("div")
|
|
85
|
+
heading.id = controlId()
|
|
86
|
+
heading.className = "lango-combo-heading"
|
|
87
|
+
slot = new RichContent(form, heading, renderer, false, "ComboBox group")
|
|
88
|
+
slot.replace(option.control)
|
|
89
|
+
@slots.add(slot)
|
|
90
|
+
item.appendChild(heading)
|
|
91
|
+
group = cloneMarkup("combo-group", <ul class="list-group" role="group"></ul>)
|
|
92
|
+
group.setAttribute("aria-labelledby", heading.id)
|
|
93
|
+
item.appendChild(group)
|
|
94
|
+
list.appendChild(item)
|
|
95
|
+
@elements.add(null)
|
|
96
|
+
else
|
|
97
|
+
item.className = "list-group-item list-group-item-action"
|
|
98
|
+
item.setAttribute("role", "option")
|
|
99
|
+
item.tabIndex = -1
|
|
100
|
+
item.id = controlId()
|
|
101
|
+
slot = new RichContent(form, item, renderer, false, "ComboBox option")
|
|
102
|
+
slot.replace(option.control)
|
|
103
|
+
label = item.textContent.trim()
|
|
104
|
+
content = item.firstElementChild
|
|
105
|
+
if content != null and content.hasAttribute("aria-label")
|
|
106
|
+
label = content.getAttribute("aria-label")
|
|
107
|
+
if label == ""
|
|
108
|
+
labels = []
|
|
109
|
+
for item.querySelectorAll("img[alt]") as image
|
|
110
|
+
labels.add(image.alt)
|
|
111
|
+
label = labels.join(" ").trim()
|
|
112
|
+
if label == ""
|
|
113
|
+
throw "ComboBox option requires text or an accessible label"
|
|
114
|
+
item.setAttribute("aria-label", label)
|
|
115
|
+
@slots.add(slot)
|
|
116
|
+
group.appendChild(item)
|
|
117
|
+
@elements.add(item)
|
|
118
|
+
choice = index
|
|
119
|
+
click = (event)
|
|
120
|
+
capture choice
|
|
121
|
+
event.preventDefault()
|
|
122
|
+
event.stopPropagation()
|
|
123
|
+
choose(choice)
|
|
124
|
+
key = (event)
|
|
125
|
+
capture choice
|
|
126
|
+
handleKey(event, choice)
|
|
127
|
+
listen(item, "click", click)
|
|
128
|
+
listen(item, "keydown", key)
|
|
129
|
+
index = index + 1
|
|
130
|
+
setValue(props.value)
|
|
131
|
+
setDisabled(props.disabled == true)
|
|
132
|
+
toggle = ()
|
|
133
|
+
if @panel.hidden
|
|
134
|
+
open()
|
|
135
|
+
else
|
|
136
|
+
close()
|
|
137
|
+
key = (event)
|
|
138
|
+
handleKey(event, -1)
|
|
139
|
+
outside = (event)
|
|
140
|
+
if !@panel.hidden and !@element.contains(event.target)
|
|
141
|
+
close()
|
|
142
|
+
listen(@input, "click", toggle)
|
|
143
|
+
listen(@input, "keydown", key)
|
|
144
|
+
listen(document, "pointerdown", outside)
|
|
145
|
+
listen(document, "focusin", outside)
|
|
146
|
+
|
|
147
|
+
ComboBox:listen(element, type, listener)
|
|
148
|
+
element.addEventListener(type, listener)
|
|
149
|
+
release = ()
|
|
150
|
+
capture element
|
|
151
|
+
capture type
|
|
152
|
+
capture listener
|
|
153
|
+
element.removeEventListener(type, listener)
|
|
154
|
+
@release.add(release)
|
|
155
|
+
return null
|
|
156
|
+
|
|
157
|
+
ComboBox:getValue()
|
|
158
|
+
values = []
|
|
159
|
+
for @selected as index
|
|
160
|
+
option = @options[index]
|
|
161
|
+
values.add(option.value)
|
|
162
|
+
if @multi
|
|
163
|
+
return values
|
|
164
|
+
if values.length > 0
|
|
165
|
+
return values[0]
|
|
166
|
+
return null
|
|
167
|
+
|
|
168
|
+
ComboBox:setValue(value)
|
|
169
|
+
selected = comboSelection(@options, value, @multi)
|
|
170
|
+
@selected = selected
|
|
171
|
+
paint()
|
|
172
|
+
return @this
|
|
173
|
+
|
|
174
|
+
ComboBox:paint()
|
|
175
|
+
labels = []
|
|
176
|
+
index = 0
|
|
177
|
+
for @elements as item
|
|
178
|
+
if item != null
|
|
179
|
+
selected = @selected.includes(index)
|
|
180
|
+
item.setAttribute("aria-selected", "${selected}")
|
|
181
|
+
item.classList.toggle("active", selected)
|
|
182
|
+
index = index + 1
|
|
183
|
+
for @selected as choice
|
|
184
|
+
selectedItem = @elements[choice]
|
|
185
|
+
labels.add(selectedItem.getAttribute("aria-label"))
|
|
186
|
+
@input.textContent = labels.join(", ")
|
|
187
|
+
return null
|
|
188
|
+
|
|
189
|
+
ComboBox:setDisabled(value)
|
|
190
|
+
@input.disabled = value or @locked == true
|
|
191
|
+
if @input.disabled and @panel != null
|
|
192
|
+
close()
|
|
193
|
+
return @this
|
|
194
|
+
|
|
195
|
+
ComboBox:open(last = false)
|
|
196
|
+
if @input.disabled
|
|
197
|
+
return @this
|
|
198
|
+
@panel.hidden = false
|
|
199
|
+
@input.setAttribute("aria-expanded", "true")
|
|
200
|
+
candidates = []
|
|
201
|
+
index = 0
|
|
202
|
+
for @elements as item
|
|
203
|
+
if item != null
|
|
204
|
+
candidates.add(index)
|
|
205
|
+
index = index + 1
|
|
206
|
+
if candidates.length > 0
|
|
207
|
+
position = 0
|
|
208
|
+
if last
|
|
209
|
+
position = candidates.length - 1
|
|
210
|
+
@cursor = candidates[position]
|
|
211
|
+
if !last and @selected.length > 0
|
|
212
|
+
@cursor = @selected[0]
|
|
213
|
+
focusChoice(@cursor)
|
|
214
|
+
return @this
|
|
215
|
+
|
|
216
|
+
ComboBox:close(focus = false)
|
|
217
|
+
@panel.hidden = true
|
|
218
|
+
@input.setAttribute("aria-expanded", "false")
|
|
219
|
+
if focus
|
|
220
|
+
@input.focus()
|
|
221
|
+
return @this
|
|
222
|
+
|
|
223
|
+
ComboBox:focusChoice(index)
|
|
224
|
+
item = @elements[index]
|
|
225
|
+
item.focus()
|
|
226
|
+
return null
|
|
227
|
+
|
|
228
|
+
ComboBox:choose(index)
|
|
229
|
+
if @input.disabled
|
|
230
|
+
return null
|
|
231
|
+
option = @options[index]
|
|
232
|
+
if option.value == null
|
|
233
|
+
return null
|
|
234
|
+
if @multi
|
|
235
|
+
position = @selected.indexOf(index)
|
|
236
|
+
if position < 0
|
|
237
|
+
@selected.add(index)
|
|
238
|
+
else
|
|
239
|
+
@selected.splice(position, 1)
|
|
240
|
+
else
|
|
241
|
+
@selected = [index]
|
|
242
|
+
paint()
|
|
243
|
+
if !@multi
|
|
244
|
+
close(true)
|
|
245
|
+
if option.url != null
|
|
246
|
+
return chain @form.send(option.url)
|
|
247
|
+
catch(error)
|
|
248
|
+
@form.app.error(@form, error)
|
|
249
|
+
return null
|
|
250
|
+
|
|
251
|
+
ComboBox:handleKey(event, index)
|
|
252
|
+
if event.key == "Escape"
|
|
253
|
+
event.preventDefault()
|
|
254
|
+
event.stopPropagation()
|
|
255
|
+
close(true)
|
|
256
|
+
return null
|
|
257
|
+
if index < 0
|
|
258
|
+
switch event.key
|
|
259
|
+
case "ArrowDown"
|
|
260
|
+
event.preventDefault()
|
|
261
|
+
open()
|
|
262
|
+
case "ArrowUp"
|
|
263
|
+
event.preventDefault()
|
|
264
|
+
open(true)
|
|
265
|
+
return null
|
|
266
|
+
if event.key == "Enter" or event.key == " "
|
|
267
|
+
event.preventDefault()
|
|
268
|
+
choose(index)
|
|
269
|
+
return null
|
|
270
|
+
candidates = []
|
|
271
|
+
position = 0
|
|
272
|
+
for @elements as item
|
|
273
|
+
if item != null
|
|
274
|
+
candidates.add(position)
|
|
275
|
+
position = position + 1
|
|
276
|
+
target = candidates.indexOf(index)
|
|
277
|
+
switch event.key
|
|
278
|
+
case "ArrowDown"
|
|
279
|
+
target = (target + 1) % candidates.length
|
|
280
|
+
case "ArrowUp"
|
|
281
|
+
target = (target + candidates.length - 1) % candidates.length
|
|
282
|
+
case "Home"
|
|
283
|
+
target = 0
|
|
284
|
+
case "End"
|
|
285
|
+
target = candidates.length - 1
|
|
286
|
+
else
|
|
287
|
+
return null
|
|
288
|
+
event.preventDefault()
|
|
289
|
+
@cursor = candidates[target]
|
|
290
|
+
focusChoice(@cursor)
|
|
291
|
+
return null
|
|
292
|
+
|
|
293
|
+
ComboBox:dispose()
|
|
294
|
+
for @slots as slot
|
|
295
|
+
slot.dispose()
|
|
296
|
+
@slots = []
|
|
297
|
+
super.dispose()
|
|
298
|
+
return null
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import js global document
|
|
2
|
+
|
|
3
|
+
export appendContent(form, element, content, renderer)
|
|
4
|
+
export bindAction(control, element, url)
|
|
5
|
+
export decorate(control, props)
|
|
6
|
+
|
|
7
|
+
decorate(control, props)
|
|
8
|
+
if props.style != null
|
|
9
|
+
for props.style as name: value
|
|
10
|
+
control.element.style.setProperty(name, value)
|
|
11
|
+
if props.aria != null
|
|
12
|
+
for props.aria as name: value
|
|
13
|
+
control.element.setAttribute("aria-${name}", value)
|
|
14
|
+
return null
|
|
15
|
+
|
|
16
|
+
appendContent(form, element, content, renderer)
|
|
17
|
+
if content == null
|
|
18
|
+
return null
|
|
19
|
+
if is_array(content)
|
|
20
|
+
for content as value
|
|
21
|
+
appendContent(form, element, value, renderer)
|
|
22
|
+
else
|
|
23
|
+
if is_object(content) and is_string(content.type)
|
|
24
|
+
if renderer == null
|
|
25
|
+
throw "Control content requires a renderer"
|
|
26
|
+
element.appendChild(renderer.build(form, content))
|
|
27
|
+
else
|
|
28
|
+
if !is_string(content) and !is_number(content)
|
|
29
|
+
throw "Content must be text or a control"
|
|
30
|
+
element.appendChild(document/createTextNode("${content}"))
|
|
31
|
+
return null
|
|
32
|
+
|
|
33
|
+
bindAction(control, element, url)
|
|
34
|
+
if url == null
|
|
35
|
+
return null
|
|
36
|
+
control.form.app.checkUrl(url)
|
|
37
|
+
element.tabIndex = 0
|
|
38
|
+
click = (event)
|
|
39
|
+
capture control
|
|
40
|
+
capture element
|
|
41
|
+
capture url
|
|
42
|
+
if event.defaultPrevented
|
|
43
|
+
return null
|
|
44
|
+
interactive = event.target.closest("button, a, input, select, textarea, label, [role=button], [role=tab], [contenteditable=true]")
|
|
45
|
+
if interactive != null and interactive != element
|
|
46
|
+
return null
|
|
47
|
+
event.preventDefault()
|
|
48
|
+
event.stopPropagation()
|
|
49
|
+
sendAction(control, url)
|
|
50
|
+
key = (event)
|
|
51
|
+
capture control
|
|
52
|
+
capture element
|
|
53
|
+
capture url
|
|
54
|
+
if event.target != element or (event.key != "Enter" and event.key != " ")
|
|
55
|
+
return null
|
|
56
|
+
event.preventDefault()
|
|
57
|
+
event.stopPropagation()
|
|
58
|
+
sendAction(control, url)
|
|
59
|
+
element.addEventListener("click", click)
|
|
60
|
+
element.addEventListener("keydown", key)
|
|
61
|
+
release = ()
|
|
62
|
+
capture element
|
|
63
|
+
capture click
|
|
64
|
+
capture key
|
|
65
|
+
element.removeEventListener("click", click)
|
|
66
|
+
element.removeEventListener("keydown", key)
|
|
67
|
+
releases = control.release
|
|
68
|
+
releases.add(release)
|
|
69
|
+
return null
|
|
70
|
+
|
|
71
|
+
sendAction(control, url)
|
|
72
|
+
return chain control.form.send(url)
|
|
73
|
+
catch(error)
|
|
74
|
+
capture control
|
|
75
|
+
control.form.app.error(control.form, error)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import js global document
|
|
2
|
+
import "./templates"
|
|
3
|
+
controlId()
|
|
4
|
+
|
|
5
|
+
export class Control(form, props, element)
|
|
6
|
+
properties
|
|
7
|
+
form
|
|
8
|
+
element
|
|
9
|
+
release
|
|
10
|
+
methods
|
|
11
|
+
getValue()
|
|
12
|
+
setValue(value)
|
|
13
|
+
setDisabled(value)
|
|
14
|
+
setCaption(value)
|
|
15
|
+
validationTarget(element)
|
|
16
|
+
setInvalid(message)
|
|
17
|
+
clearValidation()
|
|
18
|
+
dispose()
|
|
19
|
+
|
|
20
|
+
Control(form, props, element)
|
|
21
|
+
@form = form
|
|
22
|
+
@element = element
|
|
23
|
+
@value = props.value
|
|
24
|
+
@release = []
|
|
25
|
+
@feedback = null
|
|
26
|
+
validationTarget(element)
|
|
27
|
+
|
|
28
|
+
Control:getValue()
|
|
29
|
+
return null
|
|
30
|
+
|
|
31
|
+
Control:setValue(value)
|
|
32
|
+
@value = value
|
|
33
|
+
return @this
|
|
34
|
+
|
|
35
|
+
Control:setDisabled(value)
|
|
36
|
+
@element.disabled = value
|
|
37
|
+
return @this
|
|
38
|
+
|
|
39
|
+
Control:setCaption(value)
|
|
40
|
+
@element.textContent = value
|
|
41
|
+
return @this
|
|
42
|
+
|
|
43
|
+
Control:validationTarget(element)
|
|
44
|
+
@target = element
|
|
45
|
+
@describedBy = element.getAttribute("aria-describedby")
|
|
46
|
+
@invalid = element.getAttribute("aria-invalid")
|
|
47
|
+
return null
|
|
48
|
+
|
|
49
|
+
Control:setInvalid(message)
|
|
50
|
+
clearValidation()
|
|
51
|
+
@feedback = document/createElement("div")
|
|
52
|
+
@feedback.id = controlId()
|
|
53
|
+
@feedback.className = "invalid-feedback d-block"
|
|
54
|
+
@feedback.textContent = message
|
|
55
|
+
@target.classList.add("is-invalid")
|
|
56
|
+
@target.setAttribute("aria-invalid", "true")
|
|
57
|
+
description = @feedback.id
|
|
58
|
+
if @describedBy != null and @describedBy != ""
|
|
59
|
+
description = "${@describedBy} ${description}"
|
|
60
|
+
@target.setAttribute("aria-describedby", description)
|
|
61
|
+
@element.appendChild(@feedback)
|
|
62
|
+
return @this
|
|
63
|
+
|
|
64
|
+
Control:clearValidation()
|
|
65
|
+
if @feedback != null
|
|
66
|
+
@feedback.remove()
|
|
67
|
+
@feedback = null
|
|
68
|
+
@target.classList.remove("is-invalid")
|
|
69
|
+
if @invalid == null
|
|
70
|
+
@target.removeAttribute("aria-invalid")
|
|
71
|
+
else
|
|
72
|
+
@target.setAttribute("aria-invalid", @invalid)
|
|
73
|
+
if @describedBy == null
|
|
74
|
+
@target.removeAttribute("aria-describedby")
|
|
75
|
+
else
|
|
76
|
+
@target.setAttribute("aria-describedby", @describedBy)
|
|
77
|
+
return null
|
|
78
|
+
|
|
79
|
+
Control:dispose()
|
|
80
|
+
clearValidation()
|
|
81
|
+
for @release as release
|
|
82
|
+
release()
|
|
83
|
+
@release = []
|
|
84
|
+
return null
|
|
85
|
+
|
|
86
|
+
export class Value(form, props, element) : Control
|
|
87
|
+
methods
|
|
88
|
+
getValue()
|
|
89
|
+
setValue(value)
|
|
90
|
+
|
|
91
|
+
Value(form, props, element)
|
|
92
|
+
super(form, props, element)
|
|
93
|
+
@value = props.value
|
|
94
|
+
|
|
95
|
+
Value:getValue()
|
|
96
|
+
return @value
|
|
97
|
+
|
|
98
|
+
Value:setValue(value)
|
|
99
|
+
@value = value
|
|
100
|
+
return @this
|
package/src/create.lango
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import js "node:fs" as fs
|
|
2
|
+
import js "node:path" as path
|
|
3
|
+
import js global process
|
|
4
|
+
|
|
5
|
+
export main(args)
|
|
6
|
+
export copyClient(source, destination, update = false)
|
|
7
|
+
|
|
8
|
+
copyClient(source, destination, update = false)
|
|
9
|
+
source = path/resolve(source)
|
|
10
|
+
destination = path/resolve(destination)
|
|
11
|
+
relative = path/relative(source, destination)
|
|
12
|
+
if relative == "" or (relative != ".." and !relative.startsWith("..${path.sep}") and !path/isAbsolute(relative))
|
|
13
|
+
throw "Destination must be outside the client distribution"
|
|
14
|
+
if !fs/existsSync(path/join(source, "index.html")) or !fs/existsSync(path/join(source, "boot.mjs"))
|
|
15
|
+
throw "Client distribution is missing; build the package first"
|
|
16
|
+
if fs/existsSync(destination)
|
|
17
|
+
if !fs/statSync(destination).isDirectory()
|
|
18
|
+
throw "Client destination must be a directory"
|
|
19
|
+
if !update and fs/readdirSync(destination).length > 0
|
|
20
|
+
throw "Client destination is not empty; --update refreshes generated assets"
|
|
21
|
+
fs/mkdirSync(destination, {
|
|
22
|
+
recursive: true
|
|
23
|
+
})
|
|
24
|
+
fs/cpSync(source, destination, {
|
|
25
|
+
recursive: true
|
|
26
|
+
force: update
|
|
27
|
+
errorOnExist: !update
|
|
28
|
+
})
|
|
29
|
+
return destination
|
|
30
|
+
|
|
31
|
+
main(args)
|
|
32
|
+
if args.length == 0 or args[0] == "--help"
|
|
33
|
+
println("Usage: lango-client <directory> [--update]")
|
|
34
|
+
println("Write the same-origin Web/Bootstrap browser application to a static directory.")
|
|
35
|
+
return null
|
|
36
|
+
if args.length > 2 or (args.length == 2 and args[1] != "--update")
|
|
37
|
+
throw "Usage: lango-client <directory> [--update]"
|
|
38
|
+
executable = fs/realpathSync(process.argv[1])
|
|
39
|
+
source = path/resolve(path/dirname(executable), "../dist")
|
|
40
|
+
directory = copyClient(source, args[0], args.length == 2)
|
|
41
|
+
println("Browser assets written to ${directory}")
|
|
42
|
+
return null
|