@bian-womp/spark-workbench 0.3.67 → 0.3.69

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/lib/cjs/index.cjs CHANGED
@@ -564,6 +564,7 @@ class InMemoryWorkbench extends AbstractWorkbench {
564
564
  const copiedNodes = nodesToCopy.map((node) => {
565
565
  const pos = positions[node.nodeId];
566
566
  const size = sizes[node.nodeId];
567
+ const customNodeData = this.getCustomNodeData(node.nodeId);
567
568
  // Get all inbound edges for this node
568
569
  const inboundEdges = this.def.edges.filter((e) => e.target.nodeId === node.nodeId);
569
570
  // Build set of handles that have inbound edges
@@ -588,6 +589,9 @@ class InMemoryWorkbench extends AbstractWorkbench {
588
589
  : undefined,
589
590
  size,
590
591
  inputs: inputsToCopy,
592
+ customData: customNodeData !== undefined
593
+ ? lod.cloneDeep(customNodeData)
594
+ : undefined,
591
595
  originalNodeId: node.nodeId,
592
596
  };
593
597
  });
@@ -864,6 +868,12 @@ class InMemoryWorkbench extends AbstractWorkbench {
864
868
  dry: true,
865
869
  });
866
870
  nodeIdMap.set(nodeData.originalNodeId, newNodeId);
871
+ if (nodeData.customData !== undefined) {
872
+ this.setCustomNodeData(newNodeId, lod.cloneDeep(nodeData.customData), {
873
+ commit: false,
874
+ reason: options?.reason,
875
+ });
876
+ }
867
877
  }
868
878
  // Add edges
869
879
  for (const edgeData of data.edges) {
@@ -2542,7 +2552,7 @@ function layoutNode(args, overrides) {
2542
2552
  };
2543
2553
  }
2544
2554
 
2545
- function useWorkbenchBridge(wb) {
2555
+ function useWorkbenchBridge(wb, handlesMap) {
2546
2556
  const onConnect = React.useCallback((params) => {
2547
2557
  if (!params.source || !params.target)
2548
2558
  return;
@@ -2555,11 +2565,27 @@ function useWorkbenchBridge(wb) {
2555
2565
  e.target.handle === params.targetHandle);
2556
2566
  if (exists)
2557
2567
  return;
2568
+ // Check if target input handle is a non-array type (typeId doesn't end with [])
2569
+ // If so, remove any existing connections to that handle before connecting
2570
+ const targetHandles = handlesMap?.[params.target];
2571
+ const targetTypeId = targetHandles
2572
+ ? sparkGraph.getInputTypeId(targetHandles.inputs, params.targetHandle)
2573
+ : undefined;
2574
+ const isArrayInput = targetTypeId?.endsWith("[]") ?? false;
2575
+ if (!isArrayInput) {
2576
+ // Find existing edges to this input handle
2577
+ const existingEdges = wb.def.edges.filter((e) => e.target.nodeId === params.target &&
2578
+ e.target.handle === params.targetHandle);
2579
+ // Remove existing edges (without committing yet)
2580
+ for (const edge of existingEdges) {
2581
+ wb.disconnect(edge.id, { commit: false });
2582
+ }
2583
+ }
2558
2584
  wb.connect({
2559
2585
  source: { nodeId: params.source, handle: params.sourceHandle },
2560
2586
  target: { nodeId: params.target, handle: params.targetHandle },
2561
2587
  }, { commit: true });
2562
- }, [wb]);
2588
+ }, [wb, handlesMap]);
2563
2589
  const onNodesChange = React.useCallback((changes) => {
2564
2590
  const positions = {};
2565
2591
  let commit = false;
@@ -6001,7 +6027,7 @@ const WorkbenchCanvasComponent = React.forwardRef((props, ref) => {
6001
6027
  }
6002
6028
  },
6003
6029
  }), []);
6004
- const { onConnect, onNodesChange, onEdgesChange, onEdgesDelete, onNodesDelete, } = useWorkbenchBridge(wb);
6030
+ const { onConnect, onNodesChange, onEdgesChange, onEdgesDelete, onNodesDelete, } = useWorkbenchBridge(wb, handlesMap);
6005
6031
  const ui = React.useMemo(() => wb.getUI(), [wb, uiVersion]);
6006
6032
  const { nodeTypes, resolveNodeType } = React.useMemo(() => {
6007
6033
  // Build nodeTypes map using UI extension registry