// THE ONE SYNCHRONOUS CAMERA DECISION (accepted, 8 Nov 2026): what a shot writes// (`newDefaults`, `onePhoto`, `shotValues`) stays here, in Swift, because the// shutter cannot wait on a core call. Every other rule about a record is the core's.// A create whose record is one photo (`TableDefinition.onePhoto`): the camera// at once, as the Camera tool opens it — no page of fields, no second tap.// The shot makes the row, its moment the record's time, and the camera// closes. A hand-built screen for the camera's own reason (`CameraScreen`);// which creates come here is the definition's shape, never a table's id.importCottonKitimportCottonValuesimportSwiftUIstructShotCreate: View {let definition: TableDefinitionlet column: ColumnDefinitionlet preset: [String: RecordValue] @Environment(\.records) privatevar store @Environment(\.cottonCore) privatevar core @Environment(\.cottonCapabilities) privatevar capabilities @Environment(\.dismiss) privatevar dismiss @Environment(ToastCenter.self) privatevar toasts @State privatevar camera: CameraModel?var body: someView {Group {iflet camera {CameraScreen(model: camera) { dismiss() } } else {Color.black.ignoresSafeArea() } } .task {guard camera == nil, let core, let store else { return }let shot = OneShot() camera = CameraModel(shooter: FormShooter(core: core), capabilities: capabilities) { taken, moment in// One shot, one record: a second while the first is kept makes none.guard shot.take() else { return }do { _ = tryawait store.create( table: definition.id, data: definition.shotValues(column, key: taken.captured.key, at: moment, preset: preset)) dismiss() } catch { shot.release() toasts.show(ActionRefused.words(for: error), tone: .error) } } } }}/// Whether the create's one shot has been taken.@MainActorprivatefinalclassOneShot {privatevar taken = falsefunc take() -> Bool {guard !taken else { returnfalse } taken = truereturntrue }/// The create was refused: the next shot may try again.func release() { taken = false }}// The one-photo create: whether a new record opens the camera, and what its shot writes.extensionTableDefinition {/// The photo a new record asks for, when it is all the record asks for:/// the one column the person can write on it besides its time (`date`,/// which the shot fills with its moment), and a photo. Such a create/// opens the camera, never a page of fields (owner, 17 Oct 2026: "the/// minute we say add a meal, it should just open up the camera"). Nil/// when the record asks anything else, or is not new.publicfunc onePhoto(of record: TableRecord) -> ColumnDefinition? {let asked = columns.filter { column in column.key != date && !column.readonly && column.isShown(on: record) }guard asked.count == 1, let only = asked.first, only.type == .photo else { returnnil }return only }/// Each writable column's definition default, by key: what a new record/// holds before anything is written (the value the core gives a record/// that leaves it out).publicvar newDefaults: [String: RecordValue] {var values: [String: RecordValue] = [:]for column in columns where !column.readonly {iflet value = column.defaultValue, value != .null { values[column.key] = value } }return values }/// The values a one-photo create's shot makes its record with/// (`onePhoto`): the defaults under `preset`, the picture's key in/// `column`, and the shot's moment in the record's time column where the/// person may write it.publicfunc shotValues(_ column: ColumnDefinition, key: String, at moment: Date, preset: [String: RecordValue]) -> [String: RecordValue] {let blank = newDefaults.merging(preset) { _, given in given }var values = blank values[column.key] = .text(key)iflet time = self.column(date), !time.readonly { values[time.key] = .text(CottonDate.format(moment)) }return values }}privateextensionColumnDefinition {/// Whether a shot writes this column for `record`: not hidden by the/// owner, and its `shown_when` holds.func isShown(on record: TableRecord) -> Bool {if hidden == true { returnfalse }guardlet shownWhen else { returntrue }return record[shownWhen.column].text.map(shownWhen.values.contains) ?? false }}