@yuneta/gobj-ui 7.26.42 → 7.26.44

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 +770 -192
  3. package/dist/gobj-ui.es.js +770 -192
  4. package/package.json +2 -2
  5. package/scripts/validate-locales.mjs +355 -63
  6. package/src/c_yui_form.js +268 -155
  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 +533 -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
@@ -0,0 +1,486 @@
1
+ /***********************************************************************
2
+ * window_dialog.wiring.test.js
3
+ *
4
+ * A C_YUI_WINDOW is a DIALOG for the keyboard and for a reader:
5
+ *
6
+ * - it says so (`role="dialog"`), and it has a name: its title,
7
+ * by `aria-labelledby`, so the name changes language with it;
8
+ * - it takes the focus when it starts (`focus`: an element, a
9
+ * selector, a number; by default the window itself) and gives
10
+ * it back to where it came from when it goes;
11
+ * - Escape closes it (`keyboard`), the way its ✕ does: through
12
+ * EV_CLOSE_WINDOW, so EV_WINDOW_TO_CLOSE can still veto or
13
+ * ask -- but not an Escape that something inside took first;
14
+ * - a `modal` one blocks the rest of the app: a backdrop in the
15
+ * shell's dialog layer, `aria-modal`, Tab kept inside.
16
+ *
17
+ * Up to 7.26.42 `focus`, `modal` and `keyboard` were declared and
18
+ * did nothing: a window took no focus, closed with no key, kept
19
+ * nothing in, and had no role.
20
+ *
21
+ * Copyright (c) 2026, ArtGins.
22
+ * All Rights Reserved.
23
+ ***********************************************************************/
24
+ import {describe, test, expect, beforeAll, beforeEach, afterEach} from "vitest";
25
+ import {install_dom_double, FakeElement} from "../test/dom_double.js";
26
+
27
+ install_dom_double();
28
+
29
+ /* focus() moves document.activeElement, as in a browser. */
30
+ FakeElement.prototype.focus = function() {
31
+ document.activeElement = this;
32
+ };
33
+
34
+ /* In the document or not, as a browser answers it. */
35
+ Object.defineProperty(FakeElement.prototype, "isConnected", {
36
+ configurable: true,
37
+ get() {
38
+ let n = this;
39
+ while(n) {
40
+ if(n === document.documentElement) {
41
+ return true;
42
+ }
43
+ n = n.parentNode;
44
+ }
45
+ return false;
46
+ }
47
+ });
48
+
49
+ const {
50
+ SDATA_END, gclass_create, gclass_find_by_name,
51
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
52
+ gobj_start, gobj_read_attr, gobj_is_destroying, gobj_send_event,
53
+ set_log_callback,
54
+ } = await import("@yuneta/gobj-js");
55
+ const {register_c_yui_shell} = await import("./c_yui_shell.js");
56
+ const {register_c_yui_window} = await import("./c_yui_window.js");
57
+ const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
58
+
59
+ const logged = [];
60
+ const actions_run = [];
61
+ let veto = false;
62
+ let yuno = null;
63
+ let app = null;
64
+ let shell = null;
65
+ let seq = 0;
66
+
67
+ /* A keydown that walks up from its target, as a browser bubbles it,
68
+ * to the document and the window -- along the path it had when it
69
+ * was dispatched, as a browser does, even if the target leaves the
70
+ * document on the way. Something inside may take it first
71
+ * (`taken(ev)` runs at the target, as a widget's own listener
72
+ * does). */
73
+ function press(target, key, init, taken)
74
+ {
75
+ const ev = Object.assign({
76
+ type: "keydown", key: key, target: target, bubbles: true,
77
+ defaultPrevented: false, stopped: false, isComposing: false,
78
+ shiftKey: false,
79
+ preventDefault() {
80
+ this.defaultPrevented = true;
81
+ },
82
+ stopPropagation() {
83
+ this.stopped = true;
84
+ },
85
+ stopImmediatePropagation() {
86
+ this.stopped = true;
87
+ }
88
+ }, init || {});
89
+ const path = [];
90
+ for(let n = target; n; n = n.parentNode) {
91
+ path.push(n);
92
+ }
93
+ if(taken) {
94
+ taken(ev);
95
+ }
96
+ for(const n of path) {
97
+ if(ev.stopped) {
98
+ break;
99
+ }
100
+ ev.currentTarget = n;
101
+ for(const fn of [...((n.listeners && n.listeners.keydown) || [])]) {
102
+ fn.call(n, ev);
103
+ }
104
+ }
105
+ if(!ev.stopped) {
106
+ document.dispatchEvent(ev);
107
+ }
108
+ if(!ev.stopped) {
109
+ window.dispatchEvent(ev);
110
+ }
111
+ return ev;
112
+ }
113
+
114
+ function errors()
115
+ {
116
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
117
+ }
118
+
119
+ function warnings()
120
+ {
121
+ return logged.filter((l) => l.level === "warning").map((l) => l.msg);
122
+ }
123
+
124
+ /* A window of the app, started: what a host does. */
125
+ function open_window(attrs)
126
+ {
127
+ const name = `dwin${++seq}`;
128
+ const win = gobj_create_service(name, "C_YUI_WINDOW", Object.assign({
129
+ subscriber: app,
130
+ title: "demo window",
131
+ body: ["div", {class: "TEST_BODY"}, [
132
+ ["input", {class: "TEST_FIRST", type: "text"}],
133
+ ["textarea", {class: "TEST_TEXT"}],
134
+ ["button", {class: "TEST_BUTTON", type: "button"}, "ok"],
135
+ ]],
136
+ }, attrs || {}), app);
137
+ gobj_start(win);
138
+ return win;
139
+ }
140
+
141
+ function $of(win)
142
+ {
143
+ return gobj_read_attr(win, "$container");
144
+ }
145
+
146
+ beforeAll(async () => {
147
+ const i18next = (await import("i18next")).default;
148
+ await i18next.init({lng: "en", resources: {}});
149
+ gobj_start_up(null, null, null, null, null, null, null);
150
+ set_log_callback((level, msg) => {
151
+ logged.push({level: String(level), msg: String(msg)});
152
+ });
153
+ gclass_create("C_TEST_DLG_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
154
+ gclass_create(
155
+ "C_TEST_DLG_APP",
156
+ [["EV_WINDOW_TO_CLOSE", 0]],
157
+ [["ST_IDLE", [
158
+ ["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
159
+ kw.abort_close = veto;
160
+ return 0;
161
+ }, null]
162
+ ]]],
163
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
164
+ );
165
+ register_c_yui_shell();
166
+ register_c_yui_window();
167
+ register_c_yui_window_manager();
168
+
169
+ /* Which actions of the window ran, by event: the machine's view. */
170
+ const gclass = gclass_find_by_name("C_YUI_WINDOW", false);
171
+ for(const st of gclass.dl_states) {
172
+ for(const a of st.dl_actions) {
173
+ const action = a.action;
174
+ a.action = (gobj, event, kw, src) => {
175
+ actions_run.push({event: event, kw: JSON.parse(JSON.stringify(kw || {}))});
176
+ return action(gobj, event, kw, src);
177
+ };
178
+ }
179
+ }
180
+
181
+ yuno = gobj_create_yuno("dlg_yuno", "C_TEST_DLG_HOST", {});
182
+ gobj_start(yuno);
183
+ app = gobj_create("dapp", "C_TEST_DLG_APP", {}, yuno);
184
+ gobj_start(app);
185
+ shell = gobj_create("dshell", "C_YUI_SHELL",
186
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
187
+ gobj_start(shell);
188
+ });
189
+
190
+ beforeEach(() => {
191
+ logged.length = 0;
192
+ actions_run.length = 0;
193
+ veto = false;
194
+ document.activeElement = document.body;
195
+ });
196
+
197
+ /* Nothing but what a test asks for is logged as an error. */
198
+ afterEach(() => {
199
+ expect(errors()).toEqual([]);
200
+ });
201
+
202
+ describe("a window is a dialog, with a name", () => {
203
+ test("role=dialog, named by its title, focusable itself", () => {
204
+ const win = open_window({title_prefix: "#7"});
205
+ const $c = $of(win);
206
+
207
+ expect($c.getAttribute("role")).toBe("dialog");
208
+ expect($c.getAttribute("aria-modal")).toBe(null);
209
+ expect($c.getAttribute("tabindex")).toBe("-1");
210
+
211
+ /* Named by its two halves, the data and the kind: a reader
212
+ * joins them with a space, and the kind half carries its key,
213
+ * so the name changes language. */
214
+ const ids = ($c.getAttribute("aria-labelledby") || "").split(" ").filter(Boolean);
215
+ expect(ids.length).toBe(2);
216
+ const $prefix = $c.querySelector(`#${ids[0]}`);
217
+ const $kind = $c.querySelector(`#${ids[1]}`);
218
+ expect(!!$prefix && !!$kind, "both halves exist").toBe(true);
219
+ expect($prefix.classList.contains("WINDOW_TITLE_PREFIX")).toBe(true);
220
+ expect($prefix.textContent).toBe("#7");
221
+ expect($kind.classList.contains("WINDOW_TITLE_KIND")).toBe(true);
222
+ expect($kind.getAttribute("i18n") || $kind.dataset.i18n).toBe("demo window");
223
+ expect(!!$kind.closest(".WINDOW_HEADER"), "the halves of the title bar").toBe(true);
224
+ });
225
+
226
+ test("with a header of its own, the name is still its title", () => {
227
+ const win = open_window({header: ["span", {class: "TEST_TOOLBAR"}, "tools"]});
228
+ const $c = $of(win);
229
+
230
+ const id = $c.getAttribute("aria-labelledby");
231
+ expect(id).toBeTruthy();
232
+ const $kind = $c.querySelector(`#${id}`);
233
+ expect(!!$kind, "the title node exists").toBe(true);
234
+ expect($kind.textContent).toBe("demo window");
235
+ expect($kind.closest(".WINDOW_TITLE").classList.contains("is-sr-only")).toBe(true);
236
+ expect(!!$c.querySelector(".TEST_TOOLBAR"), "the header of its own is there").toBe(true);
237
+ });
238
+ });
239
+
240
+ describe("the focus", () => {
241
+ test("goes to the window when it starts, and back to the opener when it closes", () => {
242
+ const $opener = document.createElement("button");
243
+ document.body.appendChild($opener);
244
+ $opener.focus();
245
+
246
+ const win = open_window();
247
+ expect(document.activeElement === $of(win), "the focus is on $of(win)").toBe(true);
248
+
249
+ $of(win).querySelector(".WINDOW_CLOSE").click();
250
+ expect(gobj_is_destroying(win)).toBe(true);
251
+ expect(document.activeElement === $opener, "the focus is on $opener").toBe(true);
252
+ $opener.remove();
253
+ });
254
+
255
+ test("`focus` picks what takes it: a selector, a number, an element", () => {
256
+ const w1 = open_window({focus: ".TEST_BUTTON"});
257
+ expect(document.activeElement === $of(w1).querySelector(".TEST_BUTTON"), "the focus is on the button").toBe(true);
258
+
259
+ const w2 = open_window({focus: 1});
260
+ expect(document.activeElement === $of(w2).querySelector(".TEST_TEXT"), "the focus is on the second control").toBe(true);
261
+
262
+ const $own = document.createElement("input");
263
+ const w3 = open_window({body: $own, focus: $own});
264
+ expect(document.activeElement === $own, "the focus is on $own").toBe(true);
265
+
266
+ for(const w of [w1, w2, w3]) {
267
+ $of(w).querySelector(".WINDOW_CLOSE").click();
268
+ }
269
+ });
270
+
271
+ test("a `focus` that names nothing is said, and the window takes it", () => {
272
+ const win = open_window({focus: ".NOT_THERE"});
273
+ expect(document.activeElement === $of(win), "the focus is on $of(win)").toBe(true);
274
+ expect(warnings().some((w) => w.includes(".NOT_THERE"))).toBe(true);
275
+ $of(win).querySelector(".WINDOW_CLOSE").click();
276
+ });
277
+
278
+ test("a window that closes while the focus is elsewhere leaves it there", () => {
279
+ const $opener = document.createElement("button");
280
+ const $elsewhere = document.createElement("input");
281
+ document.body.appendChild($opener);
282
+ document.body.appendChild($elsewhere);
283
+ $opener.focus();
284
+
285
+ const win = open_window();
286
+ $elsewhere.focus();
287
+ gobj_send_event(win, "EV_CLOSE_WINDOW", {}, win);
288
+ expect(gobj_is_destroying(win)).toBe(true);
289
+ expect(document.activeElement === $elsewhere, "the focus is on $elsewhere").toBe(true);
290
+ $opener.remove();
291
+ $elsewhere.remove();
292
+ });
293
+ });
294
+
295
+ describe("a window the reader did not open", () => {
296
+ /* What the browser says of the moment: `isActive` is true only in
297
+ * answer to a press or a key of the reader (a user activation). */
298
+ function with_activation(is_active, fn)
299
+ {
300
+ const had = Object.getOwnPropertyDescriptor(navigator, "userActivation");
301
+ Object.defineProperty(navigator, "userActivation", {
302
+ value: {isActive: is_active, hasBeenActive: is_active},
303
+ configurable: true, writable: true
304
+ });
305
+ try {
306
+ fn();
307
+ } finally {
308
+ if(had) {
309
+ Object.defineProperty(navigator, "userActivation", had);
310
+ } else {
311
+ delete navigator.userActivation;
312
+ }
313
+ }
314
+ }
315
+
316
+ test("one the app restores at start up leaves the focus where it is", () => {
317
+ const $page = document.createElement("input");
318
+ document.body.appendChild($page);
319
+ $page.focus();
320
+
321
+ with_activation(false, () => {
322
+ const win = open_window();
323
+ expect(document.activeElement === $page, "the focus stays in the page").toBe(true);
324
+ $of(win).querySelector(".WINDOW_CLOSE").click();
325
+ });
326
+ with_activation(true, () => {
327
+ const win = open_window();
328
+ expect(document.activeElement === $of(win), "opened by the reader, it takes it").toBe(true);
329
+ $of(win).querySelector(".WINDOW_CLOSE").click();
330
+ });
331
+ $page.remove();
332
+ });
333
+
334
+ test("a modal one takes the focus all the same: nothing else can be used", () => {
335
+ with_activation(false, () => {
336
+ const win = open_window({modal: true});
337
+ expect($of(win).contains(document.activeElement), "the focus is in the modal").toBe(true);
338
+ $of(win).querySelector(".WINDOW_CLOSE").click();
339
+ });
340
+ });
341
+ });
342
+
343
+ describe("Escape", () => {
344
+ test("closes the window the way its ✕ does: EV_CLOSE_WINDOW, vetoable", () => {
345
+ const win = open_window();
346
+ const $input = $of(win).querySelector(".TEST_FIRST");
347
+ $input.focus();
348
+
349
+ veto = true;
350
+ let ev = press($input, "Escape");
351
+ expect(gobj_is_destroying(win)).toBe(false);
352
+ expect(ev.defaultPrevented).toBe(true);
353
+ expect(ev.stopped).toBe(true);
354
+ expect(actions_run.filter((a) => a.event === "EV_CLOSE_WINDOW"))
355
+ .toEqual([{event: "EV_CLOSE_WINDOW", kw: {key: "Escape"}}]);
356
+
357
+ veto = false;
358
+ press($input, "Escape");
359
+ expect(gobj_is_destroying(win)).toBe(true);
360
+ });
361
+
362
+ test("with `keyboard: false` it is not the window's: it goes on", () => {
363
+ const win = open_window({keyboard: false});
364
+ const $button = $of(win).querySelector(".TEST_BUTTON");
365
+ const ev = press($button, "Escape");
366
+ expect(gobj_is_destroying(win)).toBe(false);
367
+ expect(ev.defaultPrevented).toBe(false);
368
+ expect(ev.stopped).toBe(false);
369
+ expect(actions_run.filter((a) => a.event === "EV_CLOSE_WINDOW")).toEqual([]);
370
+ $of(win).querySelector(".WINDOW_CLOSE").click();
371
+ });
372
+
373
+ test("an Escape that something inside took first does not close it", () => {
374
+ const win = open_window();
375
+ const $c = $of(win);
376
+ const $input = $c.querySelector(".TEST_FIRST");
377
+
378
+ /* A widget used it (a menu, a search box closed). */
379
+ press($input, "Escape", {}, (ev) => ev.preventDefault());
380
+ /* An input method composing. */
381
+ press($input, "Escape", {isComposing: true});
382
+ /* A cell editor that went with the key: Tabulator cancels the
383
+ * edit by removing the box the key was typed in, and says
384
+ * nothing else. */
385
+ const $cell = document.createElement("div");
386
+ const $editor = document.createElement("input");
387
+ $cell.appendChild($editor);
388
+ $c.querySelector(".TEST_BODY").appendChild($cell);
389
+ $editor.focus();
390
+ press($editor, "Escape", {}, () => {
391
+ $cell.removeChild($editor);
392
+ document.activeElement = document.body; /* as a browser does */
393
+ });
394
+ /* The focus went with the editor: the window takes it back, so
395
+ * the next Escape is still heard. */
396
+ expect(document.activeElement === $c, "the window took the focus back").toBe(true);
397
+ /* A search box with text: the browser clears it with Escape. */
398
+ const $search = document.createElement("input");
399
+ $search.setAttribute("type", "search");
400
+ $search.value = "abc";
401
+ $c.querySelector(".TEST_BODY").appendChild($search);
402
+ press($search, "Escape");
403
+ /* A text editor: a textarea, a contenteditable. */
404
+ press($c.querySelector(".TEST_TEXT"), "Escape");
405
+ const $editable = document.createElement("div");
406
+ $editable.isContentEditable = true;
407
+ $c.querySelector(".TEST_BODY").appendChild($editable);
408
+ press($editable, "Escape");
409
+
410
+ expect(gobj_is_destroying(win)).toBe(false);
411
+ expect(actions_run.filter((a) => a.event === "EV_CLOSE_WINDOW")).toEqual([]);
412
+ $c.querySelector(".WINDOW_CLOSE").click();
413
+ });
414
+ });
415
+
416
+ describe("a modal window", () => {
417
+ test("blocks the rest: a backdrop in the dialog layer, aria-modal, no dock", () => {
418
+ const dock = gobj_create_service("dlg_dock", "C_YUI_WINDOW_MANAGER", {}, app);
419
+ gobj_start(dock);
420
+ logged.length = 0;
421
+
422
+ const win = open_window({modal: true, manager: dock});
423
+ const $c = $of(win);
424
+ expect($c.getAttribute("aria-modal")).toBe("true");
425
+
426
+ const $lock = $c.parentNode;
427
+ expect($lock.classList.contains("WINDOW_MODAL_LOCK")).toBe(true);
428
+ expect(!!$lock.querySelector(".WINDOW_MODAL_BACKDROP"), "a backdrop").toBe(true);
429
+ expect($lock.parentNode === shell.priv.layers.modal, "the lock is in the modal layer").toBe(true);
430
+
431
+ /* It does not go to the dock: there is no getting back from it. */
432
+ expect(dock.priv.windows.length).toBe(0);
433
+ expect($c.querySelector(".WINDOW_MIN").style.cssText).toContain("display:none");
434
+ expect(warnings().some((w) => w.includes("modal") && w.includes("dock"))).toBe(true);
435
+
436
+ /* A press on the backdrop closes nothing. */
437
+ $lock.querySelector(".WINDOW_MODAL_BACKDROP").click();
438
+ expect(gobj_is_destroying(win)).toBe(false);
439
+
440
+ press($c.querySelector(".TEST_BUTTON"), "Escape");
441
+ expect(gobj_is_destroying(win)).toBe(true);
442
+ expect($lock.parentNode === null, "the lock went with the window").toBe(true);
443
+ });
444
+
445
+ test("keeps Tab inside, and gives the focus back when it goes", () => {
446
+ const $opener = document.createElement("button");
447
+ document.body.appendChild($opener);
448
+ $opener.focus();
449
+
450
+ const win = open_window({modal: true});
451
+ const $c = $of(win);
452
+ expect(document.activeElement === $c, "the focus is on $c").toBe(true);
453
+
454
+ const $last = $c.querySelector(".TEST_BUTTON");
455
+ $last.focus();
456
+ const tab = press(document.activeElement, "Tab");
457
+ expect(tab.defaultPrevented).toBe(true);
458
+ expect($c.contains(document.activeElement)).toBe(true);
459
+ expect(document.activeElement !== $last, "the focus left the last control").toBe(true);
460
+
461
+ $c.querySelector(".WINDOW_CLOSE").click();
462
+ expect(document.activeElement === $opener, "the focus is on $opener").toBe(true);
463
+ $opener.remove();
464
+ });
465
+ });
466
+
467
+ describe("a window of the dock", () => {
468
+ test("minimized, the focus goes to its chip; brought back from it, into the window", () => {
469
+ const dock = gobj_create_service("dlg_dock2", "C_YUI_WINDOW_MANAGER", {}, app);
470
+ gobj_start(dock);
471
+ const win = open_window({manager: dock});
472
+ const $c = $of(win);
473
+ expect(document.activeElement === $c, "the window took the focus").toBe(true);
474
+
475
+ $c.querySelector(".WINDOW_MIN").click();
476
+ const $toggle = dock.priv.windows[0].$chip.querySelector(".DOCK_CHIP_TOGGLE");
477
+ expect(document.activeElement === $toggle,
478
+ "the focus is on the way back, not lost with the hidden window").toBe(true);
479
+
480
+ $toggle.click();
481
+ expect(document.activeElement === $c, "the window brought back has it").toBe(true);
482
+
483
+ $c.querySelector(".WINDOW_CLOSE").click();
484
+ expect(gobj_is_destroying(win)).toBe(true);
485
+ });
486
+ });
@@ -0,0 +1,189 @@
1
+ /***********************************************************************
2
+ * window_dock_band.wiring.test.js
3
+ *
4
+ * A FLOATING dock sits above every window, at a corner of the
5
+ * viewport. A window that fills the screen -- the sheet a window
6
+ * becomes on a phone, a maximized one on a laptop -- went under
7
+ * it: at a bottom corner the dock covered the foot of the window,
8
+ * at a top corner its ✕ and its minimize. The dock says the band
9
+ * it keeps (`--yui-dock-inset-top` / `--yui-dock-inset-bottom` on
10
+ * the root element), and a full-screen window leaves it free.
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+ import {describe, test, expect, beforeAll, beforeEach, afterEach} 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_service,
23
+ gobj_start, gobj_stop, gobj_destroy, gobj_read_attr,
24
+ set_log_callback,
25
+ } = await import("@yuneta/gobj-js");
26
+ const {register_c_yui_window} = await import("./c_yui_window.js");
27
+ const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
28
+
29
+ const logged = [];
30
+ let yuno = null;
31
+ let seq = 0;
32
+
33
+ const TOP = "var(--yui-dock-inset-top, 0px)";
34
+ const BOTTOM = "var(--yui-dock-inset-bottom, 0px)";
35
+
36
+ function errors()
37
+ {
38
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
39
+ }
40
+
41
+ function root_style()
42
+ {
43
+ return document.documentElement.style;
44
+ }
45
+
46
+ /* A dock, drawn where a browser would draw it: `height` px high, at
47
+ * 12px from the edge of its corner. */
48
+ function open_dock(attrs, height)
49
+ {
50
+ const dock = gobj_create_service(`band_dock${++seq}`, "C_YUI_WINDOW_MANAGER",
51
+ Object.assign({dock_mode: "floating"}, attrs || {}), yuno);
52
+ gobj_start(dock);
53
+ const $dock = gobj_read_attr(dock, "$container");
54
+ $dock.getBoundingClientRect = function() {
55
+ const vh = window.innerHeight;
56
+ const top_corner = this.classList.contains("yui-dock--top-left") ||
57
+ this.classList.contains("yui-dock--top-right");
58
+ const shown = !this.classList.contains("is-empty") && this.isConnected !== false;
59
+ if(!shown) {
60
+ return {x: 0, y: 0, top: 0, left: 0, right: 0, bottom: 0, width: 0, height: 0};
61
+ }
62
+ const top = top_corner ? 12 : vh - 12 - height;
63
+ return {x: 12, y: top, top: top, left: 12, right: 212, bottom: top + height,
64
+ width: 200, height: height};
65
+ };
66
+ return dock;
67
+ }
68
+
69
+ function open_window(dock, attrs)
70
+ {
71
+ const win = gobj_create_service(`band_win${++seq}`, "C_YUI_WINDOW", Object.assign({
72
+ title: "demo window",
73
+ body: ["div", {}, "body"],
74
+ manager: dock,
75
+ }, attrs || {}), yuno);
76
+ gobj_start(win);
77
+ return win;
78
+ }
79
+
80
+ function close(gobj)
81
+ {
82
+ gobj_stop(gobj);
83
+ gobj_destroy(gobj);
84
+ }
85
+
86
+ beforeAll(async () => {
87
+ const i18next = (await import("i18next")).default;
88
+ await i18next.init({lng: "en", resources: {}});
89
+ gobj_start_up(null, null, null, null, null, null, null);
90
+ set_log_callback((level, msg) => {
91
+ logged.push({level: String(level), msg: String(msg)});
92
+ });
93
+ gclass_create("C_TEST_BAND_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
94
+ register_c_yui_window();
95
+ register_c_yui_window_manager();
96
+ yuno = gobj_create_yuno("band_yuno", "C_TEST_BAND_HOST", {});
97
+ gobj_start(yuno);
98
+ });
99
+
100
+ beforeEach(() => {
101
+ logged.length = 0;
102
+ window.innerWidth = 1280;
103
+ window.innerHeight = 800;
104
+ });
105
+
106
+ afterEach(() => {
107
+ window.innerWidth = 1280;
108
+ window.innerHeight = 800;
109
+ expect(errors()).toEqual([]);
110
+ });
111
+
112
+ describe("the floating dock says the band it keeps", () => {
113
+ test("at a bottom corner, while it shows a window; none once it is empty", () => {
114
+ const dock = open_dock({dock_corner: "bottom-left"}, 40);
115
+ expect(root_style().getPropertyValue("--yui-dock-inset-bottom")).toBe("");
116
+
117
+ const win = open_window(dock);
118
+ expect(root_style().getPropertyValue("--yui-dock-inset-bottom")).toBe("52px");
119
+ expect(root_style().getPropertyValue("--yui-dock-inset-top")).toBe("");
120
+
121
+ close(win);
122
+ expect(root_style().getPropertyValue("--yui-dock-inset-bottom")).toBe("");
123
+ close(dock);
124
+ });
125
+
126
+ test("at a top corner, the top band; and the dock that goes takes its band", () => {
127
+ const dock = open_dock({dock_corner: "top-right"}, 40);
128
+ const win = open_window(dock);
129
+ expect(root_style().getPropertyValue("--yui-dock-inset-top")).toBe("52px");
130
+ expect(root_style().getPropertyValue("--yui-dock-inset-bottom")).toBe("");
131
+
132
+ close(dock);
133
+ expect(root_style().getPropertyValue("--yui-dock-inset-top")).toBe("");
134
+ close(win);
135
+ });
136
+
137
+ test("an inline dock keeps no band: it is in the layout", () => {
138
+ const $zone = document.createElement("div");
139
+ $zone.className = "BAND_ZONE";
140
+ document.body.appendChild($zone);
141
+ const dock = open_dock({dock_mode: "inline", inline_selector: ".BAND_ZONE"}, 40);
142
+ const win = open_window(dock);
143
+ expect(root_style().getPropertyValue("--yui-dock-inset-bottom")).toBe("");
144
+ expect(root_style().getPropertyValue("--yui-dock-inset-top")).toBe("");
145
+ close(win);
146
+ close(dock);
147
+ $zone.remove();
148
+ });
149
+ });
150
+
151
+ describe("a window that fills the screen leaves the band free", () => {
152
+ test("the sheet of a phone", () => {
153
+ window.innerWidth = 390;
154
+ window.innerHeight = 844;
155
+ const dock = open_dock({dock_corner: "bottom-right"}, 40);
156
+ const win = open_window(dock);
157
+ const $c = gobj_read_attr(win, "$container");
158
+
159
+ expect($c.classList.contains("is-mobile-sheet")).toBe(true);
160
+ expect($c.style.top).toBe(TOP);
161
+ expect($c.style.height).toBe(`calc(844px - ${TOP} - ${BOTTOM})`);
162
+
163
+ /* And again when the viewport changes. */
164
+ window.innerHeight = 744;
165
+ window.dispatchEvent({type: "resize"});
166
+ expect($c.style.top).toBe(TOP);
167
+ expect($c.style.height).toBe(`calc(744px - ${TOP} - ${BOTTOM})`);
168
+ close(win);
169
+ close(dock);
170
+ });
171
+
172
+ test("a maximized window of a laptop", () => {
173
+ const dock = open_dock({dock_corner: "bottom-left"}, 40);
174
+ const win = open_window(dock, {center: false, x: 40, y: 50, width: 500, height: 300});
175
+ const $c = gobj_read_attr(win, "$container");
176
+
177
+ $c.querySelector(".WINDOW_MAX").click();
178
+ expect($c.style.top).toBe(TOP);
179
+ expect($c.style.left).toBe("0px");
180
+ expect($c.style.width).toBe("1280px");
181
+ expect($c.style.height).toBe(`calc(800px - ${TOP} - ${BOTTOM})`);
182
+
183
+ window.innerHeight = 700;
184
+ window.dispatchEvent({type: "resize"});
185
+ expect($c.style.height).toBe(`calc(700px - ${TOP} - ${BOTTOM})`);
186
+ close(win);
187
+ close(dock);
188
+ });
189
+ });