@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
package/src/shell_route_map.js
CHANGED
|
@@ -37,6 +37,7 @@ import {yui_shell_nav_map} from "./c_yui_shell.js";
|
|
|
37
37
|
import {attach_clear} from "./yui_inputs.js";
|
|
38
38
|
|
|
39
39
|
import i18next from "i18next";
|
|
40
|
+
import {text_node} from "./yui_text.js";
|
|
40
41
|
|
|
41
42
|
const WIN_NAME = "shell-route-map-window";
|
|
42
43
|
|
|
@@ -78,10 +79,10 @@ function render_node(node)
|
|
|
78
79
|
row.push(["span", {class: "icon ROUTEMAP_ICON"},
|
|
79
80
|
[["i", {class: node.icon}]]]);
|
|
80
81
|
}
|
|
81
|
-
row.push(["span", {class: "ROUTEMAP_NAME", i18n: node.label}, node.label]);
|
|
82
|
+
row.push(["span", {class: "ROUTEMAP_NAME", i18n: node.label}, text_node(node.label)]);
|
|
82
83
|
/* Documentation columns: route + implementing gclass + action event. */
|
|
83
84
|
if(node.route) {
|
|
84
|
-
row.push(["code", {class: "ROUTEMAP_ROUTE"}, node.route]);
|
|
85
|
+
row.push(["code", {class: "ROUTEMAP_ROUTE"}, text_node(node.route)]);
|
|
85
86
|
}
|
|
86
87
|
if(node.gclass) {
|
|
87
88
|
row.push(["span", {class: "ROUTEMAP_GCLASS",
|
|
@@ -89,7 +90,7 @@ function render_node(node)
|
|
|
89
90
|
node.gclass]);
|
|
90
91
|
}
|
|
91
92
|
if(node.event) {
|
|
92
|
-
row.push(["span", {class: "ROUTEMAP_EVENT"}, node.event]);
|
|
93
|
+
row.push(["span", {class: "ROUTEMAP_EVENT"}, text_node(node.event)]);
|
|
93
94
|
}
|
|
94
95
|
/* A reference: this route's structure is drawn under whichever
|
|
95
96
|
* surface owns it (the model's dedupe keeps one subtree per
|
|
@@ -479,11 +480,10 @@ export function yui_shell_show_route_map(shell, opts)
|
|
|
479
480
|
let win_ref = {gobj: null};
|
|
480
481
|
/* A workspace surface, not a thing floating over one view: it
|
|
481
482
|
* joins the dock when the app HAS one (minimise, restore, focus
|
|
482
|
-
* like any other window). Passed only when it exists
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* dock. Without one the map stays a floating overlay, and
|
|
483
|
+
* like any other window). Passed only when it exists (an absent
|
|
484
|
+
* service is null, which a DTP_POINTER takes as "no dock"; up to
|
|
485
|
+
* gobj-js 7.12.0 it was undefined, one "attr undefined: manager"
|
|
486
|
+
* per open). Without one the map stays a floating overlay, and
|
|
487
487
|
* `keep_on_navigate` gives it the same survives-navigation
|
|
488
488
|
* behaviour there. */
|
|
489
489
|
let $body = build_body(shell, t);
|
|
@@ -505,11 +505,10 @@ export function yui_shell_show_route_map(shell, opts)
|
|
|
505
505
|
title: "site map",
|
|
506
506
|
icon: "yi-bars",
|
|
507
507
|
body: $body,
|
|
508
|
-
/* Opt into the dock/taskbar if the app provides one
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* trap yui_dev.js already documents; null = no dock, and
|
|
508
|
+
/* Opt into the dock/taskbar if the app provides one: null = no
|
|
509
|
+
* dock (gobj_find_service() answers null for an absent service
|
|
510
|
+
* since gobj-js 7.12.0; the `|| null` is the old guard, from when
|
|
511
|
+
* it answered undefined), and
|
|
513
512
|
* keep_on_navigate then gives the map the same
|
|
514
513
|
* survives-navigation behaviour a docked window has. */
|
|
515
514
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
@@ -42,6 +42,7 @@ const {register_c_yui_shell, yui_shell_set_connection_state, yui_shell_icons_cha
|
|
|
42
42
|
const {register_c_yui_treedb_topics} = await import("./c_yui_treedb_topics.js");
|
|
43
43
|
|
|
44
44
|
const logged = [];
|
|
45
|
+
const icons_heard = []; /* the EV_ICONS_CHANGED a declaring app heard */
|
|
45
46
|
const written = []; /* the EV_RECORD_WRITTEN the host heard */
|
|
46
47
|
const answers = []; /* what the fake forms were told */
|
|
47
48
|
const loaded = []; /* the rows each fake form was loaded with */
|
|
@@ -138,6 +139,18 @@ beforeAll(() => {
|
|
|
138
139
|
/* An app that subscribes to EVERY event of its shell and declares
|
|
139
140
|
* none of the new ones: wattyzer's and yunovatios' shape. */
|
|
140
141
|
gclass_create("C_TEST_APP", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
142
|
+
/* An app that DOES declare it: it must still be told. */
|
|
143
|
+
gclass_create(
|
|
144
|
+
"C_TEST_ICONS_APP",
|
|
145
|
+
[["EV_ICONS_CHANGED", 0]],
|
|
146
|
+
[["ST_IDLE", [
|
|
147
|
+
["EV_ICONS_CHANGED", () => {
|
|
148
|
+
icons_heard.push(1);
|
|
149
|
+
return 0;
|
|
150
|
+
}, null]
|
|
151
|
+
]]],
|
|
152
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
153
|
+
);
|
|
141
154
|
|
|
142
155
|
register_c_yui_shell();
|
|
143
156
|
register_c_yui_treedb_topics();
|
|
@@ -263,6 +276,19 @@ describe("a Save in flight when the backend drops", () => {
|
|
|
263
276
|
expect(errors()).toEqual([]);
|
|
264
277
|
});
|
|
265
278
|
|
|
279
|
+
test("an app that declares EV_ICONS_CHANGED is still told", () => {
|
|
280
|
+
icons_heard.length = 0;
|
|
281
|
+
const app = gobj_create("t4c_app", "C_TEST_ICONS_APP", {}, yuno);
|
|
282
|
+
gobj_start(app);
|
|
283
|
+
const shell = gobj_create("t4c_shell", "C_YUI_SHELL",
|
|
284
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
285
|
+
gobj_start(shell);
|
|
286
|
+
logged.length = 0;
|
|
287
|
+
yui_shell_icons_changed(shell);
|
|
288
|
+
expect(icons_heard.length).toBe(1);
|
|
289
|
+
expect(errors()).toEqual([]);
|
|
290
|
+
});
|
|
291
|
+
|
|
266
292
|
test("an answer from the backend settles its own form only", () => {
|
|
267
293
|
const {shell, topics, forms} = build("t5");
|
|
268
294
|
yui_shell_set_connection_state(shell, true);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* vite_plugin_yuneta_html.test.js
|
|
3
|
+
*
|
|
4
|
+
* The html transform of vite-plugin-yuneta-html.js: the policy is
|
|
5
|
+
* ALWAYS emitted (connect-src 'self' alone without csp_connect_src,
|
|
6
|
+
* and without a config.json at all), and the text of config.json is
|
|
7
|
+
* escaped where it lands in markup.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026, ArtGins.
|
|
10
|
+
* All Rights Reserved.
|
|
11
|
+
***********************************************************************/
|
|
12
|
+
import {describe, test, expect, vi} from "vitest";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import os from "os";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import {yunetaHtmlPlugin} from "../vite-plugin-yuneta-html.js";
|
|
17
|
+
|
|
18
|
+
const HTML = "<head><title></title>\n<!-- METADATA_PLACEHOLDER -->\n<!-- CSP_PLACEHOLDER --></head>";
|
|
19
|
+
|
|
20
|
+
function transform(config)
|
|
21
|
+
{
|
|
22
|
+
let configPath = path.join(os.tmpdir(), `yuneta-html-${process.pid}-${Math.random()}.json`);
|
|
23
|
+
if(config !== undefined) {
|
|
24
|
+
fs.writeFileSync(configPath, JSON.stringify(config));
|
|
25
|
+
}
|
|
26
|
+
const plugin = yunetaHtmlPlugin({defaultTitle: "Fallback", configPath});
|
|
27
|
+
try {
|
|
28
|
+
return plugin.transformIndexHtml.handler(HTML);
|
|
29
|
+
} finally {
|
|
30
|
+
if(config !== undefined) {
|
|
31
|
+
fs.unlinkSync(configPath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function connect_src(html)
|
|
37
|
+
{
|
|
38
|
+
let m = html.match(/connect-src ([^;]*);/);
|
|
39
|
+
return m? m[1].split(/\s+/).filter(Boolean) : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("vite-plugin-yuneta-html", () => {
|
|
43
|
+
test("a declared csp_connect_src goes into connect-src, comments left out", () => {
|
|
44
|
+
const html = transform({
|
|
45
|
+
title: "App",
|
|
46
|
+
csp_connect_src: ["wss://host:1620", "_comment: why", "https://tiles.example"]
|
|
47
|
+
});
|
|
48
|
+
expect(connect_src(html)).toEqual(["'self'", "wss://host:1620", "https://tiles.example"]);
|
|
49
|
+
expect(html).toContain("<title>App</title>");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("no csp_connect_src: the policy is still there, connect-src 'self' only", () => {
|
|
53
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
54
|
+
const html = transform({title: "App"});
|
|
55
|
+
expect(connect_src(html)).toEqual(["'self'"]);
|
|
56
|
+
expect(warn).toHaveBeenCalled();
|
|
57
|
+
warn.mockRestore();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("no config.json: the policy is still there, with the fallback title", () => {
|
|
61
|
+
const err = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
62
|
+
const html = transform(undefined);
|
|
63
|
+
expect(connect_src(html)).toEqual(["'self'"]);
|
|
64
|
+
expect(html).toContain("<title>Fallback</title>");
|
|
65
|
+
err.mockRestore();
|
|
66
|
+
});
|
|
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
|
+
|
|
83
|
+
test("what config.json says is escaped where it lands in markup", () => {
|
|
84
|
+
const html = transform({
|
|
85
|
+
title: "</title><script>x()</script>",
|
|
86
|
+
metadata: {description: '"><b>'},
|
|
87
|
+
csp_connect_src: ['wss://a"onload="x']
|
|
88
|
+
});
|
|
89
|
+
expect(html).not.toContain("<script>");
|
|
90
|
+
expect(html).toContain("</title><script>");
|
|
91
|
+
expect(html).not.toContain('content=""><b>"');
|
|
92
|
+
expect(html).not.toContain('wss://a"onload');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* window_show.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* EV_SHOW brings a C_YUI_WINDOW back in front of the reader. Its
|
|
5
|
+
* action was an empty stub, so the map's second click on the same
|
|
6
|
+
* marker -- which finds the marker's window by name and sends it
|
|
7
|
+
* EV_SHOW instead of opening a second one -- did nothing for a
|
|
8
|
+
* window that was minimized or covered.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2026, ArtGins.
|
|
11
|
+
* All Rights Reserved.
|
|
12
|
+
***********************************************************************/
|
|
13
|
+
import {describe, test, expect, beforeAll} from "vitest";
|
|
14
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
15
|
+
|
|
16
|
+
install_dom_double();
|
|
17
|
+
|
|
18
|
+
if(typeof globalThis.matchMedia === "undefined") {
|
|
19
|
+
globalThis.matchMedia = () => ({matches: false, addEventListener() {}, removeEventListener() {}});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
SDATA_END, gclass_create,
|
|
24
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
25
|
+
gobj_start, gobj_read_attr, gobj_send_event,
|
|
26
|
+
set_log_callback,
|
|
27
|
+
} = await import("@yuneta/gobj-js");
|
|
28
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
29
|
+
const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
|
|
30
|
+
|
|
31
|
+
const logged = [];
|
|
32
|
+
let yuno = null;
|
|
33
|
+
|
|
34
|
+
beforeAll(async () => {
|
|
35
|
+
const i18next = (await import("i18next")).default;
|
|
36
|
+
await i18next.init({lng: "en", resources: {}});
|
|
37
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
38
|
+
set_log_callback((level, msg) => {
|
|
39
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
40
|
+
});
|
|
41
|
+
gclass_create("C_TEST_SHOW_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
42
|
+
register_c_yui_window();
|
|
43
|
+
register_c_yui_window_manager();
|
|
44
|
+
yuno = gobj_create_yuno("show_yuno", "C_TEST_SHOW_HOST", {});
|
|
45
|
+
gobj_start(yuno);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function errors()
|
|
49
|
+
{
|
|
50
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("EV_SHOW", () => {
|
|
54
|
+
test("without a dock: a hidden window is shown, and goes on top of its layer", () => {
|
|
55
|
+
const a = gobj_create_service("show_a", "C_YUI_WINDOW", {header: "a", body: ["div", {}, "a"]}, yuno);
|
|
56
|
+
gobj_start(a);
|
|
57
|
+
const b = gobj_create_service("show_b", "C_YUI_WINDOW", {header: "b", body: ["div", {}, "b"]}, yuno);
|
|
58
|
+
gobj_start(b);
|
|
59
|
+
const $a = gobj_read_attr(a, "$container");
|
|
60
|
+
$a.style.setProperty("display", "none", "important");
|
|
61
|
+
|
|
62
|
+
gobj_send_event(a, "EV_SHOW", {}, yuno);
|
|
63
|
+
expect($a.style.getPropertyValue("display")).toBe("");
|
|
64
|
+
expect($a.parentNode.lastChild).toBe($a);
|
|
65
|
+
expect(errors()).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("with a dock: a minimized window comes back out of it", () => {
|
|
69
|
+
const dock = gobj_create_service("show_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
|
|
70
|
+
gobj_start(dock);
|
|
71
|
+
const w = gobj_create_service("show_w", "C_YUI_WINDOW",
|
|
72
|
+
{header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
|
|
73
|
+
gobj_start(w);
|
|
74
|
+
const $w = gobj_read_attr(w, "$container");
|
|
75
|
+
|
|
76
|
+
gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: w}, w);
|
|
77
|
+
expect($w.style.getPropertyValue("display")).toBe("none");
|
|
78
|
+
|
|
79
|
+
gobj_send_event(w, "EV_SHOW", {}, yuno);
|
|
80
|
+
expect($w.style.getPropertyValue("display")).toBe("");
|
|
81
|
+
expect(errors()).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -27,6 +27,7 @@ const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
|
27
27
|
|
|
28
28
|
const logged = [];
|
|
29
29
|
let veto = true;
|
|
30
|
+
let warning = null;
|
|
30
31
|
let yuno = null;
|
|
31
32
|
|
|
32
33
|
beforeAll(async () => {
|
|
@@ -43,6 +44,9 @@ beforeAll(async () => {
|
|
|
43
44
|
[["ST_IDLE", [
|
|
44
45
|
["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
|
|
45
46
|
kw.abort_close = veto;
|
|
47
|
+
if(warning) {
|
|
48
|
+
kw.warning = warning;
|
|
49
|
+
}
|
|
46
50
|
return 0;
|
|
47
51
|
}, null]
|
|
48
52
|
]]],
|
|
@@ -57,6 +61,7 @@ beforeAll(async () => {
|
|
|
57
61
|
beforeEach(() => {
|
|
58
62
|
logged.length = 0;
|
|
59
63
|
veto = true;
|
|
64
|
+
warning = null;
|
|
60
65
|
});
|
|
61
66
|
|
|
62
67
|
function errors()
|
|
@@ -98,4 +103,34 @@ describe("a floating window that vetoes its close", () => {
|
|
|
98
103
|
expect(shell.priv.overlay_stack).toEqual([]);
|
|
99
104
|
expect(errors()).toEqual([]);
|
|
100
105
|
});
|
|
106
|
+
|
|
107
|
+
test("that ASKS first: Back closes the question, it does not stack another", async () => {
|
|
108
|
+
const app = gobj_create("vapp2", "C_TEST_VETO_APP", {}, yuno);
|
|
109
|
+
gobj_start(app);
|
|
110
|
+
const shell = gobj_create("vshell2", "C_YUI_SHELL",
|
|
111
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
112
|
+
gobj_start(shell);
|
|
113
|
+
logged.length = 0;
|
|
114
|
+
|
|
115
|
+
const win = gobj_create_service("vwin2", "C_YUI_WINDOW",
|
|
116
|
+
{subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
|
|
117
|
+
gobj_start(win);
|
|
118
|
+
warning = "unsaved changes";
|
|
119
|
+
|
|
120
|
+
/* Back: the window asks. Only the question is on the stack. */
|
|
121
|
+
press_back();
|
|
122
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
123
|
+
expect(shell.priv.overlay_stack.length).toBe(1);
|
|
124
|
+
expect(gobj_read_attr(win, "back_overlay")).toBe(null);
|
|
125
|
+
|
|
126
|
+
/* Back again: the question goes; the window takes its entry back
|
|
127
|
+
* only then, once there is nothing above it. */
|
|
128
|
+
press_back();
|
|
129
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
130
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
131
|
+
const entry = gobj_read_attr(win, "back_overlay");
|
|
132
|
+
expect(entry).toBeTruthy();
|
|
133
|
+
expect(shell.priv.overlay_stack).toEqual([entry]);
|
|
134
|
+
expect(errors()).toEqual([]);
|
|
135
|
+
});
|
|
101
136
|
});
|
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
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
} from "@yuneta/gobj-js";
|
|
30
30
|
|
|
31
31
|
import i18next, {t} from 'i18next';
|
|
32
|
+
import {text_node} from "./yui_text.js";
|
|
32
33
|
|
|
33
34
|
/***********************************************************************
|
|
34
35
|
* Traffic model (bounded ring buffer)
|
|
@@ -628,7 +629,7 @@ function traffic_scalar_row(key, value)
|
|
|
628
629
|
value is one click away in the Expanded view. On a value SHORTER than
|
|
629
630
|
the clip -- almost all of them -- it repeated the visible text anyway. */
|
|
630
631
|
let val_children = [
|
|
631
|
-
['span', {class: 'TRAFFIC_VAL ' + cls}, text],
|
|
632
|
+
['span', {class: 'TRAFFIC_VAL ' + cls}, text_node(text)],
|
|
632
633
|
];
|
|
633
634
|
if((key in TRAFFIC_TS_FIELDS) && typeof value === "number") {
|
|
634
635
|
let iso = traffic_iso(value);
|
|
@@ -639,7 +640,7 @@ function traffic_scalar_row(key, value)
|
|
|
639
640
|
|
|
640
641
|
return ['div', {class: 'TRAFFIC_ROW'}, [
|
|
641
642
|
['span', {class: 'TRAFFIC_BULLET'}, '•'],
|
|
642
|
-
['span', {class: 'TRAFFIC_KEY'}, key + ':'],
|
|
643
|
+
['span', {class: 'TRAFFIC_KEY'}, text_node(key + ':')],
|
|
643
644
|
['span', {}, val_children],
|
|
644
645
|
]];
|
|
645
646
|
}
|
|
@@ -743,7 +744,7 @@ function traffic_value_node(key, value)
|
|
|
743
744
|
if(count === 0) {
|
|
744
745
|
return ['div', {class: 'TRAFFIC_ROW'}, [
|
|
745
746
|
['span', {class: 'TRAFFIC_BULLET'}, '•'],
|
|
746
|
-
['span', {class: 'TRAFFIC_KEY'}, key + ':'],
|
|
747
|
+
['span', {class: 'TRAFFIC_KEY'}, text_node(key + ':')],
|
|
747
748
|
['span', {class: 'TRAFFIC_VAL t-empty'}, is_arr ? '[ ]' : '{ }'],
|
|
748
749
|
]];
|
|
749
750
|
}
|
|
@@ -751,12 +752,12 @@ function traffic_value_node(key, value)
|
|
|
751
752
|
let hint = is_arr ?
|
|
752
753
|
[['span', {class: 'TRAFFIC_NEST_HINT'}, `[${count}]`]] :
|
|
753
754
|
object_preview_parts(value, count).map(
|
|
754
|
-
(t) => ['span', {class: 'TRAFFIC_PREV ' + t.cls}, t.text]
|
|
755
|
+
(t) => ['span', {class: 'TRAFFIC_PREV ' + t.cls}, text_node(t.text)]
|
|
755
756
|
);
|
|
756
757
|
return ['details', {class: 'TRAFFIC_NEST'}, [
|
|
757
758
|
['summary', {}, [
|
|
758
759
|
['span', {class: 'TRAFFIC_BULLET'}, '▸'],
|
|
759
|
-
['span', {class: 'TRAFFIC_NEST_KEY'}, key],
|
|
760
|
+
['span', {class: 'TRAFFIC_NEST_KEY'}, text_node(key)],
|
|
760
761
|
['span', {class: 'TRAFFIC_NEST_HINT_WRAP'}, hint],
|
|
761
762
|
]],
|
|
762
763
|
['div', {class: 'TRAFFIC_KW'}, traffic_bullets(value)],
|
|
@@ -804,12 +805,12 @@ function traffic_bullets(obj)
|
|
|
804
805
|
function event_spans(e)
|
|
805
806
|
{
|
|
806
807
|
let spans = [['span', {class: 'TRAFFIC_ARROW'}, dir_arrow(e.dir)],
|
|
807
|
-
['span', {class: 'TRAFFIC_EVENT'}, e.event]];
|
|
808
|
+
['span', {class: 'TRAFFIC_EVENT'}, text_node(e.event)]];
|
|
808
809
|
if(e.command) {
|
|
809
|
-
spans.push(['span', {class: 'TRAFFIC_CMD'}, e.command]);
|
|
810
|
+
spans.push(['span', {class: 'TRAFFIC_CMD'}, text_node(e.command)]);
|
|
810
811
|
}
|
|
811
812
|
if(e.title) {
|
|
812
|
-
spans.push(['span', {class: 'TRAFFIC_SRC'}, e.title]);
|
|
813
|
+
spans.push(['span', {class: 'TRAFFIC_SRC'}, text_node(e.title)]);
|
|
813
814
|
}
|
|
814
815
|
return spans;
|
|
815
816
|
}
|
|
@@ -891,7 +892,7 @@ function render_full(e)
|
|
|
891
892
|
}
|
|
892
893
|
let children = [
|
|
893
894
|
['div', {class: 'TRAFFIC_HEADER'}, head],
|
|
894
|
-
['pre', {class: 'TRAFFIC_FULL'}, text],
|
|
895
|
+
['pre', {class: 'TRAFFIC_FULL'}, document.createTextNode(String(text))],
|
|
895
896
|
];
|
|
896
897
|
return createElement2(['div', {class: 'TRAFFIC_ENTRY ' + dir_class(e.dir)}, children]);
|
|
897
898
|
}
|
|
@@ -1860,10 +1861,11 @@ function setup_dev(self, show)
|
|
|
1860
1861
|
center: false,
|
|
1861
1862
|
title: "developer",
|
|
1862
1863
|
icon: "yi-terminal",
|
|
1863
|
-
/* Opt into the dock/taskbar if the app provides one
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
1866
|
-
*
|
|
1864
|
+
/* Opt into the dock/taskbar if the app provides one; null =
|
|
1865
|
+
* no dock. (gobj_find_service() answers null for an absent
|
|
1866
|
+
* service since gobj-js 7.12.0; the `|| null` is from when it
|
|
1867
|
+
* answered undefined, which logged "attr undefined: manager",
|
|
1868
|
+
* and stays as a guard.) */
|
|
1867
1869
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
1868
1870
|
/* A monitor is watched WHILE navigating: closing it on every
|
|
1869
1871
|
* route change made it useless for the one job it has. A
|
package/src/yui_frontend_view.js
CHANGED
|
@@ -74,10 +74,10 @@ function setup_frontend_view(self)
|
|
|
74
74
|
title: "frontend view",
|
|
75
75
|
icon: "yi-hexagon-nodes",
|
|
76
76
|
body: $body,
|
|
77
|
-
/* Opt into the dock/taskbar if the app provides one
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
/* Opt into the dock/taskbar if the app provides one; null = no
|
|
78
|
+
* dock. (gobj_find_service() answers null for an absent service
|
|
79
|
+
* since gobj-js 7.12.0; the `|| null` is from when it answered
|
|
80
|
+
* undefined, and stays as a guard.) */
|
|
81
81
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
82
82
|
},
|
|
83
83
|
self
|
package/src/yui_gclass_view.js
CHANGED
|
@@ -228,9 +228,9 @@ function open_gclass_view(host, gclass_name, opts)
|
|
|
228
228
|
body: $box,
|
|
229
229
|
/* The same dock the other windows are on: raising a window
|
|
230
230
|
* is the manager's job, and a viewer registered nowhere
|
|
231
|
-
* cannot come to the front when the reader clicks it.
|
|
232
|
-
* null
|
|
233
|
-
*
|
|
231
|
+
* cannot come to the front when the reader clicks it. An
|
|
232
|
+
* absent service is null (gobj-js 7.12.0+); the `|| null` is
|
|
233
|
+
* the guard from when it was undefined. */
|
|
234
234
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
235
235
|
on_close: on_close,
|
|
236
236
|
},
|
package/src/yui_text.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_text.js
|
|
3
|
+
*
|
|
4
|
+
* DATA as text for createElement2().
|
|
5
|
+
*
|
|
6
|
+
* createElement2() takes a string content that starts with '<' for
|
|
7
|
+
* MARKUP and parses it (that is how a component passes an inline
|
|
8
|
+
* icon). So a value that came from outside -- a backend answer, a
|
|
9
|
+
* treedb node, a name somebody typed, a frame of the traffic -- must
|
|
10
|
+
* never go in as a bare string: "<img src=x onerror=...>" would run.
|
|
11
|
+
* It goes in as a Text node, which is always text.
|
|
12
|
+
*
|
|
13
|
+
* Trimmed like createElement2() trims a string, so the change of
|
|
14
|
+
* form does not change what is shown. A Text node under an
|
|
15
|
+
* `i18n`/`data-i18n` element is still re-translated by
|
|
16
|
+
* refresh_language(), which sets textContent.
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2026, ArtGins.
|
|
19
|
+
* All Rights Reserved.
|
|
20
|
+
***********************************************************************/
|
|
21
|
+
|
|
22
|
+
/************************************************************
|
|
23
|
+
* A Text node with `value` as its text ("" for null/undefined).
|
|
24
|
+
************************************************************/
|
|
25
|
+
export function text_node(value)
|
|
26
|
+
{
|
|
27
|
+
if(value === null || value === undefined) {
|
|
28
|
+
return document.createTextNode("");
|
|
29
|
+
}
|
|
30
|
+
return document.createTextNode(String(value).trim());
|
|
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
|
+
}
|