@antv/g6 5.0.0-beta.5 → 5.0.0-beta.6

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 (147) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +13 -1
  3. package/esm/index.js +1 -1
  4. package/esm/item/combo.d.ts +1 -1
  5. package/esm/item/combo.js +16 -9
  6. package/esm/item/combo.js.map +1 -1
  7. package/esm/item/edge.d.ts +1 -1
  8. package/esm/item/edge.js +15 -7
  9. package/esm/item/edge.js.map +1 -1
  10. package/esm/item/node.d.ts +1 -1
  11. package/esm/item/node.js +16 -9
  12. package/esm/item/node.js.map +1 -1
  13. package/esm/runtime/controller/item.d.ts +1 -0
  14. package/esm/runtime/controller/item.js +19 -3
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +82 -4
  17. package/esm/runtime/graph.js +361 -47
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/brush-select.js +1 -2
  20. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  21. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  22. package/esm/stdlib/behavior/create-edge.js +206 -0
  23. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  24. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
  25. package/esm/stdlib/behavior/drag-canvas.js +7 -7
  26. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  27. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  28. package/esm/stdlib/behavior/drag-combo.js +35 -24
  29. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  30. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  31. package/esm/stdlib/behavior/drag-node.js +70 -57
  32. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  33. package/esm/stdlib/behavior/index.d.ts +2 -0
  34. package/esm/stdlib/behavior/index.js +2 -0
  35. package/esm/stdlib/behavior/index.js.map +1 -1
  36. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  37. package/esm/stdlib/behavior/lasso-select.js +1 -2
  38. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  39. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  40. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  41. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  42. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -1
  43. package/esm/stdlib/behavior/zoom-canvas.js +7 -7
  44. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  45. package/esm/stdlib/index.d.ts +4 -0
  46. package/esm/stdlib/index.js +5 -1
  47. package/esm/stdlib/index.js.map +1 -1
  48. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  49. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  50. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  51. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  52. package/esm/stdlib/plugin/minimap/index.js +109 -8
  53. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  54. package/esm/types/graph.d.ts +31 -5
  55. package/esm/types/hook.d.ts +16 -2
  56. package/esm/types/spec.d.ts +6 -3
  57. package/esm/util/item.d.ts +16 -1
  58. package/esm/util/item.js +31 -8
  59. package/esm/util/item.js.map +1 -1
  60. package/esm/util/warn.d.ts +14 -0
  61. package/esm/util/warn.js +4 -0
  62. package/esm/util/warn.js.map +1 -0
  63. package/lib/index.d.ts +13 -1
  64. package/lib/index.js +1 -1
  65. package/lib/item/combo.d.ts +1 -1
  66. package/lib/item/combo.js +16 -9
  67. package/lib/item/combo.js.map +1 -1
  68. package/lib/item/edge.d.ts +1 -1
  69. package/lib/item/edge.js +15 -7
  70. package/lib/item/edge.js.map +1 -1
  71. package/lib/item/node.d.ts +1 -1
  72. package/lib/item/node.js +16 -9
  73. package/lib/item/node.js.map +1 -1
  74. package/lib/runtime/controller/item.d.ts +1 -0
  75. package/lib/runtime/controller/item.js +19 -3
  76. package/lib/runtime/controller/item.js.map +1 -1
  77. package/lib/runtime/graph.d.ts +82 -4
  78. package/lib/runtime/graph.js +361 -47
  79. package/lib/runtime/graph.js.map +1 -1
  80. package/lib/stdlib/behavior/brush-select.js +1 -2
  81. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  82. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  83. package/lib/stdlib/behavior/create-edge.js +210 -0
  84. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  85. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
  86. package/lib/stdlib/behavior/drag-canvas.js +7 -7
  87. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  88. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  89. package/lib/stdlib/behavior/drag-combo.js +35 -24
  90. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  91. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  92. package/lib/stdlib/behavior/drag-node.js +70 -57
  93. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  94. package/lib/stdlib/behavior/index.d.ts +2 -0
  95. package/lib/stdlib/behavior/index.js +2 -0
  96. package/lib/stdlib/behavior/index.js.map +1 -1
  97. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  98. package/lib/stdlib/behavior/lasso-select.js +1 -2
  99. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  100. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  101. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  102. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  103. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -1
  104. package/lib/stdlib/behavior/zoom-canvas.js +7 -7
  105. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  106. package/lib/stdlib/index.d.ts +4 -0
  107. package/lib/stdlib/index.js +5 -1
  108. package/lib/stdlib/index.js.map +1 -1
  109. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  110. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  111. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  112. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  113. package/lib/stdlib/plugin/minimap/index.js +109 -8
  114. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  115. package/lib/types/graph.d.ts +31 -5
  116. package/lib/types/hook.d.ts +16 -2
  117. package/lib/types/spec.d.ts +6 -3
  118. package/lib/util/item.d.ts +16 -1
  119. package/lib/util/item.js +33 -9
  120. package/lib/util/item.js.map +1 -1
  121. package/lib/util/warn.d.ts +14 -0
  122. package/lib/util/warn.js +8 -0
  123. package/lib/util/warn.js.map +1 -0
  124. package/package.json +1 -1
  125. package/src/index.ts +1 -1
  126. package/src/item/combo.ts +14 -9
  127. package/src/item/edge.ts +13 -7
  128. package/src/item/node.ts +14 -9
  129. package/src/runtime/controller/item.ts +28 -6
  130. package/src/runtime/graph.ts +445 -51
  131. package/src/stdlib/behavior/brush-select.ts +4 -2
  132. package/src/stdlib/behavior/create-edge.ts +295 -0
  133. package/src/stdlib/behavior/drag-canvas.ts +8 -8
  134. package/src/stdlib/behavior/drag-combo.ts +2 -2
  135. package/src/stdlib/behavior/drag-node.ts +8 -8
  136. package/src/stdlib/behavior/index.ts +2 -0
  137. package/src/stdlib/behavior/lasso-select.ts +5 -3
  138. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  139. package/src/stdlib/behavior/zoom-canvas.ts +8 -8
  140. package/src/stdlib/index.ts +6 -0
  141. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  142. package/src/stdlib/plugin/minimap/index.ts +113 -9
  143. package/src/types/graph.ts +31 -5
  144. package/src/types/hook.ts +16 -2
  145. package/src/types/spec.ts +9 -3
  146. package/src/util/item.ts +65 -28
  147. package/src/util/warn.ts +20 -0
