@yuneta/gobj-ui 7.27.31 → 7.27.32

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.
@@ -17186,6 +17186,41 @@ function classify_press(press, x, y, t) {
17186
17186
  return "tap";
17187
17187
  }
17188
17188
  //#endregion
17189
+ //#region src/g6_replace_behavior.js
17190
+ /***********************************************************************
17191
+ * g6_replace_behavior.js
17192
+ *
17193
+ * Replace one of G6's built-in behaviors, without a warning on
17194
+ * every page load.
17195
+ *
17196
+ * gobj-ui replaces two built-ins on purpose (`drag-canvas` and
17197
+ * `zoom-canvas`, the touch round of 7.23.9), so that every graph
17198
+ * gets the fix without touching its behaviors list. G6's
17199
+ * `register()` warns whenever a type is registered again --
17200
+ * "The extension drag-canvas of behavior has been registered
17201
+ * before, and will be overridden" -- and its `print` is not
17202
+ * exported, so the warning cannot be muted. It went to the
17203
+ * console of every app that draws a graph, on every load.
17204
+ *
17205
+ * `getExtensions(category)` hands out G6's live registry, so the
17206
+ * replacement is written there. Whether it took is checked with
17207
+ * `getExtension()`: a G6 that hands out a copy one day gets the
17208
+ * replacement through `register()` -- with its warning, which
17209
+ * then says something -- instead of losing it in silence.
17210
+ *
17211
+ * Copyright (c) 2026, ArtGins.
17212
+ * All Rights Reserved.
17213
+ ***********************************************************************/
17214
+ /************************************************************
17215
+ * Make `Ctor` the behavior `type`, replacing the built-in.
17216
+ ************************************************************/
17217
+ function replace_g6_behavior(type, Ctor) {
17218
+ const category = _antv_g6.ExtensionCategory.BEHAVIOR;
17219
+ const behaviors = (0, _antv_g6.getExtensions)(category);
17220
+ if (behaviors && (0, _antv_g6.getExtension)(category, type)) behaviors[type] = Ctor;
17221
+ if ((0, _antv_g6.getExtension)(category, type) !== Ctor) (0, _antv_g6.register)(category, type, Ctor);
17222
+ }
17223
+ //#endregion
17189
17224
  //#region src/g6_touch_gestures.js
17190
17225
  /***********************************************************************
17191
17226
  * g6_touch_gestures.js
@@ -17387,7 +17422,7 @@ var ZoomCanvasPinch = class extends _antv_g6.ZoomCanvas {
17387
17422
  var __zoom_canvas_patched__ = false;
17388
17423
  function ensure_pinch_zoom_patch() {
17389
17424
  if (__zoom_canvas_patched__) return;
17390
- (0, _antv_g6.register)(_antv_g6.ExtensionCategory.BEHAVIOR, "zoom-canvas", ZoomCanvasPinch);
17425
+ replace_g6_behavior("zoom-canvas", ZoomCanvasPinch);
17391
17426
  __zoom_canvas_patched__ = true;
17392
17427
  }
17393
17428
  /***************************
@@ -17630,7 +17665,7 @@ var DragCanvasTouch = class extends _antv_g6.DragCanvas {
17630
17665
  var __drag_canvas_patched__ = false;
17631
17666
  function ensure_drag_canvas_patch() {
17632
17667
  if (__drag_canvas_patched__) return;
17633
- (0, _antv_g6.register)(_antv_g6.ExtensionCategory.BEHAVIOR, "drag-canvas", DragCanvasTouch);
17668
+ replace_g6_behavior("drag-canvas", DragCanvasTouch);
17634
17669
  __drag_canvas_patched__ = true;
17635
17670
  }
17636
17671
  //#endregion
@@ -5,7 +5,7 @@ import { createJSONEditor } from "vanilla-jsoneditor";
5
5
  import { TabulatorFull } from "tabulator-tables";
6
6
  import * as maplibregl from "maplibre-gl";
7
7
  import uPlot from "uplot";
8
- import { BaseLayout, BrushSelect, CanvasEvent, Circle, CommonEvent, DragCanvas, EdgeEvent, ExtensionCategory, Graph, GraphEvent, HTML, HistoryEvent, NodeEvent, Polyline, Toolbar, ZoomCanvas, register } from "@antv/g6";
8
+ import { BaseLayout, BrushSelect, CanvasEvent, Circle, CommonEvent, DragCanvas, EdgeEvent, ExtensionCategory, Graph, GraphEvent, HTML, HistoryEvent, NodeEvent, Polyline, Toolbar, ZoomCanvas, getExtension, getExtensions, register } from "@antv/g6";
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
11
11
  var __defProp = Object.defineProperty;
@@ -17181,6 +17181,41 @@ function classify_press(press, x, y, t) {
17181
17181
  return "tap";
17182
17182
  }
17183
17183
  //#endregion
17184
+ //#region src/g6_replace_behavior.js
17185
+ /***********************************************************************
17186
+ * g6_replace_behavior.js
17187
+ *
17188
+ * Replace one of G6's built-in behaviors, without a warning on
17189
+ * every page load.
17190
+ *
17191
+ * gobj-ui replaces two built-ins on purpose (`drag-canvas` and
17192
+ * `zoom-canvas`, the touch round of 7.23.9), so that every graph
17193
+ * gets the fix without touching its behaviors list. G6's
17194
+ * `register()` warns whenever a type is registered again --
17195
+ * "The extension drag-canvas of behavior has been registered
17196
+ * before, and will be overridden" -- and its `print` is not
17197
+ * exported, so the warning cannot be muted. It went to the
17198
+ * console of every app that draws a graph, on every load.
17199
+ *
17200
+ * `getExtensions(category)` hands out G6's live registry, so the
17201
+ * replacement is written there. Whether it took is checked with
17202
+ * `getExtension()`: a G6 that hands out a copy one day gets the
17203
+ * replacement through `register()` -- with its warning, which
17204
+ * then says something -- instead of losing it in silence.
17205
+ *
17206
+ * Copyright (c) 2026, ArtGins.
17207
+ * All Rights Reserved.
17208
+ ***********************************************************************/
17209
+ /************************************************************
17210
+ * Make `Ctor` the behavior `type`, replacing the built-in.
17211
+ ************************************************************/
17212
+ function replace_g6_behavior(type, Ctor) {
17213
+ const category = ExtensionCategory.BEHAVIOR;
17214
+ const behaviors = getExtensions(category);
17215
+ if (behaviors && getExtension(category, type)) behaviors[type] = Ctor;
17216
+ if (getExtension(category, type) !== Ctor) register(category, type, Ctor);
17217
+ }
17218
+ //#endregion
17184
17219
  //#region src/g6_touch_gestures.js
