@yuneta/gobj-ui 7.26.7 → 7.26.9
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 +53 -0
- package/dist/gobj-ui.cjs.js +534 -232
- package/dist/gobj-ui.es.js +534 -232
- package/package.json +2 -2
- package/src/c_g6_nodes_tree.js +65 -31
- package/src/c_yui_form.js +230 -63
- package/src/c_yui_gclass.js +23 -22
- package/src/c_yui_gobj_tree_js.js +13 -9
- package/src/c_yui_json.js +7 -6
- package/src/c_yui_json_graph.js +8 -7
- package/src/c_yui_json_pad.js +2 -1
- package/src/c_yui_map.js +25 -1
- package/src/c_yui_nav.js +9 -8
- package/src/c_yui_schema_editor.js +25 -24
- package/src/c_yui_shell.js +64 -3
- package/src/c_yui_treedb_topic_with_form.js +26 -21
- package/src/c_yui_treedb_topics.js +17 -16
- package/src/c_yui_window.js +73 -32
- package/src/c_yui_window_manager.js +3 -2
- package/src/form_json_field.js +10 -3
- package/src/form_json_field.test.js +6 -0
- package/src/form_json_field.wiring.test.js +1 -1
- package/src/form_table_rearm.wiring.test.js +158 -0
- package/src/form_toolbar_plan.js +5 -5
- package/src/g6_event_kw.js +36 -0
- package/src/map_stop_windows.wiring.test.js +112 -0
- package/src/nav_cards_helpers.js +2 -1
- package/src/nav_cards_helpers.test.js +7 -3
- package/src/overlay_marker_after_back.wiring.test.js +212 -0
- package/src/schema_to_c.js +10 -0
- package/src/schema_to_c.test.js +8 -1
- package/src/shell_modals.js +7 -5
- package/src/shell_route_map.js +12 -13
- package/src/treedb_topics_transport.wiring.test.js +26 -0
- package/src/vite_plugin_yuneta_html.test.js +94 -0
- package/src/window_show.wiring.test.js +83 -0
- package/src/window_veto_back.wiring.test.js +35 -0
- package/src/yui_asset.js +3 -2
- package/src/yui_data_color.js +33 -0
- package/src/yui_data_color.test.js +27 -0
- package/src/yui_dev.js +15 -13
- package/src/yui_frontend_view.js +4 -4
- package/src/yui_gclass_view.js +3 -3
- package/src/yui_text.js +43 -0
- package/src/yui_text.test.js +67 -0
- package/vite-plugin-yuneta-html.js +24 -5
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* form_table_rearm.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* A C_YUI_FORM with a table field, destroyed less than 200 ms after
|
|
5
|
+
* a save or an undo -- which is what a dialog does: it closes the
|
|
6
|
+
* moment the record is saved.
|
|
7
|
+
*
|
|
8
|
+
* set_changed_stated(false) re-wires the tables' `dataChanged` from
|
|
9
|
+
* a 200 ms timer. Since 7.26.7 destroy_ui() destroys the widgets and
|
|
10
|
+
* nulls `$table.tabulator`, and the timer, left running, called
|
|
11
|
+
* `.on()` on that null: an uncaught TypeError. The timer is kept and
|
|
12
|
+
* cancelled now, and it skips a table that is gone.
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026, ArtGins.
|
|
15
|
+
* All Rights Reserved.
|
|
16
|
+
***********************************************************************/
|
|
17
|
+
import {describe, test, expect, beforeAll, vi} from "vitest";
|
|
18
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
19
|
+
|
|
20
|
+
install_dom_double();
|
|
21
|
+
|
|
22
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
23
|
+
globalThis.ResizeObserver = class {
|
|
24
|
+
observe() {}
|
|
25
|
+
unobserve() {}
|
|
26
|
+
disconnect() {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* A Tabulator that answers anything: the form drives a dozen of its
|
|
31
|
+
* methods, and this test is about the timer, not about the table. */
|
|
32
|
+
const tables = vi.hoisted(() => []);
|
|
33
|
+
vi.mock("tabulator-tables", () => {
|
|
34
|
+
class FakeTabulator {
|
|
35
|
+
constructor() {
|
|
36
|
+
this.externalEvents = {events: {}};
|
|
37
|
+
this.destroyed = false;
|
|
38
|
+
this.initialized = true;
|
|
39
|
+
this.added = [];
|
|
40
|
+
tables.push(this);
|
|
41
|
+
return new Proxy(this, {
|
|
42
|
+
get(target, prop) {
|
|
43
|
+
if(prop in target) {
|
|
44
|
+
return target[prop];
|
|
45
|
+
}
|
|
46
|
+
return () => [];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
on(ev, fn) {
|
|
51
|
+
(this.externalEvents.events[ev] = this.externalEvents.events[ev] || []).push(fn);
|
|
52
|
+
}
|
|
53
|
+
off(ev) {
|
|
54
|
+
delete this.externalEvents.events[ev];
|
|
55
|
+
}
|
|
56
|
+
destroy() {
|
|
57
|
+
this.destroyed = true;
|
|
58
|
+
}
|
|
59
|
+
addRow(record) {
|
|
60
|
+
this.added.push(record);
|
|
61
|
+
return Promise.resolve({getElement: () => document.createElement("div")});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {TabulatorFull: FakeTabulator, Tabulator: FakeTabulator};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const {
|
|
68
|
+
SDATA_END, gclass_create,
|
|
69
|
+
gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
70
|
+
gobj_start, gobj_stop, gobj_destroy, gobj_send_event,
|
|
71
|
+
set_log_callback,
|
|
72
|
+
} = await import("@yuneta/gobj-js");
|
|
73
|
+
const {register_c_yui_form} = await import("./c_yui_form.js");
|
|
74
|
+
|
|
75
|
+
let yuno = null;
|
|
76
|
+
|
|
77
|
+
beforeAll(async () => {
|
|
78
|
+
const i18next = (await import("i18next")).default;
|
|
79
|
+
await i18next.init({lng: "en", resources: {}});
|
|
80
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
81
|
+
set_log_callback(() => {});
|
|
82
|
+
gclass_create("C_TEST_RA_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
83
|
+
gclass_create(
|
|
84
|
+
"C_TEST_RA_APP",
|
|
85
|
+
[["EV_SAVE_RECORD", 0], ["EV_RECORD_CHANGED", 0]],
|
|
86
|
+
[["ST_IDLE", [
|
|
87
|
+
["EV_SAVE_RECORD", () => 0, null],
|
|
88
|
+
["EV_RECORD_CHANGED", () => 0, null],
|
|
89
|
+
]]],
|
|
90
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
91
|
+
);
|
|
92
|
+
register_c_yui_form();
|
|
93
|
+
yuno = gobj_create_yuno("form_rearm_yuno", "C_TEST_RA_HOST", {});
|
|
94
|
+
gobj_start(yuno);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
let seq = 0;
|
|
98
|
+
|
|
99
|
+
function build(rows)
|
|
100
|
+
{
|
|
101
|
+
const app = gobj_create_pure_child(`raapp${++seq}`, "C_TEST_RA_APP", {}, yuno);
|
|
102
|
+
gobj_start(app);
|
|
103
|
+
const form = gobj_create_pure_child(`raform${seq}`, "C_YUI_FORM", {
|
|
104
|
+
template: [
|
|
105
|
+
{id: "id", header: "id", type: "string", flag: ["persistent", "required"]},
|
|
106
|
+
{
|
|
107
|
+
id: "rows", header: "rows", type: "array",
|
|
108
|
+
flag: ["persistent", "writable", "table"],
|
|
109
|
+
table: {k: ""},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
record: {id: "a", rows: rows || []},
|
|
113
|
+
editable: true,
|
|
114
|
+
}, app);
|
|
115
|
+
gobj_start(form);
|
|
116
|
+
return {app, form};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
describe("a form with a table, destroyed right after", () => {
|
|
120
|
+
test("an undo: the deferred re-wiring does not throw", async () => {
|
|
121
|
+
const {form} = build();
|
|
122
|
+
expect(tables.length).toBeGreaterThan(0);
|
|
123
|
+
const errors = [];
|
|
124
|
+
const on_error = (e) => {
|
|
125
|
+
errors.push(e);
|
|
126
|
+
};
|
|
127
|
+
process.on("uncaughtException", on_error);
|
|
128
|
+
|
|
129
|
+
gobj_send_event(form, "EV_UNDO_RECORD", {}, form);
|
|
130
|
+
gobj_stop(form);
|
|
131
|
+
gobj_destroy(form);
|
|
132
|
+
await new Promise(resolve => setTimeout(resolve, 260));
|
|
133
|
+
|
|
134
|
+
process.off("uncaughtException", on_error);
|
|
135
|
+
expect(errors).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("a live form is still re-wired", async () => {
|
|
139
|
+
const {form} = build();
|
|
140
|
+
const table = tables[tables.length - 1];
|
|
141
|
+
gobj_send_event(form, "EV_UNDO_RECORD", {}, form);
|
|
142
|
+
await new Promise(resolve => setTimeout(resolve, 260));
|
|
143
|
+
expect(table.externalEvents.events["dataChanged"].length).toBe(1);
|
|
144
|
+
gobj_stop(form);
|
|
145
|
+
gobj_destroy(form);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a loaded row reaches its table through EV_ADD_TABLE_ROW's table id", async () => {
|
|
149
|
+
const before = tables.length;
|
|
150
|
+
const {form} = build([{k: "x"}, {k: "y"}]);
|
|
151
|
+
const table = tables.slice(before).find(tb => tb.added.length > 0);
|
|
152
|
+
expect(table).toBeTruthy();
|
|
153
|
+
expect(table.added).toEqual([{k: "x"}, {k: "y"}]);
|
|
154
|
+
gobj_stop(form);
|
|
155
|
+
gobj_destroy(form);
|
|
156
|
+
await new Promise(resolve => setTimeout(resolve, 60));
|
|
157
|
+
});
|
|
158
|
+
});
|
package/src/form_toolbar_plan.js
CHANGED
|
@@ -64,11 +64,11 @@ function plan_toolbar(wanted)
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
67
|
+
/* With one group only, `space-between` puts the button against one
|
|
68
|
+
* edge and the whole gap on the other side: a dialog of one action
|
|
69
|
+
* looks better centred. It is decided here and not in the caller's
|
|
70
|
+
* CSS, because the class that spreads them is a Bulma helper, and
|
|
71
|
+
* those carry `!important`: an app rule cannot win over them. */
|
|
72
72
|
const single_group = (left.length === 0) !== (right.length === 0);
|
|
73
73
|
|
|
74
74
|
return {left, right, unknown, single_group};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* g6_event_kw.js
|
|
3
|
+
*
|
|
4
|
+
* The kw an FSM event carries for a G6 pointer event: an identity
|
|
5
|
+
* and three scalars, never the event. Shared by the three graphs
|
|
6
|
+
* (C_G6_NODES_TREE, C_YUI_JSON_GRAPH, C_YUI_GOBJ_TREE_JS), which
|
|
7
|
+
* each had a copy.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026, ArtGins.
|
|
10
|
+
* All Rights Reserved.
|
|
11
|
+
***********************************************************************/
|
|
12
|
+
|
|
13
|
+
/************************************************************
|
|
14
|
+
* A G6 event, as PLAIN JSON.
|
|
15
|
+
*
|
|
16
|
+
* A kw is dumped by the `machine` trace (`trace_json(kw)`), and a
|
|
17
|
+
* G6 / @antv/g event is circular: serializing one THROWS, so the
|
|
18
|
+
* first thing a kw carrying `evt` breaks is the trace the FSM
|
|
19
|
+
* exists to feed. It also drags a live graph element into a
|
|
20
|
+
* message that may be read after that element is gone.
|
|
21
|
+
*
|
|
22
|
+
* What the actions read of it is an id and three scalars. The
|
|
23
|
+
* event itself never leaves the callback that received it.
|
|
24
|
+
************************************************************/
|
|
25
|
+
export function g6_event_kw(evt)
|
|
26
|
+
{
|
|
27
|
+
let target = (evt && evt.target)? evt.target : null;
|
|
28
|
+
let client = (evt && evt.client)? evt.client : null;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
id: (target && target.id)? String(target.id) : "",
|
|
32
|
+
shift: !!(evt && evt.shiftKey),
|
|
33
|
+
client_x: (client && typeof client.x === "number")? client.x : 0,
|
|
34
|
+
client_y: (client && typeof client.y === "number")? client.y : 0
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* map_stop_windows.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* C_YUI_MAP opens one C_YUI_WINDOW per marker clicked, as its own
|
|
5
|
+
* child. A C_YUI_WINDOW has no mt_stop: stopping the map with the
|
|
6
|
+
* framework's gobj_stop_children() left each one on screen, holding
|
|
7
|
+
* its service name, so the next click on that marker found the old
|
|
8
|
+
* window. mt_stop destroys them.
|
|
9
|
+
*
|
|
10
|
+
* maplibre is replaced by a stand-in: the test is about the gobjs,
|
|
11
|
+
* not about a map, and node has no WebGL.
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2026, ArtGins.
|
|
14
|
+
* All Rights Reserved.
|
|
15
|
+
***********************************************************************/
|
|
16
|
+
import {describe, test, expect, beforeAll, vi} from "vitest";
|
|
17
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
18
|
+
|
|
19
|
+
install_dom_double();
|
|
20
|
+
|
|
21
|
+
vi.mock("maplibre-gl", () => {
|
|
22
|
+
class Map {
|
|
23
|
+
on() {
|
|
24
|
+
}
|
|
25
|
+
addControl() {
|
|
26
|
+
}
|
|
27
|
+
getCanvasContainer() {
|
|
28
|
+
return {querySelector: () => null};
|
|
29
|
+
}
|
|
30
|
+
remove() {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class NavigationControl {
|
|
34
|
+
}
|
|
35
|
+
class GeolocateControl {
|
|
36
|
+
}
|
|
37
|
+
class Popup {
|
|
38
|
+
}
|
|
39
|
+
return {Map, NavigationControl, GeolocateControl, Popup};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
SDATA, SDATA_END, data_type_t, gclass_create,
|
|
44
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
45
|
+
gobj_start, gobj_stop, gobj_find_service, gobj_is_destroying, gobj_send_event,
|
|
46
|
+
set_log_callback,
|
|
47
|
+
} = await import("@yuneta/gobj-js");
|
|
48
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
49
|
+
const {register_c_yui_map} = await import("./c_yui_map.js");
|
|
50
|
+
|
|
51
|
+
const logged = [];
|
|
52
|
+
let yuno = null;
|
|
53
|
+
|
|
54
|
+
beforeAll(async () => {
|
|
55
|
+
const i18next = (await import("i18next")).default;
|
|
56
|
+
await i18next.init({lng: "en", resources: {}});
|
|
57
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
58
|
+
set_log_callback((level, msg) => {
|
|
59
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
60
|
+
});
|
|
61
|
+
gclass_create("C_TEST_MAP_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
62
|
+
gclass_create(
|
|
63
|
+
"C_TEST_MAP_DEVICE", [], [["ST_IDLE", []]], {}, 0,
|
|
64
|
+
[SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "What its window shows"), SDATA_END()],
|
|
65
|
+
{}, 0, 0, 0, 0
|
|
66
|
+
);
|
|
67
|
+
register_c_yui_window();
|
|
68
|
+
register_c_yui_map();
|
|
69
|
+
yuno = gobj_create_yuno("map_yuno", "C_TEST_MAP_HOST", {});
|
|
70
|
+
gobj_start(yuno);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function errors()
|
|
74
|
+
{
|
|
75
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe("C_YUI_MAP stopped with marker windows open", () => {
|
|
79
|
+
test("destroys them, so their service names are free again", () => {
|
|
80
|
+
const host = gobj_create("map_host", "C_TEST_MAP_HOST", {}, yuno);
|
|
81
|
+
gobj_start(host);
|
|
82
|
+
const device = gobj_create_service("dev1", "C_TEST_MAP_DEVICE",
|
|
83
|
+
{$container: document.createElement("div")}, host);
|
|
84
|
+
gobj_start(device);
|
|
85
|
+
const map = gobj_create("map1", "C_YUI_MAP",
|
|
86
|
+
{$map: document.createElement("div")}, host);
|
|
87
|
+
gobj_start(map);
|
|
88
|
+
logged.length = 0;
|
|
89
|
+
|
|
90
|
+
gobj_send_marker_click(map, "dev1");
|
|
91
|
+
const win = gobj_find_service("window-map-dev1", false);
|
|
92
|
+
expect(win).toBeTruthy();
|
|
93
|
+
|
|
94
|
+
gobj_stop(map);
|
|
95
|
+
expect(gobj_is_destroying(win)).toBe(true);
|
|
96
|
+
expect(gobj_find_service("window-map-dev1", false)).toBe(null);
|
|
97
|
+
|
|
98
|
+
/* Started again, the marker opens a NEW window. */
|
|
99
|
+
gobj_start(map);
|
|
100
|
+
gobj_send_marker_click(map, "dev1");
|
|
101
|
+
const again = gobj_find_service("window-map-dev1", false);
|
|
102
|
+
expect(again).toBeTruthy();
|
|
103
|
+
expect(again).not.toBe(win);
|
|
104
|
+
expect(errors()).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/* As the marker's click handler sends it. */
|
|
109
|
+
function gobj_send_marker_click(map, service_name)
|
|
110
|
+
{
|
|
111
|
+
return gobj_send_event(map, "EV_MARKER_CLICKED", {gobj_service_name: service_name}, map);
|
|
112
|
+
}
|
package/src/nav_cards_helpers.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* Copyright (c) 2026, ArtGins.
|
|
12
12
|
* All Rights Reserved.
|
|
13
13
|
***********************************************************************/
|
|
14
|
+
import {text_node} from "./yui_text.js";
|
|
14
15
|
|
|
15
16
|
/************************************************************
|
|
16
17
|
* Descriptor of one card: an <a> carrying the same data-*
|
|
@@ -28,7 +29,7 @@ export function card_descriptor(it, show_label)
|
|
|
28
29
|
["i", {class: it.icon, "aria-hidden": "true"}]]);
|
|
29
30
|
}
|
|
30
31
|
if(show_label && label) {
|
|
31
|
-
children.push(["span", {class: "yui-nav-label", i18n: label}, label]);
|
|
32
|
+
children.push(["span", {class: "yui-nav-label", i18n: label}, text_node(label)]);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
let a_attrs = {
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
* nav_cards_helpers.test.js
|
|
3
3
|
*
|
|
4
4
|
* Unit tests for the pure "cards" layout descriptor builders.
|
|
5
|
-
* Descriptors are plain createElement2 arrays
|
|
5
|
+
* Descriptors are plain createElement2 arrays; the label is a Text
|
|
6
|
+
* node (data, never markup), so a document double is installed.
|
|
6
7
|
***********************************************************************/
|
|
7
8
|
import { test, expect } from "vitest";
|
|
9
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
10
|
+
|
|
11
|
+
install_dom_double();
|
|
8
12
|
import {
|
|
9
13
|
card_descriptor,
|
|
10
14
|
cards_grid_descriptor,
|
|
@@ -35,7 +39,7 @@ test("card carries the nav item data-* contract", () => {
|
|
|
35
39
|
let [label_tag, label_attrs, label_text] = children[1];
|
|
36
40
|
expect(label_tag).toBe("span");
|
|
37
41
|
expect(label_attrs.i18n).toBe("budgets");
|
|
38
|
-
expect(label_text).toBe("budgets");
|
|
42
|
+
expect(label_text.textContent).toBe("budgets");
|
|
39
43
|
});
|
|
40
44
|
|
|
41
45
|
test("card without icon renders label only", () => {
|
|
@@ -45,7 +49,7 @@ test("card without icon renders label only", () => {
|
|
|
45
49
|
);
|
|
46
50
|
expect(children.length).toBe(1);
|
|
47
51
|
expect(children[0][0]).toBe("span");
|
|
48
|
-
expect(children[0][2]).toBe("x label");
|
|
52
|
+
expect(children[0][2].textContent).toBe("x label");
|
|
49
53
|
});
|
|
50
54
|
|
|
51
55
|
test("show_label=false drops the label span", () => {
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* overlay_marker_after_back.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* An overlay registered while a history.back() of the shell is
|
|
5
|
+
* still in flight. The common case: a floating window asks about
|
|
6
|
+
* unsaved changes on Back, and the user answers with a BUTTON
|
|
7
|
+
* (Cancel). The question's close calls history.back() to retire its
|
|
8
|
+
* marker -- asynchronous -- and in the same turn the window takes
|
|
9
|
+
* its entry back with pushState, which is synchronous. The marker
|
|
10
|
+
* landed before the traversal, the traversal then ran FROM it, and
|
|
11
|
+
* the window's marker was left orphaned ahead of the question's
|
|
12
|
+
* dead one.
|
|
13
|
+
*
|
|
14
|
+
* The history here is a model of a browser's session history: a
|
|
15
|
+
* list and an index, pushState truncating what is ahead, and
|
|
16
|
+
* back() traversing on a later task, from whatever entry is current
|
|
17
|
+
* THEN.
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2026, ArtGins.
|
|
20
|
+
* All Rights Reserved.
|
|
21
|
+
***********************************************************************/
|
|
22
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
23
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
24
|
+
|
|
25
|
+
install_dom_double();
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
SDATA_END, gclass_create,
|
|
29
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
30
|
+
gobj_start, gobj_read_attr, gobj_is_destroying,
|
|
31
|
+
set_log_callback,
|
|
32
|
+
} = await import("@yuneta/gobj-js");
|
|
33
|
+
const {register_c_yui_shell} = await import("./c_yui_shell.js");
|
|
34
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
35
|
+
|
|
36
|
+
const logged = [];
|
|
37
|
+
let veto = true;
|
|
38
|
+
let warning = null;
|
|
39
|
+
let yuno = null;
|
|
40
|
+
|
|
41
|
+
/* The session history of one tab. */
|
|
42
|
+
const session = {entries: [{state: null}], index: 0};
|
|
43
|
+
|
|
44
|
+
function install_history_model()
|
|
45
|
+
{
|
|
46
|
+
session.entries = [{state: null}];
|
|
47
|
+
session.index = 0;
|
|
48
|
+
window.history = {
|
|
49
|
+
get state() {
|
|
50
|
+
return session.entries[session.index].state;
|
|
51
|
+
},
|
|
52
|
+
get length() {
|
|
53
|
+
return session.entries.length;
|
|
54
|
+
},
|
|
55
|
+
pushState(state) {
|
|
56
|
+
session.entries.splice(session.index + 1);
|
|
57
|
+
session.entries.push({state: state});
|
|
58
|
+
session.index++;
|
|
59
|
+
},
|
|
60
|
+
replaceState(state) {
|
|
61
|
+
session.entries[session.index] = {state: state};
|
|
62
|
+
},
|
|
63
|
+
back() {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
if(session.index > 0) {
|
|
66
|
+
session.index--;
|
|
67
|
+
fire_popstate();
|
|
68
|
+
}
|
|
69
|
+
}, 0);
|
|
70
|
+
},
|
|
71
|
+
forward() {
|
|
72
|
+
},
|
|
73
|
+
go() {
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fire_popstate()
|
|
79
|
+
{
|
|
80
|
+
const ev = new Event("popstate");
|
|
81
|
+
ev.state = window.history.state;
|
|
82
|
+
window.dispatchEvent(ev);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* The user's Back: the browser's own traversal. */
|
|
86
|
+
function user_back()
|
|
87
|
+
{
|
|
88
|
+
session.index--;
|
|
89
|
+
fire_popstate();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function next_task()
|
|
93
|
+
{
|
|
94
|
+
return new Promise(resolve => setTimeout(resolve, 0));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
beforeAll(async () => {
|
|
98
|
+
const i18next = (await import("i18next")).default;
|
|
99
|
+
await i18next.init({lng: "en", resources: {}});
|
|
100
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
101
|
+
set_log_callback((level, msg) => {
|
|
102
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
103
|
+
});
|
|
104
|
+
gclass_create("C_TEST_MARKER_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
105
|
+
gclass_create(
|
|
106
|
+
"C_TEST_MARKER_APP",
|
|
107
|
+
[["EV_WINDOW_TO_CLOSE", 0]],
|
|
108
|
+
[["ST_IDLE", [
|
|
109
|
+
["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
|
|
110
|
+
kw.abort_close = veto;
|
|
111
|
+
if(warning) {
|
|
112
|
+
kw.warning = warning;
|
|
113
|
+
}
|
|
114
|
+
return 0;
|
|
115
|
+
}, null]
|
|
116
|
+
]]],
|
|
117
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
118
|
+
);
|
|
119
|
+
register_c_yui_shell();
|
|
120
|
+
register_c_yui_window();
|
|
121
|
+
yuno = gobj_create_yuno("marker_yuno", "C_TEST_MARKER_HOST", {});
|
|
122
|
+
gobj_start(yuno);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
beforeEach(() => {
|
|
126
|
+
logged.length = 0;
|
|
127
|
+
veto = true;
|
|
128
|
+
warning = null;
|
|
129
|
+
install_history_model();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
function errors()
|
|
133
|
+
{
|
|
134
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
describe("an overlay registered while a back() of ours is in flight", () => {
|
|
138
|
+
test("the window's marker lands where it belongs, and the next Back closes it", async () => {
|
|
139
|
+
const app = gobj_create("mapp", "C_TEST_MARKER_APP", {}, yuno);
|
|
140
|
+
gobj_start(app);
|
|
141
|
+
const shell = gobj_create("mshell", "C_YUI_SHELL",
|
|
142
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
143
|
+
gobj_start(shell);
|
|
144
|
+
logged.length = 0; /* the shell's own start: no route table here */
|
|
145
|
+
install_history_model();
|
|
146
|
+
|
|
147
|
+
const win = gobj_create_service("mwin", "C_YUI_WINDOW",
|
|
148
|
+
{subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
|
|
149
|
+
gobj_start(win);
|
|
150
|
+
expect(session.entries.length).toBe(2);
|
|
151
|
+
warning = "unsaved changes";
|
|
152
|
+
|
|
153
|
+
/* Back: the window asks. */
|
|
154
|
+
user_back();
|
|
155
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
156
|
+
const question = shell.priv.overlay_stack[0];
|
|
157
|
+
expect(question).toBeTruthy();
|
|
158
|
+
expect(window.history.state).toEqual({__yui_overlay__: question.id});
|
|
159
|
+
|
|
160
|
+
/* The user answers with the Cancel BUTTON, not with Back. */
|
|
161
|
+
const $cancel = document.querySelector('.CONFIRM_BTN[data-modal-button-value="cancel"]');
|
|
162
|
+
expect($cancel).toBeTruthy();
|
|
163
|
+
$cancel.click();
|
|
164
|
+
await next_task();
|
|
165
|
+
await next_task();
|
|
166
|
+
|
|
167
|
+
const entry = gobj_read_attr(win, "back_overlay");
|
|
168
|
+
expect(entry).toBeTruthy();
|
|
169
|
+
expect(shell.priv.overlay_stack).toEqual([entry]);
|
|
170
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
171
|
+
/* One route entry and the window's marker, current: nothing
|
|
172
|
+
* orphaned ahead, no dead question's marker under it. */
|
|
173
|
+
expect(session.entries.length).toBe(2);
|
|
174
|
+
expect(window.history.state).toEqual({__yui_overlay__: entry.id});
|
|
175
|
+
|
|
176
|
+
/* And the user's next Back is the window's, not swallowed. */
|
|
177
|
+
veto = false;
|
|
178
|
+
warning = null;
|
|
179
|
+
user_back();
|
|
180
|
+
expect(gobj_is_destroying(win)).toBe(true);
|
|
181
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
182
|
+
expect(errors()).toEqual([]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("an overlay closed before its marker was pushed leaves no marker", async () => {
|
|
186
|
+
const app = gobj_create("mapp2", "C_TEST_MARKER_APP", {}, yuno);
|
|
187
|
+
gobj_start(app);
|
|
188
|
+
const shell = gobj_create("mshell2", "C_YUI_SHELL",
|
|
189
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
190
|
+
gobj_start(shell);
|
|
191
|
+
logged.length = 0;
|
|
192
|
+
install_history_model();
|
|
193
|
+
|
|
194
|
+
const {yui_shell_register_overlay, yui_shell_overlay_dismissed} =
|
|
195
|
+
await import("./c_yui_shell.js");
|
|
196
|
+
const first = yui_shell_register_overlay(shell, () => {});
|
|
197
|
+
expect(session.entries.length).toBe(2);
|
|
198
|
+
yui_shell_overlay_dismissed(shell, first); // back() in flight
|
|
199
|
+
const second = yui_shell_register_overlay(shell, () => {});
|
|
200
|
+
expect(second.marker_pending).toBe(true);
|
|
201
|
+
yui_shell_overlay_dismissed(shell, second); // gone before its marker
|
|
202
|
+
await next_task();
|
|
203
|
+
await next_task();
|
|
204
|
+
|
|
205
|
+
expect(shell.priv.overlay_stack).toEqual([]);
|
|
206
|
+
expect(shell.priv.expected_pops).toBe(0);
|
|
207
|
+
expect(session.entries.length).toBe(2); // the dead first marker, ahead
|
|
208
|
+
expect(session.index).toBe(0);
|
|
209
|
+
expect(window.history.state).toBe(null);
|
|
210
|
+
expect(errors()).toEqual([]);
|
|
211
|
+
});
|
|
212
|
+
});
|
package/src/schema_to_c.js
CHANGED
|
@@ -279,6 +279,16 @@ const JSON_SHORT_ESCAPES = {"\n": "n", "\r": "r", "\t": "t", "\b": "b", "\f": "f
|
|
|
279
279
|
|
|
280
280
|
function json_control(ch)
|
|
281
281
|
{
|
|
282
|
+
/* A NUL has no way through: jansson refuses "\u0000" in a string
|
|
283
|
+
* unless the loader passes JSON_ALLOW_NUL, which the yunos do not, so
|
|
284
|
+
* the whole schema would fail to load. It is written as U+FFFD, the
|
|
285
|
+
* replacement character -- visible in the literal and on screen, not
|
|
286
|
+
* dropped without a trace (this module is dependency-free on purpose:
|
|
287
|
+
* scripts/schema_diagram.mjs loads it with no npm install, so it has
|
|
288
|
+
* no log to write to). */
|
|
289
|
+
if(ch === "\u0000") {
|
|
290
|
+
return C_BACKSLASH + "ufffd";
|
|
291
|
+
}
|
|
282
292
|
let short = JSON_SHORT_ESCAPES[ch];
|
|
283
293
|
if(short) {
|
|
284
294
|
return C_BACKSLASH + short;
|
package/src/schema_to_c.test.js
CHANGED
|
@@ -17,7 +17,8 @@ import { schema_to_diagram } from "./schema_to_diagram.js";
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
/***************************************************************
|
|
20
|
-
*
|
|
20
|
+
* A JS MODEL of the yuno's loader (not the C code itself) --
|
|
21
|
+
* what the yuno does to the literal before parsing it:
|
|
21
22
|
* 1. the C compiler resolves `\<newline>` continuations and
|
|
22
23
|
* the `\\` / `\"` escapes,
|
|
23
24
|
* 2. helper_quote2doublequote() turns EVERY ' into ",
|
|
@@ -235,6 +236,12 @@ describe("the characters that cannot be written as themselves", () => {
|
|
|
235
236
|
expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe(header);
|
|
236
237
|
});
|
|
237
238
|
|
|
239
|
+
test("a NUL becomes U+FFFD: jansson refuses \\u0000 without JSON_ALLOW_NUL", () => {
|
|
240
|
+
const src = with_header("a\u0000b");
|
|
241
|
+
expect(src.includes("u0000")).toBe(false);
|
|
242
|
+
expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe("a\ufffdb");
|
|
243
|
+
});
|
|
244
|
+
|
|
238
245
|
test("all three at once", () => {
|
|
239
246
|
const header = 'a\\b "c" d\'e';
|
|
240
247
|
expect(load_like_the_yuno(with_header(header)).topics[0].cols.id.header)
|
package/src/shell_modals.js
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
yui_shell_register_overlay,
|
|
48
48
|
yui_shell_overlay_dismissed,
|
|
49
49
|
} from "./c_yui_shell.js";
|
|
50
|
+
import {text_node} from "./yui_text.js";
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
/***************************************************************
|
|
@@ -154,7 +155,8 @@ function show_notification(shell, kind, message, opts)
|
|
|
154
155
|
[
|
|
155
156
|
["button", {class: "TOAST_CLOSE delete", title: t("close"), "data-i18n-title": "close",
|
|
156
157
|
"aria-label": t("close"), "data-i18n-aria-label": "close"}],
|
|
157
|
-
["p", {...p_attrs, class: "TOAST_MSG"},
|
|
158
|
+
["p", {...p_attrs, class: "TOAST_MSG"},
|
|
159
|
+
(typeof message === "string")? text_node(message) : message]
|
|
158
160
|
]
|
|
159
161
|
]
|
|
160
162
|
);
|
|
@@ -281,9 +283,9 @@ export function yui_shell_show_modal(shell, content, opts)
|
|
|
281
283
|
"aria-label": t("back"), "data-i18n-aria-label": "back"},
|
|
282
284
|
[["i", {class: "yi-arrow-left"}]]],
|
|
283
285
|
["span", {class: "MODAL_TITLE yui-dialog-title"},
|
|
284
|
-
(title_prefix ? [["span", {class: "MODAL_TITLE_PREFIX"}, title_prefix]] : [])
|
|
286
|
+
(title_prefix ? [["span", {class: "MODAL_TITLE_PREFIX"}, text_node(title_prefix)]] : [])
|
|
285
287
|
.concat(title
|
|
286
|
-
? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, title]]
|
|
288
|
+
? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, text_node(title)]]
|
|
287
289
|
: [])],
|
|
288
290
|
["button", {class: "MODAL_CLOSE yui-dialog-x", type: "button", title: t("close"), "data-i18n-title": "close",
|
|
289
291
|
"aria-label": t("close"), "data-i18n-aria-label": "close"},
|
|
@@ -492,7 +494,7 @@ function build_dialog(shell, message, buttons, opts)
|
|
|
492
494
|
let icon = CONFIRM_TYPE_ICONS[type] || CONFIRM_TYPE_ICONS["question"];
|
|
493
495
|
|
|
494
496
|
let $body_children = (typeof message === "string")
|
|
495
|
-
? [["p", {class: "CONFIRM_MSG yui-confirm-msg", i18n: message}, message]]
|
|
497
|
+
? [["p", {class: "CONFIRM_MSG yui-confirm-msg", i18n: message}, text_node(message)]]
|
|
496
498
|
: [message];
|
|
497
499
|
|
|
498
500
|
let $footer_children = buttons.map(b => {
|
|
@@ -525,7 +527,7 @@ function build_dialog(shell, message, buttons, opts)
|
|
|
525
527
|
if(!empty_string(title)) {
|
|
526
528
|
$card_children.push(
|
|
527
529
|
["p", {class: "CONFIRM_TITLE yui-confirm-title has-text-centered",
|
|
528
|
-
i18n: title}, title]
|
|
530
|
+
i18n: title}, text_node(title)]
|
|
529
531
|
);
|
|
530
532
|
}
|
|
531
533
|
$card_children.push(
|