{"version":3,"names":["getNodeChildren","nodes","id","onlyOpenChildren","directChildren","filter","node","parentId","flatMap","child","context","open","getDeepestNode","deepestNodeId","maxDepth","findDeepest","nodeId","depth","children","forEach","find","getNodeAncestors","allAncestors","currentParentId","currentNode","concat"],"sources":["nodes.ts"],"sourcesContent":["import type { FloatingNodeType } from \"../types\";\n\n/**\n * Tree walks over a flat `FloatingNodeType[]` list, each node storing\n * its `parentId`. Ported 1:1 from the React source; no reactivity in\n * play here.\n */\n\nexport function getNodeChildren(\n\tnodes: Array<FloatingNodeType>,\n\tid: string | undefined,\n\tonlyOpenChildren = true,\n): Array<FloatingNodeType> {\n\tconst directChildren = nodes.filter((node) => node.parentId === id);\n\n\treturn directChildren.flatMap((child) => [\n\t\t...(!onlyOpenChildren || child.context?.open ? [child] : []),\n\t\t...getNodeChildren(nodes, child.id, onlyOpenChildren),\n\t]);\n}\n\nexport function getDeepestNode(\n\tnodes: Array<FloatingNodeType>,\n\tid: string | undefined,\n): FloatingNodeType | undefined {\n\tlet deepestNodeId: string | undefined;\n\tlet maxDepth = -1;\n\n\tfunction findDeepest(nodeId: string | undefined, depth: number) {\n\t\tif (depth > maxDepth) {\n\t\t\tdeepestNodeId = nodeId;\n\t\t\tmaxDepth = depth;\n\t\t}\n\n\t\tconst children = getNodeChildren(nodes, nodeId);\n\n\t\tchildren.forEach((child) => {\n\t\t\tfindDeepest(child.id, depth + 1);\n\t\t});\n\t}\n\n\tfindDeepest(id, 0);\n\n\treturn nodes.find((node) => node.id === deepestNodeId);\n}\n\nexport function getNodeAncestors(\n\tnodes: Array<FloatingNodeType>,\n\tid: string | undefined,\n): Array<FloatingNodeType> {\n\tlet allAncestors: Array<FloatingNodeType> = [];\n\tlet currentParentId = nodes.find((node) => node.id === id)?.parentId;\n\n\twhile (currentParentId) {\n\t\tconst currentNode = nodes.find((node) => node.id === currentParentId);\n\t\tcurrentParentId = currentNode?.parentId;\n\t\tif (currentNode) {\n\t\t\tallAncestors = allAncestors.concat(currentNode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