@yuneta/gobj-ui 7.26.8 → 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 +164 -59
- package/dist/gobj-ui.es.js +164 -59
- package/package.json +2 -2
- package/src/c_g6_nodes_tree.js +37 -7
- package/src/c_yui_form.js +39 -6
- package/src/c_yui_gclass.js +1 -1
- package/src/c_yui_gobj_tree_js.js +6 -2
- package/src/c_yui_nav.js +2 -2
- package/src/c_yui_schema_editor.js +22 -22
- package/src/c_yui_shell.js +57 -3
- package/src/c_yui_treedb_topic_with_form.js +4 -4
- package/src/c_yui_treedb_topics.js +9 -9
- package/src/c_yui_window.js +1 -1
- package/src/form_toolbar_plan.js +5 -5
- package/src/map_stop_windows.wiring.test.js +112 -0
- package/src/overlay_marker_after_back.wiring.test.js +212 -0
- package/src/shell_modals.js +2 -2
- package/src/vite_plugin_yuneta_html.test.js +17 -2
- 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 +2 -2
- package/src/yui_text.js +12 -0
- package/src/yui_text.test.js +29 -1
- package/vite-plugin-yuneta-html.js +15 -1
|
@@ -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
|
+
}
|
|
@@ -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/shell_modals.js
CHANGED
|
@@ -285,7 +285,7 @@ export function yui_shell_show_modal(shell, content, opts)
|
|
|
285
285
|
["span", {class: "MODAL_TITLE yui-dialog-title"},
|
|
286
286
|
(title_prefix ? [["span", {class: "MODAL_TITLE_PREFIX"}, text_node(title_prefix)]] : [])
|
|
287
287
|
.concat(title
|
|
288
|
-
? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, title]]
|
|
288
|
+
? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, text_node(title)]]
|
|
289
289
|
: [])],
|
|
290
290
|
["button", {class: "MODAL_CLOSE yui-dialog-x", type: "button", title: t("close"), "data-i18n-title": "close",
|
|
291
291
|
"aria-label": t("close"), "data-i18n-aria-label": "close"},
|
|
@@ -527,7 +527,7 @@ function build_dialog(shell, message, buttons, opts)
|
|
|
527
527
|
if(!empty_string(title)) {
|
|
528
528
|
$card_children.push(
|
|
529
529
|
["p", {class: "CONFIRM_TITLE yui-confirm-title has-text-centered",
|
|
530
|
-
i18n: title}, title]
|
|
530
|
+
i18n: title}, text_node(title)]
|
|
531
531
|
);
|
|
532
532
|
}
|
|
533
533
|
$card_children.push(
|
|
@@ -65,15 +65,30 @@ describe("vite-plugin-yuneta-html", () => {
|
|
|
65
65
|
err.mockRestore();
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
test("an entry that is not a single source is refused, the rest kept", () => {
|
|
69
|
+
const err = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
70
|
+
const html = transform({
|
|
71
|
+
title: "App",
|
|
72
|
+
csp_connect_src: [
|
|
73
|
+
"wss://a:1; base-uri *", "wss://b, wss://c", "wss://d wss://e",
|
|
74
|
+
"wss://ok:1620"
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
expect(connect_src(html)).toEqual(["'self'", "wss://ok:1620"]);
|
|
78
|
+
expect(html).not.toContain("base-uri");
|
|
79
|
+
expect(err).toHaveBeenCalledTimes(3);
|
|
80
|
+
err.mockRestore();
|
|
81
|
+
});
|
|
82
|
+
|
|
68
83
|
test("what config.json says is escaped where it lands in markup", () => {
|
|
69
84
|
const html = transform({
|
|
70
85
|
title: "</title><script>x()</script>",
|
|
71
86
|
metadata: {description: '"><b>'},
|
|
72
|
-
csp_connect_src: ['wss://a"
|
|
87
|
+
csp_connect_src: ['wss://a"onload="x']
|
|
73
88
|
});
|
|
74
89
|
expect(html).not.toContain("<script>");
|
|
75
90
|
expect(html).toContain("</title><script>");
|
|
76
91
|
expect(html).not.toContain('content=""><b>"');
|
|
77
|
-
expect(html).not.toContain('wss://a"
|
|
92
|
+
expect(html).not.toContain('wss://a"onload');
|
|
78
93
|
});
|
|
79
94
|
});
|
package/src/yui_asset.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "@yuneta/gobj-js";
|
|
21
21
|
|
|
22
22
|
import {t} from "i18next";
|
|
23
|
+
import {text_node} from "./yui_text.js";
|
|
23
24
|
|
|
24
25
|
import "./yui_asset.css";
|
|
25
26
|
|
|
@@ -357,10 +358,10 @@ function yui_asset_element(answer, opts = {})
|
|
|
357
358
|
|
|
358
359
|
if(kind === "other") {
|
|
359
360
|
const children = [
|
|
360
|
-
["span", {class: "ASSET_OTHER_TYPE"},
|
|
361
|
+
["span", {class: "ASSET_OTHER_TYPE"}, text_node(answer.content_type || "?")]
|
|
361
362
|
];
|
|
362
363
|
if(opts.detail) {
|
|
363
|
-
children.push(["span", {class: "ASSET_OTHER_DETAIL"},
|
|
364
|
+
children.push(["span", {class: "ASSET_OTHER_DETAIL"}, text_node(opts.detail)]);
|
|
364
365
|
}
|
|
365
366
|
const $card = createElement2(["div", {class: `${cls} ASSET_OTHER`}, children]);
|
|
366
367
|
const $open = yui_asset_open_link(answer);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_data_color.js
|
|
3
|
+
*
|
|
4
|
+
* A colour read from DATA, checked before it goes into markup.
|
|
5
|
+
*
|
|
6
|
+
* A card of the treedb graph is html, and the colour a user gave it
|
|
7
|
+
* (a `__graphs__` record) is written into its `style="..."`. A value
|
|
8
|
+
* like `red" onmouseover="...` would leave the attribute and run.
|
|
9
|
+
* Only the plain colour syntaxes pass -- hex, the rgb()/hsl()
|
|
10
|
+
* functions, a name -- and the browser, where it can, also checks
|
|
11
|
+
* that it is a colour.
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2026, ArtGins.
|
|
14
|
+
* All Rights Reserved.
|
|
15
|
+
***********************************************************************/
|
|
16
|
+
|
|
17
|
+
const DATA_COLOR_RE = /^(#[0-9a-f]{3,8}|(rgb|rgba|hsl|hsla)\([0-9.,%\s/+-]+\)|[a-z]+)$/i;
|
|
18
|
+
|
|
19
|
+
/************************************************************
|
|
20
|
+
* `value` when it is a css colour, else null.
|
|
21
|
+
************************************************************/
|
|
22
|
+
export function css_color_or_null(value)
|
|
23
|
+
{
|
|
24
|
+
if(typeof value !== "string" || !DATA_COLOR_RE.test(value)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if(typeof CSS !== "undefined" && CSS && typeof CSS.supports === "function") {
|
|
28
|
+
if(!CSS.supports("color", value)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_data_color.test.js
|
|
3
|
+
*
|
|
4
|
+
* A colour from data goes into a card's `style="..."`: only a
|
|
5
|
+
* colour passes.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2026, ArtGins.
|
|
8
|
+
* All Rights Reserved.
|
|
9
|
+
***********************************************************************/
|
|
10
|
+
import {describe, test, expect} from "vitest";
|
|
11
|
+
import {css_color_or_null} from "./yui_data_color.js";
|
|
12
|
+
|
|
13
|
+
describe("css_color_or_null", () => {
|
|
14
|
+
test("the colour syntaxes pass", () => {
|
|
15
|
+
for(const c of ["#abc", "#AABBCC", "#aabbcc80", "red", "rgb(1, 2, 3)",
|
|
16
|
+
"rgba(1,2,3,0.5)", "hsl(120 50% 50%)", "hsla(120, 50%, 50%, .2)"]) {
|
|
17
|
+
expect(css_color_or_null(c)).toBe(c);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("anything that could leave the attribute does not", () => {
|
|
22
|
+
for(const c of ['red" onmouseover="x()', "red; background:url(x)", "url(x)",
|
|
23
|
+
"<b>", "red\"", "expression(alert(1))", "", " red", 5, null, {}]) {
|
|
24
|
+
expect(css_color_or_null(c)).toBe(null);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
package/src/yui_dev.js
CHANGED
|
@@ -640,7 +640,7 @@ function traffic_scalar_row(key, value)
|
|
|
640
640
|
|
|
641
641
|
return ['div', {class: 'TRAFFIC_ROW'}, [
|
|
642
642
|
['span', {class: 'TRAFFIC_BULLET'}, '•'],
|
|
643
|
-
['span', {class: 'TRAFFIC_KEY'}, key + ':'],
|
|
643
|
+
['span', {class: 'TRAFFIC_KEY'}, text_node(key + ':')],
|
|
644
644
|
['span', {}, val_children],
|
|
645
645
|
]];
|
|
646
646
|
}
|
|
@@ -744,7 +744,7 @@ function traffic_value_node(key, value)
|
|
|
744
744
|
if(count === 0) {
|
|
745
745
|
return ['div', {class: 'TRAFFIC_ROW'}, [
|
|
746
746
|
['span', {class: 'TRAFFIC_BULLET'}, '•'],
|
|
747
|
-
['span', {class: 'TRAFFIC_KEY'}, key + ':'],
|
|
747
|
+
['span', {class: 'TRAFFIC_KEY'}, text_node(key + ':')],
|
|
748
748
|
['span', {class: 'TRAFFIC_VAL t-empty'}, is_arr ? '[ ]' : '{ }'],
|
|
749
749
|
]];
|
|
750
750
|
}
|
package/src/yui_text.js
CHANGED
|
@@ -29,3 +29,15 @@ export function text_node(value)
|
|
|
29
29
|
}
|
|
30
30
|
return document.createTextNode(String(value).trim());
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
/************************************************************
|
|
34
|
+
* A Tabulator `titleFormatter` that shows the column title as text.
|
|
35
|
+
*
|
|
36
|
+
* Tabulator puts a STRING title in with innerHTML, so a title taken
|
|
37
|
+
* from a schema (`header`, which the schema editor writes) is markup
|
|
38
|
+
* unless the column carries a formatter that returns a Node.
|
|
39
|
+
************************************************************/
|
|
40
|
+
export function text_title_formatter(cell)
|
|
41
|
+
{
|
|
42
|
+
return text_node(cell.getValue());
|
|
43
|
+
}
|
package/src/yui_text.test.js
CHANGED
|
@@ -13,7 +13,12 @@ import {install_dom_double} from "../test/dom_double.js";
|
|
|
13
13
|
install_dom_double();
|
|
14
14
|
|
|
15
15
|
const {createElement2} = await import("@yuneta/gobj-js");
|
|
16
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
|
|
18
|
+
gobj_read_attr, set_log_callback
|
|
19
|
+
} = await import("@yuneta/gobj-js");
|
|
20
|
+
const {text_node, text_title_formatter} = await import("./yui_text.js");
|
|
21
|
+
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
17
22
|
const {card_descriptor} = await import("./nav_cards_helpers.js");
|
|
18
23
|
|
|
19
24
|
const EVIL = "<img src=x onerror=alert(1)>";
|
|
@@ -36,4 +41,27 @@ describe("text_node()", () => {
|
|
|
36
41
|
expect($card.querySelector("img")).toBe(null);
|
|
37
42
|
expect($card.textContent).toContain(EVIL);
|
|
38
43
|
});
|
|
44
|
+
|
|
45
|
+
test("a Tabulator column titled from a schema `header` shows it as text", () => {
|
|
46
|
+
const $title = text_title_formatter({getValue: () => EVIL});
|
|
47
|
+
expect($title instanceof Text).toBe(true);
|
|
48
|
+
expect($title.textContent).toBe(EVIL);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("the accordion nav shows a section named by a backend as text", async () => {
|
|
52
|
+
const i18next = (await import("i18next")).default;
|
|
53
|
+
await i18next.init({lng: "en", resources: {}});
|
|
54
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
55
|
+
set_log_callback(() => {});
|
|
56
|
+
gclass_create("C_TEST_TEXT_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
57
|
+
register_c_yui_nav();
|
|
58
|
+
const yuno = gobj_create_yuno("text_yuno", "C_TEST_TEXT_HOST", {});
|
|
59
|
+
const nav = gobj_create("acc", "C_YUI_NAV", {
|
|
60
|
+
layout: "accordion",
|
|
61
|
+
menu_items: [{id: "h", name: EVIL, submenu: {items: [{id: "s", name: EVIL, route: "/s"}]}}]
|
|
62
|
+
}, yuno);
|
|
63
|
+
const $c = gobj_read_attr(nav, "$container");
|
|
64
|
+
expect($c.querySelector("img")).toBe(null);
|
|
65
|
+
expect($c.querySelector(".yui-accordion-head").textContent).toBe(EVIL);
|
|
66
|
+
});
|
|
39
67
|
});
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* - <meta> tags from config.metadata
|
|
8
8
|
* - Content-Security-Policy from config.csp_connect_src
|
|
9
9
|
* (always emitted: connect-src 'self' alone when the
|
|
10
|
-
* list is missing, with a warning
|
|
10
|
+
* list is missing, with a warning; an entry that is
|
|
11
|
+
* not one CSP source -- a `;`, `,` or space -- is refused)
|
|
11
12
|
*
|
|
12
13
|
* Usage in vite.config.js (vendored copy):
|
|
13
14
|
* import { yunetaHtmlPlugin } from "./src/gobj-ui/vite-plugin-yuneta-html.js";
|
|
@@ -107,6 +108,19 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
107
108
|
* attribute, where a quote would end it. */
|
|
108
109
|
origins = config.csp_connect_src
|
|
109
110
|
.filter(s => typeof s === "string" && !s.startsWith("_comment"))
|
|
111
|
+
.filter(s => {
|
|
112
|
+
/* One SOURCE of the CSP grammar: a `;` would
|
|
113
|
+
* open a new directive (`wss://a; base-uri *`),
|
|
114
|
+
* and a `,` or a space would add sources the
|
|
115
|
+
* entry does not name. */
|
|
116
|
+
if (/[;,\s]/.test(s)) {
|
|
117
|
+
console.error(
|
|
118
|
+
`❌ csp_connect_src entry refused, not a single source: ${JSON.stringify(s)}`
|
|
119
|
+
);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
})
|
|
110
124
|
.map(escape_html);
|
|
111
125
|
} else {
|
|
112
126
|
console.warn(
|