Repository Public
1import SwiftUI2import SheetCore3import SheetUI45/// A studio: grouped list of tools on the left, the selected tool (form → run → results) in the centre.6public struct ToolStudioView: View {7 @Bindable var model: ToolSessionModel8 let session: WorkbookSession910 public init(model: ToolSessionModel, session: WorkbookSession) { self.model = model; self.session = session }1112 public var body: some View {13 HStack(spacing: 0) {14 list15 Rectangle().fill(ORIX.Palette.hairline).frame(width: 1)16 detail17 }18 .background(ORIX.Palette.canvas)19 .accessibilityIdentifier("studio-\(model.studio)")20 }2122 private var list: some View {23 ScrollView(.vertical) {24 VStack(alignment: .leading, spacing: 2) {25 ForEach(model.groups, id: \.name) { group in26 Text(group.name.uppercased())27 .font(.system(size: 10.5, weight: .semibold)).kerning(0.6)28 .foregroundStyle(ORIX.Palette.textTertiary)29 .padding(.horizontal, 10).padding(.top, 12).padding(.bottom, 3)30 .accessibilityAddTraits(.isHeader)31 ForEach(group.tools) { tool in ToolRow(tool: tool, selected: model.selectedID == tool.id) { model.selectedID = tool.id } }32 }33 }34 .padding(.horizontal, 6).padding(.bottom, 12)35 }36 .frame(width: 228)37 .background(ORIX.Palette.surface)38 .accessibilityLabel(L("Tools"))39 }4041 @ViewBuilder private var detail: some View {42 if let tool = model.selected {43 ScrollView(.vertical) {44 ToolPanel(tool: tool, model: model, session: session)45 .id(tool.id)46 .padding(ORIX.Space.lg)47 .frame(maxWidth: 980, alignment: .leading)48 .frame(maxWidth: .infinity, alignment: .leading)49 }50 } else {51 EmptyStateView(systemImage: "square.grid.2x2", title: L("No tool selected"), message: L("Choose a tool in the list."))52 }53 }54}5556private struct ToolRow: View {57 let tool: ToolDescriptor58 let selected: Bool59 let action: () -> Void60 @State private var hover = false6162 var body: some View {63 Button(action: action) {64 HStack(spacing: 8) {65 Image(systemName: tool.systemImage)66 .font(.system(size: 12, weight: .medium))67 .foregroundStyle(selected ? ORIX.Palette.accent : ORIX.Palette.textSecondary)68 .frame(width: 18)69 .accessibilityHidden(true)70 Text(tool.title)71 .font(.system(size: 12.5, weight: selected ? .semibold : .regular))72 .foregroundStyle(ORIX.Palette.textPrimary)73 .lineLimit(1)74 Spacer(minLength: 0)75 }76 .padding(.horizontal, 8).padding(.vertical, 5)77 .background(RoundedRectangle(cornerRadius: ORIX.Radius.chip).fill(selected ? ORIX.Palette.accent.opacity(0.14) : (hover ? ORIX.Palette.surfaceRaised : .clear)))78 .contentShape(Rectangle())79 }80 .buttonStyle(.plain)81 .onHover { hover = $0 }82 .help(tool.summary)83 .accessibilityLabel(tool.title)84 .accessibilityHint(tool.summary)85 .accessibilityAddTraits(selected ? .isSelected : [])86 .accessibilityIdentifier("tool-\(tool.id)")87 }88}8990/// Narrow host for the inspector: a tool chooser on top, the compact panel below.91public struct ToolInspectorView: View {92 @Bindable var model: ToolSessionModel93 let session: WorkbookSession94 let title: String95 /// Studio pane showing the same tools with more room (adds an "Open in Studio" button).96 var studioPane: String?9798 public init(model: ToolSessionModel, session: WorkbookSession, title: String, studioPane: String? = nil) {99 self.model = model; self.session = session; self.title = title; self.studioPane = studioPane100 }101102 public var body: some View {103 VStack(spacing: 0) {104 VStack(alignment: .leading, spacing: 6) {105 HStack {106 SectionHeader(title)107 if let studioPane {108 Button { session.studioPane = studioPane } label: { Image(systemName: "arrow.up.left.and.arrow.down.right") }109 .buttonStyle(.borderless).controlSize(.small)110 .help(L("Open in Studio (more room for charts and tables)"))111 .accessibilityLabel(L("Open in Studio (more room for charts and tables)"))112 .accessibilityIdentifier("inspector-\(model.studio)-expand")113 }114 }115 Picker(title, selection: $model.selectedID) {116 ForEach(model.groups, id: \.name) { group in117 Section(group.name) { ForEach(group.tools) { t in Label(t.title, systemImage: t.systemImage).tag(t.id) } }118 }119 }120 .labelsHidden()121 .accessibilityLabel(title)122 .accessibilityIdentifier("inspector-\(model.studio)-tool")123 }124 .padding(.horizontal, ORIX.Space.sm).padding(.vertical, ORIX.Space.xs)125 Rectangle().fill(ORIX.Palette.hairline).frame(height: 1)126 if let tool = model.selected {127 ScrollView(.vertical) {128 ToolPanel(tool: tool, model: model, session: session)129 .id(tool.id)130 .padding(ORIX.Space.sm)131 .frame(maxWidth: .infinity, alignment: .leading)132 }133 .environment(\.compactForm, true)134 }135 }136 .accessibilityIdentifier("inspector-\(model.studio)")137 }138}139