@yuneta/gobj-ui 7.26.44 → 7.26.45
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 +83 -16
- package/dist/gobj-ui.cjs.js +103 -20
- package/dist/gobj-ui.es.js +103 -21
- package/index.js +1 -0
- package/package.json +1 -1
- package/scripts/check-markup-strings.mjs +4 -1
- package/scripts/validate-locales.mjs +531 -155
- package/src/c_yui_form.js +47 -32
- package/src/c_yui_node.js +3 -1
- package/src/c_yui_schema_editor.js +3 -0
- package/src/c_yui_shell.js +55 -1
- package/src/c_yui_window.js +30 -5
- package/src/form_table_edits_ask.wiring.test.js +11 -2
- package/src/form_table_rows.wiring.test.js +120 -8
- package/src/i18n_key_functions.js +2 -2
- package/src/i18n_key_functions.test.js +37 -3
- 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 +15 -0
- package/src/window_dialog.wiring.test.js +80 -1
- package/src/window_rect_rounding.wiring.test.js +22 -0
|
@@ -957,7 +957,11 @@ function table_errors(found, table = I18N_KEY_FUNCTIONS)
|
|
|
957
957
|
* function whose own fallbacks are positions of this one, handed
|
|
958
958
|
* there with it (`{...it}`, not `{id: it.id}`, which drops them). A
|
|
959
959
|
* fallback the code does not show would let the validator skip a key
|
|
960
|
-
* the function asks for.
|
|
960
|
+
* the function asks for. And the other way round: a position the code
|
|
961
|
+
* reads first at EVERY such place is named, or the validator asks for
|
|
962
|
+
* the position where the function never reads it (the toolbar brand's
|
|
963
|
+
* id, behind its aria_label and name, was listed behind its aria_label
|
|
964
|
+
* alone up to gobj-ui 7.26.44).
|
|
961
965
|
*/
|
|
962
966
|
function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
963
967
|
{
|
|
@@ -993,6 +997,7 @@ function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
|
993
997
|
return guards;
|
|
994
998
|
};
|
|
995
999
|
let modules = [...new Set(table.filter((e) => e.fallbacks).map((e) => e.module))];
|
|
1000
|
+
let read_first = new Map(); // "<name>\n<position>" -> {e, pos, guards read first at every place}
|
|
996
1001
|
for(let module of modules) {
|
|
997
1002
|
let ast = asts(module);
|
|
998
1003
|
let entries = table.filter((e) => e.module === module && e.fallbacks);
|
|
@@ -1028,9 +1033,25 @@ function fallback_errors(table = I18N_KEY_FUNCTIONS, asts = ast_of)
|
|
|
1028
1033
|
`is read without reading [${lacking.join(", ")}] first: its \`fallbacks\` in ` +
|
|
1029
1034
|
`I18N_KEY_FUNCTIONS say otherwise`);
|
|
1030
1035
|
}
|
|
1036
|
+
let id = `${e.name}\n${pos}`;
|
|
1037
|
+
let seen = read_first.get(id);
|
|
1038
|
+
read_first.set(id, {e, pos, guards: seen? new Set([...seen.guards].filter((g) => guards.has(g))) : guards});
|
|
1031
1039
|
}
|
|
1032
1040
|
}
|
|
1033
1041
|
}
|
|
1042
|
+
/* ...and names every one the code reads first at EVERY place: one
|
|
1043
|
+
* it leaves out makes the validator ask for the position where the
|
|
1044
|
+
* function never reads it */
|
|
1045
|
+
for(let {e, pos, guards} of read_first.values()) {
|
|
1046
|
+
let parent = pos.slice(0, pos.lastIndexOf(".") + 1);
|
|
1047
|
+
let unnamed = [...guards].filter((g) => !e.fallbacks[pos].includes(g) && e.keys.includes(g)
|
|
1048
|
+
&& g.startsWith(parent) && !g.slice(parent.length).includes("."));
|
|
1049
|
+
if(unnamed.length > 0) {
|
|
1050
|
+
out.push(`${module} ${e.name}() reads [${unnamed.join(", ")}] before [${pos}] wherever it hands ` +
|
|
1051
|
+
`[${pos}] to a place a key is read: its \`fallbacks\` in I18N_KEY_FUNCTIONS do not say so`);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
read_first.clear();
|
|
1034
1055
|
}
|
|
1035
1056
|
return [...new Set(out)];
|
|
1036
1057
|
}
|
|
@@ -1114,7 +1135,18 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
1114
1135
|
Object.assign({}, e, {fallbacks: {"0.id": ["0.name", "0.aria_label", "0.tooltip"]}}));
|
|
1115
1136
|
expect(fallback_errors(wider)).toEqual([
|
|
1116
1137
|
`${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
|
|
1138
|
+
`first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise`,
|
|
1139
|
+
`${module} cards_grid_descriptor() reads [0[].tooltip] before [0[].id] wherever it hands [0[].id] ` +
|
|
1140
|
+
`to a place a key is read: its \`fallbacks\` in I18N_KEY_FUNCTIONS do not say so`
|
|
1141
|
+
]);
|
|
1142
|
+
/* A fallback the code reads first and the table leaves out */
|
|
1143
|
+
let narrower = I18N_KEY_FUNCTIONS.map((e) => (e.name !== "card_descriptor")? e :
|
|
1144
|
+
Object.assign({}, e, {fallbacks: {"0.id": ["0.aria_label"]}}));
|
|
1145
|
+
expect(fallback_errors(narrower)).toEqual([
|
|
1146
|
+
`${module}:94 cards_grid_descriptor() hands [0[].id] to a place a key is read without reading ` +
|
|
1147
|
+
`[0[].name] first: its \`fallbacks\` in I18N_KEY_FUNCTIONS say otherwise`,
|
|
1148
|
+
`${module} card_descriptor() reads [0.name] before [0.id] wherever it hands [0.id] ` +
|
|
1149
|
+
`to a place a key is read: its \`fallbacks\` in I18N_KEY_FUNCTIONS do not say so`
|
|
1118
1150
|
]);
|
|
1119
1151
|
let code = readFileSync(join(SRC, module), "utf8");
|
|
1120
1152
|
let plain = code.replace('"data-disabled": it.disabled ? "1" : "0",',
|
|
@@ -1238,7 +1270,9 @@ describe("the reader never gives up on the library", () => {
|
|
|
1238
1270
|
lines.push(`function f() { return t(K24); }`);
|
|
1239
1271
|
let ast = parse_as(lines.join("\n"), "x.js");
|
|
1240
1272
|
scan_ast(ast, {lib_module: "x.js"});
|
|
1241
|
-
|
|
1273
|
+
/* At the read, and past where it went */
|
|
1274
|
+
expect(gave_up(ast).map((g) => `${g.line} ${g.text} past ${g.past.line} ${g.past.text}`))
|
|
1275
|
+
.toEqual([`26 K24 past 1 "far"`]);
|
|
1242
1276
|
});
|
|
1243
1277
|
});
|
|
1244
1278
|
|
|
@@ -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
|
@@ -123,6 +123,7 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
|
+
trap.$panel = $panel;
|
|
126
127
|
doc.addEventListener("keydown", trap, true);
|
|
127
128
|
__trap_stack__.push(trap);
|
|
128
129
|
|
|
@@ -149,3 +150,17 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
149
150
|
}
|
|
150
151
|
};
|
|
151
152
|
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
/***************************************************************
|
|
156
|
+
* The panel of the trap that holds the focus now (the top of the
|
|
157
|
+
* stack), or null when none is up. What holds one -- a modal, a
|
|
158
|
+
* dialog, a drawer, a menu -- is drawn above every window that is
|
|
159
|
+
* not modal: such a window that took the focus would take it
|
|
160
|
+
* where it cannot be seen, and the next Tab would give it back.
|
|
161
|
+
***************************************************************/
|
|
162
|
+
export function focus_trap_panel()
|
|
163
|
+
{
|
|
164
|
+
let top = __trap_stack__[__trap_stack__.length - 1];
|
|
165
|
+
return top ? top.$panel : null;
|
|
166
|
+
}
|
|
@@ -52,7 +52,7 @@ const {
|
|
|
52
52
|
gobj_start, gobj_read_attr, gobj_is_destroying, gobj_send_event,
|
|
53
53
|
set_log_callback,
|
|
54
54
|
} = await import("@yuneta/gobj-js");
|
|
55
|
-
const {register_c_yui_shell} = await import("./c_yui_shell.js");
|
|
55
|
+
const {register_c_yui_shell, yui_shell_push_escape, yui_shell_pop_escape} = await import("./c_yui_shell.js");
|
|
56
56
|
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
57
57
|
const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
|
|
58
58
|
|
|
@@ -338,6 +338,41 @@ describe("a window the reader did not open", () => {
|
|
|
338
338
|
$of(win).querySelector(".WINDOW_CLOSE").click();
|
|
339
339
|
});
|
|
340
340
|
});
|
|
341
|
+
|
|
342
|
+
/* Every overlay that holds the focus (a modal, a dialog, a drawer,
|
|
343
|
+
* a menu) is drawn above the window layer: a window opened under
|
|
344
|
+
* one took the focus where it could not be seen, and the next Tab
|
|
345
|
+
* gave it back to the overlay. */
|
|
346
|
+
test("one opened under a modal leaves the focus in the modal; it is there when the modal goes", () => {
|
|
347
|
+
const $opener = document.createElement("button");
|
|
348
|
+
document.body.appendChild($opener);
|
|
349
|
+
$opener.focus();
|
|
350
|
+
with_activation(true, () => {
|
|
351
|
+
const modal = open_window({modal: true});
|
|
352
|
+
const $field = $of(modal).querySelector(".TEST_FIRST");
|
|
353
|
+
$field.focus();
|
|
354
|
+
const win = open_window();
|
|
355
|
+
expect(document.activeElement === $field, "the focus stays in the modal").toBe(true);
|
|
356
|
+
expect($of(win).parentNode === shell.priv.window_layer ||
|
|
357
|
+
$of(win).parentNode === shell.priv.layers.overlay, "under the modal, in the window layer").toBe(true);
|
|
358
|
+
|
|
359
|
+
$of(modal).querySelector(".WINDOW_CLOSE").click();
|
|
360
|
+
expect(document.activeElement === $opener, "the focus is back on the opener").toBe(true);
|
|
361
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
362
|
+
$of(win).querySelector(".WINDOW_CLOSE").click();
|
|
363
|
+
});
|
|
364
|
+
$opener.remove();
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("one opened in a modal's own body takes the focus", () => {
|
|
368
|
+
with_activation(true, () => {
|
|
369
|
+
const modal = open_window({modal: true});
|
|
370
|
+
const win = open_window({$parent: $of(modal).querySelector(".TEST_BODY")});
|
|
371
|
+
expect(document.activeElement === $of(win), "the focus is in the window").toBe(true);
|
|
372
|
+
$of(win).querySelector(".WINDOW_CLOSE").click();
|
|
373
|
+
$of(modal).querySelector(".WINDOW_CLOSE").click();
|
|
374
|
+
});
|
|
375
|
+
});
|
|
341
376
|
});
|
|
342
377
|
|
|
343
378
|
describe("Escape", () => {
|
|
@@ -413,6 +448,50 @@ describe("Escape", () => {
|
|
|
413
448
|
});
|
|
414
449
|
});
|
|
415
450
|
|
|
451
|
+
describe("Escape, with an overlay of the shell open", () => {
|
|
452
|
+
/* The window stops the key at its container, so the shell's own
|
|
453
|
+
* Escape (an overlay stack, LIFO, heard on `window`) never saw
|
|
454
|
+
* it: with the focus in the window, an overlay opened AFTER it --
|
|
455
|
+
* the toolbar's user menu -- stayed open, and the window under
|
|
456
|
+
* it closed. */
|
|
457
|
+
test("one opened after the window is closed first; the window is next", () => {
|
|
458
|
+
const win = open_window();
|
|
459
|
+
const $input = $of(win).querySelector(".TEST_FIRST");
|
|
460
|
+
let overlay_open = true;
|
|
461
|
+
const close_overlay = () => {
|
|
462
|
+
overlay_open = false;
|
|
463
|
+
yui_shell_pop_escape(shell, close_overlay);
|
|
464
|
+
};
|
|
465
|
+
yui_shell_push_escape(shell, "popup", close_overlay);
|
|
466
|
+
$input.focus();
|
|
467
|
+
|
|
468
|
+
let ev = press($input, "Escape");
|
|
469
|
+
expect(overlay_open, "the overlay closed").toBe(false);
|
|
470
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
471
|
+
expect(ev.defaultPrevented).toBe(true);
|
|
472
|
+
|
|
473
|
+
press($input, "Escape");
|
|
474
|
+
expect(gobj_is_destroying(win)).toBe(true);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test("one opened before the window stays: the window is closed first", () => {
|
|
478
|
+
let overlay_open = true;
|
|
479
|
+
const close_overlay = () => {
|
|
480
|
+
overlay_open = false;
|
|
481
|
+
yui_shell_pop_escape(shell, close_overlay);
|
|
482
|
+
};
|
|
483
|
+
yui_shell_push_escape(shell, "popup", close_overlay);
|
|
484
|
+
const win = open_window();
|
|
485
|
+
const $input = $of(win).querySelector(".TEST_FIRST");
|
|
486
|
+
$input.focus();
|
|
487
|
+
|
|
488
|
+
press($input, "Escape");
|
|
489
|
+
expect(gobj_is_destroying(win)).toBe(true);
|
|
490
|
+
expect(overlay_open, "the overlay is still open").toBe(true);
|
|
491
|
+
close_overlay();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
416
495
|
describe("a modal window", () => {
|
|
417
496
|
test("blocks the rest: a backdrop in the dialog layer, aria-modal, no dock", () => {
|
|
418
497
|
const dock = gobj_create_service("dlg_dock", "C_YUI_WINDOW_MANAGER", {}, app);
|
|
@@ -94,6 +94,28 @@ describe("the saved rect of a window is whole pixels", () => {
|
|
|
94
94
|
expect(errors()).toEqual([]);
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
test("an entry that is not a rect is said, and the window opens where it would", () => {
|
|
98
|
+
window.localStorage.setItem("rect_bad-rect", JSON.stringify({x: 10, y: "20", width: 400}));
|
|
99
|
+
logged.length = 0;
|
|
100
|
+
const win = gobj_create_service("rect_bad", "C_YUI_WINDOW", {
|
|
101
|
+
header: "bad", body: ["div", {}, "bad"], auto_save_size_and_position: true,
|
|
102
|
+
x: 5, y: 6, width: 300, height: 200,
|
|
103
|
+
}, yuno);
|
|
104
|
+
gobj_start(win);
|
|
105
|
+
expect(attrs_rect(win)).toEqual({x: 5, y: 6, width: 300, height: 200});
|
|
106
|
+
const warned = logged.filter((l) => l.level === "warning" && l.msg.includes("rect_bad-rect"));
|
|
107
|
+
expect(warned.length, "the bad entry is said").toBe(1);
|
|
108
|
+
expect(errors()).toEqual([]);
|
|
109
|
+
|
|
110
|
+
/* No entry at all is nothing to say. */
|
|
111
|
+
logged.length = 0;
|
|
112
|
+
const fresh = gobj_create_service("rect_none", "C_YUI_WINDOW", {
|
|
113
|
+
header: "none", body: ["div", {}, "none"], auto_save_size_and_position: true,
|
|
114
|
+
}, yuno);
|
|
115
|
+
gobj_start(fresh);
|
|
116
|
+
expect(logged.filter((l) => l.msg.includes("rect_none-rect"))).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
|
|
97
119
|
test("a move saves whole pixels, and writes them into the attrs", () => {
|
|
98
120
|
const win = gobj_create_service("rect_move", "C_YUI_WINDOW", {
|
|
99
121
|
header: "move", body: ["div", {}, "move"], auto_save_size_and_position: true,
|