import NorgKit import SwiftUI struct TreeNodesView: View { let nodes: [NorgNode] let onSetStatus: (Int, TaskStatus) -> Void @Environment(\.norgTheme) private var theme var body: some View { let siblingOrdinals = ordinals(forSiblings: nodes) VStack(alignment: .leading, spacing: theme.blockSpacing) { ForEach(Array(nodes.enumerated()), id: \.offset) { index, node in NodeView(node: node, ordinal: siblingOrdinals[index], onSetStatus: onSetStatus) .id(node.block.line) .frame(maxWidth: .infinity, alignment: .leading) } } } } private struct NodeView: View { let node: NorgNode let ordinal: Int? let onSetStatus: (Int, TaskStatus) -> Void @State private var expanded = true var body: some View { if !node.children.isEmpty { DisclosureGroup(isExpanded: $expanded) { TreeNodesView(nodes: node.children, onSetStatus: onSetStatus) } label: { label } } else if let body = node.block.body, !body.isEmpty { DisclosureGroup(isExpanded: $expanded) { FlatBlocksView(blocks: body, onSetStatus: onSetStatus) } label: { label } } else { label } } private var label: some View { BlockView(block: node.block, ordinal: ordinal, onSetStatus: onSetStatus) } }