* Finds all descendant block IDs of a container (recursive). * Works with raw DB block arrays.
(containerId: string, allBlocks: DbBlockRef[])
| 70 | * Works with raw DB block arrays. |
| 71 | */ |
| 72 | function findDbDescendants(containerId: string, allBlocks: DbBlockRef[]): string[] { |
| 73 | const descendants: string[] = [] |
| 74 | const visited = new Set<string>() |
| 75 | const stack = [containerId] |
| 76 | while (stack.length > 0) { |
| 77 | const current = stack.pop()! |
| 78 | if (visited.has(current)) continue |
| 79 | visited.add(current) |
| 80 | for (const b of allBlocks) { |
| 81 | const pid = (b.data as Record<string, unknown> | null)?.parentId |
| 82 | if (pid === current) { |
| 83 | descendants.push(b.id) |
| 84 | stack.push(b.id) |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | return descendants |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Shared function to handle auto-connect edge insertion |
no test coverage detected