@yuneta/gobj-ui 7.26.46 → 7.26.48
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 +100 -16
- package/dist/gobj-ui.cjs.js +285 -60
- package/dist/gobj-ui.es.js +285 -60
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +185 -8
- package/src/c_yui_form.css +9 -0
- package/src/c_yui_form.js +158 -20
- package/src/c_yui_shell.js +73 -4
- package/src/c_yui_treedb_topic_with_form.js +8 -2
- package/src/c_yui_window.js +15 -1
- package/src/form_table_rows.wiring.test.js +169 -3
- package/src/form_time_cell_editor.js +40 -23
- package/src/form_time_cell_editor.test.js +38 -0
- package/src/form_time_field.wiring.test.js +118 -0
- package/src/form_time_value.js +59 -1
- package/src/form_time_value.test.js +25 -1
- package/src/shell_focus_trap.js +19 -24
- package/src/shell_focus_trap.test.js +53 -9
- package/src/shell_stop_overlays.wiring.test.js +90 -5
- package/src/treedb_time_cell.wiring.test.js +103 -0
- package/src/window_rect_rounding.wiring.test.js +29 -1
- package/src/yui_tabulator_i18n.js +18 -7
- package/src/yui_tabulator_i18n.test.js +36 -0
package/src/form_time_value.js
CHANGED
|
@@ -66,4 +66,62 @@ function datetime_local_to_epoch(value)
|
|
|
66
66
|
return Math.floor(date.getTime() / 1000);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
/************************************************************
|
|
70
|
+
* The value of a time column -> a Date, or null when it holds
|
|
71
|
+
* none. A `string` column holds an ISO text, any other an epoch
|
|
72
|
+
* in SECONDS. The form's time field and the cell editor of a
|
|
73
|
+
* table read it here, so the two agree: up to gobj-ui 7.26.46 the
|
|
74
|
+
* field read every column with parseInt -- an ISO text as the
|
|
75
|
+
* year 2026 in SECONDS, in January 1970 -- and showed an empty
|
|
76
|
+
* one as January 1970 too, which a save then wrote back as 0.
|
|
77
|
+
************************************************************/
|
|
78
|
+
function time_value_to_date(value, real_type)
|
|
79
|
+
{
|
|
80
|
+
if(value === null || value === undefined || value === "") {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
let date = (real_type === "string")?
|
|
84
|
+
new Date(String(value)) : new Date(Number(value) * 1000);
|
|
85
|
+
return isNaN(date.getTime())? null : date;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/************************************************************
|
|
89
|
+
* An epoch in seconds (null: no time) -> the value of a time
|
|
90
|
+
* column: an ISO text for a `string` column, the epoch for any
|
|
91
|
+
* other. Up to gobj-ui 7.26.46 the field wrote the epoch into a
|
|
92
|
+
* `string` column too.
|
|
93
|
+
************************************************************/
|
|
94
|
+
function epoch_to_time_value(epoch, real_type)
|
|
95
|
+
{
|
|
96
|
+
if(epoch === null || epoch === undefined) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if(typeof epoch !== "number" || !Number.isFinite(epoch)) {
|
|
100
|
+
return epoch; // not an epoch: handed on as it came
|
|
101
|
+
}
|
|
102
|
+
if(real_type === "string") {
|
|
103
|
+
return new Date(epoch * 1000).toISOString();
|
|
104
|
+
}
|
|
105
|
+
return epoch;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/************************************************************
|
|
109
|
+
* The value of a time column as a table cell shows it: the
|
|
110
|
+
* local clock the editor opens on, "YYYY-MM-DD HH:mm:ss", as
|
|
111
|
+
* fmt_epoch() of yui_time.js writes a timestamp in a table. ""
|
|
112
|
+
* for no time; a value that is not one is shown as it is, so the
|
|
113
|
+
* reader sees what the column holds.
|
|
114
|
+
************************************************************/
|
|
115
|
+
function time_value_to_text(value, real_type)
|
|
116
|
+
{
|
|
117
|
+
let date = time_value_to_date(value, real_type);
|
|
118
|
+
if(!date) {
|
|
119
|
+
return (value === null || value === undefined)? "" : String(value);
|
|
120
|
+
}
|
|
121
|
+
return date_to_datetime_local(date).replace("T", " ");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
date_to_datetime_local, datetime_local_to_epoch,
|
|
126
|
+
time_value_to_date, epoch_to_time_value, time_value_to_text
|
|
127
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {describe, it, expect} from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
date_to_datetime_local, datetime_local_to_epoch, time_value_to_date, epoch_to_time_value, time_value_to_text
|
|
4
|
+
} from "./form_time_value.js";
|
|
3
5
|
|
|
4
6
|
describe("form_time_value", () => {
|
|
5
7
|
|
|
@@ -20,4 +22,26 @@ describe("form_time_value", () => {
|
|
|
20
22
|
expect(date_to_datetime_local(null)).toBe("");
|
|
21
23
|
expect(date_to_datetime_local(new Date(NaN))).toBe("");
|
|
22
24
|
});
|
|
25
|
+
|
|
26
|
+
it("a time column is read and written by its type, and no time is null", () => {
|
|
27
|
+
const epoch = 1790000037;
|
|
28
|
+
const iso = new Date(epoch * 1000).toISOString();
|
|
29
|
+
expect(time_value_to_date(epoch, "integer").getTime()).toBe(epoch * 1000);
|
|
30
|
+
expect(time_value_to_date(iso, "string").getTime()).toBe(epoch * 1000);
|
|
31
|
+
expect(time_value_to_date(null, "integer")).toBe(null);
|
|
32
|
+
expect(time_value_to_date("", "string")).toBe(null);
|
|
33
|
+
expect(time_value_to_date("not a time", "string")).toBe(null);
|
|
34
|
+
expect(epoch_to_time_value(epoch, "integer")).toBe(epoch);
|
|
35
|
+
expect(epoch_to_time_value(epoch, "string")).toBe(iso);
|
|
36
|
+
expect(epoch_to_time_value(null, "string")).toBe(null);
|
|
37
|
+
expect(epoch_to_time_value("already text", "string")).toBe("already text");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("a time cell shows the local clock, and what is not a time as it is", () => {
|
|
41
|
+
const wall = "2026-03-14T09:26:53";
|
|
42
|
+
const epoch = Math.floor(new Date(wall).getTime() / 1000);
|
|
43
|
+
expect(time_value_to_text(epoch, "integer")).toBe("2026-03-14 09:26:53");
|
|
44
|
+
expect(time_value_to_text(null, "integer")).toBe("");
|
|
45
|
+
expect(time_value_to_text("garbage", "string")).toBe("garbage");
|
|
46
|
+
});
|
|
23
47
|
});
|
package/src/shell_focus_trap.js
CHANGED
|
@@ -24,12 +24,15 @@
|
|
|
24
24
|
* that wrapped to it, did nothing and was prevented -- the
|
|
25
25
|
* keyboard never got into the dialog.
|
|
26
26
|
*
|
|
27
|
-
* A trap whose panel
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
27
|
+
* A trap whose panel is out of the document is not the top:
|
|
28
|
+
* the top is the highest trap whose panel is in it. Up to
|
|
29
|
+
* gobj-ui 7.26.45 a trap left behind by an owner torn down with
|
|
30
|
+
* it stayed the top: every window opened later believed itself
|
|
31
|
+
* under an overlay and took no focus, and a live trap under it
|
|
32
|
+
* no longer heard Tab. 7.26.46 dropped such a trap from the
|
|
33
|
+
* stack, which was for good: a panel that only moved (taken out
|
|
34
|
+
* and put back, its trap never released) lost its trap. It is
|
|
35
|
+
* skipped now, and leaves the stack only by its release().
|
|
33
36
|
*
|
|
34
37
|
* No gobj dependency: only gobj-js's logger. The optional
|
|
35
38
|
* second argument lets callers inject a mock document object
|
|
@@ -39,8 +42,6 @@
|
|
|
39
42
|
* All Rights Reserved.
|
|
40
43
|
***********************************************************************/
|
|
41
44
|
|
|
42
|
-
import {log_warning} from "@yuneta/gobj-js";
|
|
43
|
-
|
|
44
45
|
/* Selector matching the elements typically considered focusable.
|
|
45
46
|
* Kept conservative: items that are explicitly removed from the tab
|
|
46
47
|
* order (`tabindex="-1"`) are excluded; everything else is in. */
|
|
@@ -59,21 +60,20 @@ export const FOCUSABLE_SELECTOR =
|
|
|
59
60
|
* topmost trap; the rest short-circuit. */
|
|
60
61
|
const __trap_stack__ = [];
|
|
61
62
|
|
|
62
|
-
/*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
|
|
63
|
+
/* The top trap whose panel is in the document. One that is not
|
|
64
|
+
* is skipped, not dropped: a panel that only MOVES (taken out and
|
|
65
|
+
* put back) is the top again once it is back. Only a panel that
|
|
66
|
+
* SAYS so (isConnected === false) is out: a stub that cannot say
|
|
67
|
+
* is taken as in. A trap leaves the stack only by its release(). */
|
|
68
|
+
function top_trap()
|
|
66
69
|
{
|
|
67
70
|
for(let i = __trap_stack__.length - 1; i >= 0; i--) {
|
|
68
71
|
let trap = __trap_stack__[i];
|
|
69
72
|
if(trap.$panel.isConnected !== false) {
|
|
70
|
-
|
|
73
|
+
return trap;
|
|
71
74
|
}
|
|
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
75
|
}
|
|
76
|
+
return null;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
|
|
@@ -126,8 +126,7 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
126
126
|
* Earlier-registered listeners fire too (capture phase),
|
|
127
127
|
* but they short-circuit unless they own the top of the
|
|
128
128
|
* stack. */
|
|
129
|
-
|
|
130
|
-
if(__trap_stack__[__trap_stack__.length - 1] !== trap) {
|
|
129
|
+
if(top_trap() !== trap) {
|
|
131
130
|
return;
|
|
132
131
|
}
|
|
133
132
|
let nodes = focusables_of($panel);
|
|
@@ -151,9 +150,6 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
151
150
|
}
|
|
152
151
|
};
|
|
153
152
|
trap.$panel = $panel;
|
|
154
|
-
trap.detach = function() {
|
|
155
|
-
doc.removeEventListener("keydown", trap, true);
|
|
156
|
-
};
|
|
157
153
|
doc.addEventListener("keydown", trap, true);
|
|
158
154
|
__trap_stack__.push(trap);
|
|
159
155
|
|
|
@@ -191,7 +187,6 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
191
187
|
***************************************************************/
|
|
192
188
|
export function focus_trap_panel()
|
|
193
189
|
{
|
|
194
|
-
|
|
195
|
-
let top = __trap_stack__[__trap_stack__.length - 1];
|
|
190
|
+
let top = top_trap();
|
|
196
191
|
return top ? top.$panel : null;
|
|
197
192
|
}
|
|
@@ -390,8 +390,9 @@ test("Tab and Shift+Tab wrap to the first and last DRAWN controls", () => {
|
|
|
390
390
|
* drawer or a dialog open) holds the focus of nothing. Kept on
|
|
391
391
|
* the stack it was the "overlay" every later window opened
|
|
392
392
|
* under, so none of them took the focus; and above a live trap
|
|
393
|
-
* it left that one deaf to Tab. It is
|
|
394
|
-
*
|
|
393
|
+
* it left that one deaf to Tab. It is skipped: the top is the
|
|
394
|
+
* highest trap whose panel is in the document. It stays on the
|
|
395
|
+
* stack, listener and all, until its release().
|
|
395
396
|
***************************************************************/
|
|
396
397
|
function connected_panel(focusables)
|
|
397
398
|
{
|
|
@@ -407,12 +408,12 @@ test("a trap whose panel left the document is no longer the top", () => {
|
|
|
407
408
|
let doc = make_doc(null);
|
|
408
409
|
|
|
409
410
|
let release_a = activate_focus_trap_on(panel_a, doc);
|
|
410
|
-
activate_focus_trap_on(panel_b, doc);
|
|
411
|
+
let release_b = activate_focus_trap_on(panel_b, doc);
|
|
411
412
|
expect(focus_trap_panel()).toBe(panel_b);
|
|
412
413
|
|
|
413
414
|
panel_b.isConnected = false;
|
|
414
415
|
expect(focus_trap_panel()).toBe(panel_a);
|
|
415
|
-
expect(doc.listeners.length).toBe(
|
|
416
|
+
expect(doc.listeners.length).toBe(2);
|
|
416
417
|
|
|
417
418
|
/* And the live one under it hears Tab again. */
|
|
418
419
|
a_first.focus_calls.length = 0;
|
|
@@ -429,6 +430,7 @@ test("a trap whose panel left the document is no longer the top", () => {
|
|
|
429
430
|
expect(a_first.focus_calls).toEqual(["a-first.focus"]);
|
|
430
431
|
|
|
431
432
|
release_a();
|
|
433
|
+
release_b();
|
|
432
434
|
expect(doc.listeners.length).toBe(0);
|
|
433
435
|
});
|
|
434
436
|
|
|
@@ -439,10 +441,10 @@ test("a detached trap above a live one does not leave the live one deaf to Tab",
|
|
|
439
441
|
let doc = make_doc(null);
|
|
440
442
|
|
|
441
443
|
let release_a = activate_focus_trap_on(panel_a, doc);
|
|
442
|
-
activate_focus_trap_on(panel_b, doc);
|
|
444
|
+
let release_b = activate_focus_trap_on(panel_b, doc);
|
|
443
445
|
panel_b.isConnected = false;
|
|
444
446
|
|
|
445
|
-
/* Nobody asked for the top: the Tab itself
|
|
447
|
+
/* Nobody asked for the top: the Tab itself skips the stale one. */
|
|
446
448
|
a_first.focus_calls.length = 0;
|
|
447
449
|
doc.activeElement = make_focusable("outside");
|
|
448
450
|
let prevented = false;
|
|
@@ -458,12 +460,13 @@ test("a detached trap above a live one does not leave the live one deaf to Tab",
|
|
|
458
460
|
}
|
|
459
461
|
expect(prevented).toBe(true);
|
|
460
462
|
expect(a_first.focus_calls).toEqual(["a-first.focus"]);
|
|
461
|
-
expect(doc.listeners.length).toBe(1);
|
|
462
463
|
|
|
463
464
|
release_a();
|
|
465
|
+
release_b();
|
|
466
|
+
expect(doc.listeners.length).toBe(0);
|
|
464
467
|
});
|
|
465
468
|
|
|
466
|
-
test("the release of a
|
|
469
|
+
test("the release of a skipped trap takes it off and gives the focus back", () => {
|
|
467
470
|
let prev = make_focusable("prev");
|
|
468
471
|
let panel = connected_panel([make_focusable("first")]);
|
|
469
472
|
let doc = make_doc(prev);
|
|
@@ -471,8 +474,49 @@ test("the release of a dropped trap still gives the focus back", () => {
|
|
|
471
474
|
let release = activate_focus_trap_on(panel, doc);
|
|
472
475
|
panel.isConnected = false;
|
|
473
476
|
expect(focus_trap_panel()).not.toBe(panel);
|
|
474
|
-
expect(doc.listeners.length).toBe(
|
|
477
|
+
expect(doc.listeners.length).toBe(1);
|
|
475
478
|
|
|
476
479
|
release();
|
|
480
|
+
expect(doc.listeners.length).toBe(0);
|
|
477
481
|
expect(prev.focus_calls).toEqual(["prev.focus"]);
|
|
482
|
+
panel.isConnected = true;
|
|
483
|
+
expect(focus_trap_panel()).not.toBe(panel);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
/***************************************************************
|
|
487
|
+
* A panel that only MOVES -- taken out of the document and put
|
|
488
|
+
* back, its trap never released -- keeps its trap. Up to gobj-ui
|
|
489
|
+
* 7.26.46 the first read of the stack while it was out dropped
|
|
490
|
+
* the trap for good: back in the document, Tab left the window.
|
|
491
|
+
***************************************************************/
|
|
492
|
+
test("a panel taken out and put back keeps its trap", () => {
|
|
493
|
+
let first = make_focusable("first");
|
|
494
|
+
let last = make_focusable("last");
|
|
495
|
+
let panel = connected_panel([first, last]);
|
|
496
|
+
let doc = make_doc(null);
|
|
497
|
+
|
|
498
|
+
let release = activate_focus_trap_on(panel, doc);
|
|
499
|
+
panel.isConnected = false;
|
|
500
|
+
expect(focus_trap_panel()).not.toBe(panel);
|
|
501
|
+
panel.isConnected = true;
|
|
502
|
+
expect(focus_trap_panel()).toBe(panel);
|
|
503
|
+
|
|
504
|
+
first.focus_calls.length = 0;
|
|
505
|
+
doc.activeElement = last;
|
|
506
|
+
let prevented = false;
|
|
507
|
+
for(let fn of doc.listeners.slice()) {
|
|
508
|
+
fn({
|
|
509
|
+
key: "Tab",
|
|
510
|
+
shiftKey: false,
|
|
511
|
+
preventDefault() {
|
|
512
|
+
prevented = true;
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
expect(prevented).toBe(true);
|
|
517
|
+
expect(first.focus_calls).toEqual(["first.focus"]);
|
|
518
|
+
|
|
519
|
+
release();
|
|
520
|
+
expect(doc.listeners.length).toBe(0);
|
|
521
|
+
expect(focus_trap_panel()).not.toBe(panel);
|
|
478
522
|
});
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
* Copyright (c) 2026, ArtGins.
|
|
14
14
|
* All Rights Reserved.
|
|
15
15
|
***********************************************************************/
|
|
16
|
-
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
16
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
17
17
|
import {install_dom_double} from "../test/dom_double.js";
|
|
18
18
|
|
|
19
19
|
install_dom_double();
|
|
20
20
|
|
|
21
21
|
const {
|
|
22
22
|
SDATA_END, gclass_create,
|
|
23
|
-
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop, gobj_destroy,
|
|
23
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop, gobj_destroy, gobj_read_attr,
|
|
24
24
|
set_log_callback,
|
|
25
25
|
} = await import("@yuneta/gobj-js");
|
|
26
|
-
const {register_c_yui_shell, yui_shell_open_drawer} = await import("./c_yui_shell.js");
|
|
26
|
+
const {register_c_yui_shell, yui_shell_open_drawer, yui_shell_unpark_route} = await import("./c_yui_shell.js");
|
|
27
27
|
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
28
28
|
const {yui_shell_show_modal, yui_shell_confirm_yesno} = await import("./shell_modals.js");
|
|
29
29
|
const {focus_trap_panel} = await import("./shell_focus_trap.js");
|
|
@@ -60,7 +60,7 @@ function settle()
|
|
|
60
60
|
return new Promise(resolve => setTimeout(resolve, 0));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function make_shell()
|
|
63
|
+
function make_shell(use_hash)
|
|
64
64
|
{
|
|
65
65
|
seq++;
|
|
66
66
|
const app = gobj_create(`sapp${seq}`, "C_TEST_STOP_HOST", {}, yuno);
|
|
@@ -75,7 +75,8 @@ function make_shell()
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
subscriber: app
|
|
78
|
+
subscriber: app,
|
|
79
|
+
use_hash: !!use_hash
|
|
79
80
|
}, app);
|
|
80
81
|
gobj_start(shell);
|
|
81
82
|
logged.length = 0; /* the shell's own start: no route table here */
|
|
@@ -140,4 +141,88 @@ describe("a shell stopped with an overlay up", () => {
|
|
|
140
141
|
/* gobj-js says what the test did; nothing else is said. */
|
|
141
142
|
expect(errors().filter((m) => !m.includes("Destroying a RUNNING gobj"))).toEqual([]);
|
|
142
143
|
});
|
|
144
|
+
|
|
145
|
+
test("it moves no browser history: their markers are left in place", async () => {
|
|
146
|
+
window.location.hash = "#/home";
|
|
147
|
+
const shell = make_shell(true);
|
|
148
|
+
|
|
149
|
+
yui_shell_show_modal(shell, "the sheet", {
|
|
150
|
+
dialog: true, logical_class: "TEST_STOP_SHEET", title: "settings"
|
|
151
|
+
});
|
|
152
|
+
let answer = null;
|
|
153
|
+
yui_shell_confirm_yesno(shell, "really?").then((a) => {
|
|
154
|
+
answer = a;
|
|
155
|
+
});
|
|
156
|
+
expect(window.history.state && window.history.state.__yui_overlay__).toBeTruthy();
|
|
157
|
+
|
|
158
|
+
/* A stopped shell hears no landing: a back() of its own would be
|
|
159
|
+
* taken by whatever the next shell pushed in the same turn. */
|
|
160
|
+
const back = vi.spyOn(window.history, "back");
|
|
161
|
+
try {
|
|
162
|
+
gobj_stop(shell);
|
|
163
|
+
gobj_destroy(shell);
|
|
164
|
+
await settle();
|
|
165
|
+
expect(back).not.toHaveBeenCalled();
|
|
166
|
+
} finally {
|
|
167
|
+
back.mockRestore();
|
|
168
|
+
window.location.hash = "";
|
|
169
|
+
}
|
|
170
|
+
expect(answer).toBe(false);
|
|
171
|
+
expect(document.querySelectorAll(".TEST_STOP_SHEET").length).toBe(0);
|
|
172
|
+
expect(focus_trap_panel()).toBe(null);
|
|
173
|
+
expect(errors()).toEqual([]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("an action route the app parked is taken off in place, not with a back()", async () => {
|
|
177
|
+
window.location.hash = "#/home";
|
|
178
|
+
const shell = make_shell(true);
|
|
179
|
+
const resting = gobj_read_attr(shell, "current_route") || "/";
|
|
180
|
+
|
|
181
|
+
/* `redirect:"stay"`: the URL sits on the action route while
|
|
182
|
+
* the overlay is up, and the app's on_close takes it off. */
|
|
183
|
+
window.history.pushState(null, "", "#/prefs");
|
|
184
|
+
let closed = 0;
|
|
185
|
+
yui_shell_show_modal(shell, "the prefs", {
|
|
186
|
+
dialog: true, logical_class: "TEST_STOP_PREFS", title: "preferences",
|
|
187
|
+
on_close: () => {
|
|
188
|
+
closed++;
|
|
189
|
+
yui_shell_unpark_route("/prefs");
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/* The back() landed on the action entry (the marker above it
|
|
194
|
+
* keeps its hash): the URL stayed on #/prefs, and a shell built
|
|
195
|
+
* next read it and opened the overlay again. */
|
|
196
|
+
const back = vi.spyOn(window.history, "back");
|
|
197
|
+
try {
|
|
198
|
+
gobj_stop(shell);
|
|
199
|
+
gobj_destroy(shell);
|
|
200
|
+
await settle();
|
|
201
|
+
expect(closed).toBe(1);
|
|
202
|
+
expect(back).not.toHaveBeenCalled();
|
|
203
|
+
expect(window.location.hash).toBe(`#${resting.startsWith("/") ? resting : "/" + resting}`);
|
|
204
|
+
} finally {
|
|
205
|
+
back.mockRestore();
|
|
206
|
+
window.location.hash = "";
|
|
207
|
+
}
|
|
208
|
+
expect(errors()).toEqual([]);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("closed by the user, an overlay still unparks with a back()", async () => {
|
|
212
|
+
window.location.hash = "#/home";
|
|
213
|
+
const shell = make_shell(true);
|
|
214
|
+
window.history.pushState(null, "", "#/prefs");
|
|
215
|
+
const back = vi.spyOn(window.history, "back");
|
|
216
|
+
try {
|
|
217
|
+
yui_shell_unpark_route("/prefs");
|
|
218
|
+
expect(back).toHaveBeenCalledTimes(1);
|
|
219
|
+
yui_shell_unpark_route("/other");
|
|
220
|
+
expect(back).toHaveBeenCalledTimes(1);
|
|
221
|
+
} finally {
|
|
222
|
+
back.mockRestore();
|
|
223
|
+
gobj_stop(shell);
|
|
224
|
+
gobj_destroy(shell);
|
|
225
|
+
window.location.hash = "";
|
|
226
|
+
}
|
|
227
|
+
});
|
|
143
228
|
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* treedb_time_cell.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A time column of C_YUI_TREEDB_TOPIC_WITH_FORM's table reads its
|
|
5
|
+
* value as the form does (form_time_value.js): an ISO text for a
|
|
6
|
+
* string column, an epoch in seconds for any other, nothing for no
|
|
7
|
+
* time. Up to gobj-ui 7.26.46 it read every column with parseInt --
|
|
8
|
+
* an ISO text as 2026 SECONDS, in January 1970 -- and showed a
|
|
9
|
+
* column with no time as January 1970.
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026, ArtGins.
|
|
12
|
+
* All Rights Reserved.
|
|
13
|
+
***********************************************************************/
|
|
14
|
+
import {describe, test, expect, beforeAll, vi} from "vitest";
|
|
15
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
16
|
+
|
|
17
|
+
install_dom_double();
|
|
18
|
+
|
|
19
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
20
|
+
globalThis.ResizeObserver = class {
|
|
21
|
+
observe() {
|
|
22
|
+
}
|
|
23
|
+
unobserve() {
|
|
24
|
+
}
|
|
25
|
+
disconnect() {
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const tables = vi.hoisted(() => []);
|
|
31
|
+
vi.mock("tabulator-tables", () => {
|
|
32
|
+
class FakeTabulator {
|
|
33
|
+
constructor($el, settings) {
|
|
34
|
+
this.element = $el;
|
|
35
|
+
this.options = settings;
|
|
36
|
+
tables.push(this);
|
|
37
|
+
return new Proxy(this, {
|
|
38
|
+
get(target, prop) {
|
|
39
|
+
if(prop in target) {
|
|
40
|
+
return target[prop];
|
|
41
|
+
}
|
|
42
|
+
return () => [];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
on() {
|
|
47
|
+
}
|
|
48
|
+
off() {
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
SDATA_END, gclass_create, set_log_callback,
|
|
58
|
+
gobj_start_up, gobj_create_yuno, gobj_create_service, gobj_start,
|
|
59
|
+
} = await import("@yuneta/gobj-js");
|
|
60
|
+
const {register_c_yui_treedb_topic_with_form} = await import("./c_yui_treedb_topic_with_form.js");
|
|
61
|
+
|
|
62
|
+
const logged = [];
|
|
63
|
+
let yuno = null;
|
|
64
|
+
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
const i18next = (await import("i18next")).default;
|
|
67
|
+
await i18next.init({lng: "en", resources: {}});
|
|
68
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
69
|
+
set_log_callback((level, msg) => {
|
|
70
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
71
|
+
});
|
|
72
|
+
gclass_create("C_TEST_TIME_CELL_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
73
|
+
register_c_yui_treedb_topic_with_form();
|
|
74
|
+
yuno = gobj_create_yuno("time_cell_yuno", "C_TEST_TIME_CELL_HOST", {});
|
|
75
|
+
gobj_start(yuno);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("a time column of a treedb topic's table", () => {
|
|
79
|
+
test("reads an ISO text column as ISO, and shows no time as nothing", () => {
|
|
80
|
+
const view = gobj_create_service("time_cell_view", "C_YUI_TREEDB_TOPIC_WITH_FORM", {
|
|
81
|
+
treedb_name: "treedb_test",
|
|
82
|
+
topic_name: "events",
|
|
83
|
+
desc: {id: "events", pkey: "id", cols: [
|
|
84
|
+
{id: "id", header: "Id", type: "string", flag: ["persistent", "required"]},
|
|
85
|
+
{id: "at", header: "at", type: "string", flag: ["persistent", "time"]},
|
|
86
|
+
{id: "when", header: "when", type: "integer", flag: ["persistent", "time"]}
|
|
87
|
+
]}
|
|
88
|
+
}, yuno);
|
|
89
|
+
gobj_start(view);
|
|
90
|
+
const columns = tables[tables.length - 1].options.columns;
|
|
91
|
+
const text = (field, value) => {
|
|
92
|
+
const col = columns.find((c) => c.field === field);
|
|
93
|
+
const out = col.formatter({getValue: () => value, getData: () => ({}), getField: () => field}, {}, () => {});
|
|
94
|
+
return (out && typeof out === "object") ? out.textContent : String(out);
|
|
95
|
+
};
|
|
96
|
+
const year = (s) => (s.match(/\b(19|20)\d\d\b/) || [""])[0];
|
|
97
|
+
const epoch = Math.floor(new Date("2026-03-14T09:26:53").getTime() / 1000);
|
|
98
|
+
expect(year(text("at", new Date(epoch * 1000).toISOString()))).toBe("2026");
|
|
99
|
+
expect(year(text("when", epoch))).toBe("2026");
|
|
100
|
+
expect(text("when", null)).toBe("");
|
|
101
|
+
expect(logged.filter((l) => l.level === "error")).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* Copyright (c) 2026, ArtGins.
|
|
15
15
|
* All Rights Reserved.
|
|
16
16
|
***********************************************************************/
|
|
17
|
-
import {describe, test, expect, beforeAll} from "vitest";
|
|
17
|
+
import {describe, test, expect, beforeAll, vi} from "vitest";
|
|
18
18
|
import {install_dom_double} from "../test/dom_double.js";
|
|
19
19
|
|
|
20
20
|
install_dom_double();
|
|
@@ -117,6 +117,34 @@ describe("the saved rect of a window is whole pixels", () => {
|
|
|
117
117
|
expect(logged.filter((l) => l.msg.includes("rect_none-rect"))).toEqual([]);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
/* Not json at all, or the json `null`: kw_get_local_storage_value()
|
|
121
|
+
* answers nothing for either (the first with a console.warn of its
|
|
122
|
+
* own). Up to 7.26.46 the entry stayed, and was said on every open. */
|
|
123
|
+
test.each([["not json", "garbage{"], ["json null", "null"]])(
|
|
124
|
+
"an entry that is %s is said once, forgotten, and the window opens where it would",
|
|
125
|
+
(label, text) => {
|
|
126
|
+
const name = label === "not json" ? "rect_text" : "rect_null";
|
|
127
|
+
window.localStorage.setItem(`${name}-rect`, text);
|
|
128
|
+
logged.length = 0;
|
|
129
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
130
|
+
let win;
|
|
131
|
+
try {
|
|
132
|
+
win = gobj_create_service(name, "C_YUI_WINDOW", {
|
|
133
|
+
header: name, body: ["div", {}, name], auto_save_size_and_position: true,
|
|
134
|
+
x: 5, y: 6, width: 300, height: 200,
|
|
135
|
+
}, yuno);
|
|
136
|
+
gobj_start(win);
|
|
137
|
+
} finally {
|
|
138
|
+
warn.mockRestore();
|
|
139
|
+
}
|
|
140
|
+
expect(attrs_rect(win)).toEqual({x: 5, y: 6, width: 300, height: 200});
|
|
141
|
+
const warned = logged.filter((l) => l.level === "warning" && l.msg.includes(`${name}-rect`));
|
|
142
|
+
expect(warned.length, "the entry is said").toBe(1);
|
|
143
|
+
expect(window.localStorage.getItem(`${name}-rect`), "and forgotten").toBe(null);
|
|
144
|
+
expect(errors()).toEqual([]);
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
|
|
120
148
|
/* A rect with no size -- what the box of a window that is not
|
|
121
149
|
* drawn answers -- is no place to open in: the window was drawn at
|
|
122
150
|
* the CSS minimum while its attrs said 0 x 0, and every open
|
|
@@ -169,8 +169,14 @@ function yui_tabulator_name_filters(table, t)
|
|
|
169
169
|
* from `yui_tabulator_relocalize()` so a language change
|
|
170
170
|
* reaches them.
|
|
171
171
|
*
|
|
172
|
-
* It matches Tabulator's OWN literal and
|
|
173
|
-
* view named itself is
|
|
172
|
+
* It matches Tabulator's OWN literal, and the boxes it named itself
|
|
173
|
+
* (they carry `data-yui-row-select`), so a box a view named itself is
|
|
174
|
+
* left alone. Up to 7.26.46 it matched only the literal: a box named
|
|
175
|
+
* once was never found again, and a language change through
|
|
176
|
+
* yui_tabulator_relocalize() left it in the old language.
|
|
177
|
+
*
|
|
178
|
+
* The box in the HEADER selects every row, and is named so
|
|
179
|
+
* ("select all rows"); up to 7.26.46 it was "select row" too.
|
|
174
180
|
***************************************************************/
|
|
175
181
|
const TABULATOR_ROW_SELECT_ARIA = "Select Row";
|
|
176
182
|
|
|
@@ -193,12 +199,17 @@ function yui_tabulator_name_row_selects(table, t)
|
|
|
193
199
|
return;
|
|
194
200
|
}
|
|
195
201
|
let boxes = $el.querySelectorAll(
|
|
196
|
-
`input[type=checkbox][aria-label="${TABULATOR_ROW_SELECT_ARIA}"]`
|
|
202
|
+
`input[type=checkbox][aria-label="${TABULATOR_ROW_SELECT_ARIA}"], ` +
|
|
203
|
+
`input[type=checkbox][data-yui-row-select]`);
|
|
197
204
|
for(let $box of boxes) {
|
|
198
|
-
$box.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
$box.setAttribute("
|
|
205
|
+
let all = typeof $box.closest === "function" && !!$box.closest(".tabulator-header");
|
|
206
|
+
let name = all ? t("select all rows") : t("select row");
|
|
207
|
+
let key = all ? "select all rows" : "select row";
|
|
208
|
+
$box.setAttribute("aria-label", name);
|
|
209
|
+
$box.setAttribute("data-i18n-aria-label", key);
|
|
210
|
+
$box.setAttribute("title", name);
|
|
211
|
+
$box.setAttribute("data-i18n-title", key);
|
|
212
|
+
$box.setAttribute("data-yui-row-select", "");
|
|
202
213
|
}
|
|
203
214
|
} catch(e) {
|
|
204
215
|
/* a table between renders has no boxes to name */
|
|
@@ -81,6 +81,42 @@ describe("yui_tabulator_name_row_selects", () => {
|
|
|
81
81
|
expect($box.attrs["title"]).toBe("Seleccionar fila");
|
|
82
82
|
expect($box.attrs["data-i18n-title"]).toBe("select row");
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
/* Up to 7.26.46 the header's box -- which selects every row -- was
|
|
86
|
+
* named "select row" too. */
|
|
87
|
+
it("names the header's box for what it does: select all rows", () => {
|
|
88
|
+
const $box = element();
|
|
89
|
+
$box.setAttribute("aria-label", "Select Row");
|
|
90
|
+
$box.closest = (sel) => (sel === ".tabulator-header" ? {} : null);
|
|
91
|
+
const table = {element: element($box)};
|
|
92
|
+
|
|
93
|
+
yui_tabulator_name_row_selects(table, (key) => key === "select all rows" ? "Seleccionar todas las filas" : key);
|
|
94
|
+
|
|
95
|
+
expect($box.attrs["aria-label"]).toBe("Seleccionar todas las filas");
|
|
96
|
+
expect($box.attrs["data-i18n-aria-label"]).toBe("select all rows");
|
|
97
|
+
expect($box.attrs["title"]).toBe("Seleccionar todas las filas");
|
|
98
|
+
expect($box.attrs["data-i18n-title"]).toBe("select all rows");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/* Up to 7.26.46 only Tabulator's English literal was matched, so a
|
|
102
|
+
* box named once was never named again: a language change through
|
|
103
|
+
* yui_tabulator_relocalize() (C_YUI_FORM's EV_LANGUAGE_CHANGED) left
|
|
104
|
+
* it in the old language. */
|
|
105
|
+
it("names again, in the new language, a box it named before", () => {
|
|
106
|
+
const $box = element();
|
|
107
|
+
$box.setAttribute("aria-label", "Select Row");
|
|
108
|
+
/* Found again by the mark it left, not by Tabulator's literal */
|
|
109
|
+
const table = {element: {querySelectorAll: (sel) => (
|
|
110
|
+
sel.includes("Select Row") && $box.attrs["aria-label"] !== "Select Row" &&
|
|
111
|
+
!sel.includes("data-yui-row-select") ? [] : [$box])}};
|
|
112
|
+
|
|
113
|
+
yui_tabulator_name_row_selects(table, t);
|
|
114
|
+
expect($box.attrs["aria-label"]).toBe("Seleccionar fila");
|
|
115
|
+
|
|
116
|
+
yui_tabulator_name_row_selects(table, (key) => key === "select row" ? "Select the row" : key);
|
|
117
|
+
expect($box.attrs["aria-label"]).toBe("Select the row");
|
|
118
|
+
expect($box.attrs["title"]).toBe("Select the row");
|
|
119
|
+
});
|
|
84
120
|
});
|
|
85
121
|
|
|
86
122
|
describe("yui_tabulator_name_editor", () => {
|