@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/index.js CHANGED
@@ -2584,12 +2584,14 @@ var WorkflowDocument = class extends import_document8.FlowDocument {
2584
2584
  * 批量添加节点
2585
2585
  */
2586
2586
  batchAddFromJSON(json, options) {
2587
- const { parent = this.root } = options ?? {};
2587
+ const { parent = this.root, onNodeCreated, onEdgeCreated } = options ?? {};
2588
2588
  const parentID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2589
2589
  const processedJSON = buildGroupJSON(json);
2590
2590
  const nodes = processedJSON.nodes.map(
2591
2591
  (nodeJSON) => this._createWorkflowNode(nodeJSON, {
2592
- parentID
2592
+ parentID,
2593
+ onNodeCreated,
2594
+ onEdgeCreated
2593
2595
  })
2594
2596
  );
2595
2597
  const edges = processedJSON.edges.map((edge) => this.createWorkflowLine(edge, parentID)).filter(Boolean);
@@ -3611,6 +3613,7 @@ var WorkflowOperationBaseServiceImpl = class extends import_document12.FlowOpera
3611
3613
  edges: json.edges ?? []
3612
3614
  };
3613
3615
  const oldNodes = this.document.getAllNodes();
3616
+ const oldEdges = this.linesManager.getAllLines();
3614
3617
  const oldPositionMap = new Map(
3615
3618
  oldNodes.map((node) => [
3616
3619
  node.id,
@@ -3622,11 +3625,17 @@ var WorkflowOperationBaseServiceImpl = class extends import_document12.FlowOpera
3622
3625
  );
3623
3626
  const newNodes = [];
3624
3627
  const newEdges = [];
3625
- this.linesManager.getAllLines().map((line) => line.dispose());
3626
3628
  this.document.batchAddFromJSON(workflowJSON, {
3627
3629
  onNodeCreated: (node) => newNodes.push(node),
3628
3630
  onEdgeCreated: (edge) => newEdges.push(edge)
3629
3631
  });
3632
+ const newEdgeIDSet = new Set(newEdges.map((edge) => edge.id));
3633
+ oldEdges.forEach((edge) => {
3634
+ if (!newEdgeIDSet.has(edge.id)) {
3635
+ edge.dispose();
3636
+ return;
3637
+ }
3638
+ });
3630
3639
  const newNodeIDSet = new Set(newNodes.map((node) => node.id));
3631
3640
  oldNodes.forEach((node) => {
3632
3641
  if (!newNodeIDSet.has(node.id)) {