17185
17220
  /***********************************************************************
17186
17221
  * g6_touch_gestures.js
@@ -17382,7 +17417,7 @@ var ZoomCanvasPinch = class extends ZoomCanvas {
17382
17417
  var __zoom_canvas_patched__ = false;
17383
17418
  function ensure_pinch_zoom_patch() {
17384
17419
  if (__zoom_canvas_patched__) return;
17385
- register(ExtensionCategory.BEHAVIOR, "zoom-canvas", ZoomCanvasPinch);
17420
+ replace_g6_behavior("zoom-canvas", ZoomCanvasPinch);
17386
17421
  __zoom_canvas_patched__ = true;
17387
17422
  }
17388
17423
  /***************************
@@ -17625,7 +17660,7 @@ var DragCanvasTouch = class extends DragCanvas {
17625
17660
  var __drag_canvas_patched__ = false;
17626
17661
  function ensure_drag_canvas_patch() {
17627
17662
  if (__drag_canvas_patched__) return;
17628
- register(ExtensionCategory.BEHAVIOR, "drag-canvas", DragCanvasTouch);
17663
+ replace_g6_behavior("drag-canvas", DragCanvasTouch);
17629
17664
  __drag_canvas_patched__ = true;
17630
17665
  }
17631
17666
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.27.31",
3
+ "version": "7.27.32",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -53,11 +53,10 @@
53
53
  import {
54
54
  DragCanvas,
55
55
  CommonEvent,
56
- ExtensionCategory,
57
- register,
58
56
  } from '@antv/g6';
59
57
 
60
58
  import {is_pinching} from './g6_touch_gestures.js';
59
+ import {replace_g6_behavior} from './g6_replace_behavior.js';
61
60
 
62
61
  /************************************************************
63
62
  * Custom drag-canvas: same behavior, reliable delta source
@@ -155,7 +154,7 @@ function ensure_drag_canvas_patch()
155
154
  if(__drag_canvas_patched__) {
156
155
  return;
157
156
  }
158
- register(ExtensionCategory.BEHAVIOR, 'drag-canvas', DragCanvasTouch);
157
+ replace_g6_behavior('drag-canvas', DragCanvasTouch);
159
158
  __drag_canvas_patched__ = true;
160
159
  }
161
160
 
@@ -0,0 +1,47 @@
1
+ /***********************************************************************
2
+ * g6_replace_behavior.js
3
+ *
4
+ * Replace one of G6's built-in behaviors, without a warning on
5
+ * every page load.
6
+ *
7
+ * gobj-ui replaces two built-ins on purpose (`drag-canvas` and
8
+ * `zoom-canvas`, the touch round of 7.23.9), so that every graph
9
+ * gets the fix without touching its behaviors list. G6's
10
+ * `register()` warns whenever a type is registered again --
11
+ * "The extension drag-canvas of behavior has been registered
12
+ * before, and will be overridden" -- and its `print` is not
13
+ * exported, so the warning cannot be muted. It went to the
14
+ * console of every app that draws a graph, on every load.
15
+ *
16
+ * `getExtensions(category)` hands out G6's live registry, so the
17
+ * replacement is written there. Whether it took is checked with
18
+ * `getExtension()`: a G6 that hands out a copy one day gets the
19
+ * replacement through `register()` -- with its warning, which
20
+ * then says something -- instead of losing it in silence.
21
+ *
22
+ * Copyright (c) 2026, ArtGins.
23
+ * All Rights Reserved.
24
+ ***********************************************************************/
25
+ import {
26
+ ExtensionCategory,
27
+ getExtension,
28
+ getExtensions,
29
+ register,
30
+ } from '@antv/g6';
31
+
32
+ /************************************************************
33
+ * Make `Ctor` the behavior `type`, replacing the built-in.
34
+ ************************************************************/
35
+ function replace_g6_behavior(type, Ctor)
36
+ {
37
+ const category = ExtensionCategory.BEHAVIOR;
38
+ const behaviors = getExtensions(category);
39
+ if(behaviors && getExtension(category, type)) {
40
+ behaviors[type] = Ctor;
41
+ }
42
+ if(getExtension(category, type) !== Ctor) {
43
+ register(category, type, Ctor);
44
+ }
45
+ }
46
+
47
+ export {replace_g6_behavior};
@@ -0,0 +1,38 @@
1
+ /*
2
+ * gobj-ui replaces G6's built-in drag-canvas and zoom-canvas on purpose;
3
+ * G6's register() warned "has been registered before" for each, on every
4
+ * page load, in every app that draws a graph.
5
+ */
6
+ import {describe, it, expect, vi, afterEach} from "vitest";
7
+ import {ExtensionCategory, getExtension} from "@antv/g6";
8
+ import {ensure_drag_canvas_patch} from "./g6_drag_canvas_touch.js";
9
+ import {ensure_pinch_zoom_patch} from "./g6_touch_gestures.js";
10
+ import {replace_g6_behavior} from "./g6_replace_behavior.js";
11
+
12
+ afterEach(() => {
13
+ vi.restoreAllMocks();
14
+ });
15
+
16
+ describe("replacing G6's built-in behaviors", () => {
17
+ it("puts gobj-ui's drag-canvas and zoom-canvas in place, with no warning", () => {
18
+ const builtin_drag = getExtension(ExtensionCategory.BEHAVIOR, "drag-canvas");
19
+ const builtin_zoom = getExtension(ExtensionCategory.BEHAVIOR, "zoom-canvas");
20
+ const warn = vi.spyOn(console, "warn");
21
+ ensure_drag_canvas_patch();
22
+ ensure_pinch_zoom_patch();
23
+ const said = warn.mock.calls.map((c) => String(c[0]));
24
+ expect(said.filter((m) => m.includes("registered before"))).toEqual([]);
25
+ const drag = getExtension(ExtensionCategory.BEHAVIOR, "drag-canvas");
26
+ const zoom = getExtension(ExtensionCategory.BEHAVIOR, "zoom-canvas");
27
+ expect(drag).not.toBe(builtin_drag);
28
+ expect(zoom).not.toBe(builtin_zoom);
29
+ expect(Object.getPrototypeOf(drag)).toBe(builtin_drag);
30
+ expect(Object.getPrototypeOf(zoom)).toBe(builtin_zoom);
31
+ });
32
+
33
+ it("registers a type G6 does not have", () => {
34
+ class Probe {}
35
+ replace_g6_behavior("gobj-ui-probe-behavior", Probe);
36
+ expect(getExtension(ExtensionCategory.BEHAVIOR, "gobj-ui-probe-behavior")).toBe(Probe);
37
+ });
38
+ });
@@ -61,11 +61,10 @@
61
61
  import {
62
62
  ZoomCanvas,
63
63
  CommonEvent,
64
- ExtensionCategory,
65
- register,
66
64
  } from '@antv/g6';
67
65
 
68
66
  import {press_moved, classify_press, LONG_PRESS_MS} from "./press_arbiter.js";
67
+ import {replace_g6_behavior} from "./g6_replace_behavior.js";
69
68
 
70
69
 
71
70
  /***************************************************************
@@ -309,7 +308,7 @@ export function ensure_pinch_zoom_patch()
309
308
  if(__zoom_canvas_patched__) {
310
309
  return;
311
310
  }
312
- register(ExtensionCategory.BEHAVIOR, 'zoom-canvas', ZoomCanvasPinch);
311
+ replace_g6_behavior('zoom-canvas', ZoomCanvasPinch);
313
312
  __zoom_canvas_patched__ = true;
314
313
  }
315
314