@yuneta/gobj-ui 7.26.57 → 7.26.59
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 +57 -12
- package/dist/gobj-ui.es.js +57 -12
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +10 -4
- package/src/c_yui_treedb_topic_with_form.js +20 -2
- package/src/fmt_date_time.test.js +1 -1
- package/src/treedb_topic_editor_guard.wiring.test.js +186 -0
- package/src/yui_tabulator_edit.js +56 -11
- package/src/yui_tabulator_edit.test.js +112 -3
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -10369,12 +10369,16 @@ 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 threw, or -- before a promise answers
|
|
10377
|
+
* -- the table was destroyed or another cell's editor was opened
|
|
10378
|
+
* (the same cell opened again by the code is left as it is).
|
|
10375
10379
|
*
|
|
10376
10380
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
10377
|
-
* destroy)
|
|
10381
|
+
* destroy) cancels the edit first with
|
|
10378
10382
|
* `yui_tabulator_close_editor()`: there is no cell to open it
|
|
10379
10383
|
* on again.
|
|
10380
10384
|
*
|
|
@@ -10422,18 +10426,42 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10422
10426
|
tabulator.on("cellEditCancelled", function() {
|
|
10423
10427
|
editing = null;
|
|
10424
10428
|
});
|
|
10429
|
+
function stays_closed(field, why) {
|
|
10430
|
+
(0, _yuneta_gobj_js.log_warning)(`yui_tabulator_keep_edit_on_redraw: the edit of '${field}' stays closed: ${why}`);
|
|
10431
|
+
}
|
|
10432
|
+
function has_column(field) {
|
|
10433
|
+
return tabulator.getColumns().some((c) => c.getField() === field);
|
|
10434
|
+
}
|
|
10425
10435
|
function edit_again(row, field, name) {
|
|
10436
|
+
if (tabulator.destroyed) {
|
|
10437
|
+
stays_closed(field, `the table was destroyed after ${name}()`);
|
|
10438
|
+
return;
|
|
10439
|
+
}
|
|
10440
|
+
let $open = editing ? editing.getElement() : null;
|
|
10441
|
+
if ($open && $open.classList.contains("tabulator-editing")) {
|
|
10442
|
+
if (editing.getRow() !== row || editing.getField() !== field) stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10443
|
+
return;
|
|
10444
|
+
}
|
|
10426
10445
|
let again = row.getCell(field);
|
|
10427
10446
|
if (!again) {
|
|
10428
|
-
(
|
|
10447
|
+
if (has_column(field)) stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10448
|
+
else stays_closed(field, `no column '${field}' after ${name}()`);
|
|
10429
10449
|
return;
|
|
10430
10450
|
}
|
|
10431
10451
|
let $again = again.getElement();
|
|
10432
10452
|
if (!$again || !$again.isConnected) {
|
|
10433
|
-
(
|
|
10453
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10454
|
+
return;
|
|
10455
|
+
}
|
|
10456
|
+
if (!again.getColumn().getDefinition().editor) {
|
|
10457
|
+
stays_closed(field, `the column has no editor after ${name}()`);
|
|
10434
10458
|
return;
|
|
10435
10459
|
}
|
|
10436
|
-
|
|
10460
|
+
try {
|
|
10461
|
+
again.edit(true);
|
|
10462
|
+
} catch (e) {
|
|
10463
|
+
stays_closed(field, `Tabulator refused to open it after ${name}(): ${e}`);
|
|
10464
|
+
}
|
|
10437
10465
|
}
|
|
10438
10466
|
function keep_edit_around(name, rebuilds) {
|
|
10439
10467
|
let original = tabulator[name].bind(tabulator);
|
|
@@ -10444,12 +10472,18 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10444
10472
|
let row = cell.getRow();
|
|
10445
10473
|
let field = cell.getField();
|
|
10446
10474
|
cell.cancelEdit();
|
|
10447
|
-
let ret
|
|
10475
|
+
let ret;
|
|
10476
|
+
try {
|
|
10477
|
+
ret = original(...args);
|
|
10478
|
+
} catch (e) {
|
|
10479
|
+
stays_closed(field, `${name}() threw: ${e}`);
|
|
10480
|
+
throw e;
|
|
10481
|
+
}
|
|
10448
10482
|
if (ret && typeof ret.then === "function") return ret.then((value) => {
|
|
10449
10483
|
edit_again(row, field, name);
|
|
10450
10484
|
return value;
|
|
10451
10485
|
}, (reason) => {
|
|
10452
|
-
|
|
10486
|
+
stays_closed(field, `${name}() was refused: ${reason}`);
|
|
10453
10487
|
throw reason;
|
|
10454
10488
|
});
|
|
10455
10489
|
edit_again(row, field, name);
|
|
@@ -34629,9 +34663,20 @@ function ac_load_node_updated(gobj, event, kw, src) {
|
|
|
34629
34663
|
return -1;
|
|
34630
34664
|
}
|
|
34631
34665
|
let tabulator = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "tabulator");
|
|
34632
|
-
if (tabulator) {
|
|
34633
|
-
|
|
34634
|
-
|
|
34666
|
+
if (tabulator) for (let record of data) {
|
|
34667
|
+
let row = tabulator.getRow(record.id);
|
|
34668
|
+
if (row) {
|
|
34669
|
+
let $row = row.getElement();
|
|
34670
|
+
let $ed = $row ? $row.querySelector(".tabulator-editing") : null;
|
|
34671
|
+
let ed_field = $ed ? $ed.getAttribute("tabulator-field") : null;
|
|
34672
|
+
if (ed_field && Object.hasOwn(record, ed_field) && record[ed_field] !== row.getData()[ed_field]) {
|
|
34673
|
+
(0, _yuneta_gobj_js.log_warning)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: row '${record.id}' changed '${ed_field}' under its open editor: the edit is cancelled`);
|
|
34674
|
+
yui_tabulator_close_editor(tabulator, (0, _yuneta_gobj_js.gobj_short_name)(gobj));
|
|
34675
|
+
}
|
|
34676
|
+
tabulator.updateData([record]).catch((e) => {
|
|
34677
|
+
(0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
34678
|
+
});
|
|
34679
|
+
} 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
34680
|
}
|
|
34636
34681
|
return 0;
|
|
34637
34682
|
}
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -10364,12 +10364,16 @@ 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 threw, or -- before a promise answers
|
|
10372
|
+
* -- the table was destroyed or another cell's editor was opened
|
|
10373
|
+
* (the same cell opened again by the code is left as it is).
|
|
10370
10374
|
*
|
|
10371
10375
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
10372
|
-
* destroy)
|
|
10376
|
+
* destroy) cancels the edit first with
|
|
10373
10377
|
* `yui_tabulator_close_editor()`: there is no cell to open it
|
|
10374
10378
|
* on again.
|
|
10375
10379
|
*
|
|
@@ -10417,18 +10421,42 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10417
10421
|
tabulator.on("cellEditCancelled", function() {
|
|
10418
10422
|
editing = null;
|
|
10419
10423
|
});
|
|
10424
|
+
function stays_closed(field, why) {
|
|
10425
|
+
log_warning(`yui_tabulator_keep_edit_on_redraw: the edit of '${field}' stays closed: ${why}`);
|
|
10426
|
+
}
|
|
10427
|
+
function has_column(field) {
|
|
10428
|
+
return tabulator.getColumns().some((c) => c.getField() === field);
|
|
10429
|
+
}
|
|
10420
10430
|
function edit_again(row, field, name) {
|
|
10431
|
+
if (tabulator.destroyed) {
|
|
10432
|
+
stays_closed(field, `the table was destroyed after ${name}()`);
|
|
10433
|
+
return;
|
|
10434
|
+
}
|
|
10435
|
+
let $open = editing ? editing.getElement() : null;
|
|
10436
|
+
if ($open && $open.classList.contains("tabulator-editing")) {
|
|
10437
|
+
if (editing.getRow() !== row || editing.getField() !== field) stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10438
|
+
return;
|
|
10439
|
+
}
|
|
10421
10440
|
let again = row.getCell(field);
|
|
10422
10441
|
if (!again) {
|
|
10423
|
-
|
|
10442
|
+
if (has_column(field)) stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10443
|
+
else stays_closed(field, `no column '${field}' after ${name}()`);
|
|
10424
10444
|
return;
|
|
10425
10445
|
}
|
|
10426
10446
|
let $again = again.getElement();
|
|
10427
10447
|
if (!$again || !$again.isConnected) {
|
|
10428
|
-
|
|
10448
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
10449
|
+
return;
|
|
10450
|
+
}
|
|
10451
|
+
if (!again.getColumn().getDefinition().editor) {
|
|
10452
|
+
stays_closed(field, `the column has no editor after ${name}()`);
|
|
10429
10453
|
return;
|
|
10430
10454
|
}
|
|
10431
|
-
|
|
10455
|
+
try {
|
|
10456
|
+
again.edit(true);
|
|
10457
|
+
} catch (e) {
|
|
10458
|
+
stays_closed(field, `Tabulator refused to open it after ${name}(): ${e}`);
|
|
10459
|
+
}
|
|
10432
10460
|
}
|
|
10433
10461
|
function keep_edit_around(name, rebuilds) {
|
|
10434
10462
|
let original = tabulator[name].bind(tabulator);
|
|
@@ -10439,12 +10467,18 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10439
10467
|
let row = cell.getRow();
|
|
10440
10468
|
let field = cell.getField();
|
|
10441
10469
|
cell.cancelEdit();
|
|
10442
|
-
let ret
|
|
10470
|
+
let ret;
|
|
10471
|
+
try {
|
|
10472
|
+
ret = original(...args);
|
|
10473
|
+
} catch (e) {
|
|
10474
|
+
stays_closed(field, `${name}() threw: ${e}`);
|
|
10475
|
+
throw e;
|
|
10476
|
+
}
|
|
10443
10477
|
if (ret && typeof ret.then === "function") return ret.then((value) => {
|
|
10444
10478
|
edit_again(row, field, name);
|
|
10445
10479
|
return value;
|
|
10446
10480
|
}, (reason) => {
|
|
10447
|
-
|
|
10481
|
+
stays_closed(field, `${name}() was refused: ${reason}`);
|
|
10448
10482
|
throw reason;
|
|
10449
10483
|
});
|
|
10450
10484
|
edit_again(row, field, name);
|
|
@@ -34624,9 +34658,20 @@ function ac_load_node_updated(gobj, event, kw, src) {
|
|
|
34624
34658
|
return -1;
|
|
34625
34659
|
}
|
|
34626
34660
|
let tabulator = gobj_read_attr(gobj, "tabulator");
|
|
34627
|
-
if (tabulator) {
|
|
34628
|
-
|
|
34629
|
-
|
|
34661
|
+
if (tabulator) for (let record of data) {
|
|
34662
|
+
let row = tabulator.getRow(record.id);
|
|
34663
|
+
if (row) {
|
|
34664
|
+
let $row = row.getElement();
|
|
34665
|
+
let $ed = $row ? $row.querySelector(".tabulator-editing") : null;
|
|
34666
|
+
let ed_field = $ed ? $ed.getAttribute("tabulator-field") : null;
|
|
34667
|
+
if (ed_field && Object.hasOwn(record, ed_field) && record[ed_field] !== row.getData()[ed_field]) {
|
|
34668
|
+
log_warning(`${gobj_short_name(gobj)}: row '${record.id}' changed '${ed_field}' under its open editor: the edit is cancelled`);
|
|
34669
|
+
yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
|
|
34670
|
+
}
|
|
34671
|
+
tabulator.updateData([record]).catch((e) => {
|
|
34672
|
+
log_error(`${gobj_short_name(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
34673
|
+
});
|
|
34674
|
+
} else if (tabulator.getDataCount() > 0) log_error(`${gobj_short_name(gobj)}: updated node is not in the loaded table: ${record.id}`);
|
|
34630
34675
|
}
|
|
34631
34676
|
return 0;
|
|
34632
34677
|
}
|
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,26 @@ 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
|
+
/* Tabulator 6.6.0 redraws only the cells whose value changes
|
|
3931
|
+
* (strict !==, as below), and throws, painting half the row,
|
|
3932
|
+
* when one of them is the cell in edition. So the editor is
|
|
3933
|
+
* cancelled only then: the echo of the reader's own write of
|
|
3934
|
+
* the previous cell, arriving while Tab has opened the next
|
|
3935
|
+
* one, leaves it open and what is being typed in it. */
|
|
3936
|
+
let $row = row.getElement();
|
|
3937
|
+
let $ed = $row? $row.querySelector(".tabulator-editing") : null;
|
|
3938
|
+
let ed_field = $ed? $ed.getAttribute("tabulator-field") : null;
|
|
3939
|
+
if(ed_field && Object.hasOwn(record, ed_field) &&
|
|
3940
|
+
record[ed_field] !== row.getData()[ed_field]) {
|
|
3941
|
+
log_warning(`${gobj_short_name(gobj)}: row '${record.id}' changed ` +
|
|
3942
|
+
`'${ed_field}' under its open editor: the edit is cancelled`);
|
|
3943
|
+
yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
|
|
3944
|
+
}
|
|
3945
|
+
tabulator.updateData([record]).catch((e) => {
|
|
3946
|
+
log_error(`${gobj_short_name(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
3947
|
+
});
|
|
3930
3948
|
} else if(tabulator.getDataCount() > 0) {
|
|
3931
3949
|
log_error(`${gobj_short_name(gobj)}: updated node is not in ` +
|
|
3932
3950
|
`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,186 @@
|
|
|
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) that
|
|
8
|
+
* changes the cell being edited -- not the backend echo of the
|
|
9
|
+
* write the reader just made of the previous cell, which arrives
|
|
10
|
+
* while the next cell's editor is open and must leave it. A
|
|
11
|
+
* refused updateData is logged, not left unhandled. The table is a
|
|
12
|
+
* double that records the order of the calls; that the real
|
|
13
|
+
* Tabulator throws without this is proved in a browser by
|
|
14
|
+
* scripts/qa-cell-editor.mjs.
|
|
15
|
+
*
|
|
16
|
+
* Copyright (c) 2026, ArtGins.
|
|
17
|
+
* All Rights Reserved.
|
|
18
|
+
***********************************************************************/
|
|
19
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
20
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
21
|
+
|
|
22
|
+
install_dom_double();
|
|
23
|
+
|
|
24
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
25
|
+
globalThis.ResizeObserver = class {
|
|
26
|
+
observe() {
|
|
27
|
+
}
|
|
28
|
+
unobserve() {
|
|
29
|
+
}
|
|
30
|
+
disconnect() {
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const state = vi.hoisted(() => ({tables: [], calls: [], edited_row: null, edited_field: "age", refuse: false}));
|
|
36
|
+
vi.mock("tabulator-tables", () => {
|
|
37
|
+
class FakeTabulator {
|
|
38
|
+
constructor($el, settings) {
|
|
39
|
+
this.element = $el;
|
|
40
|
+
this.options = settings;
|
|
41
|
+
this.modules = {edit: {
|
|
42
|
+
get currentCell() {
|
|
43
|
+
return state.edited_row? {row: state.edited_row} : false;
|
|
44
|
+
},
|
|
45
|
+
cancelEdit() {
|
|
46
|
+
state.calls.push(`cancel ${state.edited_row}`);
|
|
47
|
+
state.edited_row = null;
|
|
48
|
+
},
|
|
49
|
+
}};
|
|
50
|
+
state.tables.push(this);
|
|
51
|
+
return new Proxy(this, {
|
|
52
|
+
get(target, prop) {
|
|
53
|
+
if(prop in target) {
|
|
54
|
+
return target[prop];
|
|
55
|
+
}
|
|
56
|
+
return () => [];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
on() {
|
|
61
|
+
}
|
|
62
|
+
off() {
|
|
63
|
+
}
|
|
64
|
+
getRow(id) {
|
|
65
|
+
return {
|
|
66
|
+
getElement: () => ({
|
|
67
|
+
querySelector: (s) => (s === ".tabulator-editing" && state.edited_row === id)?
|
|
68
|
+
{getAttribute: (a) => (a === "tabulator-field")? state.edited_field : null} : null,
|
|
69
|
+
}),
|
|
70
|
+
getData: () => ({id, name: `${id}0`, age: 41}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
getDataCount() {
|
|
74
|
+
return 2;
|
|
75
|
+
}
|
|
76
|
+
setData() {
|
|
77
|
+
state.calls.push(`setData edited=${state.edited_row}`);
|
|
78
|
+
}
|
|
79
|
+
replaceData() {
|
|
80
|
+
state.calls.push(`replaceData edited=${state.edited_row}`);
|
|
81
|
+
}
|
|
82
|
+
updateData(records) {
|
|
83
|
+
state.calls.push(`updateData ${records[0].id} edited=${state.edited_row}`);
|
|
84
|
+
return state.refuse? Promise.reject("Update Error - Unable to update row") : Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
state.calls.push(`destroy edited=${state.edited_row}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const {
|
|
94
|
+
SDATA_END, gclass_create, set_log_callback, gobj_send_event, gobj_stop,
|
|
95
|
+
gobj_start_up, gobj_create_yuno, gobj_create_service, gobj_start,
|
|
96
|
+
} = await import("@yuneta/gobj-js");
|
|
97
|
+
const {register_c_yui_treedb_topic_with_form} = await import("./c_yui_treedb_topic_with_form.js");
|
|
98
|
+
|
|
99
|
+
const logged = [];
|
|
100
|
+
let yuno = null;
|
|
101
|
+
let n = 0;
|
|
102
|
+
|
|
103
|
+
beforeAll(async () => {
|
|
104
|
+
const i18next = (await import("i18next")).default;
|
|
105
|
+
await i18next.init({lng: "en", resources: {}});
|
|
106
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
107
|
+
set_log_callback((level, msg) => {
|
|
108
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
109
|
+
});
|
|
110
|
+
gclass_create("C_TEST_EDITOR_GUARD_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
111
|
+
register_c_yui_treedb_topic_with_form();
|
|
112
|
+
yuno = gobj_create_yuno("editor_guard_yuno", "C_TEST_EDITOR_GUARD_HOST", {});
|
|
113
|
+
gobj_start(yuno);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
state.calls.length = 0;
|
|
118
|
+
state.edited_row = null;
|
|
119
|
+
state.refuse = false;
|
|
120
|
+
logged.length = 0;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
function make_view()
|
|
124
|
+
{
|
|
125
|
+
const view = gobj_create_service(`editor_guard_view_${++n}`, "C_YUI_TREEDB_TOPIC_WITH_FORM", {
|
|
126
|
+
treedb_name: "treedb_test",
|
|
127
|
+
topic_name: "people",
|
|
128
|
+
desc: {id: "people", pkey: "id", cols: [
|
|
129
|
+
{id: "id", header: "Id", type: "string", flag: ["persistent", "required"]},
|
|
130
|
+
{id: "name", header: "name", type: "string", flag: ["persistent", "writable"]},
|
|
131
|
+
]}
|
|
132
|
+
}, yuno);
|
|
133
|
+
gobj_start(view);
|
|
134
|
+
state.tables[state.tables.length - 1]._ready = true;
|
|
135
|
+
return view;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
describe("an open cell editor of a treedb topic's table", () => {
|
|
139
|
+
test("is cancelled before setData (EV_LOAD_NODES)", () => {
|
|
140
|
+
const view = make_view();
|
|
141
|
+
state.edited_row = "b";
|
|
142
|
+
gobj_send_event(view, "EV_LOAD_NODES", [{id: "x"}], view);
|
|
143
|
+
expect(state.calls).toEqual(["cancel b", "setData edited=null"]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("is cancelled before replaceData (EV_REPULL_PAGE)", () => {
|
|
147
|
+
const view = make_view();
|
|
148
|
+
state.edited_row = "b";
|
|
149
|
+
gobj_send_event(view, "EV_REPULL_PAGE", {}, view);
|
|
150
|
+
expect(state.calls).toEqual(["cancel b", "replaceData edited=null"]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("is cancelled before the table is destroyed (stop)", () => {
|
|
154
|
+
const view = make_view();
|
|
155
|
+
state.edited_row = "b";
|
|
156
|
+
gobj_stop(view);
|
|
157
|
+
expect(state.calls).toEqual(["cancel b", "destroy edited=null"]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("is cancelled, with a WARNING, before updateData changes ITS cell; left alone otherwise", () => {
|
|
161
|
+
const view = make_view();
|
|
162
|
+
state.edited_row = "b";
|
|
163
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "a", age: 99}], view);
|
|
164
|
+
/* The echo of the reader's own write of the previous cell (7.26.58 cancelled here) */
|
|
165
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "b", name: "B"}], view);
|
|
166
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "b", name: "B", age: 41}], view);
|
|
167
|
+
expect(logged.filter((l) => /under its open editor/.test(l.msg)).length).toBe(0);
|
|
168
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "b", age: 99}], view);
|
|
169
|
+
expect(state.calls).toEqual([
|
|
170
|
+
"updateData a edited=b",
|
|
171
|
+
"updateData b edited=b",
|
|
172
|
+
"updateData b edited=b",
|
|
173
|
+
"cancel b", "updateData b edited=null",
|
|
174
|
+
]);
|
|
175
|
+
expect(logged.filter((l) => /row 'b' changed 'age' under its open editor: the edit is cancelled/
|
|
176
|
+
.test(l.msg)).length).toBe(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("a refused updateData is logged as an error, not left unhandled", async () => {
|
|
180
|
+
const view = make_view();
|
|
181
|
+
state.refuse = true;
|
|
182
|
+
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "a", name: "A"}], view);
|
|
183
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
184
|
+
expect(logged.filter((l) => /cannot update row 'a'.*Unable to update row/.test(l.msg)).length).toBe(1);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -27,12 +27,16 @@
|
|
|
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 threw, or -- before a promise answers
|
|
35
|
+
* -- the table was destroyed or another cell's editor was opened
|
|
36
|
+
* (the same cell opened again by the code is left as it is).
|
|
33
37
|
*
|
|
34
38
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
35
|
-
* destroy)
|
|
39
|
+
* destroy) cancels the edit first with
|
|
36
40
|
* `yui_tabulator_close_editor()`: there is no cell to open it
|
|
37
41
|
* on again.
|
|
38
42
|
*
|
|
@@ -89,21 +93,54 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
89
93
|
editing = null;
|
|
90
94
|
});
|
|
91
95
|
|
|
96
|
+
function stays_closed(field, why)
|
|
97
|
+
{
|
|
98
|
+
log_warning(`yui_tabulator_keep_edit_on_redraw: the edit of '${field}' stays closed: ${why}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function has_column(field)
|
|
102
|
+
{
|
|
103
|
+
return tabulator.getColumns().some((c) => c.getField() === field);
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
function edit_again(row, field, name)
|
|
93
107
|
{
|
|
108
|
+
if(tabulator.destroyed) {
|
|
109
|
+
stays_closed(field, `the table was destroyed after ${name}()`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
let $open = editing? editing.getElement() : null;
|
|
113
|
+
if($open && $open.classList.contains("tabulator-editing")) {
|
|
114
|
+
if(editing.getRow() !== row || editing.getField() !== field) {
|
|
115
|
+
stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
116
|
+
}
|
|
117
|
+
return; // else the code opened this same cell again: it is open
|
|
118
|
+
}
|
|
119
|
+
/* A row the page does not draw keeps the cells of the old
|
|
120
|
+
* columns, so it answers no cell for a column that does exist. */
|
|
94
121
|
let again = row.getCell(field);
|
|
95
122
|
if(!again) {
|
|
96
|
-
|
|
97
|
-
|
|
123
|
+
if(has_column(field)) {
|
|
124
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
125
|
+
} else {
|
|
126
|
+
stays_closed(field, `no column '${field}' after ${name}()`);
|
|
127
|
+
}
|
|
98
128
|
return;
|
|
99
129
|
}
|
|
100
130
|
let $again = again.getElement();
|
|
101
131
|
if(!$again || !$again.isConnected) {
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
stays_closed(field, `its row is not in the page after ${name}()`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if(!again.getColumn().getDefinition().editor) {
|
|
136
|
+
stays_closed(field, `the column has no editor after ${name}()`);
|
|
104
137
|
return;
|
|
105
138
|
}
|
|
106
|
-
|
|
139
|
+
try {
|
|
140
|
+
again.edit(true);
|
|
141
|
+
} catch(e) {
|
|
142
|
+
stays_closed(field, `Tabulator refused to open it after ${name}(): ${e}`);
|
|
143
|
+
}
|
|
107
144
|
}
|
|
108
145
|
|
|
109
146
|
function keep_edit_around(name, rebuilds)
|
|
@@ -120,7 +157,13 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
120
157
|
let row = cell.getRow();
|
|
121
158
|
let field = cell.getField();
|
|
122
159
|
cell.cancelEdit();
|
|
123
|
-
let ret
|
|
160
|
+
let ret;
|
|
161
|
+
try {
|
|
162
|
+
ret = original(...args);
|
|
163
|
+
} catch(e) {
|
|
164
|
+
stays_closed(field, `${name}() threw: ${e}`);
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
124
167
|
if(ret && typeof ret.then === "function") {
|
|
125
168
|
return ret.then(
|
|
126
169
|
(value) => {
|
|
@@ -128,7 +171,9 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
128
171
|
return value;
|
|
129
172
|
},
|
|
130
173
|
(reason) => {
|
|
131
|
-
|
|
174
|
+
/* The edit had to be ended before asking; a refused
|
|
175
|
+
* call rebuilt nothing, so nothing is opened again. */
|
|
176
|
+
stays_closed(field, `${name}() was refused: ${reason}`);
|
|
132
177
|
throw reason;
|
|
133
178
|
}
|
|
134
179
|
);
|
|
@@ -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] || editors[field] === "throws") {
|
|
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
|
},
|
|
@@ -67,6 +78,9 @@ function make_table()
|
|
|
67
78
|
"moveColumn"]) {
|
|
68
79
|
table[name] = function(...args) {
|
|
69
80
|
calls.push(`${name}(${args.join(",")})`);
|
|
81
|
+
if(args[0] === null) {
|
|
82
|
+
throw new TypeError(`${name}(null)`);
|
|
83
|
+
}
|
|
70
84
|
return `${name} done`;
|
|
71
85
|
};
|
|
72
86
|
}
|
|
@@ -89,6 +103,8 @@ function make_table()
|
|
|
89
103
|
beforeEach(() => {
|
|
90
104
|
calls = [];
|
|
91
105
|
connected = true;
|
|
106
|
+
drawn = true;
|
|
107
|
+
editors = {when: "input", note: "input"};
|
|
92
108
|
});
|
|
93
109
|
|
|
94
110
|
describe("an open edit around a call that builds the cells again", () => {
|
|
@@ -143,7 +159,9 @@ describe("what it leaves alone", () => {
|
|
|
143
159
|
|
|
144
160
|
test("a column the new columns do not have: the edit stays closed", () => {
|
|
145
161
|
const table = make_table();
|
|
162
|
+
editors.gone = "input";
|
|
146
163
|
table.emit("cellEditing", make_cell(table.row, "gone", true));
|
|
164
|
+
delete editors.gone;
|
|
147
165
|
expect(table.setColumns(["other"])).toBe("setColumns done");
|
|
148
166
|
expect(calls).toEqual(["cancel gone", "setColumns(other)", "getCell gone"]);
|
|
149
167
|
});
|
|
@@ -164,11 +182,56 @@ describe("a call that answers a promise", () => {
|
|
|
164
182
|
});
|
|
165
183
|
}
|
|
166
184
|
|
|
167
|
-
test("a refusal
|
|
185
|
+
test("a refusal rebuilt nothing: not opened again, said, and passed on", async () => {
|
|
186
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
168
187
|
const table = make_table();
|
|
169
188
|
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
170
189
|
await expect(table.updateColumnDefinition("reject")).rejects.toThrow("refused");
|
|
171
|
-
expect(calls
|
|
190
|
+
expect(calls).toEqual(["cancel when", "updateColumnDefinition(reject)",
|
|
191
|
+
"updateColumnDefinition resolved"]);
|
|
192
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: updateColumnDefinition\(\) was refused/);
|
|
193
|
+
warn.mockRestore();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("another edit opened before the answer keeps the edit", async () => {
|
|
197
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
198
|
+
const table = make_table();
|
|
199
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
200
|
+
const ret = table.addColumn("x");
|
|
201
|
+
table.emit("cellEditing", make_cell(table.row, "note", true));
|
|
202
|
+
await ret;
|
|
203
|
+
expect(calls).toEqual(["cancel when", "addColumn(x)", "addColumn resolved"]);
|
|
204
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: another cell \('note'\) was opened after addColumn\(\)/);
|
|
205
|
+
warn.mockRestore();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("a table destroyed before the answer: not opened, and said so", async () => {
|
|
209
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
210
|
+
const table = make_table();
|
|
211
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
212
|
+
const ret = table.updateColumnDefinition("when");
|
|
213
|
+
table.destroyed = true;
|
|
214
|
+
await ret;
|
|
215
|
+
expect(calls).toEqual(["cancel when", "updateColumnDefinition(when)",
|
|
216
|
+
"updateColumnDefinition resolved"]);
|
|
217
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: the table was destroyed after updateColumnDefinition\(\)/);
|
|
218
|
+
warn.mockRestore();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("a column the call left with no editor", () => {
|
|
223
|
+
test("not opened (no throw), and the log says why", async () => {
|
|
224
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
225
|
+
const table = make_table();
|
|
226
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
227
|
+
editors.when = false;
|
|
228
|
+
expect(table.setColumns(["defs"])).toBe("setColumns done");
|
|
229
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
230
|
+
expect(await table.updateColumnDefinition("when")).toBe("updateColumnDefinition done");
|
|
231
|
+
expect(calls.filter((c) => c.startsWith("edit"))).toEqual([]);
|
|
232
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: the column has no editor after setColumns\(\)/);
|
|
233
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/after updateColumnDefinition\(\)/);
|
|
234
|
+
warn.mockRestore();
|
|
172
235
|
});
|
|
173
236
|
});
|
|
174
237
|
|
|
@@ -183,4 +246,50 @@ describe("a cell the call left out of the page", () => {
|
|
|
183
246
|
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: its row is not in the page after setHeight\(\)/);
|
|
184
247
|
warn.mockRestore();
|
|
185
248
|
});
|
|
249
|
+
|
|
250
|
+
test("an undrawn row answers no cell: said as out of the page, not as no column", () => {
|
|
251
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
252
|
+
const table = make_table();
|
|
253
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
254
|
+
drawn = false;
|
|
255
|
+
expect(table.setColumns(["defs"])).toBe("setColumns done");
|
|
256
|
+
expect(calls).toEqual(["cancel when", "setColumns(defs)", "getCell when"]);
|
|
257
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: its row is not in the page after setColumns\(\)/);
|
|
258
|
+
warn.mockRestore();
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe("what the re-open does not let through", () => {
|
|
263
|
+
test("an editor that throws when opened: caught, and said", () => {
|
|
264
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
265
|
+
editors.when = "throws";
|
|
266
|
+
const table = make_table();
|
|
267
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
268
|
+
expect(table.setHeight(300)).toBe("setHeight done");
|
|
269
|
+
expect(calls).toEqual(["cancel when", "setHeight(300)", "getCell when", "edit when true"]);
|
|
270
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: Tabulator refused to open it after setHeight\(\): TypeError/);
|
|
271
|
+
warn.mockRestore();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("a call that throws: not opened again, said, and thrown on", () => {
|
|
275
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
276
|
+
const table = make_table();
|
|
277
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
278
|
+
expect(() => table.setColumns(null)).toThrow("setColumns(null)");
|
|
279
|
+
expect(calls).toEqual(["cancel when", "setColumns()"]);
|
|
280
|
+
expect(warn.mock.calls.flat().join(" ")).toMatch(/'when' stays closed: setColumns\(\) threw: TypeError: setColumns\(null\)/);
|
|
281
|
+
warn.mockRestore();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("the same cell opened again by the code before the answer: left open, nothing said", async () => {
|
|
285
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
286
|
+
const table = make_table();
|
|
287
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
288
|
+
const ret = table.addColumn("x");
|
|
289
|
+
table.emit("cellEditing", make_cell(table.row, "when", true));
|
|
290
|
+
await ret;
|
|
291
|
+
expect(calls).toEqual(["cancel when", "addColumn(x)", "addColumn resolved"]);
|
|
292
|
+
expect(warn).not.toHaveBeenCalled();
|
|
293
|
+
warn.mockRestore();
|
|
294
|
+
});
|
|
186
295
|
});
|