@antv/g6 5.0.7 → 5.0.9

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.
Files changed (177) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/click-select.d.ts +8 -16
  3. package/dist/lib/elements/base-element.d.ts +5 -4
  4. package/dist/lib/plugins/fullscreen/index.d.ts +2 -0
  5. package/dist/lib/registry/index.d.ts +5 -1
  6. package/dist/lib/runtime/animation.d.ts +7 -0
  7. package/dist/lib/runtime/canvas.d.ts +27 -39
  8. package/dist/lib/runtime/element.d.ts +1 -1
  9. package/dist/lib/runtime/graph.d.ts +1 -17
  10. package/dist/lib/utils/print.d.ts +15 -0
  11. package/dist/lib/utils/shortcut.d.ts +1 -0
  12. package/dist/lib/utils/state.d.ts +9 -0
  13. package/dist/lib/version.d.ts +1 -1
  14. package/esm/behaviors/brush-select.js +1 -2
  15. package/esm/behaviors/brush-select.js.map +1 -1
  16. package/esm/behaviors/click-select.d.ts +8 -16
  17. package/esm/behaviors/click-select.js +108 -90
  18. package/esm/behaviors/click-select.js.map +1 -1
  19. package/esm/behaviors/drag-element-force.js +2 -1
  20. package/esm/behaviors/drag-element-force.js.map +1 -1
  21. package/esm/behaviors/drag-element.js +1 -2
  22. package/esm/behaviors/drag-element.js.map +1 -1
  23. package/esm/elements/base-element.d.ts +5 -4
  24. package/esm/elements/base-element.js +3 -0
  25. package/esm/elements/base-element.js.map +1 -1
  26. package/esm/elements/combos/base-combo.js +2 -2
  27. package/esm/elements/combos/base-combo.js.map +1 -1
  28. package/esm/elements/nodes/html.js +3 -5
  29. package/esm/elements/nodes/html.js.map +1 -1
  30. package/esm/elements/shapes/base-shape.js +27 -3
  31. package/esm/elements/shapes/base-shape.js.map +1 -1
  32. package/esm/plugins/contextmenu/index.js +1 -0
  33. package/esm/plugins/contextmenu/index.js.map +1 -1
  34. package/esm/plugins/fullscreen/index.d.ts +2 -0
  35. package/esm/plugins/fullscreen/index.js +15 -2
  36. package/esm/plugins/fullscreen/index.js.map +1 -1
  37. package/esm/registry/extension/index.js +2 -1
  38. package/esm/registry/extension/index.js.map +1 -1
  39. package/esm/registry/index.d.ts +5 -1
  40. package/esm/registry/index.js +8 -3
  41. package/esm/registry/index.js.map +1 -1
  42. package/esm/runtime/animation.d.ts +7 -0
  43. package/esm/runtime/animation.js +17 -0
  44. package/esm/runtime/animation.js.map +1 -1
  45. package/esm/runtime/canvas.d.ts +27 -39
  46. package/esm/runtime/canvas.js +128 -175
  47. package/esm/runtime/canvas.js.map +1 -1
  48. package/esm/runtime/data.js +4 -3
  49. package/esm/runtime/data.js.map +1 -1
  50. package/esm/runtime/element.d.ts +1 -1
  51. package/esm/runtime/element.js +2 -1
  52. package/esm/runtime/element.js.map +1 -1
  53. package/esm/runtime/graph.d.ts +1 -17
  54. package/esm/runtime/graph.js +8 -34
  55. package/esm/runtime/graph.js.map +1 -1
  56. package/esm/runtime/layout.js +5 -2
  57. package/esm/runtime/layout.js.map +1 -1
  58. package/esm/runtime/viewport.js +1 -1
  59. package/esm/runtime/viewport.js.map +1 -1
  60. package/esm/utils/animation.js +9 -3
  61. package/esm/utils/animation.js.map +1 -1
  62. package/esm/utils/id.js +2 -1
  63. package/esm/utils/id.js.map +1 -1
  64. package/esm/utils/layout.js +9 -1
  65. package/esm/utils/layout.js.map +1 -1
  66. package/esm/utils/palette.js +2 -1
  67. package/esm/utils/palette.js.map +1 -1
  68. package/esm/utils/print.d.ts +15 -0
  69. package/esm/utils/print.js +28 -0
  70. package/esm/utils/print.js.map +1 -0
  71. package/esm/utils/shortcut.d.ts +1 -0
  72. package/esm/utils/shortcut.js +7 -0
  73. package/esm/utils/shortcut.js.map +1 -1
  74. package/esm/utils/state.d.ts +9 -0
  75. package/esm/utils/state.js +11 -0
  76. package/esm/utils/state.js.map +1 -0
  77. package/esm/utils/theme.js +5 -1
  78. package/esm/utils/theme.js.map +1 -1
  79. package/esm/version.d.ts +1 -1
  80. package/esm/version.js +1 -1
  81. package/lib/behaviors/brush-select.js +1 -2
  82. package/lib/behaviors/brush-select.js.map +1 -1
  83. package/lib/behaviors/click-select.d.ts +8 -16
  84. package/lib/behaviors/click-select.js +106 -88
  85. package/lib/behaviors/click-select.js.map +1 -1
  86. package/lib/behaviors/drag-element-force.js +2 -1
  87. package/lib/behaviors/drag-element-force.js.map +1 -1
  88. package/lib/behaviors/drag-element.js +1 -2
  89. package/lib/behaviors/drag-element.js.map +1 -1
  90. package/lib/elements/base-element.d.ts +5 -4
  91. package/lib/elements/base-element.js +3 -0
  92. package/lib/elements/base-element.js.map +1 -1
  93. package/lib/elements/combos/base-combo.js +2 -2
  94. package/lib/elements/combos/base-combo.js.map +1 -1
  95. package/lib/elements/nodes/html.js +3 -5
  96. package/lib/elements/nodes/html.js.map +1 -1
  97. package/lib/elements/shapes/base-shape.js +27 -3
  98. package/lib/elements/shapes/base-shape.js.map +1 -1
  99. package/lib/plugins/contextmenu/index.js +1 -0
  100. package/lib/plugins/contextmenu/index.js.map +1 -1
  101. package/lib/plugins/fullscreen/index.d.ts +2 -0
  102. package/lib/plugins/fullscreen/index.js +15 -2
  103. package/lib/plugins/fullscreen/index.js.map +1 -1
  104. package/lib/registry/extension/index.js +2 -1
  105. package/lib/registry/extension/index.js.map +1 -1
  106. package/lib/registry/index.d.ts +5 -1
  107. package/lib/registry/index.js +8 -3
  108. package/lib/registry/index.js.map +1 -1
  109. package/lib/runtime/animation.d.ts +7 -0
  110. package/lib/runtime/animation.js +17 -0
  111. package/lib/runtime/animation.js.map +1 -1
  112. package/lib/runtime/canvas.d.ts +27 -39
  113. package/lib/runtime/canvas.js +127 -174
  114. package/lib/runtime/canvas.js.map +1 -1
  115. package/lib/runtime/data.js +4 -3
  116. package/lib/runtime/data.js.map +1 -1
  117. package/lib/runtime/element.d.ts +1 -1
  118. package/lib/runtime/element.js +2 -1
  119. package/lib/runtime/element.js.map +1 -1
  120. package/lib/runtime/graph.d.ts +1 -17
  121. package/lib/runtime/graph.js +8 -34
  122. package/lib/runtime/graph.js.map +1 -1
  123. package/lib/runtime/layout.js +5 -2
  124. package/lib/runtime/layout.js.map +1 -1
  125. package/lib/runtime/viewport.js +1 -1
  126. package/lib/runtime/viewport.js.map +1 -1
  127. package/lib/utils/animation.js +8 -2
  128. package/lib/utils/animation.js.map +1 -1
  129. package/lib/utils/id.js +2 -1
  130. package/lib/utils/id.js.map +1 -1
  131. package/lib/utils/layout.js +9 -1
  132. package/lib/utils/layout.js.map +1 -1
  133. package/lib/utils/palette.js +2 -1
  134. package/lib/utils/palette.js.map +1 -1
  135. package/lib/utils/print.d.ts +15 -0
  136. package/lib/utils/print.js +32 -0
  137. package/lib/utils/print.js.map +1 -0
  138. package/lib/utils/shortcut.d.ts +1 -0
  139. package/lib/utils/shortcut.js +7 -0
  140. package/lib/utils/shortcut.js.map +1 -1
  141. package/lib/utils/state.d.ts +9 -0
  142. package/lib/utils/state.js +14 -0
  143. package/lib/utils/state.js.map +1 -0
  144. package/lib/utils/theme.js +5 -1
  145. package/lib/utils/theme.js.map +1 -1
  146. package/lib/version.d.ts +1 -1
  147. package/lib/version.js +1 -1
  148. package/package.json +8 -8
  149. package/src/behaviors/brush-select.ts +1 -2
  150. package/src/behaviors/click-select.ts +117 -88
  151. package/src/behaviors/drag-element-force.ts +2 -1
  152. package/src/behaviors/drag-element.ts +1 -2
  153. package/src/elements/base-element.ts +8 -4
  154. package/src/elements/combos/base-combo.ts +2 -2
  155. package/src/elements/nodes/html.ts +3 -7
  156. package/src/elements/shapes/base-shape.ts +30 -3
  157. package/src/global.d.ts +12 -0
  158. package/src/plugins/contextmenu/index.ts +1 -0
  159. package/src/plugins/fullscreen/index.ts +18 -2
  160. package/src/registry/extension/index.ts +2 -1
  161. package/src/registry/index.ts +8 -2
  162. package/src/runtime/animation.ts +21 -0
  163. package/src/runtime/canvas.ts +140 -209
  164. package/src/runtime/data.ts +4 -3
  165. package/src/runtime/element.ts +3 -2
  166. package/src/runtime/graph.ts +8 -38
  167. package/src/runtime/layout.ts +5 -2
  168. package/src/runtime/viewport.ts +2 -2
  169. package/src/utils/animation.ts +9 -2
  170. package/src/utils/id.ts +2 -1
  171. package/src/utils/layout.ts +7 -1
  172. package/src/utils/palette.ts +2 -1
  173. package/src/utils/print.ts +30 -0
  174. package/src/utils/shortcut.ts +9 -0
  175. package/src/utils/state.ts +12 -0
  176. package/src/utils/theme.ts +6 -1
  177. package/src/version.ts +1 -1
