import { Key , TreeNode } from './interface' ; export function flatten < R , G , I > ( treeNodes , expandedKeys ? ) { const expandedKeySet = expandedKeys ? new Set < Key > ( expandedKeys ) : undefined ; const flattenedNodes = [ ] ; function traverse ( treeNodes ) { treeNodes . forEach ( ( treeNode ) => { flattenedNodes . push ( treeNode ) ; if ( treeNode . isLeaf || ! treeNode . children || treeNode . ignored ) return ; if ( treeNode . isGroup ) { traverse ( treeNode . children ) ; } else if ( expandedKeySet === undefined || expandedKeySet . has ( treeNode . key ) ) { traverse ( treeNode . children ) ; } } ) ; } traverse ( treeNodes ) ; return flattenedNodes ; }