// // WorkspaceViewSheets.swift // Museion // // #193: the house ask sheets, moved from WorkspaceView.swift // (file-length ceiling) — OriginAskSheet (#94), OutlineGuardSheet // (#111), ConvertSheet (#114), NewProjectSheet (#108) — code // unchanged (private → internal: WorkspaceView presents them // cross-file now). // import SwiftUI /// #94: the ONE Origin ask per import batch — writer (default) / ai, with the /// immutability line (CONTEXT.md: Origin). Answering runs the batch. 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) } } /// #111 (S7): the mixed-content outline guard ask. The piece has prose /// lines the outliner can't show — opening it as an outline would drop /// them on the next save. Prose = nothing drops; Outline = the explicit /// choice the ruling requires. struct OutlineGuardSheet: View { let openInProse: () -> Void let openAsOutline: () -> Void var body: some View { VStack(alignment: .leading, spacing: 12) { Text("Open as outline or prose?") .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Text( "This outline has paragraph lines between its bullets. The outliner can't show them — opening as an outline " + "drops them on the next save. Prose mode shows everything.", ) .font(.callout) .foregroundStyle(DesignTokens.muted) Text("Outline mode keeps its bullets, indentation, and folding. You can convert or clean up later.") .font(.callout) .foregroundStyle(DesignTokens.muted) HStack { Spacer() // Dismissal itself is the cancel (binding set(false) → // cancelOutlineGuard) — Esc and ⌘. land here too. Button("Cancel", role: .cancel) {} .keyboardShortcut(.cancelAction) Button("Open as Outline") { openAsOutline() } Button("Open in Prose") { openInProse() } .keyboardShortcut(.defaultAction) } } .padding(20) .frame(width: 420) } } /// #114 (S4): the Convert to Post ask — which body the piece becomes. /// Verbatim (default) keeps every line; the ladder re-maps outline levels /// to headings. On mixed content the ladder would drop prose lines — /// the sheet says so. struct ConvertSheet: View { let lossy: Bool /// false = verbatim bullets, true = headings ladder — one decision, /// one model call. let convert: (Bool) -> Void var body: some View { VStack(alignment: .leading, spacing: 12) { Text("Convert to Post") .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Text("The piece keeps its name, project, and Pass State — it becomes a prose post. How should the outline body read?") .font(.callout) .foregroundStyle(DesignTokens.muted) if lossy { Text("This outline has paragraph lines between its bullets. The headings ladder drops them; verbatim keeps every line.") .font(.callout) .foregroundStyle(DesignTokens.muted) } Text("Verbatim keeps the bullets as they are; Headings turns top-level blocks into section headings, deeper levels step down.") .font(.callout) .foregroundStyle(DesignTokens.muted) HStack { Spacer() // Dismissal itself is the cancel (binding set(false) → // cancelConversion) — Esc and ⌘. land here too. Button("Cancel", role: .cancel) {} .keyboardShortcut(.cancelAction) Button("Headings") { convert(true) } Button("Verbatim Bullets") { convert(false) } .keyboardShortcut(.defaultAction) } } .padding(20) .frame(width: 440) } } /// #108: New Project ask — the sheet behind File ▸ New Project… (and any /// future materialize path). Create runs through the model's raw op; the /// thrown reason is shown inline and the sheet stays up. struct NewProjectSheet: View { /// Create + open a draft in it; nil = success, a string = the failure /// reason to show inline (keeps the sheet up). let create: (String) -> String? @Environment(\.dismiss) private var dismiss @State private var name = "" @State private var failure: String? var body: some View { VStack(alignment: .leading, spacing: 12) { Text("New Project") .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Text("Pieces land here when it's selected.") .font(.callout) .foregroundStyle(DesignTokens.muted) TextField("Name", text: $name) .textFieldStyle(.roundedBorder) .onSubmit { confirm() } if let failure { Text(failure) .font(.system(size: 11, design: DesignTokens.mono)) .foregroundStyle(DesignTokens.accent) } HStack { Spacer() Button("Cancel", role: .cancel) { dismiss() } .keyboardShortcut(.cancelAction) Button("Create", action: confirm) .keyboardShortcut(.defaultAction) .disabled(name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) } } .padding(20) .frame(width: 360) } private func confirm() { let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines) guard !trimmed.isEmpty else { return } if let reason = create(trimmed) { failure = reason } else { dismiss() } } }