(layoutState: LayoutTreeState, action: LayoutTreeDeleteNodeAction)
| 352 | } |
| 353 | |
| 354 | export function deleteNode(layoutState: LayoutTreeState, action: LayoutTreeDeleteNodeAction) { |
| 355 | if (!action?.nodeId) { |
| 356 | console.error("no delete node action provided"); |
| 357 | return; |
| 358 | } |
| 359 | if (!layoutState.rootNode) { |
| 360 | console.error("no root node"); |
| 361 | return; |
| 362 | } |
| 363 | if (layoutState.rootNode.id === action.nodeId) { |
| 364 | layoutState.rootNode = undefined; |
| 365 | } else { |
| 366 | const parent = findParent(layoutState.rootNode, action.nodeId); |
| 367 | if (parent) { |
| 368 | const node = parent.children.find((child) => child.id === action.nodeId); |
| 369 | removeChild(parent, node); |
| 370 | if (layoutState.focusedNodeId === node.id) { |
| 371 | layoutState.focusedNodeId = undefined; |
| 372 | } |
| 373 | } else { |
| 374 | console.error("unable to delete node, not found in tree"); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | export function resizeNode(layoutState: LayoutTreeState, action: LayoutTreeResizeNodeAction) { |
| 380 | if (!action.resizeOperations) { |
no test coverage detected