15 lines
445 B
TypeScript
15 lines
445 B
TypeScript
import type { Node } from "~/types"
|
|
import { childrenOf } from "./childrenOf"
|
|
|
|
/** Chain of nodes from the voyage root down to the node at `path`. */
|
|
export const resolvePath = (root: Node, path: string[]): Node[] => {
|
|
const chain: Node[] = [root]
|
|
let list = childrenOf(root)
|
|
for (const id of path) {
|
|
const node = list.find((n) => n.id === id)
|
|
if (!node) break
|
|
chain.push(node)
|
|
list = childrenOf(node)
|
|
}
|
|
return chain
|
|
}
|