(blocks: Record<string, BlockState>)
| 471 | * Groups blocks by their parent container |
| 472 | */ |
| 473 | export function getBlocksByParent(blocks: Record<string, BlockState>): { |
| 474 | root: string[] |
| 475 | children: Map<string, string[]> |
| 476 | } { |
| 477 | const root: string[] = [] |
| 478 | const children = new Map<string, string[]>() |
| 479 | |
| 480 | for (const [id, block] of Object.entries(blocks)) { |
| 481 | const parentId = block.data?.parentId |
| 482 | |
| 483 | if (!parentId) { |
| 484 | root.push(id) |
| 485 | } else { |
| 486 | if (!children.has(parentId)) { |
| 487 | children.set(parentId, []) |
| 488 | } |
| 489 | children.get(parentId)!.push(id) |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | return { root, children } |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * Normalizes node positions to start from a given padding offset. |
no test coverage detected