// // WorkspaceView.swift // Museion // // #17 (S1.1): the workspace shell — nav rail + panes, built from the design // contract's grid geometry (ref/Web-Prototype/museion-workspace.html): // rail 56 | library 232 | editor min 420 | mentor 356. // import SwiftUI /// The post-gate main surface. Posts shows the full four-column workspace; /// Sessions/Learnings/Settings fill the space after the rail until their /// tickets land (#28/#26; Settings is real here). struct WorkspaceView: View { @Environment(AppGateState.self) private var gate @State private var selection: Pane = .posts enum Pane: Hashable { case posts case sessions case learnings case settings } var body: some View { GeometryReader { geo in Group { if gate.isFocused { // #21: the rail recedes; the pane takes the full width. The // measure stays centered — revealed panes float, never push. paneContent(geo) } else { HStack(spacing: 0) { navRail paneBorder paneContent(geo) } } } // #91: drag a markdown file onto the window — same guest slot as // File ▸ Open… Non-markdown drops are refused. .dropDestination(for: URL.self) { urls, _ in guard let url = urls.first(where: PostStore.isMarkdown) else { return false } gate.posts.openExternal(url) selection = .posts return true } // #21: left-edge hover slides rail+library back in as an overlay. // Library only while the window width allows it (#17 verdict stands: // a collapsed pane is not summoned by focus). .overlay { if gate.isFocused { // #17 verdict: the library reveal honors the width collapse. let showsLibrary = geo.size.width >= 1100 FocusOverlayPanel(edge: .leading, panelWidth: leftRevealWidth(showsLibrary)) { HStack(spacing: 0) { navRail paneBorder if showsLibrary { PostsLibraryColumn(home: gate.museionHome, model: gate.posts) } } } } } .background(DesignTokens.background) // #94: the ONE Origin ask per import batch. Dismissal without an // answer (Esc/Cancel) drops the batch. .sheet(isPresented: originAskBinding) { OriginAskSheet(count: gate.posts.pendingImportURLs?.count ?? 0) { origin in gate.posts.importFiles(origin: origin, home: gate.museionHome) } } } // Collapsed floor: rail 56 + editor placeholder (export ≤920 layout). .frame(minWidth: 480, minHeight: 320) // #92/#94: the editor column lives in Posts — a guest buffer or an // import's opened post surfaces there, whatever pane was showing. .onChange(of: gate.posts.externalSession != nil) { _, isUp in if isUp { selection = .posts } } .onChange(of: gate.posts.selectedPostID) { _, _ in if gate.posts.session != nil { selection = .posts } } } /// #94: the ask presents while a batch is staged. private var originAskBinding: Binding { Binding( get: { gate.posts.pendingImportURLs != nil }, set: { if !$0 { gate.posts.cancelImport() } }, ) } @ViewBuilder private func paneContent(_ geo: GeometryProxy) -> some View { @Bindable var gate = gate switch selection { case .posts: // #14: mentor column hands in the app-scoped model + gate's winner. // Column collapse mirrors the export's media queries (library ≤1100, // mentor ≤920) as macOS pane collapse per the PRD. PostsPaneView( home: gate.museionHome, mentor: gate.mentor, mentorBinaryPath: gate.gateModel.currentBinaryPath, model: gate.posts, availableWidth: geo.size.width - DesignTokens.railWidth, ) case .sessions: PlaceholderPane(title: "Sessions", detail: "Session lifecycle arrives with S2.3 (#28).") case .learnings: PlaceholderPane(title: "Learnings", detail: "Promote, consult, and decay arrive with S4 (#26, #27).") case .settings: SettingsPaneView(home: $gate.museionHome) } } /// The left reveal panel's width: rail + border (+ library when the /// unfocused width verdict grants it). private func leftRevealWidth(_ showsLibrary: Bool) -> CGFloat { DesignTokens.railWidth + 1 + (showsLibrary ? DesignTokens.libraryWidth : 0) } /// 1px contract border between rail and pane (`.rail { border-right }`). private var paneBorder: some View { Rectangle() .fill(DesignTokens.border) .frame(width: 1) } // MARK: Nav rail private var navRail: some View { VStack(spacing: 8) { RailButton(pane: .posts, selection: $selection, label: "Posts", systemImage: "doc.text") RailButton(pane: .sessions, selection: $selection, label: "Sessions", systemImage: "bubble.left") RailButton(pane: .learnings, selection: $selection, label: "Learnings", systemImage: "cube") Spacer() RailButton(pane: .settings, selection: $selection, label: "Settings", systemImage: "gearshape") } .padding(.horizontal, 4) .padding(.vertical, 8) .frame(width: DesignTokens.railWidth) .frame(maxHeight: .infinity) } } /// #94: the ONE Origin ask per import batch — writer (default) / ai, with the /// immutability line (CONTEXT.md: Origin). Answering runs the batch. private struct OriginAskSheet: View { let count: Int let answer: (Post.Origin) -> Void @Environment(\.dismiss) private var dismiss @State private var origin: Post.Origin = .writer var body: some View { VStack(alignment: .leading, spacing: 12) { Text("Who wrote this?") .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Text(count == 1 ? "Importing 1 file as a Post — the original is untouched." : "Importing \(count) files as Posts — the originals are untouched.") .font(.callout) .foregroundStyle(DesignTokens.muted) Picker("Origin", selection: $origin) { Text("I wrote it (writer)").tag(Post.Origin.writer) Text("AI-assisted (ai)").tag(Post.Origin.ai) } .pickerStyle(.radioGroup) Text("Origin is stamped once and never asked again — it decides whether the draft's stats can measure you.") .font(.caption) .foregroundStyle(DesignTokens.muted) HStack { Spacer() Button("Cancel", role: .cancel) { dismiss() } .keyboardShortcut(.cancelAction) Button("Import") { answer(origin) dismiss() } .keyboardShortcut(.defaultAction) } } .padding(20) .frame(width: 380) } } /// Rail button per the export: 44×44 muted icon, hover wash, and the current /// pane raised as a surface card with a 2px selection bar on the rail's edge. private struct RailButton: View { let pane: WorkspaceView.Pane @Binding var selection: WorkspaceView.Pane let label: String let systemImage: String @State private var hover = false var body: some View { let selected = selection == pane Button { selection = pane } label: { Image(systemName: systemImage) .frame(width: 44, height: 44) } .buttonStyle(.plain) .foregroundStyle(selected ? DesignTokens.foreground : DesignTokens.muted) .background { if selected || hover { RoundedRectangle(cornerRadius: DesignTokens.radius) .fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06)) .overlay( RoundedRectangle(cornerRadius: DesignTokens.radius) .strokeBorder(selected ? DesignTokens.border : .clear), ) } } .overlay(alignment: .leading) { // Selection bar (`.rail-btn[aria-current]::before`); offset to sit // on the rail's leading edge like the export's negative inset. if selected { Rectangle() .fill(DesignTokens.foreground) .frame(width: 2, height: 22) .offset(x: -6) } } .onHover { hover = $0 } .help(label) .accessibilityLabel(label) } } /// Pane-head row per the export (52pt, serif 15 semibold title, bottom border). /// Trailing slot carries #18's New Post button (export `.pane-head .icon-btn`). struct PaneHeader: View { let title: String @ViewBuilder var trailing: () -> Trailing init(title: String, @ViewBuilder trailing: @escaping () -> Trailing = { EmptyView() }) { self.title = title self.trailing = trailing } var body: some View { VStack(spacing: 0) { HStack { Text(title) .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Spacer() trailing() } .padding(.horizontal, 14) .frame(minHeight: 52) Rectangle() .fill(DesignTokens.border) .frame(height: 1) } } } /// Navigation-target placeholder (#17 AC: panes exist as targets; real content /// arrives with their tickets — honest copy, no fake controls). struct PlaceholderPane: View { let title: String let detail: String var body: some View { VStack(spacing: 10) { Image(systemName: "hourglass") .font(.largeTitle) .foregroundStyle(DesignTokens.muted) Text(title) .font(.system(size: 16, weight: .semibold, design: DesignTokens.serif)) Text(detail) .font(.callout) .foregroundStyle(DesignTokens.muted) } .frame(maxWidth: .infinity, maxHeight: .infinity) } }