@yuneta/gobj-ui 7.26.7 → 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.
- package/dist/gobj-ui.cjs.js +372 -175
- package/dist/gobj-ui.es.js +372 -175
- package/package.json +1 -1
- package/src/c_g6_nodes_tree.js +28 -24
- package/src/c_yui_form.js +197 -63
- package/src/c_yui_gclass.js +22 -21
- package/src/c_yui_gobj_tree_js.js +7 -7
- 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 +7 -6
- package/src/c_yui_schema_editor.js +3 -2
- package/src/c_yui_shell.js +7 -0
- package/src/c_yui_treedb_topic_with_form.js +22 -17
- package/src/c_yui_treedb_topics.js +8 -7
- package/src/c_yui_window.js +72 -31
- 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/g6_event_kw.js +36 -0
- package/src/nav_cards_helpers.js +2 -1
- package/src/nav_cards_helpers.test.js +7 -3
- package/src/schema_to_c.js +10 -0
- package/src/schema_to_c.test.js +8 -1
- package/src/shell_modals.js +5 -3
- 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 +79 -0
- package/src/window_show.wiring.test.js +83 -0
- package/src/window_veto_back.wiring.test.js +35 -0
- package/src/yui_dev.js +13 -11
- package/src/yui_frontend_view.js +4 -4
- package/src/yui_gclass_view.js +3 -3
- package/src/yui_text.js +31 -0
- package/src/yui_text.test.js +39 -0
- package/vite-plugin-yuneta-html.js +9 -4
package/src/c_yui_window.js
CHANGED
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
} from "./c_yui_shell.js";
|
|
55
55
|
|
|
56
56
|
import "./c_yui_window.css";
|
|
57
|
+
import {text_node} from "./yui_text.js";
|
|
57
58
|
|
|
58
59
|
/***************************************************************
|
|
59
60
|
* Constants
|
|
@@ -104,9 +105,9 @@ SDATA(data_type_t.DTP_STRING, "title_prefix", 0, "", "Optional DATA half
|
|
|
104
105
|
SDATA(data_type_t.DTP_STRING, "title", 0, "", "Window title, an i18n KEY: painted in the title bar (unless `header` overrides it) and on the dock chip. Pass the key, not t(key), or it cannot re-translate"),
|
|
105
106
|
SDATA(data_type_t.DTP_STRING, "icon", 0, "", "Window icon (by window type), leading the title bar and the dock chip: a yi-* class name or inline SVG"),
|
|
106
107
|
// TODO declared, NOT implemented yet: focus, modal, keyboard (Escape does not close a window)
|
|
107
|
-
SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "
|
|
108
|
-
SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "
|
|
109
|
-
SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "
|
|
108
|
+
SDATA(data_type_t.DTP_POINTER, "focus", 0, null, "NOT implemented yet: would bring focus to the element, a number or a selector"),
|
|
109
|
+
SDATA(data_type_t.DTP_BOOLEAN, "modal", 0, false, "NOT implemented yet: would enable modal mode"),
|
|
110
|
+
SDATA(data_type_t.DTP_BOOLEAN, "keyboard", 0, true, "NOT implemented yet: would close the window on ESC (Escape does nothing today)"),
|
|
110
111
|
SDATA(data_type_t.DTP_BOOLEAN, "back_dismissable", 0, true, "Browser Back closes this window (floating overlays only; ignored when it has a `manager`)"),
|
|
111
112
|
SDATA(data_type_t.DTP_BOOLEAN, "keep_on_navigate", 0, false, "This window is a navigation PANEL: a route change does not close it"),
|
|
112
113
|
SDATA(data_type_t.DTP_POINTER, "back_overlay", 0, null, "Internal: overlay-history entry (Back-button integration)"),
|
|
@@ -340,7 +341,7 @@ function build_default_header(gobj)
|
|
|
340
341
|
if(!empty_string(prefix)) {
|
|
341
342
|
items.push(
|
|
342
343
|
['span', {class: 'WINDOW_TITLE_PREFIX has-text-weight-semibold'},
|
|
343
|
-
|
|
344
|
+
text_node(prefix)] // data, not markup
|
|
344
345
|
);
|
|
345
346
|
}
|
|
346
347
|
if(!empty_string(title)) {
|
|
@@ -772,13 +773,25 @@ function register_back_overlay(gobj)
|
|
|
772
773
|
if(!shell) {
|
|
773
774
|
return;
|
|
774
775
|
}
|
|
776
|
+
/* A window that survives its close gets its entry back -- but only
|
|
777
|
+
* once the question is over. A close that ASKS (unsaved changes)
|
|
778
|
+
* opened a dialog that registered its own entry; one put back now
|
|
779
|
+
* would sit ABOVE the question, and every Back would stack another
|
|
780
|
+
* dialog instead of closing the one on screen. */
|
|
781
|
+
const rearm = function() {
|
|
782
|
+
if(!gobj_is_destroying(gobj) && !gobj_read_attr(gobj, "back_overlay")) {
|
|
783
|
+
register_back_overlay(gobj);
|
|
784
|
+
}
|
|
785
|
+
};
|
|
775
786
|
let overlay = yui_shell_register_overlay(
|
|
776
787
|
shell,
|
|
777
788
|
function() {
|
|
778
789
|
gobj_write_attr(gobj, "back_overlay", null);
|
|
779
|
-
close_window(gobj);
|
|
780
|
-
if(
|
|
781
|
-
|
|
790
|
+
const closing = close_window(gobj);
|
|
791
|
+
if(closing.state === "vetoed") {
|
|
792
|
+
rearm();
|
|
793
|
+
} else if(closing.state === "asking") {
|
|
794
|
+
closing.answer.then(rearm);
|
|
782
795
|
}
|
|
783
796
|
},
|
|
784
797
|
{keep_on_navigate: gobj_read_bool_attr(gobj, "keep_on_navigate")}
|
|
@@ -787,7 +800,12 @@ function register_back_overlay(gobj)
|
|
|
787
800
|
}
|
|
788
801
|
|
|
789
802
|
/************************************************************
|
|
790
|
-
*
|
|
803
|
+
* Ask to close the window. Answers what happened:
|
|
804
|
+
* {state: "closed"} the window is destroyed
|
|
805
|
+
* {state: "vetoed"} a subscriber kept it open
|
|
806
|
+
* {state: "asking", answer} a subscriber asked a question
|
|
807
|
+
* first; `answer` resolves to
|
|
808
|
+
* it once it is over
|
|
791
809
|
************************************************************/
|
|
792
810
|
function close_window(gobj)
|
|
793
811
|
{
|
|
@@ -809,29 +827,34 @@ function close_window(gobj)
|
|
|
809
827
|
}
|
|
810
828
|
gobj_stop_children(gobj);
|
|
811
829
|
gobj_destroy(gobj);
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
).then(function(answer) {
|
|
817
|
-
if(answer !== "yes") {
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
/* The question was asynchronous: the window may have been
|
|
821
|
-
* torn down by another path while it was open. */
|
|
822
|
-
if(gobj_is_destroying(gobj)) {
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
if(on_close) {
|
|
826
|
-
on_close();
|
|
827
|
-
}
|
|
828
|
-
if(gobj_is_running(gobj)) {
|
|
829
|
-
gobj_stop(gobj);
|
|
830
|
-
}
|
|
831
|
-
gobj_stop_children(gobj);
|
|
832
|
-
gobj_destroy(gobj);
|
|
833
|
-
});
|
|
830
|
+
return {state: "closed"};
|
|
831
|
+
}
|
|
832
|
+
if(!kw_close.warning) {
|
|
833
|
+
return {state: "vetoed"};
|
|
834
834
|
}
|
|
835
|
+
const answer = yui_shell_confirm_yesnocancel(
|
|
836
|
+
yui_shell_of(gobj), kw_close.warning,
|
|
837
|
+
{t: t, yes_label: "yes", no_label: "no", cancel_label: "cancel"}
|
|
838
|
+
).then(function(answer) {
|
|
839
|
+
if(answer !== "yes") {
|
|
840
|
+
return answer;
|
|
841
|
+
}
|
|
842
|
+
/* The question was asynchronous: the window may have been
|
|
843
|
+
* torn down by another path while it was open. */
|
|
844
|
+
if(gobj_is_destroying(gobj)) {
|
|
845
|
+
return answer;
|
|
846
|
+
}
|
|
847
|
+
if(on_close) {
|
|
848
|
+
on_close();
|
|
849
|
+
}
|
|
850
|
+
if(gobj_is_running(gobj)) {
|
|
851
|
+
gobj_stop(gobj);
|
|
852
|
+
}
|
|
853
|
+
gobj_stop_children(gobj);
|
|
854
|
+
gobj_destroy(gobj);
|
|
855
|
+
return answer;
|
|
856
|
+
});
|
|
857
|
+
return {state: "asking", answer: answer};
|
|
835
858
|
}
|
|
836
859
|
|
|
837
860
|
/************************************************************
|
|
@@ -1211,7 +1234,25 @@ function ac_refresh(gobj, event, kw, src)
|
|
|
1211
1234
|
************************************************************/
|
|
1212
1235
|
function ac_show(gobj, event, kw, src)
|
|
1213
1236
|
{
|
|
1214
|
-
|
|
1237
|
+
/* Bring the window back in front of the reader: out of the dock if
|
|
1238
|
+
* it was minimized, above the others. The manager owns both when
|
|
1239
|
+
* there is one; without one the window is just made visible and
|
|
1240
|
+
* moved to the top of its layer. */
|
|
1241
|
+
let manager = gobj_read_pointer_attr(gobj, "manager");
|
|
1242
|
+
if(manager) {
|
|
1243
|
+
gobj_send_event(manager, "EV_FOCUS_WINDOW", {window: gobj}, gobj);
|
|
1244
|
+
return 0;
|
|
1245
|
+
}
|
|
1246
|
+
let $container = gobj_read_attr(gobj, "$container");
|
|
1247
|
+
if(!$container) {
|
|
1248
|
+
log_error(`${gobj_short_name(gobj)}: EV_SHOW without a container`);
|
|
1249
|
+
return -1;
|
|
1250
|
+
}
|
|
1251
|
+
$container.style.removeProperty('display');
|
|
1252
|
+
let $parent = $container.parentNode;
|
|
1253
|
+
if($parent && $parent.lastChild !== $container) {
|
|
1254
|
+
$parent.appendChild($container);
|
|
1255
|
+
}
|
|
1215
1256
|
return 0;
|
|
1216
1257
|
}
|
|
1217
1258
|
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
} from "@yuneta/gobj-js";
|
|
46
46
|
|
|
47
47
|
import {t} from "i18next";
|
|
48
|
+
import {text_node} from "./yui_text.js";
|
|
48
49
|
|
|
49
50
|
|
|
50
51
|
/***************************************************************
|
|
@@ -470,7 +471,7 @@ function ac_register_window(gobj, event, kw, src)
|
|
|
470
471
|
let label_items = [];
|
|
471
472
|
if(prefix) {
|
|
472
473
|
label_items.push(['span', {class: 'yui-dock-label-prefix'},
|
|
473
|
-
|
|
474
|
+
text_node(prefix)]); // data, not markup
|
|
474
475
|
}
|
|
475
476
|
if(title_key) {
|
|
476
477
|
label_items.push(
|
|
@@ -481,7 +482,7 @@ function ac_register_window(gobj, event, kw, src)
|
|
|
481
482
|
if(label_items.length === 0) {
|
|
482
483
|
/* No split halves supplied (legacy caller): plain text. */
|
|
483
484
|
label_items.push(['span', {class: 'yui-dock-label-kind'},
|
|
484
|
-
|
|
485
|
+
text_node(title)]); // data, not markup
|
|
485
486
|
}
|
|
486
487
|
|
|
487
488
|
let entry = {gobj: win, $chip: null, minimized: false};
|
package/src/form_json_field.js
CHANGED
|
@@ -101,8 +101,12 @@ export function parse_json_field(value, type)
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/************************************************************
|
|
104
|
-
* What a jsoneditor content ({text} or {json}) holds:
|
|
105
|
-
* text as typed, or the tree-mode json
|
|
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.
|
|
106
110
|
************************************************************/
|
|
107
111
|
export function json_editor_value(content)
|
|
108
112
|
{
|
|
@@ -112,5 +116,8 @@ export function json_editor_value(content)
|
|
|
112
116
|
if(content.text !== undefined) {
|
|
113
117
|
return content.text;
|
|
114
118
|
}
|
|
115
|
-
|
|
119
|
+
if(content.json === undefined) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return JSON.stringify(content.json);
|
|
116
123
|
}
|
|
@@ -40,4 +40,10 @@ describe("parse_json_field", () => {
|
|
|
40
40
|
expect(json_field_shape("table")).toBe("list");
|
|
41
41
|
expect(json_field_shape("blob")).toBe("any");
|
|
42
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
|
+
});
|
|
43
49
|
});
|
|
@@ -132,6 +132,6 @@ describe("a json field that does not parse", () => {
|
|
|
132
132
|
expect($editor.classList.contains("is-danger")).toBe(false);
|
|
133
133
|
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
134
134
|
expect(saved.length).toBe(1);
|
|
135
|
-
expect(saved[0].settings).
|
|
135
|
+
expect(saved[0].settings).toEqual({a: 1}); // parsed: the backend gets json, not text
|
|
136
136
|
});
|
|
137
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
|
+
}
|
package/src/nav_cards_helpers.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* Copyright (c) 2026, ArtGins.
|
|
12
12
|
* All Rights Reserved.
|
|
13
13
|
***********************************************************************/
|
|
14
|
+
import {text_node} from "./yui_text.js";
|
|
14
15
|
|
|
15
16
|
/************************************************************
|
|
16
17
|
* Descriptor of one card: an <a> carrying the same data-*
|
|
@@ -28,7 +29,7 @@ export function card_descriptor(it, show_label)
|
|
|
28
29
|
["i", {class: it.icon, "aria-hidden": "true"}]]);
|
|
29
30
|
}
|
|
30
31
|
if(show_label && label) {
|
|
31
|
-
children.push(["span", {class: "yui-nav-label", i18n: label}, label]);
|
|
32
|
+
children.push(["span", {class: "yui-nav-label", i18n: label}, text_node(label)]);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
let a_attrs = {
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
* nav_cards_helpers.test.js
|
|
3
3
|
*
|
|
4
4
|
* Unit tests for the pure "cards" layout descriptor builders.
|
|
5
|
-
* Descriptors are plain createElement2 arrays
|
|
5
|
+
* Descriptors are plain createElement2 arrays; the label is a Text
|
|
6
|
+
* node (data, never markup), so a document double is installed.
|
|
6
7
|
***********************************************************************/
|
|
7
8
|
import { test, expect } from "vitest";
|
|
9
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
10
|
+
|
|
11
|
+
install_dom_double();
|
|
8
12
|
import {
|
|
9
13
|
card_descriptor,
|
|
10
14
|
cards_grid_descriptor,
|
|
@@ -35,7 +39,7 @@ test("card carries the nav item data-* contract", () => {
|
|
|
35
39
|
let [label_tag, label_attrs, label_text] = children[1];
|
|
36
40
|
expect(label_tag).toBe("span");
|
|
37
41
|
expect(label_attrs.i18n).toBe("budgets");
|
|
38
|
-
expect(label_text).toBe("budgets");
|
|
42
|
+
expect(label_text.textContent).toBe("budgets");
|
|
39
43
|
});
|
|
40
44
|
|
|
41
45
|
test("card without icon renders label only", () => {
|
|
@@ -45,7 +49,7 @@ test("card without icon renders label only", () => {
|
|
|
45
49
|
);
|
|
46
50
|
expect(children.length).toBe(1);
|
|
47
51
|
expect(children[0][0]).toBe("span");
|
|
48
|
-
expect(children[0][2]).toBe("x label");
|
|
52
|
+
expect(children[0][2].textContent).toBe("x label");
|
|
49
53
|
});
|
|
50
54
|
|
|
51
55
|
test("show_label=false drops the label span", () => {
|
package/src/schema_to_c.js
CHANGED
|
@@ -279,6 +279,16 @@ const JSON_SHORT_ESCAPES = {"\n": "n", "\r": "r", "\t": "t", "\b": "b", "\f": "f
|
|
|
279
279
|
|
|
280
280
|
function json_control(ch)
|
|
281
281
|
{
|
|
282
|
+
/* A NUL has no way through: jansson refuses "\u0000" in a string
|
|
283
|
+
* unless the loader passes JSON_ALLOW_NUL, which the yunos do not, so
|
|
284
|
+
* the whole schema would fail to load. It is written as U+FFFD, the
|
|
285
|
+
* replacement character -- visible in the literal and on screen, not
|
|
286
|
+
* dropped without a trace (this module is dependency-free on purpose:
|
|
287
|
+
* scripts/schema_diagram.mjs loads it with no npm install, so it has
|
|
288
|
+
* no log to write to). */
|
|
289
|
+
if(ch === "\u0000") {
|
|
290
|
+
return C_BACKSLASH + "ufffd";
|
|
291
|
+
}
|
|
282
292
|
let short = JSON_SHORT_ESCAPES[ch];
|
|
283
293
|
if(short) {
|
|
284
294
|
return C_BACKSLASH + short;
|
package/src/schema_to_c.test.js
CHANGED
|
@@ -17,7 +17,8 @@ import { schema_to_diagram } from "./schema_to_diagram.js";
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
/***************************************************************
|
|
20
|
-
*
|
|
20
|
+
* A JS MODEL of the yuno's loader (not the C code itself) --
|
|
21
|
+
* what the yuno does to the literal before parsing it:
|
|
21
22
|
* 1. the C compiler resolves `\<newline>` continuations and
|
|
22
23
|
* the `\\` / `\"` escapes,
|
|
23
24
|
* 2. helper_quote2doublequote() turns EVERY ' into ",
|
|
@@ -235,6 +236,12 @@ describe("the characters that cannot be written as themselves", () => {
|
|
|
235
236
|
expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe(header);
|
|
236
237
|
});
|
|
237
238
|
|
|
239
|
+
test("a NUL becomes U+FFFD: jansson refuses \\u0000 without JSON_ALLOW_NUL", () => {
|
|
240
|
+
const src = with_header("a\u0000b");
|
|
241
|
+
expect(src.includes("u0000")).toBe(false);
|
|
242
|
+
expect(load_like_the_yuno(src).topics[0].cols.id.header).toBe("a\ufffdb");
|
|
243
|
+
});
|
|
244
|
+
|
|
238
245
|
test("all three at once", () => {
|
|
239
246
|
const header = 'a\\b "c" d\'e';
|
|
240
247
|
expect(load_like_the_yuno(with_header(header)).topics[0].cols.id.header)
|
package/src/shell_modals.js
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
yui_shell_register_overlay,
|
|
48
48
|
yui_shell_overlay_dismissed,
|
|
49
49
|
} from "./c_yui_shell.js";
|
|
50
|
+
import {text_node} from "./yui_text.js";
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
/***************************************************************
|
|
@@ -154,7 +155,8 @@ function show_notification(shell, kind, message, opts)
|
|
|
154
155
|
[
|
|
155
156
|
["button", {class: "TOAST_CLOSE delete", title: t("close"), "data-i18n-title": "close",
|
|
156
157
|
"aria-label": t("close"), "data-i18n-aria-label": "close"}],
|
|
157
|
-
["p", {...p_attrs, class: "TOAST_MSG"},
|
|
158
|
+
["p", {...p_attrs, class: "TOAST_MSG"},
|
|
159
|
+
(typeof message === "string")? text_node(message) : message]
|
|
158
160
|
]
|
|
159
161
|
]
|
|
160
162
|
);
|
|
@@ -281,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 => {
|
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);
|