Files
helder/Sources/HelderUI/SchemaView/SchemaView.swift
T

148 lines
5.4 KiB
Swift

import HelderCore
import SwiftUI
/// ⌘D: the full-screen Schema view over the title bar, the columns and the status bar.
struct SchemaView: View {
let model: WorkspaceModel
let store: SchemaStore
var body: some View {
VStack(spacing: 0) {
SchemaTopBar(model: model, store: store)
HStack(spacing: 0) {
switch store.body {
case .diagram:
if let schema = store.model {
SchemaTableList(store: store, schema: schema)
.frame(width: SchemaViewMetrics.tableList)
SchemaCanvas(model: model, store: store, schema: schema)
if let table = store.selectedTable {
SchemaDetailPanel(model: model, store: store, schema: schema, table: table)
.frame(width: SchemaViewMetrics.detailPanel)
}
}
case .noDump:
SchemaEmptyState(model: model, store: store)
case .commandMissing:
SchemaCommandMissing(model: model)
case .loading:
Color.clear
}
}
.frame(maxHeight: .infinity)
if store.isConsoleOpen && !store.lines.isEmpty && store.body != .commandMissing {
SchemaConsolePanel(store: store)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Palette.editor)
.contentShape(Rectangle())
}
}
/// The Schema view's fixed sizes, from the design handoff.
enum SchemaViewMetrics {
static let topBar: CGFloat = 44
static let topButton: CGFloat = 28
static let tableList: CGFloat = 240
static let searchRow: CGFloat = 44
static let listLabelRow: CGFloat = 34
static let listRow: CGFloat = 30
static let accentBar: CGFloat = 3
static let detailPanel: CGFloat = 320
static let detailHeader: CGFloat = 44
static let footerButton: CGFloat = 30
static let console: CGFloat = 150
static let consoleHeader: CGFloat = 32
static let primaryButton: CGFloat = 36
static let emptyStateWidth: CGFloat = 440
static let promptPreview: CGFloat = 240
static let zoomControl: CGFloat = 28
static let zoomButton: CGFloat = 30
static let zoomLabel: CGFloat = 52
static let canvasInset: CGFloat = 14
}
/// The amber primary of the empty and command-missing states: 36pt, Sans 600 13, amber-deep on hover.
struct SchemaPrimaryButton: View {
let label: String
var icon: GitIcon?
var height: CGFloat = SchemaViewMetrics.primaryButton
var role = Typography.gitCommitButton
var padding: CGFloat = 16
let action: () -> Void
@State private var isHovered = false
var body: some View {
Button(action: action) {
HStack(spacing: 7) {
if let icon { GitIconView(icon: icon, size: 14) }
Text(label).typeRole(role).lineLimit(1)
}
.foregroundStyle(Palette.badgeText)
.padding(.horizontal, padding)
.frame(height: height)
.background(isHovered ? Palette.amberDeep : Palette.amber, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.fixedSize()
.pointerHand()
.tracksHover($isHovered)
}
}
/// The outline button of the detail footer and the command-missing state: text-5 border, raised fill on hover.
struct SchemaOutlineButton: View {
let label: String
var height: CGFloat = SchemaViewMetrics.footerButton
var fills = false
var padding: CGFloat = 16
let action: () -> Void
@State private var isHovered = false
var body: some View {
Button(action: action) {
Text(label)
.typeRole(Typography.button)
.lineLimit(1)
.foregroundStyle(isHovered ? Palette.text1 : Palette.text3)
.padding(.horizontal, padding)
.frame(maxWidth: fills ? .infinity : nil)
.frame(height: height)
.background(isHovered ? Palette.raised : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall)
.strokeBorder(isHovered ? Palette.text4 : Palette.text5, lineWidth: Metrics.hairline))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.fixedSize(horizontal: !fills, vertical: false)
.pointerHand()
.tracksHover($isHovered)
}
}
/// A borderless icon button: text-muted, text-1 on hover.
struct SchemaIconButton: View {
let icon: GitIcon
let tip: String
let action: () -> Void
@State private var isHovered = false
var body: some View {
Button(action: action) {
GitIconView(icon: icon, size: 14)
.foregroundStyle(isHovered ? Palette.text1 : Palette.textMuted)
.padding(4)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.pointerHand()
.tracksHover($isHovered)
.tip(tip, edge: .trailing)
}
}
/// The table search's field editor; the key router tells it apart from the other fields by its class.
final class SchemaSearchFieldEditor: PointerBoundTextView {}