@@ -1117,9 +1117,12 @@ export const useNodesInteractions = () => {
1117
1117
const {
1118
1118
getNodes,
1119
1119
setNodes,
1120
+ edges,
1121
+ setEdges,
1120
1122
} = store . getState ( )
1121
1123
1122
1124
const nodesToPaste : Node [ ] = [ ]
1125
+ const edgesToPaste : Edge [ ] = [ ]
1123
1126
const nodes = getNodes ( )
1124
1127
1125
1128
if ( clipboardElements . length ) {
@@ -1128,6 +1131,7 @@ export const useNodesInteractions = () => {
1128
1131
const currentPosition = screenToFlowPosition ( { x : mousePosition . pageX , y : mousePosition . pageY } )
1129
1132
const offsetX = currentPosition . x - x
1130
1133
const offsetY = currentPosition . y - y
1134
+ let idMapping : Record < string , string > = { }
1131
1135
clipboardElements . forEach ( ( nodeToPaste , index ) => {
1132
1136
const nodeType = nodeToPaste . data . type
1133
1137
@@ -1159,7 +1163,13 @@ export const useNodesInteractions = () => {
1159
1163
newIterationStartNode ! . parentId = newNode . id ;
1160
1164
( newNode . data as IterationNodeType ) . start_node_id = newIterationStartNode ! . id
1161
1165
1162
- newChildren = handleNodeIterationChildrenCopy ( nodeToPaste . id , newNode . id )
1166
+ const oldIterationStartNode = nodes
1167
+ . find ( n => n . parentId === nodeToPaste . id && n . type === CUSTOM_ITERATION_START_NODE )
1168
+ idMapping [ oldIterationStartNode ! . id ] = newIterationStartNode ! . id
1169
+
1170
+ const { copyChildren, newIdMapping } = handleNodeIterationChildrenCopy ( nodeToPaste . id , newNode . id , idMapping )
1171
+ newChildren = copyChildren
1172
+ idMapping = newIdMapping
1163
1173
newChildren . forEach ( ( child ) => {
1164
1174
newNode . data . _children ?. push ( child . id )
1165
1175
} )
@@ -1172,7 +1182,27 @@ export const useNodesInteractions = () => {
1172
1182
nodesToPaste . push ( ...newChildren )
1173
1183
} )
1174
1184
1185
+ edges . forEach ( ( edge ) => {
1186
+ const sourceId = idMapping [ edge . source ]
1187
+ const targetId = idMapping [ edge . target ]
1188
+
1189
+ if ( sourceId && targetId ) {
1190
+ const newEdge : Edge = {
1191
+ ...edge ,
1192
+ id : `${ sourceId } -${ edge . sourceHandle } -${ targetId } -${ edge . targetHandle } ` ,
1193
+ source : sourceId ,
1194
+ target : targetId ,
1195
+ data : {
1196
+ ...edge . data ,
1197
+ _connectedNodeIsSelected : false ,
1198
+ } ,
1199
+ }
1200
+ edgesToPaste . push ( newEdge )
1201
+ }
1202
+ } )
1203
+
1175
1204
setNodes ( [ ...nodes , ...nodesToPaste ] )
1205
+ setEdges ( [ ...edges , ...edgesToPaste ] )
1176
1206
saveStateToHistory ( WorkflowHistoryEvent . NodePaste )
1177
1207
handleSyncWorkflowDraft ( )
1178
1208
}
0 commit comments