@yuneta/gobj-ui 7.27.32 → 7.27.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -5
- package/dist/gobj-ui.cjs.js +139 -37
- package/dist/gobj-ui.es.js +139 -37
- package/package.json +2 -1
- package/src/c_yui_form.js +3 -2
- package/src/c_yui_fsm_graph.js +2 -1
- package/src/c_yui_gobj_tree_js.js +60 -15
- package/src/c_yui_json_graph.js +5 -4
- package/src/c_yui_nav.js +5 -11
- package/src/c_yui_schema_editor.js +2 -1
- package/src/c_yui_shell.js +3 -2
- package/src/c_yui_treedb_graph.js +2 -1
- package/src/c_yui_treedb_schema.js +5 -1
- package/src/c_yui_treedb_topic_with_form.js +5 -4
- package/src/c_yui_treedb_topics.js +4 -3
- package/src/g6_patches_first_graph.wiring.test.js +179 -0
- package/src/gobj_tree_remote.wiring.test.js +119 -3
- package/src/selector_from_data.wiring.test.js +296 -0
- package/src/yui_selector.js +79 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/***********************************************************************
|
|
3
|
+
* selector_from_data.wiring.test.js
|
|
4
|
+
*
|
|
5
|
+
* A NAME IS DATA, NOT A SELECTOR (REV-CLOUD V40.3.1).
|
|
6
|
+
*
|
|
7
|
+
* The G6 views gave their canvas mount the id
|
|
8
|
+
* `<prefix><gobj name>` and found it again with
|
|
9
|
+
* `querySelector("#" + id)`. A gobj name may hold any character,
|
|
10
|
+
* and gui_agent names its gobj tree window
|
|
11
|
+
* `<encoded node>~<encoded key>`:
|
|
12
|
+
*
|
|
13
|
+
* - `~` is a CSS combinator: the lookup answered null, so every
|
|
14
|
+
* open logged "no canvas mount" and the canvas never resized;
|
|
15
|
+
* - `%` (a `^` encoded as `%5E`) makes the selector INVALID:
|
|
16
|
+
* querySelector THROWS, out of mt_start and out of the host's
|
|
17
|
+
* action, and leaves an orphan window behind it -- every later
|
|
18
|
+
* open of that card is "service ALREADY registered";
|
|
19
|
+
* - `.` turns the rest of the id into a class.
|
|
20
|
+
*
|
|
21
|
+
* The real gclasses, in jsdom (whose querySelector throws on an
|
|
22
|
+
* invalid selector as a browser does -- asserted first, or the
|
|
23
|
+
* test proves nothing), on a G6 Graph double.
|
|
24
|
+
*
|
|
25
|
+
* Copyright (c) 2026, ArtGins.
|
|
26
|
+
* All Rights Reserved.
|
|
27
|
+
***********************************************************************/
|
|
28
|
+
import {describe, test, expect, beforeAll, beforeEach, vi} from "vitest";
|
|
29
|
+
|
|
30
|
+
/* What each view watches: the element it handed to observe(). */
|
|
31
|
+
const observed = vi.hoisted(() => []);
|
|
32
|
+
globalThis.ResizeObserver = class {
|
|
33
|
+
observe($el) {
|
|
34
|
+
observed.push($el);
|
|
35
|
+
}
|
|
36
|
+
unobserve() {
|
|
37
|
+
}
|
|
38
|
+
disconnect() {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
vi.mock("@antv/g6", async (importOriginal) => {
|
|
43
|
+
const real = await importOriginal();
|
|
44
|
+
class FakeGraph {
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.options = options;
|
|
47
|
+
return new Proxy(this, {
|
|
48
|
+
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
draw() {
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
on() {
|
|
58
|
+
}
|
|
59
|
+
getZoom() {
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
getPosition() {
|
|
63
|
+
return [0, 0];
|
|
64
|
+
}
|
|
65
|
+
zoomTo() {
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
translateTo() {
|
|
69
|
+
return Promise.resolve();
|
|
70
|
+
}
|
|
71
|
+
getData() {
|
|
72
|
+
return {nodes: [], edges: [], combos: []};
|
|
73
|
+
}
|
|
74
|
+
getNodeData() {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
getEdgeData() {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
getPlugins() {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
getBehaviors() {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
getOptions() {
|
|
87
|
+
return {behaviors: []};
|
|
88
|
+
}
|
|
89
|
+
getCanvas() {
|
|
90
|
+
return {getLayers: () => ({}), getContainer: () => null};
|
|
91
|
+
}
|
|
92
|
+
fitView() {
|
|
93
|
+
return Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
destroy() {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {...real, Graph: FakeGraph};
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
|
|
103
|
+
gobj_create_pure_child, gobj_start, gobj_read_attr, gobj_read_str_attr,
|
|
104
|
+
gobj_find_service, gobj_name, set_log_callback, register_c_timer,
|
|
105
|
+
} = await import("@yuneta/gobj-js");
|
|
106
|
+
const {register_c_yui_gobj_tree_js} = await import("./c_yui_gobj_tree_js.js");
|
|
107
|
+
const {register_c_yui_json_graph} = await import("./c_yui_json_graph.js");
|
|
108
|
+
const {register_c_yui_fsm_graph} = await import("./c_yui_fsm_graph.js");
|
|
109
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
110
|
+
const {open_gobj_tree_view, close_gobj_tree_view} = await import("./yui_gobj_tree_view.js");
|
|
111
|
+
const {css_string, find_by_id} = await import("./yui_selector.js");
|
|
112
|
+
|
|
113
|
+
const logged = [];
|
|
114
|
+
let yuno = null;
|
|
115
|
+
let host = null;
|
|
116
|
+
let seq = 0;
|
|
117
|
+
|
|
118
|
+
/* The names of the review, and the old one with a dot. */
|
|
119
|
+
const NAMES = [
|
|
120
|
+
"local~gate", /* gui_agent 0.29.106: node~key */
|
|
121
|
+
"n~x%5Ey", /* a `^` in the key, encoded */
|
|
122
|
+
"node.a~key.b", /* a dot: a class selector */
|
|
123
|
+
"a b#c:d[e]\"f\\g", /* what clean_name() leaves and what it does not */
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
beforeAll(async () => {
|
|
127
|
+
const i18next = (await import("i18next")).default;
|
|
128
|
+
await i18next.init({lng: "en", resources: {en: {translation: {}}}});
|
|
129
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
130
|
+
set_log_callback((level, msg) => {
|
|
131
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
132
|
+
});
|
|
133
|
+
register_c_timer();
|
|
134
|
+
register_c_yui_gobj_tree_js();
|
|
135
|
+
register_c_yui_json_graph();
|
|
136
|
+
register_c_yui_fsm_graph();
|
|
137
|
+
register_c_yui_window();
|
|
138
|
+
gclass_create("C_TEST_SEL_YUNO", [], [["ST_IDLE", []]], {}, 0,
|
|
139
|
+
[SDATA_END()], {}, 0, 0, 0, 0);
|
|
140
|
+
gclass_create("C_TEST_SEL_HOST",
|
|
141
|
+
[["EV_TREE_WANTED", 0], ["EV_TRACE_INFO_WANTED", 0],
|
|
142
|
+
["EV_SET_TRACE_LEVEL", 0], ["EV_GCLASS_WANTED", 0]],
|
|
143
|
+
[["ST_IDLE", [
|
|
144
|
+
["EV_TREE_WANTED", null, null],
|
|
145
|
+
["EV_TRACE_INFO_WANTED", null, null],
|
|
146
|
+
["EV_SET_TRACE_LEVEL", null, null],
|
|
147
|
+
["EV_GCLASS_WANTED", null, null],
|
|
148
|
+
]]],
|
|
149
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
150
|
+
yuno = gobj_create_yuno("sel_yuno", "C_TEST_SEL_YUNO", {});
|
|
151
|
+
host = gobj_create("host", "C_TEST_SEL_HOST", {}, yuno);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
logged.length = 0;
|
|
156
|
+
observed.length = 0;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
function problems()
|
|
160
|
+
{
|
|
161
|
+
return logged.filter((l) => l.level === "error" || l.level === "warning").map((l) => l.msg);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function settle()
|
|
165
|
+
{
|
|
166
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
describe("the environment is a browser for selectors", () => {
|
|
170
|
+
test("jsdom's querySelector throws on an invalid selector, and reads `~` as a combinator", () => {
|
|
171
|
+
const $root = document.createElement("div");
|
|
172
|
+
const $a = document.createElement("div");
|
|
173
|
+
$a.id = "gobj-tree-canvas-gobj-tree-local~gate";
|
|
174
|
+
$root.appendChild($a);
|
|
175
|
+
const $b = document.createElement("div");
|
|
176
|
+
$b.id = "gobj-tree-canvas-gobj-tree-n~x%5Ey";
|
|
177
|
+
$root.appendChild($b);
|
|
178
|
+
|
|
179
|
+
expect($root.querySelector("#" + $a.id)).toBe(null);
|
|
180
|
+
expect(() => $root.querySelector("#" + $b.id)).toThrow(/selector/i);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("yui_selector.js", () => {
|
|
185
|
+
test("find_by_id() finds any id, in a detached tree, and only below the root", () => {
|
|
186
|
+
const $root = document.createElement("div");
|
|
187
|
+
for(const name of NAMES) {
|
|
188
|
+
const $el = document.createElement("div");
|
|
189
|
+
$el.id = "x-" + name;
|
|
190
|
+
const $wrap = document.createElement("section");
|
|
191
|
+
$wrap.appendChild($el);
|
|
192
|
+
$root.appendChild($wrap);
|
|
193
|
+
expect(find_by_id($root, "x-" + name)).toBe($el);
|
|
194
|
+
}
|
|
195
|
+
$root.id = "the-root";
|
|
196
|
+
expect(find_by_id($root, "the-root")).toBe(null);
|
|
197
|
+
expect(find_by_id($root, "x-absent")).toBe(null);
|
|
198
|
+
expect(find_by_id(null, "x")).toBe(null);
|
|
199
|
+
expect(find_by_id($root, "")).toBe(null);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("css_string() quotes any value for an attribute selector", () => {
|
|
203
|
+
const $root = document.createElement("div");
|
|
204
|
+
const values = NAMES.concat(["a\"]b", "back\\slash", "new\nline", "tab\there", "]'\""]);
|
|
205
|
+
for(const v of values) {
|
|
206
|
+
const $el = document.createElement("a");
|
|
207
|
+
$el.setAttribute("data-v", v);
|
|
208
|
+
$root.appendChild($el);
|
|
209
|
+
}
|
|
210
|
+
for(const v of values) {
|
|
211
|
+
const $found = $root.querySelector('[data-v="' + css_string(v) + '"]');
|
|
212
|
+
expect($found, JSON.stringify(v)).toBeTruthy();
|
|
213
|
+
expect($found.getAttribute("data-v")).toBe(v);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("C_YUI_GOBJ_TREE_JS in a window named by data", () => {
|
|
219
|
+
for(const name of NAMES) {
|
|
220
|
+
test(`open_gobj_tree_view(${JSON.stringify(name)}): the canvas is found and watched`, async () => {
|
|
221
|
+
let handle = null;
|
|
222
|
+
expect(() => {
|
|
223
|
+
handle = open_gobj_tree_view(host, {source: "remote", name: name, title: name});
|
|
224
|
+
}).not.toThrow();
|
|
225
|
+
expect(handle).toBeTruthy();
|
|
226
|
+
expect(handle.win).toBeTruthy();
|
|
227
|
+
await settle();
|
|
228
|
+
|
|
229
|
+
const canvas_id = gobj_read_str_attr(handle.tree, "canvas_id");
|
|
230
|
+
const $canvas = document.getElementById(canvas_id);
|
|
231
|
+
expect($canvas).toBeTruthy();
|
|
232
|
+
expect(observed).toContain($canvas);
|
|
233
|
+
expect(problems()).toEqual([]);
|
|
234
|
+
|
|
235
|
+
/* Closed and opened again: nothing was left registered. */
|
|
236
|
+
const win_name = gobj_name(handle.win);
|
|
237
|
+
close_gobj_tree_view(handle);
|
|
238
|
+
expect(gobj_find_service(win_name, false)).toBeFalsy();
|
|
239
|
+
const again = open_gobj_tree_view(host, {source: "remote", name: name, title: name});
|
|
240
|
+
expect(again && again.win).toBeTruthy();
|
|
241
|
+
await settle();
|
|
242
|
+
expect(problems()).toEqual([]);
|
|
243
|
+
close_gobj_tree_view(again);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
async function mount(gclass_name, name, attrs)
|
|
249
|
+
{
|
|
250
|
+
const $container = document.createElement("div");
|
|
251
|
+
document.body.appendChild($container);
|
|
252
|
+
const view = gobj_create_pure_child(name, gclass_name,
|
|
253
|
+
Object.assign({$container: $container}, attrs), yuno);
|
|
254
|
+
document.body.appendChild(gobj_read_attr(view, "$container"));
|
|
255
|
+
gobj_start(view);
|
|
256
|
+
await settle();
|
|
257
|
+
return view;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const FSM = {
|
|
261
|
+
entry_state: "ST_IDLE",
|
|
262
|
+
states: [{name: "ST_IDLE"}, {name: "ST_BUSY"}],
|
|
263
|
+
rows: [
|
|
264
|
+
{event: "EV_GO", cells: [{next_state: "ST_BUSY"}, null]},
|
|
265
|
+
{event: "EV_DONE", cells: [null, {next_state: "ST_IDLE"}]},
|
|
266
|
+
],
|
|
267
|
+
published: [],
|
|
268
|
+
unreachable: [],
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
describe("the other G6 views named by data", () => {
|
|
272
|
+
for(const name of NAMES) {
|
|
273
|
+
test(`C_YUI_JSON_GRAPH ${JSON.stringify(name)}: fold handles and resize on its canvas`, async () => {
|
|
274
|
+
let view = null;
|
|
275
|
+
await expect((async () => {
|
|
276
|
+
view = await mount("C_YUI_JSON_GRAPH", `json-${++seq}-${name}`, {json_data: {a: 1}});
|
|
277
|
+
})()).resolves.toBeUndefined();
|
|
278
|
+
const $canvas = document.getElementById(gobj_read_str_attr(view, "canvas_id"));
|
|
279
|
+
expect($canvas).toBeTruthy();
|
|
280
|
+
expect(view.priv.fold_listener).toBeTruthy();
|
|
281
|
+
expect(observed).toContain($canvas);
|
|
282
|
+
expect(problems()).toEqual([]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test(`C_YUI_FSM_GRAPH ${JSON.stringify(name)}: the graph is built on its canvas`, async () => {
|
|
286
|
+
let view = null;
|
|
287
|
+
await expect((async () => {
|
|
288
|
+
view = await mount("C_YUI_FSM_GRAPH", `fsm-${++seq}-${name}`, {fsm: FSM});
|
|
289
|
+
})()).resolves.toBeUndefined();
|
|
290
|
+
const $canvas = document.getElementById(gobj_read_str_attr(view, "canvas_id"));
|
|
291
|
+
expect($canvas).toBeTruthy();
|
|
292
|
+
expect(view.priv.graph).toBeTruthy();
|
|
293
|
+
expect(problems()).toEqual([]);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_selector.js
|
|
3
|
+
*
|
|
4
|
+
* A NAME IS DATA, NOT A SELECTOR.
|
|
5
|
+
*
|
|
6
|
+
* A gobj name, a topic, a route, a key: any of them may hold a
|
|
7
|
+
* character that means something to CSS. Pasted into a selector,
|
|
8
|
+
* it changes what the selector says or breaks it:
|
|
9
|
+
*
|
|
10
|
+
* - `~ + > space` are combinators: `#a~b` is "a b after an #a",
|
|
11
|
+
* and the lookup answers null;
|
|
12
|
+
* - `.` `#` `:` `[` start another simple selector: `#a.b` is the
|
|
13
|
+
* element #a with the class b;
|
|
14
|
+
* - `%` `^` `"` `\` and the rest make it INVALID: querySelector
|
|
15
|
+
* THROWS a SyntaxError, out of whatever action was running.
|
|
16
|
+
*
|
|
17
|
+
* REV-CLOUD V40.3.1: the gobj tree found its canvas with
|
|
18
|
+
* `querySelector("#" + id)`, and gui_agent named the window
|
|
19
|
+
* `node~key` -- every open logged "no canvas mount" and the
|
|
20
|
+
* canvas never resized; a `^` in the key (`%5E`) threw out of
|
|
21
|
+
* mt_start and left an orphan window behind it.
|
|
22
|
+
*
|
|
23
|
+
* So data reaches a selector in one of two ways only:
|
|
24
|
+
*
|
|
25
|
+
* find_by_id($root, id) the element below $root whose id is
|
|
26
|
+
* `id` -- no selector is built at all.
|
|
27
|
+
* It works in a tree that is not in the
|
|
28
|
+
* document yet, where getElementById()
|
|
29
|
+
* answers null.
|
|
30
|
+
*
|
|
31
|
+
* css_string(value) the value written inside a DOUBLE
|
|
32
|
+
* quoted CSS string, for an attribute
|
|
33
|
+
* selector:
|
|
34
|
+
* '[data-x="' + css_string(v) + '"]'
|
|
35
|
+
*
|
|
36
|
+
* `CSS.escape()` is not used: it does not exist in node, where the
|
|
37
|
+
* wiring tests run, and inside a quoted string only the quote, the
|
|
38
|
+
* backslash and the control characters have to be escaped.
|
|
39
|
+
*
|
|
40
|
+
* Copyright (c) 2026, ArtGins.
|
|
41
|
+
* All Rights Reserved.
|
|
42
|
+
***********************************************************************/
|
|
43
|
+
|
|
44
|
+
/************************************************************
|
|
45
|
+
* The element below `$root` (not `$root` itself, as with
|
|
46
|
+
* querySelector) whose id is exactly `id`, or null.
|
|
47
|
+
************************************************************/
|
|
48
|
+
export function find_by_id($root, id)
|
|
49
|
+
{
|
|
50
|
+
if(!$root || typeof $root.querySelectorAll !== "function") {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if(id === null || id === undefined || id === "") {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
let wanted = String(id);
|
|
57
|
+
for(let $el of $root.querySelectorAll("[id]")) {
|
|
58
|
+
if($el.id === wanted) {
|
|
59
|
+
return $el;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/************************************************************
|
|
66
|
+
* `value` as the body of a double-quoted CSS string.
|
|
67
|
+
*
|
|
68
|
+
* The quote and the backslash take a backslash; a control
|
|
69
|
+
* character (a newline ends a CSS string, it is a parse
|
|
70
|
+
* error inside one) is written as its hex escape, which a
|
|
71
|
+
* space ends so the next character is never read as hex.
|
|
72
|
+
************************************************************/
|
|
73
|
+
export function css_string(value)
|
|
74
|
+
{
|
|
75
|
+
return String(value)
|
|
76
|
+
.replace(/[\\"]/g, "\\$&")
|
|
77
|
+
.replace(/[\u0000-\u001f\u007f]/g,
|
|
78
|
+
(c) => "\\" + c.charCodeAt(0).toString(16) + " ");
|
|
79
|
+
}
|