import HelderCore import SwiftUI /// The 240pt list left of the canvas: the table search, `[ tables ] N`, and one row per matching table. struct SchemaTableList: View { let store: SchemaStore let schema: SchemaModel var body: some View { let highlight = store.highlight VStack(alignment: .leading, spacing: 0) { HStack(spacing: 8) { GitIconView(icon: .search, size: 14).foregroundStyle(Palette.textMuted) ConsoleInputField( text: Binding(get: { store.query }, set: { store.query = $0 }), placeholder: "Find a table", role: Typography.gitPath, makeEditor: { SchemaSearchFieldEditor() }, onSubmit: { store.centreFirstMatch() } ) .frame(maxWidth: .infinity) .frame(height: 20) } .padding(.leading, 14) .padding(.trailing, 12) .frame(height: SchemaViewMetrics.searchRow) .hairline(.bottom) Text(SchemaSearch.listLabel(schema, query: store.query)) .typeRole(Typography.panelLabel) .foregroundStyle(Palette.text4) .lineLimit(1) .padding(.horizontal, 14) .frame(height: SchemaViewMetrics.listLabelRow) ScrollView { LazyVStack(spacing: 0) { ForEach(store.listedTables, id: \.name) { table in SchemaTableRow(table: table, isSelected: store.selected == table.name, isFocus: highlight?.focus == table.name, isRelated: highlight.map { $0.linesRecede && $0.relatedTables.contains(table.name) } ?? false, onHover: { inside in hover(table.name, inside) }, onClick: { store.centre(table.name) }) } } .padding(.bottom, 12) } } .background(Palette.panel) .hairline(.trailing) } private func hover(_ name: String, _ inside: Bool) { if inside { store.hover(name) } else if store.hovered == name { store.hover(nil) } } } /// One table: its name and row count, the amber bar while selected. private struct SchemaTableRow: View { let table: SchemaTable let isSelected: Bool let isFocus: Bool let isRelated: Bool let onHover: (Bool) -> Void let onClick: () -> Void @State private var isHovered = false var body: some View { Button(action: onClick) { HStack(spacing: 8) { Text(table.name) .typeRole(Typography.path) .foregroundStyle(isSelected || isFocus || isHovered ? Palette.text1 : isRelated ? Palette.text2 : Palette.text3) .lineLimit(1) .truncationMode(.tail) .frame(maxWidth: .infinity, alignment: .leading) Text(table.rowsLabel).typeRole(Typography.meta).foregroundStyle(Palette.text4).lineLimit(1).fixedSize() } .padding(.leading, 11) .padding(.trailing, 14) .frame(height: SchemaViewMetrics.listRow) .background(background) .overlay(alignment: .leading) { Rectangle().fill(isSelected ? Palette.amber : .clear).frame(width: SchemaViewMetrics.accentBar) } .contentShape(Rectangle()) } .buttonStyle(.plain) .pointerHand() .onHover { inside in isHovered = inside onHover(inside) } .animation(Metrics.colorTransition, value: isHovered) } private var background: Color { if isSelected { return Palette.amberTint } return isFocus || isHovered ? Palette.gitRowHover : .clear } }