@yuneta/gobj-ui 7.27.32 → 7.27.34

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.
@@ -12,12 +12,13 @@
12
12
  * it WANTS and the host answers with the data:
13
13
  *
14
14
  * out EV_TREE_WANTED {} Refresh pressed
15
- * in EV_LOAD_TREE {tree} the `view-gobj-tree` answer
16
- * out EV_TRACE_INFO_WANTED {gclass} a card was opened
15
+ * in EV_LOAD_TREE {tree, set_id} the `view-gobj-tree` answer
16
+ * out EV_TRACE_INFO_WANTED {gclass, set_id} a card was opened
17
17
  * in EV_TRACE_INFO {gclass, gclass_levels, global_levels,
18
- * gclass_on, global_on, error}
18
+ * gclass_on, global_on, error, set_id}
19
19
  * out EV_SET_TRACE_LEVEL {scope: "gobj"|"gclass"|"global",
20
- * gobj, gclass, levels: [...], set}
20
+ * gobj, gclass, levels: [...], set,
21
+ * set_id}
21
22
  * out EV_GCLASS_WANTED {gclass} the gclass button
22
23
  * in EV_GCLASS_DESCRIPTION {gclass, description}
23
24
  *
@@ -27,6 +28,14 @@
27
28
  * trace info of `gclass` again: what the reader is on stays
28
29
  * open.
29
30
  *
31
+ * `set_id` (7.27.33) numbers each set. A host that echoes
32
+ * it says WHICH set an answer follows: the set_id of the
33
+ * set in the two reads made after it (and in the answer of
34
+ * a WANTED that carried one), null in any other answer. A
35
+ * read asked BEFORE a set and answered after it then no
36
+ * longer unlocks what the set locked. A host that leaves
37
+ * it out is matched by gclass, as before.
38
+ *
30
39
  * TRACES, in "remote": three scopes, each where it belongs.
31
40
  * The kernel's levels (`machine`, `create_delete`...; the
32
41
  * table gobj.c calls "global") are valid in all three, a
@@ -143,6 +152,7 @@ import { ensure_pinch_zoom_patch } from "./g6_touch_gestures.js";
143
152
  import { yui_is_dark, yui_theme_now, yui_watch_theme } from "./yui_theme.js";
144
153
  import {g6_event_kw} from "./g6_event_kw.js";
145
154
  import {keep_canvas_tab_order} from "./g6_canvas_tab_order.js";
155
+ import {find_by_id, css_string} from "./yui_selector.js";
146
156
  import {yui_graph_minimap_options, yui_graph_minimap_block} from "./yui_graph_minimap.js";
147
157
 
