(
levels: ReadonlyMap<string, TreeLevel>,
expanded: ReadonlySet<string>,
rootPath = '',
)
| 281 | * Pfeil-Zeichen, statt eine leere Ebene als "hier ist nichts" auszugeben. |
| 282 | */ |
| 283 | export function flattenTree( |
| 284 | levels: ReadonlyMap<string, TreeLevel>, |
| 285 | expanded: ReadonlySet<string>, |
| 286 | rootPath = '', |
| 287 | ): TreeRow[] { |
| 288 | const rows: TreeRow[] = []; |
| 289 | const walk = (path: string, depth: number, seen: Set<string>): void => { |
| 290 | const level = levels.get(path); |
| 291 | if (level === undefined || seen.has(path)) { |
| 292 | return; |
| 293 | } |
| 294 | seen.add(path); |
| 295 | for (const child of level.children) { |
| 296 | const isExpanded = child.kind === 'dir' && expanded.has(child.path); |
| 297 | rows.push({ |
| 298 | ...child, |
| 299 | depth, |
| 300 | expanded: isExpanded, |
| 301 | loaded: child.kind === 'dir' ? levels.has(child.path) : true, |
| 302 | }); |
| 303 | if (isExpanded) { |
| 304 | walk(child.path, depth + 1, seen); |
| 305 | } |
| 306 | } |
| 307 | }; |
| 308 | walk(rootPath, 0, new Set()); |
| 309 | return rows; |
| 310 | } |
| 311 | |
| 312 | /** Alle Ordnerpfade einer Ebene, in Anzeigeordnung. */ |
| 313 | export function directoryPaths(level: TreeLevel): string[] { |
no test coverage detected