removeNode method
Implementation
MindMap removeNode(String nodeId) {
assertValidId(nodeId);
if (nodeId == rootNodeId) {
throw Exception('Cannot remove root node');
}
final node = nodes[nodeId]!;
Map<String, Node> newNodes = Map.of(nodes)..remove(nodeId);
if (node.parentId != rootNodeId) {
final parentNode = nodes[node.parentId]!.copyWith(
children:
nodes[node.parentId]!.children
.where((child) => child.id != nodeId)
.toList(),
);
newNodes = _updateWithAncestors(newNodes, parentNode);
}
return _copyWith(
nodes: newNodes,
nodeMetas: Map.of(nodeMetas)..remove(nodeId),
);
}