@yuneta/gobj-ui 7.26.41 → 7.26.43
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 +510 -78
- package/dist/gobj-ui.cjs.js +1120 -326
- package/dist/gobj-ui.es.js +1120 -326
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +971 -177
- package/src/c_g6_nodes_tree.js +3 -2
- package/src/c_yui_form.js +261 -154
- package/src/c_yui_fsm_graph.js +3 -2
- package/src/c_yui_gobj_tree_js.js +3 -2
- package/src/c_yui_json_graph.js +3 -2
- package/src/c_yui_nav.js +43 -28
- package/src/c_yui_node.js +51 -7
- package/src/c_yui_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +110 -20
- package/src/c_yui_shell.css +4 -1
- package/src/c_yui_shell.js +227 -61
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window.js +373 -62
- package/src/c_yui_window_manager.js +80 -8
- package/src/escape_taken.js +58 -0
- package/src/form_close_asks_for_edits.wiring.test.js +6 -3
- package/src/form_json_editor_names.js +3 -1
- package/src/form_json_editor_names.wiring.test.js +8 -4
- package/src/form_json_expand.wiring.test.js +6 -3
- package/src/form_json_field.wiring.test.js +8 -4
- package/src/form_label_i18n.wiring.test.js +10 -5
- package/src/form_table_edits_ask.wiring.test.js +18 -8
- package/src/form_table_rearm.wiring.test.js +13 -5
- package/src/form_table_rows.wiring.test.js +489 -0
- package/src/form_table_validator.wiring.test.js +8 -4
- package/src/form_template_field.wiring.test.js +6 -3
- package/src/g6_canvas_tab_order.css +29 -0
- package/src/g6_canvas_tab_order.js +41 -9
- package/src/g6_canvas_tab_order.wiring.test.js +107 -1
- package/src/g6_long_press_clock.test.js +8 -3
- package/src/i18n_key_functions.js +81 -27
- package/src/i18n_key_functions.test.js +402 -4
- package/src/modal_guard_back.wiring.test.js +188 -0
- package/src/named_controls.wiring.test.js +323 -19
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/node_nav_events.wiring.test.js +93 -1
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_diagram_click.wiring.test.js +277 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_dialog_names.wiring.test.js +149 -0
- package/src/shell_escape_taken.wiring.test.js +142 -0
- package/src/shell_focus_trap.js +30 -2
- package/src/shell_focus_trap.test.js +90 -6
- package/src/shell_modals.js +113 -22
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/table_editor_name.wiring.test.js +10 -5
- package/src/treedb_column_title.wiring.test.js +8 -4
- package/src/treedb_graph_writes.wiring.test.js +6 -3
- package/src/treedb_json_drill.wiring.test.js +6 -3
- package/src/uplot_add_serie.test.js +6 -3
- package/src/uplot_ink.test.js +8 -4
- package/src/window_dialog.wiring.test.js +486 -0
- package/src/window_dock_band.wiring.test.js +189 -0
- package/src/window_layer.wiring.test.js +114 -0
- package/src/window_rect_rounding.wiring.test.js +121 -0
- package/src/yui_gclass_view.js +16 -1
- package/src/yui_tabulator_i18n.js +31 -1
- package/src/yui_tabulator_i18n.test.js +46 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* form_table_rows.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The rows of a C_YUI_FORM's tables: whose objects they are, when
|
|
5
|
+
* they are loaded, and what happens to the nested tables they hold.
|
|
6
|
+
*
|
|
7
|
+
* - Tabulator KEEPS the objects it is given (Row.setData() copies
|
|
8
|
+
* nothing) and a cell edit writes into them. Up to 7.26.42 the
|
|
9
|
+
* form handed it the objects of its `record`: an edit wrote into
|
|
10
|
+
* the record, Undo loaded that record again -- the edited values
|
|
11
|
+
* -- and cleared `edited`, so a later save sent what the reader
|
|
12
|
+
* believed undone. The record of the host was written too, and
|
|
13
|
+
* so was what the form published on a save.
|
|
14
|
+
* - A load waits for the table to be built (`tableBuilt`). Each load
|
|
15
|
+
* hung a listener of its own, and a clear skipped a table not
|
|
16
|
+
* built yet: two loads before the build drew the rows twice.
|
|
17
|
+
* - A row builds its nested tables when it is drawn. Nothing
|
|
18
|
+
* destroyed them -- not a reload, not an undo, not a deleted row,
|
|
19
|
+
* not the form -- and a row drawn AGAIN built new ones, empty.
|
|
20
|
+
* - A load added its rows one by one and redrew the table once per
|
|
21
|
+
* row, a redraw of every row each time: quadratic.
|
|
22
|
+
*
|
|
23
|
+
* Driven through the real gclass on a document double, with a
|
|
24
|
+
* Tabulator double that does what Tabulator does with rows: it
|
|
25
|
+
* keeps the objects it is given, writes an edit into them, answers
|
|
26
|
+
* getData() with copies and a row's getData() with the row itself,
|
|
27
|
+
* draws a row by running its formatter, says `dataChanged` per row
|
|
28
|
+
* added, synchronously, and builds itself a turn after it is made.
|
|
29
|
+
*
|
|
30
|
+
* Copyright (c) 2026, ArtGins.
|
|
31
|
+
* All Rights Reserved.
|
|
32
|
+
***********************************************************************/
|
|
33
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
34
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
35
|
+
|
|
36
|
+
install_dom_double();
|
|
37
|
+
|
|
38
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
39
|
+
globalThis.ResizeObserver = class {
|
|
40
|
+
observe() {
|
|
41
|
+
}
|
|
42
|
+
unobserve() {
|
|
43
|
+
}
|
|
44
|
+
disconnect() {
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const tables = vi.hoisted(() => []);
|
|
50
|
+
vi.mock("tabulator-tables", () => {
|
|
51
|
+
class FakeTabulator {
|
|
52
|
+
constructor($el, settings) {
|
|
53
|
+
this.element = $el;
|
|
54
|
+
this.settings = settings;
|
|
55
|
+
this.options = {};
|
|
56
|
+
this.handlers = {};
|
|
57
|
+
this.initialized = false;
|
|
58
|
+
this.destroyed = false;
|
|
59
|
+
this.rows = [];
|
|
60
|
+
this.calls = {addRow: 0, addData: 0, redraw: 0};
|
|
61
|
+
this.modules = {
|
|
62
|
+
localize: {
|
|
63
|
+
installLang: () => {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
tables.push(this);
|
|
68
|
+
/* Tabulator builds itself a turn after it is made. */
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
if(!this.destroyed) {
|
|
71
|
+
this.initialized = true;
|
|
72
|
+
this.emit("tableBuilt");
|
|
73
|
+
}
|
|
74
|
+
}, 0);
|
|
75
|
+
return new Proxy(this, {
|
|
76
|
+
get(target, prop) {
|
|
77
|
+
if(prop in target) {
|
|
78
|
+
return target[prop];
|
|
79
|
+
}
|
|
80
|
+
return () => [];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
on(ev, fn) {
|
|
85
|
+
(this.handlers[ev] = this.handlers[ev] || []).push(fn);
|
|
86
|
+
}
|
|
87
|
+
off(ev) {
|
|
88
|
+
delete this.handlers[ev];
|
|
89
|
+
}
|
|
90
|
+
emit(ev, ...args) {
|
|
91
|
+
for(const fn of (this.handlers[ev] || [])) {
|
|
92
|
+
fn(...args);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
must_be_built() {
|
|
96
|
+
if(!this.initialized) {
|
|
97
|
+
throw new Error("Table Not Initialized");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
add(record) {
|
|
101
|
+
const $row = document.createElement("div");
|
|
102
|
+
this.element.appendChild($row);
|
|
103
|
+
const row = {data: record, $row: $row};
|
|
104
|
+
row.component = {
|
|
105
|
+
getElement: () => row.$row,
|
|
106
|
+
getData: () => row.data,
|
|
107
|
+
delete: () => {
|
|
108
|
+
this.delete_row(this.rows.indexOf(row));
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
if(this.settings && typeof this.settings.rowFormatter === "function") {
|
|
112
|
+
this.settings.rowFormatter(row.component);
|
|
113
|
+
}
|
|
114
|
+
this.rows.push(row);
|
|
115
|
+
this.emit("dataChanged");
|
|
116
|
+
return row.component;
|
|
117
|
+
}
|
|
118
|
+
addRow(record) {
|
|
119
|
+
this.must_be_built();
|
|
120
|
+
this.calls.addRow++;
|
|
121
|
+
return Promise.resolve(this.add(record));
|
|
122
|
+
}
|
|
123
|
+
addData(records) {
|
|
124
|
+
this.must_be_built();
|
|
125
|
+
this.calls.addData++;
|
|
126
|
+
return Promise.resolve(records.map((record) => this.add(record)));
|
|
127
|
+
}
|
|
128
|
+
getRows() {
|
|
129
|
+
return this.rows.map((row) => row.component);
|
|
130
|
+
}
|
|
131
|
+
getData() {
|
|
132
|
+
return this.rows.map((row) => structuredClone(row.data));
|
|
133
|
+
}
|
|
134
|
+
getDataCount() {
|
|
135
|
+
return this.rows.length;
|
|
136
|
+
}
|
|
137
|
+
/* What an edited cell does: the row's own object is written. */
|
|
138
|
+
edit_cell(index, field, value) {
|
|
139
|
+
this.rows[index].data[field] = value;
|
|
140
|
+
this.emit("dataChanged");
|
|
141
|
+
}
|
|
142
|
+
/* row.delete(): `rowDeleted` while the row still has its element. */
|
|
143
|
+
delete_row(index) {
|
|
144
|
+
const row = this.rows[index];
|
|
145
|
+
this.rows.splice(index, 1);
|
|
146
|
+
this.emit("rowDeleted", row.component);
|
|
147
|
+
row.$row.remove();
|
|
148
|
+
this.emit("dataChanged");
|
|
149
|
+
}
|
|
150
|
+
/* What a forced redraw does to a row: its children are taken off
|
|
151
|
+
* and its formatter runs again. */
|
|
152
|
+
draw_row_again(index) {
|
|
153
|
+
const row = this.rows[index];
|
|
154
|
+
while(row.$row.firstChild) {
|
|
155
|
+
row.$row.removeChild(row.$row.firstChild);
|
|
156
|
+
}
|
|
157
|
+
this.settings.rowFormatter(row.component);
|
|
158
|
+
}
|
|
159
|
+
clearData() {
|
|
160
|
+
this.must_be_built();
|
|
161
|
+
for(const row of this.rows) {
|
|
162
|
+
while(row.$row.firstChild) {
|
|
163
|
+
row.$row.removeChild(row.$row.firstChild);
|
|
164
|
+
}
|
|
165
|
+
row.$row.remove();
|
|
166
|
+
}
|
|
167
|
+
this.rows = [];
|
|
168
|
+
}
|
|
169
|
+
redraw() {
|
|
170
|
+
this.calls.redraw++;
|
|
171
|
+
}
|
|
172
|
+
validate() {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
setLocale() {
|
|
176
|
+
}
|
|
177
|
+
destroy() {
|
|
178
|
+
this.destroyed = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const {
|
|
185
|
+
SDATA_END, gclass_create,
|
|
186
|
+
gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
187
|
+
gobj_start, gobj_stop, gobj_destroy, gobj_send_event, gobj_read_attr,
|
|
188
|
+
set_log_callback,
|
|
189
|
+
} = await import("@yuneta/gobj-js");
|
|
190
|
+
const {register_c_yui_form} = await import("./c_yui_form.js");
|
|
191
|
+
|
|
192
|
+
const logged = [];
|
|
193
|
+
const saved = [];
|
|
194
|
+
let yuno = null;
|
|
195
|
+
|
|
196
|
+
/* A device's settings, cut down: the alarms as a table whose rows
|
|
197
|
+
* carry a nested table of triggers. */
|
|
198
|
+
const TEMPLATE = {
|
|
199
|
+
template_version: {
|
|
200
|
+
type: "integer",
|
|
201
|
+
default: 7,
|
|
202
|
+
flag: ["hidden", "persistent"]
|
|
203
|
+
},
|
|
204
|
+
alarms: {
|
|
205
|
+
type: "array",
|
|
206
|
+
flag: ["writable", "persistent", "table"],
|
|
207
|
+
table: {
|
|
208
|
+
name: {
|
|
209
|
+
type: "string",
|
|
210
|
+
header: "alarm name",
|
|
211
|
+
flag: ["writable", "persistent"]
|
|
212
|
+
},
|
|
213
|
+
triggers: {
|
|
214
|
+
type: "array",
|
|
215
|
+
flag: ["writable", "persistent", "table"],
|
|
216
|
+
table: {
|
|
217
|
+
measure: {
|
|
218
|
+
type: "string",
|
|
219
|
+
header: "measure",
|
|
220
|
+
flag: ["writable", "persistent"]
|
|
221
|
+
},
|
|
222
|
+
value: {
|
|
223
|
+
type: "integer",
|
|
224
|
+
header: "value",
|
|
225
|
+
flag: ["writable", "persistent"]
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
function record()
|
|
234
|
+
{
|
|
235
|
+
return {
|
|
236
|
+
template_version: 7,
|
|
237
|
+
alarms: [
|
|
238
|
+
{name: "too hot", triggers: [{measure: "temperature", value: 30}]},
|
|
239
|
+
{name: "too wet", triggers: [{measure: "humidity", value: 80}]}
|
|
240
|
+
]
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
beforeAll(async () => {
|
|
245
|
+
const i18next = (await import("i18next")).default;
|
|
246
|
+
await i18next.init({lng: "en", resources: {}});
|
|
247
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
248
|
+
set_log_callback((level, msg) => {
|
|
249
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
250
|
+
});
|
|
251
|
+
gclass_create("C_TEST_TR_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
252
|
+
gclass_create(
|
|
253
|
+
"C_TEST_TR_APP",
|
|
254
|
+
[["EV_SAVE_RECORD", 0]],
|
|
255
|
+
[["ST_IDLE", [
|
|
256
|
+
["EV_SAVE_RECORD", (gobj, event, kw) => {
|
|
257
|
+
saved.push(kw);
|
|
258
|
+
return 0;
|
|
259
|
+
}, null],
|
|
260
|
+
]]],
|
|
261
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
262
|
+
);
|
|
263
|
+
register_c_yui_form();
|
|
264
|
+
yuno = gobj_create_yuno("form_table_rows_yuno", "C_TEST_TR_HOST", {});
|
|
265
|
+
gobj_start(yuno);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
beforeEach(() => {
|
|
269
|
+
logged.length = 0;
|
|
270
|
+
saved.length = 0;
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
let seq = 0;
|
|
274
|
+
|
|
275
|
+
/* `then(form)` runs in the same turn as the start, before any table
|
|
276
|
+
* is built. */
|
|
277
|
+
function build(rec, then)
|
|
278
|
+
{
|
|
279
|
+
const first = tables.length;
|
|
280
|
+
const app = gobj_create_pure_child(`trapp${++seq}`, "C_TEST_TR_APP", {}, yuno);
|
|
281
|
+
gobj_start(app);
|
|
282
|
+
const form = gobj_create_pure_child(`trform${seq}`, "C_YUI_FORM", {
|
|
283
|
+
template: TEMPLATE,
|
|
284
|
+
record: rec,
|
|
285
|
+
editable: true,
|
|
286
|
+
}, app);
|
|
287
|
+
gobj_start(form);
|
|
288
|
+
if(then) {
|
|
289
|
+
then(form);
|
|
290
|
+
}
|
|
291
|
+
return {form, first};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/* Every table builds itself a turn after it is made, and a nested one
|
|
295
|
+
* is made when its row is drawn: a few turns until all are loaded. */
|
|
296
|
+
async function settle()
|
|
297
|
+
{
|
|
298
|
+
for(let i = 0; i < 4; i++) {
|
|
299
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* The alarms table of the form, and the tables alive. */
|
|
304
|
+
function alarms_of(first)
|
|
305
|
+
{
|
|
306
|
+
return tables[first];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function live()
|
|
310
|
+
{
|
|
311
|
+
return tables.filter((tb) => !tb.destroyed).length;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* The triggers table drawn in a row of the alarms table. */
|
|
315
|
+
function triggers_of(alarms, index)
|
|
316
|
+
{
|
|
317
|
+
const $nested = alarms.rows[index].$row.querySelector(".yui-tabulator-table-nested");
|
|
318
|
+
return $nested ? $nested.tabulator : null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function shown(alarms)
|
|
322
|
+
{
|
|
323
|
+
return alarms.rows.map((row) => {
|
|
324
|
+
const triggers = triggers_of(alarms, alarms.rows.indexOf(row));
|
|
325
|
+
return {
|
|
326
|
+
name: row.data.name,
|
|
327
|
+
values: triggers ? triggers.rows.map((r) => r.data.value) : null
|
|
328
|
+
};
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function close_asks(form)
|
|
333
|
+
{
|
|
334
|
+
const kw = {abort_close: false};
|
|
335
|
+
gobj_send_event(form, "EV_WINDOW_TO_CLOSE", kw, form);
|
|
336
|
+
return kw.abort_close;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function errors()
|
|
340
|
+
{
|
|
341
|
+
return logged.filter((l) => /error/i.test(l.level) || /ERROR/.test(l.msg));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
describe("Undo gives the tables back the values the form was loaded with", () => {
|
|
345
|
+
test("an edited cell and an edited nested cell are undone, and the record is untouched", async () => {
|
|
346
|
+
const host_record = record();
|
|
347
|
+
const {form, first} = build(host_record);
|
|
348
|
+
await settle();
|
|
349
|
+
const alarms = alarms_of(first);
|
|
350
|
+
expect(shown(alarms)).toEqual([
|
|
351
|
+
{name: "too hot", values: [30]},
|
|
352
|
+
{name: "too wet", values: [80]}
|
|
353
|
+
]);
|
|
354
|
+
|
|
355
|
+
alarms.edit_cell(0, "name", "too hot EDIT");
|
|
356
|
+
triggers_of(alarms, 0).edit_cell(0, "value", 309);
|
|
357
|
+
expect(gobj_read_attr(form, "edited")).toBe(true);
|
|
358
|
+
expect(gobj_read_attr(form, "record")).toEqual(record());
|
|
359
|
+
expect(host_record).toEqual(record());
|
|
360
|
+
|
|
361
|
+
gobj_send_event(form, "EV_UNDO_RECORD", {}, form);
|
|
362
|
+
await settle();
|
|
363
|
+
expect(shown(alarms)).toEqual([
|
|
364
|
+
{name: "too hot", values: [30]},
|
|
365
|
+
{name: "too wet", values: [80]}
|
|
366
|
+
]);
|
|
367
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
368
|
+
expect(close_asks(form)).toBe(false);
|
|
369
|
+
expect(errors()).toEqual([]);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("what a save published is not written by a later edit", async () => {
|
|
373
|
+
const {form, first} = build(record());
|
|
374
|
+
await settle();
|
|
375
|
+
const alarms = alarms_of(first);
|
|
376
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
377
|
+
expect(saved.length).toBe(1);
|
|
378
|
+
const published = structuredClone(saved[0]);
|
|
379
|
+
|
|
380
|
+
alarms.edit_cell(0, "name", "after the save");
|
|
381
|
+
triggers_of(alarms, 0).edit_cell(0, "value", 1);
|
|
382
|
+
expect(saved[0]).toEqual(published);
|
|
383
|
+
expect(saved[0].alarms[0].name).toBe("too hot");
|
|
384
|
+
expect(saved[0].alarms[0].triggers).toEqual([{measure: "temperature", value: 30}]);
|
|
385
|
+
expect(errors()).toEqual([]);
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
describe("a load before the table is built", () => {
|
|
390
|
+
test("two loads in the turn the form starts in draw the rows once", async () => {
|
|
391
|
+
const {first} = build(record(), (form) => {
|
|
392
|
+
gobj_send_event(form, "EV_LOAD_RECORD", record(), form);
|
|
393
|
+
});
|
|
394
|
+
await settle();
|
|
395
|
+
expect(shown(alarms_of(first))).toEqual([
|
|
396
|
+
{name: "too hot", values: [30]},
|
|
397
|
+
{name: "too wet", values: [80]}
|
|
398
|
+
]);
|
|
399
|
+
expect(errors()).toEqual([]);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test("a Clear before the build leaves the table empty", async () => {
|
|
403
|
+
const {first} = build(record(), (form) => {
|
|
404
|
+
gobj_send_event(form, "EV_CLEAR_RECORD", {}, form);
|
|
405
|
+
});
|
|
406
|
+
await settle();
|
|
407
|
+
expect(alarms_of(first).rows.length).toBe(0);
|
|
408
|
+
expect(errors()).toEqual([]);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
describe("the nested tables go with what they belong to", () => {
|
|
413
|
+
test("reloads and an undo destroy the nested tables they replace; the form takes the rest", async () => {
|
|
414
|
+
const before = live();
|
|
415
|
+
const {form} = build(record());
|
|
416
|
+
await settle();
|
|
417
|
+
expect(live() - before).toBe(3); // the alarms, and a triggers table per row
|
|
418
|
+
for(let i = 0; i < 5; i++) {
|
|
419
|
+
gobj_send_event(form, "EV_LOAD_RECORD", record(), form);
|
|
420
|
+
await settle();
|
|
421
|
+
}
|
|
422
|
+
expect(live() - before).toBe(3);
|
|
423
|
+
gobj_send_event(form, "EV_UNDO_RECORD", {}, form);
|
|
424
|
+
await settle();
|
|
425
|
+
expect(live() - before).toBe(3);
|
|
426
|
+
gobj_send_event(form, "EV_CLEAR_RECORD", {}, form);
|
|
427
|
+
await settle();
|
|
428
|
+
expect(live() - before).toBe(1);
|
|
429
|
+
gobj_send_event(form, "EV_LOAD_RECORD", record(), form);
|
|
430
|
+
await settle();
|
|
431
|
+
gobj_stop(form);
|
|
432
|
+
gobj_destroy(form);
|
|
433
|
+
expect(live() - before).toBe(0);
|
|
434
|
+
expect(errors()).toEqual([]);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
test("a row the reader deletes takes its nested table with it", async () => {
|
|
438
|
+
const before = live();
|
|
439
|
+
const {form, first} = build(record());
|
|
440
|
+
await settle();
|
|
441
|
+
const alarms = alarms_of(first);
|
|
442
|
+
const triggers = triggers_of(alarms, 0);
|
|
443
|
+
alarms.delete_row(0);
|
|
444
|
+
expect(triggers.destroyed).toBe(true);
|
|
445
|
+
expect(live() - before).toBe(2);
|
|
446
|
+
expect(close_asks(form)).toBe(true);
|
|
447
|
+
expect(errors()).toEqual([]);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
test("a row drawn again keeps its nested table, with its rows", async () => {
|
|
451
|
+
const {form, first} = build(record());
|
|
452
|
+
await settle();
|
|
453
|
+
const alarms = alarms_of(first);
|
|
454
|
+
const triggers = triggers_of(alarms, 0);
|
|
455
|
+
triggers.edit_cell(0, "value", 31);
|
|
456
|
+
const made = tables.length;
|
|
457
|
+
|
|
458
|
+
alarms.draw_row_again(0);
|
|
459
|
+
await settle();
|
|
460
|
+
expect(tables.length).toBe(made);
|
|
461
|
+
expect(triggers_of(alarms, 0)).toBe(triggers);
|
|
462
|
+
expect(triggers.destroyed).toBe(false);
|
|
463
|
+
expect(shown(alarms)[0]).toEqual({name: "too hot", values: [31]});
|
|
464
|
+
|
|
465
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
466
|
+
expect(saved[0].alarms[0].triggers).toEqual([{measure: "temperature", value: 31}]);
|
|
467
|
+
expect(errors()).toEqual([]);
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
describe("a table is loaded in one call", () => {
|
|
472
|
+
test("one call for all its rows and one redraw, not one of each per row", async () => {
|
|
473
|
+
const many = {
|
|
474
|
+
template_version: 7,
|
|
475
|
+
alarms: Array.from({length: 40}, (_, i) => ({name: `a${i}`, triggers: []}))
|
|
476
|
+
};
|
|
477
|
+
const {form, first} = build(many);
|
|
478
|
+
await settle();
|
|
479
|
+
await new Promise(resolve => setTimeout(resolve, 60)); // the redraw after the load
|
|
480
|
+
const alarms = alarms_of(first);
|
|
481
|
+
expect(alarms.rows.length).toBe(40);
|
|
482
|
+
expect(alarms.calls.addRow).toBe(0);
|
|
483
|
+
expect(alarms.calls.addData).toBe(1);
|
|
484
|
+
expect(alarms.calls.redraw).toBe(1);
|
|
485
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
486
|
+
expect(close_asks(form)).toBe(false);
|
|
487
|
+
expect(errors()).toEqual([]);
|
|
488
|
+
});
|
|
489
|
+
});
|
|
@@ -27,9 +27,12 @@ install_dom_double();
|
|
|
27
27
|
|
|
28
28
|
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
29
29
|
globalThis.ResizeObserver = class {
|
|
30
|
-
observe() {
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
observe() {
|
|
31
|
+
}
|
|
32
|
+
unobserve() {
|
|
33
|
+
}
|
|
34
|
+
disconnect() {
|
|
35
|
+
}
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -87,7 +90,8 @@ beforeAll(async () => {
|
|
|
87
90
|
const i18next = (await import("i18next")).default;
|
|
88
91
|
await i18next.init({lng: "en", resources: {}});
|
|
89
92
|
gobj_start_up(null, null, null, null, null, null, null);
|
|
90
|
-
set_log_callback(() => {
|
|
93
|
+
set_log_callback(() => {
|
|
94
|
+
});
|
|
91
95
|
gclass_create("C_TEST_FORM_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
92
96
|
gclass_create(
|
|
93
97
|
"C_TEST_FORM_APP",
|
|
@@ -21,9 +21,12 @@ install_dom_double();
|
|
|
21
21
|
|
|
22
22
|
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
23
23
|
globalThis.ResizeObserver = class {
|
|
24
|
-
observe() {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
observe() {
|
|
25
|
+
}
|
|
26
|
+
unobserve() {
|
|
27
|
+
}
|
|
28
|
+
disconnect() {
|
|
29
|
+
}
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* g6_canvas_tab_order.css
|
|
3
|
+
*
|
|
4
|
+
* The focus ring of the main canvas of a G6 graph -- the one
|
|
5
|
+
* control of the graph in the Tab order, and named for what it
|
|
6
|
+
* draws (g6_canvas_tab_order.js gives it the `G6_MAIN_CANVAS`
|
|
7
|
+
* class). Brought along by that module, which every view that
|
|
8
|
+
* draws a G6 graph imports.
|
|
9
|
+
*
|
|
10
|
+
* G6 writes `outline: none` on its canvases, INLINE (configCanvasDom,
|
|
11
|
+
* when it builds them and on a renderer change), so a keyboard that
|
|
12
|
+
* Tabbed onto the graph saw no sign of where it was. An inline style
|
|
13
|
+
* is reached only by `!important`.
|
|
14
|
+
*
|
|
15
|
+
* `:focus-visible`, so a pointer that presses the graph -- and the
|
|
16
|
+
* views that give the canvas the keyboard on a press -- draw no
|
|
17
|
+
* ring. The colour is the link token as INK (`-on-scheme`, see the
|
|
18
|
+
* README's "Colour" convention), legible on the light and the dark
|
|
19
|
+
* scheme; inset, so a container that clips the graph does not clip
|
|
20
|
+
* the ring. No transition: a focus appears at once.
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) 2026, ArtGins.
|
|
23
|
+
* All Rights Reserved.
|
|
24
|
+
***********************************************************************/
|
|
25
|
+
|
|
26
|
+
.G6_MAIN_CANVAS:focus-visible {
|
|
27
|
+
outline: 2px solid var(--bulma-link-on-scheme, var(--bulma-link, #485fc7)) !important;
|
|
28
|
+
outline-offset: -2px !important;
|
|
29
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* g6_canvas_tab_order.js
|
|
3
3
|
*
|
|
4
4
|
* The canvases of a G6 graph in the page's Tab order: the main
|
|
5
|
-
* one in its place, the other layers out of it.
|
|
5
|
+
* one in its place, and NAMED; the other layers out of it.
|
|
6
6
|
*
|
|
7
7
|
* G6 stacks four canvases (background, main, label, transient)
|
|
8
8
|
* and gives each of them `tabIndex = 1` (configCanvasDom, when it
|
|
@@ -15,6 +15,24 @@
|
|
|
15
15
|
* to the graph's toolbars and buttons in DOM order; the other
|
|
16
16
|
* layers receive nothing (`pointer-events: none`) and take -1.
|
|
17
17
|
*
|
|
18
|
+
* A canvas in the Tab order is a control, and a control has a
|
|
19
|
+
* name: the main canvas carries a `title` and an `aria-label`,
|
|
20
|
+
* through t() and each with its key, that say WHICH graph it is
|
|
21
|
+
* -- the key is the view's, one per gclass ("json graph",
|
|
22
|
+
* "schema graph"...). From 7.26.28 to 7.26.41 Tab landed on it
|
|
23
|
+
* and a reader announced nothing. The keys are what a language
|
|
24
|
+
* switch reaches (refresh_language()), as on any control. It is
|
|
25
|
+
* a `region`, as maplibre makes its own canvas: a name on an
|
|
26
|
+
* element with no role is one ARIA forbids, and a reader is not
|
|
27
|
+
* bound to say it.
|
|
28
|
+
*
|
|
29
|
+
* And it can be SEEN when it has the focus: G6 writes `outline:
|
|
30
|
+
* none` on its canvases, inline, so a keyboard that Tabbed onto
|
|
31
|
+
* the graph had no sign of where it was. The main canvas takes
|
|
32
|
+
* the `G6_MAIN_CANVAS` class, and g6_canvas_tab_order.css --
|
|
33
|
+
* imported here, so it comes with the module to every view --
|
|
34
|
+
* draws a ring on it at `:focus-visible`.
|
|
35
|
+
*
|
|
18
36
|
* Every view that creates a G6 Graph calls
|
|
19
37
|
* keep_canvas_tab_order() right after `new Graph()`: the order is
|
|
20
38
|
* put right each time G6 writes the 1 -- once the canvas is built
|
|
@@ -32,12 +50,16 @@ import {
|
|
|
32
50
|
} from "@yuneta/gobj-js";
|
|
33
51
|
|
|
34
52
|
import {GraphEvent} from "@antv/g6";
|
|
53
|
+
import {t} from "i18next";
|
|
54
|
+
|
|
55
|
+
import "./g6_canvas_tab_order.css";
|
|
35
56
|
|
|
36
57
|
/************************************************************
|
|
37
|
-
* Main canvas 0,
|
|
38
|
-
*
|
|
58
|
+
* Main canvas 0, named by `name_key`, and marked for its
|
|
59
|
+
* focus ring; every other layer -1. Returns 0, or -1 with the
|
|
60
|
+
* cause logged.
|
|
39
61
|
************************************************************/
|
|
40
|
-
function set_canvas_tab_order(gobj, graph)
|
|
62
|
+
function set_canvas_tab_order(gobj, graph, name_key)
|
|
41
63
|
{
|
|
42
64
|
let canvas = graph? graph.getCanvas() : null;
|
|
43
65
|
|
|
@@ -60,20 +82,30 @@ function set_canvas_tab_order(gobj, graph)
|
|
|
60
82
|
ret = -1;
|
|
61
83
|
continue;
|
|
62
84
|
}
|
|
63
|
-
|
|
85
|
+
if(name !== "main") {
|
|
86
|
+
$el.tabIndex = -1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
$el.tabIndex = 0;
|
|
90
|
+
$el.classList.add("G6_MAIN_CANVAS");
|
|
91
|
+
$el.setAttribute("role", "region");
|
|
92
|
+
$el.setAttribute("title", t(name_key));
|
|
93
|
+
$el.setAttribute("data-i18n-title", name_key);
|
|
94
|
+
$el.setAttribute("aria-label", t(name_key));
|
|
95
|
+
$el.setAttribute("data-i18n-aria-label", name_key);
|
|
64
96
|
}
|
|
65
97
|
return ret;
|
|
66
98
|
}
|
|
67
99
|
|
|
68
100
|
/************************************************************
|
|
69
|
-
* Keep the order for the life of `graph`: on
|
|
70
|
-
* writes its own.
|
|
101
|
+
* Keep the order, and the name, for the life of `graph`: on
|
|
102
|
+
* every moment G6 writes its own.
|
|
71
103
|
************************************************************/
|
|
72
|
-
function keep_canvas_tab_order(gobj, graph)
|
|
104
|
+
function keep_canvas_tab_order(gobj, graph, name_key)
|
|
73
105
|
{
|
|
74
106
|
for(let ev of [GraphEvent.AFTER_CANVAS_INIT, GraphEvent.AFTER_RENDERER_CHANGE]) {
|
|
75
107
|
graph.on(ev, () => {
|
|
76
|
-
set_canvas_tab_order(gobj, graph);
|
|
108
|
+
set_canvas_tab_order(gobj, graph, name_key);
|
|
77
109
|
});
|
|
78
110
|
}
|
|
79
111
|
}
|