refactor(posts): split PostsPaneView into PostsLibraryColumn/LibraryPostRow (#193)
This commit is contained in:
1 parent
70cd1c2b55
commit
2a02b95ed0
4 files changed
+623
-597
No files matched your search
+3
-1
@@ -27,7 +27,9 @@ The map and the contracts, one bullet per file. Pin-level detail lives in the te
|
|||||||
- `ArchivePaneView.swift` — #193: the #108 Archive pane (moved from WorkspaceView.swift) — archive/ as a rail destination, List-only: clicking a piece selects it and hops to Posts (where the editor column lives); reuses `LibraryPostRow`.
|
- `ArchivePaneView.swift` — #193: the #108 Archive pane (moved from WorkspaceView.swift) — archive/ as a rail destination, List-only: clicking a piece selects it and hops to Posts (where the editor column lives); reuses `LibraryPostRow`.
|
||||||
- `WorkspaceViewSheets.swift` — #193: the house ask sheets (moved from WorkspaceView.swift) — `OriginAskSheet` (the ONE origin ask per import batch, #94), `OutlineGuardSheet` (#111 mixed-content), `ConvertSheet` (#114), `NewProjectSheet` (#108).
|
- `WorkspaceViewSheets.swift` — #193: the house ask sheets (moved from WorkspaceView.swift) — `OriginAskSheet` (the ONE origin ask per import batch, #94), `OutlineGuardSheet` (#111 mixed-content), `ConvertSheet` (#114), `NewProjectSheet` (#108).
|
||||||
- `WorkspaceChrome.swift` — #193: the shared chrome (moved from WorkspaceView.swift) — `SelectedRowStrip` (the selected-row capsule), `BorderedSecondaryButtonStyle` (the bordered secondary button), `PaneHeader` (the 52pt pane-head row); every pane reuses them.
|
- `WorkspaceChrome.swift` — #193: the shared chrome (moved from WorkspaceView.swift) — `SelectedRowStrip` (the selected-row capsule), `BorderedSecondaryButtonStyle` (the bordered secondary button), `PaneHeader` (the 52pt pane-head row); every pane reuses them.
|
||||||
- `PostsPaneView.swift` — Posts destination: library column (`PostsLibraryColumn`: project section heads + Pass-State groups, collapse toggle per-view; `LibraryPostRow` — 2px leading strip, ✳ on outline pieces, row menu Rename/Convert/Move to Project/Move to Archive/Trash), editor column, mentor column (fixed 356). Library search: debounced, title+body over non-archived pieces, body scan off-main through `readBody` (frontmatter never searched). Editor column renders the external guest ahead of the post session (one guest at a time). Focused branch mounts the Cold Turkey chrome as overlays; lock transitions never restructure the editor column.
|
- `PostsPaneView.swift` — Posts destination (#193: the library column and the row live in their own files): editor column, mentor column (fixed 356). Editor column renders the external guest ahead of the post session (one guest at a time). Focused branch mounts the Cold Turkey chrome as overlays; lock transitions never restructure the editor column.
|
||||||
|
- `PostsLibraryColumn.swift` — #193: the library column (moved from PostsPaneView.swift), shared by the unfocused layout and the focus-mode left reveal — one implementation, both surfaces. Project section heads + Pass-State groups, collapse toggle per-view; owns the rename + move sheets (`RenamePostSheet`, `MoveToProjectSheet`) and the row context menu. Library search: debounced, title+body over non-archived pieces through the file-scope `librarySearch` mount, body scan off-main through `readBody` (frontmatter never searched). `LaunchFocusReset` (r8) rides the column: the window's first become-key resigns focus back to the window, once per process.
|
||||||
|
- `LibraryPostRow.swift` — #193: the post row (moved from PostsPaneView.swift) — 2px leading strip, ✳ on outline pieces, row menu Rename/Convert/Move to Project/Move to Archive/Trash; the Archive pane reuses it.
|
||||||
- `PostLibrary.swift` — `Post` + `Post.scan`: two-level scan over `projects/<name>/<id>/post.md` AND `archive/<name>/<id>/post.md` (ADR-0012), skip guards at both levels (lazy folders, loose files, hidden dirs, symlinked dirs); frontmatter keys read leniently (First Draft/writer/post defaults); title = first non-empty body line, `untitled` fallbacks; runs off-main. `stats_*` keys load only if EVERY value parses finite (a non-finite peak would trap the chart y-domain); read-back re-gates on the named immutable pair (`PostFrontmatter.isUnaidedFirstDraftPair` — origin writer, type post; never pass_state, which legitimately advances). `scan(home:cache:)` takes a `PostScanCache` (path+mtime+size memo; the stamp is taken BEFORE the read, so a mid-scan rewrite can never pin as fresh). `micropubURL` gated on `Micropub.trustworthyURL` — imported YAML rides verbatim, so hostile values scan nil.
|
- `PostLibrary.swift` — `Post` + `Post.scan`: two-level scan over `projects/<name>/<id>/post.md` AND `archive/<name>/<id>/post.md` (ADR-0012), skip guards at both levels (lazy folders, loose files, hidden dirs, symlinked dirs); frontmatter keys read leniently (First Draft/writer/post defaults); title = first non-empty body line, `untitled` fallbacks; runs off-main. `stats_*` keys load only if EVERY value parses finite (a non-finite peak would trap the chart y-domain); read-back re-gates on the named immutable pair (`PostFrontmatter.isUnaidedFirstDraftPair` — origin writer, type post; never pass_state, which legitimately advances). `scan(home:cache:)` takes a `PostScanCache` (path+mtime+size memo; the stamp is taken BEFORE the read, so a mid-scan rewrite can never pin as fresh). `micropubURL` gated on `Micropub.trustworthyURL` — imported YAML rides verbatim, so hostile values scan nil.
|
||||||
- `PostFrontmatter.swift` — #180: the Post frontmatter codec — the ONE lenient read (`parse`/`split`/`decoded`) and the three write postures behind one known-key table (`ownedKeys`: type, pass_state, origin — one insertion-order rule): fresh stamp (`stamped`), merge-import (`mergingImport` — external keys verbatim, ours win), update-keys (`updating` — the in-place line-walk, every other line byte-identical). Absorbed and deleted `PostStore.stamped/splitFrontmatter/mergedFrontmatter` and `LearningDecay.stampingFrontmatter` byte-identically (merge-import's documented prefix-preservation divergence excepted). Owns the two named eligibility predicates both gates consume: `isUnaidedFirstDraftPair` (writer ∧ post — the scan's read-back gate) and `isCaptureEligible` (pair ∧ First Draft — the capture gate). Learning/Fix Card documents stay out of scope; the learnings dismiss stamp rides the generic update posture.
|
- `PostFrontmatter.swift` — #180: the Post frontmatter codec — the ONE lenient read (`parse`/`split`/`decoded`) and the three write postures behind one known-key table (`ownedKeys`: type, pass_state, origin — one insertion-order rule): fresh stamp (`stamped`), merge-import (`mergingImport` — external keys verbatim, ours win), update-keys (`updating` — the in-place line-walk, every other line byte-identical). Absorbed and deleted `PostStore.stamped/splitFrontmatter/mergedFrontmatter` and `LearningDecay.stampingFrontmatter` byte-identically (merge-import's documented prefix-preservation divergence excepted). Owns the two named eligibility predicates both gates consume: `isUnaidedFirstDraftPair` (writer ∧ post — the scan's read-back gate) and `isCaptureEligible` (pair ∧ First Draft — the capture gate). Learning/Fix Card documents stay out of scope; the learnings dismiss stamp rides the generic update posture.
|
||||||
- `PostStore.swift` — write side (nonisolated). Shared slug (lowercase, diacritic-fold, strip punctuation, whitespace→hyphens, keep CJK, 80-char cap); collision suffixes over the GLOBAL slug space (projects + archive — an archived slug is never reused), all comparisons through `folded` = NFC + lowercase (APFS is case- and normalization-insensitive); `folder(of:home:)` is the ONE id→folder resolver — write paths derive their target from the id alone. `writeNew` defaults `type: .post` / `origin: .writer` (session-born pieces pass `.ai`, immutable). `overwrite` preserves type/pass_state/origin and updates owned keys IN PLACE via the codec's update posture — block rewrites erase captured stats and foreign frontmatter. `rename` = retitle + move within the same parent. `importFile` copies (never moves), strips BOM + normalizes CRLF→LF at the boundary, external YAML keys verbatim with our `type`/`pass_state`/`origin` winning. Project ops (`move`/`archive`/`restore`/`unarchiveProject`/`createProject`) derive current state from the resolved DISK path, never the scan snapshot; post.md bytes are never rewritten by them; `createProject` validates names (empty/slash/dot/`:`/control + case-insensitive duplicates throw). Pass substrate: `snapshotPass` (pre-pass body verbatim to `passes/pass-<n>.md`, fixed name per type), `advancePassState` (monotonic, in-place stamp; also ticks the decay clock — a failed tick never fails a pass). `writeResearchNote` is the ONLY path to `research/` (a symlinked dir refuses). `captureFirstDraftStats` — eligibility is the codec's named `isCaptureEligible` predicate over the file's own frontmatter; failure never fails the pass. `ingestImage` copies into `assets/`, publishable types only (what can't ship can't enter); `illustrationRef` is the one `` builder.
|
- `PostStore.swift` — write side (nonisolated). Shared slug (lowercase, diacritic-fold, strip punctuation, whitespace→hyphens, keep CJK, 80-char cap); collision suffixes over the GLOBAL slug space (projects + archive — an archived slug is never reused), all comparisons through `folded` = NFC + lowercase (APFS is case- and normalization-insensitive); `folder(of:home:)` is the ONE id→folder resolver — write paths derive their target from the id alone. `writeNew` defaults `type: .post` / `origin: .writer` (session-born pieces pass `.ai`, immutable). `overwrite` preserves type/pass_state/origin and updates owned keys IN PLACE via the codec's update posture — block rewrites erase captured stats and foreign frontmatter. `rename` = retitle + move within the same parent. `importFile` copies (never moves), strips BOM + normalizes CRLF→LF at the boundary, external YAML keys verbatim with our `type`/`pass_state`/`origin` winning. Project ops (`move`/`archive`/`restore`/`unarchiveProject`/`createProject`) derive current state from the resolved DISK path, never the scan snapshot; post.md bytes are never rewritten by them; `createProject` validates names (empty/slash/dot/`:`/control + case-insensitive duplicates throw). Pass substrate: `snapshotPass` (pre-pass body verbatim to `passes/pass-<n>.md`, fixed name per type), `advancePassState` (monotonic, in-place stamp; also ticks the decay clock — a failed tick never fails a pass). `writeResearchNote` is the ONLY path to `research/` (a symlinked dir refuses). `captureFirstDraftStats` — eligibility is the codec's named `isCaptureEligible` predicate over the file's own frontmatter; failure never fails the pass. `ingestImage` copies into `assets/`, publishable types only (what can't ship can't enter); `illustrationRef` is the one `` builder.
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
//
|
||||||
|
// LibraryPostRow.swift
|
||||||
|
// Museion
|
||||||
|
//
|
||||||
|
// #193: the shared post row, moved from PostsPaneView.swift
|
||||||
|
// (file-length ceiling) — the Archive pane reuses it, code
|
||||||
|
// unchanged.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
/// One post row per the export: title + origin-only mono-11 meta (the Pass
|
||||||
|
/// State rides the uppercase group label above; it stays in the a11y label).
|
||||||
|
/// #108 (variant B): 2px accent edge bar on the leading side when selected
|
||||||
|
/// (`.vB .post-row[aria-current] { border-left-color: var(--accent) }`,
|
||||||
|
/// radius 0 8 8 0), and a muted ✳ suffix on outline pieces. Internal: the
|
||||||
|
/// Archive pane reuses it.
|
||||||
|
struct LibraryPostRow: View {
|
||||||
|
let post: Post
|
||||||
|
let selected: Bool
|
||||||
|
let select: () -> Void
|
||||||
|
@State private var hover = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
// `.vB .post-row { border-left: 2px solid transparent;
|
||||||
|
// border-radius: 0 8px 8px 0 }` — every row: leading corners square
|
||||||
|
// (the 2px strip below), trailing rounded 8. Only the strip's
|
||||||
|
// VISIBILITY changes on selection.
|
||||||
|
let shape = UnevenRoundedRectangle(cornerRadii: .init(bottomTrailing: 8, topTrailing: 8))
|
||||||
|
return Button(action: select) {
|
||||||
|
HStack(spacing: 0) {
|
||||||
|
// The leading strip is always 2px wide so hover/selection
|
||||||
|
// never shifts the title. r6 (mercury#49/52, argon#13):
|
||||||
|
// the shared SelectedRowStrip capsule — accent, radius-1
|
||||||
|
// ends, vertically inset 6pt (was 3) so it sits INSIDE
|
||||||
|
// the card, never pasted on its square leading edge.
|
||||||
|
SelectedRowStrip()
|
||||||
|
.opacity(selected ? 1 : 0)
|
||||||
|
VStack(alignment: .leading, spacing: 5) {
|
||||||
|
HStack(alignment: .firstTextBaseline, spacing: 0) {
|
||||||
|
Text(post.title)
|
||||||
|
if post.type == .outline {
|
||||||
|
Text(" ✳")
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ui-polish r8: serif-13 per the row contract — `.callout`
|
||||||
|
// was the system sans design (the r6/r7 councils pixel-
|
||||||
|
// verified sans glyphs on the Archive rows).
|
||||||
|
.font(.system(size: 13, weight: .semibold, design: DesignTokens.serif))
|
||||||
|
.lineLimit(1)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
// Origin only — the Pass State already rides the uppercase
|
||||||
|
// group label above (it stays in the accessibility label).
|
||||||
|
// r7: the status micro-label sits INSIDE the row's content
|
||||||
|
// padding — same x as the title, never flush with the edge.
|
||||||
|
Text(post.origin.rawValue)
|
||||||
|
.font(.system(size: 11, design: DesignTokens.mono))
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 12)
|
||||||
|
.padding(.vertical, 10)
|
||||||
|
}
|
||||||
|
.clipShape(shape)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.foregroundStyle(DesignTokens.foreground)
|
||||||
|
.background {
|
||||||
|
if selected || hover {
|
||||||
|
// r8 (mercury#11): the selected row DROPS its gray outline —
|
||||||
|
// fill + accent capsule read as ONE shape; stacking fill +
|
||||||
|
// outline + capsule competed. Hover keeps its borderless
|
||||||
|
// 0.06 wash exactly as before.
|
||||||
|
shape
|
||||||
|
.fill(selected ? DesignTokens.foreground.opacity(0.08) : DesignTokens.foreground.opacity(0.06))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// r7 (mercury#18, argon#12 — two-axis ladder): the row CARD
|
||||||
|
// leads at the PRIMARY inset (x14, the 'Posts' header text's
|
||||||
|
// edge); its INNER content (title + status micro-label, strip
|
||||||
|
// 2 + padding 12) lands at x28 — the ONE indent step, shared
|
||||||
|
// with the head text and the group labels. No other x-axis
|
||||||
|
// exists in the column. Vertical padding stays the content
|
||||||
|
// VStack's constant 10 whether or not the row shows its strip.
|
||||||
|
.padding(.horizontal, 14)
|
||||||
|
.onHover { hover = $0 }
|
||||||
|
// help sits on the row — the ✳ span isn't individually hoverable in
|
||||||
|
// SwiftUI (prototype: `title="outline"` on the star).
|
||||||
|
.help(post.type == .outline ? "\(post.title) — outline" : post.title)
|
||||||
|
.accessibilityLabel("\(post.title), \(post.passState.rawValue), origin \(post.origin.rawValue)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,521 @@
|
|||||||
|
//
|
||||||
|
// PostsLibraryColumn.swift
|
||||||
|
// Museion
|
||||||
|
//
|
||||||
|
// #193: the Posts library column, moved from PostsPaneView.swift
|
||||||
|
// (file-length ceiling) — PostsLibraryColumn with its rename/move
|
||||||
|
// sheets, the file-scope librarySearch mount (#144), and
|
||||||
|
// LaunchFocusReset (r8), code unchanged.
|
||||||
|
//
|
||||||
|
|
||||||
|
import AppKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
/// #21: the library column, shared by the unfocused layout and the focus-mode
|
||||||
|
/// left reveal overlay — one implementation, both surfaces. Owns the rename +
|
||||||
|
/// move sheets and the context menu (they travel with the post rows).
|
||||||
|
/// #108 variant B: sections per project, Pass-State groups inside.
|
||||||
|
struct PostsLibraryColumn: View {
|
||||||
|
let home: URL
|
||||||
|
var model: PostsModel
|
||||||
|
@State private var renamingPost: Post?
|
||||||
|
@State private var movingPost: Post?
|
||||||
|
/// #108: collapsed project sections — per-view state, not persisted (a
|
||||||
|
/// fresh open shows everything; the prototype behaved the same).
|
||||||
|
@State private var collapsed: Set<String> = []
|
||||||
|
/// #144: the library search — live title+body filter over the
|
||||||
|
/// non-archived pieces. nil = not searching (sections render).
|
||||||
|
@State private var query = ""
|
||||||
|
/// #144 (mounted half): the landed sweep — results plus the key that
|
||||||
|
/// computed them. nil = not searching or recomputing (the sections /
|
||||||
|
/// spinner states); a snapshot that isn't `isFresh` for the current
|
||||||
|
/// key never renders.
|
||||||
|
@State private var snapshot: LibrarySearch.Snapshot?
|
||||||
|
/// r5 (argon#44, mercury#52, sol#37): focus state for the field's
|
||||||
|
/// accent ring. r8 (argon#6, mercury#12 — root cause found): the r6/r7
|
||||||
|
/// onAppear-unfocus could never work — the launch focus is AppKit
|
||||||
|
/// assigning the window's INITIAL first responder to its first text
|
||||||
|
/// input (this field), at window-become-key, AFTER onAppear. FocusState
|
||||||
|
/// merely mirrors that back as true. LaunchFocusReset (below) resigns
|
||||||
|
/// it at the first become-key; from then on only the user drives this.
|
||||||
|
@FocusState private var searchFocused: Bool
|
||||||
|
|
||||||
|
private var trimmedQuery: String {
|
||||||
|
query.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// #144 (mounted half): the sweep's identity — trimmed query, the
|
||||||
|
/// Home, and the library content revision (`PostsModel.contentRevision`,
|
||||||
|
/// bumped by the rescan rail on any list change or re-read body). The
|
||||||
|
/// `.task(id:)` below re-keys on ANY difference, so library writes and
|
||||||
|
/// Home repoints restart the sweep instead of leaving stale rows; the
|
||||||
|
/// landed snapshot renders only while `isFresh` for the current key.
|
||||||
|
private var searchKey: LibrarySearch.SearchKey {
|
||||||
|
LibrarySearch.SearchKey(query: trimmedQuery, homePath: home.path, revision: model.contentRevision)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isSearching: Bool {
|
||||||
|
!trimmedQuery.isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Non-archived pieces keyed by project (scan order = title order holds
|
||||||
|
/// inside each group — filter preserves it).
|
||||||
|
private var activeByProject: [String: [Post]] {
|
||||||
|
Dictionary(grouping: model.posts.filter { !$0.isArchived }, by: \.project)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
PaneHeader(title: "Posts") {
|
||||||
|
Button {
|
||||||
|
model.newPost()
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "plus")
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
.help("New Post")
|
||||||
|
.accessibilityLabel("New Post")
|
||||||
|
}
|
||||||
|
searchField
|
||||||
|
if isSearching {
|
||||||
|
// #144 (mounted half): a landed sweep renders only while
|
||||||
|
// fresh for the CURRENT key — a library write that bumped
|
||||||
|
// the revision (archive, trash, rename, body edit) or a
|
||||||
|
// moved query drops to the recompute state, never stale rows.
|
||||||
|
if let snapshot, snapshot.isFresh(for: searchKey) {
|
||||||
|
if snapshot.results.isEmpty {
|
||||||
|
searchEmptyState
|
||||||
|
} else {
|
||||||
|
searchResults(snapshot.results)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ProgressView()
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
}
|
||||||
|
} else if activeByProject.isEmpty {
|
||||||
|
emptyState
|
||||||
|
} else {
|
||||||
|
ScrollView {
|
||||||
|
LazyVStack(alignment: .leading, spacing: 4) {
|
||||||
|
// #108 audit: Finder order (scan's own sort), not Unicode-scalar
|
||||||
|
// order — the heads render lowercased, "Beta" must not read before "apple".
|
||||||
|
ForEach(activeByProject.keys.sorted { $0.localizedStandardCompare($1) == .orderedAscending }, id: \.self) { project in
|
||||||
|
let pieces = activeByProject[project] ?? []
|
||||||
|
// #108: the head is the prototype's toggle — click
|
||||||
|
// collapses the project's pieces (chevron rotates).
|
||||||
|
Button {
|
||||||
|
withAnimation {
|
||||||
|
if collapsed.contains(project) {
|
||||||
|
collapsed.remove(project)
|
||||||
|
} else {
|
||||||
|
collapsed.insert(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
// r7 (mercury#18, argon#12 — TWO-AXIS ladder,
|
||||||
|
// the r6 four-step collapse undone): the
|
||||||
|
// head ROW leads at the column's PRIMARY
|
||||||
|
// inset (x14) — chevron glyph in a 14pt slot
|
||||||
|
// — and every nested CONTENT shares the one
|
||||||
|
// indent step (x28): head text, group
|
||||||
|
// labels, and the rows' inner text. No third
|
||||||
|
// or fourth x-axis exists in the column.
|
||||||
|
HStack(alignment: .firstTextBaseline, spacing: 0) {
|
||||||
|
Image(systemName: "chevron.down")
|
||||||
|
.font(.system(size: 10, weight: .semibold))
|
||||||
|
.frame(width: 14, alignment: .leading)
|
||||||
|
.rotationEffect(.degrees(collapsed.contains(project) ? -90 : 0))
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
Text(project)
|
||||||
|
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||||
|
.textCase(.lowercase) // #108: display-only — the folder name keeps its case
|
||||||
|
.lineLimit(1)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
Text("· \(pieces.count)")
|
||||||
|
.font(.system(size: 11, design: DesignTokens.mono))
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.foregroundStyle(DesignTokens.foreground)
|
||||||
|
.accessibilityLabel("\(project), \(pieces.count) pieces")
|
||||||
|
.accessibilityHint(collapsed.contains(project) ? "Collapsed" : "Expanded")
|
||||||
|
.padding(.top, 16)
|
||||||
|
.padding(.horizontal, 14)
|
||||||
|
.padding(.bottom, 6)
|
||||||
|
if !collapsed.contains(project) {
|
||||||
|
passStateGroups(pieces)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.bottom, 12)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(width: DesignTokens.libraryWidth)
|
||||||
|
// r8 (argon#6, mercury#12): the focus-rider replaces the r6/r7
|
||||||
|
// onAppear-unfocus — see LaunchFocusReset below for the mechanism.
|
||||||
|
.background(LaunchFocusReset())
|
||||||
|
.sheet(item: $renamingPost) { post in
|
||||||
|
RenamePostSheet(post: post) { title in
|
||||||
|
model.rename(post, to: title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sheet(item: $movingPost) { post in
|
||||||
|
// #108 audit 2: disk-derived list, localized-sorted — same order
|
||||||
|
// the library renders (Unicode-scalar sort split them), and it
|
||||||
|
// includes empty projects (a fresh New Project has no pieces yet —
|
||||||
|
// it must already be a move target).
|
||||||
|
MoveToProjectSheet(post: post, projects: model.moveTargets()) { project in
|
||||||
|
model.moveToProject(post, project: project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #144: keystroke-debounced (250 ms), structured body scan —
|
||||||
|
// nonisolated search() runs the disk reads off MainActor while
|
||||||
|
// staying inside this task, so a superseding keystroke or clear
|
||||||
|
// cancels the sweep between pieces (the in-flight file read
|
||||||
|
// always finishes — readBody is synchronous). Keyed to the full
|
||||||
|
// search key: a library write (revision bump) or a Home repoint
|
||||||
|
// restarts the sweep too. The snapshot lands under the key
|
||||||
|
// captured at start; a mid-sweep key change cancels here, and
|
||||||
|
// even a raced assignment can't render — body gates on isFresh.
|
||||||
|
.task(id: searchKey) {
|
||||||
|
let key = searchKey
|
||||||
|
guard !key.query.isEmpty else {
|
||||||
|
snapshot = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try? await Task.sleep(for: .milliseconds(250))
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
let found = await librarySearch(
|
||||||
|
candidates: model.posts.filter { !$0.isArchived },
|
||||||
|
matching: key.query,
|
||||||
|
home: home,
|
||||||
|
)
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
snapshot = LibrarySearch.Snapshot(key: key, results: found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One piece row + its context menu — sections and search results
|
||||||
|
/// render the same row (#144: results carry the full menu too).
|
||||||
|
private func postRow(_ post: Post) -> some View {
|
||||||
|
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
||||||
|
model.select(post.id)
|
||||||
|
}
|
||||||
|
.contextMenu {
|
||||||
|
Button("Rename…") { renamingPost = post }
|
||||||
|
// #114 (S4): outline pieces only — the ask picks the
|
||||||
|
// body transform, then the piece becomes a prose post.
|
||||||
|
if post.type == .outline {
|
||||||
|
Button("Convert to Post…") {
|
||||||
|
model.stageConversion(post)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Button("Move to Project…") { movingPost = post }
|
||||||
|
Button("Move to Archive") {
|
||||||
|
model.archivePost(post)
|
||||||
|
}
|
||||||
|
Button("Move to Trash", role: .destructive) {
|
||||||
|
model.trash(post)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pass-State groups inside one project (`.vB .group-label`: smaller,
|
||||||
|
/// softer, indented under the section head). r2: the label binds to
|
||||||
|
/// its FIRST row (bottom 1 + stack 4) — it floated closer to the
|
||||||
|
/// preceding row than to its own children.
|
||||||
|
private func passStateGroups(_ pieces: [Post]) -> some View {
|
||||||
|
ForEach(Post.PassState.allCases, id: \.self) { state in
|
||||||
|
let grouped = pieces.filter { $0.passState == state }
|
||||||
|
if !grouped.isEmpty {
|
||||||
|
// mercury#53 (r5): display-only normalization — the stored
|
||||||
|
// rawValues keep their hyphen ("Pass-1 Done"); the rendered
|
||||||
|
// label uses the space form so it matches the Pass 1 / Pass 2
|
||||||
|
// vocabulary everywhere else.
|
||||||
|
Text(state.rawValue.uppercased().replacingOccurrences(of: "-", with: " "))
|
||||||
|
.font(.system(size: 11, weight: .medium, design: DesignTokens.mono))
|
||||||
|
.kerning(0.6)
|
||||||
|
// r6 (sol#6/21 — contrast final): group labels are
|
||||||
|
// informational meta — FULL muted ink, no wash.
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
// r6 ladder: full muted ink. r7 two-axis: x28 — the ONE
|
||||||
|
// indent step, shared with the head text and the row
|
||||||
|
// cards' inner content.
|
||||||
|
.padding(.leading, 28)
|
||||||
|
.padding(.top, 10)
|
||||||
|
.padding(.bottom, 1)
|
||||||
|
ForEach(grouped) { post in
|
||||||
|
postRow(post)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// #144 + mercury#54 (r4): a real field surface — surface fill + hairline
|
||||||
|
/// border on the column's chrome, taller than a text row; the placeholder
|
||||||
|
/// r5 (argon#44, mercury#52, sol#37): the insertion caret tints
|
||||||
|
/// terracotta (.tint on the field), and the small magnifier glyph sits at
|
||||||
|
/// the field's leading edge (icon→text spacing rides the HStack's 6pt);
|
||||||
|
/// the placeholder is the native prompt wearing the palette's muted ink
|
||||||
|
/// (the composer's pattern).
|
||||||
|
/// r8 (argon#6, mercury#12): focus draws a QUIET 1pt ring — accent at 0.6,
|
||||||
|
/// present but never the strongest saturation on screen.
|
||||||
|
private var searchField: some View {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
Image(systemName: "magnifyingglass")
|
||||||
|
.font(.system(size: 11))
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
TextField("Search posts", text: $query, prompt: Text("Search posts").foregroundStyle(DesignTokens.muted))
|
||||||
|
.textFieldStyle(.plain)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.focused($searchFocused)
|
||||||
|
.tint(DesignTokens.accent)
|
||||||
|
if isSearching {
|
||||||
|
Button {
|
||||||
|
query = ""
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
.accessibilityLabel("Clear search")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.fill(DesignTokens.surface)
|
||||||
|
.overlay(
|
||||||
|
// r8 (argon#6, mercury#12): quiet focus — accent at 0.6,
|
||||||
|
// one step down from full strength.
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.strokeBorder(
|
||||||
|
searchFocused ? DesignTokens.accent.opacity(0.6) : DesignTokens.border,
|
||||||
|
lineWidth: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// r7 (mercury#18, argon#12 — two-axis ladder): the box spans the
|
||||||
|
// FULL padded column width at the PRIMARY inset — leading 14
|
||||||
|
// (aligned with the 'Posts' header text) to trailing 14 — the
|
||||||
|
// same edges the row cards lead at.
|
||||||
|
.padding(.horizontal, 14)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flat results, title matches first (stable partition — both halves
|
||||||
|
/// keep the scan's Finder order). Same row the sections render.
|
||||||
|
private func searchResults(_ found: [Post]) -> some View {
|
||||||
|
ScrollView {
|
||||||
|
LazyVStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("\(found.count) \(found.count == 1 ? "match" : "matches")")
|
||||||
|
.font(.system(size: 11, design: DesignTokens.mono))
|
||||||
|
.kerning(0.6)
|
||||||
|
// r6: full muted ink; r7 two-axis: x28 — the indent
|
||||||
|
// step, heading the flat result list exactly where
|
||||||
|
// group labels head their sections.
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
.padding(.leading, 28)
|
||||||
|
.padding(.top, 12)
|
||||||
|
.padding(.bottom, 1)
|
||||||
|
ForEach(found) { post in
|
||||||
|
postRow(post)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.bottom, 12)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var searchEmptyState: some View {
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
Text("No matches")
|
||||||
|
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
|
||||||
|
Text("No piece's title or body contains “\(trimmedQuery)”.")
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
.padding(38)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var emptyState: some View {
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
Text("No posts yet")
|
||||||
|
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
|
||||||
|
Text("Posts in this Home's projects/ folders appear here.")
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
.padding(38)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// #144: the title+body scan — a thin mount for the pure
|
||||||
|
/// `LibrarySearch` seam (title matches first, stable partition, both
|
||||||
|
/// halves keep the scan's Finder order; body via readBody — frontmatter
|
||||||
|
/// never searched), pinned by MuseionTests/LibrarySearchTests.swift.
|
||||||
|
/// The reader's per-piece cancellation check stops a superseded sweep's
|
||||||
|
/// body reads between files; the in-memory title walk itself completes
|
||||||
|
/// cheaply and the caller's guard discards its result. File scope since
|
||||||
|
/// r6 (PostsLibraryColumn hit its type-body ceiling).
|
||||||
|
///
|
||||||
|
/// ponytail: full-body re-read per sweep (folder(of:) re-walked per
|
||||||
|
/// piece — same unbounded-read ceiling as Post.scan, LearningsIndex
|
||||||
|
/// posture); a PostScanCache-style body memo if it ever measures hot.
|
||||||
|
private nonisolated func librarySearch(
|
||||||
|
candidates: [Post],
|
||||||
|
matching trimmed: String,
|
||||||
|
home: URL,
|
||||||
|
) async -> [Post] {
|
||||||
|
LibrarySearch.results(for: trimmed, in: candidates) { post in
|
||||||
|
guard !Task.isCancelled else { return nil }
|
||||||
|
return PostStore.readBody(id: post.id, home: home)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// r8 (argon#6, mercury#12 — the launch auto-focus ROOT CAUSE, killed at
|
||||||
|
/// the source): the search field is the window's first — and at launch,
|
||||||
|
/// only — text input, and AppKit assigns the window's initial first
|
||||||
|
/// responder to it when the window becomes key. That happens AFTER
|
||||||
|
/// onAppear, so the r6/r7 `searchFocused = false` writes were always
|
||||||
|
/// overridden (FocusState mirrors the assignment back as true: terracotta
|
||||||
|
/// ring + caret, the strongest element on screen). This invisible rider
|
||||||
|
/// rides the library column and, at the window's FIRST become-key,
|
||||||
|
/// resigns focus back to the window itself (`makeFirstResponder(nil)` —
|
||||||
|
/// the neutral state; nothing gains focus instead). ONCE per process: a
|
||||||
|
/// pane-switch remount must never steal a focus the user set on return.
|
||||||
|
/// The second, next-runloop resign covers an assignment that lands after
|
||||||
|
/// the notification (the PostEditorView layout-race precedent).
|
||||||
|
private struct LaunchFocusReset: NSViewRepresentable {
|
||||||
|
/// Process-wide once-flag — launch is a once-per-process event.
|
||||||
|
private static var hasRun = false
|
||||||
|
|
||||||
|
final class RiderView: NSView {
|
||||||
|
private var keyObserver: NSObjectProtocol?
|
||||||
|
|
||||||
|
override func viewDidMoveToWindow() {
|
||||||
|
if let keyObserver {
|
||||||
|
NotificationCenter.default.removeObserver(keyObserver)
|
||||||
|
}
|
||||||
|
keyObserver = nil
|
||||||
|
guard let window else { return }
|
||||||
|
keyObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: NSWindow.didBecomeKeyNotification,
|
||||||
|
object: window,
|
||||||
|
queue: .main,
|
||||||
|
) { _ in
|
||||||
|
MainActor.assumeIsolated {
|
||||||
|
// The observer is scoped to `window` (object:), so the
|
||||||
|
// notification carries nothing we don't already hold —
|
||||||
|
// reading `note` here would cross a Sendable boundary.
|
||||||
|
guard !LaunchFocusReset.hasRun else { return }
|
||||||
|
LaunchFocusReset.hasRun = true
|
||||||
|
window.makeFirstResponder(nil)
|
||||||
|
DispatchQueue.main.async { window.makeFirstResponder(nil) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeNSView(context _: Context) -> RiderView {
|
||||||
|
RiderView()
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNSView(_: RiderView, context _: Context) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// #108: Move to Project ask — radio list of the non-archived projects,
|
||||||
|
/// default = the piece's current project. Matches RenamePostSheet's shape.
|
||||||
|
struct MoveToProjectSheet: View {
|
||||||
|
let post: Post
|
||||||
|
let projects: [String]
|
||||||
|
let move: (String) -> Void
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
@State private var target: String
|
||||||
|
|
||||||
|
init(post: Post, projects: [String], move: @escaping (String) -> Void) {
|
||||||
|
self.post = post
|
||||||
|
self.projects = projects
|
||||||
|
self.move = move
|
||||||
|
_target = State(initialValue: post.project)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
Text("Move to Project")
|
||||||
|
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||||
|
Text("“\(post.title)” moves into the chosen project. The file stays post.md.")
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
Picker("Project", selection: $target) {
|
||||||
|
ForEach(projects, id: \.self) { name in
|
||||||
|
Text(name).tag(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(.radioGroup)
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Button("Cancel", role: .cancel) { dismiss() }
|
||||||
|
.keyboardShortcut(.cancelAction)
|
||||||
|
Button("Move") {
|
||||||
|
move(target)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
.keyboardShortcut(.defaultAction)
|
||||||
|
.disabled(target == post.project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(20)
|
||||||
|
.frame(width: 360)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// #60: Explicit Rename dialog — asks the new Title (not a slug).
|
||||||
|
struct RenamePostSheet: View {
|
||||||
|
let rename: (String) -> Void
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
@State private var title: String
|
||||||
|
|
||||||
|
init(post: Post, rename: @escaping (String) -> Void) {
|
||||||
|
self.rename = rename
|
||||||
|
_title = State(initialValue: post.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
Text("Rename Post")
|
||||||
|
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||||
|
Text("The folder moves to match the new Title. The file stays post.md.")
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundStyle(DesignTokens.muted)
|
||||||
|
TextField("Title", text: $title)
|
||||||
|
.textFieldStyle(.roundedBorder)
|
||||||
|
.onSubmit { confirm() }
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Button("Cancel", role: .cancel) { dismiss() }
|
||||||
|
.keyboardShortcut(.cancelAction)
|
||||||
|
Button("Rename", action: confirm)
|
||||||
|
.keyboardShortcut(.defaultAction)
|
||||||
|
.disabled(title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(20)
|
||||||
|
.frame(width: 360)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func confirm() {
|
||||||
|
let trimmed = title.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
guard !trimmed.isEmpty else { return }
|
||||||
|
rename(trimmed)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-596
@@ -7,11 +7,13 @@
|
|||||||
// trash. #19: the TextKit2 editor core (PostEditorView) replaces the stub;
|
// trash. #19: the TextKit2 editor core (PostEditorView) replaces the stub;
|
||||||
// mentor column (#14).
|
// mentor column (#14).
|
||||||
// #108 (variant B, ref/prototypes/wf104-library-ui-prototype.html): sections
|
// #108 (variant B, ref/prototypes/wf104-library-ui-prototype.html): sections
|
||||||
// per project (serif-15 head + mono count), Pass-State groups inside, and a
|
// per project (serif-15 head + mono count), Pass-State groups inside, and
|
||||||
// 2px accent edge bar on the selected row.
|
// 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 AppKit
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
/// The Posts destination: the workspace's full four-column layout
|
/// The Posts destination: the workspace's full four-column layout
|
||||||
@@ -181,596 +183,3 @@ struct PostsPaneView: View {
|
|||||||
.frame(width: DesignTokens.mentorWidth)
|
.frame(width: DesignTokens.mentorWidth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #21: the library column, shared by the unfocused layout and the focus-mode
|
|
||||||
/// left reveal overlay — one implementation, both surfaces. Owns the rename +
|
|
||||||
/// move sheets and the context menu (they travel with the post rows).
|
|
||||||
/// #108 variant B: sections per project, Pass-State groups inside.
|
|
||||||
struct PostsLibraryColumn: View {
|
|
||||||
let home: URL
|
|
||||||
var model: PostsModel
|
|
||||||
@State private var renamingPost: Post?
|
|
||||||
@State private var movingPost: Post?
|
|
||||||
/// #108: collapsed project sections — per-view state, not persisted (a
|
|
||||||
/// fresh open shows everything; the prototype behaved the same).
|
|
||||||
@State private var collapsed: Set<String> = []
|
|
||||||
/// #144: the library search — live title+body filter over the
|
|
||||||
/// non-archived pieces. nil = not searching (sections render).
|
|
||||||
@State private var query = ""
|
|
||||||
/// #144 (mounted half): the landed sweep — results plus the key that
|
|
||||||
/// computed them. nil = not searching or recomputing (the sections /
|
|
||||||
/// spinner states); a snapshot that isn't `isFresh` for the current
|
|
||||||
/// key never renders.
|
|
||||||
@State private var snapshot: LibrarySearch.Snapshot?
|
|
||||||
/// r5 (argon#44, mercury#52, sol#37): focus state for the field's
|
|
||||||
/// accent ring. r8 (argon#6, mercury#12 — root cause found): the r6/r7
|
|
||||||
/// onAppear-unfocus could never work — the launch focus is AppKit
|
|
||||||
/// assigning the window's INITIAL first responder to its first text
|
|
||||||
/// input (this field), at window-become-key, AFTER onAppear. FocusState
|
|
||||||
/// merely mirrors that back as true. LaunchFocusReset (below) resigns
|
|
||||||
/// it at the first become-key; from then on only the user drives this.
|
|
||||||
@FocusState private var searchFocused: Bool
|
|
||||||
|
|
||||||
private var trimmedQuery: String {
|
|
||||||
query.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// #144 (mounted half): the sweep's identity — trimmed query, the
|
|
||||||
/// Home, and the library content revision (`PostsModel.contentRevision`,
|
|
||||||
/// bumped by the rescan rail on any list change or re-read body). The
|
|
||||||
/// `.task(id:)` below re-keys on ANY difference, so library writes and
|
|
||||||
/// Home repoints restart the sweep instead of leaving stale rows; the
|
|
||||||
/// landed snapshot renders only while `isFresh` for the current key.
|
|
||||||
private var searchKey: LibrarySearch.SearchKey {
|
|
||||||
LibrarySearch.SearchKey(query: trimmedQuery, homePath: home.path, revision: model.contentRevision)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var isSearching: Bool {
|
|
||||||
!trimmedQuery.isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Non-archived pieces keyed by project (scan order = title order holds
|
|
||||||
/// inside each group — filter preserves it).
|
|
||||||
private var activeByProject: [String: [Post]] {
|
|
||||||
Dictionary(grouping: model.posts.filter { !$0.isArchived }, by: \.project)
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(spacing: 0) {
|
|
||||||
PaneHeader(title: "Posts") {
|
|
||||||
Button {
|
|
||||||
model.newPost()
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "plus")
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
.help("New Post")
|
|
||||||
.accessibilityLabel("New Post")
|
|
||||||
}
|
|
||||||
searchField
|
|
||||||
if isSearching {
|
|
||||||
// #144 (mounted half): a landed sweep renders only while
|
|
||||||
// fresh for the CURRENT key — a library write that bumped
|
|
||||||
// the revision (archive, trash, rename, body edit) or a
|
|
||||||
// moved query drops to the recompute state, never stale rows.
|
|
||||||
if let snapshot, snapshot.isFresh(for: searchKey) {
|
|
||||||
if snapshot.results.isEmpty {
|
|
||||||
searchEmptyState
|
|
||||||
} else {
|
|
||||||
searchResults(snapshot.results)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ProgressView()
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
}
|
|
||||||
} else if activeByProject.isEmpty {
|
|
||||||
emptyState
|
|
||||||
} else {
|
|
||||||
ScrollView {
|
|
||||||
LazyVStack(alignment: .leading, spacing: 4) {
|
|
||||||
// #108 audit: Finder order (scan's own sort), not Unicode-scalar
|
|
||||||
// order — the heads render lowercased, "Beta" must not read before "apple".
|
|
||||||
ForEach(activeByProject.keys.sorted { $0.localizedStandardCompare($1) == .orderedAscending }, id: \.self) { project in
|
|
||||||
let pieces = activeByProject[project] ?? []
|
|
||||||
// #108: the head is the prototype's toggle — click
|
|
||||||
// collapses the project's pieces (chevron rotates).
|
|
||||||
Button {
|
|
||||||
withAnimation {
|
|
||||||
if collapsed.contains(project) {
|
|
||||||
collapsed.remove(project)
|
|
||||||
} else {
|
|
||||||
collapsed.insert(project)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} label: {
|
|
||||||
// r7 (mercury#18, argon#12 — TWO-AXIS ladder,
|
|
||||||
// the r6 four-step collapse undone): the
|
|
||||||
// head ROW leads at the column's PRIMARY
|
|
||||||
// inset (x14) — chevron glyph in a 14pt slot
|
|
||||||
// — and every nested CONTENT shares the one
|
|
||||||
// indent step (x28): head text, group
|
|
||||||
// labels, and the rows' inner text. No third
|
|
||||||
// or fourth x-axis exists in the column.
|
|
||||||
HStack(alignment: .firstTextBaseline, spacing: 0) {
|
|
||||||
Image(systemName: "chevron.down")
|
|
||||||
.font(.system(size: 10, weight: .semibold))
|
|
||||||
.frame(width: 14, alignment: .leading)
|
|
||||||
.rotationEffect(.degrees(collapsed.contains(project) ? -90 : 0))
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
Text(project)
|
|
||||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
|
||||||
.textCase(.lowercase) // #108: display-only — the folder name keeps its case
|
|
||||||
.lineLimit(1)
|
|
||||||
.truncationMode(.tail)
|
|
||||||
Text("· \(pieces.count)")
|
|
||||||
.font(.system(size: 11, design: DesignTokens.mono))
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
Spacer(minLength: 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.foregroundStyle(DesignTokens.foreground)
|
|
||||||
.accessibilityLabel("\(project), \(pieces.count) pieces")
|
|
||||||
.accessibilityHint(collapsed.contains(project) ? "Collapsed" : "Expanded")
|
|
||||||
.padding(.top, 16)
|
|
||||||
.padding(.horizontal, 14)
|
|
||||||
.padding(.bottom, 6)
|
|
||||||
if !collapsed.contains(project) {
|
|
||||||
passStateGroups(pieces)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.bottom, 12)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(width: DesignTokens.libraryWidth)
|
|
||||||
// r8 (argon#6, mercury#12): the focus-rider replaces the r6/r7
|
|
||||||
// onAppear-unfocus — see LaunchFocusReset below for the mechanism.
|
|
||||||
.background(LaunchFocusReset())
|
|
||||||
.sheet(item: $renamingPost) { post in
|
|
||||||
RenamePostSheet(post: post) { title in
|
|
||||||
model.rename(post, to: title)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.sheet(item: $movingPost) { post in
|
|
||||||
// #108 audit 2: disk-derived list, localized-sorted — same order
|
|
||||||
// the library renders (Unicode-scalar sort split them), and it
|
|
||||||
// includes empty projects (a fresh New Project has no pieces yet —
|
|
||||||
// it must already be a move target).
|
|
||||||
MoveToProjectSheet(post: post, projects: model.moveTargets()) { project in
|
|
||||||
model.moveToProject(post, project: project)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// #144: keystroke-debounced (250 ms), structured body scan —
|
|
||||||
// nonisolated search() runs the disk reads off MainActor while
|
|
||||||
// staying inside this task, so a superseding keystroke or clear
|
|
||||||
// cancels the sweep between pieces (the in-flight file read
|
|
||||||
// always finishes — readBody is synchronous). Keyed to the full
|
|
||||||
// search key: a library write (revision bump) or a Home repoint
|
|
||||||
// restarts the sweep too. The snapshot lands under the key
|
|
||||||
// captured at start; a mid-sweep key change cancels here, and
|
|
||||||
// even a raced assignment can't render — body gates on isFresh.
|
|
||||||
.task(id: searchKey) {
|
|
||||||
let key = searchKey
|
|
||||||
guard !key.query.isEmpty else {
|
|
||||||
snapshot = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try? await Task.sleep(for: .milliseconds(250))
|
|
||||||
guard !Task.isCancelled else { return }
|
|
||||||
let found = await librarySearch(
|
|
||||||
candidates: model.posts.filter { !$0.isArchived },
|
|
||||||
matching: key.query,
|
|
||||||
home: home,
|
|
||||||
)
|
|
||||||
guard !Task.isCancelled else { return }
|
|
||||||
snapshot = LibrarySearch.Snapshot(key: key, results: found)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One piece row + its context menu — sections and search results
|
|
||||||
/// render the same row (#144: results carry the full menu too).
|
|
||||||
private func postRow(_ post: Post) -> some View {
|
|
||||||
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
|
||||||
model.select(post.id)
|
|
||||||
}
|
|
||||||
.contextMenu {
|
|
||||||
Button("Rename…") { renamingPost = post }
|
|
||||||
// #114 (S4): outline pieces only — the ask picks the
|
|
||||||
// body transform, then the piece becomes a prose post.
|
|
||||||
if post.type == .outline {
|
|
||||||
Button("Convert to Post…") {
|
|
||||||
model.stageConversion(post)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Button("Move to Project…") { movingPost = post }
|
|
||||||
Button("Move to Archive") {
|
|
||||||
model.archivePost(post)
|
|
||||||
}
|
|
||||||
Button("Move to Trash", role: .destructive) {
|
|
||||||
model.trash(post)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pass-State groups inside one project (`.vB .group-label`: smaller,
|
|
||||||
/// softer, indented under the section head). r2: the label binds to
|
|
||||||
/// its FIRST row (bottom 1 + stack 4) — it floated closer to the
|
|
||||||
/// preceding row than to its own children.
|
|
||||||
private func passStateGroups(_ pieces: [Post]) -> some View {
|
|
||||||
ForEach(Post.PassState.allCases, id: \.self) { state in
|
|
||||||
let grouped = pieces.filter { $0.passState == state }
|
|
||||||
if !grouped.isEmpty {
|
|
||||||
// mercury#53 (r5): display-only normalization — the stored
|
|
||||||
// rawValues keep their hyphen ("Pass-1 Done"); the rendered
|
|
||||||
// label uses the space form so it matches the Pass 1 / Pass 2
|
|
||||||
// vocabulary everywhere else.
|
|
||||||
Text(state.rawValue.uppercased().replacingOccurrences(of: "-", with: " "))
|
|
||||||
.font(.system(size: 11, weight: .medium, design: DesignTokens.mono))
|
|
||||||
.kerning(0.6)
|
|
||||||
// r6 (sol#6/21 — contrast final): group labels are
|
|
||||||
// informational meta — FULL muted ink, no wash.
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
// r6 ladder: full muted ink. r7 two-axis: x28 — the ONE
|
|
||||||
// indent step, shared with the head text and the row
|
|
||||||
// cards' inner content.
|
|
||||||
.padding(.leading, 28)
|
|
||||||
.padding(.top, 10)
|
|
||||||
.padding(.bottom, 1)
|
|
||||||
ForEach(grouped) { post in
|
|
||||||
postRow(post)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// #144 + mercury#54 (r4): a real field surface — surface fill + hairline
|
|
||||||
/// border on the column's chrome, taller than a text row; the placeholder
|
|
||||||
/// r5 (argon#44, mercury#52, sol#37): the insertion caret tints
|
|
||||||
/// terracotta (.tint on the field), and the small magnifier glyph sits at
|
|
||||||
/// the field's leading edge (icon→text spacing rides the HStack's 6pt);
|
|
||||||
/// the placeholder is the native prompt wearing the palette's muted ink
|
|
||||||
/// (the composer's pattern).
|
|
||||||
/// r8 (argon#6, mercury#12): focus draws a QUIET 1pt ring — accent at 0.6,
|
|
||||||
/// present but never the strongest saturation on screen.
|
|
||||||
private var searchField: some View {
|
|
||||||
HStack(spacing: 6) {
|
|
||||||
Image(systemName: "magnifyingglass")
|
|
||||||
.font(.system(size: 11))
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
TextField("Search posts", text: $query, prompt: Text("Search posts").foregroundStyle(DesignTokens.muted))
|
|
||||||
.textFieldStyle(.plain)
|
|
||||||
.font(.system(size: 12))
|
|
||||||
.focused($searchFocused)
|
|
||||||
.tint(DesignTokens.accent)
|
|
||||||
if isSearching {
|
|
||||||
Button {
|
|
||||||
query = ""
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "xmark.circle.fill")
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
.accessibilityLabel("Clear search")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 10)
|
|
||||||
.padding(.vertical, 8)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: 8)
|
|
||||||
.fill(DesignTokens.surface)
|
|
||||||
.overlay(
|
|
||||||
// r8 (argon#6, mercury#12): quiet focus — accent at 0.6,
|
|
||||||
// one step down from full strength.
|
|
||||||
RoundedRectangle(cornerRadius: 8)
|
|
||||||
.strokeBorder(
|
|
||||||
searchFocused ? DesignTokens.accent.opacity(0.6) : DesignTokens.border,
|
|
||||||
lineWidth: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
// r7 (mercury#18, argon#12 — two-axis ladder): the box spans the
|
|
||||||
// FULL padded column width at the PRIMARY inset — leading 14
|
|
||||||
// (aligned with the 'Posts' header text) to trailing 14 — the
|
|
||||||
// same edges the row cards lead at.
|
|
||||||
.padding(.horizontal, 14)
|
|
||||||
.padding(.vertical, 8)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Flat results, title matches first (stable partition — both halves
|
|
||||||
/// keep the scan's Finder order). Same row the sections render.
|
|
||||||
private func searchResults(_ found: [Post]) -> some View {
|
|
||||||
ScrollView {
|
|
||||||
LazyVStack(alignment: .leading, spacing: 4) {
|
|
||||||
Text("\(found.count) \(found.count == 1 ? "match" : "matches")")
|
|
||||||
.font(.system(size: 11, design: DesignTokens.mono))
|
|
||||||
.kerning(0.6)
|
|
||||||
// r6: full muted ink; r7 two-axis: x28 — the indent
|
|
||||||
// step, heading the flat result list exactly where
|
|
||||||
// group labels head their sections.
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
.padding(.leading, 28)
|
|
||||||
.padding(.top, 12)
|
|
||||||
.padding(.bottom, 1)
|
|
||||||
ForEach(found) { post in
|
|
||||||
postRow(post)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.bottom, 12)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var searchEmptyState: some View {
|
|
||||||
VStack(spacing: 8) {
|
|
||||||
Text("No matches")
|
|
||||||
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
|
|
||||||
Text("No piece's title or body contains “\(trimmedQuery)”.")
|
|
||||||
.font(.callout)
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
}
|
|
||||||
.padding(38)
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var emptyState: some View {
|
|
||||||
VStack(spacing: 8) {
|
|
||||||
Text("No posts yet")
|
|
||||||
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
|
|
||||||
Text("Posts in this Home's projects/ folders appear here.")
|
|
||||||
.font(.callout)
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
}
|
|
||||||
.padding(38)
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// #144: the title+body scan — a thin mount for the pure
|
|
||||||
/// `LibrarySearch` seam (title matches first, stable partition, both
|
|
||||||
/// halves keep the scan's Finder order; body via readBody — frontmatter
|
|
||||||
/// never searched), pinned by MuseionTests/LibrarySearchTests.swift.
|
|
||||||
/// The reader's per-piece cancellation check stops a superseded sweep's
|
|
||||||
/// body reads between files; the in-memory title walk itself completes
|
|
||||||
/// cheaply and the caller's guard discards its result. File scope since
|
|
||||||
/// r6 (PostsLibraryColumn hit its type-body ceiling).
|
|
||||||
///
|
|
||||||
/// ponytail: full-body re-read per sweep (folder(of:) re-walked per
|
|
||||||
/// piece — same unbounded-read ceiling as Post.scan, LearningsIndex
|
|
||||||
/// posture); a PostScanCache-style body memo if it ever measures hot.
|
|
||||||
private nonisolated func librarySearch(
|
|
||||||
candidates: [Post],
|
|
||||||
matching trimmed: String,
|
|
||||||
home: URL,
|
|
||||||
) async -> [Post] {
|
|
||||||
LibrarySearch.results(for: trimmed, in: candidates) { post in
|
|
||||||
guard !Task.isCancelled else { return nil }
|
|
||||||
return PostStore.readBody(id: post.id, home: home)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// r8 (argon#6, mercury#12 — the launch auto-focus ROOT CAUSE, killed at
|
|
||||||
/// the source): the search field is the window's first — and at launch,
|
|
||||||
/// only — text input, and AppKit assigns the window's initial first
|
|
||||||
/// responder to it when the window becomes key. That happens AFTER
|
|
||||||
/// onAppear, so the r6/r7 `searchFocused = false` writes were always
|
|
||||||
/// overridden (FocusState mirrors the assignment back as true: terracotta
|
|
||||||
/// ring + caret, the strongest element on screen). This invisible rider
|
|
||||||
/// rides the library column and, at the window's FIRST become-key,
|
|
||||||
/// resigns focus back to the window itself (`makeFirstResponder(nil)` —
|
|
||||||
/// the neutral state; nothing gains focus instead). ONCE per process: a
|
|
||||||
/// pane-switch remount must never steal a focus the user set on return.
|
|
||||||
/// The second, next-runloop resign covers an assignment that lands after
|
|
||||||
/// the notification (the PostEditorView layout-race precedent).
|
|
||||||
private struct LaunchFocusReset: NSViewRepresentable {
|
|
||||||
/// Process-wide once-flag — launch is a once-per-process event.
|
|
||||||
private static var hasRun = false
|
|
||||||
|
|
||||||
final class RiderView: NSView {
|
|
||||||
private var keyObserver: NSObjectProtocol?
|
|
||||||
|
|
||||||
override func viewDidMoveToWindow() {
|
|
||||||
if let keyObserver {
|
|
||||||
NotificationCenter.default.removeObserver(keyObserver)
|
|
||||||
}
|
|
||||||
keyObserver = nil
|
|
||||||
guard let window else { return }
|
|
||||||
keyObserver = NotificationCenter.default.addObserver(
|
|
||||||
forName: NSWindow.didBecomeKeyNotification,
|
|
||||||
object: window,
|
|
||||||
queue: .main,
|
|
||||||
) { _ in
|
|
||||||
MainActor.assumeIsolated {
|
|
||||||
// The observer is scoped to `window` (object:), so the
|
|
||||||
// notification carries nothing we don't already hold —
|
|
||||||
// reading `note` here would cross a Sendable boundary.
|
|
||||||
guard !LaunchFocusReset.hasRun else { return }
|
|
||||||
LaunchFocusReset.hasRun = true
|
|
||||||
window.makeFirstResponder(nil)
|
|
||||||
DispatchQueue.main.async { window.makeFirstResponder(nil) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeNSView(context _: Context) -> RiderView {
|
|
||||||
RiderView()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateNSView(_: RiderView, context _: Context) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// #108: Move to Project ask — radio list of the non-archived projects,
|
|
||||||
/// default = the piece's current project. Matches RenamePostSheet's shape.
|
|
||||||
struct MoveToProjectSheet: View {
|
|
||||||
let post: Post
|
|
||||||
let projects: [String]
|
|
||||||
let move: (String) -> Void
|
|
||||||
@Environment(\.dismiss) private var dismiss
|
|
||||||
@State private var target: String
|
|
||||||
|
|
||||||
init(post: Post, projects: [String], move: @escaping (String) -> Void) {
|
|
||||||
self.post = post
|
|
||||||
self.projects = projects
|
|
||||||
self.move = move
|
|
||||||
_target = State(initialValue: post.project)
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
|
||||||
Text("Move to Project")
|
|
||||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
|
||||||
Text("“\(post.title)” moves into the chosen project. The file stays post.md.")
|
|
||||||
.font(.callout)
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
Picker("Project", selection: $target) {
|
|
||||||
ForEach(projects, id: \.self) { name in
|
|
||||||
Text(name).tag(name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(.radioGroup)
|
|
||||||
HStack {
|
|
||||||
Spacer()
|
|
||||||
Button("Cancel", role: .cancel) { dismiss() }
|
|
||||||
.keyboardShortcut(.cancelAction)
|
|
||||||
Button("Move") {
|
|
||||||
move(target)
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
.disabled(target == post.project)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(20)
|
|
||||||
.frame(width: 360)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// #60: Explicit Rename dialog — asks the new Title (not a slug).
|
|
||||||
struct RenamePostSheet: View {
|
|
||||||
let rename: (String) -> Void
|
|
||||||
@Environment(\.dismiss) private var dismiss
|
|
||||||
@State private var title: String
|
|
||||||
|
|
||||||
init(post: Post, rename: @escaping (String) -> Void) {
|
|
||||||
self.rename = rename
|
|
||||||
_title = State(initialValue: post.title)
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
|
||||||
Text("Rename Post")
|
|
||||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
|
||||||
Text("The folder moves to match the new Title. The file stays post.md.")
|
|
||||||
.font(.callout)
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
TextField("Title", text: $title)
|
|
||||||
.textFieldStyle(.roundedBorder)
|
|
||||||
.onSubmit { confirm() }
|
|
||||||
HStack {
|
|
||||||
Spacer()
|
|
||||||
Button("Cancel", role: .cancel) { dismiss() }
|
|
||||||
.keyboardShortcut(.cancelAction)
|
|
||||||
Button("Rename", action: confirm)
|
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
.disabled(title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(20)
|
|
||||||
.frame(width: 360)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func confirm() {
|
|
||||||
let trimmed = title.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
guard !trimmed.isEmpty else { return }
|
|
||||||
rename(trimmed)
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One post row per the export: title + origin-only mono-11 meta (the Pass
|
|
||||||
/// State rides the uppercase group label above; it stays in the a11y label).
|
|
||||||
/// #108 (variant B): 2px accent edge bar on the leading side when selected
|
|
||||||
/// (`.vB .post-row[aria-current] { border-left-color: var(--accent) }`,
|
|
||||||
/// radius 0 8 8 0), and a muted ✳ suffix on outline pieces. Internal: the
|
|
||||||
/// Archive pane reuses it.
|
|
||||||
struct LibraryPostRow: View {
|
|
||||||
let post: Post
|
|
||||||
let selected: Bool
|
|
||||||
let select: () -> Void
|
|
||||||
@State private var hover = false
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
// `.vB .post-row { border-left: 2px solid transparent;
|
|
||||||
// border-radius: 0 8px 8px 0 }` — every row: leading corners square
|
|
||||||
// (the 2px strip below), trailing rounded 8. Only the strip's
|
|
||||||
// VISIBILITY changes on selection.
|
|
||||||
let shape = UnevenRoundedRectangle(cornerRadii: .init(bottomTrailing: 8, topTrailing: 8))
|
|
||||||
return Button(action: select) {
|
|
||||||
HStack(spacing: 0) {
|
|
||||||
// The leading strip is always 2px wide so hover/selection
|
|
||||||
// never shifts the title. r6 (mercury#49/52, argon#13):
|
|
||||||
// the shared SelectedRowStrip capsule — accent, radius-1
|
|
||||||
// ends, vertically inset 6pt (was 3) so it sits INSIDE
|
|
||||||
// the card, never pasted on its square leading edge.
|
|
||||||
SelectedRowStrip()
|
|
||||||
.opacity(selected ? 1 : 0)
|
|
||||||
VStack(alignment: .leading, spacing: 5) {
|
|
||||||
HStack(alignment: .firstTextBaseline, spacing: 0) {
|
|
||||||
Text(post.title)
|
|
||||||
if post.type == .outline {
|
|
||||||
Text(" ✳")
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ui-polish r8: serif-13 per the row contract — `.callout`
|
|
||||||
// was the system sans design (the r6/r7 councils pixel-
|
|
||||||
// verified sans glyphs on the Archive rows).
|
|
||||||
.font(.system(size: 13, weight: .semibold, design: DesignTokens.serif))
|
|
||||||
.lineLimit(1)
|
|
||||||
.truncationMode(.tail)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
// Origin only — the Pass State already rides the uppercase
|
|
||||||
// group label above (it stays in the accessibility label).
|
|
||||||
// r7: the status micro-label sits INSIDE the row's content
|
|
||||||
// padding — same x as the title, never flush with the edge.
|
|
||||||
Text(post.origin.rawValue)
|
|
||||||
.font(.system(size: 11, design: DesignTokens.mono))
|
|
||||||
.foregroundStyle(DesignTokens.muted)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 12)
|
|
||||||
.padding(.vertical, 10)
|
|
||||||
}
|
|
||||||
.clipShape(shape)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.foregroundStyle(DesignTokens.foreground)
|
|
||||||
.background {
|
|
||||||
if selected || hover {
|
|
||||||
// r8 (mercury#11): the selected row DROPS its gray outline —
|
|
||||||
// fill + accent capsule read as ONE shape; stacking fill +
|
|
||||||
// outline + capsule competed. Hover keeps its borderless
|
|
||||||
// 0.06 wash exactly as before.
|
|
||||||
shape
|
|
||||||
.fill(selected ? DesignTokens.foreground.opacity(0.08) : DesignTokens.foreground.opacity(0.06))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// r7 (mercury#18, argon#12 — two-axis ladder): the row CARD
|
|
||||||
// leads at the PRIMARY inset (x14, the 'Posts' header text's
|
|
||||||
// edge); its INNER content (title + status micro-label, strip
|
|
||||||
// 2 + padding 12) lands at x28 — the ONE indent step, shared
|
|
||||||
// with the head text and the group labels. No other x-axis
|
|
||||||
// exists in the column. Vertical padding stays the content
|
|
||||||
// VStack's constant 10 whether or not the row shows its strip.
|
|
||||||
.padding(.horizontal, 14)
|
|
||||||
.onHover { hover = $0 }
|
|
||||||
// help sits on the row — the ✳ span isn't individually hoverable in
|
|
||||||
// SwiftUI (prototype: `title="outline"` on the star).
|
|
||||||
.help(post.type == .outline ? "\(post.title) — outline" : post.title)
|
|
||||||
.accessibilityLabel("\(post.title), \(post.passState.rawValue), origin \(post.origin.rawValue)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user