@yuneta/gobj-ui 7.26.6 → 7.26.8

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.
Files changed (48) hide show
  1. package/README.md +74 -25
  2. package/dist/gobj-ui.cjs.js +967 -377
  3. package/dist/gobj-ui.es.js +967 -377
  4. package/index.js +5 -1
  5. package/package.json +2 -2
  6. package/src/c_g6_nodes_tree.js +69 -24
  7. package/src/c_yui_form.js +331 -140
  8. package/src/c_yui_gclass.js +26 -21
  9. package/src/c_yui_gobj_tree_js.js +16 -5
  10. package/src/c_yui_json.js +7 -6
  11. package/src/c_yui_json_graph.js +42 -14
  12. package/src/c_yui_json_pad.js +2 -1
  13. package/src/c_yui_map.js +139 -75
  14. package/src/c_yui_nav.js +60 -20
  15. package/src/c_yui_pager.js +14 -9
  16. package/src/c_yui_period.js +16 -6
  17. package/src/c_yui_schema_editor.js +3 -2
  18. package/src/c_yui_shell.js +96 -31
  19. package/src/c_yui_treedb_topic_with_form.js +50 -56
  20. package/src/c_yui_treedb_topics.js +8 -7
  21. package/src/c_yui_uplot.js +1 -1
  22. package/src/c_yui_window.js +123 -36
  23. package/src/c_yui_window_manager.js +8 -3
  24. package/src/c_yui_wizard.js +23 -8
  25. package/src/delete_impact.js +5 -3
  26. package/src/form_json_field.js +123 -0
  27. package/src/form_json_field.test.js +49 -0
  28. package/src/form_json_field.wiring.test.js +137 -0
  29. package/src/form_table_rearm.wiring.test.js +158 -0
  30. package/src/g6_event_kw.js +36 -0
  31. package/src/nav_cards_helpers.js +2 -1
  32. package/src/nav_cards_helpers.test.js +7 -3
  33. package/src/schema_to_c.js +27 -1
  34. package/src/schema_to_c.test.js +15 -1
  35. package/src/shell_modals.js +5 -3
  36. package/src/shell_route_map.js +18 -13
  37. package/src/treedb_topics_transport.wiring.test.js +35 -1
  38. package/src/vite_plugin_yuneta_html.test.js +79 -0
  39. package/src/window_show.wiring.test.js +83 -0
  40. package/src/window_veto_back.wiring.test.js +136 -0
  41. package/src/wizard_chrome.wiring.test.js +87 -0
  42. package/src/yui_dev.js +23 -14
  43. package/src/yui_frontend_view.js +4 -4
  44. package/src/yui_gclass_view.js +3 -3
  45. package/src/yui_table_filter_clear.js +44 -44
  46. package/src/yui_text.js +31 -0
  47. package/src/yui_text.test.js +39 -0
  48. package/vite-plugin-yuneta-html.js +36 -9
@@ -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
@@ -249,6 +250,8 @@ function build_body(shell, t)
249
250
  ["input", {class: "input is-small ROUTEMAP_SEARCH", type: "text",
250
251
  placeholder: t("filter", {defaultValue: "Filter…"}),
251
252
  "data-i18n-placeholder": "filter",
253
+ title: t("filter", {defaultValue: "Filter"}),
254
+ "data-i18n-title": "filter",
252
255
  "aria-label": t("filter", {defaultValue: "Filter"}),
253
256
  "data-i18n-aria-label": "filter"}]
254
257
  );
@@ -334,6 +337,10 @@ function build_body(shell, t)
334
337
  $tree,
335
338
  ["div", {class: "ROUTEMAP_ACTIONS"}, [
336
339
  ["button", {class: "button is-small ROUTEMAP_PRINT",
340
+ title: t("print", {defaultValue: "Print"}),
341
+ "data-i18n-title": "print",
342
+ "aria-label": t("print", {defaultValue: "Print"}),
343
+ "data-i18n-aria-label": "print",
337
344
  i18n: "print"}, t("print", {defaultValue: "Print"})]
338
345
  ]]
339
346
  ]]
@@ -473,11 +480,10 @@ export function yui_shell_show_route_map(shell, opts)
473
480
  let win_ref = {gobj: null};
474
481
  /* A workspace surface, not a thing floating over one view: it
475
482
  * joins the dock when the app HAS one (minimise, restore, focus
476
- * like any other window). Passed only when it exists —
477
- * gobj_find_service() answers `undefined` for an absent
478
- * service, and handing undefined to a DTP_POINTER attr is one
479
- * "attr undefined: manager" per open in every app without a
480
- * 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
481
487
  * `keep_on_navigate` gives it the same survives-navigation
482
488
  * behaviour there. */
483
489
  let $body = build_body(shell, t);
