@lango-project/lango-client 0.4.0 → 0.4.2
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/README.md +63 -4
- package/cli/.lango/runtime.mjs +24 -1
- package/cli/create.mjs +0 -0
- package/dist/.lango/runtime.mjs +24 -1
- package/dist/accordion.mjs +9 -8
- package/dist/accordion.mjs.map +1 -1
- package/dist/activities.mjs +8 -7
- package/dist/activities.mjs.map +1 -1
- package/dist/app.mjs +500 -50
- package/dist/app.mjs.map +1 -1
- package/dist/boot.mjs +3 -2
- package/dist/boot.mjs.map +1 -1
- package/dist/button.mjs +8 -7
- package/dist/button.mjs.map +1 -1
- package/dist/chip.mjs +5 -4
- package/dist/chip.mjs.map +1 -1
- package/dist/client.css +7 -0
- package/dist/combo_box.mjs +15 -14
- package/dist/combo_box.mjs.map +1 -1
- package/dist/content.mjs +9 -8
- package/dist/content.mjs.map +1 -1
- package/dist/control.mjs +2 -0
- package/dist/control.mjs.map +1 -1
- package/dist/date_input.mjs +3 -2
- package/dist/date_input.mjs.map +1 -1
- package/dist/dimensions.mjs +102 -0
- package/dist/dimensions.mjs.map +1 -0
- package/dist/error_reporter.mjs +6 -5
- package/dist/error_reporter.mjs.map +1 -1
- package/dist/fields.mjs +9 -8
- package/dist/fields.mjs.map +1 -1
- package/dist/file_input.mjs +19 -18
- package/dist/file_input.mjs.map +1 -1
- package/dist/form.mjs +15 -3
- package/dist/form.mjs.map +1 -1
- package/dist/heartbeat.mjs +12 -11
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +1 -1
- package/dist/input_changes.mjs +5 -4
- package/dist/input_changes.mjs.map +1 -1
- package/dist/longpoll.mjs +12 -11
- package/dist/longpoll.mjs.map +1 -1
- package/dist/main.mjs +45 -19
- package/dist/main.mjs.map +1 -1
- package/dist/menus.mjs +19 -18
- package/dist/menus.mjs.map +1 -1
- package/dist/navigation.mjs +7 -6
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +9 -8
- package/dist/numeric_input.mjs.map +1 -1
- package/dist/otp_input.mjs +5 -4
- package/dist/otp_input.mjs.map +1 -1
- package/dist/presentations.mjs +17 -16
- package/dist/presentations.mjs.map +1 -1
- package/dist/renderer.mjs +88 -12
- package/dist/renderer.mjs.map +1 -1
- package/dist/table_scope.mjs +167 -0
- package/dist/table_scope.mjs.map +1 -0
- package/dist/tables.mjs +809 -125
- package/dist/tables.mjs.map +1 -1
- package/dist/tabs.mjs +7 -6
- package/dist/tabs.mjs.map +1 -1
- package/dist/widgets.mjs +5 -4
- package/dist/widgets.mjs.map +1 -1
- package/docs/implementation.md +51 -0
- package/package.json +4 -3
- package/src/app.lango +358 -12
- package/src/control.lango +3 -0
- package/src/dimensions.lango +65 -0
- package/src/form.lango +13 -3
- package/src/heartbeat.lango +2 -2
- package/src/main.lango +24 -0
- package/src/renderer.lango +78 -9
- package/src/table_scope.lango +119 -0
- package/src/tables.lango +620 -105
- package/web/client.css +7 -0
- package/web/index.html +1 -1
package/src/tables.lango
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
import js global getComputedStyle
|
|
2
|
+
import "./dimensions"
|
|
3
|
+
measure(value, unit)
|
|
1
4
|
import js global document
|
|
2
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
|
|
3
14
|
import "./control"
|
|
4
15
|
class Control
|
|
16
|
+
import "./form"
|
|
17
|
+
class Form
|
|
5
18
|
import "./templates"
|
|
6
19
|
cloneMarkup(name, xml)
|
|
7
20
|
import "./content"
|
|
@@ -10,6 +23,7 @@ import "./content"
|
|
|
10
23
|
decorate(control, props)
|
|
11
24
|
|
|
12
25
|
export spanValue(value)
|
|
26
|
+
export columnWidth(value)
|
|
13
27
|
|
|
14
28
|
spanValue(value)
|
|
15
29
|
if value == null
|
|
@@ -18,122 +32,452 @@ spanValue(value)
|
|
|
18
32
|
throw "Table span must be an integer between 1 and 1000"
|
|
19
33
|
return value
|
|
20
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
|
+
|
|
21
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()
|
|
22
67
|
|
|
23
68
|
Table(form, props, renderer)
|
|
24
69
|
super(form, props, cloneMarkup("table", <div class="table-responsive"><table class="table"><colgroup></colgroup><tbody></tbody></table></div>))
|
|
25
|
-
|
|
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
|
|
26
91
|
group = table.firstElementChild
|
|
27
|
-
|
|
28
|
-
|
|
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()
|
|
29
221
|
rows = []
|
|
30
|
-
|
|
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)
|
|
31
363
|
width = 1
|
|
32
|
-
header = null
|
|
33
|
-
if props.stripedRows == true
|
|
34
|
-
table.classList.add("table-striped")
|
|
35
|
-
if props.stripedColumns == true
|
|
36
|
-
table.classList.add("table-striped-columns")
|
|
37
|
-
if props.hoverableRows == true
|
|
38
|
-
table.classList.add("table-hover")
|
|
39
|
-
if props.small == true
|
|
40
|
-
table.classList.add("table-sm")
|
|
41
|
-
if props.border != null and props.border != false
|
|
42
|
-
table.classList.add("table-bordered")
|
|
43
|
-
if is_object(props.border)
|
|
44
|
-
if props.border.color != null
|
|
45
|
-
table.style.setProperty("--bs-table-border-color", props.border.color)
|
|
46
|
-
if props.border.width != null
|
|
47
|
-
table.style.setProperty("--bs-border-width", "${props.border.width}px")
|
|
48
|
-
if props.caption != null
|
|
49
|
-
caption = document/createElement("caption")
|
|
50
|
-
appendContent(form, caption, props.caption, renderer)
|
|
51
|
-
table.prepend(caption)
|
|
52
|
-
if props.aria != null
|
|
53
|
-
for props.aria as name: value
|
|
54
|
-
table.setAttribute("aria-${name}", value)
|
|
55
|
-
if props.controls != null
|
|
56
|
-
for props.controls as definition
|
|
57
|
-
switch definition.type
|
|
58
|
-
case "tableCol"
|
|
59
|
-
col = new TableCol(form, definition)
|
|
60
|
-
form.register(definition.name, col)
|
|
61
|
-
columns.add(col)
|
|
62
|
-
group.appendChild(col.element)
|
|
63
|
-
case "tableHeader"
|
|
64
|
-
if header != null
|
|
65
|
-
throw "Table accepts one TableHeader"
|
|
66
|
-
header = new TableHeader(form, definition, renderer)
|
|
67
|
-
form.register(definition.name, header)
|
|
68
|
-
table.insertBefore(header.element, body)
|
|
69
|
-
for header.rows as heading
|
|
70
|
-
rows.add(heading)
|
|
71
|
-
case "tableRow"
|
|
72
|
-
row = new TableRow(form, definition, renderer, false)
|
|
73
|
-
form.register(definition.name, row)
|
|
74
|
-
rows.add(row)
|
|
75
|
-
body.appendChild(row.element)
|
|
76
|
-
case "tableDivider"
|
|
77
|
-
divider = new TableDivider(form, definition)
|
|
78
|
-
form.register(definition.name, divider)
|
|
79
|
-
dividers.add(divider)
|
|
80
|
-
body.appendChild(divider.element)
|
|
81
|
-
else
|
|
82
|
-
throw "Unsupported Table child: ${definition.type}"
|
|
83
364
|
for rows as row
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
90
376
|
offset = 0
|
|
91
|
-
for columns as col
|
|
377
|
+
for @columns as col
|
|
92
378
|
offset = offset + col.span
|
|
93
379
|
if col.resize
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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()
|
|
98
396
|
|
|
99
397
|
export class TableHeader(form, props, renderer) : Control
|
|
100
398
|
properties
|
|
101
399
|
rows
|
|
400
|
+
methods
|
|
401
|
+
prepareValue()
|
|
402
|
+
clearValidation()
|
|
403
|
+
dispose()
|
|
102
404
|
|
|
103
405
|
TableHeader(form, props, renderer)
|
|
104
406
|
super(form, props, cloneMarkup("table-header", <thead></thead>))
|
|
105
407
|
decorate(@this, props)
|
|
106
408
|
@rows = []
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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()
|
|
115
441
|
|
|
116
442
|
export class TableRow(form, props, renderer, heading) : Control
|
|
117
443
|
properties
|
|
444
|
+
name
|
|
445
|
+
data
|
|
446
|
+
generated
|
|
118
447
|
width
|
|
448
|
+
cells
|
|
119
449
|
methods
|
|
120
450
|
boundary(column)
|
|
451
|
+
setRowValue(value, columns)
|
|
452
|
+
getRowValue(columns)
|
|
453
|
+
getValue()
|
|
454
|
+
prepareValue()
|
|
455
|
+
clearValidation()
|
|
456
|
+
dispose()
|
|
121
457
|
|
|
122
458
|
TableRow(form, props, renderer, heading)
|
|
123
459
|
super(form, props, cloneMarkup("table-row", <tr></tr>))
|
|
124
460
|
decorate(@this, props)
|
|
461
|
+
@name = props.name
|
|
462
|
+
@data = structuredClone(props.data)
|
|
463
|
+
@generated = false
|
|
125
464
|
@width = 0
|
|
126
465
|
@cells = []
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
137
481
|
|
|
138
482
|
TableRow:boundary(column)
|
|
139
483
|
offset = 0
|
|
@@ -143,24 +487,131 @@ TableRow:boundary(column)
|
|
|
143
487
|
return cell.element
|
|
144
488
|
return null
|
|
145
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
|
+
|
|
146
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()
|
|
147
542
|
|
|
148
543
|
TableCell(form, props, renderer, heading)
|
|
149
544
|
super(form, props, cellElement(heading))
|
|
150
|
-
@
|
|
151
|
-
@
|
|
152
|
-
|
|
153
|
-
@element
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
|
164
615
|
|
|
165
616
|
cellElement(heading)
|
|
166
617
|
if heading
|
|
@@ -173,12 +624,63 @@ TableDivider(form, props)
|
|
|
173
624
|
super(form, props, cloneMarkup("table-divider", <tr class="lango-table-divider" aria-hidden="true"><td><hr /></td></tr>))
|
|
174
625
|
decorate(@this, props)
|
|
175
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
|
+
|
|
176
676
|
export class TableCol(form, props) : Control
|
|
177
677
|
properties
|
|
678
|
+
name
|
|
178
679
|
span
|
|
179
680
|
resize
|
|
180
681
|
methods
|
|
181
682
|
attach(cell, table)
|
|
683
|
+
detach()
|
|
182
684
|
size(width)
|
|
183
685
|
|
|
184
686
|
TableCol(form, props)
|
|
@@ -186,17 +688,24 @@ TableCol(form, props)
|
|
|
186
688
|
decorate(@this, props)
|
|
187
689
|
@span = spanValue(props.colSpan)
|
|
188
690
|
@resize = props.resize == true
|
|
189
|
-
@element
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
else
|
|
194
|
-
@element.style.width = props.width
|
|
691
|
+
applySpan(@element, "span", @span)
|
|
692
|
+
width = columnWidth(props.width)
|
|
693
|
+
if width != null
|
|
694
|
+
@element.style.width = width
|
|
195
695
|
|
|
196
696
|
TableCol:size(width)
|
|
197
697
|
if width < 24
|
|
198
698
|
width = 24
|
|
199
|
-
|
|
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"
|
|
200
709
|
@handle.setAttribute("aria-valuenow", "${width}")
|
|
201
710
|
return null
|
|
202
711
|
|
|
@@ -269,3 +778,9 @@ TableCol:attach(cell, table)
|
|
|
269
778
|
handle.removeEventListener("keydown", key)
|
|
270
779
|
handle.remove()
|
|
271
780
|
@release.add(release)
|
|
781
|
+
|
|
782
|
+
TableCol:detach()
|
|
783
|
+
for @release as release
|
|
784
|
+
release()
|
|
785
|
+
@release = []
|
|
786
|
+
return null
|