// A PAGE OF A SCROLLING LIST, AS THE CORE ANSWERS IT (`shell.list`; the // shell boundary, 5 Nov 2026: the core answers what to show, a platform shell // only draws). Its sections in order under their headings with their counts // in words, each row's slip words, check, stamp, acts and tap; the list's // title, menu, links, groups, index rail, filter row, empty words, clear and // Select. The list draws this and decides none of it. Plain JSON, the same // answer a Kotlin shell reads. import CottonKit import CottonValues import Foundation /// Select's Delete over the records picked (`shell.list {deleting}`): those /// it takes, whether it asks, its question, its word, the receipt's words /// over them all and once undone, and what is said after. struct ListDeleting: Decodable, Equatable, Sendable { let ids: [String] let asks: Bool let word: String let question: ListAnswer.Question let done: String let undone: String let outcome: String struct Envelope: Decodable { let deleting: ListDeleting } } struct ListAnswer: Decodable, Equatable, Sendable { let table: String let title: String let head: Head? let sections: [Section] let acts: [String: Act] let menu: [MenuItem] let links: [Link] /// The table's groups as its row of stacks; nil where the list draws none. let groups: [Group]? let offers_new_group: Bool /// The index rail's landings; nil on a list with no rail. let index: [Landing]? let filter: FilterRow? let empty: Empty? let clear: Clear? let select: Select /// What the search field says before anything is typed. let search: String? /// The words of the rows under this table's section on another's page. let section_words: SectionWords? /// A long press drags: the list is the whole of a hand-written order. let reorders: Bool /// Seconds between asks while the list is open; nil, never. let polls: Int? /// A grid's columns; nil, a column of slips. let across: Int? /// The "Recent" rows above the list: its latest, on the whole table unnarrowed. let recent: [Recent] /// The notes of the group sections the list holds none of, said under it. let notes: [String] /// How many rows the whole read holds. let count: Int /// The cursor of the page after this one; nil at the list's end. let next: Int? struct SectionWords: Decodable, Equatable, Sendable { let new: String let create: String let select: String let reorder: String let all: String } struct Recent: Decodable, Equatable, Sendable { let id: String let title: String? /// When, as the core says it ("2 min ago"). let when: String? } struct Head: Decodable, Equatable, Sendable { let lines: [HeadLine]? } struct HeadLine: Decodable, Equatable, Sendable { let line: String? } struct Section: Decodable, Equatable, Sendable { let id: String let heading: String? /// Drawn open; a section that folds opens shut. let open: Bool let folds: Bool /// The whole section's count in words, on a section that folds. let count: String? let note: String? /// The core's head lines over the whole group ("₹1,200 in"). let lines: [String]? let rows: [Row] } struct Row: Decodable, Equatable, Sendable { let id: String let slip: Slip /// Whether the slip's check is on; nil on a table with no check. let toggled: Bool? /// What a tap on the check writes, `{column: value}`; nil, nothing. let toggle: [String: RecordValue]? let dimmed: Bool /// The stamp the record wears, by its word (done, dropped, a choice's stamp). let stamp: String? /// On a pick: whether the record is already held. let held: Bool? /// Whether Select's Delete may take it. let deletes: Bool /// The long press's acts, by id (`acts`). let acts: [String] /// What the long press runs, each act whole as `shell.opened` answers /// it, a command that asks first with its question. let press: [Press] /// What a tap does: `open.`, or `pick`. let tap: String /// Its place on a numbered list, counted from 1. let place: Int? var record: TableRecord { slip.record.record } /// The row as the record's one answer. var said: RecordSaid { let held = record.said return RecordSaid(slip: slip.words, toggled: toggled, toggle: toggle, dimmed: dimmed, stamp: stamp, deletes: deletes, readOnly: held?.readOnly ?? false, typesInto: held?.typesInto ?? false, archived: held?.archived ?? false, listed: held?.listed ?? true, project: held?.project, layout: held?.layout, red: held?.red ?? [], unitWords: held?.unitWords ?? [:]) } } /// The words a slip draws (`SlipWords`, the core's one slip answer) and /// the record they say. @dynamicMemberLookup struct Slip: Decodable, Equatable, Sendable { let words: SlipWords let record: CoreRecords.WireRecord subscript(dynamicMember path: KeyPath) -> Value { words[keyPath: path] } private enum Keys: String, CodingKey { case record } init(from decoder: Decoder) throws { guard case .object(let said) = try RecordValue(from: decoder) else { throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "a slip is an object")) } words = SlipWords(said) record = try decoder.container(keyedBy: Keys.self).decode(CoreRecords.WireRecord.self, forKey: .record) } } struct Act: Decodable, Equatable, Sendable { let label: String? let kind: String? let red: Bool let primary: Bool? let icon: String? } /// One act of a row's long press: the act as the held card's, and the /// question it asks first, in the core's words. struct Press: Decodable, Equatable, Sendable, Identifiable { let act: CardAction let question: Question? /// What Archive and Bring back write, `{column: value}`. let write: [String: RecordValue]? var id: String { act.id } private enum Keys: String, CodingKey { case question, write } init(from decoder: Decoder) throws { act = try CardAction(from: decoder) let keys = try decoder.container(keyedBy: Keys.self) question = try keys.decodeIfPresent(Question.self, forKey: .question) write = try keys.decodeIfPresent([String: RecordValue].self, forKey: .write) } } /// A question asked before an act, whole: its title, its sentence, its button. struct Question: Decodable, Equatable, Sendable { let title: String let message: String let confirm: String let cancel: String? } struct MenuItem: Decodable, Equatable, Sendable, Identifiable { let id: String let label: String let red: Bool /// The item asks first: `true`, or `{words: {hint}}` for a short text. let asks: JSONValue? /// Where it goes: `{path}` or a list `{table, where, …}`. let opens: Opens? let object: String? /// What it does, which its card is coloured by (`moves`, …). let does: CommandDoes? /// A group page's own act, as `tool_acts::list_acts` said it. let act: CardAction? /// A group page's pick: `add` (the table's records put in) or `remove`. let picks: String? /// What it asks first, in the list's words (Remove list). let question: Question? } struct Link: Decodable, Equatable, Sendable { let id: String let label: String /// The label with its count said ("Senders 12", "3 recordings failed"). let words: String let count: Int? let lead: Bool let above: Bool let opens: Opens } /// A list another list opens: its table, narrowing and title. struct Opens: Decodable, Equatable, Sendable { let table: String? let `where`: [String: RecordValue]? let title: String? let section: String? let query: String? let archived: Bool? /// A record it opens (a group kept as another table's record). let id: String? let path: String? } struct Group: Decodable, Equatable, Sendable { let id: String let name: String let count: Int? let picture: String? /// The word the group's record wears in red under its name ("suggested"). let byline: String? let top: [Top] let opens: Opens struct Top: Decodable, Equatable, Sendable { let id: String let title: String? let picture: String? /// The member itself, which its pile's face draws. let record: CoreRecords.WireRecord? } } struct Landing: Decodable, Equatable, Sendable { let letter: String let row: String /// The cursor that reaches it. let at: Int } struct FilterRow: Decodable, Equatable, Sendable { let column: String? let all: String? let tabs: Bool let values: [Value] let reviews: Bool? /// What waits on the owner ("3 to review"); nil while nothing does. let review: String? struct Value: Decodable, Equatable, Sendable { let value: String let word: String } } struct Empty: Decodable, Equatable, Sendable { let title: String let message: String let picture: String? } struct Clear: Decodable, Equatable, Sendable { let label: String let note: String? let question: String let message: String let confirm: String /// What the receipt says once every record went; nil, the shell's words. let done: String? } struct Select: Decodable, Equatable, Sendable { let deletes: Bool let adds_to_group: Bool /// Its Delete's word: the table's ("Remove"), else Delete. let word: String } } extension ListAnswer.Slip { /// Two slips are one where their words and their record's columns are. static func == (a: Self, b: Self) -> Bool { a.title == b.title && a.subtitle == b.subtitle && a.caption == b.caption && a.caption_late == b.caption_late && a.figure == b.figure && a.foot == b.foot && a.foot_late == b.foot_late && a.day_foot == b.day_foot && a.stub == b.stub && a.byline == b.byline && a.badge == b.badge && a.unread == b.unread && a.record.id == b.record.id && a.record.data == b.record.data } } extension ListAnswer.Group.Top { static func == (a: Self, b: Self) -> Bool { a.id == b.id && a.title == b.title && a.picture == b.picture && a.record?.data == b.record?.data } } extension ListAnswer { /// Every row the answer holds, in its order. var rows: [Row] { sections.flatMap(\.rows) } }