@@ -194,7 +194,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
194
194
  }
195
195
 
196
196
  protected getComboZIndex(attributes: Required<S>): number {
197
- const ancestors = attributes.context!.model.getAncestorsData(this.id, COMBO_KEY) || [];
197
+ const ancestors = this.context.model.getAncestorsData(this.id, COMBO_KEY) || [];
198
198
  return ancestors.length;
199
199
  }
200
200
 
@@ -231,7 +231,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
231
231
  Object.assign(this.style, comboStyle);
232
232
  // Sync combo position to model
233
233
  const { x, y } = comboStyle;
234
- attributes.context!.model.syncComboDatum({ id: this.id, style: { x, y } });
234
+ this.context.model.syncComboDatum({ id: this.id, style: { x, y } });
235
235
  }
236
236
 
237
237
  public render(attributes: Required<S>, container: Group = this) {
@@ -50,7 +50,7 @@ export class HTML extends BaseNode<HTMLStyleProps> {
50
50
  private rootPointerEvent = new FederatedPointerEvent(null);
51
51
 
52
52
  private get eventService() {
53
- return this.attributes.context!.canvas.context.eventService;
53
+ return this.context.canvas.context.eventService;
54
54
  }
55
55
 
56
56
  private get events() {
@@ -105,7 +105,7 @@ export class HTML extends BaseNode<HTMLStyleProps> {
105
105
  }
106
106
 
107
107
  private forwardEvents = (nativeEvent: PointerEvent) => {
108
- const canvas = this.attributes.context!.canvas.main;
108
+ const canvas = this.context.canvas;
109
109
  const iCanvas = canvas.context.renderingContext.root!.ownerDocument!.defaultView!;
110
110
 
111
111
  const normalizedEvents = this.normalizeToPointerEvent(nativeEvent, iCanvas);
@@ -232,11 +232,7 @@ export class HTML extends BaseNode<HTMLStyleProps> {
232
232
  let x: number;
233
233
  let y: number;
234
234
  const { offsetX, offsetY, clientX, clientY } = nativeEvent;
235
- if (
236
- this.attributes.context?.canvas.main.context.config.supportsCSSTransform &&
237
- !isNil(offsetX) &&
238
- !isNil(offsetY)
239
- ) {
235
+ if (this.context.canvas.context.config.supportsCSSTransform && !isNil(offsetX) && !isNil(offsetY)) {
240
236
  x = offsetX;
241
237
  y = offsetY;
242
238
  } else {
@@ -152,7 +152,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
152
152
  }
153
153
 
154
154
  const result = super.animate(keyframes, options);
155
- if (result) animationMap.push(result);
155
+ if (result) {
156
+ releaseAnimation(this, result);
157
+ animationMap.push(result);
158
+ }
156
159
 
157
160
  if (Array.isArray(keyframes) && keyframes.length > 0) {
158
161
  // 如果 keyframes 中仅存在 skippedAttrs 中的属性,则仅更新父元素属性(跳过子图形)
@@ -170,7 +173,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
170
173
  method.call(this, { ...this.attributes, ...style }),
171
174
  );
172
175
  const result = shape.animate(preprocessKeyframes(subKeyframes), options);
173
- if (result) animationMap.push(result);
176
+ if (result) {
177
+ releaseAnimation(shape, result);
178
+ animationMap.push(result);
179
+ }
174
180
  }
175
181
  });
176
182
 
@@ -185,7 +191,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
185
191
  const shape = shapeSet[key];
186
192
  if (shape) {
187
193
  const result = shape.animate(preprocessKeyframes(subKeyframes), options);
188
- if (result) animationMap.push(result);
194
+ if (result) {
195
+ releaseAnimation(shape, result);
196
+ animationMap.push(result);
197
+ }
189
198
  }
190
199
  });
191
200
  }
