adds schema view and schema generating command

This commit is contained in:
2026-11-03 09:35:41 +01:00
parent cc41decccb
commit 600d4874d2
62 changed files with 4416 additions and 105 deletions
+21
View File
@@ -76,6 +76,10 @@ public enum Command: Equatable, Sendable {
case toggleGit
/// Esc with the Git view open and no overlay over it.
case closeGitView
/// ⌘D and the title bar's Schema button, in a Laravel app: opens or closes the full-screen Schema view.
case toggleSchemaView
/// Esc with nothing selected in the Schema view, and its Close button.
case closeSchemaView
/// ⌘1–⌘3 and the title-bar pane toggles: shows or hides one column.
case togglePane(Panel)
/// ⌘L
@@ -126,6 +130,23 @@ public enum Command: Equatable, Sendable {
/// ⌘C without a selection, outside a terminal: opens the Git view on its message field.
case focusCommitMessage
// MARK: Schema view
/// The Run button: `php artisan helder:schema`, then the dump is re-read.
case runSchemaDump
/// Closes the view and pastes the prompt that writes `HelderSchemaCommand.php` into the agent, unsent.
case generateSchemaCommand
case copySchemaPrompt
/// The detail panel's Pass on to Claude: `@schema:<table>` into the agent.
case passSchemaTable(String)
case copySchemaTableName(String)
/// The top bar's command path: closes the view and opens the command in the editor.
case openSchemaCommandFile
/// Esc with a table selected.
case clearSchemaSelection
/// Esc in the table search while it holds text.
case clearSchemaSearch
// MARK: Clean copy
/// The clean-copy popup's Copy and ⌘↩: copies its text and closes it.
+6 -1
View File
@@ -19,7 +19,7 @@ public struct HelderScene: Scene {
}
}
/// The menu bar. Shortcuts the key router owns (⌘F, ⌘G, ⌘1–⌘3, ⌘L, ⌘.) are shown here too; the router
/// The menu bar. Shortcuts the key router owns (⌘F, ⌘G, ⌘D, ⌘1–⌘3, ⌘L, ⌘.) are shown here too; the router
/// consumes them first, so the menu item fires only when a field or an overlay let the key through.
struct HelderCommands: Commands {
@FocusedValue(\.workspace) private var workspace
@@ -70,6 +70,11 @@ struct HelderCommands: Commands {
workspace?.perform(.toggleGit)
}
.keyboardShortcut("g", modifiers: .command)
Button(workspace?.layout.isSchemaViewOpen == true ? "Hide Schema" : "Show Schema") {
workspace?.perform(.toggleSchemaView)
}
.keyboardShortcut("d", modifiers: .command)
.disabled(workspace?.schema?.isLaravelApp != true)
Button(workspace?.layout.isVisible(.explorer) == false ? "Show Explorer" : "Hide Explorer") {
workspace?.perform(.togglePane(.explorer))
}
+41 -3
View File
@@ -59,11 +59,21 @@ public struct KeyContext: Equatable, Sendable {
public var gitViewOpen: Bool
/// The keyboard sits in the Git view's console input, where ⌘↵ must not commit.
public var inGitConsole: Bool
/// The project is a Laravel app, so ⌘D has a Schema view to toggle.
public var schemaAvailable: Bool
/// The full-screen Schema view covers the columns, like the Git view.
public var schemaViewOpen: Bool
/// A table is selected in the Schema view; Esc clears it first.
public var schemaHasSelection: Bool
/// The keyboard sits in the Schema table search and it holds text; Esc clears it before closing the view.
public var schemaSearchHasText: Bool
public init(hasProject: Bool = true, overlay: OverlayKind = .none, owner: KeyboardOwner = .workspace,
hasTextSelection: Bool = false, editorTextSelection: TextSelectionInfo? = nil,
hasEditorLineSelection: Bool = false, activePanel: Panel? = nil, focusZone: FocusZone = .neutral,
recentFileCount: Int = 0, searchSeed: String = "", gitViewOpen: Bool = false, inGitConsole: Bool = false) {
recentFileCount: Int = 0, searchSeed: String = "", gitViewOpen: Bool = false, inGitConsole: Bool = false,
schemaAvailable: Bool = false, schemaViewOpen: Bool = false, schemaHasSelection: Bool = false,
schemaSearchHasText: Bool = false) {
self.hasProject = hasProject
self.overlay = overlay
self.owner = owner
@@ -76,6 +86,10 @@ public struct KeyContext: Equatable, Sendable {
self.searchSeed = searchSeed
self.gitViewOpen = gitViewOpen
self.inGitConsole = inGitConsole
self.schemaAvailable = schemaAvailable
self.schemaViewOpen = schemaViewOpen
self.schemaHasSelection = schemaHasSelection
self.schemaSearchHasText = schemaSearchHasText
}
}
@@ -105,7 +119,8 @@ public enum KeyRoute: Equatable {
/// Maps a key press to a command. A key that a focused field or terminal needs is never taken:
/// arrows, ↵, `?`, ⌘A and ⌘C/⌘←/⌘→ go to the field; ⌘O, ⌘R and ⇧⌘N are left to the menu bar.
/// Esc closes the topmost layer: an overlay, then the Git view, else it reaches the terminal.
/// Esc closes the topmost layer: an overlay, then the Schema selection, search and view, then the Git view,
/// else it reaches the terminal.
public enum KeyRouter {
public static func route(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
if press.control || press.option { return .pass }
@@ -116,7 +131,9 @@ public enum KeyRouter {
case .diff(busy: true): return .pass
case .none:
if press.key == .escape {
return context.gitViewOpen && !press.command ? .perform(.closeGitView) : .pass
guard !press.command else { return .pass }
if context.schemaViewOpen { return schemaEscape(context) }
return context.gitViewOpen ? .perform(.closeGitView) : .pass
}
default: if press.key == .escape && !press.command { return .perform(.dismissOverlay) }
}
@@ -127,6 +144,7 @@ public enum KeyRouter {
case .other: return .pass
}
if context.schemaViewOpen { return schemaViewKey(press, context) }
if context.gitViewOpen { return gitViewKey(press, context) }
return press.command ? commandKey(press, context) : plainKey(press, context)
}
@@ -145,6 +163,25 @@ public enum KeyRouter {
}
}
private static func schemaEscape(_ context: KeyContext) -> KeyRoute {
if context.schemaHasSelection { return .perform(.clearSchemaSelection) }
if context.schemaSearchHasText { return .perform(.clearSchemaSearch) }
return .perform(.closeSchemaView)
}
/// Over the Schema view the columns' keys rest as over the Git view; ⌘↵ and ⌘C have nothing to act on.
private static func schemaViewKey(_ press: KeyPress, _ context: KeyContext) -> KeyRoute {
guard press.command else {
return press.key == .character("?") && context.owner == .workspace ? .perform(.showShortcuts) : .pass
}
if press.shift { return commandKey(press, context) }
switch press.key {
case .character("a"), .character("c"): return .pass
case let .character(c): return commandCharacter(c, context)
default: return .pass
}
}
private static func launcherKey(_ press: KeyPress) -> KeyRoute {
guard !press.shift else { return .pass }
switch press.key {
@@ -198,6 +235,7 @@ public enum KeyRouter {
case "m": return .perform(.cycleMode)
case "w": return .perform(.closeFileOrWindow)
case "g": return .perform(.toggleGit)
case "d": return context.schemaAvailable ? .perform(.toggleSchemaView) : .pass
case "1": return .perform(.togglePane(.explorer))
case "2": return .perform(.togglePane(.editor))
case "3": return .perform(.togglePane(.terminal))
+14 -4
View File
@@ -130,16 +130,15 @@ private struct PaneToggles: View {
}
}
/// Git ⌘G · Search ⌘F · Fluid ⌘L · Hidden ⌘., then `?`. Search is an action; the others toggle.
/// While Helder reads aloud, a Stop toggle leads the group; switching it off stops the reading.
/// Git ⌘G · Schema ⌘D · Search ⌘F · Fluid ⌘L · Hidden ⌘., then `?`. Search is an action; the others toggle.
/// Schema shows only in a Laravel app. While Helder reads aloud, a Stop toggle leads the group.
private struct TitleToolbar: View {
let model: WorkspaceModel
var body: some View {
let layout = model.layout
HStack(spacing: Metrics.toolbarIconGap) {
ButtonGroup(stop + [
git,
ButtonGroup(stop + [git] + schema + [
GroupItem("Search", keys: "⌘F", kind: .action,
tip: Text("Search the open file, the project and the file names.")) { model.perform(.showSearch(seed: "")) },
GroupItem("Fluid", keys: "⌘L", kind: .toggle(isOn: layout.fluid),
@@ -173,6 +172,17 @@ private struct TitleToolbar: View {
}
}
private var schema: [GroupItem] {
guard model.schema?.isLaravelApp == true else { return [] }
let open = model.layout.isSchemaViewOpen
let tip = open
? Tooltip.stated("Schema view: ", "open", ". Click to close it (⌘D).")
: Tooltip.stated("Schema view: ", "closed", ". Click to open the database diagram (⌘D).")
return [GroupItem("Schema", keys: "⌘D", kind: .toggle(isOn: open), tip: tip) {
model.perform(.toggleSchemaView)
}]
}
private var stop: [GroupItem] {
guard model.readAloud.isReading else { return [] }
return [GroupItem("Stop", kind: .toggle(isOn: true), tip: Tooltip.stated("Read aloud: ", "playing", ". Click to stop.")) {
+17 -11
View File
@@ -8,7 +8,8 @@ struct WindowBridge: NSViewRepresentable {
/// Passed as values so a project switch re-runs `updateNSView`, which renames the window and the app.
let title: String
let hasProject: Bool
let gitViewOpen: Bool
/// The Git or the Schema view covers the columns.
let fullScreenViewOpen: Bool
func makeCoordinator() -> WindowCoordinator {
WindowCoordinator(model: model)
@@ -22,7 +23,7 @@ struct WindowBridge: NSViewRepresentable {
func updateNSView(_ view: BridgeView, context: Context) {
context.coordinator.updateTitle(title, hasProject: hasProject)
context.coordinator.updateGitView(open: gitViewOpen)
context.coordinator.updateFullScreenView(open: fullScreenViewOpen)
context.coordinator.guardClose()
}
@@ -50,7 +51,7 @@ final class WindowCoordinator: NSObject {
/// Set once the unsaved prompt said yes, so the second close goes through.
private var closeApproved = false
private var isAskingToClose = false
private var gitViewOpen = false
private var fullScreenViewOpen = false
init(model: WorkspaceModel) {
self.model = model
@@ -106,11 +107,11 @@ final class WindowCoordinator: NSObject {
AppName.set(hasProject ? title : AppName.standard)
}
/// Opening the Git view takes the keyboard from the column behind it at once; its message field
/// takes focus a run loop later, so typing never lands in a covered terminal.
func updateGitView(open: Bool) {
defer { gitViewOpen = open }
guard open, !gitViewOpen, let window else { return }
/// Opening the Git or Schema view takes the keyboard from the column behind it at once; the Git
/// message field takes focus a run loop later, so typing never lands in a covered terminal.
func updateFullScreenView(open: Bool) {
defer { fullScreenViewOpen = open }
guard open, !fullScreenViewOpen, let window else { return }
window.makeFirstResponder(nil)
}
@@ -221,7 +222,7 @@ final class WindowCoordinator: NSObject {
private func handleMouseDown(_ event: NSEvent) {
guard let window, event.window === window, model.root != nil, !model.overlay.isPresented,
!model.layout.isGitViewOpen else { return }
!model.layout.isGitViewOpen, !model.layout.isSchemaViewOpen else { return }
let point = event.locationInWindow
let height = window.contentView?.bounds.height ?? window.frame.height
guard height - point.y > Metrics.titleBar, point.y > Metrics.statusBar else { return }
@@ -248,8 +249,9 @@ final class WindowCoordinator: NSObject {
var editorSelection: TextSelectionInfo?
var seed = ""
let gitViewOpen = model.layout.isGitViewOpen
let schemaViewOpen = model.layout.isSchemaViewOpen
if let text = responder as? NSTextView {
let column = gitViewOpen ? nil : column(of: text)
let column = gitViewOpen || schemaViewOpen ? nil : column(of: text)
owner = .text(in: column)
let range = text.selectedRange()
hasSelection = range.length > 0
@@ -285,7 +287,11 @@ final class WindowCoordinator: NSObject {
recentFileCount: editor?.history.count ?? 0,
searchSeed: seed,
gitViewOpen: gitViewOpen,
inGitConsole: responder is GitConsoleFieldEditor
inGitConsole: responder is GitConsoleFieldEditor,
schemaAvailable: model.schema?.isLaravelApp ?? false,
schemaViewOpen: schemaViewOpen,
schemaHasSelection: model.schema?.selected != nil,
schemaSearchHasText: responder is SchemaSearchFieldEditor && !(model.schema?.query.isEmpty ?? true)
)
}
+12 -4
View File
@@ -2,8 +2,8 @@ import AppKit
import HelderCore
import SwiftUI
/// The launcher without a project; with one, the title bar, three columns and status bar, then the Git view
/// over all of them, overlays above.
/// The launcher without a project; with one, the title bar, three columns and status bar, then the Git or
/// Schema view over all of them, overlays above.
struct WorkspaceView: View {
let model: WorkspaceModel
@@ -37,12 +37,19 @@ struct WorkspaceView: View {
.environment(\.pointerLayer, model.overlay.isPresented ? .workspace : .overlay)
}
}
.overlay {
if model.layout.isSchemaViewOpen, let schema = model.schema {
SchemaView(model: model, store: schema)
.environment(\.pointerLayer, model.overlay.isPresented ? .workspace : .overlay)
}
}
.overlay { OverlayHost(model: model) }
.overlay {
if model.overlay.current == .launcher { RecentProjectsOverlay(model: model).environment(\.pointerLayer, .overlay) }
}
.background(PointerRefresher(trigger: PointerRefresher.Trigger(
overlay: model.overlay.current, gitViewOpen: model.layout.isGitViewOpen, activePath: model.editor?.activePath,
overlay: model.overlay.current, gitViewOpen: model.layout.isGitViewOpen,
schemaViewOpen: model.layout.isSchemaViewOpen, activePath: model.editor?.activePath,
visibility: model.layout.visibility, scale: model.layout.textScale)))
.onAppear { model.layout.windowResized(width: proxy.size.width) }
.onChange(of: proxy.size.width) { _, width in model.layout.windowResized(width: width) }
@@ -147,12 +154,13 @@ private struct HiddenPaneFocusGuard: NSViewRepresentable {
}
}
/// Re-reads the pointer when what lies under a still mouse changes: an overlay, the Git view, the open file,
/// Re-reads the pointer when what lies under a still mouse changes: an overlay, the Git or Schema view, the open file,
/// a column shown or hidden.
private struct PointerRefresher: NSViewRepresentable {
struct Trigger: Equatable {
var overlay: Overlay
var gitViewOpen: Bool
var schemaViewOpen: Bool
var activePath: String?
var visibility: ColumnVisibility
var scale: Double
+1 -1
View File
@@ -14,7 +14,7 @@ public struct WorkspaceWindow: View {
.frame(minWidth: Metrics.minimumWindow.width, minHeight: Metrics.minimumWindow.height)
.background(Palette.editor)
.background(WindowBridge(model: model, title: model.title, hasProject: model.root != nil,
gitViewOpen: model.layout.isGitViewOpen))
fullScreenViewOpen: model.layout.isGitViewOpen || model.layout.isSchemaViewOpen))
.preferredColorScheme(.dark)
.focusedSceneValue(\.workspace, model)
.task { await model.start() }