@@ -6,8 +6,6 @@ import { isInputDefinitionTrigger } from '@/lib/workflows/triggers/input-definit
66import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
77import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
88import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
9- import { useSubBlockStore } from '@/stores/workflows/subblock/store'
10- import { getUniqueBlockName , prepareDuplicateBlockState } from '@/stores/workflows/utils'
119import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1210
1311const DEFAULT_DUPLICATE_OFFSET = { x : 50 , y : 50 }
@@ -48,29 +46,25 @@ export const ActionBar = memo(
4846 collaborativeBatchToggleBlockEnabled,
4947 collaborativeBatchToggleBlockHandles,
5048 } = useCollaborativeWorkflow ( )
51- const { activeWorkflowId , setPendingSelection } = useWorkflowRegistry ( )
49+ const { setPendingSelection } = useWorkflowRegistry ( )
5250
5351 const handleDuplicateBlock = useCallback ( ( ) => {
54- const blocks = useWorkflowStore . getState ( ) . blocks
55- const sourceBlock = blocks [ blockId ]
56- if ( ! sourceBlock ) return
52+ const { copyBlocks, preparePasteData } = useWorkflowRegistry . getState ( )
53+ copyBlocks ( [ blockId ] )
5754
58- const newId = crypto . randomUUID ( )
59- const newName = getUniqueBlockName ( sourceBlock . name , blocks )
60- const subBlockValues =
61- useSubBlockStore . getState ( ) . workflowValues [ activeWorkflowId || '' ] ?. [ blockId ] || { }
55+ const pasteData = preparePasteData ( DEFAULT_DUPLICATE_OFFSET )
56+ if ( ! pasteData ) return
6257
63- const { block, subBlockValues : filteredValues } = prepareDuplicateBlockState ( {
64- sourceBlock,
65- newId,
66- newName,
67- positionOffset : DEFAULT_DUPLICATE_OFFSET ,
68- subBlockValues,
69- } )
70-
71- setPendingSelection ( [ newId ] )
72- collaborativeBatchAddBlocks ( [ block ] , [ ] , { } , { } , { [ newId ] : filteredValues } )
73- } , [ blockId , activeWorkflowId , collaborativeBatchAddBlocks , setPendingSelection ] )
58+ const blocks = Object . values ( pasteData . blocks )
59+ setPendingSelection ( blocks . map ( ( b ) => b . id ) )
60+ collaborativeBatchAddBlocks (
61+ blocks ,
62+ pasteData . edges ,
63+ pasteData . loops ,
64+ pasteData . parallels ,
65+ pasteData . subBlockValues
66+ )
67+ } , [ blockId , collaborativeBatchAddBlocks , setPendingSelection ] )
7468
7569 const { isEnabled, horizontalHandles, parentId, parentType } = useWorkflowStore (
7670 useCallback (
0 commit comments