Build the trash quasi-lane

Deletion becomes a two-stage, Finder-style story. File > Delete and
plain Backspace tombstone the live selection; View > Show Trash (no
chord — Shift-Cmd-T stays with the system's tab bar) reveals the
quasi-lane: trailing, one fixed width unit consumed only while shown,
hatched dimmed header, count badge, no new-card button, exempt from
resize and reorder alike. Its contents are a pure view over the
snapshot — the deterministic sort (deleted newest first, folder-name
ties, unparseable stamps oldest) interleaves card rows with a
tombstoned lane's single entry, whose count names what Put Back
returns; the ancestor walk is absolute, so an own-flag card beneath a
tombstoned lane has no row and recovery is deliberately two steps.
Put Back twins Delete on Cmd-Backspace with validation enabling
exactly one; restore fidelity is byte-perfect because nothing ever
moved. Delete Immediately confirms exactly where loss is real (every
board is mode-none today; the predicate names the git carve-out for
m7), Empty Trash always confirms with the true whole-board count,
and dragging a tombstoned card onto a live lane restores it there —
positional drops and cross-board locality arrive with m5's machinery.
The banner's delete phrasing drops "move to the trash" per the naming
constraint: board deletion says Delete, "Move to Trash" stays
reserved for the system Trash. 47 new tests.

Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
2026-07-27 15:38:34 -04:00
parent aa6aaf2a11
commit 2090d742b9
14 changed files with 2428 additions and 18 deletions
+8 -4
View File
@@ -422,9 +422,13 @@ public final class BannerCenter {
///
/// Titles are quoted where the operation carries one and the phrasing stays graceful where it
/// does not: the enum knows an item's title, never its *kind*, so an untitled failure says
/// "the item" rather than guessing "card" and being wrong about a lane. The trash verbs are
/// Finder's, matching the commands the user pressed (03-board-ui.md § Trash): Move to Trash,
/// Put Back, Delete Immediately.
/// "the item" rather than guessing "card" and being wrong about a lane.
///
/// The trash verbs match the commands the user pressed **Delete**, Put Back, Delete
/// Immediately which is 03-board-ui.md § Trash's naming constraint, settled with the trash UI
/// copy: "Finder's 'Move to Trash' phrasing is reserved for the system Trash; board deletion says
/// 'Delete'". A banner saying a card could not be *moved to the trash* would name the wrong one
/// of the app's two trashes (the card window's attachment Remove is the other).
private nonisolated static func actionPhrase(for operation: WriteOperation) -> String {
switch operation {
case .createBoard:
@@ -440,7 +444,7 @@ public final class BannerCenter {
case let .copy(title):
if let title { "Couldn't copy '\(title)'" } else { "Couldn't copy the item" }
case let .delete(title):
if let title { "Couldn't move '\(title)' to the trash" } else { "Couldn't move the item to the trash" }
if let title { "Couldn't delete '\(title)'" } else { "Couldn't delete the item" }
case let .restore(title):
if let title { "Couldn't put '\(title)' back" } else { "Couldn't put the item back" }
case let .purge(title):
+182
View File
@@ -1070,6 +1070,188 @@ public final class BoardStore {
}
}
// MARK: - The trash
/// Whether physically removing an item on this board destroys the only copy of it and
/// therefore whether Delete Immediately stands an alert between one keystroke and unrecoverable
/// deletion (03-board-ui.md § Trash, "Delete Immediately confirms exactly where the loss is
/// real").
///
/// **Every board is `true` today**, because every board is history mode *none*: nothing in the
/// app keeps a second copy, so a purge is final everywhere.
///
// m7-git: git boards answer `false` here "on git boards it acts immediately, since the content
// remains reachable in history" (06-history-undo.md's delete-never-forgets). Repo-nested boards
// stay `true` alongside mode none: the app manages no history for them either. The named
// predicate exists now so the committer card changes one expression rather than hunting the
// confirmation logic out of two menu items and an alert.
public var purgeIsUnrecoverable: Bool { true }
/// Tombstones the current selection File Delete and its plain- grammar twin
/// (04-interactions.md The map, 11-command-nexus.md).
///
/// A convenience over `delete(_:)` so the two call sites cannot disagree about *what* the
/// command acts on.
public func deleteSelection() {
delete(selection.ids)
}
/// Tombstones every live item in `ids` cards or lanes, in one bracket.
///
/// **One `performWrite` whatever the set's size**, matching the style batch's rule and for its
/// reason: one gesture, one app-mediated reload, and (on git boards) one commit rather than N.
/// A lane's tombstone rewrites only the lane's own `index.md` hiding the subtree is the
/// renderer's ancestor walk, not a stored flag (`BoardWriter.deleteItem`).
///
/// **Tombstoned ids are silently skipped**, not refused: the paths are resolved on the live side
/// only, so a selection the next reload will drop writes nothing rather than re-stamping a
/// `deleted:` that is already there. An empty resolution never opens the bracket at all.
///
/// The selection is **cleared**, not moved to a successor. 04-interactions.md The map asks for
/// the Finder-style successor sibling ("repeated walks down a lane"), which needs the
/// navigation order the keyboard grammar defines that is m5's card. Clearing is the honest
/// interim: what was selected renders nowhere now, and the reload's resolve rule would empty the
/// set a moment later anyway.
public func delete(_ ids: Set<ItemID>) {
let folders = TrashModel.paths(of: ids, on: .live, in: snapshot).map { $0.folder(under: rootURL) }
guard !folders.isEmpty else { return }
try? performWrite { () throws(BoardWriteError) -> Void in
for folder in folders {
try BoardWriter.deleteItem(at: folder)
}
}
// m5-keyboard: the successor-selection grammar replaces this line.
clearSelection()
}
/// Put Back: removes `deleted:` from every tombstoned item in `ids`, in one bracket
/// (03-board-ui.md § Trash).
///
/// **Restore fidelity is perfect because nothing ever moved** the item re-enters the visible
/// set at its recorded `order` among its current siblings, and the folder is exactly where it
/// has been all along (`BoardWriter.restoreItem`).
///
/// **Putting back a lane splits its contents by flag for free.** The write is the lane's own
/// `index.md` and nothing else, so cards hidden *with* the lane return with it while cards
/// carrying their own `deleted:` stay tombstoned and their rows reappear in the trash, which
/// is exactly the two-step recovery the design settled on.
///
/// A card whose lane is itself tombstoned cannot be reached this way through the UI (it has no
/// row `TrashModel.entries`), but the path resolution admits it, and the outcome is the pure
/// view's honest one: the key is removed, and the card still renders nowhere because its lane
/// is still tombstoned. Putting the lane back then shows it.
///
/// The selection is deliberately left alone: the restored items flip liveness, and the reload's
/// resolve rule ejects them from a `.trashed` set as a vanish the same silent shrink an
/// external restore would produce.
public func putBack(_ ids: Set<ItemID>) {
let folders = TrashModel.paths(of: ids, on: .trashed, in: snapshot).map { $0.folder(under: rootURL) }
guard !folders.isEmpty else { return }
try? performWrite { () throws(BoardWriteError) -> Void in
for folder in folders {
try BoardWriter.restoreItem(at: folder)
}
}
}
/// Delete Immediately : physically removes every tombstoned item in `ids` (03-board-ui.md §
/// Trash), in one bracket.
///
/// **The confirmation is not here.** Whether the loss is real is `purgeIsUnrecoverable`'s
/// question and the alert is the window's; a store method that put up its own dialog could not
/// be driven from a test, and the same purge is reached by two surfaces (the menu item and the
/// trash row's context menu) that must not each grow their own copy of the rule.
///
/// Purging a **lane** takes its whole folder every card inside it, tombstoned or not. That is
/// what the lane entry subsuming its subtree means on disk.
public func deleteImmediately(_ ids: Set<ItemID>) {
let folders = TrashModel.paths(of: ids, on: .trashed, in: snapshot).map { $0.folder(under: rootURL) }
guard !folders.isEmpty else { return }
try? performWrite { () throws(BoardWriteError) -> Void in
for folder in folders {
try BoardWriter.purgeItem(at: folder)
}
}
// Nothing the set named exists any more, on either side of the boundary unlike Put Back,
// where the items merely changed sides, there is no vanish for the reload to notice on the
// trashed side that would not equally be a vanish here.
clearSelection()
}
/// Empty Trash : purges **every** tombstone on the board, in one bracket.
///
/// **Whole-trash scope, search-independent** (03-board-ui.md § Trash, settled): the targets come
/// from the snapshot, never from the filtered view "a bulk command about the trash itself never
/// silently narrows to the visible subset". The filter does not reach this method at all, which
/// is the strongest form of that guarantee.
///
/// Cards carrying their own `deleted:` under a tombstoned lane go too, without being listed:
/// they live inside the lane folder this removes (`TrashModel.emptyTrashTargets`).
public func emptyTrash() {
let folders = TrashModel.emptyTrashTargets(in: snapshot).map { $0.folder(under: rootURL) }
guard !folders.isEmpty else { return }
try? performWrite { () throws(BoardWriteError) -> Void in
for folder in folders {
try BoardWriter.purgeItem(at: folder)
}
}
clearSelection()
}
/// Drag-to-restore: a tombstoned card row dropped over a live lane comes back **into that lane**
/// (03-board-ui.md § Trash, 04-interactions.md The trash).
///
/// Two writes in **one bracket**, and the order is load-bearing: `restoreItem` first the folder
/// is still where the trash row said it was then, only when the destination differs, the move.
/// Doing it the other way round would have the second call chasing a folder the first one had
/// already relocated.
///
/// **Same lane is a plain Put Back**: the key is removed and nothing else is touched, so the card
/// returns at its recorded `order` rather than at the bottom. "Folder moved only if the
/// destination lane differs" is the design's own wording, and the position-perfect restore is the
/// point of the trash being a pure view.
///
// m5-drag: two things arrive with the drag card's `DropSlot` port. (1) The **positional** drop
// the design restores "at the drop position", and the append below is the interim; the rank comes
// from `Ranks.insertionRank` over the destination's visible cards, exactly as `commitPlaceholder`
// computes it. (2) **Cross-board locality** a drop on another board is a live *copy* by
// default with the tombstoned original staying put, and -drag forces the true restore-move.
// Both need the drag controller's target vocabulary; this method is deliberately within-board.
///
/// Silent no-ops, all of them the reload being the authority rather than this gesture: a
/// destination lane that is gone or tombstoned, a card that is not a trash row (its own flag
/// unset, or its lane tombstoned so it has no row to drag), and an id that names nothing.
public func restoreByDrag(cardID: ItemID, intoLane laneID: ItemID) {
guard snapshot.lanes.contains(where: { $0.id == laneID && !$0.isDeleted }),
let source = snapshot.lanes.first(where: { lane in
!lane.isDeleted && lane.cards.contains { $0.id == cardID && $0.isDeleted }
})
else { return }
let root = rootURL
let cardFolder = TrashModel.ItemPath(laneID: source.id, cardID: cardID).folder(under: root)
let destination = root.appendingPathComponent(laneID.rawValue, isDirectory: true)
let crossesLanes = source.id != laneID
try? performWrite { () throws(BoardWriteError) -> Void in
try BoardWriter.restoreItem(at: cardFolder)
guard crossesLanes else { return }
// `order: nil` is the Writer's own append computed over the destination's *visible*
// siblings, which the arriving card is not yet among.
_ = try BoardWriter.moveItem(
at: cardFolder,
toParent: destination,
sourceBoardRoot: root,
destinationBoardRoot: root,
order: nil
)
}
}
// MARK: - Selection (delegated)
// The thin pass-throughs to `transient`, and the only ones.
+396
View File
@@ -0,0 +1,396 @@
import Foundation
// MARK: - TrashEntry
/// One row of the trash quasi-lane (03-board-ui.md § Trash).
///
/// **Two cases, not one**, because a tombstoned lane is not a tombstoned card wearing a different
/// symbol: it is "a single restorable entry" that *subsumes* everything beneath it, and Put Back on
/// it "returns [the lane] whole, cards and all" (04-interactions.md The trash). The card count it
/// carries is part of the entry rather than something the row re-derives, because the rule for what
/// that number means is subtle enough to want one home see `TrashModel.entries(of:)`.
///
/// The card case carries its lane's id for the same reason `BoardStore.liveItem` returns two
/// components rather than a URL: the row's folder is `<root>/<lane>/<card>`, and the root is the
/// store's to supply a mid-session folder rename may have moved it.
public enum TrashEntry: Identifiable, Sendable, Equatable {
/// A card carrying its own `deleted:` under a **live** lane. A card whose lane is tombstoned
/// never becomes one of these see `TrashModel.entries(of:)`'s ancestor walk.
case card(Card, laneID: ItemID)
/// A tombstoned lane, and how many of its cards Put Back would return to the board.
case lane(Lane, returningCardCount: Int)
public var id: ItemID {
switch self {
case let .card(card, _): card.id
case let .lane(lane, _): lane.id
}
}
/// The title as written, or `nil` for an untitled item "Untitled" is a rendering, never a
/// value (03-board-ui.md § Card face).
public var title: String? {
switch self {
case let .card(card, _): card.title.value
case let .lane(lane, _): lane.title.value
}
}
/// Which kind of row this is the axis 04-interactions.md The trash makes a selection
/// homogeneous over ("a selection never mixes card entries and lane entries").
public var isLaneEntry: Bool {
if case .lane = self { return true }
return false
}
/// The `icon` field this row renders, so the row's symbol obeys the same lenient rule the board
/// face does (`ItemSymbol`).
public var icon: FieldValue<String> {
switch self {
case let .card(card, _): card.icon
case let .lane(lane, _): lane.icon
}
}
/// Where this row's folder sits under the board root.
public var path: TrashModel.ItemPath {
switch self {
case let .card(card, laneID): TrashModel.ItemPath(laneID: laneID, cardID: card.id)
case let .lane(lane, _): TrashModel.ItemPath(laneID: lane.id, cardID: nil)
}
}
}
// MARK: - TrashModel
/// The trash quasi-lane's contents, as a pure function of a snapshot (`TrashModelTests`)
/// 03-board-ui.md § Trash's Contents rules with nothing else mixed in.
///
/// **Pure because the trash is a pure view.** "Tombstoned cards keep their `deleted:` key and stay
/// exactly where they are on disk; nothing about the storage schema is trash-specific", so there is
/// no trash *state* anywhere only this derivation, re-run against whatever snapshot is current.
/// A reload therefore rebuilds the rows for free, exactly as it rebuilds the lanes.
///
/// The three rules it owns, each of which the design settles explicitly:
///
/// 1. **The absolute ancestor walk.** A tombstoned lane's entry subsumes everything beneath it "a
/// card that carries its own `deleted:` under a tombstoned lane has **no row of its own**". There
/// is no trash carve-out from 01-storage-format.md's consumer rule.
/// 2. **The returning count.** A lane entry's number "counts what Put Back returns to the board
/// cards without their own flag; individually tombstoned descendants aren't in that number, since
/// they come back to the *trash*".
/// 3. **The deterministic sort.** Newest `deleted` first; ties by folder name ascending; an
/// unparseable stamp sorts as *oldest*, after every dated entry, folder-name-ordered among its
/// kind; lane entries interleave in the same single ordering by their own stamp. The order is
/// load-bearing for input "arrow walks, -ranges, and the rubber band all read it" so it is
/// total, not merely stable.
public enum TrashModel {
// MARK: - Where a row lives
/// An item's folder, as its identity components rather than as a URL.
///
/// Same shape and same reasoning as `BoardStore.liveItem`'s return: the caller builds the URL off
/// the store's *current* `rootURL`, so a board renamed or moved mid-session writes at the new
/// location (02-architecture.md § Write-failure surfacing).
public struct ItemPath: Sendable, Equatable {
public let laneID: ItemID
/// `nil` for a lane the path is then the lane folder itself.
public let cardID: ItemID?
public init(laneID: ItemID, cardID: ItemID?) {
self.laneID = laneID
self.cardID = cardID
}
public var isLane: Bool { cardID == nil }
/// This path resolved under a board root.
public func folder(under root: URL) -> URL {
var url = root.appendingPathComponent(laneID.rawValue, isDirectory: true)
if let cardID {
url.append(component: cardID.rawValue, directoryHint: .isDirectory)
}
return url
}
}
// MARK: - Entries
/// The trash's rows, in the order the quasi-lane shows them.
///
/// The walk is one level deep because the tree is (01-storage-format.md § Fractal layout), and
/// the branch on `lane.isDeleted` *is* the ancestor walk: a tombstoned lane contributes exactly
/// one entry and its cards contribute none, whatever their own flags say.
public static func entries(of snapshot: BoardModel) -> [TrashEntry] {
var rows: [Row] = []
for lane in snapshot.lanes {
if lane.isDeleted {
// Rule 2: only the cards *without* their own flag come back with the lane. The ones
// that carry a flag stay tombstoned and get their rows back in the trash which is
// why Put Back on such a card is deliberately two steps.
let returning = lane.cards.filter { !$0.isDeleted }.count
rows.append(Row(
entry: .lane(lane, returningCardCount: returning),
deleted: lane.deleted.value,
name: lane.id.rawValue
))
continue
}
for card in lane.cards where card.isDeleted {
rows.append(Row(
entry: .card(card, laneID: lane.id),
deleted: card.deleted.value,
name: card.id.rawValue
))
}
}
return rows.sorted(by: isOrdered).map(\.entry)
}
/// Whether the board has anything in its trash at all the "non-empty" half of Empty Trash's
/// menu validation, which "reads the board's tombstones, not the filtered view" (03 Trash).
///
/// Cheaper than building the entries and used where only the answer matters.
public static func isEmpty(_ snapshot: BoardModel) -> Bool {
!snapshot.lanes.contains { lane in
lane.isDeleted || lane.cards.contains(where: \.isDeleted)
}
}
/// One entry's sort inputs, kept beside it so the comparator never re-reads the model.
private struct Row {
let entry: TrashEntry
/// The parsed `deleted` stamp, or `nil` when the value is present but unparseable
/// 01-storage-format.md's unusable-timestamp rule, which still deletes (presence, not
/// validity) but supplies no position in time.
let deleted: Date?
/// The folder name, byte-for-byte the tie-break the loader's display order already uses
/// (`Ranks.sortedForDisplay`, `name: { $0.id.rawValue }`), so the trash breaks ties the same
/// way the board does.
let name: String
}
/// The sort, stated once: newest first among dated entries, then every undated entry.
///
/// **Undated sorts oldest, not first.** "A corrupt stamp must not outrank fresh deletions for the
/// trash's most prominent rows" so an unparseable value loses to every real timestamp, however
/// old, and orders by folder name among its own kind.
private static func isOrdered(_ lhs: Row, _ rhs: Row) -> Bool {
switch (lhs.deleted, rhs.deleted) {
case let (left?, right?):
return left == right ? lhs.name < rhs.name : left > right
case (.some, nil):
return true
case (nil, .some):
return false
case (nil, nil):
return lhs.name < rhs.name
}
}
// MARK: - Paths for the trash's writes
/// The folders `ids` names, in display order, restricted to one **effective** liveness side.
///
/// The universe rule is `ItemReferenceSet.idUniverse`'s, spelled here in terms of paths rather
/// than ids because a write needs to know *where* the item is: a lane contributes itself on the
/// side its own flag names, and a card on the side `lane.isDeleted || card.isDeleted` names.
///
/// Display order lanes left to right, each lane then its cards rather than the caller's set
/// iteration order, which is not an order at all: a batch that fails partway must fail the same
/// way twice (`BoardStore.styleSubjects` makes the same choice for the same reason).
public static func paths(of ids: Set<ItemID>, on side: Liveness, in snapshot: BoardModel) -> [ItemPath] {
guard !ids.isEmpty else { return [] }
var result: [ItemPath] = []
for lane in snapshot.lanes {
let laneSide = Liveness(isDeleted: lane.isDeleted)
if laneSide == side, ids.contains(lane.id) {
result.append(ItemPath(laneID: lane.id, cardID: nil))
}
for card in lane.cards
where Liveness(isDeleted: lane.isDeleted || card.isDeleted) == side && ids.contains(card.id) {
result.append(ItemPath(laneID: lane.id, cardID: card.id))
}
}
return result
}
/// Every folder Empty Trash removes "emptying purges every tombstone on the board, filter or
/// no filter" (03 Trash).
///
/// **A tombstoned lane contributes only itself**, and that is not an omission: removing the lane
/// folder removes the tree beneath it, own-flag cards included. Listing those cards as well would
/// be redundant purges of paths the first removal already took (harmless `purgeItem` treats a
/// folder that is already gone as success but noise).
public static func emptyTrashTargets(in snapshot: BoardModel) -> [ItemPath] {
var result: [ItemPath] = []
for lane in snapshot.lanes {
if lane.isDeleted {
result.append(ItemPath(laneID: lane.id, cardID: nil))
continue
}
for card in lane.cards where card.isDeleted {
result.append(ItemPath(laneID: lane.id, cardID: card.id))
}
}
return result
}
// MARK: - Counts and phrasing
/// How many lane entries and card entries a set of entries holds the confirmation dialogs'
/// only input beyond the item titles.
public struct EntryCounts: Sendable, Equatable {
public var lanes: Int = 0
public var cards: Int = 0
public var total: Int { lanes + cards }
public var isEmpty: Bool { total == 0 }
}
public static func counts(of entries: [TrashEntry]) -> EntryCounts {
var counts = EntryCounts()
for entry in entries {
if entry.isLaneEntry { counts.lanes += 1 } else { counts.cards += 1 }
}
return counts
}
/// The counts a set of `ItemPath`s describes the same two numbers, from the shape the write
/// path actually carries.
public static func counts(of paths: [ItemPath]) -> EntryCounts {
var counts = EntryCounts()
for path in paths {
if path.isLane { counts.lanes += 1 } else { counts.cards += 1 }
}
return counts
}
/// "2 lanes and 3 cards", "41 cards", "1 lane" 06-history-undo.md's **plural folding** applied
/// to a mixed trash selection.
///
/// An empty count reads "nothing", which no caller renders: both confirmations refuse to open on
/// an empty scope. It is spelled anyway so the function is total.
public static func phrase(_ counts: EntryCounts) -> String {
switch (counts.lanes, counts.cards) {
case (0, 0): "nothing"
case let (0, cards): plural(cards, "card")
case let (lanes, 0): plural(lanes, "lane")
case let (lanes, cards): "\(plural(lanes, "lane")) and \(plural(cards, "card"))"
}
}
private static func plural(_ count: Int, _ noun: String) -> String {
"\(count) \(noun)\(count == 1 ? "" : "s")"
}
// MARK: - Confirmations
/// A purge confirmation's three strings, built once and rendered by the window's alert.
///
/// A value rather than a view so the phrasing rules plural folding, naming a sole item, the
/// lane caveat, and whether the loss is actually irreversible are testable without an alert on
/// screen (`TrashModelTests`).
public struct PurgePrompt: Sendable, Equatable {
public let title: String
public let message: String
public let confirmTitle: String
}
/// Delete Immediately's alert "the alert stands between one keystroke and unrecoverable
/// deletion" (03-board-ui.md § Trash).
///
/// A sole item is **named**; several fold into counts. `nil` when the ids name nothing
/// tombstoned, which is also the command's own refusal so the prompt and the action can never
/// disagree about whether there is anything to purge.
public static func purgePrompt(
for ids: Set<ItemID>,
in snapshot: BoardModel,
unrecoverable: Bool
) -> PurgePrompt? {
let targets = paths(of: ids, on: .trashed, in: snapshot)
guard !targets.isEmpty else { return nil }
let counts = counts(of: targets)
let subject: String
if targets.count == 1, let only = targets.first {
subject = "\u{201C}\(displayName(of: only, in: snapshot))\u{201D}"
} else {
subject = phrase(counts)
}
return PurgePrompt(
title: "Permanently delete \(subject)?",
message: message(lanes: counts.lanes, unrecoverable: unrecoverable),
confirmTitle: "Delete"
)
}
/// Empty Trash's alert **always shown** ("bulk scope, not per-item recoverability, is what it
/// guards"), and always naming the **true count**: every tombstone on the board, never the
/// filtered view.
///
/// Counts rather than names even for a single entry, because the command is about the trash
/// rather than about an item: "Permanently delete 41 cards" is the design's own example phrasing
/// (06-history-undo.md's plural folding).
public static func emptyTrashPrompt(in snapshot: BoardModel, unrecoverable: Bool) -> PurgePrompt? {
let counts = counts(of: emptyTrashTargets(in: snapshot))
guard !counts.isEmpty else { return nil }
return PurgePrompt(
title: "Permanently delete \(phrase(counts))?",
message: message(lanes: counts.lanes, unrecoverable: unrecoverable),
confirmTitle: "Delete"
)
}
/// The alert's body: what a lane takes with it, and whether any of it comes back.
///
/// The lane sentence is not decoration a lane entry's row says "3 cards" (what Put Back would
/// return), while purging the lane folder takes *every* card inside it, individually tombstoned
/// ones included. That gap is exactly what a confirmation is for.
private static func message(lanes: Int, unrecoverable: Bool) -> String {
var parts: [String] = []
if lanes > 0 {
parts.append("Deleting a lane also deletes every card inside it.")
}
// m7-git: on a git board the content stays reachable in history, so the second sentence is
// the honest one and Delete Immediately does not confirm there at all
// (`BoardStore.purgeIsUnrecoverable`).
parts.append(unrecoverable
? "This can\u{2019}t be undone."
: "The board\u{2019}s history still has them.")
return parts.joined(separator: " ")
}
/// What to call an item in a prompt its title, or the "Untitled" rendering.
///
/// Total by construction: a path whose item has gone since the prompt was asked for reads
/// "Untitled" rather than failing, which is the same shrug every other vanished-target rule in
/// the app gives.
private static func displayName(of path: ItemPath, in snapshot: BoardModel) -> String {
guard let lane = snapshot.lanes.first(where: { $0.id == path.laneID }) else { return "Untitled" }
guard let cardID = path.cardID else { return lane.title.value ?? "Untitled" }
return lane.cards.first { $0.id == cardID }?.title.value ?? "Untitled"
}
// MARK: - Menu validation
/// Whether File Delete has something to tombstone a **live**, non-empty selection that still
/// names something the board renders.
///
/// The liveness side is the whole of the binary: "menu validation stays binary Delete for live
/// selections, Put Back / Delete Immediately for tombstoned ones" (04 The trash). The
/// resolution against the snapshot is what keeps a selection the next reload will drop from
/// enabling an item that would write nothing.
public static func canDelete(selection: ItemReferenceSet, in snapshot: BoardModel) -> Bool {
selection.liveness == .live && !paths(of: selection.ids, on: .live, in: snapshot).isEmpty
}
/// Whether File Put Back and File Delete Immediately have something to act on the exact
/// mirror of `canDelete`, which is what makes the two twins enable exactly one of themselves.
public static func canActOnTrash(selection: ItemReferenceSet, in snapshot: BoardModel) -> Bool {
selection.liveness == .trashed && !paths(of: selection.ids, on: .trashed, in: snapshot).isEmpty
}
}