@@ -3,6 +3,7 @@ import { createLogger } from '@sim/logger'
33import { useReactFlow } from 'reactflow'
44import type { AutoLayoutOptions } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils'
55import { applyAutoLayoutAndUpdateStore as applyAutoLayoutStandalone } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils'
6+ import { useSnapToGridSize } from '@/hooks/queries/general-settings'
67import { useCanvasViewport } from '@/hooks/use-canvas-viewport'
78
89export type { AutoLayoutOptions }
@@ -13,21 +14,28 @@ const logger = createLogger('useAutoLayout')
1314 * Hook providing auto-layout functionality for workflows.
1415 * Binds workflowId context and provides memoized callback for React components.
1516 * Includes automatic fitView animation after successful layout.
17+ * Automatically uses the user's snap-to-grid setting for grid-aligned layout.
1618 *
1719 * Note: This hook requires a ReactFlowProvider ancestor.
1820 */
1921export function useAutoLayout ( workflowId : string | null ) {
2022 const reactFlowInstance = useReactFlow ( )
2123 const { fitViewToBounds } = useCanvasViewport ( reactFlowInstance )
24+ const snapToGridSize = useSnapToGridSize ( )
2225
2326 const applyAutoLayoutAndUpdateStore = useCallback (
2427 async ( options : AutoLayoutOptions = { } ) => {
2528 if ( ! workflowId ) {
2629 return { success : false , error : 'No workflow ID provided' }
2730 }
28- return applyAutoLayoutStandalone ( workflowId , options )
31+ // Include gridSize from user's snap-to-grid setting
32+ const optionsWithGrid : AutoLayoutOptions = {
33+ ...options ,
34+ gridSize : options . gridSize ?? ( snapToGridSize > 0 ? snapToGridSize : undefined ) ,
35+ }
36+ return applyAutoLayoutStandalone ( workflowId , optionsWithGrid )
2937 } ,
30- [ workflowId ]
38+ [ workflowId , snapToGridSize ]
3139 )
3240
3341 /**
0 commit comments