148
158
  /***************************************************************
@@ -498,7 +508,10 @@ let PRIVATE_DATA = {
498
508
  popover_mode: "", // what the popover shows: "node" (a card) | "yuno" (the yuno's traces)
499
509
  viewer_awaits: "", // the gclass whose answer unlocks the open viewer ("" = not locked)
500
510
  viewer_stale: "", // a gclass whose open viewer must be asked again after a yuno set
501
- set_in_flight: null, // {gclass, scope}: the set whose answer (EV_TRACE_INFO of gclass) is owed
511
+ set_in_flight: null, // {gclass, scope, set_id}: the set whose answer (EV_TRACE_INFO of gclass) is owed
512
+ set_serial: 0, // numbers the sets (set_id), so an answer can say which one it follows
513
+ pending_set_id: 0, // the set the locked blocks wait for
514
+ viewer_awaits_set: 0, // the set whose answer unlocks the open viewer
502
515
  view_refused: false, // the saved camera showed no card: the opening's framing replaces it
503
516
  };
504
517
 
@@ -1351,7 +1364,7 @@ function canvas_mount(gobj)
1351
1364
  if(!$container) {
1352
1365
  return null;
1353
1366
  }
1354
- return $container.querySelector("#" + gobj.priv.canvas_id);
1367
+ return find_by_id($container, gobj.priv.canvas_id);
1355
1368
  }
1356
1369
 
1357
1370
  /************************************************************
@@ -3291,7 +3304,7 @@ function paint_anchor_mark(gobj)
3291
3304
  return;
3292
3305
  }
3293
3306
  let $it = $container.querySelector(
3294
- '.GOBJ_CARD[data-gobj-name="' + CSS.escape(priv.anchor_name) + '"]'
3307
+ '.GOBJ_CARD[data-gobj-name="' + css_string(priv.anchor_name) + '"]'
3295
3308
  );
3296
3309
  if($it) {
3297
3310
  $it.classList.add('GOBJ_CARD_ANCHORED');
@@ -3667,7 +3680,9 @@ function ac_load_tree(gobj, event, kw, src)
3667
3680
  }
3668
3681
  let first = !priv.remote_root;
3669
3682
  priv.remote_root = root;
3670
- priv.trace_pending = false;
3683
+ if(answers_set(kw, priv.pending_set_id)) {
3684
+ priv.trace_pending = false;
3685
+ }
3671
3686
  reload_keeping_popover(gobj, first? {}: {preserve_view: true});
3672
3687
  return 0;
3673
3688
  }
@@ -3691,8 +3706,11 @@ function ac_trace_info(gobj, event, kw, src)
3691
3706
  global_on: list(kw.global_on),
3692
3707
  error: kw.error || "",
3693
3708
  };
3694
- priv.trace_pending = false;
3695
- if(priv.set_in_flight && priv.set_in_flight.gclass === kw.gclass) {
3709
+ if(answers_set(kw, priv.pending_set_id)) {
3710
+ priv.trace_pending = false;
3711
+ }
3712
+ if(priv.set_in_flight && priv.set_in_flight.gclass === kw.gclass &&
3713
+ answers_set(kw, priv.set_in_flight.set_id)) {
3696
3714
  priv.set_in_flight = null;
3697
3715
  }
3698
3716
 
@@ -3709,18 +3727,21 @@ function ac_trace_info(gobj, event, kw, src)
3709
3727
  /* Only the answer the viewer waits for unlocks it: an answer
3710
3728
  * for another gclass (another card's set) is none of its
3711
3729
  * business. */
3712
- if(priv.viewer_awaits === kw.gclass) {
3730
+ if(priv.viewer_awaits === kw.gclass && answers_set(kw, priv.viewer_awaits_set)) {
3713
3731
  priv.viewer_awaits = "";
3714
3732
  if(priv.viewer_stale === shown && shown !== kw.gclass) {
3715
3733
  /* A set of the YUNO's scope: what the viewer shows as
3716
3734
  * held by the yuno moved too, and the host refreshed
3717
- * only the root's gclass. Locked until its own. */
3735
+ * only the root's gclass. Locked until its own -- a
3736
+ * read that is part of the set, so it carries the
3737
+ * set's number. */
3738
+ let set_id = priv.viewer_awaits_set;
3718
3739
  priv.viewer_stale = "";
3719
3740
  priv.viewer_awaits = shown;
3720
3741
  /* Owed like a set of its own: a viewer of it reopened
3721
3742
  * before the answer opens locked too. */
3722
- priv.set_in_flight = {gclass: shown, scope: "gclass"};
3723
- gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: shown});
3743
+ priv.set_in_flight = {gclass: shown, scope: "gclass", set_id: set_id};
3744
+ gobj_publish_event(gobj, "EV_TRACE_INFO_WANTED", {gclass: shown, set_id: set_id});
3724
3745
  }
3725
3746
  }
3726
3747
  if(shown === kw.gclass) {
@@ -3730,6 +3751,26 @@ function ac_trace_info(gobj, event, kw, src)
3730
3751
  return 0;
3731
3752
  }
3732
3753
 
