11import { useCallback } from 'react'
22import { useReactFlow } from 'reactflow'
3+ import { BLOCK_DIMENSIONS , CONTAINER_DIMENSIONS } from '@/lib/blocks/block-dimensions'
34import { createLogger } from '@/lib/logs/console/logger'
45
56const logger = createLogger ( 'NodeUtilities' )
67
7- const DEFAULT_CONTAINER_WIDTH = 500
8- const DEFAULT_CONTAINER_HEIGHT = 300
9-
108/**
119 * Hook providing utilities for node position, hierarchy, and dimension calculations
1210 */
@@ -27,40 +25,43 @@ export function useNodeUtilities(blocks: Record<string, any>) {
2725 const getBlockDimensions = useCallback (
2826 ( blockId : string ) : { width : number ; height : number } => {
2927 const block = blocks [ blockId ]
30- if ( ! block ) return { width : 250 , height : 100 }
28+ if ( ! block ) {
29+ return { width : BLOCK_DIMENSIONS . FIXED_WIDTH , height : BLOCK_DIMENSIONS . MIN_HEIGHT }
30+ }
3131
3232 if ( isContainerType ( block . type ) ) {
3333 return {
34- width : block . data ?. width ? Math . max ( block . data . width , 400 ) : DEFAULT_CONTAINER_WIDTH ,
35- height : block . data ?. height ? Math . max ( block . data . height , 200 ) : DEFAULT_CONTAINER_HEIGHT ,
34+ width : block . data ?. width
35+ ? Math . max ( block . data . width , CONTAINER_DIMENSIONS . MIN_WIDTH )
36+ : CONTAINER_DIMENSIONS . DEFAULT_WIDTH ,
37+ height : block . data ?. height
38+ ? Math . max ( block . data . height , CONTAINER_DIMENSIONS . MIN_HEIGHT )
39+ : CONTAINER_DIMENSIONS . DEFAULT_HEIGHT ,
3640 }
3741 }
3842
3943 // Workflow block nodes have fixed visual width
40- const width = 250
44+ const width = BLOCK_DIMENSIONS . FIXED_WIDTH
4145
4246 // Prefer deterministic height published by the block component; fallback to estimate
4347 let height = block . height
4448
4549 if ( ! height ) {
4650 // Estimate height for workflow blocks before ResizeObserver measures them
47- // Block structure: header (40px) + content area with subblocks
51+ // Block structure: header + content area with subblocks
4852 // Each subblock row is approximately 29px (14px text + 8px gap + padding)
49- const headerHeight = 40
50- const subblockRowHeight = 29
51- const contentPadding = 16 // p-[8px] top and bottom = 16px total
52-
53- // Estimate number of visible subblock rows
54- // This is a rough estimate - actual rendering may vary
5553 const estimatedRows = 3 // Conservative estimate for typical blocks
5654 const hasErrorRow = block . type !== 'starter' && block . type !== 'response' ? 1 : 0
5755
58- height = headerHeight + contentPadding + ( estimatedRows + hasErrorRow ) * subblockRowHeight
56+ height =
57+ BLOCK_DIMENSIONS . HEADER_HEIGHT +
58+ BLOCK_DIMENSIONS . WORKFLOW_CONTENT_PADDING +
59+ ( estimatedRows + hasErrorRow ) * BLOCK_DIMENSIONS . WORKFLOW_ROW_HEIGHT
5960 }
6061
6162 return {
6263 width,
63- height : Math . max ( height , 100 ) ,
64+ height : Math . max ( height , BLOCK_DIMENSIONS . MIN_HEIGHT ) ,
6465 }
6566 } ,
6667 [ blocks , isContainerType ]
@@ -205,9 +206,9 @@ export function useNodeUtilities(blocks: Record<string, any>) {
205206 const absolutePos = getNodeAbsolutePosition ( n . id )
206207 const rect = {
207208 left : absolutePos . x ,
208- right : absolutePos . x + ( n . data ?. width || DEFAULT_CONTAINER_WIDTH ) ,
209+ right : absolutePos . x + ( n . data ?. width || CONTAINER_DIMENSIONS . DEFAULT_WIDTH ) ,
209210 top : absolutePos . y ,
210- bottom : absolutePos . y + ( n . data ?. height || DEFAULT_CONTAINER_HEIGHT ) ,
211+ bottom : absolutePos . y + ( n . data ?. height || CONTAINER_DIMENSIONS . DEFAULT_HEIGHT ) ,
211212 }
212213
213214 return (
@@ -222,8 +223,8 @@ export function useNodeUtilities(blocks: Record<string, any>) {
222223 // Return absolute position so callers can compute relative placement correctly
223224 loopPosition : getNodeAbsolutePosition ( n . id ) ,
224225 dimensions : {
225- width : n . data ?. width || DEFAULT_CONTAINER_WIDTH ,
226- height : n . data ?. height || DEFAULT_CONTAINER_HEIGHT ,
226+ width : n . data ?. width || CONTAINER_DIMENSIONS . DEFAULT_WIDTH ,
227+ height : n . data ?. height || CONTAINER_DIMENSIONS . DEFAULT_HEIGHT ,
227228 } ,
228229 } ) )
229230
@@ -247,8 +248,8 @@ export function useNodeUtilities(blocks: Record<string, any>) {
247248 */
248249 const calculateLoopDimensions = useCallback (
249250 ( nodeId : string ) : { width : number ; height : number } => {
250- const minWidth = DEFAULT_CONTAINER_WIDTH
251- const minHeight = DEFAULT_CONTAINER_HEIGHT
251+ const minWidth = CONTAINER_DIMENSIONS . DEFAULT_WIDTH
252+ const minHeight = CONTAINER_DIMENSIONS . DEFAULT_HEIGHT
252253
253254 // Match styling in subflow-node.tsx:
254255 // - Header section: 50px total height
0 commit comments