MCPcopy Index your code
hub / github.com/simstudioai/sim / getSourceHandleYOffset

Function getSourceHandleYOffset

apps/sim/lib/workflows/autolayout/core.ts:26–56  ·  view source on GitHub ↗

* Calculates the Y offset for a source handle based on block type and handle ID.

(block: BlockState, sourceHandle?: string | null)

Source from the content-addressed store, hash-verified

24 * Calculates the Y offset for a source handle based on block type and handle ID.
25 */
26function getSourceHandleYOffset(block: BlockState, sourceHandle?: string | null): number {
27 if (sourceHandle === 'error') {
28 const blockHeight = block.height || BLOCK_DIMENSIONS.MIN_HEIGHT
29 return blockHeight - HANDLE_POSITIONS.ERROR_BOTTOM_OFFSET
30 }
31
32 if (sourceHandle && SUBFLOW_START_HANDLES.has(sourceHandle)) {
33 return HANDLE_POSITIONS.SUBFLOW_START_Y_OFFSET
34 }
35
36 if (block.type === 'condition' && sourceHandle?.startsWith(EDGE.CONDITION_PREFIX)) {
37 const conditionId = sourceHandle.replace(EDGE.CONDITION_PREFIX, '')
38 try {
39 const conditionsValue = block.subBlocks?.conditions?.value
40 if (typeof conditionsValue === 'string' && conditionsValue) {
41 const conditions = JSON.parse(conditionsValue) as Array<{ id?: string }>
42 const conditionIndex = conditions.findIndex((c) => c.id === conditionId)
43 if (conditionIndex >= 0) {
44 return (
45 HANDLE_POSITIONS.CONDITION_START_Y +
46 conditionIndex * HANDLE_POSITIONS.CONDITION_ROW_HEIGHT
47 )
48 }
49 }
50 } catch {
51 // Fall back to default offset
52 }
53 }
54
55 return HANDLE_POSITIONS.DEFAULT_Y_OFFSET
56}
57
58/**
59 * Calculates the Y offset for a target handle based on block type and handle ID.

Callers 1

calculatePositionsFunction · 0.85

Calls 2

parseMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected