@yuneta/gobj-ui 7.26.42 → 7.26.43

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.
Files changed (47) hide show
  1. package/README.md +227 -36
  2. package/dist/gobj-ui.cjs.js +768 -191
  3. package/dist/gobj-ui.es.js +768 -191
  4. package/package.json +1 -1
  5. package/scripts/validate-locales.mjs +355 -63
  6. package/src/c_yui_form.js +261 -154
  7. package/src/c_yui_node.js +51 -7
  8. package/src/c_yui_schema_editor.js +49 -3
  9. package/src/c_yui_shell.css +4 -1
  10. package/src/c_yui_shell.js +28 -2
  11. package/src/c_yui_window.js +373 -62
  12. package/src/c_yui_window_manager.js +74 -2
  13. package/src/escape_taken.js +58 -0
  14. package/src/form_close_asks_for_edits.wiring.test.js +6 -3
  15. package/src/form_json_editor_names.js +3 -1
  16. package/src/form_json_editor_names.wiring.test.js +8 -4
  17. package/src/form_json_expand.wiring.test.js +6 -3
  18. package/src/form_json_field.wiring.test.js +8 -4
  19. package/src/form_label_i18n.wiring.test.js +10 -5
  20. package/src/form_table_edits_ask.wiring.test.js +18 -8
  21. package/src/form_table_rearm.wiring.test.js +13 -5
  22. package/src/form_table_rows.wiring.test.js +489 -0
  23. package/src/form_table_validator.wiring.test.js +8 -4
  24. package/src/form_template_field.wiring.test.js +6 -3
  25. package/src/g6_long_press_clock.test.js +8 -3
  26. package/src/i18n_key_functions.js +63 -25
  27. package/src/i18n_key_functions.test.js +230 -8
  28. package/src/modal_guard_back.wiring.test.js +53 -0
  29. package/src/named_controls.wiring.test.js +53 -13
  30. package/src/node_nav_events.wiring.test.js +93 -1
  31. package/src/schema_editor_diagram_click.wiring.test.js +277 -0
  32. package/src/shell_dialog_names.wiring.test.js +149 -0
  33. package/src/shell_escape_taken.wiring.test.js +142 -0
  34. package/src/shell_focus_trap.js +30 -2
  35. package/src/shell_focus_trap.test.js +90 -6
  36. package/src/shell_modals.js +90 -19
  37. package/src/table_editor_name.wiring.test.js +10 -5
  38. package/src/treedb_column_title.wiring.test.js +8 -4
  39. package/src/treedb_graph_writes.wiring.test.js +6 -3
  40. package/src/treedb_json_drill.wiring.test.js +6 -3
  41. package/src/uplot_add_serie.test.js +6 -3
  42. package/src/uplot_ink.test.js +8 -4
  43. package/src/window_dialog.wiring.test.js +486 -0
  44. package/src/window_dock_band.wiring.test.js +189 -0
  45. package/src/window_rect_rounding.wiring.test.js +121 -0
  46. package/src/yui_tabulator_i18n.js +31 -1
  47. package/src/yui_tabulator_i18n.test.js +46 -0
@@ -12,6 +12,13 @@
12
12
  * of a root that is off the path landed on ST_OFF, which declared
13
13
  * none of the three.
14
14
  *
15
+ * And a click on the item a node is already showing navigates to the
16
+ * same route in the same turn (no hash change, so no hashchange):
17
+ * the node renders again INSIDE the nav's publication of
18
+ * EV_NAV_CLICKED, and the render destroyed that nav under it (the
19
+ * ERROR "Destroying a gobj while its tree is publishing" of
20
+ * gobj-js 7.26.22). The navs a render leaves go on the next turn.
21
+ *
15
22
  * Driven through the real gclasses (C_YUI_SHELL, C_YUI_NODE,
16
23
  * C_YUI_NAV) on a document double: each event is published by the
17
24
  * real nav the node created.
@@ -31,7 +38,8 @@ const {
31
38
  gobj_current_state, gobj_change_state,
32
39
  set_log_callback,
33
40
  } = await import("@yuneta/gobj-js");
