convertToBlocksOnly method

bool convertToBlocksOnly(
  1. String nodeId
)

Convert a fully expanded node to blocks-only mode.

Collapses the node (toggle), then re-expands only its non-primitive children without edges. This is an atomic operation — the caller only needs a single re-layout afterwards.

Returns true if the conversion happened.

Implementation

bool convertToBlocksOnly(String nodeId) {
  final node = nodeMap[nodeId];
  if (node == null) {
    return false;
  }

  // Must be fully expanded (not partially expanded).
  if (!node.isExpanded) {
    return false;
  }

  // Pre-check: at least one child must be non-primitive (has its own
  // children or hiddenChildren).  Without this, we'd collapse the node
  // and have nothing to show in blocks-only mode.
  final hasNonPrimitive = node.children.any(
    (c) =>
        c.children.isNotEmpty ||
        (c.hiddenChildren != null && c.hiddenChildren!.isNotEmpty),
  );
  if (!hasNonPrimitive) {
    return false;
  }

  // Toggle collapses it (children → hiddenChildren).
  node.toggle();

  // Now expand non-primitives in blocks-only mode.
  final result = expandNonPrimitives(nodeId, includeEdges: false);
  return result;
}