@yuneta/gobj-ui 7.26.45 → 7.26.47
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 +168 -17
- package/dist/gobj-ui.cjs.js +437 -43
- package/dist/gobj-ui.es.js +438 -44
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +388 -56
- package/src/c_yui_form.css +9 -0
- package/src/c_yui_form.js +225 -36
- package/src/c_yui_shell.js +82 -12
- package/src/c_yui_treedb_topic_with_form.js +8 -2
- package/src/c_yui_window.js +29 -1
- package/src/form_table_rows.wiring.test.js +330 -1
- package/src/form_time_cell_editor.js +160 -0
- package/src/form_time_cell_editor.test.js +154 -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/i18n_key_functions.test.js +8 -4
- package/src/shell_focus_trap.js +29 -3
- package/src/shell_focus_trap.test.js +139 -0
- package/src/shell_modals.js +2 -2
- package/src/shell_stop_overlays.wiring.test.js +175 -0
- package/src/tabulator_edit_internals.test.js +50 -0
- package/src/treedb_time_cell.wiring.test.js +103 -0
- package/src/window_rect_rounding.wiring.test.js +52 -1
- package/src/yui_tabulator_i18n.js +18 -7
- package/src/yui_tabulator_i18n.test.js +36 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* form_time_cell_editor.test.js
|
|
3
|
+
*
|
|
4
|
+
* The cell editor of a time column of C_YUI_FORM's tables. Up to
|
|
5
|
+
* gobj-ui 7.26.45 it was Tabulator's `datetime` with a `format`,
|
|
6
|
+
* which needs luxon -- nobody gives gobj-ui luxon: it opened empty,
|
|
7
|
+
* said so in the console, and threw when committed.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026, ArtGins.
|
|
10
|
+
* All Rights Reserved.
|
|
11
|
+
***********************************************************************/
|
|
12
|
+
import {describe, test, expect} from "vitest";
|
|
13
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
14
|
+
|
|
15
|
+
install_dom_double();
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
form_time_cell_editor, time_to_datetime_local, datetime_local_to_time,
|
|
19
|
+
} = await import("./form_time_cell_editor.js");
|
|
20
|
+
const {date_to_datetime_local} = await import("./form_time_value.js");
|
|
21
|
+
|
|
22
|
+
/* A local wall time and its epoch, whatever the zone of the run. */
|
|
23
|
+
const WALL = "2026-03-14T09:26:53";
|
|
24
|
+
const EPOCH = Math.floor(new Date(WALL).getTime() / 1000);
|
|
25
|
+
|
|
26
|
+
function open_editor(value, real_type, params)
|
|
27
|
+
{
|
|
28
|
+
const said = {success: [], cancel: 0, rendered: null};
|
|
29
|
+
const cell = {
|
|
30
|
+
getValue: () => value,
|
|
31
|
+
getType: () => "cell",
|
|
32
|
+
};
|
|
33
|
+
const $input = form_time_cell_editor(real_type)(
|
|
34
|
+
cell,
|
|
35
|
+
(fn) => {
|
|
36
|
+
said.rendered = fn;
|
|
37
|
+
},
|
|
38
|
+
(v) => {
|
|
39
|
+
said.success.push(v);
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
() => {
|
|
43
|
+
said.cancel++;
|
|
44
|
+
},
|
|
45
|
+
params || {}
|
|
46
|
+
);
|
|
47
|
+
return {$input, said};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function key(name)
|
|
51
|
+
{
|
|
52
|
+
return {
|
|
53
|
+
type: "keydown", key: name,
|
|
54
|
+
stopPropagation() {}, stopImmediatePropagation() {}, preventDefault() {},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe("a time column's cell editor", () => {
|
|
59
|
+
test("shows an epoch in seconds as a local time, to the second", () => {
|
|
60
|
+
const {$input} = open_editor(EPOCH, "integer");
|
|
61
|
+
expect($input.type).toBe("datetime-local");
|
|
62
|
+
expect($input.getAttribute("step")).toBe("1");
|
|
63
|
+
expect($input.value).toBe(WALL);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("gives back an epoch in seconds", () => {
|
|
67
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
68
|
+
$input.value = "2026-03-14T10:00:00";
|
|
69
|
+
$input.dispatchEvent(key("Enter"));
|
|
70
|
+
expect(said.success).toEqual([Math.floor(new Date("2026-03-14T10:00:00").getTime() / 1000)]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("an ISO text column stays an ISO text", () => {
|
|
74
|
+
const iso = new Date(EPOCH * 1000).toISOString();
|
|
75
|
+
const {$input, said} = open_editor(iso, "string");
|
|
76
|
+
expect($input.value).toBe(WALL);
|
|
77
|
+
$input.value = "2026-03-14T10:00:00";
|
|
78
|
+
$input.dispatchEvent(key("Enter"));
|
|
79
|
+
expect(said.success).toEqual([new Date("2026-03-14T10:00:00").toISOString()]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("an unchanged value is a cancel, and so is Escape", () => {
|
|
83
|
+
const a = open_editor(EPOCH, "integer");
|
|
84
|
+
a.$input.dispatchEvent(key("Enter"));
|
|
85
|
+
expect(a.said.success).toEqual([]);
|
|
86
|
+
expect(a.said.cancel).toBe(1);
|
|
87
|
+
|
|
88
|
+
const b = open_editor(EPOCH, "integer");
|
|
89
|
+
b.$input.value = "2026-03-14T10:00:00";
|
|
90
|
+
b.$input.dispatchEvent(key("Escape"));
|
|
91
|
+
expect(b.said.success).toEqual([]);
|
|
92
|
+
expect(b.said.cancel).toBe(1);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("an empty cell opens empty, and emptied commits null", () => {
|
|
96
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
97
|
+
$input.value = "";
|
|
98
|
+
$input.dispatchEvent(key("Enter"));
|
|
99
|
+
expect(said.success).toEqual([null]);
|
|
100
|
+
expect(open_editor(null, "integer").$input.value).toBe("");
|
|
101
|
+
expect(open_editor(undefined, "string").$input.value).toBe("");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("writes the attributes it is given: the column's name", () => {
|
|
105
|
+
const {$input} = open_editor(EPOCH, "integer", {
|
|
106
|
+
elementAttributes: {"aria-label": "since", title: "since"}
|
|
107
|
+
});
|
|
108
|
+
expect($input.getAttribute("aria-label")).toBe("since");
|
|
109
|
+
expect($input.getAttribute("title")).toBe("since");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("the conversions are each other's inverse", () => {
|
|
113
|
+
expect(datetime_local_to_time(time_to_datetime_local(EPOCH, "integer"), "integer")).toBe(EPOCH);
|
|
114
|
+
expect(time_to_datetime_local(EPOCH, "integer")).toBe(date_to_datetime_local(new Date(EPOCH * 1000)));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/* A box with a part of its date cleared answers `value ""`, as an
|
|
118
|
+
* empty one does, and only `validity.badInput` tells them apart.
|
|
119
|
+
* Up to 7.26.46 both were committed as null: one Backspace and
|
|
120
|
+
* Enter erased the stored time. */
|
|
121
|
+
function half_typed($input)
|
|
122
|
+
{
|
|
123
|
+
$input.value = "";
|
|
124
|
+
Object.defineProperty($input, "validity", {
|
|
125
|
+
configurable: true,
|
|
126
|
+
value: {badInput: true, valid: false}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
test("an incomplete date is not committed by Enter: the editor stays open, said invalid", () => {
|
|
131
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
132
|
+
half_typed($input);
|
|
133
|
+
$input.dispatchEvent(key("Enter"));
|
|
134
|
+
expect(said.success).toEqual([]);
|
|
135
|
+
expect(said.cancel).toBe(0);
|
|
136
|
+
expect($input.getAttribute("aria-invalid")).toBe("true");
|
|
137
|
+
|
|
138
|
+
/* Completed, it commits. */
|
|
139
|
+
Object.defineProperty($input, "validity", {configurable: true, value: {badInput: false, valid: true}});
|
|
140
|
+
$input.value = "2026-03-14T10:00:00";
|
|
141
|
+
$input.dispatchEvent({type: "input"});
|
|
142
|
+
expect($input.getAttribute("aria-invalid")).toBe(null);
|
|
143
|
+
$input.dispatchEvent(key("Enter"));
|
|
144
|
+
expect(said.success).toEqual([Math.floor(new Date("2026-03-14T10:00:00").getTime() / 1000)]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("an incomplete date left by a blur is a cancel: the stored time stays", () => {
|
|
148
|
+
const {$input, said} = open_editor(EPOCH, "integer");
|
|
149
|
+
half_typed($input);
|
|
150
|
+
$input.dispatchEvent({type: "blur", relatedTarget: {}});
|
|
151
|
+
expect(said.success).toEqual([]);
|
|
152
|
+
expect(said.cancel).toBe(1);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* form_time_field.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The time field of C_YUI_FORM reads and writes a time column as
|
|
5
|
+
* the cell editor of a table does (form_time_value.js): an epoch in
|
|
6
|
+
* SECONDS for an integer column, an ISO text for a string one, and
|
|
7
|
+
* an empty box for a column that holds no time. Up to gobj-ui
|
|
8
|
+
* 7.26.46 the field read every column with parseInt -- an ISO text
|
|
9
|
+
* as 2026 SECONDS, in January 1970 --, wrote the epoch into a string
|
|
10
|
+
* column, and showed a column with no time as January 1970, which a
|
|
11
|
+
* save then wrote back as 0.
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2026, ArtGins.
|
|
14
|
+
* All Rights Reserved.
|
|
15
|
+
***********************************************************************/
|
|
16
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
17
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
18
|
+
|
|
19
|
+
install_dom_double();
|
|
20
|
+
|
|
21
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
22
|
+
globalThis.ResizeObserver = class {
|
|
23
|
+
observe() {
|
|
24
|
+
}
|
|
25
|
+
unobserve() {
|
|
26
|
+
}
|
|
27
|
+
disconnect() {
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
SDATA_END, gclass_create,
|
|
34
|
+
gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
35
|
+
gobj_start, gobj_send_event, gobj_read_attr,
|
|
36
|
+
set_log_callback,
|
|
37
|
+
} = await import("@yuneta/gobj-js");
|
|
38
|
+
const {register_c_yui_form} = await import("./c_yui_form.js");
|
|
39
|
+
|
|
40
|
+
const logged = [];
|
|
41
|
+
const saved = [];
|
|
42
|
+
let yuno = null;
|
|
43
|
+
|
|
44
|
+
/* A local wall time and its epoch, whatever the zone of the run. */
|
|
45
|
+
const WALL = "2026-03-14T09:26:53";
|
|
46
|
+
const EPOCH = Math.floor(new Date(WALL).getTime() / 1000);
|
|
47
|
+
const ISO = new Date(EPOCH * 1000).toISOString();
|
|
48
|
+
|
|
49
|
+
const TEMPLATE = {
|
|
50
|
+
as_epoch: {type: "integer", flag: ["writable", "persistent", "time"]},
|
|
51
|
+
as_text: {type: "string", flag: ["writable", "persistent", "time"]},
|
|
52
|
+
no_time: {type: "integer", flag: ["writable", "persistent", "time"]},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
beforeAll(async () => {
|
|
56
|
+
const i18next = (await import("i18next")).default;
|
|
57
|
+
await i18next.init({lng: "en", resources: {}});
|
|
58
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
59
|
+
set_log_callback((level, msg) => {
|
|
60
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
61
|
+
});
|
|
62
|
+
gclass_create("C_TEST_TIME_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
63
|
+
gclass_create(
|
|
64
|
+
"C_TEST_TIME_APP",
|
|
65
|
+
[["EV_SAVE_RECORD", 0]],
|
|
66
|
+
[["ST_IDLE", [
|
|
67
|
+
["EV_SAVE_RECORD", (gobj, event, kw) => {
|
|
68
|
+
saved.push(JSON.parse(JSON.stringify(kw)));
|
|
69
|
+
return 0;
|
|
70
|
+
}, null],
|
|
71
|
+
]]],
|
|
72
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
73
|
+
);
|
|
74
|
+
register_c_yui_form();
|
|
75
|
+
yuno = gobj_create_yuno("form_time_field_yuno", "C_TEST_TIME_HOST", {});
|
|
76
|
+
gobj_start(yuno);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
logged.length = 0;
|
|
81
|
+
saved.length = 0;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
function errors()
|
|
85
|
+
{
|
|
86
|
+
return logged.filter(l => /error/i.test(l.level) || /ERROR/.test(l.msg));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function box(form, name)
|
|
90
|
+
{
|
|
91
|
+
const $container = gobj_read_attr(form, "$container");
|
|
92
|
+
return Array.from($container.querySelectorAll(".yui-form-data-input"))
|
|
93
|
+
.find(($i) => $i.dataset.treedb_name === name);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
describe("the time field of a form", () => {
|
|
97
|
+
test("shows each column as the cell editor does, and saves it back as it was", () => {
|
|
98
|
+
const app = gobj_create_pure_child("tapp", "C_TEST_TIME_APP", {}, yuno);
|
|
99
|
+
gobj_start(app);
|
|
100
|
+
const form = gobj_create_pure_child("tform", "C_YUI_FORM", {
|
|
101
|
+
template: TEMPLATE,
|
|
102
|
+
record: {as_epoch: EPOCH, as_text: ISO, no_time: null},
|
|
103
|
+
editable: true,
|
|
104
|
+
}, app);
|
|
105
|
+
gobj_start(form);
|
|
106
|
+
|
|
107
|
+
expect(box(form, "as_epoch").value).toBe(WALL);
|
|
108
|
+
expect(box(form, "as_text").value).toBe(WALL);
|
|
109
|
+
expect(box(form, "no_time").value).toBe("");
|
|
110
|
+
|
|
111
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
112
|
+
expect(saved.length).toBe(1);
|
|
113
|
+
expect(saved[0].as_epoch).toBe(EPOCH);
|
|
114
|
+
expect(saved[0].as_text).toBe(ISO);
|
|
115
|
+
expect(saved[0].no_time).toBe(null);
|
|
116
|
+
expect(errors()).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
});
|
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
|
});
|
|
@@ -111,6 +111,10 @@ import {
|
|
|
111
111
|
|
|
112
112
|
const SRC = dirname(fileURLToPath(import.meta.url));
|
|
113
113
|
|
|
114
|
+
/* The tests that parse every module of the library take a second or
|
|
115
|
+
* more alone, and brushed vitest's 5 s with the whole suite running. */
|
|
116
|
+
const SLOW_SCAN_MS = 30000;
|
|
117
|
+
|
|
114
118
|
const MODULES = readdirSync(SRC)
|
|
115
119
|
.filter((f) => f.endsWith(".js") && !f.endsWith(".test.js"))
|
|
116
120
|
.sort();
|
|
@@ -1122,11 +1126,11 @@ describe("I18N_KEY_FUNCTIONS: the table", () => {
|
|
|
1122
1126
|
describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
1123
1127
|
test("every function that hands a parameter to a place a key is read, in every module", () => {
|
|
1124
1128
|
expect(forwarders_report(find_forwarders())).toEqual([]);
|
|
1125
|
-
});
|
|
1129
|
+
}, SLOW_SCAN_MS);
|
|
1126
1130
|
|
|
1127
1131
|
test("REV-CLOUD V22: the table is CORRECT -- every entry is a hand-off the library shows", () => {
|
|
1128
1132
|
expect(table_errors(find_forwarders(MODULES, ast_of, []).found)).toEqual([]);
|
|
1129
|
-
});
|
|
1133
|
+
}, SLOW_SCAN_MS);
|
|
1130
1134
|
|
|
1131
1135
|
test("every fallback of the table is one in the code, and the check fails when it is not", () => {
|
|
1132
1136
|
expect(fallback_errors()).toEqual([]);
|
|
@@ -1222,7 +1226,7 @@ describe("REV-CLOUD V21.4.1: every forwarder is in the table", () => {
|
|
|
1222
1226
|
let unmarked = parse_as(code.replace(/\/\* i18n: data \*\/ /g, ""), module);
|
|
1223
1227
|
expect(find_forwarders([module], () => unmarked).unmarked.map((u) => u.name))
|
|
1224
1228
|
.toContain("ac_register_window");
|
|
1225
|
-
});
|
|
1229
|
+
}, SLOW_SCAN_MS);
|
|
1226
1230
|
});
|
|
1227
1231
|
|
|
1228
1232
|
describe("a `code` is a key where the library makes one", () => {
|
|
@@ -2081,7 +2085,7 @@ describe("REV-CLOUD V22.2: what the search for forwarders sees, and what fails i
|
|
|
2081
2085
|
/* ...as the real table was, before V22: an action label that went
|
|
2082
2086
|
* through a DOM property, a flag that hid an export */
|
|
2083
2087
|
expect(table_errors(found)).toEqual([]);
|
|
2084
|
-
});
|
|
2088
|
+
}, SLOW_SCAN_MS);
|
|
2085
2089
|
});
|
|
2086
2090
|
|
|
2087
2091
|
describe("REV-CLOUD V22.3-4: the data marker hides no key; one notion of a translator", () => {
|
package/src/shell_focus_trap.js
CHANGED
|
@@ -24,7 +24,17 @@
|
|
|
24
24
|
* that wrapped to it, did nothing and was prevented -- the
|
|
25
25
|
* keyboard never got into the dialog.
|
|
26
26
|
*
|
|
27
|
-
*
|
|
27
|
+
* A trap whose panel 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().
|
|
36
|
+
*
|
|
37
|
+
* No gobj dependency: only gobj-js's logger. The optional
|
|
28
38
|
* second argument lets callers inject a mock document object
|
|
29
39
|
* for unit tests.
|
|
30
40
|
*
|
|
@@ -50,6 +60,22 @@ export const FOCUSABLE_SELECTOR =
|
|
|
50
60
|
* topmost trap; the rest short-circuit. */
|
|
51
61
|
const __trap_stack__ = [];
|
|
52
62
|
|
|
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()
|
|
69
|
+
{
|
|
70
|
+
for(let i = __trap_stack__.length - 1; i >= 0; i--) {
|
|
71
|
+
let trap = __trap_stack__[i];
|
|
72
|
+
if(trap.$panel.isConnected !== false) {
|
|
73
|
+
return trap;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
53
79
|
|
|
54
80
|
/* Whether `el` is drawn, so focus() on it can take. An element that
|
|
55
81
|
* cannot say (a stub with no getClientRects) is taken as drawn. */
|
|
@@ -100,7 +126,7 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
100
126
|
* Earlier-registered listeners fire too (capture phase),
|
|
101
127
|
* but they short-circuit unless they own the top of the
|
|
102
128
|
* stack. */
|
|
103
|
-
if(
|
|
129
|
+
if(top_trap() !== trap) {
|
|
104
130
|
return;
|
|
105
131
|
}
|
|
106
132
|
let nodes = focusables_of($panel);
|
|
@@ -161,6 +187,6 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
161
187
|
***************************************************************/
|
|
162
188
|
export function focus_trap_panel()
|
|
163
189
|
{
|
|
164
|
-
let top =
|
|
190
|
+
let top = top_trap();
|
|
165
191
|
return top ? top.$panel : null;
|
|
166
192
|
}
|
|
@@ -9,6 +9,7 @@ import { test, expect } from "vitest";
|
|
|
9
9
|
import {
|
|
10
10
|
FOCUSABLE_SELECTOR,
|
|
11
11
|
activate_focus_trap_on,
|
|
12
|
+
focus_trap_panel,
|
|
12
13
|
} from "./shell_focus_trap.js";
|
|
13
14
|
|
|
14
15
|
|
|
@@ -381,3 +382,141 @@ test("Tab and Shift+Tab wrap to the first and last DRAWN controls", () => {
|
|
|
381
382
|
expect(x.focus_calls).toEqual([]);
|
|
382
383
|
release();
|
|
383
384
|
});
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
/***************************************************************
|
|
388
|
+
* A trap whose panel left the document without being released
|
|
389
|
+
* (its owner was torn down with it: a shell destroyed with a
|
|
390
|
+
* drawer or a dialog open) holds the focus of nothing. Kept on
|
|
391
|
+
* the stack it was the "overlay" every later window opened
|
|
392
|
+
* under, so none of them took the focus; and above a live trap
|
|
393
|
+
* it left that one deaf to Tab. It is 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().
|
|
396
|
+
***************************************************************/
|
|
397
|
+
function connected_panel(focusables)
|
|
398
|
+
{
|
|
399
|
+
let panel = make_panel(focusables);
|
|
400
|
+
panel.isConnected = true;
|
|
401
|
+
return panel;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
test("a trap whose panel left the document is no longer the top", () => {
|
|
405
|
+
let a_first = make_focusable("a-first");
|
|
406
|
+
let panel_a = connected_panel([a_first]);
|
|
407
|
+
let panel_b = connected_panel([make_focusable("b-first")]);
|
|
408
|
+
let doc = make_doc(null);
|
|
409
|
+
|
|
410
|
+
let release_a = activate_focus_trap_on(panel_a, doc);
|
|
411
|
+
let release_b = activate_focus_trap_on(panel_b, doc);
|
|
412
|
+
expect(focus_trap_panel()).toBe(panel_b);
|
|
413
|
+
|
|
414
|
+
panel_b.isConnected = false;
|
|
415
|
+
expect(focus_trap_panel()).toBe(panel_a);
|
|
416
|
+
expect(doc.listeners.length).toBe(2);
|
|
417
|
+
|
|
418
|
+
/* And the live one under it hears Tab again. */
|
|
419
|
+
a_first.focus_calls.length = 0;
|
|
420
|
+
doc.activeElement = make_focusable("outside");
|
|
421
|
+
let prevented = false;
|
|
422
|
+
doc.listeners[0]({
|
|
423
|
+
key: "Tab",
|
|
424
|
+
shiftKey: false,
|
|
425
|
+
preventDefault() {
|
|
426
|
+
prevented = true;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
expect(prevented).toBe(true);
|
|
430
|
+
expect(a_first.focus_calls).toEqual(["a-first.focus"]);
|
|
431
|
+
|
|
432
|
+
release_a();
|
|
433
|
+
release_b();
|
|
434
|
+
expect(doc.listeners.length).toBe(0);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
test("a detached trap above a live one does not leave the live one deaf to Tab", () => {
|
|
438
|
+
let a_first = make_focusable("a-first");
|
|
439
|
+
let panel_a = connected_panel([a_first]);
|
|
440
|
+
let panel_b = connected_panel([make_focusable("b-first")]);
|
|
441
|
+
let doc = make_doc(null);
|
|
442
|
+
|
|
443
|
+
let release_a = activate_focus_trap_on(panel_a, doc);
|
|
444
|
+
let release_b = activate_focus_trap_on(panel_b, doc);
|
|
445
|
+
panel_b.isConnected = false;
|
|
446
|
+
|
|
447
|
+
/* Nobody asked for the top: the Tab itself skips the stale one. */
|
|
448
|
+
a_first.focus_calls.length = 0;
|
|
449
|
+
doc.activeElement = make_focusable("outside");
|
|
450
|
+
let prevented = false;
|
|
451
|
+
let ev = {
|
|
452
|
+
key: "Tab",
|
|
453
|
+
shiftKey: false,
|
|
454
|
+
preventDefault() {
|
|
455
|
+
prevented = true;
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
for(let fn of doc.listeners.slice()) {
|
|
459
|
+
fn(ev);
|
|
460
|
+
}
|
|
461
|
+
expect(prevented).toBe(true);
|
|
462
|
+
expect(a_first.focus_calls).toEqual(["a-first.focus"]);
|
|
463
|
+
|
|
464
|
+
release_a();
|
|
465
|
+
release_b();
|
|
466
|
+
expect(doc.listeners.length).toBe(0);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test("the release of a skipped trap takes it off and gives the focus back", () => {
|
|
470
|
+
let prev = make_focusable("prev");
|
|
471
|
+
let panel = connected_panel([make_focusable("first")]);
|
|
472
|
+
let doc = make_doc(prev);
|
|
473
|
+
|
|
474
|
+
let release = activate_focus_trap_on(panel, doc);
|
|
475
|
+
panel.isConnected = false;
|
|
476
|
+
expect(focus_trap_panel()).not.toBe(panel);
|
|
477
|
+
expect(doc.listeners.length).toBe(1);
|
|
478
|
+
|
|
479
|
+
release();
|
|
480
|
+
expect(doc.listeners.length).toBe(0);
|
|
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);
|
|
522
|
+
});
|
package/src/shell_modals.js
CHANGED
|
@@ -518,7 +518,7 @@ export function yui_shell_show_modal(shell, content, opts)
|
|
|
518
518
|
};
|
|
519
519
|
|
|
520
520
|
escape_handler = request_close;
|
|
521
|
-
yui_shell_push_escape(shell, "modal", request_close);
|
|
521
|
+
yui_shell_push_escape(shell, "modal", request_close, do_close);
|
|
522
522
|
/* Browser Back closes the top-most modal (see overlay history in
|
|
523
523
|
* c_yui_shell.js). Null when history integration is off. */
|
|
524
524
|
overlay = yui_shell_register_overlay(shell, on_back);
|
|
@@ -693,7 +693,7 @@ function build_dialog(shell, message, buttons, opts)
|
|
|
693
693
|
};
|
|
694
694
|
close_fn = () => close(dismiss_value);
|
|
695
695
|
|
|
696
|
-
yui_shell_push_escape(shell, "modal", close_fn);
|
|
696
|
+
yui_shell_push_escape(shell, "modal", close_fn, close_fn);
|
|
697
697
|
/* Browser Back dismisses the dialog with the safe-default value,
|
|
698
698
|
* exactly like Escape. */
|
|
699
699
|
overlay = yui_shell_register_overlay(shell, close_fn);
|