{"version":3,"file":"flattenTree.mjs","names":[],"sources":["../../../../package/common/tree/flattenTree.ts"],"sourcesContent":["import type { FlatTreeNode, TreeNode, TreeValue } from './tree.types';\n\n/** The visible nodes in render order. Flat, not nested, deliberately: see docs/Tree.md. */\nexport function flattenTree(\n  nodes: TreeNode[],\n  expandedKeys: TreeValue[],\n  level = 0,\n  parentKey: TreeValue | null = null,\n): FlatTreeNode[] {\n  return nodes.flatMap((node, index) => {\n    const isBranch = node.children !== undefined;\n    const isExpanded = isBranch && expandedKeys.includes(node.key);\n    const self: FlatTreeNode = {\n      node,\n      level,\n      parentKey,\n      isBranch,\n      isExpanded,\n      setSize: nodes.length,\n      posInSet: index + 1,\n    };\n    if (!isExpanded || !node.children?.length) return [self];\n    return [self, ...flattenTree(node.children, expandedKeys, level + 1, node.key)];\n  });\n}\n"],"mappings":"aAGA,SAAgB,EACd,EACA,EACA,EAAQ,EACR,EAA8B,KACd,CAChB,OAAO,EAAM,SAAS,EAAM,IAAU,CACpC,IAAM,EAAW,EAAK,WAAa,IAAA,GAC7B,EAAa,GAAY,EAAa,SAAS,EAAK,GAAG,EACvD,EAAqB,CACzB,OACA,QACA,YACA,WACA,aACA,QAAS,EAAM,OACf,SAAU,EAAQ,CACpB,EAEA,MADI,CAAC,GAAc,CAAC,EAAK,UAAU,OAAe,CAAC,CAAI,EAChD,CAAC,EAAM,GAAG,EAAY,EAAK,SAAU,EAAc,EAAQ,EAAG,EAAK,GAAG,CAAC,CAChF,CAAC,CACH"}