( collection: Collection<Node<unknown>>, expandedKeys: Set<Key>, key: Key )
| 722 | // are expanded). Returns `key` unchanged when it is already visible. A collapsed ancestor hides |
| 723 | // everything beneath it, so the highest collapsed ancestor is the closest visible row. |
| 724 | function closestVisibleKey( |
| 725 | collection: Collection<Node<unknown>>, |
| 726 | expandedKeys: Set<Key>, |
| 727 | key: Key |
| 728 | ): Key { |
| 729 | let target = key; |
| 730 | let node = collection.getItem(key); |
| 731 | while (node?.parentKey != null) { |
| 732 | let parent = collection.getItem(node.parentKey); |
| 733 | if (parent?.type === 'item' && !expandedKeys.has(node.parentKey)) { |
| 734 | target = node.parentKey; |
| 735 | } |
| 736 | node = parent; |
| 737 | } |
| 738 | return target; |
| 739 | } |
| 740 | |
| 741 | // Cache so each row doesn't have to walk up the tree every time |
| 742 | let selectedAncestorsCache = new WeakMap< |
no test coverage detected