@@ -217,3 +226,21 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
217
226
  super.destroy();
218
227
  }
219
228
  }
229
+
230
+ /**
231
+ * <zh/> 释放动画
232
+ *
233
+ * <en/> Release animation
234
+ * @param target - <zh/> 目标对象 | <en/> target object
235
+ * @param animation - <zh/> 动画实例 | <en/> animation instance
236
+ * @description see: https://github.com/antvis/G/issues/1731
237
+ */
238
+ function releaseAnimation(target: DisplayObject, animation: IAnimation) {
239
+ animation.oncancel = () => console.log('cancel');
240
+ animation?.finished.then(() => {
241
+ // @ts-expect-error private property
242
+ const index = target.activeAnimations.findIndex((_) => _ === animation);
243
+ // @ts-expect-error private property
244
+ if (index > -1) target.activeAnimations.splice(index, 1);
245
+ });
246
+ }
@@ -0,0 +1,12 @@
1
+ import '@antv/g';
2
+
3
+ declare module '@antv/g' {
4
+ interface BaseStyleProps {
5
+ /**
6
+ * <zh/> 图形所在的图层,默认为 'main'。
7
+ *
8
+ * <en/> The layer where the shape is located, default is 'main'.
9
+ */
10
+ $layer?: string;
11
+ }
12
+ }
@@ -126,6 +126,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
126
126
  const content = await this.getDOMContent(event);
