@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
@@ -78,9 +78,11 @@ function delete_impact(desc, records)
78
78
  if(n === 0) {
79
79
  continue;
80
80
  }
81
- /* A column can be BOTH (a department's `users` is a hook to its
82
- * users and a fkey to the department that manages it). Counting
83
- * it on both sides is right: the delete does both things. */
81
+ /* A column is a hook OR a fkey: the treedb refuses one flagged
82
+ * both ("A column cannot be both 'hook' and 'fkey'"), and a node
83
+ * that is a child and a parent carries two columns. A column
84
+ * read from an older store may still carry both; it is counted
85
+ * on both sides, which is what its delete would do. */
84
86
  if(col.flag.indexOf("hook") >= 0) {
85
87
  out.children += n;
86
88
  }
@@ -0,0 +1,123 @@
1
+ /***********************************************************************
2
+ * form_json_field.js
3
+ *
4
+ * Pure logic of a json field of C_YUI_FORM: what a jsoneditor
5
+ * holds, read as the value its column stores.
6
+ *
7
+ * The editor answers its content in one of two shapes -- {json}
8
+ * (tree mode) or {text} (text mode, whatever the reader typed).
9
+ * A text that does not parse used to be caught and replaced by
10
+ * `{}` or `[]`, and SAVED: a trailing comma wiped the column, with
11
+ * no log and no message. A text that is not json, or json of the
12
+ * wrong shape (a list in a dict column), is an error now, and the
13
+ * form refuses to save while a field holds one.
14
+ *
15
+ * Copyright (c) 2026, ArtGins.
16
+ * All Rights Reserved.
17
+ ***********************************************************************/
18
+
19
+ /*
20
+ * The shape a column type stores. A type not listed takes any json.
21
+ */
22
+ const SHAPE_OF_TYPE = {
23
+ object: "dict",
24
+ dict: "dict",
25
+ template: "dict",
26
+ array: "list",
27
+ list: "list",
28
+ table: "list",
29
+ coordinates: "container",
30
+ };
31
+
32
+ /************************************************************
33
+ * The shape `type` stores: "dict", "list", "container" or "any".
34
+ ************************************************************/
35
+ export function json_field_shape(type)
36
+ {
37
+ return SHAPE_OF_TYPE[type] || "any";
38
+ }
39
+
40
+ /************************************************************
41
+ * The empty value of a shape: what a blank editor stores.
42
+ ************************************************************/
43
+ export function json_field_empty(shape)
44
+ {
45
+ if(shape === "list") {
46
+ return [];
47
+ }
48
+ return {};
49
+ }
50
+
51
+ function value_fits(value, shape)
52
+ {
53
+ let is_list = Array.isArray(value);
54
+ let is_dict = value !== null && typeof value === "object" && !is_list;
55
+ switch(shape) {
56
+ case "dict":
57
+ return is_dict;
58
+ case "list":
59
+ return is_list;
60
+ case "container":
61
+ return is_dict || is_list;
62
+ default:
63
+ return true;
64
+ }
65
+ }
66
+
67
+ /************************************************************
68
+ * Parse what a json field holds.
69
+ *
70
+ * `value` is a json string (what the form reads out of an editor)
71
+ * or an already parsed value; an editor's content goes through
72
+ * json_editor_value() first.
73
+ * Returns {value, error}: `error` is "" when the value is good, else
74
+ * an i18n key; `value` is then the empty value of the shape and must
75
+ * NOT be stored.
76
+ *
77
+ * A blank text is not an error: it is the empty value.
78
+ ************************************************************/
79
+ export function parse_json_field(value, type)
80
+ {
81
+ let shape = json_field_shape(type);
82
+
83
+ if(typeof value === "string") {
84
+ if(value.trim() === "") {
85
+ return {value: json_field_empty(shape), error: ""};
86
+ }
87
+ try {
88
+ value = JSON.parse(value);
89
+ } catch(e) {
90
+ return {value: json_field_empty(shape), error: "invalid json"};
91
+ }
92
+ }
93
+
94
+ if(value === undefined) {
95
+ return {value: json_field_empty(shape), error: ""};
96
+ }
97
+ if(!value_fits(value, shape)) {
98
+ return {value: json_field_empty(shape), error: "invalid json"};
99
+ }
100
+ return {value: value, error: ""};
101
+ }
102
+
103
+ /************************************************************
104
+ * What a jsoneditor content ({text} or {json}) holds, as TEXT:
105
+ * the text as typed, or the tree-mode json serialized -- which is
106
+ * what get_form_values() reads out of the editor too. Handing the
107
+ * tree-mode value back as is made parse_json_field() parse a
108
+ * string ROOT a second time: "123" was checked as the number 123,
109
+ * and "abc" as a text that is no json.
110
+ ************************************************************/
111
+ export function json_editor_value(content)
112
+ {
113
+ if(!content) {
114
+ return undefined;
115
+ }
116
+ if(content.text !== undefined) {
117
+ return content.text;
118
+ }
119
+ if(content.json === undefined) {
120
+ return undefined;
121
+ }
122
+ return JSON.stringify(content.json);
123
+ }
@@ -0,0 +1,49 @@
1
+ /***********************************************************************
2
+ * form_json_field.test.js
3
+ *
4
+ * Copyright (c) 2026, ArtGins.
5
+ * All Rights Reserved.
6
+ ***********************************************************************/
7
+ import {describe, it, expect} from "vitest";
8
+ import {parse_json_field, json_field_shape, json_editor_value} from "./form_json_field.js";
9
+
10
+ describe("parse_json_field", () => {
11
+ it("a text that does not parse is an error, never an empty dict to store", () => {
12
+ expect(parse_json_field('{"a": 1,}', "dict")).toEqual({value: {}, error: "invalid json"});
13
+ expect(parse_json_field(json_editor_value({text: '[1, 2'}), "list")).toEqual({value: [], error: "invalid json"});
14
+ expect(parse_json_field('{"x": }', "template").error).toBe("invalid json");
15
+ expect(parse_json_field('nope', "blob").error).toBe("invalid json");
16
+ });
17
+
18
+ it("json of the wrong shape is an error", () => {
19
+ expect(parse_json_field('[1]', "dict").error).toBe("invalid json");
20
+ expect(parse_json_field('{"a": 1}', "list").error).toBe("invalid json");
21
+ expect(parse_json_field('null', "dict").error).toBe("invalid json");
22
+ expect(parse_json_field('3', "coordinates").error).toBe("invalid json");
23
+ });
24
+
25
+ it("good json comes back parsed", () => {
26
+ expect(parse_json_field('{"a": 1}', "dict")).toEqual({value: {a: 1}, error: ""});
27
+ expect(parse_json_field(json_editor_value({json: [1, 2]}), "table")).toEqual({value: [1, 2], error: ""});
28
+ expect(parse_json_field('[0, 1]', "coordinates")).toEqual({value: [0, 1], error: ""});
29
+ expect(parse_json_field('"s"', "blob")).toEqual({value: "s", error: ""});
30
+ expect(parse_json_field({text: 1}, "dict")).toEqual({value: {text: 1}, error: ""});
31
+ });
32
+
33
+ it("a blank editor is the empty value, not an error", () => {
34
+ expect(parse_json_field("", "dict")).toEqual({value: {}, error: ""});
35
+ expect(parse_json_field(json_editor_value({text: " "}), "list")).toEqual({value: [], error: ""});
36
+ });
37
+
38
+ it("shapes", () => {
39
+ expect(json_field_shape("object")).toBe("dict");
40
+ expect(json_field_shape("table")).toBe("list");
41
+ expect(json_field_shape("blob")).toBe("any");
42
+ });
43
+
44
+ it("a tree-mode string root is read as the string it is, as the save reads it", () => {
45
+ expect(json_editor_value({json: "123"})).toBe('"123"');
46
+ expect(parse_json_field(json_editor_value({json: "123"}), "blob")).toEqual({value: "123", error: ""});
47
+ expect(parse_json_field(json_editor_value({json: "abc"}), "blob")).toEqual({value: "abc", error: ""});
48
+ });
49
+ });
@@ -0,0 +1,137 @@
1
+ /***********************************************************************
2
+ * form_json_field.wiring.test.js
3
+ *
4
+ * A C_YUI_FORM json field (a jsoneditor) whose TEXT does not parse
5
+ * was saved as `{}` or `[]`: validate_form() asked the browser
6
+ * (checkValidity) and the tables, and a jsoneditor is neither; the
7
+ * conversion then caught the parse error and stored the empty
8
+ * value. Driven through the real gclass on a document double, with
9
+ * the editor replaced by a double that answers what the real one
10
+ * answers in text mode.
11
+ *
12
+ * Copyright (c) 2026, ArtGins.
13
+ * All Rights Reserved.
14
+ ***********************************************************************/
15
+ import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
16
+ import {install_dom_double} from "../test/dom_double.js";
17
+
18
+ install_dom_double();
19
+
20
+ if(typeof globalThis.ResizeObserver === "undefined") {
21
+ globalThis.ResizeObserver = class {
22
+ observe() {}
23
+ unobserve() {}
24
+ disconnect() {}
25
+ };
26
+ }
27
+
28
+ /* The editor: what the reader typed, in text mode. */
29
+ const editors = vi.hoisted(() => []);
30
+ vi.mock("vanilla-jsoneditor", () => ({
31
+ createJSONEditor: (opts) => {
32
+ const ed = {
33
+ content: {text: ""},
34
+ props: opts.props,
35
+ get() {
36
+ return this.content;
37
+ },
38
+ set(content) {
39
+ this.content = content;
40
+ },
41
+ destroy() {},
42
+ };
43
+ editors.push(ed);
44
+ return ed;
45
+ },
46
+ }));
47
+
48
+ const {
49
+ SDATA_END, gclass_create,
50
+ gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
51
+ gobj_start, gobj_send_event, gobj_read_attr,
52
+ set_log_callback,
53
+ } = await import("@yuneta/gobj-js");
54
+ const {register_c_yui_form} = await import("./c_yui_form.js");
55
+
56
+ const saved = [];
57
+ const logged = [];
58
+ let yuno = null;
59
+
60
+ beforeAll(async () => {
61
+ const i18next = (await import("i18next")).default;
62
+ await i18next.init({lng: "en", resources: {}});
63
+ gobj_start_up(null, null, null, null, null, null, null);
64
+ set_log_callback((level, msg) => {
65
+ logged.push({level: String(level), msg: String(msg)});
66
+ });
67
+ gclass_create("C_TEST_FORM_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
68
+ gclass_create(
69
+ "C_TEST_FORM_APP",
70
+ [["EV_SAVE_RECORD", 0], ["EV_RECORD_CHANGED", 0]],
71
+ [["ST_IDLE", [
72
+ ["EV_SAVE_RECORD", (gobj, event, kw) => {
73
+ saved.push(kw);
74
+ return 0;
75
+ }, null],
76
+ ["EV_RECORD_CHANGED", () => 0, null],
77
+ ]]],
78
+ {}, 0, [SDATA_END()], {}, 0, 0, 0, 0
79
+ );
80
+ register_c_yui_form();
81
+ yuno = gobj_create_yuno("form_json_yuno", "C_TEST_FORM_HOST", {});
82
+ gobj_start(yuno);
83
+ });
84
+
85
+ beforeEach(() => {
86
+ saved.length = 0;
87
+ logged.length = 0;
88
+ editors.length = 0;
89
+ });
90
+
91
+ let seq = 0;
92
+
93
+ function build()
94
+ {
95
+ const app = gobj_create_pure_child(`fapp${++seq}`, "C_TEST_FORM_APP", {}, yuno);
96
+ gobj_start(app);
97
+ const form = gobj_create_pure_child(`form${seq}`, "C_YUI_FORM", {
98
+ template: [
99
+ {id: "id", header: "id", type: "string", flag: ["persistent", "required"]},
100
+ {id: "settings", header: "settings", type: "dict", flag: ["persistent", "writable"]},
101
+ ],
102
+ record: {id: "a", settings: {}},
103
+ render_mode: "edit",
104
+ editable: true,
105
+ }, app);
106
+ gobj_start(form);
107
+ const $c = gobj_read_attr(form, "$container");
108
+ const $editor = $c.querySelector(".jsoneditor");
109
+ expect($editor).toBeTruthy();
110
+ expect(editors.length).toBe(1);
111
+ return {form, $editor, editor: editors[0]};
112
+ }
113
+
114
+ describe("a json field that does not parse", () => {
115
+ test("is refused, marked, and nothing is saved", () => {
116
+ const {form, $editor, editor} = build();
117
+ editor.content = {text: '{"a": 1,}'};
118
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
119
+ expect(saved).toEqual([]);
120
+ expect($editor.classList.contains("is-danger")).toBe(true);
121
+ expect($editor.yui_json_error).toBe("invalid json");
122
+ });
123
+
124
+ test("is saved once it holds json again", () => {
125
+ const {form, $editor, editor} = build();
126
+ editor.content = {text: '[1]'};
127
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
128
+ expect(saved).toEqual([]);
129
+
130
+ editor.content = {text: '{"a": 1}'};
131
+ editor.props.onChange();
132
+ expect($editor.classList.contains("is-danger")).toBe(false);
133
+ gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
134
+ expect(saved.length).toBe(1);
135
+ expect(saved[0].settings).toEqual({a: 1}); // parsed: the backend gets json, not text
136
+ });
137
+ });
@@ -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
+ });
@@ -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
+ }
@@ -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, so no DOM needed.
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", () => {
@@ -267,7 +267,33 @@ function c_text(text)
267
267
  return text
