@lango-project/lango-client 0.4.0 → 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/README.md +37 -4
- package/cli/.lango/runtime.mjs +8 -1
- package/cli/create.mjs +0 -0
- package/dist/.lango/runtime.mjs +8 -1
- package/dist/app.mjs +37 -2
- package/dist/app.mjs.map +1 -1
- package/dist/client.css +7 -0
- package/dist/control.mjs +2 -0
- package/dist/control.mjs.map +1 -1
- package/dist/dimensions.mjs +102 -0
- package/dist/dimensions.mjs.map +1 -0
- package/dist/form.mjs +1 -1
- package/dist/form.mjs.map +1 -1
- package/dist/index.html +1 -1
- package/dist/main.mjs +11 -2
- package/dist/main.mjs.map +1 -1
- package/dist/renderer.mjs +15 -13
- package/dist/renderer.mjs.map +1 -1
- package/dist/table_scope.mjs +166 -0
- package/dist/table_scope.mjs.map +1 -0
- package/dist/tables.mjs +798 -115
- package/dist/tables.mjs.map +1 -1
- package/dist/vendor/dompurify.mjs +181 -267
- package/dist/vendor/purify.es.mjs.map +1 -1
- package/docs/implementation.md +51 -0
- package/package.json +2 -2
- package/src/app.lango +35 -3
- package/src/control.lango +3 -0
- package/src/dimensions.lango +65 -0
- package/src/form.lango +1 -1
- package/src/main.lango +9 -0
- package/src/renderer.lango +17 -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/dist/tables.mjs
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
import { measure } from "./dimensions.mjs";
|
|
2
|
+
import { TableScope } from "./table_scope.mjs";
|
|
1
3
|
import { Control } from "./control.mjs";
|
|
4
|
+
import { Form } from "./form.mjs";
|
|
2
5
|
import { cloneMarkup } from "./templates.mjs";
|
|
3
6
|
import { appendContent, bindAction, decorate } from "./content.mjs";
|
|
4
7
|
import {
|
|
5
8
|
hostGlobal as __hostGlobal,
|
|
9
|
+
hostGlobalCall as __hostGlobalCall,
|
|
6
10
|
xmlEscape as __xmlEscape,
|
|
11
|
+
getClass as __getClass,
|
|
12
|
+
isKindof as __isKindof,
|
|
7
13
|
isNumber as __isNumber,
|
|
8
14
|
isString as __isString,
|
|
9
15
|
isBool as __isBool,
|
|
10
16
|
isObject as __isObject,
|
|
11
17
|
isArray as __isArray,
|
|
18
|
+
includes as __includes,
|
|
12
19
|
entries as __entries,
|
|
13
20
|
add as __add,
|
|
14
21
|
remove as __remove,
|
|
@@ -16,113 +23,468 @@ import {
|
|
|
16
23
|
normalize as __normalize,
|
|
17
24
|
finite as __finite,
|
|
18
25
|
numericAdd as __numericAdd,
|
|
26
|
+
call as __call,
|
|
19
27
|
boundary as __boundary,
|
|
20
28
|
requireArity as __requireArity,
|
|
21
29
|
withArity as __withArity,
|
|
22
30
|
} from "./.lango/runtime.mjs";
|
|
23
31
|
|
|
24
32
|
export class Table extends Control {
|
|
33
|
+
rows;
|
|
34
|
+
columns;
|
|
35
|
+
#renderer;
|
|
36
|
+
#props;
|
|
37
|
+
#building;
|
|
38
|
+
#mode;
|
|
39
|
+
#layout;
|
|
40
|
+
#lookup;
|
|
41
|
+
#header;
|
|
42
|
+
#aliases;
|
|
43
|
+
#table;
|
|
44
|
+
#body;
|
|
45
|
+
#template;
|
|
25
46
|
constructor(form, props, renderer) {
|
|
26
47
|
super(form, props, cloneMarkup("table", ["<div class=\"table-responsive\"><table class=\"table\"><colgroup></colgroup><tbody></tbody></table></div>"].join("")));
|
|
27
48
|
__requireArity(arguments.length, [0, 1, 2], "constructor");
|
|
28
49
|
form = __boundary(form);
|
|
29
50
|
props = __boundary(props);
|
|
30
51
|
renderer = __boundary(renderer);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let width = 1;
|
|
38
|
-
let header = null;
|
|
39
|
-
if (__requireBoolean(__normalize(props.stripedRows) === true)) {
|
|
40
|
-
__add(table.classList, "table-striped");
|
|
52
|
+
this.#renderer = renderer;
|
|
53
|
+
this.#props = props;
|
|
54
|
+
this.#building = true;
|
|
55
|
+
this.#mode = __normalize(props.valueMode);
|
|
56
|
+
if (__requireBoolean(__normalize(this.#mode) === null)) {
|
|
57
|
+
this.#mode = "none";
|
|
41
58
|
}
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
let modes = ["none", "cells", "rows", "mixed"];
|
|
60
|
+
if (__requireBoolean(!__requireBoolean(__normalize(modes.includes(__normalize(this.#mode)))))) {
|
|
61
|
+
throw "Table valueMode must be none, cells, rows or mixed";
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
this.#layout = new TableScope(form);
|
|
64
|
+
this.#lookup = new TableScope(form);
|
|
65
|
+
this.rows = [];
|
|
66
|
+
this.columns = [];
|
|
67
|
+
this.#header = null;
|
|
68
|
+
this.#aliases = __normalize(__hostGlobal(["Object"]).create(null));
|
|
69
|
+
this.#table = __normalize(this.element.firstElementChild);
|
|
70
|
+
this.#body = __normalize(this.#table.lastElementChild);
|
|
71
|
+
this.#template = __normalize(props.rowTemplate);
|
|
72
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#template) !== null) && __requireBoolean(__normalize(this.#template.type) !== "tableRowTemplate"))) {
|
|
73
|
+
throw "Table rowTemplate requires a TableRowTemplate";
|
|
50
74
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
let table = __normalize(this.#table);
|
|
76
|
+
let group = __normalize(table.firstElementChild);
|
|
77
|
+
let headings = [];
|
|
78
|
+
let hasCaptions = false;
|
|
79
|
+
try {
|
|
80
|
+
if (__requireBoolean(__normalize(props.stripedRows) === true)) {
|
|
81
|
+
__add(table.classList, "table-striped");
|
|
82
|
+
}
|
|
83
|
+
if (__requireBoolean(__normalize(props.stripedColumns) === true)) {
|
|
84
|
+
__add(table.classList, "table-striped-columns");
|
|
85
|
+
}
|
|
86
|
+
if (__requireBoolean(__normalize(props.hoverableRows) === true)) {
|
|
87
|
+
__add(table.classList, "table-hover");
|
|
88
|
+
}
|
|
89
|
+
if (__requireBoolean(__normalize(props.small) === true)) {
|
|
90
|
+
__add(table.classList, "table-sm");
|
|
91
|
+
}
|
|
92
|
+
if (__requireBoolean(__requireBoolean(__normalize(props.border) !== null) && __requireBoolean(__normalize(props.border) !== false))) {
|
|
93
|
+
__add(table.classList, "table-bordered");
|
|
94
|
+
if (__requireBoolean(__isObject(__normalize(props.border)))) {
|
|
95
|
+
if (__requireBoolean(props.border.color !== null)) {
|
|
96
|
+
__normalize(table.style.setProperty("--bs-table-border-color", props.border.color));
|
|
97
|
+
}
|
|
98
|
+
if (__requireBoolean(props.border.width !== null)) {
|
|
99
|
+
__normalize(table.style.setProperty("--bs-border-width", `${props.border.width}px`));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (__requireBoolean(__normalize(props.caption) !== null)) {
|
|
104
|
+
let caption = __normalize(__hostGlobal(["document"]).createElement("caption"));
|
|
105
|
+
appendContent(__normalize(this.#layout), caption, __normalize(props.caption), renderer);
|
|
106
|
+
__normalize(table.prepend(caption));
|
|
107
|
+
}
|
|
108
|
+
if (__requireBoolean(__normalize(props.aria) !== null)) {
|
|
109
|
+
for (const [name, value] of __entries(__normalize(props.aria))) {
|
|
110
|
+
__normalize(table.setAttribute(`aria-${name}`, value));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (__requireBoolean(__normalize(props.controls) !== null)) {
|
|
114
|
+
for (const definition of __normalize(props.controls)) {
|
|
115
|
+
if (__normalize(definition.type) === "tableCol") {
|
|
116
|
+
let col = new TableCol(__normalize(this.#layout), definition);
|
|
117
|
+
__normalize(this.#layout.register(null, col));
|
|
118
|
+
col.name = __normalize(definition.name);
|
|
119
|
+
if (__requireBoolean(__normalize(col.name) !== null)) {
|
|
120
|
+
for (const previous of __normalize(this.columns)) {
|
|
121
|
+
if (__requireBoolean(__normalize(previous.name) === __normalize(col.name))) {
|
|
122
|
+
throw `Duplicate column name: ${__normalize(col.name)}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
this.columns.push(col);
|
|
127
|
+
headings.push({ type: "tableCell", colSpan: __normalize(definition.colSpan), controls: __normalize(definition.caption) });
|
|
128
|
+
if (__requireBoolean(__normalize(definition.caption) !== null)) {
|
|
129
|
+
hasCaptions = true;
|
|
130
|
+
}
|
|
131
|
+
__normalize(group.appendChild(__normalize(col.element)));
|
|
132
|
+
} else if (__normalize(definition.type) === "tableHeader") {
|
|
133
|
+
if (__requireBoolean(__normalize(this.#header) !== null)) {
|
|
134
|
+
throw "Table accepts one TableHeader";
|
|
135
|
+
}
|
|
136
|
+
this.#header = new TableHeader(__normalize(this.#layout), definition, renderer);
|
|
137
|
+
__normalize(this.#layout.register(__normalize(definition.name), __normalize(this.#header)));
|
|
138
|
+
__normalize(table.insertBefore(__normalize(this.#header.element), __normalize(this.#body)));
|
|
139
|
+
} else if (__normalize(definition.type) === "tableRow") {
|
|
140
|
+
let row = new TableRow(form, definition, renderer, false);
|
|
141
|
+
this.rows.push(row);
|
|
142
|
+
__normalize(this.#body.appendChild(__normalize(row.element)));
|
|
143
|
+
} else if (__normalize(definition.type) === "tableDivider") {
|
|
144
|
+
let divider = new TableDivider(__normalize(this.#layout), definition);
|
|
145
|
+
__normalize(this.#layout.register(__normalize(definition.name), divider));
|
|
146
|
+
__normalize(this.#body.appendChild(__normalize(divider.element)));
|
|
147
|
+
} else {
|
|
148
|
+
throw `Unsupported Table child: ${__normalize(definition.type)}`;
|
|
149
|
+
}
|
|
56
150
|
}
|
|
57
|
-
|
|
58
|
-
|
|
151
|
+
}
|
|
152
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#header) === null) && __requireBoolean(hasCaptions))) {
|
|
153
|
+
let generated = { controls: [{ type: "tableRow", controls: headings }] };
|
|
154
|
+
this.#header = new TableHeader(__normalize(this.#layout), generated, renderer);
|
|
155
|
+
__normalize(this.#layout.register(null, __normalize(this.#header)));
|
|
156
|
+
__normalize(table.insertBefore(__normalize(this.#header.element), __normalize(this.#body)));
|
|
157
|
+
}
|
|
158
|
+
let width = 1;
|
|
159
|
+
for (const row of __normalize(this.rows)) {
|
|
160
|
+
width = __normalize(__hostGlobal(["Math"]).max(width, __normalize(row.width)));
|
|
161
|
+
}
|
|
162
|
+
for (const child of __normalize(this.#layout.owned)) {
|
|
163
|
+
if (__requireBoolean(__isKindof(child, TableDivider))) {
|
|
164
|
+
applySpan(child.element.firstElementChild, "colspan", width);
|
|
59
165
|
}
|
|
60
166
|
}
|
|
167
|
+
if (__requireBoolean(__normalize(props.value) !== null)) {
|
|
168
|
+
this.setValue(__normalize(props.value));
|
|
169
|
+
} else {
|
|
170
|
+
this.publish(this.names(__normalize(this.rows)));
|
|
171
|
+
this.resize(__normalize(this.rows));
|
|
172
|
+
}
|
|
173
|
+
this.#building = false;
|
|
174
|
+
} catch (error) {
|
|
175
|
+
this.dispose();
|
|
176
|
+
throw error;
|
|
61
177
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
178
|
+
}
|
|
179
|
+
find(name) {
|
|
180
|
+
__requireArity(arguments.length, [0], "find");
|
|
181
|
+
name = __boundary(name);
|
|
182
|
+
return __normalize(this.#lookup.find(name));
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
names(rows, replace = false) {
|
|
186
|
+
__requireArity(arguments.length, [0], "names");
|
|
187
|
+
rows = __boundary(rows);
|
|
188
|
+
replace = __boundary(replace);
|
|
189
|
+
let result = __normalize(__hostGlobal(["Object"]).create(null));
|
|
190
|
+
for (const [name, control] of __entries(__normalize(this.#layout.controls))) {
|
|
191
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(replace)) || __requireBoolean(!__requireBoolean(__isKindof(control, TableDivider))))) {
|
|
192
|
+
addName(result, name, control);
|
|
193
|
+
}
|
|
66
194
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
195
|
+
let sources = __normalize(rows.slice());
|
|
196
|
+
if (__requireBoolean(__normalize(this.#header) !== null)) {
|
|
197
|
+
for (const row of __normalize(this.#header.rows)) {
|
|
198
|
+
__add(sources, row);
|
|
70
199
|
}
|
|
71
200
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
columns.push(col);
|
|
78
|
-
__normalize(group.appendChild(__normalize(col.element)));
|
|
79
|
-
} else if (__normalize(definition.type) === "tableHeader") {
|
|
80
|
-
if (__requireBoolean(header !== null)) {
|
|
81
|
-
throw "Table accepts one TableHeader";
|
|
82
|
-
}
|
|
83
|
-
header = new TableHeader(form, definition, renderer);
|
|
84
|
-
__normalize(form.register(__normalize(definition.name), header));
|
|
85
|
-
__normalize(table.insertBefore(__normalize(header.element), body));
|
|
86
|
-
for (const heading of __normalize(header.rows)) {
|
|
87
|
-
rows.push(heading);
|
|
88
|
-
}
|
|
89
|
-
} else if (__normalize(definition.type) === "tableRow") {
|
|
90
|
-
let row = new TableRow(form, definition, renderer, false);
|
|
91
|
-
__normalize(form.register(__normalize(definition.name), row));
|
|
92
|
-
rows.push(row);
|
|
93
|
-
__normalize(body.appendChild(__normalize(row.element)));
|
|
94
|
-
} else if (__normalize(definition.type) === "tableDivider") {
|
|
95
|
-
let divider = new TableDivider(form, definition);
|
|
96
|
-
__normalize(form.register(__normalize(definition.name), divider));
|
|
97
|
-
dividers.push(divider);
|
|
98
|
-
__normalize(body.appendChild(__normalize(divider.element)));
|
|
201
|
+
for (const row of sources) {
|
|
202
|
+
addName(result, __normalize(row.name), row);
|
|
203
|
+
for (const cell of __normalize(row.cells)) {
|
|
204
|
+
if (__requireBoolean(__normalize(cell.name) !== null)) {
|
|
205
|
+
addName(result, __normalize(cell.name), cell);
|
|
99
206
|
} else {
|
|
100
|
-
|
|
207
|
+
if (__requireBoolean(!__requireBoolean(__normalize(row.generated)))) {
|
|
208
|
+
for (const [name, control] of __entries(cell.scope.controls)) {
|
|
209
|
+
addName(result, name, control);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
publish(names) {
|
|
219
|
+
__requireArity(arguments.length, [0], "publish");
|
|
220
|
+
names = __boundary(names);
|
|
221
|
+
if (__requireBoolean(__normalize(this.#props.name) === null)) {
|
|
222
|
+
for (const [name, control] of __entries(names)) {
|
|
223
|
+
if (__requireBoolean(__requireBoolean(__includes(name, __normalize(this.form.controls))) && __requireBoolean(__normalize(this.form.controls[name]) !== __normalize(this.#aliases[name])))) {
|
|
224
|
+
throw `Invalid or duplicate control name: ${name}`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (const [name, control] of __entries(__normalize(this.#aliases))) {
|
|
228
|
+
if (__requireBoolean(__normalize(this.form.controls[name]) === control)) {
|
|
229
|
+
__normalize(__hostGlobal(["Reflect"]).deleteProperty(__normalize(this.form.controls), name));
|
|
101
230
|
}
|
|
102
231
|
}
|
|
232
|
+
for (const [name, control] of __entries(names)) {
|
|
233
|
+
this.form.controls[name] = control;
|
|
234
|
+
}
|
|
235
|
+
this.#aliases = names;
|
|
236
|
+
}
|
|
237
|
+
this.#lookup.controls = names;
|
|
238
|
+
return null;
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
getValue() {
|
|
242
|
+
if (__requireBoolean(__normalize(this.#mode) === "none")) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
if (__requireBoolean(__normalize(this.#mode) === "cells")) {
|
|
246
|
+
return __normalize(this.#lookup.getValue());
|
|
103
247
|
}
|
|
248
|
+
let rows = [];
|
|
249
|
+
for (const row of __normalize(this.rows)) {
|
|
250
|
+
rows.push(__normalize(row.getRowValue(__normalize(this.columns))));
|
|
251
|
+
}
|
|
252
|
+
if (__requireBoolean(__normalize(this.#mode) === "rows")) {
|
|
253
|
+
return rows;
|
|
254
|
+
}
|
|
255
|
+
return { cells: __normalize(this.#lookup.getValue()), rows: rows };
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
prepareValue() {
|
|
259
|
+
let pending = [];
|
|
260
|
+
let ready = __normalize(this.#layout.prepareValue());
|
|
261
|
+
if (__requireBoolean(ready !== null)) {
|
|
262
|
+
pending.push(ready);
|
|
263
|
+
}
|
|
264
|
+
for (const row of __normalize(this.rows)) {
|
|
265
|
+
ready = __normalize(row.prepareValue());
|
|
266
|
+
if (__requireBoolean(ready !== null)) {
|
|
267
|
+
pending.push(ready);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return allReady(pending);
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
clearValidation() {
|
|
274
|
+
super.clearValidation();
|
|
275
|
+
if (__requireBoolean(__normalize(this.#layout) !== null)) {
|
|
276
|
+
__normalize(this.#layout.clearValidation());
|
|
277
|
+
}
|
|
278
|
+
if (__requireBoolean(__normalize(this.rows) !== null)) {
|
|
279
|
+
for (const row of __normalize(this.rows)) {
|
|
280
|
+
__normalize(row.clearValidation());
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
createRow(value) {
|
|
287
|
+
__requireArity(arguments.length, [0], "createRow");
|
|
288
|
+
value = __boundary(value);
|
|
289
|
+
rowValue(value);
|
|
290
|
+
let definition = null;
|
|
291
|
+
if (__requireBoolean(__normalize(this.#template) !== null)) {
|
|
292
|
+
definition = __hostGlobalCall(["structuredClone"], __normalize(this.#template));
|
|
293
|
+
} else {
|
|
294
|
+
let cells = [];
|
|
295
|
+
for (const column of __normalize(this.columns)) {
|
|
296
|
+
cells.push({ type: "tableCell", colSpan: __normalize(column.span) });
|
|
297
|
+
}
|
|
298
|
+
definition = { controls: cells };
|
|
299
|
+
}
|
|
300
|
+
let row = new TableRow(__normalize(this.form), definition, __normalize(this.#renderer), false);
|
|
301
|
+
row.generated = true;
|
|
302
|
+
try {
|
|
303
|
+
__normalize(row.setRowValue(value, __normalize(this.columns)));
|
|
304
|
+
} catch (error) {
|
|
305
|
+
__normalize(row.dispose());
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
return row;
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
setValue(values) {
|
|
312
|
+
__requireArity(arguments.length, [0], "setValue");
|
|
313
|
+
values = __boundary(values);
|
|
314
|
+
if (__requireBoolean(values === null)) {
|
|
315
|
+
values = [];
|
|
316
|
+
}
|
|
317
|
+
if (__requireBoolean(!__requireBoolean(__isArray(values)))) {
|
|
318
|
+
throw "Table value must be an array of row maps";
|
|
319
|
+
}
|
|
320
|
+
let staged = [];
|
|
321
|
+
try {
|
|
322
|
+
for (const value of values) {
|
|
323
|
+
staged.push(this.createRow(value));
|
|
324
|
+
}
|
|
325
|
+
let next = this.names(staged, true);
|
|
326
|
+
validateBoundaries(__normalize(this.#header), staged, __normalize(this.columns));
|
|
327
|
+
this.publish(next);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
for (const row of staged) {
|
|
330
|
+
__normalize(row.dispose());
|
|
331
|
+
}
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
if (__requireBoolean(!__requireBoolean(__normalize(this.#building)))) {
|
|
335
|
+
__normalize(this.form.clearResources());
|
|
336
|
+
}
|
|
337
|
+
for (const row of __normalize(this.rows)) {
|
|
338
|
+
__normalize(row.dispose());
|
|
339
|
+
}
|
|
340
|
+
this.rows = staged;
|
|
341
|
+
__normalize(this.#body.replaceChildren());
|
|
342
|
+
for (const child of __normalize(this.#layout.owned.slice())) {
|
|
343
|
+
if (__requireBoolean(__isKindof(child, TableDivider))) {
|
|
344
|
+
__normalize(this.#layout.unregister(child));
|
|
345
|
+
__normalize(child.dispose());
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (const row of staged) {
|
|
349
|
+
__normalize(this.#body.appendChild(__normalize(row.element)));
|
|
350
|
+
}
|
|
351
|
+
this.resize(staged);
|
|
352
|
+
return this;
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
addRow(value = null) {
|
|
356
|
+
value = __boundary(value);
|
|
357
|
+
return this.insertRow(__normalize(this.rows.length), value);
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
insertRow(beforeIndex, value = null) {
|
|
361
|
+
__requireArity(arguments.length, [0], "insertRow");
|
|
362
|
+
beforeIndex = __boundary(beforeIndex);
|
|
363
|
+
value = __boundary(value);
|
|
364
|
+
tableIndex(beforeIndex, __normalize(this.rows.length), true);
|
|
365
|
+
let row = this.createRow(value);
|
|
366
|
+
let staged = __normalize(this.rows.slice());
|
|
367
|
+
__normalize(staged.splice(beforeIndex, 0, row));
|
|
368
|
+
try {
|
|
369
|
+
let next = this.names(staged);
|
|
370
|
+
validateBoundaries(__normalize(this.#header), staged, __normalize(this.columns));
|
|
371
|
+
this.publish(next);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
__normalize(row.dispose());
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
376
|
+
__normalize(this.form.clearResources());
|
|
377
|
+
let anchor = null;
|
|
378
|
+
if (__requireBoolean(beforeIndex < __normalize(this.rows.length))) {
|
|
379
|
+
anchor = __normalize(__normalize(this.rows[beforeIndex]).element);
|
|
380
|
+
}
|
|
381
|
+
__normalize(this.#body.insertBefore(__normalize(row.element), anchor));
|
|
382
|
+
this.rows = staged;
|
|
383
|
+
this.resize(staged);
|
|
384
|
+
return this;
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
deleteRow(index) {
|
|
388
|
+
__requireArity(arguments.length, [0], "deleteRow");
|
|
389
|
+
index = __boundary(index);
|
|
390
|
+
tableIndex(index, __normalize(this.rows.length));
|
|
391
|
+
let staged = __normalize(this.rows.slice());
|
|
392
|
+
let row = __normalize(__normalize(staged.splice(index, 1))[0]);
|
|
393
|
+
validateBoundaries(__normalize(this.#header), staged, __normalize(this.columns));
|
|
394
|
+
this.publish(this.names(staged));
|
|
395
|
+
__normalize(this.form.clearResources());
|
|
396
|
+
__normalize(row.dispose());
|
|
397
|
+
__remove(row.element);
|
|
398
|
+
this.rows = staged;
|
|
399
|
+
this.resize(staged);
|
|
400
|
+
return this;
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
setRowValue(index, value) {
|
|
404
|
+
__requireArity(arguments.length, [0, 1], "setRowValue");
|
|
405
|
+
index = __boundary(index);
|
|
406
|
+
value = __boundary(value);
|
|
407
|
+
tableIndex(index, __normalize(this.rows.length));
|
|
408
|
+
__normalize(__normalize(this.rows[index]).setRowValue(value, __normalize(this.columns)));
|
|
409
|
+
return this;
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
setRowData(index, value) {
|
|
413
|
+
__requireArity(arguments.length, [0, 1], "setRowData");
|
|
414
|
+
index = __boundary(index);
|
|
415
|
+
value = __boundary(value);
|
|
416
|
+
tableIndex(index, __normalize(this.rows.length));
|
|
417
|
+
let row = __normalize(this.rows[index]);
|
|
418
|
+
row.data = __hostGlobalCall(["structuredClone"], value);
|
|
419
|
+
return this;
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
setCellValue(index, column, value) {
|
|
423
|
+
__requireArity(arguments.length, [0, 1, 2], "setCellValue");
|
|
424
|
+
index = __boundary(index);
|
|
425
|
+
column = __boundary(column);
|
|
426
|
+
value = __boundary(value);
|
|
427
|
+
tableIndex(index, __normalize(this.rows.length));
|
|
428
|
+
let selected = columnIndex(column, __normalize(this.columns));
|
|
429
|
+
let row = __normalize(this.rows[index]);
|
|
430
|
+
tableIndex(selected, row.cells.length);
|
|
431
|
+
__normalize(row.cells[selected].setValue(value));
|
|
432
|
+
return this;
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
resize(rows) {
|
|
436
|
+
__requireArity(arguments.length, [0], "resize");
|
|
437
|
+
rows = __boundary(rows);
|
|
438
|
+
let width = 1;
|
|
104
439
|
for (const row of rows) {
|
|
105
|
-
|
|
106
|
-
|
|
440
|
+
width = __normalize(__hostGlobal(["Math"]).max(width, __normalize(row.width)));
|
|
441
|
+
}
|
|
442
|
+
if (__requireBoolean(__normalize(this.#header) !== null)) {
|
|
443
|
+
for (const row of __normalize(this.#header.rows)) {
|
|
444
|
+
width = __normalize(__hostGlobal(["Math"]).max(width, __normalize(row.width)));
|
|
107
445
|
}
|
|
108
446
|
}
|
|
109
|
-
for (const
|
|
110
|
-
|
|
447
|
+
for (const child of __normalize(this.#layout.owned)) {
|
|
448
|
+
if (__requireBoolean(__isKindof(child, TableDivider))) {
|
|
449
|
+
applySpan(child.element.firstElementChild, "colspan", width);
|
|
450
|
+
}
|
|
111
451
|
}
|
|
112
|
-
|
|
113
|
-
|
|
452
|
+
for (const col of __normalize(this.columns)) {
|
|
453
|
+
__normalize(col.detach());
|
|
454
|
+
}
|
|
455
|
+
let first = validateBoundaries(__normalize(this.#header), rows, __normalize(this.columns));
|
|
456
|
+
if (__requireBoolean(first !== null)) {
|
|
114
457
|
let offset = 0;
|
|
115
|
-
for (const col of columns) {
|
|
458
|
+
for (const col of __normalize(this.columns)) {
|
|
116
459
|
offset = __numericAdd(offset, __normalize(col.span));
|
|
117
460
|
if (__requireBoolean(__normalize(col.resize))) {
|
|
118
|
-
|
|
119
|
-
if (__requireBoolean(anchor === null)) {
|
|
120
|
-
throw "Resizable column must end at a first-row cell boundary";
|
|
121
|
-
}
|
|
122
|
-
__normalize(col.attach(anchor, table));
|
|
461
|
+
__normalize(col.attach(__normalize(first.boundary(offset)), __normalize(this.#table)));
|
|
123
462
|
}
|
|
124
463
|
}
|
|
125
464
|
}
|
|
465
|
+
return null;
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
dispose() {
|
|
469
|
+
if (__requireBoolean(__normalize(this.#aliases) !== null)) {
|
|
470
|
+
for (const [name, control] of __entries(__normalize(this.#aliases))) {
|
|
471
|
+
if (__requireBoolean(__normalize(this.form.controls[name]) === control)) {
|
|
472
|
+
__normalize(__hostGlobal(["Reflect"]).deleteProperty(__normalize(this.form.controls), name));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
this.#aliases = __normalize(__hostGlobal(["Object"]).create(null));
|
|
476
|
+
}
|
|
477
|
+
if (__requireBoolean(__normalize(this.rows) !== null)) {
|
|
478
|
+
for (const row of __normalize(this.rows)) {
|
|
479
|
+
__normalize(row.dispose());
|
|
480
|
+
}
|
|
481
|
+
this.rows = [];
|
|
482
|
+
}
|
|
483
|
+
if (__requireBoolean(__normalize(this.#layout) !== null)) {
|
|
484
|
+
__normalize(this.#layout.dispose());
|
|
485
|
+
}
|
|
486
|
+
return super.dispose();
|
|
487
|
+
return null;
|
|
126
488
|
}
|
|
127
489
|
}
|
|
128
490
|
|
|
@@ -136,23 +498,60 @@ export class TableHeader extends Control {
|
|
|
136
498
|
renderer = __boundary(renderer);
|
|
137
499
|
decorate(this, props);
|
|
138
500
|
this.rows = [];
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
501
|
+
try {
|
|
502
|
+
if (__requireBoolean(__normalize(props.controls) !== null)) {
|
|
503
|
+
for (const definition of __normalize(props.controls)) {
|
|
504
|
+
if (__requireBoolean(__normalize(definition.type) !== "tableRow")) {
|
|
505
|
+
throw "TableHeader accepts TableRow definitions";
|
|
506
|
+
}
|
|
507
|
+
let row = new TableRow(form, definition, renderer, true);
|
|
508
|
+
this.rows.push(row);
|
|
509
|
+
__normalize(this.element.appendChild(__normalize(row.element)));
|
|
143
510
|
}
|
|
144
|
-
let row = new TableRow(form, definition, renderer, true);
|
|
145
|
-
__normalize(form.register(__normalize(definition.name), row));
|
|
146
|
-
this.rows.push(row);
|
|
147
|
-
__normalize(this.element.appendChild(__normalize(row.element)));
|
|
148
511
|
}
|
|
512
|
+
} catch (error) {
|
|
513
|
+
this.dispose();
|
|
514
|
+
throw error;
|
|
149
515
|
}
|
|
150
516
|
}
|
|
517
|
+
prepareValue() {
|
|
518
|
+
let pending = [];
|
|
519
|
+
for (const row of __normalize(this.rows)) {
|
|
520
|
+
let ready = __normalize(row.prepareValue());
|
|
521
|
+
if (__requireBoolean(ready !== null)) {
|
|
522
|
+
pending.push(ready);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return allReady(pending);
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
clearValidation() {
|
|
529
|
+
super.clearValidation();
|
|
530
|
+
if (__requireBoolean(__normalize(this.rows) !== null)) {
|
|
531
|
+
for (const row of __normalize(this.rows)) {
|
|
532
|
+
__normalize(row.clearValidation());
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return null;
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
dispose() {
|
|
539
|
+
for (const row of __normalize(this.rows)) {
|
|
540
|
+
__normalize(row.dispose());
|
|
541
|
+
}
|
|
542
|
+
this.rows = [];
|
|
543
|
+
return super.dispose();
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
151
546
|
}
|
|
152
547
|
|
|
153
548
|
export class TableRow extends Control {
|
|
549
|
+
name;
|
|
550
|
+
data;
|
|
551
|
+
generated;
|
|
154
552
|
width;
|
|
155
|
-
|
|
553
|
+
cells;
|
|
554
|
+
#scope;
|
|
156
555
|
constructor(form, props, renderer, heading) {
|
|
157
556
|
super(form, props, cloneMarkup("table-row", ["<tr></tr>"].join("")));
|
|
158
557
|
__requireArity(arguments.length, [0, 1, 2, 3], "constructor");
|
|
@@ -161,27 +560,36 @@ export class TableRow extends Control {
|
|
|
161
560
|
renderer = __boundary(renderer);
|
|
162
561
|
heading = __boundary(heading);
|
|
163
562
|
decorate(this, props);
|
|
563
|
+
this.name = __normalize(props.name);
|
|
564
|
+
this.data = __hostGlobalCall(["structuredClone"], __normalize(props.data));
|
|
565
|
+
this.generated = false;
|
|
164
566
|
this.width = 0;
|
|
165
|
-
this
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
567
|
+
this.cells = [];
|
|
568
|
+
this.#scope = new TableScope(form);
|
|
569
|
+
try {
|
|
570
|
+
if (__requireBoolean(__normalize(props.controls) !== null)) {
|
|
571
|
+
for (const definition of __normalize(props.controls)) {
|
|
572
|
+
if (__requireBoolean(__normalize(definition.type) !== "tableCell")) {
|
|
573
|
+
throw "TableRow accepts TableCell definitions";
|
|
574
|
+
}
|
|
575
|
+
let cell = new TableCell(__normalize(this.#scope), definition, renderer, heading);
|
|
576
|
+
__normalize(this.#scope.register(__normalize(definition.name), cell));
|
|
577
|
+
this.cells.push(cell);
|
|
578
|
+
this.width = __numericAdd(__normalize(this.width), cell.element.colSpan);
|
|
579
|
+
__normalize(this.element.appendChild(__normalize(cell.element)));
|
|
170
580
|
}
|
|
171
|
-
let cell = new TableCell(form, definition, renderer, heading);
|
|
172
|
-
__normalize(form.register(__normalize(definition.name), cell));
|
|
173
|
-
this.#cells.push(cell);
|
|
174
|
-
this.width = __numericAdd(__normalize(this.width), cell.element.colSpan);
|
|
175
|
-
__normalize(this.element.appendChild(__normalize(cell.element)));
|
|
176
581
|
}
|
|
582
|
+
bindAction(this, __normalize(this.element), __normalize(props.url));
|
|
583
|
+
} catch (error) {
|
|
584
|
+
this.dispose();
|
|
585
|
+
throw error;
|
|
177
586
|
}
|
|
178
|
-
bindAction(this, __normalize(this.element), __normalize(props.url));
|
|
179
587
|
}
|
|
180
588
|
boundary(column) {
|
|
181
589
|
__requireArity(arguments.length, [0], "boundary");
|
|
182
590
|
column = __boundary(column);
|
|
183
591
|
let offset = 0;
|
|
184
|
-
for (const cell of __normalize(this
|
|
592
|
+
for (const cell of __normalize(this.cells)) {
|
|
185
593
|
offset = __numericAdd(offset, cell.element.colSpan);
|
|
186
594
|
if (__requireBoolean(offset === column)) {
|
|
187
595
|
return __normalize(cell.element);
|
|
@@ -190,9 +598,72 @@ export class TableRow extends Control {
|
|
|
190
598
|
return null;
|
|
191
599
|
return null;
|
|
192
600
|
}
|
|
601
|
+
setRowValue(value, columns) {
|
|
602
|
+
__requireArity(arguments.length, [0, 1], "setRowValue");
|
|
603
|
+
value = __boundary(value);
|
|
604
|
+
columns = __boundary(columns);
|
|
605
|
+
rowValue(value);
|
|
606
|
+
for (const [index, cell] of __entries(__normalize(this.cells))) {
|
|
607
|
+
let name = __normalize(cell.name);
|
|
608
|
+
if (__requireBoolean(index < __normalize(columns.length))) {
|
|
609
|
+
name = __normalize(__normalize(columns[index]).name);
|
|
610
|
+
}
|
|
611
|
+
let field = null;
|
|
612
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(value !== null) && __requireBoolean(name !== null)) && __requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(value, name))))) {
|
|
613
|
+
field = __normalize(value[name]);
|
|
614
|
+
}
|
|
615
|
+
__normalize(cell.setValue(field));
|
|
616
|
+
}
|
|
617
|
+
return this;
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
620
|
+
getRowValue(columns) {
|
|
621
|
+
__requireArity(arguments.length, [0], "getRowValue");
|
|
622
|
+
columns = __boundary(columns);
|
|
623
|
+
let result = __normalize(__hostGlobal(["Object"]).create(null));
|
|
624
|
+
for (const [index, cell] of __entries(__normalize(this.cells))) {
|
|
625
|
+
let name = __normalize(cell.name);
|
|
626
|
+
if (__requireBoolean(index < __normalize(columns.length))) {
|
|
627
|
+
name = __normalize(__normalize(columns[index]).name);
|
|
628
|
+
}
|
|
629
|
+
if (__requireBoolean(name !== null)) {
|
|
630
|
+
if (__requireBoolean(__includes(name, result))) {
|
|
631
|
+
throw `Duplicate row value name: ${name}`;
|
|
632
|
+
}
|
|
633
|
+
result[name] = __normalize(cell.getValue());
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return result;
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
getValue() {
|
|
640
|
+
return __normalize(this.#scope.getValue());
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
prepareValue() {
|
|
644
|
+
return __normalize(this.#scope.prepareValue());
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
clearValidation() {
|
|
648
|
+
super.clearValidation();
|
|
649
|
+
if (__requireBoolean(__normalize(this.#scope) !== null)) {
|
|
650
|
+
__normalize(this.#scope.clearValidation());
|
|
651
|
+
}
|
|
652
|
+
return null;
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
dispose() {
|
|
656
|
+
if (__requireBoolean(__normalize(this.#scope) !== null)) {
|
|
657
|
+
__normalize(this.#scope.dispose());
|
|
658
|
+
}
|
|
659
|
+
return super.dispose();
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
193
662
|
}
|
|
194
663
|
|
|
195
664
|
export class TableCell extends Control {
|
|
665
|
+
name;
|
|
666
|
+
scope;
|
|
196
667
|
constructor(form, props, renderer, heading) {
|
|
197
668
|
super(form, props, cellElement(heading));
|
|
198
669
|
__requireArity(arguments.length, [0, 1, 2, 3], "constructor");
|
|
@@ -200,26 +671,92 @@ export class TableCell extends Control {
|
|
|
200
671
|
props = __boundary(props);
|
|
201
672
|
renderer = __boundary(renderer);
|
|
202
673
|
heading = __boundary(heading);
|
|
203
|
-
this.
|
|
204
|
-
this.
|
|
205
|
-
|
|
206
|
-
this.element
|
|
674
|
+
this.name = __normalize(props.name);
|
|
675
|
+
this.scope = new TableScope(form);
|
|
676
|
+
try {
|
|
677
|
+
applySpan(__normalize(this.element), "colspan", __normalize(props.colSpan));
|
|
678
|
+
applySpan(__normalize(this.element), "rowspan", __normalize(props.rowSpan));
|
|
679
|
+
if (__requireBoolean(__normalize(props.verticalAlignment) !== null)) {
|
|
680
|
+
this.element.style.verticalAlign = __normalize(props.verticalAlignment);
|
|
681
|
+
}
|
|
682
|
+
if (__requireBoolean(__normalize(props.horizontalAlignment) !== null)) {
|
|
683
|
+
this.element.style.textAlign = __normalize(props.horizontalAlignment);
|
|
684
|
+
}
|
|
685
|
+
appendContent(__normalize(this.scope), __normalize(this.element), __normalize(props.controls), renderer);
|
|
686
|
+
decorate(this, props);
|
|
687
|
+
bindAction(this, __normalize(this.element), __normalize(props.url));
|
|
688
|
+
} catch (error) {
|
|
689
|
+
this.dispose();
|
|
690
|
+
throw error;
|
|
207
691
|
}
|
|
208
|
-
|
|
209
|
-
|
|
692
|
+
}
|
|
693
|
+
find(name) {
|
|
694
|
+
__requireArity(arguments.length, [0], "find");
|
|
695
|
+
name = __boundary(name);
|
|
696
|
+
return __normalize(this.scope.find(name));
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
getValue() {
|
|
700
|
+
if (__requireBoolean(__normalize(this.scope.owned.length) === 0)) {
|
|
701
|
+
return null;
|
|
210
702
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
for (const [name, value] of __entries(__normalize(props.style))) {
|
|
214
|
-
__normalize(this.element.style.setProperty(name, value));
|
|
215
|
-
}
|
|
703
|
+
if (__requireBoolean(__normalize(this.scope.owned.length) === 1)) {
|
|
704
|
+
return __normalize(__normalize(this.scope.owned[0]).getValue());
|
|
216
705
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
706
|
+
return __normalize(this.scope.getValue());
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
setValue(value) {
|
|
710
|
+
__requireArity(arguments.length, [0], "setValue");
|
|
711
|
+
value = __boundary(value);
|
|
712
|
+
if (__requireBoolean(__normalize(this.scope.owned.length) === 0)) {
|
|
713
|
+
let text = "";
|
|
714
|
+
if (__requireBoolean(value !== null)) {
|
|
715
|
+
if (__requireBoolean(__requireBoolean(__isObject(value)) || __requireBoolean(__isArray(value)))) {
|
|
716
|
+
text = __normalize(__hostGlobal(["JSON"]).stringify(value));
|
|
717
|
+
} else {
|
|
718
|
+
text = `${value}`;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
let handle = __normalize(this.element.querySelector(":scope > .lango-col-resize"));
|
|
722
|
+
this.element.textContent = text;
|
|
723
|
+
if (__requireBoolean(handle !== null)) {
|
|
724
|
+
__normalize(this.element.appendChild(handle));
|
|
220
725
|
}
|
|
726
|
+
} else {
|
|
727
|
+
if (__requireBoolean(value === null)) {
|
|
728
|
+
for (const control of __normalize(this.scope.owned)) {
|
|
729
|
+
clearValue(control);
|
|
730
|
+
}
|
|
731
|
+
} else {
|
|
732
|
+
if (__requireBoolean(__normalize(this.scope.owned.length) === 1)) {
|
|
733
|
+
__normalize(__normalize(this.scope.owned[0]).setValue(value));
|
|
734
|
+
} else {
|
|
735
|
+
__normalize(this.scope.setValue(value));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return this;
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
prepareValue() {
|
|
743
|
+
return __normalize(this.scope.prepareValue());
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
clearValidation() {
|
|
747
|
+
super.clearValidation();
|
|
748
|
+
if (__requireBoolean(__normalize(this.scope) !== null)) {
|
|
749
|
+
__normalize(this.scope.clearValidation());
|
|
221
750
|
}
|
|
222
|
-
|
|
751
|
+
return null;
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
dispose() {
|
|
755
|
+
if (__requireBoolean(__normalize(this.scope) !== null)) {
|
|
756
|
+
__normalize(this.scope.dispose());
|
|
757
|
+
}
|
|
758
|
+
return super.dispose();
|
|
759
|
+
return null;
|
|
223
760
|
}
|
|
224
761
|
}
|
|
225
762
|
|
|
@@ -234,6 +771,7 @@ export class TableDivider extends Control {
|
|
|
234
771
|
}
|
|
235
772
|
|
|
236
773
|
export class TableCol extends Control {
|
|
774
|
+
name;
|
|
237
775
|
span;
|
|
238
776
|
resize;
|
|
239
777
|
#handle;
|
|
@@ -245,13 +783,10 @@ export class TableCol extends Control {
|
|
|
245
783
|
decorate(this, props);
|
|
246
784
|
this.span = spanValue(__normalize(props.colSpan));
|
|
247
785
|
this.resize = __normalize(props.resize) === true;
|
|
248
|
-
this.element
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
} else {
|
|
253
|
-
this.element.style.width = __normalize(props.width);
|
|
254
|
-
}
|
|
786
|
+
applySpan(__normalize(this.element), "span", __normalize(this.span));
|
|
787
|
+
let width = columnWidth(__normalize(props.width));
|
|
788
|
+
if (__requireBoolean(width !== null)) {
|
|
789
|
+
this.element.style.width = width;
|
|
255
790
|
}
|
|
256
791
|
}
|
|
257
792
|
size(width) {
|
|
@@ -260,7 +795,16 @@ export class TableCol extends Control {
|
|
|
260
795
|
if (__requireBoolean(width < 24)) {
|
|
261
796
|
width = 24;
|
|
262
797
|
}
|
|
263
|
-
|
|
798
|
+
let ruler = __normalize(__hostGlobal(["document"]).createElement("span"));
|
|
799
|
+
ruler.textContent = "0";
|
|
800
|
+
let font = __hostGlobalCall(["getComputedStyle"], __normalize(this.element));
|
|
801
|
+
ruler.style.font = __normalize(font.font);
|
|
802
|
+
ruler.style.position = "absolute";
|
|
803
|
+
ruler.style.visibility = "hidden";
|
|
804
|
+
__normalize(__hostGlobal(["document"]).body.appendChild(ruler));
|
|
805
|
+
let unit = __normalize(__normalize(ruler.getBoundingClientRect()).width);
|
|
806
|
+
__remove(ruler);
|
|
807
|
+
this.element.style.width = `${__finite(width / unit)}ch`;
|
|
264
808
|
__normalize(this.#handle.setAttribute("aria-valuenow", `${width}`));
|
|
265
809
|
return null;
|
|
266
810
|
return null;
|
|
@@ -343,6 +887,14 @@ export class TableCol extends Control {
|
|
|
343
887
|
__add(this.release, release);
|
|
344
888
|
return null;
|
|
345
889
|
}
|
|
890
|
+
detach() {
|
|
891
|
+
for (const release of __normalize(this.release)) {
|
|
892
|
+
__call(release, );
|
|
893
|
+
}
|
|
894
|
+
this.release = [];
|
|
895
|
+
return null;
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
346
898
|
}
|
|
347
899
|
export function spanValue(value) {
|
|
348
900
|
__requireArity(arguments.length, [0], "spanValue");
|
|
@@ -357,6 +909,42 @@ export function spanValue(value) {
|
|
|
357
909
|
return null;
|
|
358
910
|
}
|
|
359
911
|
|
|
912
|
+
function applySpan(element, name, value) {
|
|
913
|
+
__requireArity(arguments.length, [0, 1, 2], "applySpan");
|
|
914
|
+
element = __boundary(element);
|
|
915
|
+
name = __boundary(name);
|
|
916
|
+
value = __boundary(value);
|
|
917
|
+
let span = spanValue(value);
|
|
918
|
+
if (__requireBoolean(span === 1)) {
|
|
919
|
+
__normalize(element.removeAttribute(name));
|
|
920
|
+
} else {
|
|
921
|
+
__normalize(element.setAttribute(name, `${span}`));
|
|
922
|
+
}
|
|
923
|
+
return null;
|
|
924
|
+
return null;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
export function columnWidth(value) {
|
|
928
|
+
__requireArity(arguments.length, [0], "columnWidth");
|
|
929
|
+
value = __boundary(value);
|
|
930
|
+
return measure(value, "ch");
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function clearValue(control) {
|
|
935
|
+
__requireArity(arguments.length, [0], "clearValue");
|
|
936
|
+
control = __boundary(control);
|
|
937
|
+
if (__requireBoolean(__isKindof(control, Form))) {
|
|
938
|
+
for (const child of __normalize(control.owned)) {
|
|
939
|
+
clearValue(child);
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
__normalize(control.setValue(null));
|
|
943
|
+
}
|
|
944
|
+
return null;
|
|
945
|
+
return null;
|
|
946
|
+
}
|
|
947
|
+
|
|
360
948
|
function cellElement(heading) {
|
|
361
949
|
__requireArity(arguments.length, [0], "cellElement");
|
|
362
950
|
heading = __boundary(heading);
|
|
@@ -366,4 +954,99 @@ function cellElement(heading) {
|
|
|
366
954
|
return cloneMarkup("table-cell", ["<td></td>"].join(""));
|
|
367
955
|
return null;
|
|
368
956
|
}
|
|
957
|
+
|
|
958
|
+
function addName(names, name, control) {
|
|
959
|
+
__requireArity(arguments.length, [0, 1, 2], "addName");
|
|
960
|
+
names = __boundary(names);
|
|
961
|
+
name = __boundary(name);
|
|
962
|
+
control = __boundary(control);
|
|
963
|
+
if (__requireBoolean(name === null)) {
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
966
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(__normalize(name.includes("/")))) || __requireBoolean(__includes(name, names)))) {
|
|
967
|
+
throw `Invalid or duplicate control name: ${name}`;
|
|
968
|
+
}
|
|
969
|
+
names[name] = control;
|
|
970
|
+
return null;
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
function rowValue(value) {
|
|
975
|
+
__requireArity(arguments.length, [0], "rowValue");
|
|
976
|
+
value = __boundary(value);
|
|
977
|
+
if (__requireBoolean(__requireBoolean(value !== null) && __requireBoolean(__requireBoolean(!__requireBoolean(__isObject(value))) || __requireBoolean(__isArray(value))))) {
|
|
978
|
+
throw "Table row value must be a map or null";
|
|
979
|
+
}
|
|
980
|
+
return value;
|
|
981
|
+
return null;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function tableIndex(index, length, insertion = false) {
|
|
985
|
+
__requireArity(arguments.length, [0, 1], "tableIndex");
|
|
986
|
+
index = __boundary(index);
|
|
987
|
+
length = __boundary(length);
|
|
988
|
+
insertion = __boundary(insertion);
|
|
989
|
+
let limit = __finite(length - 1);
|
|
990
|
+
if (__requireBoolean(insertion)) {
|
|
991
|
+
limit = length;
|
|
992
|
+
}
|
|
993
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(index))) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isInteger(index))))) || __requireBoolean(index < 0)) || __requireBoolean(index > limit))) {
|
|
994
|
+
throw `Table index out of range: ${index}`;
|
|
995
|
+
}
|
|
996
|
+
return index;
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function columnIndex(column, columns) {
|
|
1001
|
+
__requireArity(arguments.length, [0, 1], "columnIndex");
|
|
1002
|
+
column = __boundary(column);
|
|
1003
|
+
columns = __boundary(columns);
|
|
1004
|
+
if (__requireBoolean(__isString(column))) {
|
|
1005
|
+
for (const [index, col] of __entries(columns)) {
|
|
1006
|
+
if (__requireBoolean(__normalize(col.name) === column)) {
|
|
1007
|
+
return index;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
throw `Unknown table column: ${column}`;
|
|
1011
|
+
}
|
|
1012
|
+
return tableIndex(column, __normalize(columns.length));
|
|
1013
|
+
return null;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function validateBoundaries(header, rows, columns) {
|
|
1017
|
+
__requireArity(arguments.length, [0, 1, 2], "validateBoundaries");
|
|
1018
|
+
header = __boundary(header);
|
|
1019
|
+
rows = __boundary(rows);
|
|
1020
|
+
columns = __boundary(columns);
|
|
1021
|
+
let offset;
|
|
1022
|
+
let first = null;
|
|
1023
|
+
if (__requireBoolean(__requireBoolean(header !== null) && __requireBoolean(header.rows.length > 0))) {
|
|
1024
|
+
first = header.rows[0];
|
|
1025
|
+
} else {
|
|
1026
|
+
if (__requireBoolean(__normalize(rows.length) > 0)) {
|
|
1027
|
+
first = __normalize(rows[0]);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (__requireBoolean(first !== null)) {
|
|
1031
|
+
offset = 0;
|
|
1032
|
+
for (const col of columns) {
|
|
1033
|
+
offset = __numericAdd(offset, __normalize(col.span));
|
|
1034
|
+
if (__requireBoolean(__requireBoolean(__normalize(col.resize)) && __requireBoolean(__normalize(first.boundary(offset)) === null))) {
|
|
1035
|
+
throw "Resizable column must end at a first-row cell boundary";
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return first;
|
|
1040
|
+
return null;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function allReady(pending) {
|
|
1044
|
+
__requireArity(arguments.length, [0], "allReady");
|
|
1045
|
+
pending = __boundary(pending);
|
|
1046
|
+
if (__requireBoolean(__normalize(pending.length) === 0)) {
|
|
1047
|
+
return null;
|
|
1048
|
+
}
|
|
1049
|
+
return __normalize(__hostGlobal(["Promise"]).all(pending));
|
|
1050
|
+
return null;
|
|
1051
|
+
}
|
|
369
1052
|
//# sourceMappingURL=tables.mjs.map
|