Cotton code
80 lines · 3.0 KB · SwiftRaw
// The sampler: one synthetic table with a column of every type, for the// editors' tests, kept with them. It lives in code, not in a kit, because every// table a kit defines is served and shows on the Records screen — this one is// a specimen, not a table anyone keeps.//// Built as the view type itself, never decoded from definition JSON: the// core is the one decoder of the definition format.import CottonValuesimport Foundation@testable import CottonUIenum EditorsSampler {    static let table = "sampler"    static let recordId = "example-sampler-1"    static let definition = TableDefinition(        id: table, name: "Sample", plural: "Samples",        columns: [            ColumnDefinition(key: "title", name: "Title", type: .text, required: true),            ColumnDefinition(key: "notes", name: "Notes", type: .longtext),            ColumnDefinition(key: "day", name: "Day", type: .date),            ColumnDefinition(key: "at", name: "Time", type: .time),            ColumnDefinition(key: "count", name: "Count", type: .number),            ColumnDefinition(key: "cost", name: "Cost", type: .amount),            ColumnDefinition(key: "status", name: "Status", type: .choice, choices: ["open", "waiting", "done"]),            ColumnDefinition(key: "person", name: "Person", type: .link, linkTo: "person"),            ColumnDefinition(key: "photo", name: "Photo", type: .photo),            ColumnDefinition(key: "file", name: "File", type: .file),            ColumnDefinition(key: "done", name: "Done", type: .bool),        ],        title: "title", date: "day",        slip: SlipLayout(title: "title", subtitle: "notes", trailing: "day", photo: "photo", toggle: "done"),        tile: TileLayout(face: .slipList),        page: [            PageSection(heading: nil, columns: ["title", "notes"]),            PageSection(heading: "When", columns: ["day", "at"]),            PageSection(heading: "Numbers", columns: ["count", "cost"]),            PageSection(heading: "Details", columns: ["status", "person", "done"]),            PageSection(heading: "Attached", columns: ["photo", "file"]),        ],        instructions: "A synthetic table with one column of every type, used by the editors' and the interpreter's tests. It holds no real data.")    static let records: [TableRecord] = {        try! JSONDecoder().decode([TableRecord].self, from: Data(recordsJSON.utf8))    }()    private static let recordsJSON = #"""[  {    "id": "example-sampler-1",    "title": "Paint the fence",    "notes": "Two coats. Buy the green from the shop on the corner first.",    "day": "2026-10-03",    "at": "09:30",    "count": 2,    "cost": 185000,    "status": "open",    "person": null,    "photo": null,    "file": null,    "done": false  },  {    "id": "example-sampler-2",    "title": "Return the library book",    "notes": null,    "day": "2026-10-01T16:00:00Z",    "at": null,    "count": null,    "cost": null,    "status": "done",    "person": null,    "photo": null,    "file": null,    "done": true  }]"""#}