@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.
- package/dist/g6.min.js +2 -2
- package/dist/lib/behaviors/click-select.d.ts +8 -16
- package/dist/lib/elements/base-element.d.ts +5 -4
- package/dist/lib/plugins/fullscreen/index.d.ts +2 -0
- package/dist/lib/registry/index.d.ts +5 -1
- package/dist/lib/runtime/animation.d.ts +7 -0
- package/dist/lib/runtime/canvas.d.ts +27 -39
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/graph.d.ts +1 -17
- package/dist/lib/utils/print.d.ts +15 -0
- package/dist/lib/utils/shortcut.d.ts +1 -0
- package/dist/lib/utils/state.d.ts +9 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.js +1 -2
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.d.ts +8 -16
- package/esm/behaviors/click-select.js +108 -90
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-element-force.js +2 -1
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/behaviors/drag-element.js +1 -2
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/elements/base-element.d.ts +5 -4
- package/esm/elements/base-element.js +3 -0
- package/esm/elements/base-element.js.map +1 -1
- package/esm/elements/combos/base-combo.js +2 -2
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/nodes/html.js +3 -5
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +27 -3
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/plugins/contextmenu/index.js +1 -0
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/fullscreen/index.d.ts +2 -0
- package/esm/plugins/fullscreen/index.js +15 -2
- package/esm/plugins/fullscreen/index.js.map +1 -1
- package/esm/registry/extension/index.js +2 -1
- package/esm/registry/extension/index.js.map +1 -1
- package/esm/registry/index.d.ts +5 -1
- package/esm/registry/index.js +8 -3
- package/esm/registry/index.js.map +1 -1
- package/esm/runtime/animation.d.ts +7 -0
- package/esm/runtime/animation.js +17 -0
- package/esm/runtime/animation.js.map +1 -1
- package/esm/runtime/canvas.d.ts +27 -39
- package/esm/runtime/canvas.js +128 -175
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.js +4 -3
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +1 -1
- package/esm/runtime/element.js +2 -1
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +1 -17
- package/esm/runtime/graph.js +8 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.js +5 -2
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.js +1 -1
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/utils/animation.js +9 -3
- package/esm/utils/animation.js.map +1 -1
- package/esm/utils/id.js +2 -1
- package/esm/utils/id.js.map +1 -1
- package/esm/utils/layout.js +9 -1
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/palette.js +2 -1
- package/esm/utils/palette.js.map +1 -1
- package/esm/utils/print.d.ts +15 -0
- package/esm/utils/print.js +28 -0
- package/esm/utils/print.js.map +1 -0
- package/esm/utils/shortcut.d.ts +1 -0
- package/esm/utils/shortcut.js +7 -0
- package/esm/utils/shortcut.js.map +1 -1
- package/esm/utils/state.d.ts +9 -0
- package/esm/utils/state.js +11 -0
- package/esm/utils/state.js.map +1 -0
- package/esm/utils/theme.js +5 -1
- package/esm/utils/theme.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/brush-select.js +1 -2
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +8 -16
- package/lib/behaviors/click-select.js +106 -88
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-element-force.js +2 -1
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/behaviors/drag-element.js +1 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/elements/base-element.d.ts +5 -4
- package/lib/elements/base-element.js +3 -0
- package/lib/elements/base-element.js.map +1 -1
- package/lib/elements/combos/base-combo.js +2 -2
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/nodes/html.js +3 -5
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +27 -3
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/plugins/contextmenu/index.js +1 -0
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/fullscreen/index.d.ts +2 -0
- package/lib/plugins/fullscreen/index.js +15 -2
- package/lib/plugins/fullscreen/index.js.map +1 -1
- package/lib/registry/extension/index.js +2 -1
- package/lib/registry/extension/index.js.map +1 -1
- package/lib/registry/index.d.ts +5 -1
- package/lib/registry/index.js +8 -3
- package/lib/registry/index.js.map +1 -1
- package/lib/runtime/animation.d.ts +7 -0
- package/lib/runtime/animation.js +17 -0
- package/lib/runtime/animation.js.map +1 -1
- package/lib/runtime/canvas.d.ts +27 -39
- package/lib/runtime/canvas.js +127 -174
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.js +4 -3
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +1 -1
- package/lib/runtime/element.js +2 -1
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +1 -17
- package/lib/runtime/graph.js +8 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.js +5 -2
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.js +1 -1
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/utils/animation.js +8 -2
- package/lib/utils/animation.js.map +1 -1
- package/lib/utils/id.js +2 -1
- package/lib/utils/id.js.map +1 -1
- package/lib/utils/layout.js +9 -1
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/palette.js +2 -1
- package/lib/utils/palette.js.map +1 -1
- package/lib/utils/print.d.ts +15 -0
- package/lib/utils/print.js +32 -0
- package/lib/utils/print.js.map +1 -0
- package/lib/utils/shortcut.d.ts +1 -0
- package/lib/utils/shortcut.js +7 -0
- package/lib/utils/shortcut.js.map +1 -1
- package/lib/utils/state.d.ts +9 -0
- package/lib/utils/state.js +14 -0
- package/lib/utils/state.js.map +1 -0
- package/lib/utils/theme.js +5 -1
- package/lib/utils/theme.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -8
- package/src/behaviors/brush-select.ts +1 -2
- package/src/behaviors/click-select.ts +117 -88
- package/src/behaviors/drag-element-force.ts +2 -1
- package/src/behaviors/drag-element.ts +1 -2
- package/src/elements/base-element.ts +8 -4
- package/src/elements/combos/base-combo.ts +2 -2
- package/src/elements/nodes/html.ts +3 -7
- package/src/elements/shapes/base-shape.ts +30 -3
- package/src/global.d.ts +12 -0
- package/src/plugins/contextmenu/index.ts +1 -0
- package/src/plugins/fullscreen/index.ts +18 -2
- package/src/registry/extension/index.ts +2 -1
- package/src/registry/index.ts +8 -2
- package/src/runtime/animation.ts +21 -0
- package/src/runtime/canvas.ts +140 -209
- package/src/runtime/data.ts +4 -3
- package/src/runtime/element.ts +3 -2
- package/src/runtime/graph.ts +8 -38
- package/src/runtime/layout.ts +5 -2
- package/src/runtime/viewport.ts +2 -2
- package/src/utils/animation.ts +9 -2
- package/src/utils/id.ts +2 -1
- package/src/utils/layout.ts +7 -1
- package/src/utils/palette.ts +2 -1
- package/src/utils/print.ts +30 -0
- package/src/utils/shortcut.ts +9 -0
- package/src/utils/state.ts +12 -0
- package/src/utils/theme.ts +6 -1
- 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 =
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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)
|
|
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)
|
|
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)
|
|
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
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -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
|
|
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
|
-
|
|
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;
|
package/src/registry/index.ts
CHANGED
|
@@ -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)
|
|
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
|
|
package/src/runtime/animation.ts
CHANGED
|
@@ -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();
|