(scopeRef: ScopeRef)
| 1097 | } |
| 1098 | |
| 1099 | removeTreeNode(scopeRef: ScopeRef): void { |
| 1100 | // never remove the root |
| 1101 | if (scopeRef === null) { |
| 1102 | return; |
| 1103 | } |
| 1104 | let node = this.fastMap.get(scopeRef); |
| 1105 | if (!node) { |
| 1106 | return; |
| 1107 | } |
| 1108 | let parentNode = node.parent; |
| 1109 | // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing |
| 1110 | // if we are, then replace the siblings restore with the restore from the scope we're removing |
| 1111 | for (let current of this.traverse()) { |
| 1112 | if ( |
| 1113 | current !== node && |
| 1114 | node.nodeToRestore && |
| 1115 | current.nodeToRestore && |
| 1116 | node.scopeRef && |
| 1117 | node.scopeRef.current && |
| 1118 | isElementInScope(current.nodeToRestore, node.scopeRef.current) |
| 1119 | ) { |
| 1120 | current.nodeToRestore = node.nodeToRestore; |
| 1121 | } |
| 1122 | } |
| 1123 | let children = node.children; |
| 1124 | if (parentNode) { |
| 1125 | parentNode.removeChild(node); |
| 1126 | if (children.size > 0) { |
| 1127 | children.forEach(child => parentNode && parentNode.addChild(child)); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | this.fastMap.delete(node.scopeRef); |
| 1132 | } |
| 1133 | |
| 1134 | // Pre Order Depth First |
| 1135 | *traverse(node: TreeNode = this.root): Generator<TreeNode> { |
no test coverage detected