@antv/g6 5.0.2 → 5.0.4
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.en-US.md +118 -0
- package/README.md +118 -0
- package/dist/g6.min.js +2 -2
- package/dist/lib/behaviors/base-behavior.d.ts +1 -1
- package/dist/lib/behaviors/hover-activate.d.ts +0 -1
- package/dist/lib/behaviors/scroll-canvas.d.ts +1 -1
- package/dist/lib/behaviors/types.d.ts +0 -4
- package/dist/lib/behaviors/zoom-canvas.d.ts +1 -1
- package/dist/lib/elements/shapes/badge.d.ts +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/layouts/index.d.ts +0 -1
- package/dist/lib/plugins/contextmenu/index.d.ts +4 -3
- package/dist/lib/plugins/types.d.ts +0 -2
- package/dist/lib/registry/extension/index.d.ts +17 -6
- package/dist/lib/registry/extension/types.d.ts +15 -33
- package/dist/lib/runtime/data.d.ts +3 -1
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/graph.d.ts +2 -1
- package/dist/lib/spec/behavior.d.ts +4 -5
- package/dist/lib/spec/element/combo.d.ts +8 -4
- package/dist/lib/spec/element/edge.d.ts +8 -4
- package/dist/lib/spec/element/node.d.ts +8 -4
- package/dist/lib/spec/plugin.d.ts +4 -5
- package/dist/lib/spec/transform.d.ts +5 -6
- package/dist/lib/transforms/types.d.ts +1 -2
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/style.d.ts +2 -0
- package/dist/lib/utils/event/events.d.ts +4 -4
- package/dist/lib/utils/extension.d.ts +5 -2
- package/dist/lib/utils/style.d.ts +5 -2
- package/dist/lib/utils/transform.d.ts +1 -1
- package/dist/lib/version.d.ts +1 -0
- package/esm/behaviors/base-behavior.d.ts +1 -1
- package/esm/behaviors/base-behavior.js.map +1 -1
- package/esm/behaviors/click-select.js +7 -4
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-element.js +2 -9
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/hover-activate.d.ts +0 -1
- package/esm/behaviors/hover-activate.js +18 -16
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/scroll-canvas.d.ts +1 -1
- package/esm/behaviors/scroll-canvas.js.map +1 -1
- package/esm/behaviors/types.d.ts +0 -4
- package/esm/behaviors/zoom-canvas.d.ts +1 -1
- package/esm/elements/shapes/badge.d.ts +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/layouts/index.d.ts +0 -1
- package/esm/plugins/camera-setting.js.map +1 -1
- package/esm/plugins/contextmenu/index.d.ts +4 -3
- package/esm/plugins/contextmenu/index.js +12 -10
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/types.d.ts +0 -2
- package/esm/registry/extension/index.d.ts +17 -6
- package/esm/registry/extension/index.js +1 -1
- package/esm/registry/extension/index.js.map +1 -1
- package/esm/registry/extension/types.d.ts +15 -33
- package/esm/runtime/data.d.ts +3 -1
- package/esm/runtime/data.js +12 -0
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +1 -1
- package/esm/runtime/element.js +14 -8
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +2 -1
- package/esm/runtime/graph.js +10 -9
- package/esm/runtime/graph.js.map +1 -1
- package/esm/spec/behavior.d.ts +4 -5
- package/esm/spec/element/combo.d.ts +8 -4
- package/esm/spec/element/edge.d.ts +8 -4
- package/esm/spec/element/node.d.ts +8 -4
- package/esm/spec/plugin.d.ts +4 -5
- package/esm/spec/transform.d.ts +5 -6
- package/esm/themes/base.js +3 -0
- package/esm/themes/base.js.map +1 -1
- package/esm/transforms/types.d.ts +1 -2
- package/esm/types/index.d.ts +0 -1
- package/esm/types/style.d.ts +2 -0
- package/esm/utils/event/events.d.ts +4 -4
- package/esm/utils/extension.d.ts +5 -2
- package/esm/utils/extension.js +5 -1
- package/esm/utils/extension.js.map +1 -1
- package/esm/utils/style.d.ts +5 -2
- package/esm/utils/style.js +5 -6
- package/esm/utils/style.js.map +1 -1
- package/esm/utils/transform.d.ts +1 -1
- package/esm/version.d.ts +1 -0
- package/esm/version.js +2 -0
- package/esm/version.js.map +1 -0
- package/lib/behaviors/base-behavior.d.ts +1 -1
- package/lib/behaviors/base-behavior.js.map +1 -1
- package/lib/behaviors/click-select.js +7 -4
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-element.js +2 -9
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/hover-activate.d.ts +0 -1
- package/lib/behaviors/hover-activate.js +18 -16
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/scroll-canvas.d.ts +1 -1
- package/lib/behaviors/scroll-canvas.js.map +1 -1
- package/lib/behaviors/types.d.ts +0 -4
- package/lib/behaviors/zoom-canvas.d.ts +1 -1
- package/lib/elements/effect.js +1 -2
- package/lib/elements/effect.js.map +1 -1
- package/lib/elements/shapes/badge.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/layouts/index.d.ts +0 -1
- package/lib/plugins/camera-setting.js.map +1 -1
- package/lib/plugins/contextmenu/index.d.ts +4 -3
- package/lib/plugins/contextmenu/index.js +12 -10
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/contextmenu/util.js +2 -2
- package/lib/plugins/contextmenu/util.js.map +1 -1
- package/lib/plugins/history/util.js +2 -3
- package/lib/plugins/history/util.js.map +1 -1
- package/lib/plugins/hull/util.js +1 -2
- package/lib/plugins/hull/util.js.map +1 -1
- package/lib/plugins/toolbar/util.js +2 -2
- package/lib/plugins/toolbar/util.js.map +1 -1
- package/lib/plugins/types.d.ts +0 -2
- package/lib/plugins/watermark/util.js +2 -3
- package/lib/plugins/watermark/util.js.map +1 -1
- package/lib/registry/extension/index.d.ts +17 -6
- package/lib/registry/extension/index.js +1 -1
- package/lib/registry/extension/index.js.map +1 -1
- package/lib/registry/extension/types.d.ts +15 -33
- package/lib/registry/index.js +4 -5
- package/lib/registry/index.js.map +1 -1
- package/lib/runtime/data.d.ts +3 -1
- package/lib/runtime/data.js +12 -0
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +1 -1
- package/lib/runtime/element.js +14 -8
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +2 -1
- package/lib/runtime/graph.js +10 -9
- package/lib/runtime/graph.js.map +1 -1
- package/lib/spec/behavior.d.ts +4 -5
- package/lib/spec/element/combo.d.ts +8 -4
- package/lib/spec/element/edge.d.ts +8 -4
- package/lib/spec/element/node.d.ts +8 -4
- package/lib/spec/plugin.d.ts +4 -5
- package/lib/spec/transform.d.ts +5 -6
- package/lib/themes/base.js +4 -2
- package/lib/themes/base.js.map +1 -1
- package/lib/transforms/types.d.ts +1 -2
- package/lib/transforms/utils.js +1 -2
- package/lib/transforms/utils.js.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/style.d.ts +2 -0
- package/lib/utils/anchor.js +1 -2
- package/lib/utils/anchor.js.map +1 -1
- package/lib/utils/animation.js +5 -6
- package/lib/utils/animation.js.map +1 -1
- package/lib/utils/array.js +1 -2
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/bbox.js +13 -14
- package/lib/utils/bbox.js.map +1 -1
- package/lib/utils/cache.js +4 -5
- package/lib/utils/cache.js.map +1 -1
- package/lib/utils/change.js +2 -3
- package/lib/utils/change.js.map +1 -1
- package/lib/utils/collapsibility.js +1 -2
- package/lib/utils/collapsibility.js.map +1 -1
- package/lib/utils/data.js +3 -4
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/diff.js +1 -2
- package/lib/utils/diff.js.map +1 -1
- package/lib/utils/dom.js +4 -5
- package/lib/utils/dom.js.map +1 -1
- package/lib/utils/edge.js +18 -18
- package/lib/utils/edge.js.map +1 -1
- package/lib/utils/element.js +26 -27
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/event/events.d.ts +4 -4
- package/lib/utils/event/index.js +2 -3
- package/lib/utils/event/index.js.map +1 -1
- package/lib/utils/extension.d.ts +5 -2
- package/lib/utils/extension.js +6 -3
- package/lib/utils/extension.js.map +1 -1
- package/lib/utils/graphlib.js +3 -4
- package/lib/utils/graphlib.js.map +1 -1
- package/lib/utils/id.js +3 -4
- package/lib/utils/id.js.map +1 -1
- package/lib/utils/is.js +4 -5
- package/lib/utils/is.js.map +1 -1
- package/lib/utils/layout.js +7 -8
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/line.js +2 -3
- package/lib/utils/line.js.map +1 -1
- package/lib/utils/math.js +1 -2
- package/lib/utils/math.js.map +1 -1
- package/lib/utils/node.js +1 -2
- package/lib/utils/node.js.map +1 -1
- package/lib/utils/padding.js +1 -2
- package/lib/utils/padding.js.map +1 -1
- package/lib/utils/palette.js +3 -4
- package/lib/utils/palette.js.map +1 -1
- package/lib/utils/path.js +4 -4
- package/lib/utils/path.js.map +1 -1
- package/lib/utils/placement.js +1 -2
- package/lib/utils/placement.js.map +1 -1
- package/lib/utils/point.js +21 -22
- package/lib/utils/point.js.map +1 -1
- package/lib/utils/polygon.js +1 -2
- package/lib/utils/polygon.js.map +1 -1
- package/lib/utils/position.js +5 -5
- package/lib/utils/position.js.map +1 -1
- package/lib/utils/prefix.js +7 -8
- package/lib/utils/prefix.js.map +1 -1
- package/lib/utils/relation.js +2 -3
- package/lib/utils/relation.js.map +1 -1
- package/lib/utils/router/orth.js +9 -10
- package/lib/utils/router/orth.js.map +1 -1
- package/lib/utils/shape.js +1 -2
- package/lib/utils/shape.js.map +1 -1
- package/lib/utils/size.js +1 -2
- package/lib/utils/size.js.map +1 -1
- package/lib/utils/style.d.ts +5 -2
- package/lib/utils/style.js +8 -10
- package/lib/utils/style.js.map +1 -1
- package/lib/utils/text.js +3 -4
- package/lib/utils/text.js.map +1 -1
- package/lib/utils/theme.js +1 -2
- package/lib/utils/theme.js.map +1 -1
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.js +2 -2
- package/lib/utils/transform.js.map +1 -1
- package/lib/utils/traverse.js +2 -3
- package/lib/utils/traverse.js.map +1 -1
- package/lib/utils/tree.js +1 -2
- package/lib/utils/tree.js.map +1 -1
- package/lib/utils/vector.js +16 -17
- package/lib/utils/vector.js.map +1 -1
- package/lib/utils/visibility.js +1 -2
- package/lib/utils/visibility.js.map +1 -1
- package/lib/version.d.ts +1 -0
- package/lib/version.js +5 -0
- package/lib/version.js.map +1 -0
- package/package.json +7 -4
- package/src/behaviors/base-behavior.ts +1 -1
- package/src/behaviors/click-select.ts +6 -4
- package/src/behaviors/drag-element.ts +2 -7
- package/src/behaviors/hover-activate.ts +18 -22
- package/src/behaviors/scroll-canvas.ts +1 -1
- package/src/behaviors/types.ts +0 -4
- package/src/index.ts +1 -1
- package/src/plugins/camera-setting.ts +2 -2
- package/src/plugins/contextmenu/index.ts +16 -16
- package/src/plugins/types.ts +0 -2
- package/src/registry/extension/index.ts +15 -8
- package/src/registry/extension/types.ts +15 -40
- package/src/runtime/data.ts +10 -0
- package/src/runtime/element.ts +14 -8
- package/src/runtime/graph.ts +10 -9
- package/src/spec/behavior.ts +4 -5
- package/src/spec/element/combo.ts +16 -4
- package/src/spec/element/edge.ts +16 -4
- package/src/spec/element/node.ts +16 -4
- package/src/spec/plugin.ts +4 -5
- package/src/spec/transform.ts +5 -6
- package/src/themes/base.ts +3 -0
- package/src/transforms/types.ts +1 -2
- package/src/types/index.ts +0 -1
- package/src/types/style.ts +2 -0
- package/src/utils/extension.ts +10 -3
- package/src/utils/style.ts +11 -6
- package/src/version.ts +1 -0
- package/dist/lib/types/callable.d.ts +0 -19
- package/esm/types/callable.d.ts +0 -19
- package/esm/types/callable.js +0 -2
- package/esm/types/callable.js.map +0 -1
- package/lib/types/callable.d.ts +0 -19
- package/lib/types/callable.js +0 -3
- package/lib/types/callable.js.map +0 -1
- package/src/types/callable.ts +0 -21
|
@@ -13,9 +13,9 @@ import { CONTEXTMENU_CSS, getContentFromItems } from './util';
|
|
|
13
13
|
*/
|
|
14
14
|
export interface ContextmenuOptions extends BasePluginOptions {
|
|
15
15
|
/**
|
|
16
|
-
* <zh/> 给菜单的 DOM
|
|
16
|
+
* <zh/> 给菜单的 DOM 追加的类名
|
|
17
17
|
*
|
|
18
|
-
* <en/> The
|
|
18
|
+
* <en/> The class name appended to the menu DOM for custom styles
|
|
19
19
|
* @defaultValue 'g6-contextmenu'
|
|
20
20
|
*/
|
|
21
21
|
className?: string;
|
|
@@ -42,7 +42,7 @@ export interface ContextmenuOptions extends BasePluginOptions {
|
|
|
42
42
|
*
|
|
43
43
|
* <en/> The callback method triggered when the menu is clicked
|
|
44
44
|
*/
|
|
45
|
-
onClick?: (
|
|
45
|
+
onClick?: (value: string, target: HTMLElement) => void;
|
|
46
46
|
/**
|
|
47
47
|
* <zh/> 返回菜单的项目列表,支持 `Promise` 类型的返回值。是 `getContent` 的快捷配置
|
|
48
48
|
*
|
|
@@ -88,18 +88,24 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
88
88
|
enable: () => true,
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
private $element
|
|
91
|
+
private $element!: HTMLElement;
|
|
92
92
|
|
|
93
93
|
constructor(context: RuntimeContext, options: ContextmenuOptions) {
|
|
94
94
|
super(context, Object.assign({}, Contextmenu.defaultOptions, options));
|
|
95
95
|
|
|
96
|
+
this.initElement();
|
|
97
|
+
this.update(options);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private initElement() {
|
|
101
|
+
this.$element = createPluginContainer('contextmenu', false);
|
|
102
|
+
const { className } = this.options;
|
|
103
|
+
if (className) this.$element.classList.add(className);
|
|
104
|
+
|
|
96
105
|
const $container = this.context.canvas.getContainer();
|
|
97
106
|
$container!.appendChild(this.$element);
|
|
98
107
|
|
|
99
|
-
// 设置样式
|
|
100
108
|
insertDOM('g6-contextmenu-css', 'style', {}, CONTEXTMENU_CSS, document.head);
|
|
101
|
-
|
|
102
|
-
this.update(options);
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
/**
|
|
@@ -210,16 +216,10 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
210
216
|
const { onClick } = this.options;
|
|
211
217
|
if (event.target instanceof HTMLElement) {
|
|
212
218
|
if (event.target.className.includes('g6-contextmenu-li')) {
|
|
213
|
-
const
|
|
214
|
-
onClick
|
|
215
|
-
|
|
216
|
-
this.hide();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// 点击其他地方,隐藏菜单
|
|
220
|
-
if (!this.context.graph.getCanvas().getContainer()!.contains(event.target)) {
|
|
221
|
-
this.hide();
|
|
219
|
+
const value = event.target.getAttribute('value') as string;
|
|
220
|
+
onClick?.(value, event.target);
|
|
222
221
|
}
|
|
223
222
|
}
|
|
223
|
+
this.hide();
|
|
224
224
|
};
|
|
225
225
|
}
|
package/src/plugins/types.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import type EventEmitter from '@antv/event-emitter';
|
|
2
2
|
import { getExtension } from '..';
|
|
3
|
+
import type { Graph } from '../../runtime/graph';
|
|
3
4
|
import type { RuntimeContext } from '../../runtime/types';
|
|
4
5
|
import type { IEvent } from '../../types';
|
|
5
6
|
import { arrayDiff } from '../../utils/diff';
|
|
6
7
|
import { parseExtensions } from '../../utils/extension';
|
|
7
|
-
import type {
|
|
8
|
+
import type { STDExtensionOption } from './types';
|
|
8
9
|
|
|
9
|
-
export abstract class ExtensionController<
|
|
10
|
+
export abstract class ExtensionController<E extends BaseExtension<any>> {
|
|
10
11
|
protected context: RuntimeContext;
|
|
11
12
|
|
|
12
13
|
protected extensions: STDExtensionOption[] = [];
|
|
13
14
|
|
|
14
|
-
protected extensionMap: Record<string,
|
|
15
|
+
protected extensionMap: Record<string, E> = {};
|
|
15
16
|
|
|
16
17
|
public abstract category: 'plugin' | 'behavior' | 'transform';
|
|
17
18
|
|
|
@@ -19,8 +20,14 @@ export abstract class ExtensionController<Extension extends BaseExtension<Loosel
|
|
|
19
20
|
this.context = context;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
public setExtensions(
|
|
23
|
-
|
|
23
|
+
public setExtensions(
|
|
24
|
+
extensions: (
|
|
25
|
+
| string
|
|
26
|
+
| { type: string; [keys: string]: unknown }
|
|
27
|
+
| ((this: Graph) => { type: string; [keys: string]: unknown })
|
|
28
|
+
)[],
|
|
29
|
+
) {
|
|
30
|
+
const stdExtensions = parseExtensions(this.context.graph, this.category, extensions) as STDExtensionOption[];
|
|
24
31
|
const { enter, update, exit, keep } = arrayDiff(this.extensions, stdExtensions, (extension) => extension.key);
|
|
25
32
|
|
|
26
33
|
this.createExtensions(enter);
|
|
@@ -38,7 +45,7 @@ export abstract class ExtensionController<Extension extends BaseExtension<Loosel
|
|
|
38
45
|
if (!Ctor) return;
|
|
39
46
|
|
|
40
47
|
const instance = new Ctor(this.context, extension);
|
|
41
|
-
this.extensionMap[key] = instance as
|
|
48
|
+
this.extensionMap[key] = instance as E;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
protected createExtensions(extensions: STDExtensionOption[]) {
|
|
@@ -83,7 +90,7 @@ export abstract class ExtensionController<Extension extends BaseExtension<Loosel
|
|
|
83
90
|
*
|
|
84
91
|
* <en/> Base class for extension instance
|
|
85
92
|
*/
|
|
86
|
-
export class BaseExtension<T extends
|
|
93
|
+
export class BaseExtension<T extends { type: string; key?: string; [key: string]: unknown }> {
|
|
87
94
|
protected context: RuntimeContext;
|
|
88
95
|
|
|
89
96
|
protected options: Required<T>;
|
|
@@ -92,7 +99,7 @@ export class BaseExtension<T extends LooselyExtensionOption> {
|
|
|
92
99
|
|
|
93
100
|
public destroyed = false;
|
|
94
101
|
|
|
95
|
-
constructor(context: RuntimeContext, options: T) {
|
|
102
|
+
constructor(context: RuntimeContext, options: Partial<T>) {
|
|
96
103
|
this.context = context;
|
|
97
104
|
this.options = options as Required<T>;
|
|
98
105
|
}
|
|
@@ -1,45 +1,20 @@
|
|
|
1
|
-
interface ExtensionMetaOptions {
|
|
2
|
-
type: string;
|
|
3
|
-
key: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
interface CustomExtensionOptions {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* <zh/> 扩展配置项
|
|
12
|
-
*
|
|
13
|
-
* <en/> Extension options
|
|
14
|
-
*/
|
|
15
|
-
export type ExtensionOptions<Registry extends CustomExtensionOptions = CustomExtensionOptions> = ExtensionOption<
|
|
16
|
-
Registry | LooselyExtensionOption
|
|
17
|
-
>[];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* <zh/> 扩展配置项
|
|
21
|
-
*
|
|
22
|
-
* <en/> Extension option
|
|
23
|
-
*/
|
|
24
|
-
type ExtensionOption<Registry extends CustomExtensionOptions> = AbbrExtensionOption<Registry>;
|
|
25
|
-
|
|
26
1
|
/**
|
|
27
2
|
* <zh/> 标准扩展配置项
|
|
28
3
|
*
|
|
29
4
|
* <en/> Standard extension options
|
|
30
5
|
*/
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
export interface STDExtensionOption {
|
|
7
|
+
/**
|
|
8
|
+
* <zh/> 扩展类型
|
|
9
|
+
*
|
|
10
|
+
* <en/> Extension type
|
|
11
|
+
*/
|
|
12
|
+
type: string;
|
|
13
|
+
/**
|
|
14
|
+
* <zh/> 扩展 key,即唯一标识
|
|
15
|
+
*
|
|
16
|
+
* <en/> Extension key, that is, the unique identifier
|
|
17
|
+
*/
|
|
18
|
+
key: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
package/src/runtime/data.ts
CHANGED
|
@@ -580,6 +580,16 @@ export class DataController {
|
|
|
580
580
|
return positionOf(datum);
|
|
581
581
|
}
|
|
582
582
|
|
|
583
|
+
public translateNodeLikeBy(id: ID, offset: Point) {
|
|
584
|
+
if (this.isCombo(id)) this.translateComboBy(id, offset);
|
|
585
|
+
else this.translateNodeBy(id, offset);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
public translateNodeLikeTo(id: ID, position: Point) {
|
|
589
|
+
if (this.isCombo(id)) this.translateComboTo(id, position);
|
|
590
|
+
else this.translateNodeTo(id, position);
|
|
591
|
+
}
|
|
592
|
+
|
|
583
593
|
public translateNodeBy(id: ID, offset: Point) {
|
|
584
594
|
const curr = this.getElementPosition(id);
|
|
585
595
|
const position = add(curr, [...offset, 0].slice(0, 3) as Point);
|
package/src/runtime/element.ts
CHANGED
|
@@ -68,7 +68,7 @@ export class ElementController {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
public getElementType(elementType: ElementType, datum: ElementDatum) {
|
|
71
|
-
const { options } = this.context;
|
|
71
|
+
const { options, graph } = this.context;
|
|
72
72
|
const userDefinedType = options[elementType]?.type || datum.type;
|
|
73
73
|
|
|
74
74
|
if (!userDefinedType) {
|
|
@@ -77,7 +77,8 @@ export class ElementController {
|
|
|
77
77
|
else return 'circle';
|
|
78
78
|
}
|
|
79
79
|
if (typeof userDefinedType === 'string') return userDefinedType;
|
|
80
|
-
|
|
80
|
+
// @ts-expect-error skip type check
|
|
81
|
+
return userDefinedType.call(graph, datum);
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
private getTheme(elementType: ElementType) {
|
|
@@ -134,12 +135,13 @@ export class ElementController {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
private computeElementsDefaultStyle(ids?: ID[]) {
|
|
138
|
+
const { graph } = this.context;
|
|
137
139
|
this.forEachElementData((elementType, elementData) => {
|
|
138
140
|
const length = elementData.length;
|
|
139
141
|
for (let i = 0; i < length; i++) {
|
|
140
142
|
const datum = elementData[i];
|
|
141
143
|
if (ids === undefined || ids.includes(idOf(datum))) {
|
|
142
|
-
this.computeElementDefaultStyle(elementType, { datum });
|
|
144
|
+
this.computeElementDefaultStyle(elementType, { datum, graph });
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
});
|
|
@@ -190,13 +192,14 @@ export class ElementController {
|
|
|
190
192
|
* @param ids - <zh/> 计算指定元素的状态样式 | <en/> compute state style of specified elements
|
|
191
193
|
*/
|
|
192
194
|
private computeElementsStatesStyle(ids?: ID[]) {
|
|
195
|
+
const { graph } = this.context;
|
|
193
196
|
this.forEachElementData((elementType, elementData) => {
|
|
194
197
|
const length = elementData.length;
|
|
195
198
|
for (let i = 0; i < length; i++) {
|
|
196
199
|
const datum = elementData[i];
|
|
197
200
|
if (ids === undefined || ids.includes(idOf(datum))) {
|
|
198
201
|
const states = this.getElementState(idOf(datum));
|
|
199
|
-
this.computeElementStatesStyle(elementType, states, { datum });
|
|
202
|
+
this.computeElementStatesStyle(elementType, states, { datum, graph });
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
205
|
});
|
|
@@ -206,7 +209,10 @@ export class ElementController {
|
|
|
206
209
|
return this.stateStyle[id] || {};
|
|
207
210
|
}
|
|
208
211
|
|
|
209
|
-
private computeStyle(ids?: ID[]) {
|
|
212
|
+
private computeStyle(stage?: string, ids?: ID[]) {
|
|
213
|
+
const skip = ['translate', 'zIndex'];
|
|
214
|
+
if (stage && skip.includes(stage)) return;
|
|
215
|
+
|
|
210
216
|
this.computePaletteStyle();
|
|
211
217
|
this.computeElementsDefaultStyle(ids);
|
|
212
218
|
this.computeElementsStatesStyle(ids);
|
|
@@ -269,7 +275,7 @@ export class ElementController {
|
|
|
269
275
|
const { dataChanges, drawData } = data;
|
|
270
276
|
this.markDestroyElement(drawData);
|
|
271
277
|
// 计算样式 / Calculate style
|
|
272
|
-
this.computeStyle();
|
|
278
|
+
this.computeStyle(context.stage);
|
|
273
279
|
// 创建渲染任务 / Create render task
|
|
274
280
|
const { add, update, remove } = drawData;
|
|
275
281
|
this.destroyElements(remove, context);
|
|
@@ -616,7 +622,7 @@ export class ElementController {
|
|
|
616
622
|
model.updateData(result);
|
|
617
623
|
|
|
618
624
|
// 重新计算数据 / Recalculate data
|
|
619
|
-
this.computeStyle();
|
|
625
|
+
this.computeStyle('expand');
|
|
620
626
|
const { drawData } = this.computeChangesAndDrawData({ stage: 'collapse', animation })!;
|
|
621
627
|
const { update } = drawData;
|
|
622
628
|
|
|
@@ -694,7 +700,7 @@ export class ElementController {
|
|
|
694
700
|
const position = positionOf(model.getComboData([id])[0]);
|
|
695
701
|
|
|
696
702
|
// 重新计算数据 / Recalculate data
|
|
697
|
-
this.computeStyle();
|
|
703
|
+
this.computeStyle('expand');
|
|
698
704
|
const { dataChanges, drawData } = this.computeChangesAndDrawData({ stage: 'expand', animation })!;
|
|
699
705
|
const { add, update } = drawData;
|
|
700
706
|
const context = { animation, stage: 'expand', data: drawData } as const;
|
package/src/runtime/graph.ts
CHANGED
|
@@ -186,7 +186,7 @@ export class Graph extends EventEmitter {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
|
-
* <zh/>
|
|
189
|
+
* <zh/> 设置当前图的缩放区间
|
|
190
190
|
*
|
|
191
191
|
* <en/> Get the zoom range of the current graph
|
|
192
192
|
* @param zoomRange - <zh/> 缩放区间 | <en/> zoom range
|
|
@@ -355,7 +355,7 @@ export class Graph extends EventEmitter {
|
|
|
355
355
|
public updateBehavior(behavior: UpdateBehaviorOption): void {
|
|
356
356
|
this.setBehaviors((behaviors) =>
|
|
357
357
|
behaviors.map((_behavior) => {
|
|
358
|
-
if (
|
|
358
|
+
if (typeof _behavior === 'object' && _behavior.key === behavior.key) {
|
|
359
359
|
return { ..._behavior, ...behavior };
|
|
360
360
|
}
|
|
361
361
|
return _behavior;
|
|
@@ -414,7 +414,7 @@ export class Graph extends EventEmitter {
|
|
|
414
414
|
public updatePlugin(plugin: UpdatePluginOption): void {
|
|
415
415
|
this.setPlugins((plugins) =>
|
|
416
416
|
plugins.map((_plugin) => {
|
|
417
|
-
if (
|
|
417
|
+
if (typeof _plugin === 'object' && _plugin.key === plugin.key) {
|
|
418
418
|
return { ..._plugin, ...plugin };
|
|
419
419
|
}
|
|
420
420
|
return _plugin;
|
|
@@ -482,7 +482,7 @@ export class Graph extends EventEmitter {
|
|
|
482
482
|
public updateTransform(transform: UpdateTransformOption): void {
|
|
483
483
|
this.setTransforms((transforms) =>
|
|
484
484
|
transforms.map((_transform) => {
|
|
485
|
-
if (
|
|
485
|
+
if (typeof _transform === 'object' && _transform.key === transform.key) {
|
|
486
486
|
return { ..._transform, ...transform };
|
|
487
487
|
}
|
|
488
488
|
return _transform;
|
|
@@ -754,6 +754,7 @@ export class Graph extends EventEmitter {
|
|
|
754
754
|
* <zh/> 为组合添加子节点使用 addNodeData / addComboData 方法
|
|
755
755
|
*
|
|
756
756
|
* <en/> Use addNodeData / addComboData method to add child nodes to the combo
|
|
757
|
+
* @apiCategory data
|
|
757
758
|
*/
|
|
758
759
|
public addChildrenData(parentId: ID, childrenData: NodeData[]) {
|
|
759
760
|
this.context.model.addChildrenData(parentId, childrenData);
|
|
@@ -1442,8 +1443,8 @@ export class Graph extends EventEmitter {
|
|
|
1442
1443
|
? [args1, (args2 as boolean) ?? true]
|
|
1443
1444
|
: [{ [args1 as ID]: args2 as Point }, args3];
|
|
1444
1445
|
|
|
1445
|
-
Object.entries(config).forEach(([id, offset]) => this.context.model.
|
|
1446
|
-
await this.context.element!.draw({ animation })?.finished;
|
|
1446
|
+
Object.entries(config).forEach(([id, offset]) => this.context.model.translateNodeLikeBy(id, offset));
|
|
1447
|
+
await this.context.element!.draw({ animation, stage: 'translate' })?.finished;
|
|
1447
1448
|
}
|
|
1448
1449
|
|
|
1449
1450
|
/**
|
|
@@ -1474,8 +1475,8 @@ export class Graph extends EventEmitter {
|
|
|
1474
1475
|
? [args1, (args2 as boolean) ?? true]
|
|
1475
1476
|
: [{ [args1 as ID]: args2 as Point }, args3];
|
|
1476
1477
|
|
|
1477
|
-
Object.entries(config).forEach(([id, position]) => this.context.model.
|
|
1478
|
-
await this.context.element!.draw({ animation })?.finished;
|
|
1478
|
+
Object.entries(config).forEach(([id, position]) => this.context.model.translateNodeLikeTo(id, position));
|
|
1479
|
+
await this.context.element!.draw({ animation, stage: 'translate' })?.finished;
|
|
1479
1480
|
}
|
|
1480
1481
|
|
|
1481
1482
|
/**
|
|
@@ -1627,7 +1628,7 @@ export class Graph extends EventEmitter {
|
|
|
1627
1628
|
|
|
1628
1629
|
const { model, element } = this.context;
|
|
1629
1630
|
model.preventUpdateNodeLikeHierarchy(() => model.updateData(dataToUpdate));
|
|
1630
|
-
await element!.draw({ animation: false })?.finished;
|
|
1631
|
+
await element!.draw({ animation: false, stage: 'zIndex' })?.finished;
|
|
1631
1632
|
}
|
|
1632
1633
|
|
|
1633
1634
|
/**
|
package/src/spec/behavior.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExtensionOptions } from '../registry/extension/types';
|
|
1
|
+
import type { Graph } from '../runtime/graph';
|
|
3
2
|
|
|
4
|
-
export type BehaviorOptions =
|
|
3
|
+
export type BehaviorOptions = (string | CustomBehaviorOption | ((this: Graph) => CustomBehaviorOption))[];
|
|
5
4
|
|
|
6
5
|
export interface UpdateBehaviorOption {
|
|
7
6
|
key: string;
|
|
8
|
-
[key: string]:
|
|
7
|
+
[key: string]: unknown;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export interface CustomBehaviorOption extends Record<string, any> {
|
|
@@ -14,7 +13,7 @@ export interface CustomBehaviorOption extends Record<string, any> {
|
|
|
14
13
|
*
|
|
15
14
|
* <en/> Behavior type
|
|
16
15
|
*/
|
|
17
|
-
type
|
|
16
|
+
type: string;
|
|
18
17
|
/**
|
|
19
18
|
* <zh/> 交互 key,即唯一标识
|
|
20
19
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnimationOptions } from '../../animations/types';
|
|
2
2
|
import type { BaseComboStyleProps } from '../../elements/combos';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Graph } from '../../runtime/graph';
|
|
4
4
|
import type { ComboData } from '../data';
|
|
5
5
|
import type { AnimationStage } from './animation';
|
|
6
6
|
import type { PaletteOptions } from './palette';
|
|
@@ -16,19 +16,31 @@ export interface ComboOptions {
|
|
|
16
16
|
*
|
|
17
17
|
* <en/> Combo type
|
|
18
18
|
*/
|
|
19
|
-
type?: string | ((datum: ComboData) => string);
|
|
19
|
+
type?: string | ((this: Graph, datum: ComboData) => string);
|
|
20
20
|
/**
|
|
21
21
|
* <zh/> 组合样式
|
|
22
22
|
*
|
|
23
23
|
* <en/> Combo style
|
|
24
24
|
*/
|
|
25
|
-
style?:
|
|
25
|
+
style?:
|
|
26
|
+
| ComboStyle
|
|
27
|
+
| ((this: Graph, data: ComboData) => ComboStyle)
|
|
28
|
+
| {
|
|
29
|
+
[K in keyof ComboStyle]: ComboStyle[K] | ((this: Graph, data: ComboData) => ComboStyle[K]);
|
|
30
|
+
};
|
|
26
31
|
/**
|
|
27
32
|
* <zh/> 组合状态样式
|
|
28
33
|
*
|
|
29
34
|
* <en/> Combo state style
|
|
30
35
|
*/
|
|
31
|
-
state?: Record<
|
|
36
|
+
state?: Record<
|
|
37
|
+
string,
|
|
38
|
+
| ComboStyle
|
|
39
|
+
| ((this: Graph, data: ComboData) => ComboStyle)
|
|
40
|
+
| {
|
|
41
|
+
[K in keyof ComboStyle]: ComboStyle[K] | ((this: Graph, data: ComboData) => ComboStyle[K]);
|
|
42
|
+
}
|
|
43
|
+
>;
|
|
32
44
|
/**
|
|
33
45
|
* <zh/> 组合动画
|
|
34
46
|
*
|
package/src/spec/element/edge.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnimationOptions } from '../../animations/types';
|
|
2
2
|
import type { BaseEdgeStyleProps } from '../../elements/edges';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Graph } from '../../runtime/graph';
|
|
4
4
|
import type { EdgeData } from '../data';
|
|
5
5
|
import type { AnimationStage } from './animation';
|
|
6
6
|
import type { PaletteOptions } from './palette';
|
|
@@ -16,19 +16,31 @@ export interface EdgeOptions {
|
|
|
16
16
|
*
|
|
17
17
|
* <en/> Edge type
|
|
18
18
|
*/
|
|
19
|
-
type?: string | ((datum: EdgeData) => string);
|
|
19
|
+
type?: string | ((this: Graph, datum: EdgeData) => string);
|
|
20
20
|
/**
|
|
21
21
|
* <zh/> 边样式
|
|
22
22
|
*
|
|
23
23
|
* <en/> Edge style
|
|
24
24
|
*/
|
|
25
|
-
style?:
|
|
25
|
+
style?:
|
|
26
|
+
| EdgeStyle
|
|
27
|
+
| ((this: Graph, data: EdgeData) => EdgeStyle)
|
|
28
|
+
| {
|
|
29
|
+
[K in keyof EdgeStyle]: EdgeStyle[K] | ((this: Graph, data: EdgeData) => EdgeStyle[K]);
|
|
30
|
+
};
|
|
26
31
|
/**
|
|
27
32
|
* <zh/> 边状态样式
|
|
28
33
|
*
|
|
29
34
|
* <en/> Edge state style
|
|
30
35
|
*/
|
|
31
|
-
state?: Record<
|
|
36
|
+
state?: Record<
|
|
37
|
+
string,
|
|
38
|
+
| EdgeStyle
|
|
39
|
+
| ((this: Graph, data: EdgeData) => EdgeStyle)
|
|
40
|
+
| {
|
|
41
|
+
[K in keyof EdgeStyle]: EdgeStyle[K] | ((this: Graph, data: EdgeData) => EdgeStyle[K]);
|
|
42
|
+
}
|
|
43
|
+
>;
|
|
32
44
|
/**
|
|
33
45
|
* <zh/> 边动画
|
|
34
46
|
*
|
package/src/spec/element/node.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnimationOptions } from '../../animations/types';
|
|
2
2
|
import type { BaseNodeStyleProps } from '../../elements/nodes';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Graph } from '../../runtime/graph';
|
|
4
4
|
import type { NodeData } from '../data';
|
|
5
5
|
import type { AnimationStage } from './animation';
|
|
6
6
|
import type { PaletteOptions } from './palette';
|
|
@@ -16,19 +16,31 @@ export interface NodeOptions {
|
|
|
16
16
|
*
|
|
17
17
|
* <en/> Node type
|
|
18
18
|
*/
|
|
19
|
-
type?: string | ((datum: NodeData) => string);
|
|
19
|
+
type?: string | ((this: Graph, datum: NodeData) => string);
|
|
20
20
|
/**
|
|
21
21
|
* <zh/> 节点样式
|
|
22
22
|
*
|
|
23
23
|
* <en/> Node style
|
|
24
24
|
*/
|
|
25
|
-
style?:
|
|
25
|
+
style?:
|
|
26
|
+
| NodeStyle
|
|
27
|
+
| ((this: Graph, data: NodeData) => NodeStyle)
|
|
28
|
+
| {
|
|
29
|
+
[K in keyof NodeStyle]: NodeStyle[K] | ((this: Graph, data: NodeData) => NodeStyle[K]);
|
|
30
|
+
};
|
|
26
31
|
/**
|
|
27
32
|
* <zh/> 节点状态样式
|
|
28
33
|
*
|
|
29
34
|
* <en/> Node state style
|
|
30
35
|
*/
|
|
31
|
-
state?: Record<
|
|
36
|
+
state?: Record<
|
|
37
|
+
string,
|
|
38
|
+
| NodeStyle
|
|
39
|
+
| ((this: Graph, data: NodeData) => NodeStyle)
|
|
40
|
+
| {
|
|
41
|
+
[K in keyof NodeStyle]: NodeStyle[K] | ((this: Graph, data: NodeData) => NodeStyle[K]);
|
|
42
|
+
}
|
|
43
|
+
>;
|
|
32
44
|
/**
|
|
33
45
|
* <zh/> 节点动画
|
|
34
46
|
*
|
package/src/spec/plugin.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExtensionOptions } from '../registry/extension/types';
|
|
1
|
+
import type { Graph } from '../runtime/graph';
|
|
3
2
|
|
|
4
|
-
export type PluginOptions =
|
|
3
|
+
export type PluginOptions = (string | CustomPluginOption | ((this: Graph) => CustomPluginOption))[];
|
|
5
4
|
|
|
6
5
|
export interface UpdatePluginOption {
|
|
7
6
|
key: string;
|
|
8
|
-
[key: string]:
|
|
7
|
+
[key: string]: unknown;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export interface CustomPluginOption extends Record<string, any> {
|
|
@@ -14,7 +13,7 @@ export interface CustomPluginOption extends Record<string, any> {
|
|
|
14
13
|
*
|
|
15
14
|
* <en/> Plugin type
|
|
16
15
|
*/
|
|
17
|
-
type
|
|
16
|
+
type: string;
|
|
18
17
|
/**
|
|
19
18
|
* <zh/> 插件 key,即唯一标识
|
|
20
19
|
*
|
package/src/spec/transform.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BuiltInTransformOptions } from '../transforms/types';
|
|
1
|
+
import type { Graph } from '../runtime/graph';
|
|
3
2
|
|
|
4
|
-
export type TransformOptions =
|
|
3
|
+
export type TransformOptions = (string | CustomTransformOption | ((this: Graph) => CustomTransformOption))[];
|
|
5
4
|
|
|
6
5
|
export interface UpdateTransformOption {
|
|
7
6
|
key: string;
|
|
8
|
-
[key: string]:
|
|
7
|
+
[key: string]: unknown;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export interface CustomTransformOption {
|
|
12
|
-
type
|
|
11
|
+
type: string;
|
|
13
12
|
key?: string;
|
|
14
|
-
[key: string]:
|
|
13
|
+
[key: string]: unknown;
|
|
15
14
|
}
|
package/src/themes/base.ts
CHANGED
|
@@ -167,6 +167,7 @@ export function create(tokens: ThemeTokens): Theme {
|
|
|
167
167
|
expand: 'node-expand',
|
|
168
168
|
collapse: 'node-collapse',
|
|
169
169
|
update: [{ fields: ['x', 'y', 'fill', 'stroke'] }],
|
|
170
|
+
translate: [{ fields: ['x', 'y'] }],
|
|
170
171
|
},
|
|
171
172
|
},
|
|
172
173
|
edge: {
|
|
@@ -236,6 +237,7 @@ export function create(tokens: ThemeTokens): Theme {
|
|
|
236
237
|
show: 'fade',
|
|
237
238
|
hide: 'fade',
|
|
238
239
|
update: [{ fields: ['sourceNode', 'targetNode'] }, { fields: ['stroke'], shape: 'key' }],
|
|
240
|
+
translate: [{ fields: ['sourceNode', 'targetNode'] }],
|
|
239
241
|
},
|
|
240
242
|
},
|
|
241
243
|
combo: {
|
|
@@ -301,6 +303,7 @@ export function create(tokens: ThemeTokens): Theme {
|
|
|
301
303
|
expand: 'combo-expand',
|
|
302
304
|
collapse: 'combo-collapse',
|
|
303
305
|
update: [{ fields: ['x', 'y'] }, { fields: ['fill', 'stroke', 'lineWidth'], shape: 'key' }],
|
|
306
|
+
translate: [{ fields: ['x', 'y'] }],
|
|
304
307
|
},
|
|
305
308
|
},
|
|
306
309
|
};
|
package/src/transforms/types.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ComboData, EdgeData, NodeData } from '../spec';
|
|
2
2
|
import type { ID } from '../types';
|
|
3
|
-
import type { BaseTransform
|
|
3
|
+
import type { BaseTransform } from './base-transform';
|
|
4
4
|
|
|
5
|
-
export type BuiltInTransformOptions = BaseTransformOptions;
|
|
6
5
|
export type Transform = BaseTransform<any>;
|
|
7
6
|
|
|
8
7
|
/**
|
package/src/types/index.ts
CHANGED
package/src/types/style.ts
CHANGED
package/src/utils/extension.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { STDExtensionOption } from '../registry/extension/types';
|
|
2
|
+
import type { Graph } from '../runtime/graph';
|
|
3
|
+
import type { TransformOptions } from '../spec/transform';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* <zh/> 将模块配置项转换为标准模块格式
|
|
5
7
|
*
|
|
6
8
|
* <en/> Convert extension options to standard format
|
|
9
|
+
* @param graph - <zh/> 图实例 <en/> graph instance
|
|
7
10
|
* @param category - <zh/> 模块类型 <en/> extension type
|
|
8
11
|
* @param extensions - <zh/> 模块配置项 <en/> extension options
|
|
9
12
|
* @returns <zh/> 标准模块配置项 <en/> Standard extension options
|
|
10
13
|
*/
|
|
11
|
-
export function parseExtensions(category: string, extensions:
|
|
14
|
+
export function parseExtensions(graph: Graph, category: string, extensions: TransformOptions): STDExtensionOption[] {
|
|
12
15
|
const counter: Record<string, number> = {};
|
|
13
16
|
|
|
14
17
|
const getKey = (type: string) => {
|
|
@@ -20,7 +23,11 @@ export function parseExtensions(category: string, extensions: ExtensionOptions):
|
|
|
20
23
|
if (typeof extension === 'string') {
|
|
21
24
|
return { type: extension, key: getKey(extension) };
|
|
22
25
|
}
|
|
26
|
+
if (typeof extension === 'function') {
|
|
27
|
+
return extension.call(graph);
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
if (extension.key) return extension;
|
|
24
|
-
return { ...extension, key: getKey(extension.type) };
|
|
31
|
+
return { ...extension, key: getKey(extension.type!) };
|
|
25
32
|
}) as STDExtensionOption[];
|
|
26
33
|
}
|