// ONE SLIP ANSWER, as the core said it (`shell_slip.rs`): what a record says// wherever it is drawn. Every record read through the core carries it under// `@said`, and a list's row answers the same words (`ListAnswer.Row`), so a// face draws what it holds, whole on its first paint, and decides none of it.// Plain JSON, the same answer a Kotlin shell reads.importCottonValuesimportFoundation/// A record's answer, beside its row's acts.publicstructRecordSaid: Equatable, Sendable {publicvar slip: SlipWords/// Whether the slip's check is on; nil on a table with no check.publicvar toggled: Bool?/// What a tap on the check writes, `{column: value}`; nil, nothing.publicvar toggle: [String: RecordValue]?publicvar dimmed: Bool/// The stamp the record wears, by its word (done, dropped, a choice's stamp).publicvar stamp: String?/// Whether Delete may take it.publicvar deletes: Bool/// Nothing about the record can be written.publicvar readOnly: Bool/// A typed sentence could change it.publicvar typesInto: Boolpublicvar archived: Bool/// It stands on its table's own list.publicvar listed: Bool/// The project it is filed under.publicvar project: String?/// The slip its `slip_by` variant draws; nil, the table's own.publicvar layout: SlipLayout?/// The columns whose value its `red_when` holds.publicvar red: [String]/// The row's own words its columns' units name.publicvar unitWords: [String: String]/// What is drawn for a record no core has said anything of.publicstaticlet nothing = RecordSaid(slip: SlipWords([:]), toggled: nil, toggle: nil, dimmed: false, stamp: nil, deletes: false, readOnly: false, typesInto: false, archived: false, listed: true, project: nil)publicinit(slip: SlipWords, toggled: Bool?, toggle: [String: RecordValue]?, dimmed: Bool, stamp: String?, deletes: Bool, readOnly: Bool, typesInto: Bool, archived: Bool, listed: Bool, project: String?, layout: SlipLayout? = nil, red: [String] = [], unitWords: [String: String] = [:]) {self.slip = slipself.toggled = toggledself.toggle = toggleself.dimmed = dimmedself.stamp = stampself.deletes = deletesself.readOnly = readOnlyself.typesInto = typesIntoself.archived = archivedself.listed = listedself.project = projectself.layout = layoutself.red = redself.unitWords = unitWords }init?(_ value: RecordValue) {guardcase .object(let said) = value, case .object(let slip)? = said["slip"] else { returnnil }var toggle: [String: RecordValue]?ifcase .object(let write)? = said["toggle"] { toggle = write }var layout: SlipLayout?iflet drawn = said["layout"], let data = try? JSONEncoder().encode(drawn) { layout = try? JSONDecoder().decode(SlipLayout.self, from: data) }var red: [String] = []ifcase .list(let columns)? = said["red"] { red = columns.compactMap(\.text) }var unitWords: [String: String] = [:]ifcase .object(let words)? = said["unit_words"] { unitWords = words.compactMapValues(\.text) }self.init(slip: SlipWords(slip), toggled: said["toggled"]?.bool, toggle: toggle, dimmed: said["dimmed"]?.bool ?? false, stamp: said["stamp"]?.text, deletes: said["deletes"]?.bool ?? false, readOnly: said["read_only"]?.bool ?? false, typesInto: said["types_into"]?.bool ?? false, archived: said["archived"]?.bool ?? false, listed: said["listed"]?.bool ?? true, project: said["project"]?.text, layout: layout, red: red, unitWords: unitWords) }}/// The words a slip draws.publicstructSlipWords: Equatable, Sendable {publicstructStub: Equatable, Sendable {publiclet day: RecordValue?publiclet month: RecordValue? }publicstructByline: Equatable, Sendable {publiclet words: Stringpubliclet red: Bool }publicstructBadge: Equatable, Sendable {publiclet symbol: String?publiclet spoken: String? }publicstructPin: Equatable, Sendable {publiclet lat: Doublepubliclet lng: Double }publiclet title: String?publiclet subtitle: String?/// One line where `subtitle` joins several columns.publiclet subtitle_one: String?publiclet caption: String?publiclet caption_late: Bool?publiclet figure: RecordValue?publiclet foot: RecordValue?publiclet foot_late: RecordValue?publiclet day_foot: String?/// The trailing column's words, away from a list.publiclet trailing: String?publiclet stub: Stub?publiclet byline: Byline?publiclet badge: Badge?publiclet unread: Bool/// The record's own title alone.publiclet name: String?/// What names it where its title holds nothing.publiclet fallback: String?/// Never empty, on a record the core has said.publiclet spoken: String?/// The day heading the record, where it has no title of its own.publiclet weekday: String?/// What a cover says at its foot, part by part.publiclet cover_footer: [String]?publiclet stock: String?publiclet pin: Pin?/// The project's name, where the slip does not already say it.publiclet project_words: String?/// What heads a page or a list opened from the record.publicvar heading: String? { name ?? fallback }init(_ said: [String: RecordValue]) { title = said["title"]?.text subtitle = said["subtitle"]?.text subtitle_one = said["subtitle_one"]?.text caption = said["caption"]?.text caption_late = said["caption_late"]?.bool figure = said["figure"] foot = said["foot"] foot_late = said["foot_late"] day_foot = said["day_foot"]?.text trailing = said["trailing"]?.textifcase .object(let stub)? = said["stub"] { self.stub = Stub(day: stub["day"], month: stub["month"]) } else { stub = nil }ifcase .object(let byline)? = said["byline"], let words = byline["words"]?.text {self.byline = Byline(words: words, red: byline["red"]?.bool ?? false) } else { byline = nil }ifcase .object(let mark)? = said["badge"] {self.badge = Badge(symbol: mark["symbol"]?.text, spoken: mark["spoken"]?.text) } else { badge = nil } unread = said["unread"]?.bool ?? false name = said["name"]?.text fallback = said["fallback"]?.text spoken = said["spoken"]?.text weekday = said["weekday"]?.textifcase .list(let parts)? = said["cover_footer"] { cover_footer = parts.compactMap(\.text) } else { cover_footer = nil } stock = said["stock"]?.textifcase .object(let pin)? = said["pin"], let lat = pin["lat"]?.number, let lng = pin["lng"]?.number {self.pin = Pin(lat: lat, lng: lng) } else { pin = nil } project_words = said["project_words"]?.text }}extensionTableRecord {/// Where the core puts a record's answer.publicstaticlet saidKey = "@said"/// The record's answer as the core said it; nil on a record no core read.publicvar said: RecordSaid? { RecordSaid(self[Self.saidKey]) }/// The ink a column's words take on this record: red where the core/// says its value is, else `fallback`.publicfunc ink(_ key: String?, fallback: PaperInk = .ink) -> PaperInk {guardlet key, said?.red.contains(key) == trueelse { return fallback }return .red }}