11import type { Edge } from 'reactflow'
22import { v4 as uuidv4 } from 'uuid'
3-
4- export function filterNewEdges ( edgesToAdd : Edge [ ] , currentEdges : Edge [ ] ) : Edge [ ] {
5- return edgesToAdd . filter ( ( edge ) => {
6- if ( edge . source === edge . target ) return false
7- return ! currentEdges . some (
8- ( e ) =>
9- e . source === edge . source &&
10- e . sourceHandle === edge . sourceHandle &&
11- e . target === edge . target &&
12- e . targetHandle === edge . targetHandle
13- )
14- } )
15- }
16-
173import { getBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
4+ import { mergeSubBlockValues } from '@/lib/workflows/subblocks'
185import { getBlock } from '@/blocks'
196import { normalizeName } from '@/executor/constants'
207import { useSubBlockStore } from '@/stores/workflows/subblock/store'
@@ -32,6 +19,19 @@ const WEBHOOK_SUBBLOCK_FIELDS = ['webhookId', 'triggerPath']
3219
3320export { normalizeName }
3421
22+ export function filterNewEdges ( edgesToAdd : Edge [ ] , currentEdges : Edge [ ] ) : Edge [ ] {
23+ return edgesToAdd . filter ( ( edge ) => {
24+ if ( edge . source === edge . target ) return false
25+ return ! currentEdges . some (
26+ ( e ) =>
27+ e . source === edge . source &&
28+ e . sourceHandle === edge . sourceHandle &&
29+ e . target === edge . target &&
30+ e . targetHandle === edge . targetHandle
31+ )
32+ } )
33+ }
34+
3535export interface RegeneratedState {
3636 blocks : Record < string , BlockState >
3737 edges : Edge [ ]
@@ -201,27 +201,20 @@ export function prepareDuplicateBlockState(options: PrepareDuplicateBlockStateOp
201201 Object . entries ( subBlockValues ) . filter ( ( [ key ] ) => ! WEBHOOK_SUBBLOCK_FIELDS . includes ( key ) )
202202 )
203203
204- const mergedSubBlocks : Record < string , SubBlockState > = sourceBlock . subBlocks
204+ const baseSubBlocks : Record < string , SubBlockState > = sourceBlock . subBlocks
205205 ? JSON . parse ( JSON . stringify ( sourceBlock . subBlocks ) )
206206 : { }
207207
208208 WEBHOOK_SUBBLOCK_FIELDS . forEach ( ( field ) => {
209- if ( field in mergedSubBlocks ) {
210- delete mergedSubBlocks [ field ]
209+ if ( field in baseSubBlocks ) {
210+ delete baseSubBlocks [ field ]
211211 }
212212 } )
213213
214- Object . entries ( filteredSubBlockValues ) . forEach ( ( [ subblockId , value ] ) => {
215- if ( mergedSubBlocks [ subblockId ] ) {
216- mergedSubBlocks [ subblockId ] . value = value as SubBlockState [ 'value' ]
217- } else {
218- mergedSubBlocks [ subblockId ] = {
219- id : subblockId ,
220- type : 'short-input' ,
221- value : value as SubBlockState [ 'value' ] ,
222- }
223- }
224- } )
214+ const mergedSubBlocks = mergeSubBlockValues ( baseSubBlocks , filteredSubBlockValues ) as Record <
215+ string ,
216+ SubBlockState
217+ >
225218
226219 const block : BlockState = {
227220 id : newId ,
0 commit comments