127
127
 
128
128
  if (content instanceof HTMLElement) {
129
+ this.$element.innerHTML = '';
129
130
  this.$element.appendChild(content);
130
131
  } else {
131
132
  this.$element.innerHTML = content;
@@ -1,4 +1,5 @@
1
1
  import type { RuntimeContext } from '../../runtime/types';
2
+ import { print } from '../../utils/print';
2
3
  import type { ShortcutKey } from '../../utils/shortcut';
3
4
  import { Shortcut } from '../../utils/shortcut';
4
5
  import type { BasePluginOptions } from '../base-plugin';
@@ -57,7 +58,10 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
57
58
 
58
59
  private shortcut: Shortcut;
59
60
 
61
+ private style: HTMLStyleElement;
62
+
60
63
  private $el = this.context.canvas.getContainer()!;
64
+
61
65
  private graphSize: [number, number] = [0, 0];
62
66
 
63
67
  constructor(context: RuntimeContext, options: FullscreenOptions) {
@@ -67,7 +71,13 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
67
71
 
68
72
  this.bindEvents();
69
73
 
70
- this.$el.style.backgroundColor = this.context.graph.getBackground()!;
74
+ this.style = document.createElement('style');
75
+ document.head.appendChild(this.style);
76
+ this.style.innerHTML = `
77
+ :not(:root):fullscreen::backdrop {
78
+ background: transparent;
79
+ }
80
+ `;
71
81
  }
72
82
 
73
83
  private bindEvents() {
@@ -123,7 +133,7 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
123
133
  public request() {
124
134
  if (document.fullscreenElement || !isFullscreenEnabled()) return;
125
135
  this.$el.requestFullscreen().catch((err: Error) => {
126
- console.debug(`Error attempting to enable full-screen: ${err.message} (${err.name})`);
136
+ print.warn(`Error attempting to enable full-screen: ${err.message} (${err.name})`);
127
137
  });
128
138
  }
129
139
 
@@ -149,6 +159,12 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
149
159
  super.update(options);
150
160
  this.bindEvents();
151
161
  }
162
+
163
+ public destroy(): void {
164
+ this.exit();
165
+ this.style.remove();
166
+ super.destroy();
167
+ }
152
168
  }
