From 657aa83a5ca24dc35572c040df64a0abb85e8612 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Mon, 15 Jun 2026 14:35:36 +0200 Subject: Initial extraction from Norganize --- Sources/NorgUI/Views/TreeNodesView.swift | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Sources/NorgUI/Views/TreeNodesView.swift (limited to 'Sources/NorgUI/Views/TreeNodesView.swift') diff --git a/Sources/NorgUI/Views/TreeNodesView.swift b/Sources/NorgUI/Views/TreeNodesView.swift new file mode 100644 index 0000000..a509138 --- /dev/null +++ b/Sources/NorgUI/Views/TreeNodesView.swift @@ -0,0 +1,48 @@ +import NorgKit +import SwiftUI + +struct TreeNodesView: View { + let nodes: [NorgNode] + let onSetStatus: (Int, TaskStatus) -> Void + + var body: some View { + let siblingOrdinals = ordinals(forSiblings: nodes) + VStack(alignment: .leading, spacing: 10) { + 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) + } +} -- cgit