@yuneta/gobj-ui 7.26.58 → 7.27.0
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
CHANGED
|
@@ -10373,8 +10373,9 @@ function form_time_cell_editor(real_type) {
|
|
|
10373
10373
|
* log says why, when: the cell is out of the page (a row the
|
|
10374
10374
|
* virtual DOM does not render, or a filter hides), its column is
|
|
10375
10375
|
* gone or has no editor any more, the call answered a REFUSAL
|
|
10376
|
-
* (it rebuilt nothing), or -- before a promise answers
|
|
10377
|
-
* table was destroyed or another cell's editor was opened
|
|
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).
|
|
10378
10379
|
*
|
|
10379
10380
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
10380
10381
|
* destroy) cancels the edit first with
|
|
@@ -10438,7 +10439,7 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10438
10439
|
}
|
|
10439
10440
|
let $open = editing ? editing.getElement() : null;
|
|
10440
10441
|
if ($open && $open.classList.contains("tabulator-editing")) {
|
|
10441
|
-
stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10442
|
+
if (editing.getRow() !== row || editing.getField() !== field) stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10442
10443
|
return;
|
|
10443
10444
|
}
|
|
10444
10445
|
let again = row.getCell(field);
|
|
@@ -10471,7 +10472,13 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10471
10472
|
let row = cell.getRow();
|
|
10472
10473
|
let field = cell.getField();
|
|
10473
10474
|
cell.cancelEdit();
|
|
10474
|
-
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
|
+
}
|
|
10475
10482
|
if (ret && typeof ret.then === "function") return ret.then((value) => {
|
|
10476
10483
|
edit_again(row, field, name);
|
|
10477
10484
|
return value;
|
|
@@ -34660,7 +34667,12 @@ function ac_load_node_updated(gobj, event, kw, src) {
|
|
|
34660
34667
|
let row = tabulator.getRow(record.id);
|
|
34661
34668
|
if (row) {
|
|
34662
34669
|
let $row = row.getElement();
|
|
34663
|
-
|
|
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
|
+
}
|
|
34664
34676
|
tabulator.updateData([record]).catch((e) => {
|
|
34665
34677
|
(0, _yuneta_gobj_js.log_error)(`${(0, _yuneta_gobj_js.gobj_short_name)(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
34666
34678
|
});
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -10368,8 +10368,9 @@ function form_time_cell_editor(real_type) {
|
|
|
10368
10368
|
* log says why, when: the cell is out of the page (a row the
|
|
10369
10369
|
* virtual DOM does not render, or a filter hides), its column is
|
|
10370
10370
|
* gone or has no editor any more, the call answered a REFUSAL
|
|
10371
|
-
* (it rebuilt nothing), or -- before a promise answers
|
|
10372
|
-
* table was destroyed or another cell's editor was opened
|
|
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).
|
|
10373
10374
|
*
|
|
10374
10375
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
10375
10376
|
* destroy) cancels the edit first with
|
|
@@ -10433,7 +10434,7 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10433
10434
|
}
|
|
10434
10435
|
let $open = editing ? editing.getElement() : null;
|
|
10435
10436
|
if ($open && $open.classList.contains("tabulator-editing")) {
|
|
10436
|
-
stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10437
|
+
if (editing.getRow() !== row || editing.getField() !== field) stays_closed(field, `another cell ('${editing.getField()}') was opened after ${name}()`);
|
|
10437
10438
|
return;
|
|
10438
10439
|
}
|
|
10439
10440
|
let again = row.getCell(field);
|
|
@@ -10466,7 +10467,13 @@ function yui_tabulator_keep_edit_on_redraw(tabulator) {
|
|
|
10466
10467
|
let row = cell.getRow();
|
|
10467
10468
|
let field = cell.getField();
|
|
10468
10469
|
cell.cancelEdit();
|
|
10469
|
-
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
|
+
}
|
|
10470
10477
|
if (ret && typeof ret.then === "function") return ret.then((value) => {
|
|
10471
10478
|
edit_again(row, field, name);
|
|
10472
10479
|
return value;
|
|
@@ -34655,7 +34662,12 @@ function ac_load_node_updated(gobj, event, kw, src) {
|
|
|
34655
34662
|
let row = tabulator.getRow(record.id);
|
|
34656
34663
|
if (row) {
|
|
34657
34664
|
let $row = row.getElement();
|
|
34658
|
-
|
|
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
|
+
}
|
|
34659
34671
|
tabulator.updateData([record]).catch((e) => {
|
|
34660
34672
|
log_error(`${gobj_short_name(gobj)}: cannot update row '${record.id}': ${e}`);
|
|
34661
34673
|
});
|
package/package.json
CHANGED
|
@@ -3927,11 +3927,19 @@ function ac_load_node_updated(gobj, event, kw, src)
|
|
|
3927
3927
|
*/
|
|
3928
3928
|
let row = tabulator.getRow(record.id);
|
|
3929
3929
|
if(row) {
|
|
3930
|
-
/*
|
|
3931
|
-
*
|
|
3932
|
-
*
|
|
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. */
|
|
3933
3936
|
let $row = row.getElement();
|
|
3934
|
-
|
|
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`);
|
|
3935
3943
|
yui_tabulator_close_editor(tabulator, gobj_short_name(gobj));
|
|
3936
3944
|
}
|
|
3937
3945
|
tabulator.updateData([record]).catch((e) => {
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* C_YUI_TREEDB_TOPIC_WITH_FORM cancels an open cell editor before
|
|
5
5
|
* each call of its table that would throw under it in Tabulator
|
|
6
6
|
* 6.6.0: setData (EV_LOAD_NODES), replaceData (EV_REPULL_PAGE),
|
|
7
|
-
* destroy (mt_stop), and updateData (EV_LOAD_NODE_UPDATED)
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
10
11
|
* refused updateData is logged, not left unhandled. The table is a
|
|
11
12
|
* double that records the order of the calls; that the real
|
|
12
13
|
* Tabulator throws without this is proved in a browser by
|
|
@@ -31,7 +32,7 @@ if(typeof globalThis.ResizeObserver === "undefined") {
|
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
const state = vi.hoisted(() => ({tables: [], calls: [], edited_row: null, refuse: false}));
|
|
35
|
+
const state = vi.hoisted(() => ({tables: [], calls: [], edited_row: null, edited_field: "age", refuse: false}));
|
|
35
36
|
vi.mock("tabulator-tables", () => {
|
|
36
37
|
class FakeTabulator {
|
|
37
38
|
constructor($el, settings) {
|
|
@@ -61,9 +62,13 @@ vi.mock("tabulator-tables", () => {
|
|
|
61
62
|
off() {
|
|
62
63
|
}
|
|
63
64
|
getRow(id) {
|
|
64
|
-
return {
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
};
|
|
67
72
|
}
|
|
68
73
|
getDataCount() {
|
|
69
74
|
return 2;
|
|
@@ -152,15 +157,23 @@ describe("an open cell editor of a treedb topic's table", () => {
|
|
|
152
157
|
expect(state.calls).toEqual(["cancel b", "destroy edited=null"]);
|
|
153
158
|
});
|
|
154
159
|
|
|
155
|
-
test("is cancelled before updateData
|
|
160
|
+
test("is cancelled, with a WARNING, before updateData changes ITS cell; left alone otherwise", () => {
|
|
156
161
|
const view = make_view();
|
|
157
162
|
state.edited_row = "b";
|
|
158
|
-
gobj_send_event(view, "EV_LOAD_NODE_UPDATED", [{id: "a",
|
|
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) */
|
|
159
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);
|
|
160
169
|
expect(state.calls).toEqual([
|
|
161
170
|
"updateData a edited=b",
|
|
171
|
+
"updateData b edited=b",
|
|
172
|
+
"updateData b edited=b",
|
|
162
173
|
"cancel b", "updateData b edited=null",
|
|
163
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);
|
|
164
177
|
});
|
|
165
178
|
|
|
166
179
|
test("a refused updateData is logged as an error, not left unhandled", async () => {
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
* log says why, when: the cell is out of the page (a row the
|
|
32
32
|
* virtual DOM does not render, or a filter hides), its column is
|
|
33
33
|
* gone or has no editor any more, the call answered a REFUSAL
|
|
34
|
-
* (it rebuilt nothing), or -- before a promise answers
|
|
35
|
-
* table was destroyed or another cell's editor was opened
|
|
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).
|
|
36
37
|
*
|
|
37
38
|
* A call that WIPES the rows (setData, replaceData, clearData,
|
|
38
39
|
* destroy) cancels the edit first with
|
|
@@ -110,8 +111,10 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
110
111
|
}
|
|
111
112
|
let $open = editing? editing.getElement() : null;
|
|
112
113
|
if($open && $open.classList.contains("tabulator-editing")) {
|
|
113
|
-
|
|
114
|
-
|
|
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
|
|
115
118
|
}
|
|
116
119
|
/* A row the page does not draw keeps the cells of the old
|
|
117
120
|
* columns, so it answers no cell for a column that does exist. */
|
|
@@ -154,7 +157,13 @@ function yui_tabulator_keep_edit_on_redraw(tabulator)
|
|
|
154
157
|
let row = cell.getRow();
|
|
155
158
|
let field = cell.getField();
|
|
156
159
|
cell.cancelEdit();
|
|
157
|
-
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
|
+
}
|
|
158
167
|
if(ret && typeof ret.then === "function") {
|
|
159
168
|
return ret.then(
|
|
160
169
|
(value) => {
|
|
@@ -45,7 +45,7 @@ function make_cell(row, field, editing)
|
|
|
45
45
|
},
|
|
46
46
|
edit(force) {
|
|
47
47
|
calls.push(`edit ${field} ${force}`);
|
|
48
|
-
if(!editors[field]) {
|
|
48
|
+
if(!editors[field] || editors[field] === "throws") {
|
|
49
49
|
throw new TypeError("Cannot read properties of undefined (reading 'blocked')");
|
|
50
50
|
}
|
|
51
51
|
},
|
|
@@ -78,6 +78,9 @@ function make_table()
|
|
|
78
78
|
"moveColumn"]) {
|
|
79
79
|
table[name] = function(...args) {
|
|
80
80
|
calls.push(`${name}(${args.join(",")})`);
|
|
81
|
+
if(args[0] === null) {
|
|
82
|
+
throw new TypeError(`${name}(null)`);
|
|
83
|
+
}
|
|
81
84
|
return `${name} done`;
|
|
82
85
|
};
|
|
83
86
|
}
|
|
@@ -255,3 +258,38 @@ describe("a cell the call left out of the page", () => {
|
|
|
255
258
|
warn.mockRestore();
|
|
256
259
|
});
|
|
257
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
|
+
});
|
|
295
|
+
});
|