* Given a set of root nodes and the current node level, flattens any nested * nodes into a single array. * * If any nodes are not expanded, then their children will not be added into the array. * This will still traverse all nested children in order to build up our internal data * mod
(nodes: readonly T[], level = 0)
| 1002 | * models, but will not include them in the returned array. |
| 1003 | */ |
| 1004 | private _flattenNestedNodesWithExpansion(nodes: readonly T[], level = 0): Observable<T[]> { |
| 1005 | const childrenAccessor = this._getChildrenAccessor(); |
| 1006 | // If we're using a level accessor, we don't need to flatten anything. |
| 1007 | if (!childrenAccessor) { |
| 1008 | return observableOf([...nodes]); |
| 1009 | } |
| 1010 | |
| 1011 | return observableOf(...nodes).pipe( |
| 1012 | concatMap(node => { |
| 1013 | const parentKey = this._getExpansionKey(node); |
| 1014 | if (!this._parents.has(parentKey)) { |
| 1015 | this._parents.set(parentKey, null); |
| 1016 | } |
| 1017 | this._levels.set(parentKey, level); |
| 1018 | |
| 1019 | const children = coerceObservable(childrenAccessor(node)); |
| 1020 | return concat( |
| 1021 | observableOf([node]), |
| 1022 | children.pipe( |
| 1023 | take(1), |
| 1024 | tap(childNodes => { |
| 1025 | this._ariaSets.set(parentKey, [...(childNodes ?? [])]); |
| 1026 | for (const child of childNodes ?? []) { |
| 1027 | const childKey = this._getExpansionKey(child); |
| 1028 | this._parents.set(childKey, node); |
| 1029 | this._levels.set(childKey, level + 1); |
| 1030 | } |
| 1031 | }), |
| 1032 | switchMap(childNodes => { |
| 1033 | if (!childNodes) { |
| 1034 | return observableOf([]); |
| 1035 | } |
| 1036 | return this._flattenNestedNodesWithExpansion(childNodes, level + 1).pipe( |
| 1037 | map(nestedNodes => (this.isExpanded(node) ? nestedNodes : [])), |
| 1038 | ); |
| 1039 | }), |
| 1040 | ), |
| 1041 | ); |
| 1042 | }), |
| 1043 | reduce((results, children) => { |
| 1044 | results.push(...children); |
| 1045 | return results; |
| 1046 | }, [] as T[]), |
| 1047 | ); |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * Converts children for certain tree configurations. |
no test coverage detected