268
268
  .replace(/\\/g, JSON_BACKSLASH)
269
269
  .replace(/"/g, JSON_DQUOTE)
270
- .replace(/'/g, JSON_QUOTE);
270
+ .replace(/'/g, JSON_QUOTE)
271
+ .replace(/[\u0000-\u001f\u007f]/g, json_control);
272
+ }
273
+
274
+ /* A control character (a newline in a description) cannot stand as
275
+ * itself in either layer: a raw newline ends the C literal's line,
276
+ * and JSON refuses any control character inside a string. It is
277
+ * written as its JSON escape, with the backslash doubled for C. */
278
+ const JSON_SHORT_ESCAPES = {"\n": "n", "\r": "r", "\t": "t", "\b": "b", "\f": "f"};
279
+
280
+ function json_control(ch)
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
+ }
292
+ let short = JSON_SHORT_ESCAPES[ch];
293
+ if(short) {
294
+ return C_BACKSLASH + short;
295
+ }
296
+ return C_BACKSLASH + "u" + ch.charCodeAt(0).toString(16).padStart(4, "0");
271
297
  }
272
298
 
273
299
  /***************************************************************
@@ -17,7 +17,8 @@ import { schema_to_diagram } from "./schema_to_diagram.js";
17
17
 
18
18
 
19
19
  /***************************************************************
20
- * What the yuno does to the literal before parsing it:
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 ",
@@ -228,6 +229,19 @@ describe("the characters that cannot be written as themselves", () => {
228
229
  expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe("a\\b");
229
230
  });
230
231
 
232
+ test("a newline, a tab and another control character survive both layers", () => {
233
+ const header = "line one\nline\ttwo\r\u0001";
234
+ const src = with_header(header);
235
+ expect(src.split("\n").every((line) => !line.includes("line two"))).toBe(true);
236
+ expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe(header);
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
+
231
245
  test("all three at once", () => {
232
246
  const header = 'a\\b "c" d\'e';
233
247
  expect(load_like_the_yuno(with_header(header)).topics[0].cols.id.header)
@@ -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"}, message]
158
+ ["p", {...p_attrs, class: "TOAST_MSG"},
159
+ (typeof message === "string")? text_node(message) : message]
158
160
  ]
159
161
  ]
160
162
  );
@@ -281,7 +283,7 @@ 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
288
  ? [["span", {class: "MODAL_TITLE_KIND", i18n: title}, title]]
287
289
  : [])],
@@ -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 => {