3754
+ /************************************************************
3755
+ * Is this answer (EV_LOAD_TREE, EV_TRACE_INFO) the one that
3756
+ * follows the set `set_id`?
3757
+ *
3758
+ * A host that echoes `set_id` says so itself: null for a read
3759
+ * that is no set's, which is a read asked BEFORE the set when
3760
+ * it arrives after it (REV-CLOUD V40.2: the card's own read,
3761
+ * answered after a tick, unlocked the block and showed the
3762
+ * levels before the set, enabled, for one round trip). A host
3763
+ * that leaves it out (before 7.27.33) cannot say: any answer
3764
+ * will do, and the caller matches by gclass.
3765
+ ************************************************************/
3766
+ function answers_set(kw, set_id)
3767
+ {
3768
+ if(!kw || kw.set_id === undefined) {
3769
+ return true;
3770
+ }
3771
+ return !!set_id && kw.set_id === set_id;
3772
+ }
3773
+
3733
3774
  /************************************************************
3734
3775
  * The gclass viewer this view opened, while it is open.
3735
3776
  ************************************************************/
@@ -3852,7 +3893,9 @@ function ac_set_gclass_trace(gobj, event, kw, src)
3852
3893
  function set_trace_levels(gobj, target, scope, levels, set)
3853
3894
  {
3854
3895
  let priv = gobj.priv;
3896
+ let set_id = ++priv.set_serial;
3855
3897
  priv.trace_pending = true;
3898
+ priv.pending_set_id = set_id;
3856
3899
  render_current_popover(gobj);
3857
3900
 
3858
3901
  /* The viewer is locked only by a set that moves what it shows:
@@ -3861,12 +3904,17 @@ function set_trace_levels(gobj, target, scope, levels, set)
3861
3904
  * ends that set is not one the viewer would ever be sent. The set
3862
3905
  * is remembered for a viewer opened before its answer, and only
3863
3906
  * the LAST one: the host overtakes an earlier set in flight. */
3864
- priv.set_in_flight = {gclass: target.gclass, scope: scope};
3907
+ priv.set_in_flight = {gclass: target.gclass, scope: scope, set_id: set_id};
3865
3908
  let viewer = gclass_viewer_gobj(gobj);
3866
3909
  if(viewer) {
3867
3910
  let shown = gobj_read_str_attr(viewer, "gclass_name");
3868
3911
  if(lock_viewer_for_set(gobj, shown, priv.set_in_flight)) {
3869
3912
  gobj_send_event(viewer, "EV_SET_TRACES", viewer_traces(gobj, shown), gobj);
3913
+ } else if(priv.viewer_awaits && priv.viewer_awaits === target.gclass) {
3914
+ /* The host replaces the pending read of a gclass with the one
3915
+ * of this newer set: the answer the viewer waited for will
3916
+ * come under this set's number, not the older one's. */
3917
+ priv.viewer_awaits_set = set_id;
3870
3918
  }
3871
3919
  }
3872
3920
 
@@ -3876,6 +3924,7 @@ function set_trace_levels(gobj, target, scope, levels, set)
3876
3924
  gclass: target.gclass,
3877
3925
  levels: levels,
3878
3926
  set: set,
3927
+ set_id: set_id,
3879
3928
  });
3880
3929
  }
3881
3930
 
@@ -3891,6 +3940,7 @@ function lock_viewer_for_set(gobj, shown, set)
3891
3940
  return false;
3892
3941
  }
3893
3942
  priv.viewer_awaits = set.gclass;
3943
+ priv.viewer_awaits_set = set.set_id;
3894
3944
  priv.viewer_stale = (shown !== set.gclass)? shown: "";
3895
3945
  return true;
3896
3946
  }
@@ -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.querySelector('#' + priv.canvas_id);
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? $container.querySelector('#' + priv.canvas_id): null;
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.querySelector("#" + gobj.priv.canvas_id);
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="' + CSS.escape(priv.anchor_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="${css_escape(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="${css_escape(item_id)}"] .NAV_ITEM_BADGE`
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="${css_escape(id_to_mark)}"]`);
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="${css_escape(active_leaf_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`);
@@ -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.querySelector(`#${priv.canvas_id}`);
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
- /* Pinch to zoom on a touch screen, as in the other graphs. */
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.querySelector(`#${search_id}`);
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.querySelector(`#${table_id}`));
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.querySelector(`#${table_id}`));
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.querySelector(`#${table_id}`) : null;
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
+ });