@@ -499,11 +505,10 @@ export function yui_shell_show_route_map(shell, opts)
499
505
  title: "site map",
500
506
  icon: "yi-bars",
501
507
  body: $body,
502
- /* Opt into the dock/taskbar if the app provides one. `|| null`
503
- * because gobj_find_service returns UNDEFINED when absent, and an
504
- * undefined attr value logs "attr undefined: manager" — one per
505
- * open in every app without a window manager (wattyzer). The same
506
- * 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
507
512
  * keep_on_navigate then gives the map the same
508
513
  * survives-navigation behaviour a docked window has. */
509
514
  manager: gobj_find_service("__window_manager__", false) || null,
@@ -38,10 +38,11 @@ const {
38
38
  gobj_change_state, gobj_current_state,
39
39
  set_log_callback,
40
40
  } = gobj_js;
41
- const {register_c_yui_shell, yui_shell_set_connection_state} = await import("./c_yui_shell.js");
41
+ const {register_c_yui_shell, yui_shell_set_connection_state, yui_shell_icons_changed} = await import("./c_yui_shell.js");
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();
@@ -255,6 +268,27 @@ describe("a Save in flight when the backend drops", () => {
255
268
  expect(errors()).toEqual([]);
256
269
  });
257
270
 
271
+ test("nor EV_ICONS_CHANGED, which 7.26.6 added to the shell", () => {
272
+ /* An app hosting a treedb view heard it on every load of
273
+ * `__icons__` and answered "Event NOT DEFINED in state". */
274
+ const {shell} = build("t4b");
275
+ yui_shell_icons_changed(shell);
276
+ expect(errors()).toEqual([]);
277
+ });
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
+
258
292
  test("an answer from the backend settles its own form only", () => {
259
293
  const {shell, topics, forms} = build("t5");
260
294
  yui_shell_set_connection_state(shell, true);
@@ -0,0 +1,79 @@
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("what config.json says is escaped where it lands in markup", () => {
69
+ const html = transform({
70
+ title: "</title><script>x()</script>",
71
+ metadata: {description: '"><b>'},
72
+ csp_connect_src: ['wss://a" onload="x']
73
+ });
74
+ expect(html).not.toContain("<script>");
75
+ expect(html).toContain("&lt;/title&gt;&lt;script&gt;");
76
+ expect(html).not.toContain('content=""><b>"');
77
+ expect(html).not.toContain('wss://a" onload');
78
+ });
79
+ });
@@ -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
+ });
@@ -0,0 +1,136 @@
1
+ /***********************************************************************
2
+ * window_veto_back.wiring.test.js
3
+ *
4
+ * A floating C_YUI_WINDOW registers an entry in the shell's
5
+ * overlay history, so the browser Back closes it. The shell takes
6
+ * that entry off its stack BEFORE it calls the close; when a
7
+ * subscriber vetoed the close (EV_WINDOW_TO_CLOSE + abort_close),
8
+ * the window stayed up with no entry: the next Back did not close
9
+ * it, and a route change left it floating over the next view.
10
+ *
11
+ * Copyright (c) 2026, ArtGins.
12
+ * All Rights Reserved.
13
+ ***********************************************************************/
14
+ import {describe, test, expect, beforeAll, beforeEach} from "vitest";
15
+ import {install_dom_double} from "../test/dom_double.js";
16
+
17
+ install_dom_double();
18
+
19
+ const {
20
+ SDATA_END, gclass_create,
21
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
22
+ gobj_start, gobj_read_attr, gobj_is_destroying,
23
+ set_log_callback,
24
+ } = await import("@yuneta/gobj-js");
25
+ const {register_c_yui_shell} = await import("./c_yui_shell.js");
26
+ const {register_c_yui_window} = await import("./c_yui_window.js");
27
+
28
+ const logged = [];
29
+ let veto = true;
30
+ let warning = null;
31
+ let yuno = null;
32
+
33
+ beforeAll(async () => {
34
+ const i18next = (await import("i18next")).default;
35
+ await i18next.init({lng: "en", resources: {}});
36
+ gobj_start_up(null, null, null, null, null, null, null);
37
+ set_log_callback((level, msg) => {
38
+ logged.push({level: String(level), msg: String(msg)});
39
+ });
40
+ gclass_create("C_TEST_VETO_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
41
+ gclass_create(
42
+ "C_TEST_VETO_APP",
43
+ [["EV_WINDOW_TO_CLOSE", 0]],
44
+ [["ST_IDLE", [
45
+ ["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
46
+ kw.abort_close = veto;
47
+ if(warning) {
48
+ kw.warning = warning;
49
+ }
50
+ return 0;
51
+ }, null]
52
+ ]]],
53
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
54
+ );
55
+ register_c_yui_shell();
56
+ register_c_yui_window();
57
+ yuno = gobj_create_yuno("veto_yuno", "C_TEST_VETO_HOST", {});
58
+ gobj_start(yuno);
59
+ });
60
+
61
+ beforeEach(() => {
62
+ logged.length = 0;
63
+ veto = true;
64
+ warning = null;
65
+ });
66
+
67
+ function errors()
68
+ {
69
+ return logged.filter((l) => l.level === "error").map((l) => l.msg);
70
+ }
71
+
72
+ function press_back()
73
+ {
74
+ window.history.state = null;
75
+ window.dispatchEvent(new Event("popstate", {state: null}));
76
+ }
77
+
78
+ describe("a floating window that vetoes its close", () => {
79
+ test("keeps a Back entry, and closes on the Back after the veto is lifted", () => {
80
+ const app = gobj_create("vapp", "C_TEST_VETO_APP", {}, yuno);
81
+ gobj_start(app);
82
+ const shell = gobj_create("vshell", "C_YUI_SHELL",
83
+ {config: {shell: {}}, default_route: "/home", subscriber: app}, app);
84
+ gobj_start(shell);
85
+ logged.length = 0; /* the shell's own start: no route table here */
86
+
87
+ const win = gobj_create_service("vwin", "C_YUI_WINDOW",
88
+ {subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
89
+ gobj_start(win);
90
+ const first = gobj_read_attr(win, "back_overlay");
91
+ expect(first).toBeTruthy();
92
+
93
+ press_back();
94
+ expect(gobj_is_destroying(win)).toBe(false);
95
+ const second = gobj_read_attr(win, "back_overlay");
96
+ expect(second).toBeTruthy();
97
+ expect(second).not.toBe(first);
98
+ expect(shell.priv.overlay_stack).toEqual([second]);
99
+
100
+ veto = false;
101
+ press_back();
102
+ expect(gobj_is_destroying(win)).toBe(true);
103
+ expect(shell.priv.overlay_stack).toEqual([]);
104
+ expect(errors()).toEqual([]);
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
+ });
136
+ });
@@ -0,0 +1,87 @@
1
+ /***********************************************************************
2
+ * wizard_chrome.wiring.test.js
3
+ *
4
+ * C_YUI_WIZARD's chrome (title, primary button) is rewritten on
5
+ * every step change, after the host's one-time refresh_language().
6
+ * It stamped a bare `i18n` attribute (which refresh_language does
7
+ * not read) and put the raw key in the text: the title never went
8
+ * through t(), and on the last step the button read `confirm`
9
+ * while its `data-i18n` still said `next`, so a language switch
10
+ * relabelled it "Next".
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+ import {describe, test, expect, beforeAll} from "vitest";
16
+ import {install_dom_double} from "../test/dom_double.js";
17
+
18
+ install_dom_double();
19
+
20
+ const {
21
+ SDATA_END, gclass_create,
22
+ gobj_start_up, gobj_create_yuno, gobj_create,
23
+ gobj_start, gobj_send_event, gobj_read_attr,
24
+ } = await import("@yuneta/gobj-js");
25
+ const {register_c_yui_wizard} = await import("./c_yui_wizard.js");
26
+
27
+ let yuno = null;
28
+ let i18next = null;
29
+
30
+ beforeAll(async () => {
31
+ i18next = (await import("i18next")).default;
32
+ await i18next.init({lng: "en", resources: {
33
+ en: {translation: {"step one": "Step one", "next": "Next", "confirm": "Confirm"}},
34
+ es: {translation: {"step one": "Paso uno", "next": "Siguiente", "confirm": "Confirmar"}},
35
+ }});
36
+ gobj_start_up(null, null, null, null, null, null, null);
37
+ gclass_create("C_TEST_WIZ_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
38
+ gclass_create(
39
+ "C_TEST_WIZ_APP",
40
+ [["EV_STEP_SHOWN", 0], ["EV_WIZARD_DONE", 0]],
41
+ [["ST_IDLE", [
42
+ ["EV_STEP_SHOWN", () => 0, null],
43
+ ["EV_WIZARD_DONE", () => 0, null],
44
+ ]]],
45
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
46
+ );
47
+ register_c_yui_wizard();
48
+ yuno = gobj_create_yuno("wizard_yuno", "C_TEST_WIZ_HOST", {});
49
+ gobj_start(yuno);
50
+ });
51
+
52
+ describe("C_YUI_WIZARD chrome", () => {
53
+ test("title and primary label are translated and keep their key", async () => {
54
+ const app = gobj_create("wapp", "C_TEST_WIZ_APP", {}, yuno);
55
+ const wiz = gobj_create("wiz", "C_YUI_WIZARD", {linear: false}, app);
56
+ gobj_send_event(wiz, "EV_SET_STEPS", {steps: [
57
+ {id: "a", title: "step one", content: ["div", {}, "A"]},
58
+ {id: "b", title: "step one", content: ["div", {}, "B"]},
59
+ ]}, app);
60
+
61
+ const $c = gobj_read_attr(wiz, "$container");
62
+ const $title = $c.querySelector(".yui-wizard-title");
63
+ const $primary = $c.querySelector(".yui-wizard-primary");
64
+ const $plabel = $c.querySelector(".yui-wizard-primary-label");
65
+
66
+ expect($title.textContent).toBe("Step one");
67
+ expect($title.getAttribute("data-i18n")).toBe("step one");
68
+ expect($plabel.textContent).toBe("Next");
69
+
70
+ gobj_send_event(wiz, "EV_NEXT", {}, app);
71
+ expect($plabel.textContent).toBe("Confirm");
72
+ expect($plabel.getAttribute("data-i18n")).toBe("confirm");
73
+ expect($primary.getAttribute("aria-label")).toBe("Confirm");
74
+ expect($primary.getAttribute("data-i18n-aria-label")).toBe("confirm");
75
+ expect($primary.getAttribute("data-i18n-title")).toBe("confirm");
76
+
77
+ /* What refresh_language() reads on a language switch: the key of
78
+ * the CURRENT label, not the one the button was built with. */
79
+ await i18next.changeLanguage("es");
80
+ try {
81
+ expect(i18next.t($plabel.getAttribute("data-i18n"))).toBe("Confirmar");
82
+ expect(i18next.t($title.getAttribute("data-i18n"))).toBe("Paso uno");
83
+ } finally {
84
+ await i18next.changeLanguage("en");
85
+ }
86
+ });
87
+ });
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);
@@ -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
  }
