( expanded: readonly string[], key: string, )
| 307 | * @returns New expanded set and whether it's now expanded |
| 308 | */ |
| 309 | export function toggleExpanded( |
| 310 | expanded: readonly string[], |
| 311 | key: string, |
| 312 | ): { expanded: readonly string[]; isExpanded: boolean } { |
| 313 | const isCurrentlyExpanded = expanded.includes(key); |
| 314 | |
| 315 | if (isCurrentlyExpanded) { |
| 316 | return { |
| 317 | expanded: collapseNode(expanded, key), |
| 318 | isExpanded: false, |
| 319 | }; |
| 320 | } |
| 321 | |
| 322 | return { |
| 323 | expanded: expandNode(expanded, key), |
| 324 | isExpanded: true, |
| 325 | }; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Expand all siblings of a node (nodes at the same depth with same parent). |
no test coverage detected