@yuneta/gobj-ui 7.26.44 → 7.26.46
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 +160 -20
- package/dist/gobj-ui.cjs.js +326 -37
- package/dist/gobj-ui.es.js +327 -39
- package/index.js +1 -0
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +4 -1
- package/scripts/validate-locales.mjs +709 -178
- package/src/c_yui_form.js +116 -50
- package/src/c_yui_node.js +3 -1
- package/src/c_yui_schema_editor.js +3 -0
- package/src/c_yui_shell.js +113 -12
- package/src/c_yui_window.js +44 -5
- package/src/form_table_edits_ask.wiring.test.js +11 -2
- package/src/form_table_rows.wiring.test.js +284 -9
- package/src/form_time_cell_editor.js +143 -0
- package/src/form_time_cell_editor.test.js +116 -0
- package/src/i18n_key_functions.js +2 -2
- package/src/i18n_key_functions.test.js +45 -7
- package/src/node_nav_events.wiring.test.js +6 -0
- package/src/schema_editor_diagram_click.wiring.test.js +28 -0
- package/src/shell_escape_taken.wiring.test.js +34 -0
- package/src/shell_focus_trap.js +47 -1
- package/src/shell_focus_trap.test.js +95 -0
- package/src/shell_modals.js +2 -2
- package/src/shell_stop_overlays.wiring.test.js +143 -0
- package/src/tabulator_edit_internals.test.js +50 -0
- package/src/window_dialog.wiring.test.js +80 -1
- package/src/window_rect_rounding.wiring.test.js +45 -0
|
@@ -111,6 +111,10 @@ import {
|
|
|
111
111
|
|
|
112
112
|
const SRC = dirname(fileURLToPath(import.meta.url));
|
|
113
113
|
|
|
114
|
+
/* The tests that parse every module of the library take a second or
|
|
115
|
+
* more alone, and brushed vitest's 5 s with the whole suite running. */
|
|
116
|
+
const SLOW_SCAN_MS = 30000;
|
|
117
|
+
|
|
114
118
|
const MODULES = readdirSync(SRC)
|
|
115
119
|
.filter((f) => f.endsWith(".js") && !f.endsWith(".test.js"))
|
|
116
120
|
.sort();
|
|
@@ -957,7 +961,11 @@ function table_errors(found, table = I18N_KEY_FUNCTIONS)
|
|
|
957
961
|
* function whose own fallbacks are positions of this one, handed
|
|
958
962
|
* there with it (`{...it}`, not `{id: it.id}`, which drops them). A
|
|
959
963
|
* fallback the code does not show would let the validator skip a key
|
|
960
|
-
* the function asks for.
|
|
964
|
+
* the function asks for. And the other way round: a position the code
|
|
965
|
+
* reads first at EVERY such place is named, or the validator asks for
|
|
966
|
+
* the position where the function never reads it (the toolbar brand's
|
|
967
|
+
* id, behind its aria_label and name, was listed behind its aria_label
|
|
968
|
+
* alone up to gobj-ui 7.26.44).
|
|
961
969
|
*/
|
|
962
970
|
function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
963
971
|
{
|
|
@@ -993,6 +1001,7 @@ function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
|
993
1001
|
return guards;
|
|
994
1002
|
};
|
|
995
1003
|
let modules = [...new Set(table.filter((e) => e.fallbacks).map((e) => e.module))];
|
|
1004
|
+
let read_first = new Map(); // "<name>\n<position>" -> {e, pos, guards read first at every place}
|
|
996
1005
|
for(let module of modules) {
|
|
997
1006
|
let ast = asts(module);
|
|
998
1007
|
let entries = table.filter((e) => e.module === module && e.fallbacks);
|
|
@@ -1028,9 +1037,25 @@ function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
|
1028
1037
|
`is read without reading [${lacking.join(", ")}] first: its \`fallbacks\` in ` +
|
|
1029
1038
|
`I18N_KEY_FUNCTIONS say otherwise`);
|
|
1030
1039
|
}
|
|
1040
|
+
let id = `${e.name}\n${pos}`;
|
|
1041
|
+
let seen = read_first.get(id);
|
|
1042
|
+
read_first.set(id, {e, pos, guards: seen? new Set([...seen.guards].filter((g) => guards.has(g))) : guards});
|
|
1031
1043
|
}
|
|
1032
1044
|
}
|
|
1033
1045
|
}
|
|
1046
|
+
/* ...and names every one the code reads first at EVERY place: one
|
|
1047
|
+
* it leaves out makes the validator ask for the position where the
|
|
1048
|
+
* function never reads it */
|
|
1049
|
+
for(let {e, pos, guards} of read_first.values()) {
|
|
1050
|
+
let parent = pos.slice(0, pos.lastIndexOf(".") + 1);
|
|
1051
|
+
let unnamed = [...guards].filter((g) => !e.fallbacks[pos].includes(g) && e.keys.includes(g)
|
|
1052
|
+
&& g.startsWith(parent) && !g.slice(parent.length).includes("."));
|
|
1053
|
+
if(unnamed.length > 0) {
|
|
1054
|
+
out.push(`${module} ${e.name}() reads [${unnamed.join(", ")}] before [${pos}] wherever it hands ` +
|
|
1055
|
+
`[${pos}] to a place a key is read: its \`fallbacks\` in I18N_KEY_FUNCTIONS do not say so`);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
read_first.clear();
|
|
1034
1059
|
}
|
|
1035
1060
|
return [...new Set(out)];
|
|
1036
1061
|
}
|
|
@@ -1101,11 +1126,11 @@ describe("I18N_KEY_FUNCTIONS: the table", () => {
|
|
|
1101
1126
|
describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
1102
1127
|
test("every function that hands a parameter to a place a key is read, in every module", () => {
|
|
1103
1128
|
expect(forwarders_report(find_forwarders())).toEqual([]);
|
|
1104
|
-
});
|
|
1129
|
+
}, SLOW_SCAN_MS);
|
|
1105
1130
|
|
|
1106
1131
|
test("REV-CLOUD V22: the table is CORRECT -- every entry is a hand-off the library shows", () => {
|
|
1107
1132
|
expect(table_errors(find_forwarders(MODULES, ast_of, []).found)).toEqual([]);
|
|
1108
|
-
});
|
|
1133
|
+
}, SLOW_SCAN_MS);
|
|
1109
1134
|
|
|
1110
1135
|
test("every fallback of the table is one in the code, and the check fails when it is not", () => {
|
|
1111
1136
|
expect(fallback_errors()).toEqual([]);
|
|
@@ -1114,7 +1139,18 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
1114
1139
|
Object.assign({}, e, {fallbacks: {"0.id": ["0.name", "0.aria_label", "0.tooltip"]}}));
|
|
1115
1140
|
expect(fallback_errors(wider)).toEqual([
|
|
1116
1141
|
`${module}:55 card_descriptor() hands [0.id] to a place a key is read without reading [0.tooltip] ` +
|
|
1117
|
-
`first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise
|
|
1142
|
+
`first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise`,
|
|
1143
|
+
`${module} cards_grid_descriptor() reads [0[].tooltip] before [0[].id] wherever it hands [0[].id] ` +
|
|
1144
|
+
`to a place a key is read: its \`fallbacks\` in I18N_KEY_FUNCTIONS do not say so`
|
|
1145
|
+
]);
|
|
1146
|
+
/* A fallback the code reads first and the table leaves out */
|
|
1147
|
+
let narrower = I18N_KEY_FUNCTIONS.map((e) => (e.name !== "card_descriptor")? e :
|
|
1148
|
+
Object.assign({}, e, {fallbacks: {"0.id": ["0.aria_label"]}}));
|
|
1149
|
+
expect(fallback_errors(narrower)).toEqual([
|
|
1150
|
+
`${module}:94 cards_grid_descriptor() hands [0[].id] to a place a key is read without reading ` +
|
|
1151
|
+
`[0[].name] first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise`,
|
|
1152
|
+
`${module} card_descriptor() reads [0.name] before [0.id] wherever it hands [0.id] ` +
|
|
1153
|
+
`to a place a key is read: its \`fallbacks\` in I18N_KEY_FUNCTIONS do not say so`
|
|
1118
1154
|
]);
|
|
1119
1155
|
let code = readFileSync(join(SRC, module), "utf8");
|
|
1120
1156
|
let plain = code.replace('"data-disabled": it.disabled ? "1" : "0",',
|
|
@@ -1190,7 +1226,7 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
1190
1226
|
let unmarked = parse_as(code.replace(/\/\* i18n: data \*\/ /g, ""), module);
|
|
1191
1227
|
expect(find_forwarders([module], () => unmarked).unmarked.map((u) => u.name))
|
|
1192
1228
|
.toContain("ac_register_window");
|
|
1193
|
-
});
|
|
1229
|
+
}, SLOW_SCAN_MS);
|
|
1194
1230
|
});
|
|
1195
1231
|
|
|
1196
1232
|
describe("a `code` is a key where the library makes one", () => {
|
|
@@ -1238,7 +1274,9 @@ describe("the reader never gives up on the library", () => {
|
|
|
1238
1274
|
lines.push(`function f() { return t(K24); }`);
|
|
1239
1275
|
let ast = parse_as(lines.join("\n"), "x.js");
|
|
1240
1276
|
scan_ast(ast, {lib_module: "x.js"});
|
|
1241
|
-
|
|
1277
|
+
/* At the read, and past where it went */
|
|
1278
|
+
expect(gave_up(ast).map((g) => `${g.line} ${g.text} past ${g.past.line} ${g.past.text}`))
|
|
1279
|
+
.toEqual([`26 K24 past 1 "far"`]);
|
|
1242
1280
|
});
|
|
1243
1281
|
});
|
|
1244
1282
|
|
|
@@ -2047,7 +2085,7 @@ describe("REV-CLOUD V22.2: what the search for forwarders sees, and what fails i
|
|
|
2047
2085
|
/* ...as the real table was, before V22: an action label that went
|
|
2048
2086
|
* through a DOM property, a flag that hid an export */
|
|
2049
2087
|
expect(table_errors(found)).toEqual([]);
|
|
2050
|
-
});
|
|
2088
|
+
}, SLOW_SCAN_MS);
|
|
2051
2089
|
});
|
|
2052
2090
|
|
|
2053
2091
|
describe("REV-CLOUD V22.3-4: the data marker hides no key; one notion of a translator", () => {
|
|
@@ -234,6 +234,12 @@ describe("the item a node is showing, clicked again", () => {
|
|
|
234
234
|
expect(tree.priv.navs[0]).not.toBe(nav);
|
|
235
235
|
expect(gobj_read_attr(nav, "$container").parentNode).toBeFalsy();
|
|
236
236
|
|
|
237
|
+
/* Off the page, it is heard no more: in the turn before it
|
|
238
|
+
* goes it was still subscribed, and a click it published was
|
|
239
|
+
* taken as one of the current nav's. */
|
|
240
|
+
gobj_publish_event(nav, "EV_NAV_CLICKED", {route: "/tree/b", item_id: "b"});
|
|
241
|
+
expect(gobj_read_attr(shell, "current_route")).toBe("/tree/a");
|
|
242
|
+
|
|
237
243
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
238
244
|
expect(gobj_is_destroying(nav)).toBe(true);
|
|
239
245
|
expect(gobj_is_destroying(tree.priv.navs[0])).toBe(false);
|
|
@@ -241,6 +241,34 @@ describe("a topic clicked in the editor's drawing", () => {
|
|
|
241
241
|
expect(errors()).toEqual([]);
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
+
/* Between its retirement and its destroy the drawing was still
|
|
245
|
+
* subscribed: what it published in that turn reached the editor
|
|
246
|
+
* as if it were the current one -- a second click, with the
|
|
247
|
+
* editor already in ST_COLUMNS, was "Event NOT DEFINED". */
|
|
248
|
+
test("the drawing it leaves is heard no more, even in the turn before it goes", async () => {
|
|
249
|
+
const remote = gobj_create_service("gap_remote", "C_TEST_REMOTE", {}, yuno);
|
|
250
|
+
gobj_change_state(remote, "ST_SESSION");
|
|
251
|
+
const host = gobj_create("gap_host", "C_TEST_EDITOR_HOST", {}, yuno);
|
|
252
|
+
const editor = gobj_create("gap_editor", "C_YUI_SCHEMA_EDITOR", {
|
|
253
|
+
gobj_remote_yuno: remote,
|
|
254
|
+
treedb_name: "treedb_system_schema",
|
|
255
|
+
base_route: "/schemas"
|
|
256
|
+
}, host);
|
|
257
|
+
gobj_start(editor);
|
|
258
|
+
gobj_send_event(editor, "EV_TRANSPORT_STATE", {connected: true}, host);
|
|
259
|
+
expect(answer_the_load(editor, remote)).toBe(3);
|
|
260
|
+
gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
|
|
261
|
+
const graph = graphs[graphs.length - 1];
|
|
262
|
+
|
|
263
|
+
graph.emit(NodeEvent.CLICK, {target: {id: "users"}});
|
|
264
|
+
expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
|
|
265
|
+
graph.emit(NodeEvent.CLICK, {target: {id: "users"}});
|
|
266
|
+
expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
|
|
267
|
+
await turn();
|
|
268
|
+
expect(graph.destroyed).toBe(true);
|
|
269
|
+
expect(errors()).toEqual([]);
|
|
270
|
+
});
|
|
271
|
+
|
|
244
272
|
test("a drawing left on a stop goes with the stop", async () => {
|
|
245
273
|
const remote = gobj_create_service("stop_remote", "C_TEST_REMOTE", {}, yuno);
|
|
246
274
|
gobj_change_state(remote, "ST_SESSION");
|
|
@@ -38,6 +38,12 @@ const {
|
|
|
38
38
|
const {
|
|
39
39
|
register_c_yui_shell, yui_shell_push_escape, yui_shell_pop_escape,
|
|
40
40
|
} = await import("./c_yui_shell.js");
|
|
41
|
+
const {activate_focus_trap_on} = await import("./shell_focus_trap.js");
|
|
42
|
+
|
|
43
|
+
/* focus() moves document.activeElement, as in a browser. */
|
|
44
|
+
FakeElement.prototype.focus = function() {
|
|
45
|
+
document.activeElement = this;
|
|
46
|
+
};
|
|
41
47
|
|
|
42
48
|
const logged = [];
|
|
43
49
|
let shell = null;
|
|
@@ -139,4 +145,32 @@ describe("the shell's Escape", () => {
|
|
|
139
145
|
$text.remove();
|
|
140
146
|
$editable.remove();
|
|
141
147
|
});
|
|
148
|
+
|
|
149
|
+
/* A cell editor that went with the key took the focus with it, to
|
|
150
|
+
* <body>: a reader was left on the page, outside the dialog. A
|
|
151
|
+
* window takes the focus back (7.26.43); the dialog on top of the
|
|
152
|
+
* shell does now too. */
|
|
153
|
+
test("one that went with a cell editor gives the focus back to the dialog on top", () => {
|
|
154
|
+
const $dialog = document.createElement("div");
|
|
155
|
+
const $cell = document.createElement("div");
|
|
156
|
+
const $editor = document.createElement("input");
|
|
157
|
+
$cell.appendChild($editor);
|
|
158
|
+
$dialog.appendChild($cell);
|
|
159
|
+
document.body.appendChild($dialog);
|
|
160
|
+
const release = activate_focus_trap_on($dialog);
|
|
161
|
+
$editor.focus();
|
|
162
|
+
|
|
163
|
+
$cell.removeChild($editor); /* the editor goes with the key */
|
|
164
|
+
document.activeElement = document.body;
|
|
165
|
+
escape_at($editor);
|
|
166
|
+
expect(closed).toBe(0);
|
|
167
|
+
expect(document.activeElement === $dialog, "the dialog has the focus").toBe(true);
|
|
168
|
+
expect($dialog.getAttribute("tabindex")).toBe("-1");
|
|
169
|
+
|
|
170
|
+
escape_at($dialog);
|
|
171
|
+
expect(closed).toBe(1);
|
|
172
|
+
release();
|
|
173
|
+
yui_shell_pop_escape(shell, close_fn);
|
|
174
|
+
$dialog.remove();
|
|
175
|
+
});
|
|
142
176
|
});
|
package/src/shell_focus_trap.js
CHANGED
|
@@ -24,7 +24,14 @@
|
|
|
24
24
|
* that wrapped to it, did nothing and was prevented -- the
|
|
25
25
|
* keyboard never got into the dialog.
|
|
26
26
|
*
|
|
27
|
-
*
|
|
27
|
+
* A trap whose panel left the document without being released
|
|
28
|
+
* (its owner was torn down with it) is dropped, with its
|
|
29
|
+
* listener, the next time the stack is read, and said. Up to
|
|
30
|
+
* gobj-ui 7.26.45 it stayed the top: every window opened later
|
|
31
|
+
* believed itself under an overlay and took no focus, and a
|
|
32
|
+
* live trap under it no longer heard Tab.
|
|
33
|
+
*
|
|
34
|
+
* No gobj dependency: only gobj-js's logger. The optional
|
|
28
35
|
* second argument lets callers inject a mock document object
|
|
29
36
|
* for unit tests.
|
|
30
37
|
*
|
|
@@ -32,6 +39,8 @@
|
|
|
32
39
|
* All Rights Reserved.
|
|
33
40
|
***********************************************************************/
|
|
34
41
|
|
|
42
|
+
import {log_warning} from "@yuneta/gobj-js";
|
|
43
|
+
|
|
35
44
|
/* Selector matching the elements typically considered focusable.
|
|
36
45
|
* Kept conservative: items that are explicitly removed from the tab
|
|
37
46
|
* order (`tabindex="-1"`) are excluded; everything else is in. */
|
|
@@ -50,6 +59,23 @@ export const FOCUSABLE_SELECTOR =
|
|
|
50
59
|
* topmost trap; the rest short-circuit. */
|
|
51
60
|
const __trap_stack__ = [];
|
|
52
61
|
|
|
62
|
+
/* Drop the traps whose panel is no longer in the document. Only a
|
|
63
|
+
* panel that SAYS so (isConnected === false) is detached: a stub
|
|
64
|
+
* that cannot say is taken as connected. */
|
|
65
|
+
function drop_detached_traps()
|
|
66
|
+
{
|
|
67
|
+
for(let i = __trap_stack__.length - 1; i >= 0; i--) {
|
|
68
|
+
let trap = __trap_stack__[i];
|
|
69
|
+
if(trap.$panel.isConnected !== false) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
__trap_stack__.splice(i, 1);
|
|
73
|
+
trap.detach();
|
|
74
|
+
log_warning("focus trap: its panel left the document without releasing it; " +
|
|
75
|
+
"dropped (the overlay's owner was torn down with it open)");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
53
79
|
|
|
54
80
|
/* Whether `el` is drawn, so focus() on it can take. An element that
|
|
55
81
|
* cannot say (a stub with no getClientRects) is taken as drawn. */
|
|
@@ -100,6 +126,7 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
100
126
|
* Earlier-registered listeners fire too (capture phase),
|
|
101
127
|
* but they short-circuit unless they own the top of the
|
|
102
128
|
* stack. */
|
|
129
|
+
drop_detached_traps();
|
|
103
130
|
if(__trap_stack__[__trap_stack__.length - 1] !== trap) {
|
|
104
131
|
return;
|
|
105
132
|
}
|
|
@@ -123,6 +150,10 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
123
150
|
}
|
|
124
151
|
}
|
|
125
152
|
};
|
|
153
|
+
trap.$panel = $panel;
|
|
154
|
+
trap.detach = function() {
|
|
155
|
+
doc.removeEventListener("keydown", trap, true);
|
|
156
|
+
};
|
|
126
157
|
doc.addEventListener("keydown", trap, true);
|
|
127
158
|
__trap_stack__.push(trap);
|
|
128
159
|
|
|
@@ -149,3 +180,18 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
149
180
|
}
|
|
150
181
|
};
|
|
151
182
|
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
/***************************************************************
|
|
186
|
+
* The panel of the trap that holds the focus now (the top of the
|
|
187
|
+
* stack), or null when none is up. What holds one -- a modal, a
|
|
188
|
+
* dialog, a drawer, a menu -- is drawn above every window that is
|
|
189
|
+
* not modal: such a window that took the focus would take it
|
|
190
|
+
* where it cannot be seen, and the next Tab would give it back.
|
|
191
|
+
***************************************************************/
|
|
192
|
+
export function focus_trap_panel()
|
|
193
|
+
{
|
|
194
|
+
drop_detached_traps();
|
|
195
|
+
let top = __trap_stack__[__trap_stack__.length - 1];
|
|
196
|
+
return top ? top.$panel : null;
|
|
197
|
+
}
|
|
@@ -9,6 +9,7 @@ import { test, expect } from "vitest";
|
|
|
9
9
|
import {
|
|
10
10
|
FOCUSABLE_SELECTOR,
|
|
11
11
|
activate_focus_trap_on,
|
|
12
|
+
focus_trap_panel,
|
|
12
13
|
} from "./shell_focus_trap.js";
|
|
13
14
|
|
|
14
15
|
|
|
@@ -381,3 +382,97 @@ test("Tab and Shift+Tab wrap to the first and last DRAWN controls", () => {
|
|
|
381
382
|
expect(x.focus_calls).toEqual([]);
|
|
382
383
|
release();
|
|
383
384
|
});
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
/***************************************************************
|
|
388
|
+
* A trap whose panel left the document without being released
|
|
389
|
+
* (its owner was torn down with it: a shell destroyed with a
|
|
390
|
+
* drawer or a dialog open) holds the focus of nothing. Kept on
|
|
391
|
+
* the stack it was the "overlay" every later window opened
|
|
392
|
+
* under, so none of them took the focus; and above a live trap
|
|
393
|
+
* it left that one deaf to Tab. It is dropped, with its
|
|
394
|
+
* listener, the first time the stack is read.
|
|
395
|
+
***************************************************************/
|
|
396
|
+
function connected_panel(focusables)
|
|
397
|
+
{
|
|
398
|
+
let panel = make_panel(focusables);
|
|
399
|
+
panel.isConnected = true;
|
|
400
|
+
return panel;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
test("a trap whose panel left the document is no longer the top", () => {
|
|
404
|
+
let a_first = make_focusable("a-first");
|
|
405
|
+
let panel_a = connected_panel([a_first]);
|
|
406
|
+
let panel_b = connected_panel([make_focusable("b-first")]);
|
|
407
|
+
let doc = make_doc(null);
|
|
408
|
+
|
|
409
|
+
let release_a = activate_focus_trap_on(panel_a, doc);
|
|
410
|
+
activate_focus_trap_on(panel_b, doc);
|
|
411
|
+
expect(focus_trap_panel()).toBe(panel_b);
|
|
412
|
+
|
|
413
|
+
panel_b.isConnected = false;
|
|
414
|
+
expect(focus_trap_panel()).toBe(panel_a);
|
|
415
|
+
expect(doc.listeners.length).toBe(1);
|
|
416
|
+
|
|
417
|
+
/* And the live one under it hears Tab again. */
|
|
418
|
+
a_first.focus_calls.length = 0;
|
|
419
|
+
doc.activeElement = make_focusable("outside");
|
|
420
|
+
let prevented = false;
|
|
421
|
+
doc.listeners[0]({
|
|
422
|
+
key: "Tab",
|
|
423
|
+
shiftKey: false,
|
|
424
|
+
preventDefault() {
|
|
425
|
+
prevented = true;
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
expect(prevented).toBe(true);
|
|
429
|
+
expect(a_first.focus_calls).toEqual(["a-first.focus"]);
|
|
430
|
+
|
|
431
|
+
release_a();
|
|
432
|
+
expect(doc.listeners.length).toBe(0);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test("a detached trap above a live one does not leave the live one deaf to Tab", () => {
|
|
436
|
+
let a_first = make_focusable("a-first");
|
|
437
|
+
let panel_a = connected_panel([a_first]);
|
|
438
|
+
let panel_b = connected_panel([make_focusable("b-first")]);
|
|
439
|
+
let doc = make_doc(null);
|
|
440
|
+
|
|
441
|
+
let release_a = activate_focus_trap_on(panel_a, doc);
|
|
442
|
+
activate_focus_trap_on(panel_b, doc);
|
|
443
|
+
panel_b.isConnected = false;
|
|
444
|
+
|
|
445
|
+
/* Nobody asked for the top: the Tab itself finds the stale one. */
|
|
446
|
+
a_first.focus_calls.length = 0;
|
|
447
|
+
doc.activeElement = make_focusable("outside");
|
|
448
|
+
let prevented = false;
|
|
449
|
+
let ev = {
|
|
450
|
+
key: "Tab",
|
|
451
|
+
shiftKey: false,
|
|
452
|
+
preventDefault() {
|
|
453
|
+
prevented = true;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
for(let fn of doc.listeners.slice()) {
|
|
457
|
+
fn(ev);
|
|
458
|
+
}
|
|
459
|
+
expect(prevented).toBe(true);
|
|
460
|
+
expect(a_first.focus_calls).toEqual(["a-first.focus"]);
|
|
461
|
+
expect(doc.listeners.length).toBe(1);
|
|
462
|
+
|
|
463
|
+
release_a();
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test("the release of a dropped trap still gives the focus back", () => {
|
|
467
|
+
let prev = make_focusable("prev");
|
|
468
|
+
let panel = connected_panel([make_focusable("first")]);
|
|
469
|
+
let doc = make_doc(prev);
|
|
470
|
+
|
|
471
|
+
let release = activate_focus_trap_on(panel, doc);
|
|
472
|
+
panel.isConnected = false;
|
|
473
|
+
expect(focus_trap_panel()).not.toBe(panel);
|
|
474
|
+
expect(doc.listeners.length).toBe(0);
|
|
475
|
+
|
|
476
|
+
release();
|
|
477
|
+
expect(prev.focus_calls).toEqual(["prev.focus"]);
|
|
478
|
+
});
|
package/src/shell_modals.js
CHANGED
|
@@ -518,7 +518,7 @@ export function yui_shell_show_modal(shell, content, opts)
|
|
|
518
518
|
};
|
|
519
519
|
|
|
520
520
|
escape_handler = request_close;
|
|
521
|
-
yui_shell_push_escape(shell, "modal", request_close);
|
|
521
|
+
yui_shell_push_escape(shell, "modal", request_close, do_close);
|
|
522
522
|
/* Browser Back closes the top-most modal (see overlay history in
|
|
523
523
|
* c_yui_shell.js). Null when history integration is off. */
|
|
524
524
|
overlay = yui_shell_register_overlay(shell, on_back);
|
|
@@ -693,7 +693,7 @@ function build_dialog(shell, message, buttons, opts)
|
|
|
693
693
|
};
|
|
694
694
|
close_fn = () => close(dismiss_value);
|
|
695
695
|
|
|
696
|
-
yui_shell_push_escape(shell, "modal", close_fn);
|
|
696
|
+
yui_shell_push_escape(shell, "modal", close_fn, close_fn);
|
|
697
697
|
/* Browser Back dismisses the dialog with the safe-default value,
|
|
698
698
|
* exactly like Escape. */
|
|
699
699
|
overlay = yui_shell_register_overlay(shell, close_fn);
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* shell_stop_overlays.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A shell stopped with an overlay up -- a logout, a session cut
|
|
5
|
+
* with the drawer or a dialog open -- closes the overlay first,
|
|
6
|
+
* as if it had been dismissed, and releases its focus trap. Up
|
|
7
|
+
* to gobj-ui 7.26.45 only the toolbar dropdown was closed: the
|
|
8
|
+
* trap of a drawer, a modal or a question stayed on the stack,
|
|
9
|
+
* every window opened afterwards believed itself under an
|
|
10
|
+
* overlay and took no focus, and the question's promise never
|
|
11
|
+
* settled.
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2026, ArtGins.
|
|
14
|
+
* All Rights Reserved.
|
|
15
|
+
***********************************************************************/
|
|
16
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
17
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
18
|
+
|
|
19
|
+
install_dom_double();
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
SDATA_END, gclass_create,
|
|
23
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop, gobj_destroy,
|
|
24
|
+
set_log_callback,
|
|
25
|
+
} = await import("@yuneta/gobj-js");
|
|
26
|
+
const {register_c_yui_shell, yui_shell_open_drawer} = await import("./c_yui_shell.js");
|
|
27
|
+
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
28
|
+
const {yui_shell_show_modal, yui_shell_confirm_yesno} = await import("./shell_modals.js");
|
|
29
|
+
const {focus_trap_panel} = await import("./shell_focus_trap.js");
|
|
30
|
+
|
|
31
|
+
const logged = [];
|
|
32
|
+
let yuno = null;
|
|
33
|
+
let seq = 0;
|
|
34
|
+
|
|
35
|
+
beforeAll(async () => {
|
|
36
|
+
const i18next = (await import("i18next")).default;
|
|
37
|
+
await i18next.init({lng: "en", resources: {}});
|
|
38
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
39
|
+
set_log_callback((level, msg) => {
|
|
40
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
41
|
+
});
|
|
42
|
+
gclass_create("C_TEST_STOP_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
43
|
+
register_c_yui_nav();
|
|
44
|
+
register_c_yui_shell();
|
|
45
|
+
yuno = gobj_create_yuno("stop_overlays_yuno", "C_TEST_STOP_HOST", {});
|
|
46
|
+
gobj_start(yuno);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
logged.length = 0;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
function errors()
|
|
54
|
+
{
|
|
55
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function settle()
|
|
59
|
+
{
|
|
60
|
+
return new Promise(resolve => setTimeout(resolve, 0));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function make_shell()
|
|
64
|
+
{
|
|
65
|
+
seq++;
|
|
66
|
+
const app = gobj_create(`sapp${seq}`, "C_TEST_STOP_HOST", {}, yuno);
|
|
67
|
+
gobj_start(app);
|
|
68
|
+
const shell = gobj_create(`sshell${seq}`, "C_YUI_SHELL", {
|
|
69
|
+
config: {
|
|
70
|
+
shell: {},
|
|
71
|
+
menu: {
|
|
72
|
+
quick: {
|
|
73
|
+
render: {overlay: "drawer"},
|
|
74
|
+
items: [{id: "home", name: "home", route: "/home"}]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
subscriber: app
|
|
79
|
+
}, app);
|
|
80
|
+
gobj_start(shell);
|
|
81
|
+
logged.length = 0; /* the shell's own start: no route table here */
|
|
82
|
+
return shell;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe("a shell stopped with an overlay up", () => {
|
|
86
|
+
test("the drawer, a modal and a question close, and no trap is left", async () => {
|
|
87
|
+
const shell = make_shell();
|
|
88
|
+
|
|
89
|
+
yui_shell_open_drawer(shell, "quick");
|
|
90
|
+
const $drawer = document.querySelector(".is-active");
|
|
91
|
+
expect($drawer).not.toBe(null);
|
|
92
|
+
expect(focus_trap_panel()).not.toBe(null);
|
|
93
|
+
|
|
94
|
+
let modal_closed = 0;
|
|
95
|
+
yui_shell_show_modal(shell, "the sheet", {
|
|
96
|
+
dialog: true,
|
|
97
|
+
logical_class: "TEST_STOP_SHEET",
|
|
98
|
+
title: "settings",
|
|
99
|
+
/* A guard is for the reader's dismissals, not for the
|
|
100
|
+
* shell going away. */
|
|
101
|
+
before_close: () => false,
|
|
102
|
+
on_close: () => {
|
|
103
|
+
modal_closed++;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
let answer = null;
|
|
107
|
+
yui_shell_confirm_yesno(shell, "really?").then((a) => {
|
|
108
|
+
answer = a;
|
|
109
|
+
});
|
|
110
|
+
expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(1);
|
|
111
|
+
expect(document.querySelectorAll(".CONFIRM").length).toBe(1);
|
|
112
|
+
|
|
113
|
+
gobj_stop(shell);
|
|
114
|
+
gobj_destroy(shell);
|
|
115
|
+
await settle();
|
|
116
|
+
|
|
117
|
+
expect(focus_trap_panel()).toBe(null);
|
|
118
|
+
expect(modal_closed).toBe(1);
|
|
119
|
+
expect(answer).toBe(false); /* the answer Escape gives */
|
|
120
|
+
expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(0);
|
|
121
|
+
expect(document.querySelectorAll(".CONFIRM").length).toBe(0);
|
|
122
|
+
expect($drawer.classList.contains("is-active")).toBe(false);
|
|
123
|
+
expect(errors()).toEqual([]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("destroyed without a stop, it closes them too", async () => {
|
|
127
|
+
const shell = make_shell();
|
|
128
|
+
|
|
129
|
+
yui_shell_open_drawer(shell, "quick");
|
|
130
|
+
yui_shell_show_modal(shell, "the sheet", {
|
|
131
|
+
dialog: true, logical_class: "TEST_STOP_SHEET", title: "settings"
|
|
132
|
+
});
|
|
133
|
+
expect(focus_trap_panel()).not.toBe(null);
|
|
134
|
+
|
|
135
|
+
gobj_destroy(shell);
|
|
136
|
+
await settle();
|
|
137
|
+
|
|
138
|
+
expect(focus_trap_panel()).toBe(null);
|
|
139
|
+
expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(0);
|
|
140
|
+
/* gobj-js says what the test did; nothing else is said. */
|
|
141
|
+
expect(errors().filter((m) => !m.includes("Destroying a RUNNING gobj"))).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* tabulator_edit_internals.test.js
|
|
3
|
+
*
|
|
4
|
+
* C_YUI_FORM closes a table's open cell editor before it wipes
|
|
5
|
+
* the rows (close_table_editor): Tabulator 6.6.0 closes it while
|
|
6
|
+
* it wipes them and throws. Tabulator has no public way to ask
|
|
7
|
+
* which cell is being edited, so the form reads its edit module:
|
|
8
|
+
* `table.modules.edit`, its `currentCell` and its `cancelEdit()`.
|
|
9
|
+
* This pins those names against the Tabulator INSTALLED: an
|
|
10
|
+
* upgrade that renames them fails here, not in a reader's
|
|
11
|
+
* reload. (The form also says so in the log when they are
|
|
12
|
+
* missing.)
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026, ArtGins.
|
|
15
|
+
* All Rights Reserved.
|
|
16
|
+
***********************************************************************/
|
|
17
|
+
import {test, expect} from "vitest";
|
|
18
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
19
|
+
|
|
20
|
+
install_dom_double(); /* Tabulator reads `document` when it loads */
|
|
21
|
+
|
|
22
|
+
const {EditModule} = await import("tabulator-tables");
|
|
23
|
+
|
|
24
|
+
/* Just what the module's constructor touches. */
|
|
25
|
+
function stub_table()
|
|
26
|
+
{
|
|
27
|
+
const registry = {register() {}};
|
|
28
|
+
return {
|
|
29
|
+
optionsList: registry,
|
|
30
|
+
columnManager: {optionsList: registry},
|
|
31
|
+
componentFunctionBinder: {bind() {}},
|
|
32
|
+
eventBus: {subscribe() {}},
|
|
33
|
+
externalEvents: {subscribe() {}},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* A table keeps each module under its `moduleName`. */
|
|
38
|
+
test("the edit module is `modules.edit`", () => {
|
|
39
|
+
expect(EditModule.moduleName).toBe("edit");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("it holds the cell being edited in `currentCell`, false when none", () => {
|
|
43
|
+
const edit = new EditModule(stub_table());
|
|
44
|
+
expect(Object.prototype.hasOwnProperty.call(edit, "currentCell")).toBe(true);
|
|
45
|
+
expect(edit.currentCell).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("and closes it with `cancelEdit()`", () => {
|
|
49
|
+
expect(typeof EditModule.prototype.cancelEdit).toBe("function");
|
|
50
|
+
});
|