@@ -231,38 +231,39 @@ const WorkflowContent = React.memo(() => {
231231 [ getNodes ]
232232 )
233233
234+ // Helper function to get orientation config
235+ const getOrientationConfig = useCallback ( ( orientation : string ) => {
236+ return orientation === 'vertical'
237+ ? {
238+ // Vertical handles: optimize for top-to-bottom flow
239+ horizontalSpacing : 400 ,
240+ verticalSpacing : 300 ,
241+ startX : 200 ,
242+ startY : 200 ,
243+ }
244+ : {
245+ // Horizontal handles: optimize for left-to-right flow
246+ horizontalSpacing : 600 ,
247+ verticalSpacing : 200 ,
248+ startX : 150 ,
249+ startY : 300 ,
250+ }
251+ } , [ ] )
252+
234253 // Auto-layout handler
235254 const handleAutoLayout = useCallback ( ( ) => {
236255 if ( Object . keys ( blocks ) . length === 0 ) return
237256
238257 // Detect the predominant handle orientation in the workflow
239258 const detectedOrientation = detectHandleOrientation ( blocks )
240259
241- // Optimize spacing based on handle orientation
242- const orientationConfig = useMemo (
243- ( ) =>
244- detectedOrientation === 'vertical'
245- ? {
246- // Vertical handles: optimize for top-to-bottom flow
247- horizontalSpacing : 400 ,
248- verticalSpacing : 300 ,
249- startX : 200 ,
250- startY : 200 ,
251- }
252- : {
253- // Horizontal handles: optimize for left-to-right flow
254- horizontalSpacing : 600 ,
255- verticalSpacing : 200 ,
256- startX : 150 ,
257- startY : 300 ,
258- } ,
259- [ detectedOrientation ]
260- )
260+ // Get spacing configuration based on handle orientation
261+ const orientationConfig = getOrientationConfig ( detectedOrientation )
261262
262263 applyAutoLayoutSmooth (
263264 blocks ,
264265 edges ,
265- collaborativeUpdateBlockPosition ,
266+ storeUpdateBlockPosition ,
266267 fitView ,
267268 resizeLoopNodesWrapper ,
268269 {
@@ -271,6 +272,12 @@ const WorkflowContent = React.memo(() => {
271272 animationDuration : 500 , // Smooth 500ms animation
272273 isSidebarCollapsed,
273274 handleOrientation : detectedOrientation , // Explicitly set the detected orientation
275+ onComplete : ( finalPositions ) => {
276+ // Emit collaborative updates for final positions after animation completes
277+ finalPositions . forEach ( ( position , blockId ) => {
278+ collaborativeUpdateBlockPosition ( blockId , position )
279+ } )
280+ } ,
274281 }
275282 )
276283
@@ -286,10 +293,12 @@ const WorkflowContent = React.memo(() => {
286293 } , [
287294 blocks ,
288295 edges ,
296+ storeUpdateBlockPosition ,
289297 collaborativeUpdateBlockPosition ,
290298 fitView ,
291299 isSidebarCollapsed ,
292300 resizeLoopNodesWrapper ,
301+ getOrientationConfig ,
293302 ] )
294303
295304 const debouncedAutoLayout = useCallback ( ( ) => {
0 commit comments