34
- const {register_c_yui_shell} = await import("./c_yui_shell.js");
41
+ const {gobj_is_destroying} = await import("@yuneta/gobj-js");
42
+ const {register_c_yui_shell, yui_shell_navigate} = await import("./c_yui_shell.js");
35
43
  const {register_c_yui_nav} = await import("./c_yui_nav.js");
36
44
  const {register_c_yui_node} = await import("./c_yui_node.js");
37
45
 
@@ -148,3 +156,87 @@ describe("the events of a C_YUI_NAV reach its C_YUI_NODE", () => {
148
156
  expect(closed.map((c) => c.item_id)).toEqual(["b"]);
149
157
  });
150
158
  });
159
+
160
+ describe("the path a node draws is named by the node", () => {
161
+
162
+ /* A root that draws the PATH (`projection.path`), with or without a
163
+ * label, on the path to its child "a" */
164
+ function build_path(kw)
165
+ {
166
+ const name = `n${++seq}`;
167
+ const app = gobj_create(`${name}_app`, "C_TEST_APP", {}, yuno);
168
+ gobj_start(app);
169
+ const shell = gobj_create(`${name}_shell`, "C_YUI_SHELL",
170
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
171
+ gobj_start(shell);
172
+ const tree = gobj_create_pure_child(`${name}_tree`, "C_YUI_NODE", Object.assign({
173
+ node_id: "root",
174
+ base_route: "/tree",
175
+ projection: {index: {layout: "cards"}, path: {layout: "submenu"}},
176
+ children: [{id: "a", label: "A"}, {id: "b", label: "B"}]
177
+ }, kw), shell);
178
+ gobj_start(tree);
179
+ gobj_send_event(tree, "EV_ROUTE_CHANGED", {base: "/tree", subpath: "a"}, shell);
180
+ return tree.priv.navs.find((nav) => gobj_read_attr(nav, "menu_id").startsWith("node.path."));
181
+ }
182
+
183
+ /* A "submenu" heads the nav with its nav_label, else its menu_id, as a
184
+ * KEY: a node with no label read "node.path./tree" there (up to
185
+ * 7.26.42), a key no locale can hold, where every other nav of the
186
+ * node is named `label || node_id` */
187
+ test("by its label, else by its node_id -- never by the menu_id", () => {
188
+ const unlabelled = build_path({});
189
+ expect(unlabelled).toBeTruthy();
190
+ expect(gobj_read_attr(unlabelled, "nav_label")).toBe("root");
191
+ const labelled = build_path({label: "the tree"});
192
+ expect(gobj_read_attr(labelled, "nav_label")).toBe("the tree");
193
+ });
194
+ });
195
+
196
+ describe("the item a node is showing, clicked again", () => {
197
+
198
+ test("renders the node again; the nav that published the click goes on the next turn", async () => {
199
+ const name = `n${++seq}`;
200
+ const shell = gobj_create(`${name}_shell`, "C_YUI_SHELL", {
201
+ config: {
202
+ shell: {
203
+ zones: {center: {host: "stage.main"}},
204
+ stages: {main: {zone: "center", default_route: "/tree"}}
205
+ },
206
+ menu: {primary: {items: [
207
+ {id: "tree", name: "tree", route: "/tree", target: {
208
+ stage: "main", gclass: "C_YUI_NODE", lifecycle: "keep_alive",
209
+ name: `${name}_tree`,
210
+ kw: {
211
+ node_id: "root",
212
+ base_route: "/tree",
213
+ projection: {index: {layout: "tabs"}, chrome: {layout: "tabs"}},
214
+ children: [{id: "a", label: "A"}, {id: "b", label: "B"}]
215
+ }
216
+ }}
217
+ ]}}
218
+ },
219
+ use_hash: false
220
+ }, yuno);
221
+ gobj_start(shell);
222
+ yui_shell_navigate(shell, "/tree/a");
223
+ const tree = shell.priv.stages.main.items["/tree"];
224
+ expect(gobj_current_state(tree)).toBe("ST_CHILD");
225
+ const nav = tree.priv.navs[0];
226
+ expect(nav).toBeTruthy();
227
+ logged.length = 0;
228
+
229
+ /* What the nav's click handler does with the active item. */
230
+ gobj_publish_event(nav, "EV_NAV_CLICKED", {route: "/tree/a", item_id: "a"});
231
+
232
+ expect(gobj_is_destroying(nav)).toBe(false);
233
+ expect(tree.priv.navs.length).toBe(1);
234
+ expect(tree.priv.navs[0]).not.toBe(nav);
235
+ expect(gobj_read_attr(nav, "$container").parentNode).toBeFalsy();
236
+
237
+ await new Promise((resolve) => setTimeout(resolve, 0));
238
+ expect(gobj_is_destroying(nav)).toBe(true);
239
+ expect(gobj_is_destroying(tree.priv.navs[0])).toBe(false);
240
+ expect(errors()).toEqual([]);
241
+ });
242
+ });
@@ -0,0 +1,277 @@
1
+ /***********************************************************************
2
+ * schema_editor_diagram_click.wiring.test.js
3
+ *
4
+ * A click on a topic of C_YUI_SCHEMA_EDITOR's drawing opens that
5
+ * topic's columns -- and leaves the drawing, which the editor takes
6
+ * down. It took it down INSIDE the click: the drawing
7
+ * (C_YUI_TREEDB_SCHEMA) publishes EV_NODE_CLICK from the action of
8
+ * G6's own node-click event, and the editor's answer stopped and
9
+ * destroyed it there -- the gobj under its own publication, and its
10
+ * G6 graph under G6's own event dispatch, which goes on when the
11
+ * handler returns.
12
+ *
13
+ * A subscriber must not destroy the tree of its publisher
14
+ * synchronously (the C kernel says it since 7.26.10, gobj-js since
15
+ * 7.26.22: "Destroying a gobj while its tree is publishing"). The
16
+ * screen changes at once, as before; the drawing it leaves is
17
+ * detached at once and destroyed on the next turn.
18
+ *
19
+ * Driven through the real C_YUI_SCHEMA_EDITOR and the real
20
+ * C_YUI_TREEDB_SCHEMA, on a document double, with a G6 double that
21
+ * remembers whether it was destroyed while it was dispatching an
22
+ * event of its own.
23
+ *
24
+ * Copyright (c) 2026, ArtGins.
25
+ * All Rights Reserved.
26
+ ***********************************************************************/
27
+ import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
28
+ import {install_dom_double} from "../test/dom_double.js";
29
+
30
+ install_dom_double();
31
+
32
+ if(typeof globalThis.ResizeObserver === "undefined") {
33
+ globalThis.ResizeObserver = class {
34
+ observe() {
35
+ }
36
+ unobserve() {
37
+ }
38
+ disconnect() {
39
+ }
40
+ };
41
+ }
42
+
43
+ vi.mock("./shell_modals.js", () => ({
44
+ yui_shell_show_error: () => ({close() {}}),
45
+ yui_shell_show_info: () => ({close() {}}),
46
+ yui_shell_show_modal: () => ({close() {}}),
47
+ yui_shell_confirm_danger: () => new Promise(() => {}),
48
+ }));
49
+
50
+ const graphs = vi.hoisted(() => []);
51
+ vi.mock("@antv/g6", async (importOriginal) => {
52
+ const real = await importOriginal();
53
+ class FakeGraph {
54
+ constructor(options) {
55
+ this.options = options;
56
+ this.handlers = {};
57
+ this.emitting = 0;
58
+ this.destroyed = false;
59
+ this.destroyed_while_emitting = false;
60
+ graphs.push(this);
61
+ return new Proxy(this, {
62
+ get: (t, k) => (k in t) ? t[k] : (() => undefined),
63
+ });
64
+ }
65
+ render() {
66
+ return Promise.resolve();
67
+ }
68
+ on(name, fn) {
69
+ (this.handlers[name] = this.handlers[name] || []).push(fn);
70
+ }
71
+ emit(name, ev) {
72
+ this.emitting++;
73
+ try {
74
+ for(const fn of (this.handlers[name] || [])) {
75
+ fn(ev);
76
+ }
77
+ } finally {
78
+ this.emitting--;
79
+ }
80
+ }
81
+ getZoom() {
82
+ return 1;
83
+ }
84
+ getData() {
85
+ return {nodes: [], edges: [], combos: []};
86
+ }
87
+ getNodeData() {
88
+ return [];
89
+ }
90
+ getEdgeData() {
91
+ return [];
92
+ }
93
+ getPlugins() {
94
+ return [];
95
+ }
96
+ getBehaviors() {
97
+ return [];
98
+ }
99
+ getOptions() {
100
+ return {behaviors: []};
101
+ }
102
+ getCanvas() {
103
+ return {getLayers: () => ({}), getContainer: () => null};
104
+ }
105
+ draw() {
106
+ return Promise.resolve();
107
+ }
108
+ destroy() {
109
+ this.destroyed = true;
110
+ if(this.emitting > 0) {
111
+ this.destroyed_while_emitting = true;
112
+ }
113
+ }
114
+ }
115
+ return {...real, Graph: FakeGraph};
116
+ });
117
+
118
+ const {
119
+ SDATA_END,
120
+ gclass_create,
121
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
122
+ gobj_start, gobj_send_event, gobj_read_attr,
123
+ gobj_change_state, gobj_current_state, gobj_is_destroying,
124
+ set_log_callback,
125
+ } = await import("@yuneta/gobj-js");
126
+ const {NodeEvent} = await import("@antv/g6");
127
+ const {register_c_yui_treedb_schema} = await import("./c_yui_treedb_schema.js");
128
+ const {register_c_yui_schema_editor} = await import("./c_yui_schema_editor.js");
129
+
130
+ const logged = [];
131
+ const commands = [];
132
+
133
+ const RECORDS = {
134
+ treedbs: [{id: "db", schema_version: 4}],
135
+ topics: [
136
+ {id: "db.users", value: "users", order: 1, pkey: "id", topic_version: 2,
137
+ treedbs: ["treedbs^db^topics"]},
138
+ ],
139
+ cols: [
140
+ {id: "db.users.id", value: "id", order: 1, type: "string",
141
+ flag: ["persistent", "required"], topics: ["topics^db.users^cols"]},
142
+ ],
143
+ };
144
+
145
+ let yuno = null;
146
+
147
+ beforeAll(async () => {
148
+ const i18next = (await import("i18next")).default;
149
+ await i18next.init({lng: "en", resources: {en: {translation: {}}}});
150
+ gobj_start_up(null, null, null, null, null, null, null);
151
+ set_log_callback((level, msg) => {
152
+ logged.push({level: String(level), msg: String(msg)});
153
+ });
154
+ gclass_create("C_TEST_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
155
+ /* The editor's host hears what the editor publishes. */
156
+ const EDITOR_OUT = ["EV_POSITION_CHANGED", "EV_RECORD_WRITTEN", "EV_SCHEMA_CHECKED"];
157
+ gclass_create(
158
+ "C_TEST_EDITOR_HOST",
159
+ EDITOR_OUT.map((ev) => [ev, 0]),
160
+ [["ST_IDLE", EDITOR_OUT.map((ev) => [ev, () => 0, null])]],
161
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
162
+ );
163
+ gclass_create(
164
+ "C_TEST_REMOTE",
165
+ [],
166
+ [["ST_DISCONNECTED", []], ["ST_SESSION", []]],
167
+ {mt_command_parser: (gobj, command, kw, src) => {
168
+ commands.push({command, kw, src});
169
+ return null;
170
+ }},
171
+ 0, [SDATA_END()], {}, 0, 0, 0, 0
172
+ );
173
+ register_c_yui_treedb_schema();
174
+ register_c_yui_schema_editor();
175
+ yuno = gobj_create_yuno("diagram_click_yuno", "C_TEST_HOST", {});
176
+ gobj_start(yuno);
177
+ });
178
+
179
+ beforeEach(() => {
180
+ logged.length = 0;
181
+ commands.length = 0;
182
+ });
183
+
184
+ function answer_the_load(editor, remote)
185
+ {
186
+ const asked = commands.splice(0).filter((c) => c.command === "nodes");
187
+ for(const c of asked) {
188
+ gobj_send_event(editor, "EV_MT_COMMAND_ANSWER", {
189
+ result: 0,
190
+ comment: "",
191
+ data: JSON.parse(JSON.stringify(RECORDS[c.kw.topic_name])),
192
+ __md_iev__: {command_stack: [{command: c.command, kw: c.kw}]}
193
+ }, remote);
194
+ }
195
+ return asked.length;
196
+ }
197
+
198
+ function errors()
199
+ {
200
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
201
+ }
202
+
203
+ const turn = () => new Promise((resolve) => setTimeout(resolve, 0));
204
+
205
+ describe("a topic clicked in the editor's drawing", () => {
206
+
207
+ test("opens its columns at once; the drawing goes on the next turn, not under the click", async () => {
208
+ const remote = gobj_create_service("click_remote", "C_TEST_REMOTE", {}, yuno);
209
+ gobj_change_state(remote, "ST_SESSION");
210
+ const host = gobj_create("click_host", "C_TEST_EDITOR_HOST", {}, yuno);
211
+ const editor = gobj_create("click_editor", "C_YUI_SCHEMA_EDITOR", {
212
+ gobj_remote_yuno: remote,
213
+ treedb_name: "treedb_system_schema",
214
+ base_route: "/schemas"
215
+ }, host);
216
+ gobj_start(editor);
217
+ gobj_send_event(editor, "EV_TRANSPORT_STATE", {connected: true}, host);
218
+ expect(answer_the_load(editor, remote)).toBe(3);
219
+ gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
220
+ expect(gobj_current_state(editor)).toBe("ST_DIAGRAM");
221
+
222
+ const diagram = editor.priv.diagram_gobj;
223
+ expect(diagram).toBeTruthy();
224
+ const graph = graphs[graphs.length - 1];
225
+ expect(graph).toBeTruthy();
226
+
227
+ graph.emit(NodeEvent.CLICK, {target: {id: "users"}});
228
+
229
+ /* The screen changed in the click... */
230
+ expect(gobj_current_state(editor)).toBe("ST_COLUMNS");
231
+ const $container = gobj_read_attr(editor, "$container");
232
+ expect($container.querySelector(".SCHEMA_BODY .SCHEMA_COLUMNS")).toBeTruthy();
233
+ /* ...and the drawing was not taken down under it. */
234
+ expect(graph.destroyed_while_emitting).toBe(false);
235
+ expect(gobj_is_destroying(diagram)).toBe(false);
236
+
237
+ await turn();
238
+ expect(gobj_is_destroying(diagram)).toBe(true);
239
+ expect(graph.destroyed).toBe(true);
240
+ expect(editor.priv.diagram_gobj).toBe(null);
241
+ expect(errors()).toEqual([]);
242
+ });
243
+
244
+ test("a drawing left on a stop goes with the stop", async () => {
245
+ const remote = gobj_create_service("stop_remote", "C_TEST_REMOTE", {}, yuno);
246
+ gobj_change_state(remote, "ST_SESSION");
247
+ const host = gobj_create("stop_host", "C_TEST_EDITOR_HOST", {}, yuno);
248
+ const editor = gobj_create("stop_editor", "C_YUI_SCHEMA_EDITOR", {
249
+ gobj_remote_yuno: remote,
250
+ treedb_name: "treedb_system_schema",
251
+ base_route: "/schemas"
252
+ }, host);
253
+ gobj_start(editor);
254
+ gobj_send_event(editor, "EV_TRANSPORT_STATE", {connected: true}, host);
255
+ answer_the_load(editor, remote);
256
+ gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
257
+ const diagram = editor.priv.diagram_gobj;
258
+ const graph = graphs[graphs.length - 1];
259
+
260
+ graph.emit(NodeEvent.CLICK, {target: {id: "users"}});
261
+ expect(gobj_is_destroying(diagram)).toBe(false);
262
+
263
+ /* Stopped before the next turn: nothing of the drawing is left
264
+ * for a turn that finds the editor stopped. */
265
+ gobj_send_event(editor, "EV_SHOW", {subpath: "db/diagram"}, host);
266
+ const second = editor.priv.diagram_gobj;
267
+ expect(second).toBeTruthy();
268
+ expect(second).not.toBe(diagram);
269
+ const {gobj_stop} = await import("@yuneta/gobj-js");
270
+ gobj_stop(editor);
271
+ expect(gobj_is_destroying(diagram)).toBe(true);
272
+ expect(gobj_is_destroying(second)).toBe(true);
273
+
274
+ await turn();
275
+ expect(errors()).toEqual([]);
276
+ });
277
+ });
@@ -0,0 +1,149 @@
1
+ /***********************************************************************
2
+ * shell_dialog_names.wiring.test.js
3
+ *
4
+ * Every dialog of the shell has a NAME for a reader: a modal is
5
+ * named by its title (the two halves, `title_prefix` and `title`,
6
+ * so the name changes language with it), or by its message when a
7
+ * plain one has nothing else; a question is named by its title and
8
+ * described by its message, or named by its message when it has
9
+ * no title. Up to 7.26.42 they were `role="dialog"` with no name:
10
+ * a reader said "dialog" and nothing else.
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+ import {describe, test, expect, beforeAll, beforeEach} from "vitest";
16
+ import {install_dom_double} from "../test/dom_double.js";
17
+
18
+ install_dom_double();
19
+
20
+ const {
21
+ SDATA_END, gclass_create,
22
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_start,
23
+ set_log_callback,
24
+ } = await import("@yuneta/gobj-js");
25
+ const {register_c_yui_shell} = await import("./c_yui_shell.js");
26
+ const {
27
+ yui_shell_show_modal,
28
+ yui_shell_confirm_yesno,
29
+ } = await import("./shell_modals.js");
30
+
31
+ const logged = [];
32
+ let shell = null;
33
+
34
+ /* The nodes a reader computes the name (or the description) of
35
+ * `$dialog` from: those its `attr` lists, all in its own tree. */
36
+ function named_by($dialog, attr)
37
+ {
38
+ const ids = ($dialog.getAttribute(attr) || "").split(/\s+/).filter(Boolean);
39
+ return ids.map((id) => {
40
+ const $n = $dialog.querySelector(`#${id}`);
41
+ expect(!!$n, `${attr} points at '${id}', which is not in the dialog`).toBe(true);
42
+ return $n;
43
+ });
44
+ }
45
+
46
+ function warnings()
47
+ {
48
+ return logged.filter((l) => l.level === "warning").map((l) => l.msg);
49
+ }
50
+
51
+ beforeAll(async () => {
52
+ const i18next = (await import("i18next")).default;
53
+ await i18next.init({lng: "en", resources: {}});
54
+ gobj_start_up(null, null, null, null, null, null, null);
55
+ set_log_callback((level, msg) => {
56
+ logged.push({level: String(level), msg: String(msg)});
57
+ });
58
+ gclass_create("C_TEST_NAMES_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
59
+ register_c_yui_shell();
60
+ const yuno = gobj_create_yuno("names_yuno", "C_TEST_NAMES_HOST", {});
61
+ gobj_start(yuno);
62
+ shell = gobj_create("nshell", "C_YUI_SHELL",
63
+ {config: {shell: {}}, default_route: "/home"}, yuno);
64
+ gobj_start(shell);
65
+ });
66
+
67
+ beforeEach(() => {
68
+ logged.length = 0;
69
+ });
70
+
71
+ describe("a modal of the shell is named", () => {
72
+ test("by the two halves of its title, the kind half carrying its key", () => {
73
+ const $box = document.createElement("div");
74
+ const handle = yui_shell_show_modal(shell, $box,
75
+ {dialog: true, title: "keys", title_prefix: "raw_tracks", logical_class: "NAMED_SHEET"});
76
+ const $modal = document.querySelector(".NAMED_SHEET");
77
+
78
+ const [$prefix, $kind] = named_by($modal, "aria-labelledby");
79
+ expect($prefix.classList.contains("MODAL_TITLE_PREFIX")).toBe(true);
80
+ expect($prefix.textContent).toBe("raw_tracks");
81
+ expect($kind.classList.contains("MODAL_TITLE_KIND")).toBe(true);
82
+ expect($kind.dataset.i18n || $kind.getAttribute("i18n")).toBe("keys");
83
+ expect(named_by($modal, "aria-labelledby").length).toBe(2);
84
+ /* A form or a document is no description: read it as it is. */
85
+ expect($modal.getAttribute("aria-describedby")).toBe(null);
86
+ handle.close();
87
+ });
88
+
89
+ test("with a title and no dialog chrome, by a title only a reader sees", () => {
90
+ const $box = document.createElement("div");
91
+ const handle = yui_shell_show_modal(shell, $box,
92
+ {title: "preferences", logical_class: "PLAIN_SHEET"});
93
+ const $modal = document.querySelector(".PLAIN_SHEET");
94
+
95
+ const [$kind] = named_by($modal, "aria-labelledby");
96
+ expect($kind.textContent).toBe("preferences");
97
+ expect($kind.closest(".MODAL_TITLE").classList.contains("is-sr-only")).toBe(true);
98
+ handle.close();
99
+ });
100
+
101
+ test("with a message and no title, by its message", () => {
102
+ const handle = yui_shell_show_modal(shell, "nothing to show",
103
+ {logical_class: "MESSAGE_SHEET"});
104
+ const $modal = document.querySelector(".MESSAGE_SHEET");
105
+
106
+ const [$msg] = named_by($modal, "aria-labelledby");
107
+ expect($msg.textContent).toBe("nothing to show");
108
+ handle.close();
109
+ });
110
+
111
+ test("with nothing to be named by: said", () => {
112
+ const handle = yui_shell_show_modal(shell, document.createElement("div"),
113
+ {logical_class: "NAMELESS_SHEET"});
114
+ const $modal = document.querySelector(".NAMELESS_SHEET");
115
+ expect($modal.getAttribute("aria-labelledby")).toBe(null);
116
+ expect(warnings().some((w) => w.includes("no name"))).toBe(true);
117
+ handle.close();
118
+ });
119
+ });
120
+
121
+ describe("a question of the shell", () => {
122
+ test("is named by its title and described by its message", async () => {
123
+ const answer = yui_shell_confirm_yesno(shell, "all changes will be lost",
124
+ {title: "unsaved changes", logical_class: "TITLED_QUESTION"});
125
+ const $q = document.querySelector(".TITLED_QUESTION");
126
+
127
+ const [$title] = named_by($q, "aria-labelledby");
128
+ expect($title.classList.contains("CONFIRM_TITLE")).toBe(true);
129
+ expect($title.dataset.i18n || $title.getAttribute("i18n")).toBe("unsaved changes");
130
+ const [$body] = named_by($q, "aria-describedby");
131
+ expect($body.textContent).toBe("all changes will be lost");
132
+
133
+ $q.querySelector(".CONFIRM_CLOSE").click();
134
+ expect(await answer).toBe(false);
135
+ });
136
+
137
+ test("with no title, is named by its message", async () => {
138
+ const answer = yui_shell_confirm_yesno(shell, "delete it?",
139
+ {logical_class: "BARE_QUESTION"});
140
+ const $q = document.querySelector(".BARE_QUESTION");
141
+
142
+ const [$body] = named_by($q, "aria-labelledby");
143
+ expect($body.textContent).toBe("delete it?");
144
+ expect($q.getAttribute("aria-describedby")).toBe(null);
145
+
146
+ $q.querySelector(".CONFIRM_CLOSE").click();
147
+ await answer;
148
+ });
149
+ });
@@ -0,0 +1,142 @@
1
+ /***********************************************************************
2
+ * shell_escape_taken.wiring.test.js
3
+ *
4
+ * The shell's Escape closes the overlay on top of its chain (a
5
+ * dialog, a popup, the drawer) -- but not an Escape that what it
6
+ * was typed in took first. Up to 7.26.42 it closed the dialog for
7
+ * ANY Escape: one typed in a cell of a table being edited
8
+ * cancelled the edit (Tabulator removes the box) and closed the
9
+ * whole dialog with it.
10
+ *
11
+ * Copyright (c) 2026, ArtGins.
12
+ * All Rights Reserved.
13
+ ***********************************************************************/
14
+ import {describe, test, expect, beforeAll, beforeEach} from "vitest";
15
+ import {install_dom_double, FakeElement} from "../test/dom_double.js";
16
+
17
+ install_dom_double();
18
+
19
+ Object.defineProperty(FakeElement.prototype, "isConnected", {
20
+ configurable: true,
21
+ get() {
22
+ let n = this;
23
+ while(n) {
24
+ if(n === document.documentElement) {
25
+ return true;
26
+ }
27
+ n = n.parentNode;
28
+ }
29
+ return false;
30
+ }
31
+ });
32
+
33
+ const {
34
+ SDATA_END, gclass_create,
35
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_start,
36
+ set_log_callback,
37
+ } = await import("@yuneta/gobj-js");
38
+ const {
39
+ register_c_yui_shell, yui_shell_push_escape, yui_shell_pop_escape,
40
+ } = await import("./c_yui_shell.js");
41
+
42
+ const logged = [];
43
+ let shell = null;
44
+ let closed = 0;
45
+ const close_fn = () => {
46
+ closed++;
47
+ };
48
+
49
+ /* An Escape as the window hears it, after what it was typed in had
50
+ * its turn (`init` says what that did). */
51
+ function escape_at(target, init)
52
+ {
53
+ const ev = Object.assign({
54
+ type: "keydown", key: "Escape", target: target,
55
+ defaultPrevented: false, isComposing: false,
56
+ preventDefault() {
57
+ this.defaultPrevented = true;
58
+ },
59
+ stopPropagation() {
60
+ }
61
+ }, init || {});
62
+ window.dispatchEvent(ev);
63
+ return ev;
64
+ }
65
+
66
+ beforeAll(async () => {
67
+ const i18next = (await import("i18next")).default;
68
+ await i18next.init({lng: "en", resources: {}});
69
+ gobj_start_up(null, null, null, null, null, null, null);
70
+ set_log_callback((level, msg) => {
71
+ logged.push({level: String(level), msg: String(msg)});
72
+ });
73
+ gclass_create("C_TEST_ESC_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
74
+ register_c_yui_shell();
75
+ const yuno = gobj_create_yuno("esc_yuno", "C_TEST_ESC_HOST", {});
76
+ gobj_start(yuno);
77
+ shell = gobj_create("eshell", "C_YUI_SHELL",
78
+ {config: {shell: {}}, default_route: "/home"}, yuno);
79
+ gobj_start(shell);
80
+ });
81
+
82
+ beforeEach(() => {
83
+ closed = 0;
84
+ yui_shell_push_escape(shell, "modal", close_fn);
85
+ });
86
+
87
+ describe("the shell's Escape", () => {
88
+ test("closes the overlay on top", () => {
89
+ const $button = document.createElement("button");
90
+ document.body.appendChild($button);
91
+ const ev = escape_at($button);
92
+ expect(closed).toBe(1);
93
+ expect(ev.defaultPrevented).toBe(true);
94
+ yui_shell_pop_escape(shell, close_fn);
95
+ $button.remove();
96
+ });
97
+
98
+ test("not one a widget used, nor one composing", () => {
99
+ const $input = document.createElement("input");
100
+ document.body.appendChild($input);
101
+ escape_at($input, {defaultPrevented: true});
102
+ escape_at($input, {isComposing: true});
103
+ expect(closed).toBe(0);
104
+ yui_shell_pop_escape(shell, close_fn);
105
+ $input.remove();
106
+ });
107
+
108
+ test("not one that went with what it was typed in (a cell editor)", () => {
109
+ const $editor = document.createElement("input"); /* removed: detached */
110
+ escape_at($editor);
111
+ expect(closed).toBe(0);
112
+ yui_shell_pop_escape(shell, close_fn);
113
+ });
114
+
115
+ test("not one that clears a search box, but one in an empty search box", () => {
116
+ const $search = document.createElement("input");
117
+ $search.setAttribute("type", "search");
118
+ $search.value = "abc";
119
+ document.body.appendChild($search);
120
+ escape_at($search);
121
+ expect(closed).toBe(0);
122
+ $search.value = "";
123
+ escape_at($search);
124
+ expect(closed).toBe(1);
125
+ yui_shell_pop_escape(shell, close_fn);
126
+ $search.remove();
127
+ });
128
+
129
+ test("not one typed in a text editor", () => {
130
+ const $text = document.createElement("textarea");
131
+ const $editable = document.createElement("div");
132
+ $editable.isContentEditable = true;
133
+ document.body.appendChild($text);
134
+ document.body.appendChild($editable);
135
+ escape_at($text);
136
+ escape_at($editable);
137
+ expect(closed).toBe(0);
138
+ yui_shell_pop_escape(shell, close_fn);
139
+ $text.remove();
140
+ $editable.remove();
141
+ });
142
+ });