Cotton code
263 lines · 10.3 KB · SwiftRaw
// The + fan's rows — pure data, and the fan's whole vocabulary.//// The page-and-pill spec (2026-08-17, §"The dock") states it:////   > ***+** (circle, left): structured add fan — Todo · Event · Note · Contact//   > · Scan … Each item opens the existing creation surface. + is the//   > deterministic lane; the pill is the natural-language lane.*//// The spec named five; each tool that ships a creation surface has added its// own since. Deterministic is the whole point: the fan never asks a model// anything. Each row is a plain push onto a creation surface that already// exists, so nothing here is a new way to make a record — it is a shorter way// to reach the one the tool already owns.//// A FUNCTION, not a constant, exactly as the TypeScript is one. There the// reason is that Lingui's `t` macro resolves at call time; here it is that// `CottonStrings` resolves against the catalogue at call time too, and that the// Event row is anchored on a day key the CALLER supplies. Building the list per// draw is what keeps the words and the date honest.//// ## The glyphs are LUCIDE names, as data//// Every row carries the kebab-case lucide name the glyph table already agreed,// and the view calls `Glyph.symbol(_:)` — the ONE translation to SF Symbols.// See `Format/Glyph.swift` for why the tables keep the app's own vocabulary// rather than being rewritten in dot-case at every call site. All the// names below are already in that table, so this port added none.//// ## The query flag//// A new todo is `/todos?new=1`: the timeline opens its creation sheet.// Money is captured through the input; its old deposit form and fan row are gone.////// There is no Scan row: it pushed a "not in this build" page, and that page was// deleted (2026-09-14).//// ## The two rows that make nothing//// **Picture and Camera** put a picture on the thought being written (store// schema 36 — a bug report from the phone is one thought with a screenshot).// They are the fan's one exception to "a push onto a creation surface": the// thing being made is the capture already under the thumbs, so the rows open// the photo library or the camera over it and the picture lands on the draft.// Both are `.sheet` rows for that reason — a system sheet the HOST raises —// and a host with no draft to put a picture on is never offered them// (`canAttachPictures`), exactly as a host that cannot write a memory is// never offered Memory. The camera is a CAPABILITY, not a platform: a machine// with no camera surface (the Mac) is simply offered no Camera row.//// **Record and Import came back** when the phone regained its meetings// producer. Record pushes `/meetings/record`, which is the meetings LIST with// the recorder sheet up — the same act as the list's own "Record a meeting".// Import pushes `/meetings?import=1` — a flag rather than a route, exactly as// the Todo and Money rows carry theirs, because importing is the meetings LIST// raising a file picker and not a page of its own. The route table is// untouched by either: `/meetings/record` is in it and a query parameter is// not a path.import CottonKitimport Foundation/// A creation surface the HOST owns, named rather than routed.////// A project's memory sentence is written where the project is. There is no/// "new memory" route to push, and inventing one would be a second way to do/// the thing (chain-1 ruling R11). The photo library and the camera are the/// system's own pickers, raised by the capture surface over the draft they/// put a picture on.public enum AddFanHosted: String, Sendable, Equatable {    case memory    case photoLibrary    case camera}/// What a row DOES: push a creation surface that already exists — the/// deterministic lane, unchanged — or open what the host owns.public enum AddFanDestination: Sendable, Equatable {    case push(Route)    case hosted(AddFanHosted)}/// One row of the fan: what the reader sees, what identifies it, and what it/// does.public struct AddFanAction: Sendable, Equatable, Identifiable {    /// Stable identity — the TypeScript's `key`, which is also the suffix of    /// the row's testID there and the accessibility identifier here.    public let key: String    /// The verb-less noun the user reads — glyph plus word in ink, never an    /// emoji.    public let label: String    /// The kebab-case lucide glyph, as data. `Glyph.symbol(icon)` is what a    /// view draws.    public let icon: String    public let destination: AddFanDestination    public var id: String { key }    public init(key: String, label: String, icon: String, destination: AddFanDestination) {        self.key = key        self.label = label        self.icon = icon        self.destination = destination    }}/// The fan's rows, in the TypeScript's own order.////// `canAddMemory` means the host can open its own creation sheet. Only the/// project page can today: Home's dock is capture and Me's dock is the/// one-sentence memory composer, so a Memory row on either would be a second/// way to write the same sentence. Seven rows without it, eight with it.////// `today` is the day key (`YYYY-MM-DD`) the Event row anchors on — the/// TypeScript reads `todayKey()` inside the function and this takes it as an/// argument instead, because a list built off the wall clock is a list no test/// can pin to a date.////// `canAttachPictures` means the host holds a DRAFT a picture can go on — the/// capture surface does, Home's own fan does not — and earns the Picture row;/// `hasCamera` earns the Camera row beside it. Both lead the fan when present:/// they act on the thought under the thumbs, where every other row leaves it.public func addFanActions(    today: String,    canAddMemory: Bool = false,    canAttachPictures: Bool = false,    hasCamera: Bool = false) -> [AddFanAction] {    var rows: [AddFanAction] = []    if canAttachPictures {        rows.append(            AddFanAction(                key: "picture",                // The noun, as every row is — what goes on the thought, not                // the library it comes out of.                label: ShellLines.line("capture", "fan.picture"),                icon: "image",                destination: .hosted(.photoLibrary)            )        )        if hasCamera {            rows.append(                AddFanAction(                    key: "camera",                    label: ShellLines.line("capture", "fan.camera"),                    icon: "camera",                    destination: .hosted(.camera)                )            )        }    }    if canAddMemory {        rows.append(            AddFanAction(                key: "memory",                label: ShellLines.line("capture", "fan.memory"),                // One glyph for every memory since schema v14 — the same                // picture the cards wear, because there are no categories left                // to tell apart.                icon: "quote",                destination: .hosted(.memory)            )        )    }    rows.append(        AddFanAction(            key: "todo",            label: CottonStrings.makeTodo,            icon: "circle-check",            // The tool's own new-todo sheet, opened by the flag the timeline            // reads on entry (`newTodoPath()` → `/todos?new=1`).            destination: .push(.todos(new: true))        )    )    rows.append(        AddFanAction(            key: "event",            label: ShellLines.line("capture", "fan.event"),            icon: "calendar-days",            // The create/edit screen with no id = create, anchored on today.            destination: .push(.calendarEventEdit(id: nil, date: today, at: nil))        )    )    rows.append(        AddFanAction(            key: "note",            label: ShellLines.line("capture", "fan.note"),            icon: "notebook-text",            // The editor creates the row on the first keystroke — no blank note            // is ever written just by opening it. `new` is the id the editor            // reads as "there isn't one yet".            destination: .push(.notesNote(id: "new"))        )    )    rows.append(        AddFanAction(            key: "contact",            label: ShellLines.line("capture", "fan.contact"),            icon: "user-plus",            // Curate-on-import is the ONLY way to a new person today; a            // type-them-in form does not exist, and inventing one here would be            // a second way to do the thing.            destination: .push(.peopleImport)        )    )    rows.append(        AddFanAction(            key: "document",            // The noun a person actually holds: a statement, a bill, a scan.            // Not "Upload" — the fan names things, not transfers — and not            // "File", which in an app full of records reads as a verb.            label: ShellLines.line("capture", "fan.document"),            icon: "file-up",            destination: .push(.documentsImport)        )    )    rows.append(        AddFanAction(            key: "meeting-record",            // The noun a person thinks in. Not "Recording", which is the file;            // a meeting is what they are about to have.            label: ShellLines.line("capture", "fan.meeting"),            icon: "mic",            destination: .push(.meetingsRecord)        )    )    rows.append(        AddFanAction(            key: "meeting-import",            // Named for the FILE, because that is what this row takes: an            // audio file already on the phone, which becomes a meeting.            label: ShellLines.line("capture", "fan.recording"),            icon: "audio-lines",            destination: .push(.meetings(importing: true))        )    )    rows.append(        AddFanAction(            key: "chat-import",            // The noun is the source AND what it is: the row takes a WhatsApp            // chat export and lands its chat in Messages (diff-merged, never            // duplicated). "WhatsApp" alone named an app rather than a thing,            // which on a fan of nouns read as "open WhatsApp" (the walk of 15            // Sep 2026, finding g). Other sources join as their adapters do.            label: ShellLines.line("capture", "fan.whatsapp_chat"),            icon: "message-square-plus",            destination: .push(.messagesImport)        )    )    return rows}