package/src/item/combo.ts CHANGED
@@ -264,7 +264,7 @@ export default class Combo extends Node {
264
264
  // @ts-ignore
265
265
  public clone(
266
266
  containerGroup: Group,
267
- onlyKeyShape?: boolean,
267
+ shapeIds?: string[],
268
268
  disableAnimate?: boolean,
269
269
  getCombinedBounds?: () =>
270
270
  | {
@@ -276,14 +276,19 @@ export default class Combo extends Node {
276
276
  | false,
277
277
  getChildren?: () => (Node | Combo)[],
278
278
  ) {
279
- if (onlyKeyShape) {
280
- const clonedKeyShape = this.shapeMap.keyShape.cloneNode();
281
- const pos = this.group.getPosition();
282
- const clonedGroup = new Group();
283
- clonedGroup.setPosition(pos);
284
- clonedGroup.appendChild(clonedKeyShape);
285
- containerGroup.appendChild(clonedGroup);
286
- return clonedGroup;
279
+ if (shapeIds?.length) {
280
+ const group = new Group();
281
+ shapeIds.forEach((shapeId) => {
282
+ if (!this.shapeMap[shapeId] || this.shapeMap[shapeId].destroyed) return;
283
+ const clonedKeyShape = this.shapeMap[shapeId].cloneNode();
284
+ // TODO: other animating attributes?
285
+ clonedKeyShape.style.opacity =
286
+ this.renderExt.mergedStyles[shapeId]?.opacity || 1;
287
+ group.appendChild(clonedKeyShape);
288
+ });
289
+ group.setPosition(this.group.getPosition());
290
+ containerGroup.appendChild(group);
291
+ return group;
287
292
  }
288
293
  const clonedModel = clone(this.model);
289
294
  clonedModel.data.disableAnimate = disableAnimate;
package/src/item/edge.ts CHANGED
@@ -194,15 +194,21 @@ export default class Edge extends Item {
194
194
  containerGroup: Group,
195
195
  sourceItem: Node | Combo,
196
196
  targetItem: Node | Combo,
197
- onlyKeyShape?: boolean,
197
+ shapeIds?: string[],
198
198
  disableAnimate?: boolean,
199
199
  ) {
200
- if (onlyKeyShape) {
201
- const clonedKeyShape = this.shapeMap.keyShape.cloneNode();
202
- const clonedGroup = new Group();
203
- clonedGroup.appendChild(clonedKeyShape);
204
- containerGroup.appendChild(clonedGroup);
205
- return clonedGroup;
200
+ if (shapeIds?.length) {
201
+ const group = new Group();
202
+ shapeIds.forEach((shapeId) => {
203
+ if (!this.shapeMap[shapeId] || this.shapeMap[shapeId].destroyed) return;
204
+ const clonedKeyShape = this.shapeMap[shapeId].cloneNode();
205
+ // TODO: other animating attributes?
206
+ clonedKeyShape.style.opacity =
207
+ this.renderExt.mergedStyles[shapeId]?.opacity || 1;
208
+ group.appendChild(clonedKeyShape);
209
+ });
210
+ containerGroup.appendChild(group);
211
+ return group;
206
212
  }
207
213
  const clonedModel = clone(this.model);
208
214
  clonedModel.data.disableAnimate = disableAnimate;
package/src/item/node.ts CHANGED
@@ -205,17 +205,22 @@ export default class Node extends Item {
205
205
 
206
206
  public clone(
207
207
  containerGroup: Group,
208
- onlyKeyShape?: boolean,
208
+ shapeIds?: string[],
209
209
  disableAnimate?: boolean,
210
210
  ) {
211
- if (onlyKeyShape) {
212
- const clonedKeyShape = this.shapeMap.keyShape.cloneNode();
213
- const pos = this.group.getPosition();
214
- const clonedGroup = new Group();
215
- clonedGroup.setPosition(pos);
216
- clonedGroup.appendChild(clonedKeyShape);
217
- containerGroup.appendChild(clonedGroup);
218
- return clonedGroup;
211
+ if (shapeIds?.length) {
212
+ const group = new Group();
213
+ shapeIds.forEach((shapeId) => {
214
+ if (!this.shapeMap[shapeId] || this.shapeMap[shapeId].destroyed) return;
215
+ const clonedKeyShape = this.shapeMap[shapeId].cloneNode();
216
+ // TODO: other animating attributes?
217
+ clonedKeyShape.style.opacity =
218
+ this.renderExt.mergedStyles[shapeId]?.opacity || 1;
219
+ group.appendChild(clonedKeyShape);
220
+ });
221
+ group.setPosition(this.group.getPosition());
222
+ containerGroup.appendChild(group);
223
+ return group;
219
224
  }
220
225
  const clonedModel = clone(this.model);
221
226
  clonedModel.data.disableAnimate = disableAnimate;
@@ -177,6 +177,7 @@ export class ItemController {
177
177
  this.graph.hooks.transientupdate.tap(this.onTransientUpdate.bind(this));
178
178
  this.graph.hooks.viewportchange.tap(this.onViewportChange.bind(this));
179
179
  this.graph.hooks.themechange.tap(this.onThemeChange.bind(this));
180
+ this.graph.hooks.mapperchange.tap(this.onMapperChange.bind(this));
180
181
  this.graph.hooks.treecollapseexpand.tap(
181
182
  this.onTreeCollapseExpand.bind(this),
182
183
  );
@@ -850,6 +851,16 @@ export class ItemController {
850
851
  });
851
852
  };
852
853
 
854
+ private onMapperChange = ({ type, mapper }) => {
855
+ if (!mapper) return;
856
+ this.itemMap.forEach((item) => {
857
+ const itemTye = item.getType();
858
+ if (itemTye !== type) return;
859
+ item.mapper = mapper;
860
+ item.update(item.model, undefined, false);
861
+ });
862
+ };
863
+
853
864
  private onDestroy = () => {
854
865
  Object.values(this.itemMap).forEach((item) => item.destroy());
855
866
  // Fix OOM problem, since this map will hold all the refs of items.
@@ -860,12 +871,17 @@ export class ItemController {
860
871
  type: ITEM_TYPE | SHAPE_TYPE;
861
872
  id: ID;
862
873
  config: {
874
+ action: 'remove' | 'add' | 'update' | undefined;
863
875
  style?: ShapeStyle;
864
- // Data to be merged into the transient item.
876
+ /** Data to be merged into the transient item. */
865
877
  data?: Record<string, any>;
866
- action: 'remove' | 'add' | 'update' | undefined;
867
- onlyDrawKeyShape?: boolean;
878
+ shapeIds?: string[];
879
+ /** For type: 'edge' */
880
+ drawSource?: boolean;
881
+ /** For type: 'edge' */
882
+ drawTarget?: boolean;
868
883
  upsertAncestors?: boolean;
884
+ visible?: boolean;
869
885
  [shapeConfig: string]: unknown;
870
886
  };
871
887
  canvas: Canvas;
@@ -878,8 +894,11 @@ export class ItemController {
878
894
  data = {},
879
895
  capture,
880
896
  action,
881
- onlyDrawKeyShape,
897
+ shapeIds,
898
+ drawSource,
899
+ drawTarget,
882
900
  upsertAncestors,
901
+ visible = true,
883
902
  } = config as any;
884
903
  const isItemType = type === 'node' || type === 'edge' || type === 'combo';
885
904
  // Removing
@@ -902,6 +921,9 @@ export class ItemController {
902
921
  );
903
922
  }
904
923
  if (transientItem && !transientItem.destroyed) {
924
+ if (!(transientItem as Node | Edge | Combo).getType?.()) {
925
+ (transientItem as Group).remove();
926
+ }
905
927
  transientItem.destroy();
906
928
  }
907
929
  this.transientItemMap.delete(id);
@@ -930,11 +952,11 @@ export class ItemController {
930
952
  this.transientItemMap,
931
953
  this.itemMap,
932
954
  graphCore,
933
- onlyDrawKeyShape,
955
+ { shapeIds, drawSource, drawTarget, visible },
934
956
  upsertAncestors,
935
957
  );
936
958
 
937
- if (onlyDrawKeyShape) {
959
+ if (shapeIds) {
938
960
  // only update node positions to cloned node container(group)
939
961
  if (
940
962
  (type === 'node' || type === 'combo') &&