@@ -852,15 +853,21 @@ function full_sections(payload)
852
853
  let out = {};
853
854
  for(let k of Object.keys(payload)) {
854
855
  if(k === "schema") {
855
- if(show_schema) { out[k] = payload[k]; }
856
+ if(show_schema) {
857
+ out[k] = payload[k];
858
+ }
856
859
  continue;
857
860
  }
858
861
  if(k === "data") {
859
- if(show_data) { out[k] = payload[k]; }
862
+ if(show_data) {
863
+ out[k] = payload[k];
864
+ }
860
865
  continue;
861
866
  }
862
867
  if(/^__.*__$/.test(k)) {
863
- if(show_meta) { out[k] = payload[k]; }
868
+ if(show_meta) {
869
+ out[k] = payload[k];
870
+ }
864
871
  continue;
865
872
  }
866
873
  out[k] = payload[k];
@@ -885,7 +892,7 @@ function render_full(e)
885
892
  }
886
893
  let children = [
887
894
  ['div', {class: 'TRAFFIC_HEADER'}, head],
888
- ['pre', {class: 'TRAFFIC_FULL'}, text],
895
+ ['pre', {class: 'TRAFFIC_FULL'}, document.createTextNode(String(text))],
889
896
  ];
890
897
  return createElement2(['div', {class: 'TRAFFIC_ENTRY ' + dir_class(e.dir)}, children]);
