@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
package/src/c_yui_json_graph.js
CHANGED
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
} from "./json_view_helpers.js";
|
|
85
85
|
import {g6_event_kw} from "./g6_event_kw.js";
|
|
86
86
|
import {keep_canvas_tab_order} from "./g6_canvas_tab_order.js";
|
|
87
|
+
import {find_by_id, css_string} from "./yui_selector.js";
|
|
87
88
|
|
|
88
89
|
/***************************************************************
|
|
89
90
|
* Constants
|
|
@@ -470,7 +471,7 @@ function build_ui(gobj)
|
|
|
470
471
|
* and `mousedown` goes with them for a browser that still sends it.
|
|
471
472
|
* Measured by instrumenting the mount, not guessed.
|
|
472
473
|
*/
|
|
473
|
-
let $mount = $container
|
|
474
|
+
let $mount = find_by_id($container, priv.canvas_id);
|
|
474
475
|
if($mount) {
|
|
475
476
|
priv.fold_listener = function(evt) {
|
|
476
477
|
let $handle = evt.target && evt.target.closest
|
|
@@ -518,7 +519,7 @@ function destroy_ui(gobj)
|
|
|
518
519
|
let $container = gobj_read_attr(gobj, "$container");
|
|
519
520
|
|
|
520
521
|
if(priv.fold_listener) {
|
|
521
|
-
let $mount = $container
|
|
522
|
+
let $mount = find_by_id($container, priv.canvas_id);
|
|
522
523
|
if($mount) {
|
|
523
524
|
for(let type of FOLD_SWALLOWED_EVENTS) {
|
|
524
525
|
$mount.removeEventListener(type, priv.fold_listener, true);
|
|
@@ -716,7 +717,7 @@ function canvas_mount(gobj)
|
|
|
716
717
|
if(!$container) {
|
|
717
718
|
return null;
|
|
718
719
|
}
|
|
719
|
-
return $container
|
|
720
|
+
return find_by_id($container, gobj.priv.canvas_id);
|
|
720
721
|
}
|
|
721
722
|
|
|
722
723
|
/************************************************************
|
|
@@ -2243,7 +2244,7 @@ function paint_anchor_mark(gobj)
|
|
|
2243
2244
|
return;
|
|
2244
2245
|
}
|
|
2245
2246
|
let $it = $container.querySelector(
|
|
2246
|
-
'.JSON_CARD[data-json-path="' +
|
|
2247
|
+
'.JSON_CARD[data-json-path="' + css_string(priv.anchor_path) + '"]'
|
|
2247
2248
|
);
|
|
2248
2249
|
if($it) {
|
|
2249
2250
|
$it.classList.add('JSON_CARD_ANCHORED');
|
package/src/c_yui_nav.js
CHANGED
|
@@ -109,6 +109,7 @@ import {
|
|
|
109
109
|
bulma_hidden_class,
|
|
110
110
|
} from "./shell_show_on.js";
|
|
111
111
|
import {text_node} from "./yui_text.js";
|
|
112
|
+
import {css_string} from "./yui_selector.js";
|
|
112
113
|
import {badge_node, badge_tone, paint_badge, name_control_with_badge} from "./yui_badge.js";
|
|
113
114
|
|
|
114
115
|
/***************************************************************
|
|
@@ -363,7 +364,7 @@ function apply_active_route(gobj)
|
|
|
363
364
|
if(!$c || empty_string(route)) {
|
|
364
365
|
return;
|
|
365
366
|
}
|
|
366
|
-
let $a = $c.querySelector(`a[data-route="${
|
|
367
|
+
let $a = $c.querySelector(`a[data-route="${css_string(route)}"]`);
|
|
367
368
|
if($a) {
|
|
368
369
|
let $li = $a.closest("li");
|
|
369
370
|
if($li) {
|
|
@@ -1088,7 +1089,7 @@ function ac_set_item_badge(gobj, event, kw, src)
|
|
|
1088
1089
|
return 0;
|
|
1089
1090
|
}
|
|
1090
1091
|
let $badges = $c.querySelectorAll(
|
|
1091
|
-
`[data-item-id="${
|
|
1092
|
+
`[data-item-id="${css_string(item_id)}"] .NAV_ITEM_BADGE`
|
|
1092
1093
|
);
|
|
1093
1094
|
for(let $badge of $badges) {
|
|
1094
1095
|
paint_badge($badge, badge, tone);
|
|
@@ -1147,7 +1148,7 @@ function ac_route_changed(gobj, event, kw, src)
|
|
|
1147
1148
|
return 0;
|
|
1148
1149
|
}
|
|
1149
1150
|
|
|
1150
|
-
let $a = $c.querySelector(`[data-item-id="${
|
|
1151
|
+
let $a = $c.querySelector(`[data-item-id="${css_string(id_to_mark)}"]`);
|
|
1151
1152
|
if($a) {
|
|
1152
1153
|
/* For Bulma .tabs and .menu, 'is-active' goes on the <li> parent. */
|
|
1153
1154
|
let $li = $a.closest("li");
|
|
@@ -1168,7 +1169,7 @@ function ac_route_changed(gobj, event, kw, src)
|
|
|
1168
1169
|
return;
|
|
1169
1170
|
}
|
|
1170
1171
|
let contains_active = !!$body.querySelector(
|
|
1171
|
-
`[data-item-id="${
|
|
1172
|
+
`[data-item-id="${css_string(active_leaf_id)}"]`
|
|
1172
1173
|
);
|
|
1173
1174
|
$body.classList.toggle("is-hidden", !contains_active);
|
|
1174
1175
|
$hd.classList.toggle("is-open", contains_active);
|
|
@@ -1178,13 +1179,6 @@ function ac_route_changed(gobj, event, kw, src)
|
|
|
1178
1179
|
return 0;
|
|
1179
1180
|
}
|
|
1180
1181
|
|
|
1181
|
-
function css_escape(s)
|
|
1182
|
-
{
|
|
1183
|
-
/* For a quoted attribute selector: a backslash too, or a route
|
|
1184
|
-
* carrying one makes querySelector throw. */
|
|
1185
|
-
return String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
1182
|
/***************************************************************
|
|
1189
1183
|
* FSM
|
|
1190
1184
|
***************************************************************/
|
|
@@ -163,6 +163,7 @@ import {
|
|
|
163
163
|
|
|
164
164
|
import {t} from "i18next";
|
|
165
165
|
import {text_node} from "./yui_text.js";
|
|
166
|
+
import {css_string} from "./yui_selector.js";
|
|
166
167
|
|
|
167
168
|
|
|
168
169
|
/***************************************************************
|
|
@@ -2189,7 +2190,7 @@ function apply_form_changes(gobj, $form, changes)
|
|
|
2189
2190
|
if(name === "flag") {
|
|
2190
2191
|
continue;
|
|
2191
2192
|
}
|
|
2192
|
-
let $control = $form.querySelector(`[data-name="${name}"]`);
|
|
2193
|
+
let $control = $form.querySelector(`[data-name="${css_string(name)}"]`);
|
|
2193
2194
|
if(!$control) {
|
|
2194
2195
|
log_warning(`${gobj_short_name(gobj)}: a change of '${name}' has no field ` +
|
|
2195
2196
|
`in the form opened again: not put back`);
|
package/src/c_yui_shell.js
CHANGED
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
badge_node, badge_tone, badge_text, paint_badge, name_control_with_badge,
|
|
75
75
|
} from "./yui_badge.js";
|
|
76
76
|
import { build_nav_map } from "./route_map_model.js";
|
|
77
|
+
import { css_string } from "./yui_selector.js";
|
|
77
78
|
import {
|
|
78
79
|
section_index_target,
|
|
79
80
|
secondary_nav_renders,
|
|
@@ -5226,7 +5227,7 @@ function yui_shell_set_toolbar_item_icon(shell_gobj, item_id, icon_class)
|
|
|
5226
5227
|
return;
|
|
5227
5228
|
}
|
|
5228
5229
|
let $i = $container.querySelector(
|
|
5229
|
-
`[data-toolbar-item-id="${item_id}"] .icon i`
|
|
5230
|
+
`[data-toolbar-item-id="${css_string(item_id)}"] .icon i`
|
|
5230
5231
|
);
|
|
5231
5232
|
if($i) {
|
|
5232
5233
|
$i.className = icon_class;
|
|
@@ -5271,7 +5272,7 @@ function yui_shell_set_toolbar_item_badge(shell_gobj, item_id, value, tone)
|
|
|
5271
5272
|
return;
|
|
5272
5273
|
}
|
|
5273
5274
|
let $badge = $container.querySelector(
|
|
5274
|
-
`[data-toolbar-item-id="${item_id}"] .yui-toolbar-badge`
|
|
5275
|
+
`[data-toolbar-item-id="${css_string(item_id)}"] .yui-toolbar-badge`
|
|
5275
5276
|
);
|
|
5276
5277
|
if(!$badge) {
|
|
5277
5278
|
return;
|
|
@@ -92,6 +92,7 @@ import {
|
|
|
92
92
|
set_active_state,
|
|
93
93
|
set_pressed_state,
|
|
94
94
|
} from "./lib_graph.js";
|
|
95
|
+
import {find_by_id} from "./yui_selector.js";
|
|
95
96
|
import {yui_shell_show_error, yui_shell_show_modal} from "./shell_modals.js";
|
|
96
97
|
import {yui_shell_of, yui_shell_set_sub_routes, yui_shell_navigate, yui_shell_previous_route}
|
|
97
98
|
from "./c_yui_shell.js";
|
|
@@ -258,7 +259,7 @@ function mt_create(gobj)
|
|
|
258
259
|
/*
|
|
259
260
|
* Get canvas container
|
|
260
261
|
*/
|
|
261
|
-
let $container_canvas = $container
|
|
262
|
+
let $container_canvas = find_by_id($container, priv.canvas_id);
|
|
262
263
|
|
|
263
264
|
priv.gobj_nodes_tree = gobj_create_service(
|
|
264
265
|
`${gobj_name(gobj)}-g6`,
|
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
yui_graph_forward_wheel,
|
|
68
68
|
yui_graph_update_zoom,
|
|
69
69
|
} from "./yui_graph_camera.js";
|
|
70
|
+
import {ensure_drag_canvas_patch} from "./g6_drag_canvas_touch.js";
|
|
70
71
|
import {ensure_pinch_zoom_patch} from "./g6_touch_gestures.js";
|
|
71
72
|
import {keep_canvas_tab_order} from "./g6_canvas_tab_order.js";
|
|
72
73
|
import {col_key_roles} from "./treedb_topic_keys.js";
|
|
@@ -143,7 +144,10 @@ let __gclass__ = null;
|
|
|
143
144
|
|
|
144
145
|
function mt_create(gobj)
|
|
145
146
|
{
|
|
146
|
-
/*
|
|
147
|
+
/* The two touch fixes of the other graphs: a pan that follows a
|
|
148
|
+
* finger, and pinch to zoom. Both, or as the FIRST graph of a page
|
|
149
|
+
* the schema kept G6's own drag-canvas (REV-CLOUD V40.2). */
|
|
150
|
+
ensure_drag_canvas_patch();
|
|
147
151
|
ensure_pinch_zoom_patch();
|
|
148
152
|
|
|
149
153
|
build_ui(gobj);
|
|
@@ -115,6 +115,7 @@ import {
|
|
|
115
115
|
yui_asset_ids, yui_asset_element, yui_asset_open_link, yui_asset_release
|
|
116
116
|
} from "./yui_asset.js";
|
|
117
117
|
import {delete_impact} from "./delete_impact.js";
|
|
118
|
+
import {find_by_id} from "./yui_selector.js";
|
|
118
119
|
import {parse_json_field} from "./form_json_field.js";
|
|
119
120
|
|
|
120
121
|
import "./c_yui_treedb_topic_with_form.css";
|
|
@@ -808,7 +809,7 @@ function build_ui(gobj)
|
|
|
808
809
|
]]
|
|
809
810
|
]]
|
|
810
811
|
);
|
|
811
|
-
let $search_input = $search_box
|
|
812
|
+
let $search_input = find_by_id($search_box, search_id);
|
|
812
813
|
/* NORM clear (✕): dispatches a synthetic `input`, so the tabulator
|
|
813
814
|
* filter below re-runs (empty term → clearFilter). */
|
|
814
815
|
attach_clear($search_box, $search_input);
|
|
@@ -983,7 +984,7 @@ function build_ui(gobj)
|
|
|
983
984
|
gobj_write_attr(gobj, "selection_bar", bar);
|
|
984
985
|
/* Chrome too: it must not take height from the rows. */
|
|
985
986
|
bar.$el.style.flex = "none";
|
|
986
|
-
$container.insertBefore(bar.$el, $container
|
|
987
|
+
$container.insertBefore(bar.$el, find_by_id($container, table_id));
|
|
987
988
|
}
|
|
988
989
|
|
|
989
990
|
/* The parent filter, when a hook of another row opened this table
|
|
@@ -1009,7 +1010,7 @@ function build_ui(gobj)
|
|
|
1009
1010
|
]]
|
|
1010
1011
|
);
|
|
1011
1012
|
gobj.priv.$parent_filter = $parent_filter;
|
|
1012
|
-
$container.insertBefore($parent_filter, $container
|
|
1013
|
+
$container.insertBefore($parent_filter, find_by_id($container, table_id));
|
|
1013
1014
|
|
|
1014
1015
|
let $toolbar_slot = $container.querySelector('.toolbar_tabulator_table');
|
|
1015
1016
|
if($table_toolbar instanceof Element) {
|
|
@@ -1772,7 +1773,7 @@ function create_tabulator(gobj)
|
|
|
1772
1773
|
*/
|
|
1773
1774
|
let $view_container = gobj_read_attr(gobj, "$container");
|
|
1774
1775
|
let $table_el = $view_container ?
|
|
1775
|
-
$view_container
|
|
1776
|
+
find_by_id($view_container, table_id) : null;
|
|
1776
1777
|
if(!$table_el) {
|
|
1777
1778
|
log_error(`${gobj_short_name(gobj)}: table element '#${table_id}' not found in $container`);
|
|
1778
1779
|
return;
|
|
@@ -86,6 +86,7 @@ import {
|
|
|
86
86
|
|
|
87
87
|
import {t} from "i18next";
|
|
88
88
|
import {text_node} from "./yui_text.js";
|
|
89
|
+
import {css_string} from "./yui_selector.js";
|
|
89
90
|
|
|
90
91
|
/***************************************************************
|
|
91
92
|
* Constants
|
|
@@ -671,7 +672,7 @@ function add_tab(gobj, gobj2, id, text, icon)
|
|
|
671
672
|
function remove_tab(gobj, gobj2, id)
|
|
672
673
|
{
|
|
673
674
|
let $container = gobj_read_attr(gobj, "$container");
|
|
674
|
-
let $a = $container.querySelector(`a[href="${id}"]`);
|
|
675
|
+
let $a = $container.querySelector(`a[href="${css_string(id)}"]`);
|
|
675
676
|
if($a) {
|
|
676
677
|
let $li = $a.parentNode;
|
|
677
678
|
if($li) {
|
|
@@ -687,7 +688,7 @@ function remove_tab(gobj, gobj2, id)
|
|
|
687
688
|
}
|
|
688
689
|
/* Drop its landing card too, if any. */
|
|
689
690
|
let $card = $container.querySelector(
|
|
690
|
-
`.TREEDB_TOPIC_CARD[data-topic-href="${id}"]`);
|
|
691
|
+
`.TREEDB_TOPIC_CARD[data-topic-href="${css_string(id)}"]`);
|
|
691
692
|
if($card && $card.parentNode) {
|
|
692
693
|
$card.parentNode.removeChild($card);
|
|
693
694
|
}
|
|
@@ -2681,7 +2682,7 @@ function ac_show(gobj, event, kw, src)
|
|
|
2681
2682
|
|
|
2682
2683
|
let $container = gobj_read_attr(gobj, "$container");
|
|
2683
2684
|
let $current_item = gobj_read_attr(gobj, "$current_item");
|
|
2684
|
-
let $a = $container.querySelector(`a[href="${href}"]`);
|
|
2685
|
+
let $a = $container.querySelector(`a[href="${css_string(href)}"]`);
|
|
2685
2686
|
if($a) {
|
|
2686
2687
|
/*
|
|
2687
2688
|
* href pointing to inside gobj (with ? right part)
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* g6_patches_first_graph.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* Every G6 view of the library is fixed for touch on its OWN, when
|
|
5
|
+
* it is the first graph of the page (REV-CLOUD V40.2 note 1).
|
|
6
|
+
*
|
|
7
|
+
* gobj-ui replaces two built-ins of G6 -- `drag-canvas` (a pan
|
|
8
|
+
* that reads the pointer, not `movementX`, which a touch screen
|
|
9
|
+
* leaves at 0) and `zoom-canvas` (pinch) -- globally, the first
|
|
10
|
+
* time a view asks. C_YUI_TREEDB_SCHEMA asked only for the pinch
|
|
11
|
+
* and still put `drag-canvas` in its behaviors: as the first graph
|
|
12
|
+
* of a page it kept G6's own, and panned only when another view
|
|
13
|
+
* had been opened before it.
|
|
14
|
+
*
|
|
15
|
+
* Each test starts from a fresh module registry -- the page before
|
|
16
|
+
* any graph -- and mounts ONE view, the real gclass on a G6 Graph
|
|
17
|
+
* double (the registry of behaviors is G6's own).
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2026, ArtGins.
|
|
20
|
+
* All Rights Reserved.
|
|
21
|
+
***********************************************************************/
|
|
22
|
+
import {describe, test, expect, vi, beforeAll, beforeEach} from "vitest";
|
|
23
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
24
|
+
|
|
25
|
+
install_dom_double();
|
|
26
|
+
|
|
27
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
28
|
+
globalThis.ResizeObserver = class {
|
|
29
|
+
observe() {
|
|
30
|
+
}
|
|
31
|
+
unobserve() {
|
|
32
|
+
}
|
|
33
|
+
disconnect() {
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
vi.mock("@antv/g6", async (importOriginal) => {
|
|
39
|
+
const real = await importOriginal();
|
|
40
|
+
class FakeGraph {
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
return new Proxy(this, {
|
|
44
|
+
get: (t, k) => (k in t) ? t[k] : (() => undefined),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
render() {
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
|
50
|
+
draw() {
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
on() {
|
|
54
|
+
}
|
|
55
|
+
getZoom() {
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
getData() {
|
|
59
|
+
return {nodes: [], edges: [], combos: []};
|
|
60
|
+
}
|
|
61
|
+
getNodeData() {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
getEdgeData() {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
getPlugins() {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
getBehaviors() {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
getOptions() {
|
|
74
|
+
return {behaviors: []};
|
|
75
|
+
}
|
|
76
|
+
getCanvas() {
|
|
77
|
+
return {getLayers: () => ({}), getContainer: () => null};
|
|
78
|
+
}
|
|
79
|
+
fitView() {
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
}
|
|
82
|
+
zoomTo() {
|
|
83
|
+
return Promise.resolve();
|
|
84
|
+
}
|
|
85
|
+
destroy() {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {...real, Graph: FakeGraph};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const DESC = {topic_name: "users", cols: [
|
|
92
|
+
{id: "id", type: "string", flag: ["persistent"]},
|
|
93
|
+
]};
|
|
94
|
+
|
|
95
|
+
/* Each view: its module, its register function, what it needs to
|
|
96
|
+
* draw a first time. C_YUI_FSM_GRAPH goes first: the gobj tree
|
|
97
|
+
* registers it too (through C_YUI_GCLASS), and a gclass registered
|
|
98
|
+
* by an EARLIER evaluation of its module would run that module's
|
|
99
|
+
* code -- asserted below, so the order cannot hide a stale one. */
|
|
100
|
+
const VIEWS = {
|
|
101
|
+
C_YUI_FSM_GRAPH: ["./c_yui_fsm_graph.js", "register_c_yui_fsm_graph", {fsm: {
|
|
102
|
+
entry_state: "ST_IDLE",
|
|
103
|
+
states: [{name: "ST_IDLE"}],
|
|
104
|
+
rows: [],
|
|
105
|
+
published: [],
|
|
106
|
+
unreachable: [],
|
|
107
|
+
}}],
|
|
108
|
+
C_YUI_TREEDB_SCHEMA: ["./c_yui_treedb_schema.js", "register_c_yui_treedb_schema",
|
|
109
|
+
{descs: {users: DESC}}],
|
|
110
|
+
C_YUI_JSON_GRAPH: ["./c_yui_json_graph.js", "register_c_yui_json_graph",
|
|
111
|
+
{json_data: {a: 1}}],
|
|
112
|
+
C_YUI_GOBJ_TREE_JS: ["./c_yui_gobj_tree_js.js", "register_c_yui_gobj_tree_js", {}],
|
|
113
|
+
C_G6_NODES_TREE: ["./c_g6_nodes_tree.js", "register_c_g6_nodes_tree",
|
|
114
|
+
{with_toolbar: false, operation_mode: "reading"}],
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const gobj_js = await import("@yuneta/gobj-js");
|
|
118
|
+
const logged = [];
|
|
119
|
+
let yuno = null;
|
|
120
|
+
|
|
121
|
+
beforeAll(async () => {
|
|
122
|
+
const i18next = (await import("i18next")).default;
|
|
123
|
+
await i18next.init({lng: "en", resources: {en: {translation: {}}}});
|
|
124
|
+
gobj_js.gobj_start_up(null, null, null, null, null, null, null);
|
|
125
|
+
gobj_js.set_log_callback((level, msg) => {
|
|
126
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
127
|
+
});
|
|
128
|
+
gobj_js.register_c_timer();
|
|
129
|
+
gobj_js.gclass_create("C_TEST_FIRST_GRAPH", [], [["ST_IDLE", []]], {}, 0,
|
|
130
|
+
[gobj_js.SDATA_END()], {}, 0, 0, 0, 0);
|
|
131
|
+
yuno = gobj_js.gobj_create_yuno("first_graph", "C_TEST_FIRST_GRAPH", {});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/* gobj-js is a dependency, loaded once; the modules of THIS package
|
|
135
|
+
* are evaluated again for each test, their "patched once" flags
|
|
136
|
+
* with them. */
|
|
137
|
+
beforeEach(() => {
|
|
138
|
+
vi.resetModules();
|
|
139
|
+
logged.length = 0;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
describe("the first graph of a page takes both touch patches", () => {
|
|
144
|
+
for(const [gclass_name, [module, register, attrs]] of Object.entries(VIEWS)) {
|
|
145
|
+
test(`${gclass_name}, alone on the page`, async () => {
|
|
146
|
+
const g6 = await import("@antv/g6");
|
|
147
|
+
const B = g6.ExtensionCategory.BEHAVIOR;
|
|
148
|
+
|
|
149
|
+
/* A fresh page: G6's own behaviors, nobody patched yet. The
|
|
150
|
+
* mocked G6 survives resetModules(), so its registry is put
|
|
151
|
+
* back by hand; gobj-ui's modules (and their "patched once"
|
|
152
|
+
* flags) are evaluated again. */
|
|
153
|
+
g6.getExtensions(B)["drag-canvas"] = g6.DragCanvas;
|
|
154
|
+
g6.getExtensions(B)["zoom-canvas"] = g6.ZoomCanvas;
|
|
155
|
+
expect(g6.getExtension(B, "drag-canvas")).toBe(g6.DragCanvas);
|
|
156
|
+
expect(g6.getExtension(B, "zoom-canvas")).toBe(g6.ZoomCanvas);
|
|
157
|
+
|
|
158
|
+
expect(gobj_js.gclass_find_by_name(gclass_name, false)).toBeFalsy();
|
|
159
|
+
const mod = await import(/* @vite-ignore */ module);
|
|
160
|
+
mod[register]();
|
|
161
|
+
|
|
162
|
+
const $container = document.createElement("div");
|
|
163
|
+
document.body.appendChild($container);
|
|
164
|
+
const view = gobj_js.gobj_create_pure_child(`view_${gclass_name}`, gclass_name,
|
|
165
|
+
Object.assign({$container: $container}, attrs), yuno);
|
|
166
|
+
document.body.appendChild(gobj_js.gobj_read_attr(view, "$container"));
|
|
167
|
+
gobj_js.gobj_start(view);
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
169
|
+
|
|
170
|
+
const drag = g6.getExtension(B, "drag-canvas");
|
|
171
|
+
const zoom = g6.getExtension(B, "zoom-canvas");
|
|
172
|
+
expect(drag, "drag-canvas replaced").not.toBe(g6.DragCanvas);
|
|
173
|
+
expect(Object.getPrototypeOf(drag)).toBe(g6.DragCanvas);
|
|
174
|
+
expect(zoom, "zoom-canvas replaced").not.toBe(g6.ZoomCanvas);
|
|
175
|
+
expect(Object.getPrototypeOf(zoom)).toBe(g6.ZoomCanvas);
|
|
176
|
+
expect(logged.filter((l) => l.level === "error").map((l) => l.msg)).toEqual([]);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
@@ -307,7 +307,7 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
307
307
|
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
308
308
|
expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
|
|
309
309
|
scope: "global", gobj: "C_YUNO^gate", gclass: "C_YUNO",
|
|
310
|
-
levels: ["ev_kw"], set: true
|
|
310
|
+
levels: ["ev_kw"], set: true, set_id: expect.any(Number)
|
|
311
311
|
}}]);
|
|
312
312
|
expect(row_of(view, "machine").$global.disabled).toBe(true);
|
|
313
313
|
|
|
@@ -328,7 +328,8 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
328
328
|
wanted.length = 0;
|
|
329
329
|
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["machine"], set: true}, view);
|
|
330
330
|
expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
|
|
331
|
-
scope: "gclass", gobj: "", gclass: "C_TCP", levels: ["machine"], set: true
|
|
331
|
+
scope: "gclass", gobj: "", gclass: "C_TCP", levels: ["machine"], set: true,
|
|
332
|
+
set_id: expect.any(Number)
|
|
332
333
|
}}]);
|
|
333
334
|
expect(problems()).toEqual([]);
|
|
334
335
|
});
|
|
@@ -344,7 +345,7 @@ describe("C_YUI_GOBJ_TREE_JS, source remote", () => {
|
|
|
344
345
|
$gobj.dispatchEvent(fake_event("change"));
|
|
345
346
|
expect(wanted).toEqual([{event: "EV_SET_TRACE_LEVEL", kw: {
|
|
346
347
|
scope: "gobj", gobj: "C_YUNO^gate`C_TCP^tcp1", gclass: "C_TCP",
|
|
347
|
-
levels: ["machine"], set: true
|
|
348
|
+
levels: ["machine"], set: true, set_id: expect.any(Number)
|
|
348
349
|
}}]);
|
|
349
350
|
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
350
351
|
|
|
@@ -574,3 +575,118 @@ describe("C_YUI_GOBJ_TREE_JS, source local", () => {
|
|
|
574
575
|
expect(problems()).toEqual([]);
|
|
575
576
|
});
|
|
576
577
|
});
|
|
578
|
+
|
|
579
|
+
/* REV-CLOUD V40.2: a read asked BEFORE a set, answered after it, is
|
|
580
|
+
* not the set's answer. A host that says which set an answer follows
|
|
581
|
+
* (`set_id`, echoed from EV_SET_TRACE_LEVEL; null for a plain read)
|
|
582
|
+
* is taken at its word; one that says nothing is matched by gclass,
|
|
583
|
+
* as the tests above do. */
|
|
584
|
+
describe("C_YUI_GOBJ_TREE_JS, source remote: a host that says which set it answers", () => {
|
|
585
|
+
const last_set_id = () => {
|
|
586
|
+
const sets = wanted.filter((w) => w.event === "EV_SET_TRACE_LEVEL");
|
|
587
|
+
return sets.length ? sets[sets.length - 1].kw.set_id : undefined;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
test("every set carries its own number", async () => {
|
|
591
|
+
const view = await mount("remote", host);
|
|
592
|
+
await open_tcp_card(view);
|
|
593
|
+
gobj_send_event(view, "EV_TRACE_INFO", TCP_INFO, host);
|
|
594
|
+
const {$gobj} = row_of(view, "machine");
|
|
595
|
+
$gobj.checked = true;
|
|
596
|
+
$gobj.dispatchEvent(fake_event("change"));
|
|
597
|
+
const one = last_set_id();
|
|
598
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: one}), host);
|
|
599
|
+
const again = row_of(view, "machine").$gobj;
|
|
600
|
+
again.checked = true;
|
|
601
|
+
again.dispatchEvent(fake_event("change"));
|
|
602
|
+
const two = last_set_id();
|
|
603
|
+
expect(typeof one).toBe("number");
|
|
604
|
+
expect(typeof two).toBe("number");
|
|
605
|
+
expect(two).not.toBe(one);
|
|
606
|
+
expect(problems()).toEqual([]);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("the card's own read, answered after a tick, leaves the block locked", async () => {
|
|
610
|
+
const view = await mount("remote", host);
|
|
611
|
+
await open_tcp_card(view); /* the card asks: EV_TRACE_INFO_WANTED */
|
|
612
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
613
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
614
|
+
{id: node_id_of(view, "C_YUNO^gate`C_TCP^tcp1"), client_x: 10, client_y: 10}, view);
|
|
615
|
+
|
|
616
|
+
/* ticked before the second read is answered */
|
|
617
|
+
const {$gobj} = row_of(view, "machine");
|
|
618
|
+
$gobj.checked = true;
|
|
619
|
+
$gobj.dispatchEvent(fake_event("change"));
|
|
620
|
+
const set_id = last_set_id();
|
|
621
|
+
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
622
|
+
|
|
623
|
+
/* the read the click asked for: before the set */
|
|
624
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
625
|
+
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
626
|
+
/* a tree a Refresh asked for before the tick */
|
|
627
|
+
gobj_send_event(view, "EV_LOAD_TREE", {tree: TREE, set_id: null}, host);
|
|
628
|
+
expect(row_of(view, "traffic").$gobj.disabled).toBe(true);
|
|
629
|
+
|
|
630
|
+
/* what the backend says after the set */
|
|
631
|
+
const tree = JSON.parse(JSON.stringify(TREE));
|
|
632
|
+
tree["C_YUNO^gate"].children["C_TCP^tcp1"].gobj_trace_level.push("machine");
|
|
633
|
+
gobj_send_event(view, "EV_LOAD_TREE", {tree: tree, set_id: set_id}, host);
|
|
634
|
+
expect([row_of(view, "machine").$gobj.checked, row_of(view, "machine").$gobj.disabled])
|
|
635
|
+
.toEqual([true, false]);
|
|
636
|
+
expect(problems()).toEqual([]);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("the viewer is unlocked by its set's answer, not by a read asked before it", async () => {
|
|
640
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
641
|
+
/* the card asked for C_TCP again; not answered yet */
|
|
642
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
643
|
+
{id: node_id_of(view, "C_YUNO^gate`C_TCP^tcp1"), client_x: 10, client_y: 10}, view);
|
|
644
|
+
gobj_send_event(view, "EV_SET_GCLASS_TRACE", {gclass: "C_TCP", levels: ["traffic"], set: true}, viewer);
|
|
645
|
+
const set_id = last_set_id();
|
|
646
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
647
|
+
|
|
648
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
649
|
+
expect([viewer_box(viewer, "traffic").checked, viewer_box(viewer, "traffic").disabled])
|
|
650
|
+
.toEqual([false, true]);
|
|
651
|
+
expect(view.priv.set_in_flight).not.toBe(null);
|
|
652
|
+
|
|
653
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
654
|
+
{gclass_on: ["connections", "traffic"], set_id: set_id}), host);
|
|
655
|
+
expect([viewer_box(viewer, "traffic").checked, viewer_box(viewer, "traffic").disabled])
|
|
656
|
+
.toEqual([true, false]);
|
|
657
|
+
expect(view.priv.set_in_flight).toBe(null);
|
|
658
|
+
expect(problems()).toEqual([]);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
test("a set of the yuno's scope: the viewer's own read is asked as part of the set", async () => {
|
|
662
|
+
const {view, viewer} = await open_tcp_viewer();
|
|
663
|
+
/* a read of C_TCP asked before the set (the card, opened again) */
|
|
664
|
+
gobj_send_event(view, "EV_NODE_CLICK",
|
|
665
|
+
{id: node_id_of(view, "C_YUNO^gate`C_TCP^tcp1"), client_x: 10, client_y: 10}, view);
|
|
666
|
+
gobj_read_attr(view, "$container").querySelector(".GOBJ_TREE_YUNO_TRACES_BUTTON").click();
|
|
667
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO, {set_id: null}), host);
|
|
668
|
+
wanted.length = 0;
|
|
669
|
+
|
|
670
|
+
const ev_kw = row_of(view, "ev_kw");
|
|
671
|
+
ev_kw.$global.checked = true;
|
|
672
|
+
ev_kw.$global.dispatchEvent(fake_event("change"));
|
|
673
|
+
const set_id = last_set_id();
|
|
674
|
+
wanted.length = 0;
|
|
675
|
+
|
|
676
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, YUNO_INFO,
|
|
677
|
+
{global_on: ["machine", "ev_kw"], set_id: set_id}), host);
|
|
678
|
+
expect(wanted.map((w) => [w.event, w.kw.gclass, w.kw.set_id]))
|
|
679
|
+
.toEqual([["EV_TRACE_INFO_WANTED", "C_TCP", set_id]]);
|
|
680
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
681
|
+
|
|
682
|
+
/* the read asked before the set: not the one the viewer waits for */
|
|
683
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO, {set_id: null}), host);
|
|
684
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(true);
|
|
685
|
+
|
|
686
|
+
gobj_send_event(view, "EV_TRACE_INFO", Object.assign({}, TCP_INFO,
|
|
687
|
+
{global_levels: YUNO_INFO.global_levels,
|
|
688
|
+
gclass_on: ["connections", "ev_kw"], global_on: ["ev_kw"], set_id: set_id}), host);
|
|
689
|
+
expect(viewer_box(viewer, "traffic").disabled).toBe(false);
|
|
690
|
+
expect(problems()).toEqual([]);
|
|
691
|
+
});
|
|
692
|
+
});
|