@yuneta/gobj-ui 7.26.57 → 7.26.58
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/dist/gobj-ui.cjs.js +44 -11
- package/dist/gobj-ui.es.js +44 -11
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +10 -4
- package/src/c_yui_treedb_topic_with_form.js +12 -2
- package/src/fmt_date_time.test.js +1 -1
- package/src/treedb_topic_editor_guard.wiring.test.js +173 -0
- package/src/yui_tabulator_edit.js +46 -10
- package/src/yui_tabulator_edit.test.js +74 -3
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -10369,12 +10369,15 @@ function form_time_cell_editor(real_type) {
|
|
|
10369
10369
|
* is alive, and opened again on the new cell of the same row
|
|
10370
10370
|
* and column after it (after the promise, for the calls that
|
|
10371
10371
|
* answer one). What was typed in the box is lost; the editor
|
|
10372
|
-
* stays open under the reader.
|
|
10373
|
-
*
|
|
10374
|
-
*
|
|
10372
|
+
* stays open under the reader. It is NOT opened again, and the
|
|
10373
|
+
* log says why, when: the cell is out of the page (a row the
|
|
10374
|
+
* virtual DOM does not render, or a filter hides), its column is
|
|
10375
|
+
* gone or has no editor any more, the call answered a REFUSAL
|
|
10376
|
+
* (it rebuilt nothing), or -- before a promise answers -- the
|
|
10377
|
+
* table was destroyed or another cell's editor was opened.
|
|
10375
10378
|
*
|
|
10376
10379
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
10377
|
-
* destroy)
|
|
10380
|
+
* destroy) cancels the edit first with
|
|
10378
10381
|
* `yui_tabulator_close_editor()`: there is no cell to open it
|
|
10379
10382
|
* on again.
|
|
10380
10383
|
*
|
|
@@ -10422,18 +10425,42 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10422
10425
|
tabulator.on("cellEditCancelled", function() {
|
|
10423
10426
|
editing = null;
|
|
10424
10427
|
});
|
|
10428
|
+
function stays_closed(field, why) {
|
|
10429
|
+
(0, _yuneta_gobj_js.log_warning)(`yui_tabulator_keep_edit_on_redraw: the edit of '${field}' stays closed: ${why}`);
|
|
10430
|
+
}
|
|
10431
|
+
function has_column(field) {
|
|
10432
|
+
return tabulator.getColumns().some((c) => c.getField() === field);
|
|
10433
|
+
}
|
|
10425
10434
|
function edit_again(row, field, name) {
|
|
10435
|
+
if (tabulator.destroyed) {
|
|
10436
|
+
stays_closed(field, `the table was destroyed after ${name}()`);
|
|
10437
|
+
return;
|
|
10438
|
+
}
|
|
10439
|
+
let $open = editing ? editing.getElement() : null;
|
|
10440
|
+
if ($open && $open.classList.contains("tabulator-editing")) {
|
|
10441
|
+
stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10442
|
+
return;
|
|
10443
|
+
}
|
|
10426
10444
|
let again = row.getCell(field);
|
|
10427
10445
|
if (!again) {
|
|
10428
|
-
(
|
|
10446
|
+
if (has_column(field)) stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10447
|
+
else stays_closed(field, `no column '${field}' after ${name}()`);
|
|
10429
10448
|
return;
|
|
10430
10449
|
}
|
|
10431
10450
|
let $again = again.getElement();
|
|
10432
10451
|
if (!$again || !$again.isConnected) {
|
|
10433
|
-
(
|
|
10452
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10453
|
+
return;
|
|
10454
|
+
}
|
|
10455
|
+
if (!again.getColumn().getDefinition().editor) {
|
|
10456
|
+
stays_closed(field, `the column has no editor after ${name}()`);
|
|
10434
10457
|
return;
|
|
10435
10458
|
}
|
|
10436
|
-
|
|
10459
|
+
try {
|
|
10460
|
+
again.edit(true);
|
|
10461
|
+
} catch (e) {
|
|
10462
|
+
stays_closed(field, `Tabulator refused to open it after ${name}(): ${e}`);
|
|
10463
|
+
}
|
|
10437
10464
|
}
|
|
10438
10465
|
function keep_edit_around(name, rebuilds) {
|
|
10439
10466
|
let original = tabulator[name].bind(tabulator);
|
|
@@ -10449,7 +10476,7 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10449
10476
|
edit_again(row, field, name);
|
|
10450
10477
|
return value;
|
|
10451
10478
|
}, (reason) => {
|
|
10452
|
-
|
|
10479
|
+
stays_closed(field, `${name}() was refused: ${reason}`);
|
|
10453
10480
|
throw reason;
|
|
10454
10481
|
});
|
|
10455
10482
|
edit_again(row, field, name);
|
|
@@ -34629,9 +34656,15 @@ function ac_load_node_updated(gobj, event, kw, src) {
|
|
|
34629
34656
|
return -1;
|
|
34630
34657
|
}
|
|
34631
34658
|
let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator");
|
|
34632
|
-
if (tabulator) {
|
|
34633
|
-
|
|
34634
|
-
|
|
34659
|
+
if (tabulator) for (let record of data) {
|
|
34660
|
+
let row = tabulator.getRow(record.id);
|
|
34661
|
+
if (row) {
|
|
34662
|
+
let $row = row.getElement();
|
|
34663
|
+
if ($row && $row.querySelector(".tabulator-editing")) yui_tabulator_close_editor(tabulator, (0, _yuneta_gobj_js.gobj_short_name)(gobj));
|
|
34664
|
+
tabulator.updateData([record]).catch((e) => {
|
|
34665
|
+
(0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
34666
|
+
});
|
|
34667
|
+
} else if (tabulator.getDataCount() > 0) (0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: updated node is not in the loaded table: ${record.id}`);
|
|
34635
34668
|
}
|
|
34636
34669
|
return 0;
|
|
34637
34670
|
}
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -10364,12 +10364,15 @@ function form_time_cell_editor(real_type) {
|
|
|
10364
10364
|
* is alive, and opened again on the new cell of the same row
|
|
10365
10365
|
* and column after it (after the promise, for the calls that
|
|
10366
10366
|
* answer one). What was typed in the box is lost; the editor
|
|
10367
|
-
* stays open under the reader.
|
|
10368
|
-
*
|
|
10369
|
-
*
|
|
10367
|
+
* stays open under the reader. It is NOT opened again, and the
|
|
10368
|
+
* log says why, when: the cell is out of the page (a row the
|
|
10369
|
+
* virtual DOM does not render, or a filter hides), its column is
|
|
10370
|
+
* gone or has no editor any more, the call answered a REFUSAL
|
|
10371
|
+
* (it rebuilt nothing), or -- before a promise answers -- the
|
|
10372
|
+
* table was destroyed or another cell's editor was opened.
|
|
10370
10373
|
*
|
|
10371
10374
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
10372
|
-
* destroy)
|
|
10375
|
+
* destroy) cancels the edit first with
|
|
10373
10376
|
* `yui_tabulator_close_editor()`: there is no cell to open it
|
|
10374
10377
|
* on again.
|
|
10375
10378
|
*
|
|
@@ -10417,18 +10420,42 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10417
10420
|
tabulator.on("cellEditCancelled", function() {
|
|
10418
10421
|
editing = null;
|
|
10419
10422
|
});
|
|
10423
|
+
function stays_closed(field, why) {
|
|
10424
|
+
log_warning(`yui_tabulator_keep_edit_on_redraw: the edit of '${field}' stays closed: ${why}`);
|
|
10425
|
+
}
|
|
10426
|
+
function has_column(field) {
|
|
10427
|
+
return tabulator.getColumns().some((c) => c.getField() === field);
|
|
10428
|
+
}
|
|
10420
10429
|
function edit_again(row, field, name) {
|
|
10430
|
+
if (tabulator.destroyed) {
|
|
10431
|
+
stays_closed(field, `the table was destroyed after ${name}()`);
|
|
10432
|
+
return;
|
|
10433
|
+
}
|
|
10434
|
+
let $open = editing ? editing.getElement() : null;
|
|
10435
|
+
if ($open && $open.classList.contains("tabulator-editing")) {
|
|
10436
|
+
stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10437
|
+
return;
|
|
10438
|
+
}
|
|
10421
10439
|
let again = row.getCell(field);
|
|
10422
10440
|
if (!again) {
|
|
10423
|
-
|
|
10441
|
+
if (has_column(field)) stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10442
|
+
else stays_closed(field, `no column '${field}' after ${name}()`);
|
|
10424
10443
|
return;
|
|
10425
10444
|
}
|
|
10426
10445
|
let $again = again.getElement();
|
|
10427
10446
|
if (!$again || !$again.isConnected) {
|
|
10428
|
-
|
|
10447
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10448
|
+
return;
|
|
10449
|
+
}
|
|
10450
|
+
if (!again.getColumn().getDefinition().editor) {
|
|
10451
|
+
stays_closed(field, `the column has no editor after ${name}()`);
|
|
10429
10452
|
return;
|
|
10430
10453
|
}
|
|
10431
|
-
|
|
10454
|
+
try {
|
|
10455
|
+
again.edit(true);
|
|
10456
|
+
} catch (e) {
|
|
10457
|
+
stays_closed(field, `Tabulator refused to open it after ${name}(): ${e}`);
|
|
10458
|
+
}
|
|
10432
10459
|
}
|
|
10433
10460
|
function keep_edit_around(name, rebuilds) {
|
|
10434
10461
|
let original = tabulator[name].bind(tabulator);
|
|
@@ -10444,7 +10471,7 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10444
10471
|
edit_again(row, field, name);
|
|
10445
10472
|
return value;
|
|
10446
10473
|
}, (reason) => {
|
|
10447
|
-
|
|
10474
|
+
stays_closed(field, `${name}() was refused: ${reason}`);
|
|
10448
10475
|
throw reason;
|
|
10449
10476
|
});
|
|
10450
10477
|
edit_again(row, field, name);
|
|
@@ -34624,9 +34651,15 @@ function ac_load_node_updated(gobj, event, kw, src) {
|
|
|
34624
34651
|
return -1;
|
|
34625
34652
|
}
|
|
34626
34653
|
let tabulator = gobj_read_attr(gobj, "tabulator");
|
|
34627
|
-
if (tabulator) {
|
|
34628
|
-
|
|
34629
|
-
|
|
34654
|
+
if (tabulator) for (let record of data) {
|
|
34655
|
+
let row = tabulator.getRow(record.id);
|
|
34656
|
+
if (row) {
|
|
34657
|
+
let $row = row.getElement();
|
|
34658
|
+
if ($row && $row.querySelector(".tabulator-editing")) yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
|
|
34659
|
+
tabulator.updateData([record]).catch((e) => {
|
|
34660
|
+
log_error(`${gobj_short_name(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
34661
|
+
});
|
|
34662
|
+
} else if (tabulator.getDataCount() > 0) log_error(`${gobj_short_name(gobj)}: updated node is not in the loaded table: ${record.id}`);
|
|
34630
34663
|
}
|
|
34631
34664
|
return 0;
|
|
34632
34665
|
}
|
package/package.json
CHANGED
|
@@ -646,9 +646,14 @@ function import_locales(locales_dir, codes)
|
|
|
646
646
|
/***************************************************************
|
|
647
647
|
* The code of the locales' process (import_locales()), run there
|
|
648
648
|
* from its text: it can use nothing of this module but its
|
|
649
|
-
* argument and the nonce on its stdin. What it calls after
|
|
650
|
-
* locales ran is taken BEFORE them, so a locale that replaces
|
|
649
|
+
* argument and the nonce on its stdin. What it calls by name after
|
|
650
|
+
* the locales ran is taken BEFORE them, so a locale that replaces
|
|
651
651
|
* process.reallyExit or JSON.stringify does not reach the report,
|
|
652
|
+
* and the text is encoded by a TextEncoder taken then too, not by
|
|
653
|
+
* Buffer (which looks Buffer.prototype.utf8Write up when it runs).
|
|
654
|
+
* That covers what this code names, not every lookup Node makes
|
|
655
|
+
* inside it: a locale that sets out to forge the report can (the
|
|
656
|
+
* README says what is out of reach),
|
|
652
657
|
* and the report is written by hand from strings (JSON.stringify of
|
|
653
658
|
* a primitive string reads no toJSON): a toJSON a locale puts on
|
|
654
659
|
* Object.prototype or Array.prototype is never called. It reports after a
|
|
@@ -666,7 +671,8 @@ async function report_locales(request)
|
|
|
666
671
|
const keys_of = Object.keys;
|
|
667
672
|
const set_timeout = setTimeout;
|
|
668
673
|
const set_immediate = setImmediate;
|
|
669
|
-
const
|
|
674
|
+
const encoder = new TextEncoder();
|
|
675
|
+
const encode = encoder.encode.bind(encoder);
|
|
670
676
|
const define = Object.defineProperty;
|
|
671
677
|
const has_own = Object.hasOwn;
|
|
672
678
|
const to_string = String;
|
|
@@ -728,7 +734,7 @@ async function report_locales(request)
|
|
|
728
734
|
`{"keys":${list_text(one.keys)},"name":${one.name === null? "null" : stringify(one.name)}}`
|
|
729
735
|
);
|
|
730
736
|
}
|
|
731
|
-
const buf =
|
|
737
|
+
const buf = encode(text + "}}\n");
|
|
732
738
|
let done = 0;
|
|
733
739
|
while(done < buf.length) {
|
|
734
740
|
done += writeSync(3, buf, done, buf.length - done);
|
|
@@ -3925,8 +3925,18 @@ function ac_load_node_updated(gobj, event, kw, src)
|
|
|
3925
3925
|
* it is not news: its rows are read when the topic is shown. A
|
|
3926
3926
|
* row missing from a table that IS loaded is.
|
|
3927
3927
|
*/
|
|
3928
|
-
|
|
3929
|
-
|
|
3928
|
+
let row = tabulator.getRow(record.id);
|
|
3929
|
+
if(row) {
|
|
3930
|
+
/* The echo of the reader's own write lands while the
|
|
3931
|
+
* next cell's editor is open: Tabulator 6.6.0 throws
|
|
3932
|
+
* updating a row with an open editor, and paints half of it. */
|
|
3933
|
+
let $row = row.getElement();
|
|
3934
|
+
if($row && $row.querySelector(".tabulator-editing")) {
|
|
3935
|
+
yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
|
|
3936
|
+
}
|
|
3937
|
+
tabulator.updateData([record]).catch((e) => {
|
|
3938
|
+
log_error(`${gobj_short_name(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
3939
|
+
});
|
|
3930
3940
|
} else if(tabulator.getDataCount() > 0) {
|
|
3931
3941
|
log_error(`${gobj_short_name(gobj)}: updated node is not in ` +
|
|
3932
3942
|
`the loaded table: ${record.id}`);
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
***********************************************************************/
|
|
14
14
|
import {describe, test, expect} from "vitest";
|
|
15
15
|
import {set_log_callback} from "@yuneta/gobj-js";
|
|
16
|
-
import {fmt_date_time, safe_locale} from "./
|
|
16
|
+
import {fmt_date_time, safe_locale} from "./yui_date_text.js";
|
|
17
17
|
import {time_value_to_text} from "./form_time_value.js";
|
|
18
18
|
import {format_epoch} from "./json_view_helpers.js";
|
|
19
19
|
import {yui_uplot_fmt_date} from "./yui_uplot_time.js";
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* treedb_topic_editor_guard.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* C_YUI_TREEDB_TOPIC_WITH_FORM cancels an open cell editor before
|
|
5
|
+
* each call of its table that would throw under it in Tabulator
|
|
6
|
+
* 6.6.0: setData (EV_LOAD_NODES), replaceData (EV_REPULL_PAGE),
|
|
7
|
+
* destroy (mt_stop), and updateData (EV_LOAD_NODE_UPDATED) of the
|
|
8
|
+
* row being edited -- the backend echo of a write the reader just
|
|
9
|
+
* made, which arrives while the next cell's editor is open. A
|
|
10
|
+
* refused updateData is logged, not left unhandled. The table is a
|
|
11
|
+
* double that records the order of the calls; that the real
|
|
12
|
+
* Tabulator throws without this is proved in a browser by
|
|
13
|
+
* scripts/qa-cell-editor.mjs.
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2026, ArtGins.
|
|
16
|
+
* All Rights Reserved.
|
|
17
|
+
***********************************************************************/
|
|
18
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
19
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
20
|
+
|
|
21
|
+
install_dom_double();
|
|
22
|
+
|
|
23
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
24
|
+
globalThis.ResizeObserver = class {
|
|
25
|
+
observe() {
|
|
26
|
+
}
|
|
27
|
+
unobserve() {
|
|
28
|
+
}
|
|
29
|
+
disconnect() {
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const state = vi.hoisted(() => ({tables: [], calls: [], edited_row: null, refuse: false}));
|
|
35
|
+
vi.mock("tabulator-tables", () => {
|
|
36
|
+
class FakeTabulator {
|
|
37
|
+
constructor($el, settings) {
|
|
38
|
+
this.element = $el;
|
|
39
|
+
this.options = settings;
|
|
40
|
+
this.modules = {edit: {
|
|
41
|
+
get currentCell() {
|
|
42
|
+
return state.edited_row? {row: state.edited_row} : false;
|
|
43
|
+
},
|
|
44
|
+
cancelEdit() {
|
|
45
|
+
state.calls.push(`cancel ${state.edited_row}`);
|
|
46
|
+
state.edited_row = null;
|
|
47
|
+
},
|
|
48
|
+
}};
|
|
49
|
+
state.tables.push(this);
|
|
50
|
+
return new Proxy(this, {
|
|
51
|
+
get(target, prop) {
|
|
52
|
+
if(prop in target) {
|
|
53
|
+
return target[prop];
|
|
54
|
+
}
|
|
55
|
+
return () => [];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
on() {
|
|
60
|
+
}
|
|
61
|
+
off() {
|
|
62
|
+
}
|
|
63
|
+
getRow(id) {
|
|
64
|
+
return {getElement: () => ({
|
|
65
|
+
querySelector: (s) => (s === ".tabulator-editing" && state.edited_row === id)? {} : null,
|
|
66
|
+
})};
|
|
67
|
+
}
|
|
68
|
+
getDataCount() {
|
|
69
|
+
return 2;
|
|
70
|
+
}
|
|
71
|
+
setData() {
|
|
72
|
+
state.calls.push(`setData edited=${state.edited_row}`);
|
|
73
|
+
}
|
|
74
|
+
replaceData() {
|
|
75
|
+
state.calls.push(`replaceData edited=${state.edited_row}`);
|
|
76
|
+
}
|
|
77
|
+
updateData(records) {
|
|
78
|
+
state.calls.push(`updateData ${records[0].id} edited=${state.edited_row}`);
|
|
79
|
+
return state.refuse? Promise.reject("Update Error - Unable to update row") : Promise.resolve();
|
|
80
|
+
}
|
|
81
|
+
destroy() {
|
|
82
|
+
state.calls.push(`destroy edited=${state.edited_row}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const {
|
|
89
|
+
SDATA_END, gclass_create, set_log_callback, gobj_send_event, gobj_stop,
|
|
90
|
+
gobj_start_up, gobj_create_yuno, gobj_create_service, gobj_start,
|
|
91
|
+
} = await import("@yuneta/gobj-js");
|
|
92
|
+
const {register_c_yui_treedb_topic_with_form} = await import("./c_yui_treedb_topic_with_form.js");
|
|
93
|
+
|
|
94
|
+
const logged = [];
|
|
95
|
+
let yuno = null;
|
|
96
|
+
let n = 0;
|
|
97
|
+
|
|
98
|
+
beforeAll(async () => {
|
|
99
|
+
const i18next = (await import("i18next")).default;
|
|
100
|
+
await i18next.init({lng: "en", resources: {}});
|
|
101
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
102
|
+
set_log_callback((level, msg) => {
|
|
103
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
104
|
+
});
|
|
105
|
+
gclass_create("C_TEST_EDITOR_GUARD_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
106
|
+
register_c_yui_treedb_topic_with_form();
|
|
107
|
+
yuno = gobj_create_yuno("editor_guard_yuno", "C_TEST_EDITOR_GUARD_HOST", {});
|
|
108
|
+
gobj_start(yuno);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
beforeEach(() => {
|
|
112
|
+
state.calls.length = 0;
|
|
113
|
+
state.edited_row = null;
|
|
114
|
+
state.refuse = false;
|
|
115
|
+
logged.length = 0;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
function make_view()
|
|
119
|
+
{
|
|
120
|
+
const view = gobj_create_service(`editor_guard_view_${++n}`, "C_YUI_TREEDB_TOPIC_WITH_FORM", {
|
|
121
|
+
treedb_name: "treedb_test",
|
|
122
|
+
topic_name: "people",
|
|
123
|
+
desc: {id: "people", pkey: "id", cols: [
|
|
124
|
+
{id: "id", header: "Id", type: "string", flag: ["persistent", "required"]},
|
|
125
|
+
{id: "name", header: "name", type: "string", flag: ["persistent", "writable"]},
|
|
126
|
+
]}
|
|
127
|
+
}, yuno);
|
|
128
|
+
gobj_start(view);
|
|
129
|
+
state.tables[state.tables.length - 1]._ready = true;
|
|
130
|
+
return view;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
describe("an open cell editor of a treedb topic's table", () => {
|
|
134
|
+
test("is cancelled before setData (EV_LOAD_NODES)", () => {
|
|
135
|
+
const view = make_view();
|
|
136
|
+
state.edited_row = "b";
|
|
137
|
+
gobj_send_event(view, "EV_LOAD_NODES", [{id: "x"}], view);
|
|
138
|
+
expect(state.calls).toEqual(["cancel b", "setData edited=null"]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("is cancelled before replaceData (EV_REPULL_PAGE)", () => {
|
|
142
|
+
const view = make_view();
|
|
143
|
+
state.edited_row = "b";
|
|
144
|
+
gobj_send_event(view, "EV_REPULL_PAGE", {}, view);
|
|
145
|
+
expect(state.calls).toEqual(["cancel b", "replaceData edited=null"]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("is cancelled before the table is destroyed (stop)", () => {
|
|
149
|
+
const view = make_view();
|
|
150
|
+
state.edited_row = "b";
|
|
151
|
+
gobj_stop(view);
|
|
152
|
+
expect(state.calls).toEqual(["cancel b", "destroy edited=null"]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("is cancelled before updateData of ITS row, left alone for another row", () => {
|
|
156
|
+
const view = make_view();
|
|
157
|
+
state.edited_row = "b";
|
|
158
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "a", name: "A"}], view);
|
|
159
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "b", name: "B"}], view);
|
|
160
|
+
expect(state.calls).toEqual([
|
|
161
|
+
"updateData a edited=b",
|
|
162
|
+
"cancel b", "updateData b edited=null",
|
|
163
|
+
]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("a refused updateData is logged as an error, not left unhandled", async () => {
|
|
167
|
+
const view = make_view();
|
|
168
|
+
state.refuse = true;
|
|
169
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "a", name: "A"}], view);
|
|
170
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
171
|
+
expect(logged.filter((l) => /cannot update row 'a'.*Unable to update row/.test(l.msg)).length).toBe(1);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -27,12 +27,15 @@
|
|
|
27
27
|
* is alive, and opened again on the new cell of the same row
|
|
28
28
|
* and column after it (after the promise, for the calls that
|
|
29
29
|
* answer one). What was typed in the box is lost; the editor
|
|
30
|
-
* stays open under the reader.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* stays open under the reader. It is NOT opened again, and the
|
|
31
|
+
* log says why, when: the cell is out of the page (a row the
|
|
32
|
+
* virtual DOM does not render, or a filter hides), its column is
|
|
33
|
+
* gone or has no editor any more, the call answered a REFUSAL
|
|
34
|
+
* (it rebuilt nothing), or -- before a promise answers -- the
|
|
35
|
+
* table was destroyed or another cell's editor was opened.
|
|
33
36
|
*
|
|
34
37
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
35
|
-
* destroy)
|
|
38
|
+
* destroy) cancels the edit first with
|
|
36
39
|
* `yui_tabulator_close_editor()`: there is no cell to open it
|
|
37
40
|
* on again.
|
|
38
41
|
*
|
|
@@ -89,21 +92,52 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
89
92
|
editing = null;
|
|
90
93
|
});
|
|
91
94
|
|
|
95
|
+
function stays_closed(field, why)
|
|
96
|
+
{
|
|
97
|
+
log_warning(`yui_tabulator_keep_edit_on_redraw: the edit of '${field}' stays closed: ${why}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function has_column(field)
|
|
101
|
+
{
|
|
102
|
+
return tabulator.getColumns().some((c) => c.getField() === field);
|
|
103
|
+
}
|
|
104
|
+
|
|
92
105
|
function edit_again(row, field, name)
|
|
93
106
|
{
|
|
107
|
+
if(tabulator.destroyed) {
|
|
108
|
+
stays_closed(field, `the table was destroyed after ${name}()`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
let $open = editing? editing.getElement() : null;
|
|
112
|
+
if($open && $open.classList.contains("tabulator-editing")) {
|
|
113
|
+
stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
/* A row the page does not draw keeps the cells of the old
|
|
117
|
+
* columns, so it answers no cell for a column that does exist. */
|
|
94
118
|
let again = row.getCell(field);
|
|
95
119
|
if(!again) {
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
if(has_column(field)) {
|
|
121
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
122
|
+
} else {
|
|
123
|
+
stays_closed(field, `no column '${field}' after ${name}()`);
|
|
124
|
+
}
|
|
98
125
|
return;
|
|
99
126
|
}
|
|
100
127
|
let $again = again.getElement();
|
|
101
128
|
if(!$again || !$again.isConnected) {
|
|
102
|
-
|
|
103
|
-
`its row is not in the page after ${name}()`);
|
|
129
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
104
130
|
return;
|
|
105
131
|
}
|
|
106
|
-
again.
|
|
132
|
+
if(!again.getColumn().getDefinition().editor) {
|
|
133
|
+
stays_closed(field, `the column has no editor after ${name}()`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
again.edit(true);
|
|
138
|
+
} catch(e) {
|
|
139
|
+
stays_closed(field, `Tabulator refused to open it after ${name}(): ${e}`);
|
|
140
|
+
}
|
|
107
141
|
}
|
|
108
142
|
|
|
109
143
|
function keep_edit_around(name, rebuilds)
|
|
@@ -128,7 +162,9 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
128
162
|
return value;
|
|
129
163
|
},
|
|
130
164
|
(reason) => {
|
|
131
|
-
|
|
165
|
+
/* The edit had to be ended before asking; a refused
|
|
166
|
+
* call rebuilt nothing, so nothing is opened again. */
|
|
167
|
+
stays_closed(field, `${name}() was refused: ${reason}`);
|
|
132
168
|
throw reason;
|
|
133
169
|
}
|
|
134
170
|
);
|
|
@@ -19,6 +19,8 @@ import {yui_tabulator_keep_edit_on_redraw} from "./yui_tabulator_edit.js";
|
|
|
19
19
|
|
|
20
20
|
let calls = [];
|
|
21
21
|
let connected = true;
|
|
22
|
+
let drawn = true; /* an undrawn row answers no cell */
|
|
23
|
+
let editors = {}; /* field -> its definition's editor; absent: no column */
|
|
22
24
|
|
|
23
25
|
function make_cell(row, field, editing)
|
|
24
26
|
{
|
|
@@ -38,8 +40,14 @@ function make_cell(row, field, editing)
|
|
|
38
40
|
calls.push(`cancel ${field}`);
|
|
39
41
|
cell.classes.delete("tabulator-editing");
|
|
40
42
|
},
|
|
43
|
+
getColumn() {
|
|
44
|
+
return {getDefinition: () => ({editor: editors[field]})};
|
|
45
|
+
},
|
|
41
46
|
edit(force) {
|
|
42
47
|
calls.push(`edit ${field} ${force}`);
|
|
48
|
+
if(!editors[field]) {
|
|
49
|
+
throw new TypeError("Cannot read properties of undefined (reading 'blocked')");
|
|
50
|
+
}
|
|
43
51
|
},
|
|
44
52
|
};
|
|
45
53
|
return cell;
|
|
@@ -51,11 +59,14 @@ function make_table()
|
|
|
51
59
|
const row = {
|
|
52
60
|
getCell(field) {
|
|
53
61
|
calls.push(`getCell ${field}`);
|
|
54
|
-
return field
|
|
62
|
+
return (field in editors && drawn)? make_cell(row, field, false) : false;
|
|
55
63
|
},
|
|
56
64
|
};
|
|
57
65
|
const table = {
|
|
58
66
|
row,
|
|
67
|
+
getColumns() {
|
|
68
|
+
return Object.keys(editors).map((f) => ({getField: () => f}));
|
|
69
|
+
},
|
|
59
70
|
on(name, fn) {
|
|
60
71
|
handlers[name] = fn;
|
|
61
72
|
},
|
|
@@ -89,6 +100,8 @@ function make_table()
|
|
|
89
100
|
beforeEach(() => {
|
|
90
101
|
calls = [];
|
|
91
102
|
connected = true;
|
|
103
|
+
drawn = true;
|
|
104
|
+
editors = {when: "input", note: "input"};
|
|
92
105
|
});
|
|
93
106
|
|
|
94
107
|
describe("an open edit around a call that builds the cells again", () => {
|
|
@@ -143,7 +156,9 @@ describe("what it leaves alone", () => {
|
|
|
143
156
|
|
|
144
157
|
test("a column the new columns do not have: the edit stays closed", () => {
|
|
145
158
|
const table = make_table();
|
|
159
|
+
editors.gone = "input";
|
|
146
160
|
table.emit("cellEditing", make_cell(table.row, "gone", true));
|
|
161
|
+
delete editors.gone;
|
|
147
162
|
expect(table.setColumns(["other"])).toBe("setColumns done");
|
|
148
163
|
expect(calls).toEqual(["cancel gone", "setColumns(other)", "getCell gone"]);
|
|
149
164
|
});
|
|
@@ -164,11 +179,56 @@ describe("a call that answers a promise", () => {
|
|
|
164
179
|
});
|
|
165
180
|
}
|
|
166
181
|
|
|
167
|
-
test("a refusal
|
|
182
|
+
test("a refusal rebuilt nothing: not opened again, said, and passed on", async () => {
|
|
183
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
168
184
|
const table = make_table();
|
|
169
185
|
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
170
186
|
await expect(table.updateColumnDefinition("reject")).rejects.toThrow("refused");
|
|
171
|
-
expect(calls
|
|
187
|
+
expect(calls).toEqual(["cancel when", "updateColumnDefinition(reject)",
|
|
188
|
+
"updateColumnDefinition resolved"]);
|
|
189
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: updateColumnDefinition\(\) was refused/);
|
|
190
|
+
warn.mockRestore();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("another edit opened before the answer keeps the edit", async () => {
|
|
194
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
195
|
+
const table = make_table();
|
|
196
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
197
|
+
const ret = table.addColumn("x");
|
|
198
|
+
table.emit("cellEditing", make_cell(table.row, "note", true));
|
|
199
|
+
await ret;
|
|
200
|
+
expect(calls).toEqual(["cancel when", "addColumn(x)", "addColumn resolved"]);
|
|
201
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: another cell \('note'\) was opened after addColumn\(\)/);
|
|
202
|
+
warn.mockRestore();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("a table destroyed before the answer: not opened, and said so", async () => {
|
|
206
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
207
|
+
const table = make_table();
|
|
208
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
209
|
+
const ret = table.updateColumnDefinition("when");
|
|
210
|
+
table.destroyed = true;
|
|
211
|
+
await ret;
|
|
212
|
+
expect(calls).toEqual(["cancel when", "updateColumnDefinition(when)",
|
|
213
|
+
"updateColumnDefinition resolved"]);
|
|
214
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: the table was destroyed after updateColumnDefinition\(\)/);
|
|
215
|
+
warn.mockRestore();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("a column the call left with no editor", () => {
|
|
220
|
+
test("not opened (no throw), and the log says why", async () => {
|
|
221
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
222
|
+
const table = make_table();
|
|
223
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
224
|
+
editors.when = false;
|
|
225
|
+
expect(table.setColumns(["defs"])).toBe("setColumns done");
|
|
226
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
227
|
+
expect(await table.updateColumnDefinition("when")).toBe("updateColumnDefinition done");
|
|
228
|
+
expect(calls.filter((c) => c.startsWith("edit"))).toEqual([]);
|
|
229
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: the column has no editor after setColumns\(\)/);
|
|
230
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/after updateColumnDefinition\(\)/);
|
|
231
|
+
warn.mockRestore();
|
|
172
232
|
});
|
|
173
233
|
});
|
|
174
234
|
|
|
@@ -183,4 +243,15 @@ describe("a cell the call left out of the page", () => {
|
|
|
183
243
|
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: its row is not in the page after setHeight\(\)/);
|
|
184
244
|
warn.mockRestore();
|
|
185
245
|
});
|
|
246
|
+
|
|
247
|
+
test("an undrawn row answers no cell: said as out of the page, not as no column", () => {
|
|
248
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
249
|
+
const table = make_table();
|
|
250
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
251
|
+
drawn = false;
|
|
252
|
+
expect(table.setColumns(["defs"])).toBe("setColumns done");
|
|
253
|
+
expect(calls).toEqual(["cancel when", "setColumns(defs)", "getCell when"]);
|
|
254
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: its row is not in the page after setColumns\(\)/);
|
|
255
|
+
warn.mockRestore();
|
|
256
|
+
});
|
|
186
257
|
});
|