(layoutState: LayoutTreeState, action: LayoutTreeInsertNodeAction)
| 277 | } |
| 278 | |
| 279 | export function insertNode(layoutState: LayoutTreeState, action: LayoutTreeInsertNodeAction) { |
| 280 | if (!action?.node) { |
| 281 | console.error("insertNode cannot run, no insert node action provided"); |
| 282 | return; |
| 283 | } |
| 284 | if (!layoutState.rootNode) { |
| 285 | layoutState.rootNode = action.node; |
| 286 | } else { |
| 287 | const insertLoc = findNextInsertLocation(layoutState.rootNode, DEFAULT_MAX_CHILDREN); |
| 288 | addChildAt(insertLoc.node, insertLoc.index, action.node); |
| 289 | if (action.magnified) { |
| 290 | layoutState.magnifiedNodeId = action.node.id; |
| 291 | layoutState.focusedNodeId = action.node.id; |
| 292 | } |
| 293 | } |
| 294 | if (action.focused) { |
| 295 | layoutState.focusedNodeId = action.node.id; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | export function insertNodeAtIndex(layoutState: LayoutTreeState, action: LayoutTreeInsertNodeAtIndexAction) { |
| 300 | if (!action?.node || !action?.indexArr) { |
no test coverage detected