@flowgram.ai/free-layout-core 0.5.2 → 0.5.3

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/esm/index.js CHANGED
@@ -2536,12 +2536,14 @@ var WorkflowDocument = class extends FlowDocument {
2536
2536
  * 批量添加节点
2537
2537
  */
2538
2538
  batchAddFromJSON(json, options) {
2539
- const { parent = this.root } = options ?? {};
2539
+ const { parent = this.root, onNodeCreated, onEdgeCreated } = options ?? {};
2540
2540
  const parentID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2541
2541
  const processedJSON = buildGroupJSON(json);
2542
2542
  const nodes = processedJSON.nodes.map(
2543
2543
  (nodeJSON) => this._createWorkflowNode(nodeJSON, {
2544
- parentID
2544
+ parentID,
2545
+ onNodeCreated,
2546
+ onEdgeCreated
2545
2547
  })
2546
2548
  );
2547
2549
  const edges = processedJSON.edges.map((edge) => this.createWorkflowLine(edge, parentID)).filter(Boolean);
@@ -3563,6 +3565,7 @@ var WorkflowOperationBaseServiceImpl = class extends FlowOperationBaseServiceImp
3563
3565
  edges: json.edges ?? []
3564
3566
  };
3565
3567
  const oldNodes = this.document.getAllNodes();
3568
+ const oldEdges = this.linesManager.getAllLines();
3566
3569
  const oldPositionMap = new Map(
3567
3570
  oldNodes.map((node) => [
3568
3571
  node.id,
@@ -3574,11 +3577,17 @@ var WorkflowOperationBaseServiceImpl = class extends FlowOperationBaseServiceImp
3574
3577
  );
3575
3578
  const newNodes = [];
3576
3579
  const newEdges = [];
3577
- this.linesManager.getAllLines().map((line) => line.dispose());
3578
3580
  this.document.batchAddFromJSON(workflowJSON, {
3579
3581
  onNodeCreated: (node) => newNodes.push(node),
3580
3582
  onEdgeCreated: (edge) => newEdges.push(edge)
3581
3583
  });
3584
+ const newEdgeIDSet = new Set(newEdges.map((edge) => edge.id));
3585
+ oldEdges.forEach((edge) => {
3586
+ if (!newEdgeIDSet.has(edge.id)) {
3587
+ edge.dispose();
3588
+ return;
3589
+ }
3590
+ });
3582
3591
  const newNodeIDSet = new Set(newNodes.map((node) => node.id));
3583
3592
  oldNodes.forEach((node) => {
3584
3593
  if (!newNodeIDSet.has(node.id)) {