Cotton code
219 lines · 10.0 KB · SwiftRaw
// THE DOCK — one card: the words, then `[+] … (mic) (send)`.//// Its VIEW half; every decision it makes lives in `DockModel.swift`, and the// card itself is `ComposerCard.swift`.//// ONE object, DOCKED — never floating over content — carrying the dock's two// verbs, **add · say**, along the bottom edge of the box that holds the// thought:////   • **+**, at the left end of the card's control row, opens the structured//     fan (Todo · Event · Note · Contact · Scan …) — the DETERMINISTIC lane,//     where you already know what you are making.//   • **the words** are the natural-language lane: free text, live dictation,//     the plan chips a host draws, and the typed-sigil grammar — `#` attaches a//     PROJECT, `@` attaches a PERSON. Neither sigil is a button anywhere//     (the owner's ruling: they are typing grammar).//// **Find left the dock** (2026-08-27, the owner's lived report): a ⌕ inside the// capture assembly read as part of capture. Its entry point is the page's// top-right capsule now; the dock is capture, whole. There is no search control// in this file and adding one would be the bug.//// **The one rule is scoping**: the pill captures into the PLACE you are// standing on, and `DockPlace` is the whole of that — the placeholder, the chip// that arrives pre-attached, and the destination a person's page makes certain.// A project page mounts the same view with a different place and the dock// learns nothing new.//// **TWO INPUT BARS NEVER RENDER AT ONCE**, and a surface in ARRANGE mode// suppresses the dock entirely. That is ``suppressed`` below — a stated// parameter rather than a hidden assumption, because the rule binds every host// and a rule nobody can see is a rule the fourth host breaks.import CottonKitimport SwiftUIpublic struct CaptureDock<Plan: View>: View {    private let model: DockModel    /// The day key (`YYYY-MM-DD`) the fan's Event row anchors on. An argument    /// rather than a clock read: a list built off the wall clock is a list no    /// test can pin to a date.    private let today: String    /// The host can open its own creation sheet — which is what earns the fan's    /// Memory row. Only the project page can.    private let canAddMemory: Bool    /// The dock is not drawn at all. See the header: ARRANGE mode is the one    /// state that takes the capture bar off a surface that otherwise has one.    private let suppressed: Bool    /// What a chosen fan row does. The dock neither navigates nor opens the    /// host's sheets, exactly as it never writes the capture it reports.    private let onChoose: (AddFanDestination) -> Void    private let planSlot: () -> Plan    /// The accessibility-identifier stem every part of the assembly hangs off:    /// `-sigil`, `-chips`, `-chip-…`, `-add`, `-composer` and `-fan` are all    /// derived from it. One host exists today and takes the default; the stem    /// is threaded rather than spelled out five times so a second host cannot    /// half-rename it.    private let identifier: String    /// Whether the recording row offers the keyboard disc — the switch to    /// typing Home's capture surface draws. The chat's dock does not.    private let offersTypingSwitch: Bool    /// Whether the fan offers Picture (and Camera, where there is one) — the    /// host can raise the photo library over this dock and put what comes    /// back on its draft. The capture surface can; a host that cannot is    /// never offered a row with nothing behind it.    private let offersPictures: Bool    @State private var fanIsOpen = false    /// The project pill's sheet is up.    @State private var projectsOpen = false    public init(        model: DockModel,        today: String,        canAddMemory: Bool = false,        suppressed: Bool = false,        identifier: String = "dock",        offersTypingSwitch: Bool = false,        offersPictures: Bool = false,        onChoose: @escaping (AddFanDestination) -> Void,        @ViewBuilder planSlot: @escaping () -> Plan    ) {        self.model = model        self.today = today        self.canAddMemory = canAddMemory        self.suppressed = suppressed        self.identifier = identifier        self.offersTypingSwitch = offersTypingSwitch        self.offersPictures = offersPictures        self.onChoose = onChoose        self.planSlot = planSlot    }    public var body: some View {        if !suppressed {            VStack(alignment: .leading, spacing: 0) {                // Above the pill, where the plan chips sit: first what the                // vocabulary OFFERS, then what has actually been ATTACHED.                //                // No token, no strip. The sigil is read off the TOKEN and never                // defaulted: a `#` fallback would file a person as a project                // the one time the two disagreed.                if let token = model.activeToken {                    SigilSuggestions(                        sigil: token.sigil,                        matches: model.suggestions,                        identifier: "\(identifier)-sigil"                    ) { candidate in                        model.pick(candidate)                    }                }                chipStrip                // ONE card, and the `+` is INSIDE it — the left end of the                // composer's own control row. It used to stand beside the                // pill, which made the assembly two objects with two                // backgrounds; the card is one object with the verbs along its                // bottom edge, which is the shape the owner asked for.                CaptureComposer(                    model: model,                    placeholder: model.placeholder,                    identifier: "\(identifier)-composer",                    onAdd: { fanIsOpen = true },                    onChooseProject: { projectsOpen = true },                    offersTypingSwitch: offersTypingSwitch,                    planSlot: planSlot                )            }            .accessibilityIdentifier(identifier)            // The chips, the plus and the composer are one bar: a tap on any            // of them keeps the keyboard, so the frame's dismissal skips it.            .keyboardStaysOnTap()            .addFanSheet(                isPresented: $fanIsOpen,                today: today,                canAddMemory: canAddMemory,                canAttachPictures: offersPictures,                identifier: "\(identifier)-fan",                onChoose: onChoose            )            // The pill's sheet: the same caps every record is filed with, a            // tap on one putting the project on the thought or taking it off —            // the `#` chips above the card move with it.            .cottonCard(isPresented: $projectsOpen, detents: [.half, .tall]) {                ProjectsSheetContent(                    projects: model.projectOptions,                    links: model.aimedProjects.map { ProjectsSheetLink(projectId: $0.recordId) },                    caption: ShellLines.line("capture", "dock.which_project"),                    onLink: { model.aim(atProject: $0) },                    onUnlink: { model.unaim(project: $0) }                )                .accessibilityIdentifier("\(identifier)-projects")            }        }    }    /// The chips on the pending capture. Tapping one takes it off — a    /// pre-attached one exactly as a typed one, because standing somewhere is a    /// strong signal and never a verdict.    ///    /// Nothing at all when there are none: an empty strip holding its height    /// would make the pill jump the first time somebody typed a `#`.    @ViewBuilder    private var chipStrip: some View {        let chips = model.attachedChips        if !chips.isEmpty {            // WRAPPING, as the phone wraps. SwiftUI ships no wrapping            // stack, so the wrap is a ``ChipWrap`` `Layout` below; a horizontal            // scroller was the first cut and it moved four chips that used to            // stack onto a second row onto one row somebody has to swipe.            //            // The rule that decided it: "what is shown is what is sent". Every            // chip is a link on the capture, and a chip the writer cannot see            // is a link they can neither check nor take off — which is why an            // `HStack` that clips was never an option either. The wrap grows            // the band instead, exactly as the phone's does.            ChipWrap(spacing: 8) {                ForEach(chips) { chip in                    Chip(                        label: chip.name,                        prefix: chipPrefix(for: chip.sigil),                        selected: true,                        accessibilityLabel: ShellLines.line("capture", "dock.remove_chip", ["sigil": String(chip.sigil.rawValue), "name": chip.name])                    ) {                        model.detach(chip)                    }                    .accessibilityIdentifier("\(identifier)-chip-\(chip.kindWord)-\(chip.recordId)")                }            }            .padding(.bottom, 8)            .accessibilityIdentifier("\(identifier)-chips")        }    }}extension CaptureDock where Plan == EmptyView {    /// A dock with NO plan band — `/thoughts`' own form. That surface mounts no    /// live plan preview, so the band is not merely empty there: it is absent.    public init(        model: DockModel,        today: String,        canAddMemory: Bool = false,        suppressed: Bool = false,        identifier: String = "dock",        offersTypingSwitch: Bool = false,        offersPictures: Bool = false,        onChoose: @escaping (AddFanDestination) -> Void    ) {        self.init(            model: model,            today: today,            canAddMemory: canAddMemory,            suppressed: suppressed,            identifier: identifier,            offersTypingSwitch: offersTypingSwitch,            offersPictures: offersPictures,            onChoose: onChoose        ) { EmptyView() }    }}