891
898
  }
@@ -1665,6 +1672,7 @@ function build_control_bar()
1665
1672
  let mk_dir = (dir, glyph, key, title) => ['button', {
1666
1673
  class: 'YDEV_CHIP s-' + dir, 'data-dir': key, type: 'button',
1667
1674
  title: t(title), 'data-i18n-title': title,
1675
+ 'aria-label': t(title), 'data-i18n-aria-label': title,
1668
1676
  }, glyph, {
1669
1677
  click: (ev) => {
1670
1678
  ev.stopPropagation();
@@ -1853,10 +1861,11 @@ function setup_dev(self, show)
1853
1861
  center: false,
1854
1862
  title: "developer",
1855
1863
  icon: "yi-terminal",
1856
- /* Opt into the dock/taskbar if the app provides one. `|| null`
1857
- * because gobj_find_service returns undefined when absent, and
1858
- * an undefined attr value logs "attr undefined: manager" (apps
1859
- * without a window manager, e.g. wattyzer). null = no dock. */
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.) */
1860
1869
  manager: gobj_find_service("__window_manager__", false) || null,
1861
1870
  /* A monitor is watched WHILE navigating: closing it on every
1862
1871
  * route change made it useless for the one job it has. A
@@ -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. `|| null`
78
- * because gobj_find_service returns undefined when absent, and
79
- * an undefined attr value logs "attr undefined: manager" (apps
80
- * without a window manager, e.g. wattyzer). null = no dock. */
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
@@ -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` because gobj_find_service answers undefined when
233
- * absent, and an undefined attr logs "attr undefined". */
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
  },