@lango-project/lango-client 0.2.1 → 0.4.1
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 +603 -906
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +120 -20
- 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 +120 -20
- 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 +671 -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 +102 -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 +141 -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/dimensions.mjs +102 -0
- package/dist/dimensions.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 +147 -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 +295 -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/table_scope.mjs +166 -0
- package/dist/table_scope.mjs.map +1 -0
- package/dist/tables.mjs +1052 -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 +2454 -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 +93 -0
- package/package.json +25 -43
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +540 -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 +103 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -0
- package/src/dimensions.lango +65 -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 +118 -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 +296 -0
- package/src/rich_content.lango +66 -0
- package/src/table_scope.lango +119 -0
- package/src/tables.lango +786 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +102 -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
package/src/tables.lango
ADDED
|
@@ -0,0 +1,786 @@
|
|
|
1
|
+
import js global getComputedStyle
|
|
2
|
+
import "./dimensions"
|
|
3
|
+
measure(value, unit)
|
|
4
|
+
import js global document
|
|
5
|
+
import js global Number
|
|
6
|
+
import js global Math
|
|
7
|
+
import js global Object
|
|
8
|
+
import js global Reflect
|
|
9
|
+
import js global JSON
|
|
10
|
+
import js global Promise
|
|
11
|
+
import js global structuredClone
|
|
12
|
+
import "./table_scope"
|
|
13
|
+
class TableScope
|
|
14
|
+
import "./control"
|
|
15
|
+
class Control
|
|
16
|
+
import "./form"
|
|
17
|
+
class Form
|
|
18
|
+
import "./templates"
|
|
19
|
+
cloneMarkup(name, xml)
|
|
20
|
+
import "./content"
|
|
21
|
+
appendContent(form, element, content, renderer)
|
|
22
|
+
bindAction(control, element, url)
|
|
23
|
+
decorate(control, props)
|
|
24
|
+
|
|
25
|
+
export spanValue(value)
|
|
26
|
+
export columnWidth(value)
|
|
27
|
+
|
|
28
|
+
spanValue(value)
|
|
29
|
+
if value == null
|
|
30
|
+
return 1
|
|
31
|
+
if !is_number(value) or !Number/isInteger(value) or value < 1 or value > 1000
|
|
32
|
+
throw "Table span must be an integer between 1 and 1000"
|
|
33
|
+
return value
|
|
34
|
+
|
|
35
|
+
applySpan(element, name, value)
|
|
36
|
+
span = spanValue(value)
|
|
37
|
+
if span == 1
|
|
38
|
+
element.removeAttribute(name)
|
|
39
|
+
else
|
|
40
|
+
element.setAttribute(name, "${span}")
|
|
41
|
+
return null
|
|
42
|
+
|
|
43
|
+
columnWidth(value)
|
|
44
|
+
return measure(value, "ch")
|
|
45
|
+
|
|
46
|
+
export class Table(form, props, renderer) : Control
|
|
47
|
+
properties
|
|
48
|
+
rows
|
|
49
|
+
columns
|
|
50
|
+
methods
|
|
51
|
+
find(name)
|
|
52
|
+
getValue()
|
|
53
|
+
prepareValue()
|
|
54
|
+
clearValidation()
|
|
55
|
+
setValue(values)
|
|
56
|
+
addRow(value = null)
|
|
57
|
+
insertRow(beforeIndex, value = null)
|
|
58
|
+
deleteRow(index)
|
|
59
|
+
setRowValue(index, value)
|
|
60
|
+
setRowData(index, value)
|
|
61
|
+
setCellValue(index, column, value)
|
|
62
|
+
createRow(value)
|
|
63
|
+
names(rows, replace = false)
|
|
64
|
+
publish(names)
|
|
65
|
+
resize(rows)
|
|
66
|
+
dispose()
|
|
67
|
+
|
|
68
|
+
Table(form, props, renderer)
|
|
69
|
+
super(form, props, cloneMarkup("table", <div class="table-responsive"><table class="table"><colgroup></colgroup><tbody></tbody></table></div>))
|
|
70
|
+
@renderer = renderer
|
|
71
|
+
@props = props
|
|
72
|
+
@building = true
|
|
73
|
+
@mode = props.valueMode
|
|
74
|
+
if @mode == null
|
|
75
|
+
@mode = "none"
|
|
76
|
+
modes = ["none", "cells", "rows", "mixed"]
|
|
77
|
+
if !modes.includes(@mode)
|
|
78
|
+
throw "Table valueMode must be none, cells, rows or mixed"
|
|
79
|
+
@layout = new TableScope(form)
|
|
80
|
+
@lookup = new TableScope(form)
|
|
81
|
+
@rows = []
|
|
82
|
+
@columns = []
|
|
83
|
+
@header = null
|
|
84
|
+
@aliases = Object/create(null)
|
|
85
|
+
@table = @element.firstElementChild
|
|
86
|
+
@body = @table.lastElementChild
|
|
87
|
+
@template = props.rowTemplate
|
|
88
|
+
if @template != null and @template.type != "tableRowTemplate"
|
|
89
|
+
throw "Table rowTemplate requires a TableRowTemplate"
|
|
90
|
+
table = @table
|
|
91
|
+
group = table.firstElementChild
|
|
92
|
+
headings = []
|
|
93
|
+
hasCaptions = false
|
|
94
|
+
try
|
|
95
|
+
if props.stripedRows == true
|
|
96
|
+
table.classList.add("table-striped")
|
|
97
|
+
if props.stripedColumns == true
|
|
98
|
+
table.classList.add("table-striped-columns")
|
|
99
|
+
if props.hoverableRows == true
|
|
100
|
+
table.classList.add("table-hover")
|
|
101
|
+
if props.small == true
|
|
102
|
+
table.classList.add("table-sm")
|
|
103
|
+
if props.border != null and props.border != false
|
|
104
|
+
table.classList.add("table-bordered")
|
|
105
|
+
if is_object(props.border)
|
|
106
|
+
if props.border.color != null
|
|
107
|
+
table.style.setProperty("--bs-table-border-color", props.border.color)
|
|
108
|
+
if props.border.width != null
|
|
109
|
+
table.style.setProperty("--bs-border-width", "${props.border.width}px")
|
|
110
|
+
if props.caption != null
|
|
111
|
+
caption = document/createElement("caption")
|
|
112
|
+
appendContent(@layout, caption, props.caption, renderer)
|
|
113
|
+
table.prepend(caption)
|
|
114
|
+
if props.aria != null
|
|
115
|
+
for props.aria as name: value
|
|
116
|
+
table.setAttribute("aria-${name}", value)
|
|
117
|
+
if props.controls != null
|
|
118
|
+
for props.controls as definition
|
|
119
|
+
switch definition.type
|
|
120
|
+
case "tableCol"
|
|
121
|
+
col = new TableCol(@layout, definition)
|
|
122
|
+
@layout.register(null, col)
|
|
123
|
+
col.name = definition.name
|
|
124
|
+
if col.name != null
|
|
125
|
+
for @columns as previous
|
|
126
|
+
if previous.name == col.name
|
|
127
|
+
throw "Duplicate column name: ${col.name}"
|
|
128
|
+
@columns.add(col)
|
|
129
|
+
headings.add({
|
|
130
|
+
type: "tableCell"
|
|
131
|
+
colSpan: definition.colSpan
|
|
132
|
+
controls: definition.caption
|
|
133
|
+
})
|
|
134
|
+
if definition.caption != null
|
|
135
|
+
hasCaptions = true
|
|
136
|
+
group.appendChild(col.element)
|
|
137
|
+
case "tableHeader"
|
|
138
|
+
if @header != null
|
|
139
|
+
throw "Table accepts one TableHeader"
|
|
140
|
+
@header = new TableHeader(@layout, definition, renderer)
|
|
141
|
+
@layout.register(definition.name, @header)
|
|
142
|
+
table.insertBefore(@header.element, @body)
|
|
143
|
+
case "tableRow"
|
|
144
|
+
row = new TableRow(form, definition, renderer, false)
|
|
145
|
+
@rows.add(row)
|
|
146
|
+
@body.appendChild(row.element)
|
|
147
|
+
case "tableDivider"
|
|
148
|
+
divider = new TableDivider(@layout, definition)
|
|
149
|
+
@layout.register(definition.name, divider)
|
|
150
|
+
@body.appendChild(divider.element)
|
|
151
|
+
else
|
|
152
|
+
throw "Unsupported Table child: ${definition.type}"
|
|
153
|
+
if @header == null and hasCaptions
|
|
154
|
+
generated = {
|
|
155
|
+
controls: [{
|
|
156
|
+
type: "tableRow"
|
|
157
|
+
controls: headings
|
|
158
|
+
}]
|
|
159
|
+
}
|
|
160
|
+
@header = new TableHeader(@layout, generated, renderer)
|
|
161
|
+
@layout.register(null, @header)
|
|
162
|
+
table.insertBefore(@header.element, @body)
|
|
163
|
+
width = 1
|
|
164
|
+
for @rows as row
|
|
165
|
+
width = Math/max(width, row.width)
|
|
166
|
+
for @layout.owned as child
|
|
167
|
+
if is_kindof(child, TableDivider)
|
|
168
|
+
applySpan(child.element.firstElementChild, "colspan", width)
|
|
169
|
+
if props.value != null
|
|
170
|
+
setValue(props.value)
|
|
171
|
+
else
|
|
172
|
+
publish(names(@rows))
|
|
173
|
+
resize(@rows)
|
|
174
|
+
@building = false
|
|
175
|
+
catch error
|
|
176
|
+
dispose()
|
|
177
|
+
throw error
|
|
178
|
+
|
|
179
|
+
Table:find(name)
|
|
180
|
+
return @lookup.find(name)
|
|
181
|
+
|
|
182
|
+
Table:names(rows, replace = false)
|
|
183
|
+
result = Object/create(null)
|
|
184
|
+
for @layout.controls as name: control
|
|
185
|
+
if !replace or !is_kindof(control, TableDivider)
|
|
186
|
+
addName(result, name, control)
|
|
187
|
+
sources = rows.slice()
|
|
188
|
+
if @header != null
|
|
189
|
+
for @header.rows as row
|
|
190
|
+
sources.add(row)
|
|
191
|
+
for sources as row
|
|
192
|
+
addName(result, row.name, row)
|
|
193
|
+
for row.cells as cell
|
|
194
|
+
if cell.name != null
|
|
195
|
+
addName(result, cell.name, cell)
|
|
196
|
+
else
|
|
197
|
+
if !row.generated
|
|
198
|
+
for cell.scope.controls as name: control
|
|
199
|
+
addName(result, name, control)
|
|
200
|
+
return result
|
|
201
|
+
|
|
202
|
+
Table:publish(names)
|
|
203
|
+
if @props.name == null
|
|
204
|
+
for names as name: control
|
|
205
|
+
if name in @form.controls and @form.controls[name] != @aliases[name]
|
|
206
|
+
throw "Invalid or duplicate control name: ${name}"
|
|
207
|
+
for @aliases as name: control
|
|
208
|
+
if @form.controls[name] == control
|
|
209
|
+
Reflect/deleteProperty(@form.controls, name)
|
|
210
|
+
for names as name: control
|
|
211
|
+
@form.controls[name] = control
|
|
212
|
+
@aliases = names
|
|
213
|
+
@lookup.controls = names
|
|
214
|
+
return null
|
|
215
|
+
|
|
216
|
+
Table:getValue()
|
|
217
|
+
if @mode == "none"
|
|
218
|
+
return null
|
|
219
|
+
if @mode == "cells"
|
|
220
|
+
return @lookup.getValue()
|
|
221
|
+
rows = []
|
|
222
|
+
for @rows as row
|
|
223
|
+
rows.add(row.getRowValue(@columns))
|
|
224
|
+
if @mode == "rows"
|
|
225
|
+
return rows
|
|
226
|
+
return {
|
|
227
|
+
cells: @lookup.getValue()
|
|
228
|
+
rows: rows
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
Table:prepareValue()
|
|
232
|
+
pending = []
|
|
233
|
+
ready = @layout.prepareValue()
|
|
234
|
+
if ready != null
|
|
235
|
+
pending.add(ready)
|
|
236
|
+
for @rows as row
|
|
237
|
+
ready = row.prepareValue()
|
|
238
|
+
if ready != null
|
|
239
|
+
pending.add(ready)
|
|
240
|
+
return allReady(pending)
|
|
241
|
+
|
|
242
|
+
Table:clearValidation()
|
|
243
|
+
super.clearValidation()
|
|
244
|
+
if @layout != null
|
|
245
|
+
@layout.clearValidation()
|
|
246
|
+
if @rows != null
|
|
247
|
+
for @rows as row
|
|
248
|
+
row.clearValidation()
|
|
249
|
+
return null
|
|
250
|
+
|
|
251
|
+
Table:createRow(value)
|
|
252
|
+
rowValue(value)
|
|
253
|
+
definition = null
|
|
254
|
+
if @template != null
|
|
255
|
+
definition = structuredClone(@template)
|
|
256
|
+
else
|
|
257
|
+
cells = []
|
|
258
|
+
for @columns as column
|
|
259
|
+
cells.add({
|
|
260
|
+
type: "tableCell"
|
|
261
|
+
colSpan: column.span
|
|
262
|
+
})
|
|
263
|
+
definition = {
|
|
264
|
+
controls: cells
|
|
265
|
+
}
|
|
266
|
+
row = new TableRow(@form, definition, @renderer, false)
|
|
267
|
+
row.generated = true
|
|
268
|
+
try
|
|
269
|
+
row.setRowValue(value, @columns)
|
|
270
|
+
catch error
|
|
271
|
+
row.dispose()
|
|
272
|
+
throw error
|
|
273
|
+
return row
|
|
274
|
+
|
|
275
|
+
Table:setValue(values)
|
|
276
|
+
if values == null
|
|
277
|
+
values = []
|
|
278
|
+
if !is_array(values)
|
|
279
|
+
throw "Table value must be an array of row maps"
|
|
280
|
+
staged = []
|
|
281
|
+
try
|
|
282
|
+
for values as value
|
|
283
|
+
staged.add(createRow(value))
|
|
284
|
+
next = names(staged, true)
|
|
285
|
+
validateBoundaries(@header, staged, @columns)
|
|
286
|
+
publish(next)
|
|
287
|
+
catch error
|
|
288
|
+
for staged as row
|
|
289
|
+
row.dispose()
|
|
290
|
+
throw error
|
|
291
|
+
if !@building
|
|
292
|
+
@form.clearResources()
|
|
293
|
+
for @rows as row
|
|
294
|
+
row.dispose()
|
|
295
|
+
@rows = staged
|
|
296
|
+
@body.replaceChildren()
|
|
297
|
+
for @layout.owned.slice() as child
|
|
298
|
+
if is_kindof(child, TableDivider)
|
|
299
|
+
@layout.unregister(child)
|
|
300
|
+
child.dispose()
|
|
301
|
+
for staged as row
|
|
302
|
+
@body.appendChild(row.element)
|
|
303
|
+
resize(staged)
|
|
304
|
+
return @this
|
|
305
|
+
|
|
306
|
+
Table:addRow(value = null)
|
|
307
|
+
return insertRow(@rows.length, value)
|
|
308
|
+
|
|
309
|
+
Table:insertRow(beforeIndex, value = null)
|
|
310
|
+
tableIndex(beforeIndex, @rows.length, true)
|
|
311
|
+
row = createRow(value)
|
|
312
|
+
staged = @rows.slice()
|
|
313
|
+
staged.splice(beforeIndex, 0, row)
|
|
314
|
+
try
|
|
315
|
+
next = names(staged)
|
|
316
|
+
validateBoundaries(@header, staged, @columns)
|
|
317
|
+
publish(next)
|
|
318
|
+
catch error
|
|
319
|
+
row.dispose()
|
|
320
|
+
throw error
|
|
321
|
+
@form.clearResources()
|
|
322
|
+
anchor = null
|
|
323
|
+
if beforeIndex < @rows.length
|
|
324
|
+
anchor = @rows[beforeIndex].element
|
|
325
|
+
@body.insertBefore(row.element, anchor)
|
|
326
|
+
@rows = staged
|
|
327
|
+
resize(staged)
|
|
328
|
+
return @this
|
|
329
|
+
|
|
330
|
+
Table:deleteRow(index)
|
|
331
|
+
tableIndex(index, @rows.length)
|
|
332
|
+
staged = @rows.slice()
|
|
333
|
+
row = staged.splice(index, 1)[0]
|
|
334
|
+
validateBoundaries(@header, staged, @columns)
|
|
335
|
+
publish(names(staged))
|
|
336
|
+
@form.clearResources()
|
|
337
|
+
row.dispose()
|
|
338
|
+
row.element.remove()
|
|
339
|
+
@rows = staged
|
|
340
|
+
resize(staged)
|
|
341
|
+
return @this
|
|
342
|
+
|
|
343
|
+
Table:setRowValue(index, value)
|
|
344
|
+
tableIndex(index, @rows.length)
|
|
345
|
+
@rows[index].setRowValue(value, @columns)
|
|
346
|
+
return @this
|
|
347
|
+
|
|
348
|
+
Table:setRowData(index, value)
|
|
349
|
+
tableIndex(index, @rows.length)
|
|
350
|
+
row = @rows[index]
|
|
351
|
+
row.data = structuredClone(value)
|
|
352
|
+
return @this
|
|
353
|
+
|
|
354
|
+
Table:setCellValue(index, column, value)
|
|
355
|
+
tableIndex(index, @rows.length)
|
|
356
|
+
selected = columnIndex(column, @columns)
|
|
357
|
+
row = @rows[index]
|
|
358
|
+
tableIndex(selected, row.cells.length)
|
|
359
|
+
row.cells[selected].setValue(value)
|
|
360
|
+
return @this
|
|
361
|
+
|
|
362
|
+
Table:resize(rows)
|
|
363
|
+
width = 1
|
|
364
|
+
for rows as row
|
|
365
|
+
width = Math/max(width, row.width)
|
|
366
|
+
if @header != null
|
|
367
|
+
for @header.rows as row
|
|
368
|
+
width = Math/max(width, row.width)
|
|
369
|
+
for @layout.owned as child
|
|
370
|
+
if is_kindof(child, TableDivider)
|
|
371
|
+
applySpan(child.element.firstElementChild, "colspan", width)
|
|
372
|
+
for @columns as col
|
|
373
|
+
col.detach()
|
|
374
|
+
first = validateBoundaries(@header, rows, @columns)
|
|
375
|
+
if first != null
|
|
376
|
+
offset = 0
|
|
377
|
+
for @columns as col
|
|
378
|
+
offset = offset + col.span
|
|
379
|
+
if col.resize
|
|
380
|
+
col.attach(first.boundary(offset), @table)
|
|
381
|
+
return null
|
|
382
|
+
|
|
383
|
+
Table:dispose()
|
|
384
|
+
if @aliases != null
|
|
385
|
+
for @aliases as name: control
|
|
386
|
+
if @form.controls[name] == control
|
|
387
|
+
Reflect/deleteProperty(@form.controls, name)
|
|
388
|
+
@aliases = Object/create(null)
|
|
389
|
+
if @rows != null
|
|
390
|
+
for @rows as row
|
|
391
|
+
row.dispose()
|
|
392
|
+
@rows = []
|
|
393
|
+
if @layout != null
|
|
394
|
+
@layout.dispose()
|
|
395
|
+
return super.dispose()
|
|
396
|
+
|
|
397
|
+
export class TableHeader(form, props, renderer) : Control
|
|
398
|
+
properties
|
|
399
|
+
rows
|
|
400
|
+
methods
|
|
401
|
+
prepareValue()
|
|
402
|
+
clearValidation()
|
|
403
|
+
dispose()
|
|
404
|
+
|
|
405
|
+
TableHeader(form, props, renderer)
|
|
406
|
+
super(form, props, cloneMarkup("table-header", <thead></thead>))
|
|
407
|
+
decorate(@this, props)
|
|
408
|
+
@rows = []
|
|
409
|
+
try
|
|
410
|
+
if props.controls != null
|
|
411
|
+
for props.controls as definition
|
|
412
|
+
if definition.type != "tableRow"
|
|
413
|
+
throw "TableHeader accepts TableRow definitions"
|
|
414
|
+
row = new TableRow(form, definition, renderer, true)
|
|
415
|
+
@rows.add(row)
|
|
416
|
+
@element.appendChild(row.element)
|
|
417
|
+
catch error
|
|
418
|
+
dispose()
|
|
419
|
+
throw error
|
|
420
|
+
|
|
421
|
+
TableHeader:prepareValue()
|
|
422
|
+
pending = []
|
|
423
|
+
for @rows as row
|
|
424
|
+
ready = row.prepareValue()
|
|
425
|
+
if ready != null
|
|
426
|
+
pending.add(ready)
|
|
427
|
+
return allReady(pending)
|
|
428
|
+
|
|
429
|
+
TableHeader:clearValidation()
|
|
430
|
+
super.clearValidation()
|
|
431
|
+
if @rows != null
|
|
432
|
+
for @rows as row
|
|
433
|
+
row.clearValidation()
|
|
434
|
+
return null
|
|
435
|
+
|
|
436
|
+
TableHeader:dispose()
|
|
437
|
+
for @rows as row
|
|
438
|
+
row.dispose()
|
|
439
|
+
@rows = []
|
|
440
|
+
return super.dispose()
|
|
441
|
+
|
|
442
|
+
export class TableRow(form, props, renderer, heading) : Control
|
|
443
|
+
properties
|
|
444
|
+
name
|
|
445
|
+
data
|
|
446
|
+
generated
|
|
447
|
+
width
|
|
448
|
+
cells
|
|
449
|
+
methods
|
|
450
|
+
boundary(column)
|
|
451
|
+
setRowValue(value, columns)
|
|
452
|
+
getRowValue(columns)
|
|
453
|
+
getValue()
|
|
454
|
+
prepareValue()
|
|
455
|
+
clearValidation()
|
|
456
|
+
dispose()
|
|
457
|
+
|
|
458
|
+
TableRow(form, props, renderer, heading)
|
|
459
|
+
super(form, props, cloneMarkup("table-row", <tr></tr>))
|
|
460
|
+
decorate(@this, props)
|
|
461
|
+
@name = props.name
|
|
462
|
+
@data = structuredClone(props.data)
|
|
463
|
+
@generated = false
|
|
464
|
+
@width = 0
|
|
465
|
+
@cells = []
|
|
466
|
+
@scope = new TableScope(form)
|
|
467
|
+
try
|
|
468
|
+
if props.controls != null
|
|
469
|
+
for props.controls as definition
|
|
470
|
+
if definition.type != "tableCell"
|
|
471
|
+
throw "TableRow accepts TableCell definitions"
|
|
472
|
+
cell = new TableCell(@scope, definition, renderer, heading)
|
|
473
|
+
@scope.register(definition.name, cell)
|
|
474
|
+
@cells.add(cell)
|
|
475
|
+
@width = @width + cell.element.colSpan
|
|
476
|
+
@element.appendChild(cell.element)
|
|
477
|
+
bindAction(@this, @element, props.url)
|
|
478
|
+
catch error
|
|
479
|
+
dispose()
|
|
480
|
+
throw error
|
|
481
|
+
|
|
482
|
+
TableRow:boundary(column)
|
|
483
|
+
offset = 0
|
|
484
|
+
for @cells as cell
|
|
485
|
+
offset = offset + cell.element.colSpan
|
|
486
|
+
if offset == column
|
|
487
|
+
return cell.element
|
|
488
|
+
return null
|
|
489
|
+
|
|
490
|
+
TableRow:setRowValue(value, columns)
|
|
491
|
+
rowValue(value)
|
|
492
|
+
for @cells as index: cell
|
|
493
|
+
name = cell.name
|
|
494
|
+
if index < columns.length
|
|
495
|
+
name = columns[index].name
|
|
496
|
+
field = null
|
|
497
|
+
if value != null and name != null and Object/hasOwn(value, name)
|
|
498
|
+
field = value[name]
|
|
499
|
+
cell.setValue(field)
|
|
500
|
+
return @this
|
|
501
|
+
|
|
502
|
+
TableRow:getRowValue(columns)
|
|
503
|
+
result = Object/create(null)
|
|
504
|
+
for @cells as index: cell
|
|
505
|
+
name = cell.name
|
|
506
|
+
if index < columns.length
|
|
507
|
+
name = columns[index].name
|
|
508
|
+
if name != null
|
|
509
|
+
if name in result
|
|
510
|
+
throw "Duplicate row value name: ${name}"
|
|
511
|
+
result[name] = cell.getValue()
|
|
512
|
+
return result
|
|
513
|
+
|
|
514
|
+
TableRow:getValue()
|
|
515
|
+
return @scope.getValue()
|
|
516
|
+
|
|
517
|
+
TableRow:prepareValue()
|
|
518
|
+
return @scope.prepareValue()
|
|
519
|
+
|
|
520
|
+
TableRow:clearValidation()
|
|
521
|
+
super.clearValidation()
|
|
522
|
+
if @scope != null
|
|
523
|
+
@scope.clearValidation()
|
|
524
|
+
return null
|
|
525
|
+
|
|
526
|
+
TableRow:dispose()
|
|
527
|
+
if @scope != null
|
|
528
|
+
@scope.dispose()
|
|
529
|
+
return super.dispose()
|
|
530
|
+
|
|
531
|
+
export class TableCell(form, props, renderer, heading) : Control
|
|
532
|
+
properties
|
|
533
|
+
name
|
|
534
|
+
scope
|
|
535
|
+
methods
|
|
536
|
+
find(name)
|
|
537
|
+
getValue()
|
|
538
|
+
setValue(value)
|
|
539
|
+
prepareValue()
|
|
540
|
+
clearValidation()
|
|
541
|
+
dispose()
|
|
542
|
+
|
|
543
|
+
TableCell(form, props, renderer, heading)
|
|
544
|
+
super(form, props, cellElement(heading))
|
|
545
|
+
@name = props.name
|
|
546
|
+
@scope = new TableScope(form)
|
|
547
|
+
try
|
|
548
|
+
applySpan(@element, "colspan", props.colSpan)
|
|
549
|
+
applySpan(@element, "rowspan", props.rowSpan)
|
|
550
|
+
if props.verticalAlignment != null
|
|
551
|
+
@element.style.verticalAlign = props.verticalAlignment
|
|
552
|
+
if props.horizontalAlignment != null
|
|
553
|
+
@element.style.textAlign = props.horizontalAlignment
|
|
554
|
+
appendContent(@scope, @element, props.controls, renderer)
|
|
555
|
+
decorate(@this, props)
|
|
556
|
+
bindAction(@this, @element, props.url)
|
|
557
|
+
catch error
|
|
558
|
+
dispose()
|
|
559
|
+
throw error
|
|
560
|
+
|
|
561
|
+
TableCell:find(name)
|
|
562
|
+
return @scope.find(name)
|
|
563
|
+
|
|
564
|
+
TableCell:getValue()
|
|
565
|
+
if @scope.owned.length == 0
|
|
566
|
+
return null
|
|
567
|
+
if @scope.owned.length == 1
|
|
568
|
+
return @scope.owned[0].getValue()
|
|
569
|
+
return @scope.getValue()
|
|
570
|
+
|
|
571
|
+
TableCell:setValue(value)
|
|
572
|
+
if @scope.owned.length == 0
|
|
573
|
+
text = ""
|
|
574
|
+
if value != null
|
|
575
|
+
if is_object(value) or is_array(value)
|
|
576
|
+
text = JSON/stringify(value)
|
|
577
|
+
else
|
|
578
|
+
text = "${value}"
|
|
579
|
+
handle = @element.querySelector(":scope > .lango-col-resize")
|
|
580
|
+
@element.textContent = text
|
|
581
|
+
if handle != null
|
|
582
|
+
@element.appendChild(handle)
|
|
583
|
+
else
|
|
584
|
+
if value == null
|
|
585
|
+
for @scope.owned as control
|
|
586
|
+
clearValue(control)
|
|
587
|
+
else
|
|
588
|
+
if @scope.owned.length == 1
|
|
589
|
+
@scope.owned[0].setValue(value)
|
|
590
|
+
else
|
|
591
|
+
@scope.setValue(value)
|
|
592
|
+
return @this
|
|
593
|
+
|
|
594
|
+
TableCell:prepareValue()
|
|
595
|
+
return @scope.prepareValue()
|
|
596
|
+
|
|
597
|
+
TableCell:clearValidation()
|
|
598
|
+
super.clearValidation()
|
|
599
|
+
if @scope != null
|
|
600
|
+
@scope.clearValidation()
|
|
601
|
+
return null
|
|
602
|
+
|
|
603
|
+
TableCell:dispose()
|
|
604
|
+
if @scope != null
|
|
605
|
+
@scope.dispose()
|
|
606
|
+
return super.dispose()
|
|
607
|
+
|
|
608
|
+
clearValue(control)
|
|
609
|
+
if is_kindof(control, Form)
|
|
610
|
+
for control.owned as child
|
|
611
|
+
clearValue(child)
|
|
612
|
+
else
|
|
613
|
+
control.setValue(null)
|
|
614
|
+
return null
|
|
615
|
+
|
|
616
|
+
cellElement(heading)
|
|
617
|
+
if heading
|
|
618
|
+
return cloneMarkup("table-heading", <th scope="col"></th>)
|
|
619
|
+
return cloneMarkup("table-cell", <td></td>)
|
|
620
|
+
|
|
621
|
+
export class TableDivider(form, props) : Control
|
|
622
|
+
|
|
623
|
+
TableDivider(form, props)
|
|
624
|
+
super(form, props, cloneMarkup("table-divider", <tr class="lango-table-divider" aria-hidden="true"><td><hr /></td></tr>))
|
|
625
|
+
decorate(@this, props)
|
|
626
|
+
|
|
627
|
+
addName(names, name, control)
|
|
628
|
+
if name == null
|
|
629
|
+
return null
|
|
630
|
+
if !is_string(name) or name == "" or name.includes("/") or name in names
|
|
631
|
+
throw "Invalid or duplicate control name: ${name}"
|
|
632
|
+
names[name] = control
|
|
633
|
+
return null
|
|
634
|
+
|
|
635
|
+
rowValue(value)
|
|
636
|
+
if value != null and (!is_object(value) or is_array(value))
|
|
637
|
+
throw "Table row value must be a map or null"
|
|
638
|
+
return value
|
|
639
|
+
|
|
640
|
+
tableIndex(index, length, insertion = false)
|
|
641
|
+
limit = length - 1
|
|
642
|
+
if insertion
|
|
643
|
+
limit = length
|
|
644
|
+
if !is_number(index) or !Number/isInteger(index) or index < 0 or index > limit
|
|
645
|
+
throw "Table index out of range: ${index}"
|
|
646
|
+
return index
|
|
647
|
+
|
|
648
|
+
columnIndex(column, columns)
|
|
649
|
+
if is_string(column)
|
|
650
|
+
for columns as index: col
|
|
651
|
+
if col.name == column
|
|
652
|
+
return index
|
|
653
|
+
throw "Unknown table column: ${column}"
|
|
654
|
+
return tableIndex(column, columns.length)
|
|
655
|
+
|
|
656
|
+
validateBoundaries(header, rows, columns)
|
|
657
|
+
first = null
|
|
658
|
+
if header != null and header.rows.length > 0
|
|
659
|
+
first = header.rows[0]
|
|
660
|
+
else
|
|
661
|
+
if rows.length > 0
|
|
662
|
+
first = rows[0]
|
|
663
|
+
if first != null
|
|
664
|
+
offset = 0
|
|
665
|
+
for columns as col
|
|
666
|
+
offset = offset + col.span
|
|
667
|
+
if col.resize and first.boundary(offset) == null
|
|
668
|
+
throw "Resizable column must end at a first-row cell boundary"
|
|
669
|
+
return first
|
|
670
|
+
|
|
671
|
+
allReady(pending)
|
|
672
|
+
if pending.length == 0
|
|
673
|
+
return null
|
|
674
|
+
return Promise/all(pending)
|
|
675
|
+
|
|
676
|
+
export class TableCol(form, props) : Control
|
|
677
|
+
properties
|
|
678
|
+
name
|
|
679
|
+
span
|
|
680
|
+
resize
|
|
681
|
+
methods
|
|
682
|
+
attach(cell, table)
|
|
683
|
+
detach()
|
|
684
|
+
size(width)
|
|
685
|
+
|
|
686
|
+
TableCol(form, props)
|
|
687
|
+
super(form, props, cloneMarkup("table-col", <col />))
|
|
688
|
+
decorate(@this, props)
|
|
689
|
+
@span = spanValue(props.colSpan)
|
|
690
|
+
@resize = props.resize == true
|
|
691
|
+
applySpan(@element, "span", @span)
|
|
692
|
+
width = columnWidth(props.width)
|
|
693
|
+
if width != null
|
|
694
|
+
@element.style.width = width
|
|
695
|
+
|
|
696
|
+
TableCol:size(width)
|
|
697
|
+
if width < 24
|
|
698
|
+
width = 24
|
|
699
|
+
ruler = document/createElement("span")
|
|
700
|
+
ruler.textContent = "0"
|
|
701
|
+
font = getComputedStyle(@element)
|
|
702
|
+
ruler.style.font = font.font
|
|
703
|
+
ruler.style.position = "absolute"
|
|
704
|
+
ruler.style.visibility = "hidden"
|
|
705
|
+
document/body/appendChild(ruler)
|
|
706
|
+
unit = ruler.getBoundingClientRect().width
|
|
707
|
+
ruler.remove()
|
|
708
|
+
@element.style.width = "${width / unit}ch"
|
|
709
|
+
@handle.setAttribute("aria-valuenow", "${width}")
|
|
710
|
+
return null
|
|
711
|
+
|
|
712
|
+
TableCol:attach(cell, table)
|
|
713
|
+
handle = document/createElement("button")
|
|
714
|
+
handle.type = "button"
|
|
715
|
+
handle.className = "lango-col-resize"
|
|
716
|
+
handle.setAttribute("role", "separator")
|
|
717
|
+
handle.setAttribute("aria-orientation", "vertical")
|
|
718
|
+
handle.setAttribute("aria-label", "↔")
|
|
719
|
+
handle.setAttribute("aria-valuemin", "24")
|
|
720
|
+
handle.setAttribute("aria-valuenow", "24")
|
|
721
|
+
@handle = handle
|
|
722
|
+
cell.classList.add("lango-resizable-cell")
|
|
723
|
+
cell.appendChild(handle)
|
|
724
|
+
drag = {
|
|
725
|
+
active: false
|
|
726
|
+
x: 0
|
|
727
|
+
width: 0
|
|
728
|
+
}
|
|
729
|
+
down = (event)
|
|
730
|
+
capture drag
|
|
731
|
+
capture handle
|
|
732
|
+
capture table
|
|
733
|
+
if event.button != 0 or drag.active
|
|
734
|
+
return null
|
|
735
|
+
event.preventDefault()
|
|
736
|
+
drag.active = true
|
|
737
|
+
drag.x = event.clientX
|
|
738
|
+
drag.width = @element.getBoundingClientRect().width / @span
|
|
739
|
+
style = table.style
|
|
740
|
+
style.tableLayout = "fixed"
|
|
741
|
+
handle.setPointerCapture(event.pointerId)
|
|
742
|
+
move = (event)
|
|
743
|
+
capture drag
|
|
744
|
+
if drag.active
|
|
745
|
+
size(drag.width + (event.clientX - drag.x) / @span)
|
|
746
|
+
up = (event)
|
|
747
|
+
capture drag
|
|
748
|
+
if drag.active
|
|
749
|
+
drag.active = false
|
|
750
|
+
key = (event)
|
|
751
|
+
capture table
|
|
752
|
+
if event.key != "ArrowLeft" and event.key != "ArrowRight"
|
|
753
|
+
return null
|
|
754
|
+
event.preventDefault()
|
|
755
|
+
style = table.style
|
|
756
|
+
style.tableLayout = "fixed"
|
|
757
|
+
step = 10
|
|
758
|
+
if event.key == "ArrowLeft"
|
|
759
|
+
step = -10
|
|
760
|
+
size(@element.getBoundingClientRect().width / @span + step)
|
|
761
|
+
handle.addEventListener("pointerdown", down)
|
|
762
|
+
handle.addEventListener("pointermove", move)
|
|
763
|
+
handle.addEventListener("lostpointercapture", up)
|
|
764
|
+
handle.addEventListener("pointerup", up)
|
|
765
|
+
handle.addEventListener("pointercancel", up)
|
|
766
|
+
handle.addEventListener("keydown", key)
|
|
767
|
+
release = ()
|
|
768
|
+
capture handle
|
|
769
|
+
capture down
|
|
770
|
+
capture move
|
|
771
|
+
capture up
|
|
772
|
+
capture key
|
|
773
|
+
handle.removeEventListener("pointerdown", down)
|
|
774
|
+
handle.removeEventListener("pointermove", move)
|
|
775
|
+
handle.removeEventListener("lostpointercapture", up)
|
|
776
|
+
handle.removeEventListener("pointerup", up)
|
|
777
|
+
handle.removeEventListener("pointercancel", up)
|
|
778
|
+
handle.removeEventListener("keydown", key)
|
|
779
|
+
handle.remove()
|
|
780
|
+
@release.add(release)
|
|
781
|
+
|
|
782
|
+
TableCol:detach()
|
|
783
|
+
for @release as release
|
|
784
|
+
release()
|
|
785
|
+
@release = []
|
|
786
|
+
return null
|