153
169
 
154
170
  /**
@@ -5,6 +5,7 @@ import type { RuntimeContext } from '../../runtime/types';
5
5
  import type { IEvent } from '../../types';
6
6
  import { arrayDiff } from '../../utils/diff';
7
7
  import { parseExtensions } from '../../utils/extension';
8
+ import { print } from '../../utils/print';
8
9
  import type { STDExtensionOption } from './types';
9
10
 
10
11
  export abstract class ExtensionController<E extends BaseExtension<any>> {
@@ -42,7 +43,7 @@ export abstract class ExtensionController<E extends BaseExtension<any>> {
42
43
 
43
44
  const { key, type } = extension;
44
45
  const Ctor = getExtension(category, type);
45
- if (!Ctor) return;
46
+ if (!Ctor) return print.warn(`The extension ${type} of ${category} is not registered.`);
46
47
 
47
48
  const instance = new Ctor(this.context, extension);
48
49
  this.extensionMap[key] = instance as E;
@@ -1,5 +1,6 @@
1
1
  import { ExtensionCategory } from '../constants';
2
2
  import type { Loosen } from '../types';
3
+ import { print } from '../utils/print';
3
4
  import { BUILT_IN_EXTENSIONS } from './build-in';
4
5
  import type { ExtensionRegistry } from './types';
5
6
 
@@ -37,6 +38,10 @@ const EXTENSION_REGISTRY: ExtensionRegistry = {
37
38
  * <zh/> 要注册的扩展类,在使用时创建实例
38
39
  *
39
40
  * <en/> The extension class to be registered. An instance will be created upon use
41
+ * @param override
42
+ * <zh/> 是否覆盖已注册的扩展
43
+ *
44
+ * <en/> Whether to override the registered extension
40
45
  * @remarks
41
46
  * <zh/> 内置扩展在项目导入时会自动注册。对于非内置扩展,可以通过 `register` 方法手动注册。扩展只需要注册一次,即可在项目的任何位置使用。
42
47
  *
@@ -55,10 +60,11 @@ export function register<T extends ExtensionCategory>(
55
60
  category: Loosen<T>,
56
61
  type: string,
57
62
  Ctor: ExtensionRegistry[T][string],
63
+ override = false,
58
64
  ) {
59
65
  const ext = EXTENSION_REGISTRY[category][type];
60
- if (ext) {
61
- if (ext !== Ctor) console.error(`The extension ${type} of ${category} has been registered before.`);
66
+ if (!override && ext) {
67
+ if (ext !== Ctor) print.warn(`The extension ${type} of ${category} has been registered before.`);
62
68
  } else Object.assign(EXTENSION_REGISTRY[category]!, { [type]: Ctor });
63
69
  }
64
70
 
@@ -46,6 +46,7 @@ export class Animation {
46
46
  animation.finished.then(() => {
47
47
  cb?.afterAnimate?.(animation);
48
48
  cb?.after?.();
49
+ this.animations.delete(animation);
49
50
  });
50
51
  } else cb?.after?.();
51
52
 
@@ -63,6 +64,7 @@ export class Animation {
63
64
  animation.finished.then(() => {
64
65
  callbacks?.afterAnimate?.(animation);
65
66
  callbacks?.after?.();
67
+ this.release();
66
68
  });
67
69
  } else callbacks?.after?.();
68
70
 
@@ -147,6 +149,25 @@ export class Animation {
147
149
  this.tasks = [];
148
150
  }
149
151
 
152
+ /**
153
+ * <zh/> 释放存量动画对象
154
+ *
155
+ * <en/> Release stock animation objects
156
+ * @description see: https://github.com/antvis/G/issues/1731
157
+ */
158
+ private release() {
159
+ const { canvas } = this.context;
160
+
161
+ // @ts-expect-error private property
162
+ const animationsWithPromises = canvas.document?.timeline?.animationsWithPromises;
163
+ if (animationsWithPromises) {
164
+ // @ts-expect-error private property
165
+ canvas.document.timeline.animationsWithPromises = animationsWithPromises.filter(
166
+ (animation: IAnimation) => animation.playState !== 'finished',
167
+ );
168
+ }
169
+ }
170
+
150
171
  public destroy() {
151
172
  this.stop();
152
173
  this.animations.clear();