( blocks: Record<string, BlockState>, edges: Edge[], options: TargetedLayoutOptions )
| 40 | * Unchanged blocks act as anchors to preserve existing layout. |
| 41 | */ |
| 42 | export function applyTargetedLayout( |
| 43 | blocks: Record<string, BlockState>, |
| 44 | edges: Edge[], |
| 45 | options: TargetedLayoutOptions |
| 46 | ): Record<string, BlockState> { |
| 47 | const { |
| 48 | changedBlockIds, |
| 49 | resizedBlockIds = [], |
| 50 | shiftSourceBlockIds = [], |
| 51 | verticalSpacing = DEFAULT_VERTICAL_SPACING, |
| 52 | horizontalSpacing = DEFAULT_HORIZONTAL_SPACING, |
| 53 | gridSize, |
| 54 | } = options |
| 55 | |
| 56 | if ( |
| 57 | (!changedBlockIds || changedBlockIds.length === 0) && |
| 58 | resizedBlockIds.length === 0 && |
| 59 | shiftSourceBlockIds.length === 0 |
| 60 | ) { |
| 61 | return blocks |
| 62 | } |
| 63 | |
| 64 | const changedSet = new Set(changedBlockIds) |
| 65 | const resizedSet = new Set(resizedBlockIds) |
| 66 | const shiftSourceSet = new Set(shiftSourceBlockIds) |
| 67 | const blocksCopy: Record<string, BlockState> = structuredClone(blocks) |
| 68 | |
| 69 | prepareContainerDimensions( |
| 70 | blocksCopy, |
| 71 | edges, |
| 72 | layoutBlocksCore, |
| 73 | horizontalSpacing, |
| 74 | verticalSpacing, |
| 75 | gridSize |
| 76 | ) |
| 77 | |
| 78 | const groups = getBlocksByParent(blocksCopy) |
| 79 | |
| 80 | const subflowDepths = calculateSubflowDepths(blocksCopy, edges, assignLayers) |
| 81 | |
| 82 | layoutGroup( |
| 83 | null, |
| 84 | groups.root, |
| 85 | blocksCopy, |
| 86 | edges, |
| 87 | changedSet, |
| 88 | resizedSet, |
| 89 | shiftSourceSet, |
| 90 | verticalSpacing, |
| 91 | horizontalSpacing, |
| 92 | subflowDepths, |
| 93 | gridSize |
| 94 | ) |
| 95 | |
| 96 | for (const [parentId, childIds] of groups.children.entries()) { |
| 97 | layoutGroup( |
| 98 | parentId, |
| 99 | childIds, |
no test coverage detected