@yuneta/gobj-ui 7.31.7 → 7.32.0
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 +16 -7
- package/dist/gobj-ui.cjs.js +219 -53
- package/dist/gobj-ui.es.js +219 -53
- package/package.json +1 -1
- package/src/c_yui_json_graph.js +247 -76
- package/src/c_yui_treedb_topics.js +16 -2
- package/src/fmt_date_time.test.js +55 -0
- package/src/json_graph_lit_edge.wiring.test.js +90 -4
- package/src/treedb_topics_transport.wiring.test.js +55 -2
- package/src/yui_date_text.js +27 -2
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
* edge LIGHTS it: the line in amber, its two cards ringed, and
|
|
9
9
|
* the row of the parent's key the line leaves from washed. A
|
|
10
10
|
* second click on it, or a click on the canvas, puts it out; a
|
|
11
|
-
* fold that takes its child card away puts it out too.
|
|
11
|
+
* fold that takes its child card away puts it out too. Lighting
|
|
12
|
+
* and putting out redraw the edge (its `lit` state) and its two
|
|
13
|
+
* cards, never the graph (gobj-ui 7.31.8; before, every click
|
|
14
|
+
* rebuilt every card and ran the layout again).
|
|
12
15
|
*
|
|
13
16
|
* Driven through the real gclass, in jsdom, with a G6 double that
|
|
14
17
|
* keeps the data it is given.
|
|
@@ -36,6 +39,7 @@ vi.mock("@antv/g6", async (importOriginal) => {
|
|
|
36
39
|
this.handlers = {};
|
|
37
40
|
this.plugins = (options.plugins || []).slice();
|
|
38
41
|
this.data = {nodes: [], edges: []};
|
|
42
|
+
this.counts = {setData: 0, draw: 0, updated_nodes: []};
|
|
39
43
|
graphs.push(this);
|
|
40
44
|
return new Proxy(this, {
|
|
41
45
|
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
@@ -47,6 +51,22 @@ vi.mock("@antv/g6", async (importOriginal) => {
|
|
|
47
51
|
e.id = e.id || `e${i}`;
|
|
48
52
|
});
|
|
49
53
|
this.data = data;
|
|
54
|
+
this.counts.setData++;
|
|
55
|
+
}
|
|
56
|
+
updateNodeData(updates) {
|
|
57
|
+
for(const u of updates) {
|
|
58
|
+
const nd = this.getNodeData(u.id);
|
|
59
|
+
nd.style = {...nd.style, ...(u.style || {})};
|
|
60
|
+
this.counts.updated_nodes.push(u.id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
updateData(data) {
|
|
64
|
+
for(const u of (data.edges || [])) {
|
|
65
|
+
const ed = this.getEdgeData(u.id);
|
|
66
|
+
if(u.states !== undefined) {
|
|
67
|
+
ed.states = u.states.slice();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
50
70
|
}
|
|
51
71
|
clear() {
|
|
52
72
|
this.data = {nodes: [], edges: []};
|
|
@@ -55,6 +75,7 @@ vi.mock("@antv/g6", async (importOriginal) => {
|
|
|
55
75
|
return Promise.resolve();
|
|
56
76
|
}
|
|
57
77
|
draw() {
|
|
78
|
+
this.counts.draw++;
|
|
58
79
|
return Promise.resolve();
|
|
59
80
|
}
|
|
60
81
|
on(name, fn) {
|
|
@@ -184,6 +205,7 @@ function card(graph, path)
|
|
|
184
205
|
return graph.data.nodes.find((n) => n.data && n.data.path === path && !n.data.phantom).style.innerHTML;
|
|
185
206
|
}
|
|
186
207
|
const RING = /border: 3px solid/;
|
|
208
|
+
const is_lit = (e) => (e.states || []).includes("lit");
|
|
187
209
|
const WASH = /background:color-mix\(in srgb, #[0-9a-f]+ 28%, transparent\)/g;
|
|
188
210
|
|
|
189
211
|
function problems()
|
|
@@ -222,8 +244,13 @@ describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
|
|
|
222
244
|
await settle();
|
|
223
245
|
|
|
224
246
|
const lit = edge_to(graph, child);
|
|
225
|
-
expect(lit
|
|
226
|
-
expect(
|
|
247
|
+
expect(is_lit(lit)).toBe(true);
|
|
248
|
+
expect(graph.data.edges.filter(is_lit).length).toBe(1);
|
|
249
|
+
/* The look of the state: 3px, amber, a halo */
|
|
250
|
+
const look = graph.options.edge.state.lit();
|
|
251
|
+
expect(look.lineWidth).toBe(3);
|
|
252
|
+
expect(look.halo).toBe(true);
|
|
253
|
+
expect(look.stroke).toMatch(/^#[0-9a-f]{6}$/);
|
|
227
254
|
expect(card(graph, child)).toMatch(RING);
|
|
228
255
|
expect(card(graph, root)).toMatch(RING);
|
|
229
256
|
expect((card(graph, root).match(WASH) || []).length).toBe(1);
|
|
@@ -233,7 +260,7 @@ describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
|
|
|
233
260
|
|
|
234
261
|
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, child).id}});
|
|
235
262
|
await settle();
|
|
236
|
-
expect(edge_to(graph, child)
|
|
263
|
+
expect(is_lit(edge_to(graph, child))).toBe(false);
|
|
237
264
|
expect(card(graph, root)).not.toMatch(RING);
|
|
238
265
|
expect(problems()).toEqual([]);
|
|
239
266
|
});
|
|
@@ -257,4 +284,63 @@ describe("C_YUI_JSON_GRAPH: zoom floor, minimap, lit edge", () => {
|
|
|
257
284
|
expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
|
|
258
285
|
expect(problems()).toEqual([]);
|
|
259
286
|
});
|
|
287
|
+
test("lighting and putting out redraw the edge and its two cards, never the graph", async () => {
|
|
288
|
+
const {graph} = await mount(DOC);
|
|
289
|
+
const root = graph.data.nodes[0];
|
|
290
|
+
const child = graph.data.nodes.find((n) => n.data && n.data.path === "``b");
|
|
291
|
+
const builds = graph.counts.setData;
|
|
292
|
+
const draws = graph.counts.draw;
|
|
293
|
+
|
|
294
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
|
|
295
|
+
await settle();
|
|
296
|
+
expect(graph.counts.setData).toBe(builds);
|
|
297
|
+
expect(graph.counts.draw).toBe(draws + 1);
|
|
298
|
+
expect([...graph.counts.updated_nodes].sort()).toEqual([root.id, child.id].sort());
|
|
299
|
+
|
|
300
|
+
graph.counts.updated_nodes.length = 0;
|
|
301
|
+
graph.emit(CanvasEvent.CLICK, {});
|
|
302
|
+
await settle();
|
|
303
|
+
expect(graph.counts.setData).toBe(builds);
|
|
304
|
+
expect(graph.counts.draw).toBe(draws + 2);
|
|
305
|
+
expect([...graph.counts.updated_nodes].sort()).toEqual([root.id, child.id].sort());
|
|
306
|
+
expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
|
|
307
|
+
expect(graph.data.edges.some(is_lit)).toBe(false);
|
|
308
|
+
expect(problems()).toEqual([]);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test("a click on another edge moves the light in ONE draw", async () => {
|
|
312
|
+
const {graph} = await mount(DOC);
|
|
313
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
|
|
314
|
+
await settle();
|
|
315
|
+
const draws = graph.counts.draw;
|
|
316
|
+
graph.counts.updated_nodes.length = 0;
|
|
317
|
+
|
|
318
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b`y").id}});
|
|
319
|
+
await settle();
|
|
320
|
+
expect(graph.counts.draw).toBe(draws + 1);
|
|
321
|
+
/* `b was the child and is now the parent: repainted once */
|
|
322
|
+
expect(graph.counts.updated_nodes.length).toBe(3);
|
|
323
|
+
expect(is_lit(edge_to(graph, "``b"))).toBe(false);
|
|
324
|
+
expect(is_lit(edge_to(graph, "``b`y"))).toBe(true);
|
|
325
|
+
expect(card(graph, "``b`y")).toMatch(RING);
|
|
326
|
+
expect(card(graph, "``b")).toMatch(RING);
|
|
327
|
+
expect(card(graph, graph.data.nodes[0].data.path)).not.toMatch(RING);
|
|
328
|
+
expect(problems()).toEqual([]);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("a rebuild (a find) keeps the edge lit, and a click on it then puts it out", async () => {
|
|
332
|
+
const {view, graph} = await mount(DOC);
|
|
333
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
|
|
334
|
+
await settle();
|
|
335
|
+
gobj_send_event(view, "EV_FIND_NODES", {text: "z"}, view);
|
|
336
|
+
await settle();
|
|
337
|
+
expect(is_lit(edge_to(graph, "``b"))).toBe(true);
|
|
338
|
+
expect(card(graph, "``b")).toMatch(RING);
|
|
339
|
+
|
|
340
|
+
graph.emit(EdgeEvent.CLICK, {target: {id: edge_to(graph, "``b").id}});
|
|
341
|
+
await settle();
|
|
342
|
+
expect(graph.data.edges.some(is_lit)).toBe(false);
|
|
343
|
+
expect(graph.data.nodes.some((n) => RING.test(n.style.innerHTML || ""))).toBe(false);
|
|
344
|
+
expect(problems()).toEqual([]);
|
|
345
|
+
});
|
|
260
346
|
});
|
|
@@ -34,7 +34,7 @@ const {
|
|
|
34
34
|
SDATA, SDATA_END, data_type_t, event_flag_t,
|
|
35
35
|
gclass_create,
|
|
36
36
|
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
37
|
-
gobj_start, gobj_send_event,
|
|
37
|
+
gobj_start, gobj_send_event, gobj_write_attr,
|
|
38
38
|
gobj_change_state, gobj_current_state,
|
|
39
39
|
set_log_callback,
|
|
40
40
|
} = gobj_js;
|
|
@@ -113,10 +113,16 @@ beforeAll(() => {
|
|
|
113
113
|
["EV_LOAD_NODES", ac_form_load, null],
|
|
114
114
|
["EV_LOAD_NODE_UPDATED", ac_form_update, null]
|
|
115
115
|
]]],
|
|
116
|
-
{
|
|
116
|
+
{
|
|
117
|
+
/* What the view mounts as the topic's tab. */
|
|
118
|
+
mt_create: (gobj) => {
|
|
119
|
+
gobj_write_attr(gobj, "$container", document.createElement("div"));
|
|
120
|
+
}
|
|
121
|
+
},
|
|
117
122
|
0,
|
|
118
123
|
[
|
|
119
124
|
SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "topic"),
|
|
125
|
+
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "the tab's content"),
|
|
120
126
|
SDATA(data_type_t.DTP_BOOLEAN, "with_remote_paging", 0, false, "pulls its pages"),
|
|
121
127
|
SDATA(data_type_t.DTP_POINTER, "tabulator", 0, null, "the table: only getRow() is read"),
|
|
122
128
|
SDATA_END()
|
|
@@ -833,3 +839,50 @@ describe("a link told as EV_TREEDB_NODE_LINKED / UNLINKED", () => {
|
|
|
833
839
|
expect(shown).toEqual([]);
|
|
834
840
|
});
|
|
835
841
|
});
|
|
842
|
+
|
|
843
|
+
/*
|
|
844
|
+
* The topics are shown in ALPHABETICAL order, whatever order the
|
|
845
|
+
* backend's `descs` comes in: the backend's order is not the same from
|
|
846
|
+
* one load to the next. The view loads its topics in the order it shows
|
|
847
|
+
* them, so the `nodes` requests tell that order.
|
|
848
|
+
*/
|
|
849
|
+
describe("the topics in alphabetical order", () => {
|
|
850
|
+
|
|
851
|
+
function load_descs(name, system)
|
|
852
|
+
{
|
|
853
|
+
const host = gobj_create(`${name}_host`, "C_TEST_VIEW_HOST", {}, yuno);
|
|
854
|
+
const topics = gobj_create_service(`${name}_topics`, "C_YUI_TREEDB_TOPICS", {
|
|
855
|
+
treedb_name: "treedb_test",
|
|
856
|
+
gobj_remote_yuno: remote,
|
|
857
|
+
system: system
|
|
858
|
+
}, host);
|
|
859
|
+
gobj_start(topics);
|
|
860
|
+
commands.length = 0;
|
|
861
|
+
const descs = {};
|
|
862
|
+
for(const topic of ["users", "__snaps__", "places", "__icons__",
|
|
863
|
+
"controllers", "__assets__", "device_types"]) {
|
|
864
|
+
descs[topic] = {topic_name: topic, cols: {}};
|
|
865
|
+
}
|
|
866
|
+
gobj_send_event(topics, "EV_MT_COMMAND_ANSWER", {
|
|
867
|
+
result: 0, comment: "", data: descs, __md_iev__: {
|
|
868
|
+
command_stack: [{command: "descs", kw: {}}]
|
|
869
|
+
}
|
|
870
|
+
}, remote);
|
|
871
|
+
return commands.filter((c) => c.command === "nodes")
|
|
872
|
+
.map((c) => c.kw.topic_name);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
test("every topic, the system ones first, when system is true", () => {
|
|
876
|
+
build("to0");
|
|
877
|
+
expect(load_descs("to1", true)).toEqual([
|
|
878
|
+
"__assets__", "__icons__", "__snaps__",
|
|
879
|
+
"controllers", "device_types", "places", "users"
|
|
880
|
+
]);
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
test("the user topics and __icons__, when system is false", () => {
|
|
884
|
+
expect(load_descs("to2", false)).toEqual([
|
|
885
|
+
"__icons__", "controllers", "device_types", "places", "users"
|
|
886
|
+
]);
|
|
887
|
+
});
|
|
888
|
+
});
|
package/src/yui_date_text.js
CHANGED
|
@@ -69,6 +69,30 @@ const DATE_TIME_OPTIONS = {
|
|
|
69
69
|
hourCycle: "h23"
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
/* The formatters of fmt_date_time(), by locale and time zone. A
|
|
73
|
+
* filter over a time column formats every row on every keystroke,
|
|
74
|
+
* and building an Intl.DateTimeFormat costs some 20 times what one
|
|
75
|
+
* format() costs. A formatter keeps the time zone it was built in,
|
|
76
|
+
* so the key carries the zone's offsets in January and in July: a
|
|
77
|
+
* zone that changes under the page (TZ in node, the system's in a
|
|
78
|
+
* browser) gets a new one. Plain Dates, not Intl: nothing of Intl
|
|
79
|
+
* is built at module top level (see safe_locale). */
|
|
80
|
+
const __date_time_formatters__ = new Map();
|
|
81
|
+
const JANUARY = new Date(Date.UTC(2026, 0, 1));
|
|
82
|
+
const JULY = new Date(Date.UTC(2026, 6, 1));
|
|
83
|
+
|
|
84
|
+
function date_time_formatter(locale)
|
|
85
|
+
{
|
|
86
|
+
let loc = safe_locale(locale);
|
|
87
|
+
let key = `${loc}|${JANUARY.getTimezoneOffset()}|${JULY.getTimezoneOffset()}`;
|
|
88
|
+
let f = __date_time_formatters__.get(key);
|
|
89
|
+
if(!f) {
|
|
90
|
+
f = date_time_format(loc, DATE_TIME_OPTIONS);
|
|
91
|
+
__date_time_formatters__.set(key, f);
|
|
92
|
+
}
|
|
93
|
+
return f;
|
|
94
|
+
}
|
|
95
|
+
|
|
72
96
|
/***************************************************************
|
|
73
97
|
* A moment as a VIEW shows it as text: the day, the month and the
|
|
74
98
|
* year, then the clock of 24 hours with its seconds, in the APP's
|
|
@@ -79,7 +103,8 @@ const DATE_TIME_OPTIONS = {
|
|
|
79
103
|
* fmt_date_time(d, "en") -> "Oct 14, 2026, 15:05:09"
|
|
80
104
|
*
|
|
81
105
|
* "" for anything that is not a valid Date. A locale Intl refuses
|
|
82
|
-
* writes in the environment's (date_time_format).
|
|
106
|
+
* writes in the environment's (date_time_format). The formatter is
|
|
107
|
+
* built once per locale and time zone (date_time_formatter).
|
|
83
108
|
*
|
|
84
109
|
* The time cells of C_YUI_FORM and C_YUI_TREEDB_TOPIC_WITH_FORM and
|
|
85
110
|
* the reading C_YUI_JSON writes beside a time field all come from
|
|
@@ -90,7 +115,7 @@ function fmt_date_time(date, locale)
|
|
|
90
115
|
if(!(date instanceof Date) || isNaN(date.getTime())) {
|
|
91
116
|
return "";
|
|
92
117
|
}
|
|
93
|
-
return
|
|
118
|
+
return date_time_formatter(locale).format(date);
|
|
94
119
|
}
|
|
95
120
|
|
|
96
121
|
|