// What only one KIND of machine has, handed in by that machine.//// The Mac holds the database, so it has pages the phone can never draw: the// API keys, what this Mac reads off its own disk, what it is serving, its// backup. Those are `CottonHost` views over `CottonHost`'s own model, and// `CottonHost` imports `CottonUI` — so the shared screens cannot name them,// cannot construct them, and must not learn what a Mac is in order to show// them.//// The seam is the environment, as `HostNoun` is the seam for the word a host// calls itself. The host puts pages and acts in and answers when one is// pressed; the shared screens draw whatever is there, and nothing when there// is nothing, which is the phone. There is no settings screen to hold them// (Spec 10): each lands where it belongs —//// - THIS device's own record page (`/devices/[id]`, `native Device records`)// offers `deviceActs`: one opens a page at `/device/[page]`// (`Route.hostPage`), drawn by `HostPageScreen` from `pages`; another is a// press the host answers (check for updates);// - the database page (`/database`, `DatabaseTableSource`) offers// `databaseActs` — the database's own address, its backup and leaving it// on this machine — each opening its page at `/device/[page]`.//// **Why a page is an `AnyView`.** Type erasure is the cost of a module that may// not be imported. The route carries the page's id and nothing else, so the// wire protocol learns one opaque path, never what a Mac's pages are.//// **Why the slot is also installed.** The device page's acts are read by a// records actor (`SettingsRecords`), which no environment reaches; the host// installs its one slot once (`install`), and that actor asks it on the main// actor. A process with none installed — the phone — offers no acts.importSwiftUI/// One host-only panel, drawn as the whole of `/device/[page]` when this/// device's own page or the database page opens it.publicstructHostSettingsPage: Identifiable, Sendable {/// Wire, not words: the row's id, the selection's value, and the tail of/// the accessibility identifier. Never shown.publiclet id: String/// The panel, built when it is opened rather than when the list is made: a/// page nobody opened should cost nothing.publiclet content: @MainActor () -> AnyView/// **The one erasure, and it is here.** A host writes its panel as the/// ordinary `View` it is; the type is dropped on the way in, in this file,/// so no page has to say `AnyView` and `NavigationSweepTests` has one/// exemption rather than one per page.publicinit<Content: View>( id: String, @ViewBuilder content: @escaping @MainActor () -> Content ) {self.id = idself.content = { AnyView(content()) } }}/// One act THIS device's own record page, or the database page, offers,/// named by the host.publicstructHostDeviceAct: Identifiable, Equatable, Sendable {/// What pressing it does.publicenumKind: Equatable, Sendable {/// Opens `/device/[page]` at the act's id: a page in `pages`.case page/// A press `onAct` answers, then said in this sentence.case press(said: String) }/// Wire, not words: a page's id, or the press `onAct` is handed.publiclet id: String/// The button's plain words ("API keys", "Check for updates").publiclet label: Stringpubliclet kind: Kindpublicinit(id: String, label: String, kind: Kind = .page) {self.id = idself.label = labelself.kind = kind }}/// What the host adds to the device and database pages, and what answers a/// press.////// `@Observable` rather than a plain value: the acts change while the page is/// open — a key saved, an import finishing — and the page has to redraw when/// they do. Read as an OPTIONAL environment object, so the phone, which puts/// none in, is the case where there is nothing.@Observable@MainActorpublicfinalclassHostSettingsSlot {public nonisolated staticlet pageActionPrefix = "host-page:"/// What THIS device's own record page offers, in order.publicvar deviceActs: [HostDeviceAct] = []/// What the DATABASE page offers on this kind of machine, in order — each/// opens its page at `/device/[page]` (`DatabaseTableSource`).publicvar databaseActs: [HostDeviceAct] = []/// The panels behind the acts/// whose kind is `.page`.publicvar pages: [HostSettingsPage] = []/// What a `.press` device act is handed to./// Set by the host after it has/// built the slot, which is why it is a property rather than an init/// argument: the object that answers a press is the one that OWNS the slot,/// and it cannot hand itself in before it exists. @ObservationIgnored publicvar onAct: ((String) -> Void)?publicinit() {}/// A press was pressed. The host decides what it means — there is/// nothing here to decide, and a second table of Mac verbs in this module/// is exactly what this seam exists to avoid.publicfunc act(_ id: String) { onAct?(id) }publicfunc page(_ id: String) -> HostSettingsPage? { pages.first { $0.id == id } }// ── The installed slot ─────────────────────────────────────────────────/// RULE: the device page offers host acts from the installed slot alone, and a process that installed none (the phone) offers none.publicprivate(set) staticvar installed: HostSettingsSlot?/// Makes `slot` the one the device page asks; `nil` takes it away.publicstaticfunc install(_ slot: HostSettingsSlot?) { installed = slot }/// Presses the installed host's act `id`, answering the sentence that/// says it was done — `nil` when no host offers that press.publicstaticfunc press(_ id: String) -> String? {guardlet slot = installed,let act = slot.deviceActs.first(where: { $0.id == id }),case .press(let said) = act.kindelse { returnnil } slot.act(id)return said }}