Files
museion/Museion/PostsPaneView.swift
T

186 lines
6.3 KiB
Swift

//
// PostsPaneView.swift
// Museion
//
// #17 (S1.1): the Posts pane — library column mirroring the Home's
// projects/ (and archive/) on disk. #18: lifecycle — New Post draft, ⌘S first-write/save, rename,
// trash. #19: the TextKit2 editor core (PostEditorView) replaces the stub;
// mentor column (#14).
// #108 (variant B, ref/prototypes/wf104-library-ui-prototype.html): sections
// per project (serif-15 head + mono count), Pass-State groups inside, and
// a 2px accent edge bar on the selected row.
// #193: the split-out files — the library column + its sheets + the
// launch focus rider PostsLibraryColumn.swift, the shared
// LibraryPostRow.swift.
//
import SwiftUI
/// The Posts destination: the workspace's full four-column layout
/// library 232 | editor ≥420 | mentor 356 (design contract grid).
struct PostsPaneView: View {
let home: URL
/// #14: the app-scoped mentor model + the gate's winning binary (no re-probe).
var mentor: MentorSessionModel
var mentorBinaryPath: String?
/// #18: app-scoped Posts state (watcher + lifecycle ops).
var model: PostsModel
/// Width budget after the rail — drives column collapse (export media queries:
/// library hides ≤1100, mentor hides ≤920).
var availableWidth: CGFloat
/// #137 (S4): the mentor pane's missing-key Settings link (default nil
/// keeps previews compiling).
var onOpenSettings: (() -> Void)?
@Environment(AppGateState.self) private var gate
/// #33 (S6.1): the Micro.blog publish ask over the open piece.
@State private var showingPublish = false
private var showsLibrary: Bool {
availableWidth >= 1100 - DesignTokens.railWidth
}
private var showsMentor: Bool {
availableWidth >= 920 - DesignTokens.railWidth
}
var body: some View {
Group {
if gate.isFocused {
// #21: columns recede; the editor surface + centered measure on
// the workspace background is all that remains. The mentor
// returns by right-edge hover (overlay below) — only while the
// width budget grants it (#17's collapse verdict stands here too).
// #162: hover reveal suppressed while a Cold Turkey block holds
// (editor-only — passes and chat unreachable, #158 settle 5);
// the Cold Turkey chrome mounts on this branch, so a lock
// transition never restructures the editor column itself
// (typing-continuity AC — the #87 remount hazard).
ZStack(alignment: .trailing) {
editorColumn
if showsMentor, !gate.writingLock.isLocked {
FocusOverlayPanel(edge: .trailing, panelWidth: DesignTokens.mentorWidth) {
mentorColumn
}
}
}
// #162: the Cold Turkey seat (arm-bar | readout | note,
// bottom-center) + the quiet corner dot — overlays only,
// never wrappers around editorColumn.
.overlay(alignment: .bottom) { ColdTurkeySeat() }
.overlay(alignment: .bottomTrailing) { ColdTurkeyDot(model: model) }
.onDisappear {
// Leaving focus mid-arm drops the bar (no stale bar on
// the next focus entry).
gate.writingLock.showsArmBar = false
}
} else {
HStack(spacing: 0) {
if showsLibrary {
PostsLibraryColumn(home: home, model: model)
paneBorder
}
editorColumn
if showsMentor {
paneBorder
mentorColumn
}
}
}
}
// #33 (S6.1): the publish ask rides the pane (not the library
// column) — it targets the open piece.
.sheet(isPresented: $showingPublish) {
MicropubPublishSheet(posts: model)
}
}
private var paneBorder: some View {
Rectangle()
.fill(DesignTokens.border)
.frame(width: 1)
}
// MARK: Editor column (#19: TextKit2 editor core)
private var editorColumn: some View {
VStack(spacing: 0) {
if let draft = model.draft {
PostEditorView(
session: nil,
draftText: draft.text,
draftEdited: { model.updateDraft($0) },
draftSave: {
model.saveDraft()
},
outline: draft.type == .outline,
)
// #109: identity = "draft" + mountID — remounts per staged
// draft (the outliner seeds once per mount).
.id("draft-\(draft.mountID.uuidString)")
} else if let external = model.externalSession {
// #92: the guest slot — an external file in the editor column;
// one at a time, transient per launch.
PostEditorView(session: external, draftText: nil)
.id(external.fileURL?.absoluteString ?? "external")
} else if let session = model.session, session.postID == model.selectedPostID {
// #109: outline routing — the scan's type when the list knows the
// piece, plus the just-saved-draft afterglow (the posts list lags
// one rescan; without the flag the fresh outline flashes prose).
// #111 (S7): the guard's Prose answer overrides to prose (same
// lag window); the guard hold never reaches here (no session).
PostEditorView(
session: session,
draftText: nil,
outline: session.postID != model.proseOverridePostID
&& (model.lastDraftWasOutline
|| model.posts.first(where: { $0.id == session.postID })?.type == .outline),
publish: { showingPublish = true },
)
.id(session.postID ?? "post")
} else if model.outlineGuardPieceID != nil {
// #111 (S7): the guard ask is up — empty editor, nothing
// editable until the choice lands.
VStack(spacing: 10) {
Image(systemName: "list.bullet")
.font(.largeTitle)
.foregroundStyle(DesignTokens.muted)
Text("This outline has lines the outliner can't show.")
.font(.callout)
.foregroundStyle(DesignTokens.muted)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
VStack(spacing: 10) {
Image(systemName: "square.and.pencil")
.font(.largeTitle)
.foregroundStyle(DesignTokens.muted)
Text("Select a post, or start a new one.")
.font(.callout)
.foregroundStyle(DesignTokens.muted)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
if let error = model.lastError {
Text(error)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.accent)
.padding(.vertical, 6)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(DesignTokens.surface)
}
private var mentorColumn: some View {
MentorPaneView(
model: mentor,
binaryPath: mentorBinaryPath,
gate: gate,
posts: model,
home: home,
onOpenSettings: onOpenSettings,
)
.frame(width: DesignTokens.mentorWidth)
}
}