@yuneta/gobj-ui 7.26.48 → 7.26.50
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 +133 -31
- package/dist/gobj-ui.cjs.js +288 -14
- package/dist/gobj-ui.es.js +288 -14
- package/package.json +2 -2
- package/scripts/validate-locales.mjs +734 -76
- package/src/c_yui_form.js +63 -5
- package/src/c_yui_gobj_tree_js.js +37 -4
- package/src/c_yui_shell.css +17 -3
- package/src/c_yui_shell.js +311 -0
- package/src/form_table_rows.wiring.test.js +32 -0
- package/src/form_time_cell_editor.js +20 -5
- package/src/form_time_cell_editor.test.js +73 -0
- package/src/form_time_field.wiring.test.js +71 -0
- package/src/gobj_tree_camera.wiring.test.js +185 -0
- package/src/overlay_marker_after_back.wiring.test.js +3 -0
- package/src/shell_focus_trap.js +21 -0
- package/src/shell_focus_trap.test.js +52 -0
- package/src/shell_history_debt.wiring.test.js +456 -0
|
@@ -167,6 +167,16 @@ vi.mock("tabulator-tables", () => {
|
|
|
167
167
|
getRows() {
|
|
168
168
|
return this.rows.map((row) => row.component);
|
|
169
169
|
}
|
|
170
|
+
getSelectedRows() {
|
|
171
|
+
return this.rows.filter((row) => row.selected).map((row) => row.component);
|
|
172
|
+
}
|
|
173
|
+
/* SelectRow's deselectRow(): with no argument every row, and
|
|
174
|
+
* it asks no `selectableRowsCheck`. */
|
|
175
|
+
deselectRow() {
|
|
176
|
+
for(const row of this.rows) {
|
|
177
|
+
row.selected = false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
170
180
|
/* The structured columns start with the row header, as
|
|
171
181
|
* Tabulator's (ColumnManager.columns). */
|
|
172
182
|
getColumns(structured) {
|
|
@@ -662,6 +672,28 @@ describe("the checkbox column", () => {
|
|
|
662
672
|
expect(errors()).toEqual([]);
|
|
663
673
|
});
|
|
664
674
|
|
|
675
|
+
/* Up to 7.26.48 the rows selected before stayed selected: no box
|
|
676
|
+
* to untick, and a click asks the check, which refuses. */
|
|
677
|
+
test("written false, it takes off what was selected", async () => {
|
|
678
|
+
const {form, first} = build(record(), null, {
|
|
679
|
+
with_checkbox: true, tabulator_settings: {selectableRows: true}
|
|
680
|
+
});
|
|
681
|
+
await settle();
|
|
682
|
+
const alarms = alarms_of(first);
|
|
683
|
+
alarms.click_row(0);
|
|
684
|
+
alarms.click_row(1);
|
|
685
|
+
expect(alarms.getSelectedRows().length).toBe(2);
|
|
686
|
+
gobj_write_attr(form, "selectable", false);
|
|
687
|
+
expect(alarms.getColumns(true)[0].isVisible()).toBe(false);
|
|
688
|
+
expect(alarms.getSelectedRows().length).toBe(0);
|
|
689
|
+
alarms.click_row(0);
|
|
690
|
+
expect(alarms.getSelectedRows().length).toBe(0);
|
|
691
|
+
gobj_write_attr(form, "selectable", true);
|
|
692
|
+
alarms.click_row(0);
|
|
693
|
+
expect(alarms.getSelectedRows().length).toBe(1);
|
|
694
|
+
expect(errors()).toEqual([]);
|
|
695
|
+
});
|
|
696
|
+
|
|
665
697
|
test("a table built after `selectable` was written follows it", async () => {
|
|
666
698
|
const {form, first} = build(record(), (f) => {
|
|
667
699
|
gobj_write_attr(f, "selectable", false);
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
* it had. Up to gobj-ui 7.26.46 both committed null: one
|
|
32
32
|
* Backspace and Enter erased the stored time. To clear a time
|
|
33
33
|
* on purpose, clear EVERY part of the box: an empty box
|
|
34
|
-
* commits null.
|
|
35
|
-
*
|
|
34
|
+
* commits null. Inside the box the Left and Right arrows move
|
|
35
|
+
* between its parts; Tab is the table's (Tabulator's navNext):
|
|
36
|
+
* it leaves the cell and opens the editor of the next one, in
|
|
37
|
+
* Chromium and Firefox alike.
|
|
36
38
|
*
|
|
37
39
|
* Copyright (c) 2026, ArtGins.
|
|
38
40
|
* All Rights Reserved.
|
|
@@ -82,6 +84,13 @@ function form_time_cell_editor(real_type)
|
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
input.value = original_text;
|
|
87
|
+
/* What the box holds, as the browser writes it: Chromium and
|
|
88
|
+
* Firefox drop seconds of :00 ("…T02:30:00" reads "…T02:30"),
|
|
89
|
+
* so the text written never equals the text read back. Up to
|
|
90
|
+
* gobj-ui 7.26.48 a confirm with nothing changed then fell to
|
|
91
|
+
* the epoch, which in the repeated hour of autumn is one hour
|
|
92
|
+
* earlier (form_time_value.js): Enter wrote -3600 s. */
|
|
93
|
+
let shown_text = input.value;
|
|
85
94
|
|
|
86
95
|
onRendered(function() {
|
|
87
96
|
if(cell.getType() === "cell") {
|
|
@@ -106,7 +115,7 @@ function form_time_cell_editor(real_type)
|
|
|
106
115
|
}
|
|
107
116
|
return;
|
|
108
117
|
}
|
|
109
|
-
if(input.value ===
|
|
118
|
+
if(input.value === shown_text) {
|
|
110
119
|
cancel();
|
|
111
120
|
return;
|
|
112
121
|
}
|
|
@@ -125,11 +134,17 @@ function form_time_cell_editor(real_type)
|
|
|
125
134
|
}
|
|
126
135
|
});
|
|
127
136
|
|
|
128
|
-
|
|
137
|
+
/* On every key too: a part cleared in a box whose value was
|
|
138
|
+
* already "" (incomplete) changes no value, and Chromium fires
|
|
139
|
+
* `input` only when the value changes -- the last part
|
|
140
|
+
* cleared left `aria-invalid` on an empty, valid box. */
|
|
141
|
+
let recheck = function() {
|
|
129
142
|
if(!incomplete()) {
|
|
130
143
|
input.removeAttribute("aria-invalid");
|
|
131
144
|
}
|
|
132
|
-
}
|
|
145
|
+
};
|
|
146
|
+
input.addEventListener("input", recheck);
|
|
147
|
+
input.addEventListener("keyup", recheck);
|
|
133
148
|
|
|
134
149
|
input.addEventListener("keydown", function(e) {
|
|
135
150
|
switch(e.key) {
|
|
@@ -151,4 +151,77 @@ describe("a time column's cell editor", () => {
|
|
|
151
151
|
expect(said.success).toEqual([]);
|
|
152
152
|
expect(said.cancel).toBe(1);
|
|
153
153
|
});
|
|
154
|
+
|
|
155
|
+
test("a box emptied part by part is no longer said invalid, with no `input`", () => {
|
|
156
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
157
|
+
half_typed($input);
|
|
158
|
+
$input.dispatchEvent(key("Enter"));
|
|
159
|
+
expect($input.getAttribute("aria-invalid")).toBe("true");
|
|
160
|
+
|
|
161
|
+
/* The other parts cleared: still "" -- no value changed, so
|
|
162
|
+
* Chromium fires no `input` --, and no longer badInput. */
|
|
163
|
+
Object.defineProperty($input, "validity", {configurable: true, value: {badInput: false, valid: true}});
|
|
164
|
+
$input.dispatchEvent({type: "keyup", key: "Backspace"});
|
|
165
|
+
expect($input.getAttribute("aria-invalid")).toBe(null);
|
|
166
|
+
$input.dispatchEvent(key("Enter"));
|
|
167
|
+
expect(said.success).toEqual([null]);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/* Chromium and Firefox write a `datetime-local` value without its
|
|
172
|
+
* seconds when they are :00: "…T02:30:00" reads back "…T02:30". */
|
|
173
|
+
function with_browser_box(fn)
|
|
174
|
+
{
|
|
175
|
+
const create = document.createElement;
|
|
176
|
+
document.createElement = function(tag) {
|
|
177
|
+
const el = create.call(document, tag);
|
|
178
|
+
if(String(tag).toLowerCase() === "input") {
|
|
179
|
+
let raw = "";
|
|
180
|
+
Object.defineProperty(el, "value", {
|
|
181
|
+
configurable: true,
|
|
182
|
+
get: () => raw,
|
|
183
|
+
set: (v) => {
|
|
184
|
+
raw = String(v).replace(/^(\d{4}-\d\d-\d\dT\d\d:\d\d):00$/, "$1");
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return el;
|
|
189
|
+
};
|
|
190
|
+
try {
|
|
191
|
+
fn();
|
|
192
|
+
} finally {
|
|
193
|
+
document.createElement = create;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
describe("a time on the hour, as the browser writes it", () => {
|
|
198
|
+
test("Enter with nothing changed is a cancel, in the repeated hour of autumn too", () => {
|
|
199
|
+
const tz = process.env.TZ;
|
|
200
|
+
process.env.TZ = "Europe/Madrid";
|
|
201
|
+
try {
|
|
202
|
+
/* 01:30Z on 2026-10-25 is 02:30 of the SECOND pass in Madrid:
|
|
203
|
+
* read back as a wall time it is the first one, an hour
|
|
204
|
+
* earlier. */
|
|
205
|
+
const epoch = Date.UTC(2026, 9, 25, 1, 30, 0) / 1000;
|
|
206
|
+
for(const [value, real_type] of [
|
|
207
|
+
[epoch, "integer"],
|
|
208
|
+
[new Date(epoch * 1000).toISOString(), "string"],
|
|
209
|
+
[Math.floor(new Date("2026-03-14T09:26:00").getTime() / 1000), "integer"],
|
|
210
|
+
]) {
|
|
211
|
+
with_browser_box(() => {
|
|
212
|
+
const {$input, said} = open_editor(value, real_type);
|
|
213
|
+
expect($input.value).toMatch(/T\d\d:\d\d$/);
|
|
214
|
+
$input.dispatchEvent(key("Enter"));
|
|
215
|
+
expect(said.success).toEqual([]);
|
|
216
|
+
expect(said.cancel).toBe(1);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
} finally {
|
|
220
|
+
if(tz === undefined) {
|
|
221
|
+
delete process.env.TZ;
|
|
222
|
+
} else {
|
|
223
|
+
process.env.TZ = tz;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
154
227
|
});
|
|
@@ -115,4 +115,75 @@ describe("the time field of a form", () => {
|
|
|
115
115
|
expect(saved[0].no_time).toBe(null);
|
|
116
116
|
expect(errors()).toEqual([]);
|
|
117
117
|
});
|
|
118
|
+
|
|
119
|
+
/* The template grammar defaults a spec with no real type to
|
|
120
|
+
* `string`: "time.writable" was read as an ISO text, so the
|
|
121
|
+
* test-app's appointment showed no time and a save wrote null
|
|
122
|
+
* (gobj-ui 7.26.47 and 7.26.48). */
|
|
123
|
+
test("a spec with no real type (\"time.writable\") is an epoch; \"string.time\" is a text", () => {
|
|
124
|
+
const app = gobj_create_pure_child("tapp2", "C_TEST_TIME_APP", {}, yuno);
|
|
125
|
+
gobj_start(app);
|
|
126
|
+
const form = gobj_create_pure_child("tform2", "C_YUI_FORM", {
|
|
127
|
+
template: {
|
|
128
|
+
bare: "time.writable",
|
|
129
|
+
as_text: "string.time.writable",
|
|
130
|
+
as_int: "integer.time.writable",
|
|
131
|
+
},
|
|
132
|
+
record: {bare: EPOCH, as_text: ISO, as_int: EPOCH},
|
|
133
|
+
editable: true,
|
|
134
|
+
}, app);
|
|
135
|
+
gobj_start(form);
|
|
136
|
+
|
|
137
|
+
expect(box(form, "bare").value).toBe(WALL);
|
|
138
|
+
expect(box(form, "as_text").value).toBe(WALL);
|
|
139
|
+
expect(box(form, "as_int").value).toBe(WALL);
|
|
140
|
+
|
|
141
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
142
|
+
expect(saved.length).toBe(1);
|
|
143
|
+
expect(saved[0].bare).toBe(EPOCH);
|
|
144
|
+
expect(saved[0].as_text).toBe(ISO);
|
|
145
|
+
expect(saved[0].as_int).toBe(EPOCH);
|
|
146
|
+
expect(errors()).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/* The red outline is for the eye only: up to gobj-ui 7.26.48 a field
|
|
150
|
+
* Save refused -- here a date with a part cleared -- carried no
|
|
151
|
+
* aria-invalid, and its line was not the box's description. */
|
|
152
|
+
test("a date with a part cleared is said invalid to a reader, and the line describes it", () => {
|
|
153
|
+
const app = gobj_create_pure_child("tapp3", "C_TEST_TIME_APP", {}, yuno);
|
|
154
|
+
gobj_start(app);
|
|
155
|
+
const form = gobj_create_pure_child("tform3", "C_YUI_FORM", {
|
|
156
|
+
template: TEMPLATE,
|
|
157
|
+
record: {as_epoch: EPOCH, as_text: ISO, no_time: null},
|
|
158
|
+
editable: true,
|
|
159
|
+
}, app);
|
|
160
|
+
gobj_start(form);
|
|
161
|
+
|
|
162
|
+
const $box = box(form, "as_epoch");
|
|
163
|
+
$box.value = "";
|
|
164
|
+
Object.defineProperty($box, "validity", {
|
|
165
|
+
configurable: true,
|
|
166
|
+
value: {badInput: true, valid: false, valueMissing: false}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty($box, "validationMessage", {
|
|
169
|
+
configurable: true, value: "Please enter a valid date and time."
|
|
170
|
+
});
|
|
171
|
+
$box.dispatchEvent({type: "invalid"});
|
|
172
|
+
expect($box.classList.contains("is-danger")).toBe(true);
|
|
173
|
+
expect($box.getAttribute("aria-invalid")).toBe("true");
|
|
174
|
+
const $help = $box.parentNode.querySelector(".help");
|
|
175
|
+
expect($help.textContent).toBe("Please enter a valid date and time.");
|
|
176
|
+
expect($help.id).toBeTruthy();
|
|
177
|
+
expect($box.getAttribute("aria-describedby")).toBe($help.id);
|
|
178
|
+
|
|
179
|
+
Object.defineProperty($box, "validity", {
|
|
180
|
+
configurable: true, value: {badInput: false, valid: true, valueMissing: false}
|
|
181
|
+
});
|
|
182
|
+
$box.value = WALL;
|
|
183
|
+
$box.dispatchEvent({type: "blur"});
|
|
184
|
+
expect($box.classList.contains("is-danger")).toBe(false);
|
|
185
|
+
expect($box.getAttribute("aria-invalid")).toBe(null);
|
|
186
|
+
expect($help.textContent).toBe("");
|
|
187
|
+
expect(errors()).toEqual([]);
|
|
188
|
+
});
|
|
118
189
|
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* gobj_tree_camera.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* C_YUI_GOBJ_TREE_JS keeps where the reader left the camera
|
|
5
|
+
* (localStorage, yui_gobj_tree_view:<name>). Before G6 paints, its
|
|
6
|
+
* getZoom() / getPosition() answer NaN: written as they came, the
|
|
7
|
+
* camera was saved as nulls (a NaN has no json text) and gobj-js
|
|
8
|
+
* 7.26.27 refuses the whole value with an ERROR. Only real numbers
|
|
9
|
+
* are written now; a camera that is not readable keeps the one
|
|
10
|
+
* saved before, and a saved camera of nulls is not restored.
|
|
11
|
+
*
|
|
12
|
+
* The real gclass, on a G6 Graph double whose camera the test sets.
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026, ArtGins.
|
|
15
|
+
* All Rights Reserved.
|
|
16
|
+
***********************************************************************/
|
|
17
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
18
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
19
|
+
|
|
20
|
+
install_dom_double();
|
|
21
|
+
|
|
22
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
23
|
+
globalThis.ResizeObserver = class {
|
|
24
|
+
observe() {
|
|
25
|
+
}
|
|
26
|
+
unobserve() {
|
|
27
|
+
}
|
|
28
|
+
disconnect() {
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const camera = vi.hoisted(() => ({zoom: NaN, position: [NaN, NaN], zoomed: [], moved: []}));
|
|
34
|
+
vi.mock("@antv/g6", async (importOriginal) => {
|
|
35
|
+
const real = await importOriginal();
|
|
36
|
+
class FakeGraph {
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
return new Proxy(this, {
|
|
40
|
+
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
render() {
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
}
|
|
46
|
+
draw() {
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
}
|
|
49
|
+
on() {
|
|
50
|
+
}
|
|
51
|
+
getZoom() {
|
|
52
|
+
return camera.zoom;
|
|
53
|
+
}
|
|
54
|
+
getPosition() {
|
|
55
|
+
return camera.position;
|
|
56
|
+
}
|
|
57
|
+
zoomTo(z) {
|
|
58
|
+
camera.zoomed.push(z);
|
|
59
|
+
return Promise.resolve();
|
|
60
|
+
}
|
|
61
|
+
translateTo(p) {
|
|
62
|
+
camera.moved.push(p);
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
}
|
|
65
|
+
getData() {
|
|
66
|
+
return {nodes: [], edges: [], combos: []};
|
|
67
|
+
}
|
|
68
|
+
getNodeData() {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
getEdgeData() {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
getPlugins() {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
getBehaviors() {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
getOptions() {
|
|
81
|
+
return {behaviors: []};
|
|
82
|
+
}
|
|
83
|
+
getCanvas() {
|
|
84
|
+
return {getLayers: () => ({}), getContainer: () => null};
|
|
85
|
+
}
|
|
86
|
+
fitView() {
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
}
|
|
89
|
+
destroy() {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {...real, Graph: FakeGraph};
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const {
|
|
96
|
+
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
97
|
+
gobj_start, gobj_read_attr, gobj_send_event, set_log_callback, register_c_timer,
|
|
98
|
+
} = await import("@yuneta/gobj-js");
|
|
99
|
+
const {register_c_yui_gobj_tree_js} = await import("./c_yui_gobj_tree_js.js");
|
|
100
|
+
|
|
101
|
+
const logged = [];
|
|
102
|
+
let yuno = null;
|
|
103
|
+
let seq = 0;
|
|
104
|
+
|
|
105
|
+
beforeAll(async () => {
|
|
106
|
+
const i18next = (await import("i18next")).default;
|
|
107
|
+
await i18next.init({lng: "en", resources: {en: {translation: {}}}});
|
|
108
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
109
|
+
set_log_callback((level, msg) => {
|
|
110
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
111
|
+
});
|
|
112
|
+
register_c_timer();
|
|
113
|
+
register_c_yui_gobj_tree_js();
|
|
114
|
+
gclass_create("C_TEST_CAMERA_HOST", [], [["ST_IDLE", []]], {}, 0,
|
|
115
|
+
[SDATA_END()], {}, 0, 0, 0, 0);
|
|
116
|
+
yuno = gobj_create_yuno("camera_yuno", "C_TEST_CAMERA_HOST", {});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
beforeEach(() => {
|
|
120
|
+
logged.length = 0;
|
|
121
|
+
camera.zoom = NaN;
|
|
122
|
+
camera.position = [NaN, NaN];
|
|
123
|
+
camera.zoomed = [];
|
|
124
|
+
camera.moved = [];
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
function errors()
|
|
128
|
+
{
|
|
129
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function mount(name)
|
|
133
|
+
{
|
|
134
|
+
const view = gobj_create_pure_child(name, "C_YUI_GOBJ_TREE_JS",
|
|
135
|
+
{$container: document.createElement("div")}, yuno);
|
|
136
|
+
document.body.appendChild(gobj_read_attr(view, "$container"));
|
|
137
|
+
gobj_start(view);
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
139
|
+
return view;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function saved(name)
|
|
143
|
+
{
|
|
144
|
+
const raw = window.localStorage.getItem(`yui_gobj_tree_view:${name}`);
|
|
145
|
+
return raw? JSON.parse(raw) : null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
describe("C_YUI_GOBJ_TREE_JS saves only a camera of numbers", () => {
|
|
149
|
+
test("a camera G6 cannot tell yet (NaN) is not written", async () => {
|
|
150
|
+
const name = `camera_${++seq}`;
|
|
151
|
+
const view = await mount(name);
|
|
152
|
+
gobj_send_event(view, "EV_REFRESH", {}, view);
|
|
153
|
+
const state = saved(name);
|
|
154
|
+
expect(state).not.toBe(null);
|
|
155
|
+
expect("zoom" in state).toBe(false);
|
|
156
|
+
expect("position" in state).toBe(false);
|
|
157
|
+
expect(errors()).toEqual([]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("it keeps the camera saved before", async () => {
|
|
161
|
+
const name = `camera_${++seq}`;
|
|
162
|
+
const view = await mount(name);
|
|
163
|
+
camera.zoom = 2;
|
|
164
|
+
camera.position = [10, 20];
|
|
165
|
+
gobj_send_event(view, "EV_REFRESH", {}, view);
|
|
166
|
+
expect(saved(name)).toMatchObject({zoom: 2, position: [10, 20]});
|
|
167
|
+
|
|
168
|
+
camera.zoom = NaN;
|
|
169
|
+
camera.position = [NaN, NaN];
|
|
170
|
+
gobj_send_event(view, "EV_REFRESH", {}, view);
|
|
171
|
+
expect(saved(name)).toMatchObject({zoom: 2, position: [10, 20]});
|
|
172
|
+
expect(errors()).toEqual([]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("a saved camera of nulls is not restored", async () => {
|
|
176
|
+
const name = `camera_${++seq}`;
|
|
177
|
+
window.localStorage.setItem(`yui_gobj_tree_view:${name}`,
|
|
178
|
+
JSON.stringify({layout: "", collapsed: {}, anchor: "", zoom: null, position: [null, null]}));
|
|
179
|
+
await mount(name);
|
|
180
|
+
/* zoomTo(1) is the view's own first framing, not the restore. */
|
|
181
|
+
expect(camera.zoomed.every((z) => Number.isFinite(z))).toBe(true);
|
|
182
|
+
expect(camera.moved).toEqual([]);
|
|
183
|
+
expect(errors()).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -276,6 +276,9 @@ afterEach(async () => {
|
|
|
276
276
|
gobj_stop(sh);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
+
/* A back() a test left in flight at a stop lands here: the next
|
|
280
|
+
* test's shell would adopt it (adopt_orphan_back()). */
|
|
281
|
+
window.dispatchEvent(new Event("popstate"));
|
|
279
282
|
});
|
|
280
283
|
|
|
281
284
|
function errors()
|
package/src/shell_focus_trap.js
CHANGED
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
* stack, which was for good: a panel that only moved (taken out
|
|
34
34
|
* and put back, its trap never released) lost its trap. It is
|
|
35
35
|
* skipped now, and leaves the stack only by its release().
|
|
36
|
+
* The first time a trap is skipped it is said, once: a panel out
|
|
37
|
+
* of the document whose owner is gone keeps its keydown listener
|
|
38
|
+
* until a release() that will never come, and up to gobj-ui
|
|
39
|
+
* 7.26.48 nothing said so (twenty such panels, twenty listeners).
|
|
36
40
|
*
|
|
37
41
|
* No gobj dependency: only gobj-js's logger. The optional
|
|
38
42
|
* second argument lets callers inject a mock document object
|
|
@@ -41,6 +45,7 @@
|
|
|
41
45
|
* Copyright (c) 2026, ArtGins.
|
|
42
46
|
* All Rights Reserved.
|
|
43
47
|
***********************************************************************/
|
|
48
|
+
import {log_warning} from "@yuneta/gobj-js";
|
|
44
49
|
|
|
45
50
|
/* Selector matching the elements typically considered focusable.
|
|
46
51
|
* Kept conservative: items that are explicitly removed from the tab
|
|
@@ -72,10 +77,26 @@ function top_trap()
|
|
|
72
77
|
if(trap.$panel.isConnected !== false) {
|
|
73
78
|
return trap;
|
|
74
79
|
}
|
|
80
|
+
if(!trap.said_skipped) {
|
|
81
|
+
trap.said_skipped = true;
|
|
82
|
+
log_warning(
|
|
83
|
+
`focus trap: its panel (${panel_name(trap.$panel)}) is out of the ` +
|
|
84
|
+
`document and the trap was not released; it is skipped, and its ` +
|
|
85
|
+
`listener stays until its release() (an owner torn down with it open?)`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
75
88
|
}
|
|
76
89
|
return null;
|
|
77
90
|
}
|
|
78
91
|
|
|
92
|
+
/* What names a panel in the log: its classes, where the logical name
|
|
93
|
+
* of the overlay is. */
|
|
94
|
+
function panel_name($panel)
|
|
95
|
+
{
|
|
96
|
+
let cls = (typeof $panel.className === "string")? $panel.className.trim() : "";
|
|
97
|
+
return cls || "a panel with no class";
|
|
98
|
+
}
|
|
99
|
+
|
|
79
100
|
|
|
80
101
|
/* Whether `el` is drawn, so focus() on it can take. An element that
|
|
81
102
|
* cannot say (a stub with no getClientRects) is taken as drawn. */
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* `activate_focus_trap_on($panel, doc)` — no extra devDep.
|
|
7
7
|
***********************************************************************/
|
|
8
8
|
import { test, expect } from "vitest";
|
|
9
|
+
import { set_log_callback } from "@yuneta/gobj-js";
|
|
9
10
|
import {
|
|
10
11
|
FOCUSABLE_SELECTOR,
|
|
11
12
|
activate_focus_trap_on,
|
|
@@ -520,3 +521,54 @@ test("a panel taken out and put back keeps its trap", () => {
|
|
|
520
521
|
expect(doc.listeners.length).toBe(0);
|
|
521
522
|
expect(focus_trap_panel()).not.toBe(panel);
|
|
522
523
|
});
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
/***************************************************************
|
|
527
|
+
* A trap skipped because its panel is out of the document is
|
|
528
|
+
* said, once per trap: twenty panels taken out with their traps
|
|
529
|
+
* up (owners torn down with them open) leave twenty listeners,
|
|
530
|
+
* and up to gobj-ui 7.26.48 the log said nothing of them.
|
|
531
|
+
***************************************************************/
|
|
532
|
+
test("each trap skipped for a panel out of the document is said once", () => {
|
|
533
|
+
let warnings = [];
|
|
534
|
+
set_log_callback((level, msg) => {
|
|
535
|
+
if(String(level) === "warning") {
|
|
536
|
+
warnings.push(String(msg));
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
try {
|
|
540
|
+
let doc = make_doc(null);
|
|
541
|
+
let releases = [];
|
|
542
|
+
let panels = [];
|
|
543
|
+
for(let i = 0; i < 20; i++) {
|
|
544
|
+
let panel = connected_panel([make_focusable(`f${i}`)]);
|
|
545
|
+
panel.className = `MODAL DIALOG_${i} modal`;
|
|
546
|
+
panels.push(panel);
|
|
547
|
+
releases.push(activate_focus_trap_on(panel, doc));
|
|
548
|
+
panel.isConnected = false;
|
|
549
|
+
}
|
|
550
|
+
/* Only this test's: a trap an earlier test left skipped is said
|
|
551
|
+
* when the stack is first read here. */
|
|
552
|
+
let mine = () => warnings.filter((w) => w.includes("DIALOG_"));
|
|
553
|
+
expect(mine().length).toBe(0);
|
|
554
|
+
expect(panels.includes(focus_trap_panel())).toBe(false);
|
|
555
|
+
expect(panels.includes(focus_trap_panel())).toBe(false);
|
|
556
|
+
expect(mine().length).toBe(20);
|
|
557
|
+
expect(mine().every((w) => w.startsWith("focus trap: its panel (MODAL DIALOG_"))).toBe(true);
|
|
558
|
+
expect(doc.listeners.length).toBe(20);
|
|
559
|
+
|
|
560
|
+
/* One that comes back holds the focus again, and is not said again. */
|
|
561
|
+
panels[19].isConnected = true;
|
|
562
|
+
expect(focus_trap_panel()).toBe(panels[19]);
|
|
563
|
+
panels[19].isConnected = false;
|
|
564
|
+
expect(panels.includes(focus_trap_panel())).toBe(false);
|
|
565
|
+
expect(mine().length).toBe(20);
|
|
566
|
+
|
|
567
|
+
for(let release of releases) {
|
|
568
|
+
release();
|
|
569
|
+
}
|
|
570
|
+
expect(doc.listeners.length).toBe(0);
|
|
571
|
+
} finally {
|
|
572
|
+
set_log_callback(null);
|
|
573
|
+
}
|
|
574
|
+
});
|