expandNonPrimitivesPartial method

bool expandNonPrimitivesPartial()

Partially expand this node to reveal non-primitive children (blocks-only).

Marks non-primitive children and their connecting edges as visible without doing a full expand. Returns true if new children were revealed. This mirrors ElkNode behavior but operates on the LayoutNode tree.

Non-primitive nodes are those that have their own children (submodules), whereas primitive nodes are leaf gates/operators.

Implementation

bool expandNonPrimitivesPartial() {
  if (hiddenChildren == null || hiddenChildren!.isEmpty) {
    return false;
  }

  // Find non-primitive hidden children (have children themselves)
  final nonPrimitiveIds = <String>{};
  for (final child in hiddenChildren!) {
    if (child.children.isNotEmpty || child.isExpandable) {
      nonPrimitiveIds.add(child.id);
    }
  }

  if (nonPrimitiveIds.isEmpty) {
    return false;
  }

  // Check if already visible (idempotent)
  final existingChildren = partialChildIds ?? {};
  if (existingChildren.containsAll(nonPrimitiveIds)) {
    return false; // Already visible
  }

  // Additive: merge into existing partial set
  partialChildIds = {...existingChildren, ...nonPrimitiveIds};
  // Also mark edges to these children as visible (same as blocks-only)
  // For now, reveal all edges (could be optimized to show only edges
  // connecting to revealed children)
  partialHyperedgeIds ??= {};

  return true;
}