// How the shell takes a face's parts (CottonFaces' `FacePart`, the tap// map): a part names a card place, and while the card is held the core says// what a tap on that place opens (`shell.opened`'s `parts`,// `DeckEditor.part`) — a date the days fan (`deckCorner`, ringed;// `deckWhen`), the status word the statuses (`deckStatusWord`), the group the// groups, words the short-text input or the full-screen editor// (`deckWords`); a picture opens the one viewer — or, where the core says it// chooses a column (an event's kind), turns the fan into that column's// values — and a person's discs their apps. The done box and a disc are// toggles the face keeps. Built for each card the deck draws// (`DeckFace.view`); where no editor stands each part draws exactly as it// was. A part whose editor a tap opens is the card's selected part while// that editor stands (`DeckEditor.selected(on:)`).//// ONLY WHAT THE SHELL MAY WRITE, AS THE CORE SAYS. A place the core leaves// out of the held card's parts is drawn as it is and its tap is the card's// own: a read-only or computed column, a record closed to edits, a type no// writer writes. A thread's last line is its newest message, no column of// the thread's to write: its tap opens the chat (walk 332).importCottonFacesimportCottonValuesimportSwiftUIenumDeckFaceParts {/// The card place a part shows.staticfunc slot(of part: FacePart) -> DefinitionCardSlot? {switch part {case .title: .titlecase .subtitle: .subtitlecase .body: .bodycase .quote: .quotecase .note: .notecase .corner, .when: .datecase .state: .statecase .done: .checkcase .picture: .photocase .amount: .amountcase .place: .placecase .people: .peoplecase .group: .groupcase .stars: .countcase .seal: .sealcase .weather: .weathercase .call, .videoCall, .message, .email, .play, .scrub, .next, .previous: nil } }/// The core's word for a part's place in the held card's tap map.staticfunc place(of part: FacePart) -> String? {switch part {case .corner, .when: "date"default: slot(of: part)?.rawValue } }/// The parts' taps on one card: `open` is what its picture's tap does/// (the deck's viewer) where the core's tap map says `viewer`, nil where/// the card stands outside a deck that opens it; `call`, `message` and `email` open its person's apps. @MainActor staticfunc taps(open: (() -> Void)?, call: (() -> Void)? = nil, videoCall: (() -> Void)? = nil, message: (() -> Void)? = nil, email: (() -> Void)? = nil, next: (() -> Void)? = nil, previous: (() -> Void)? = nil, play: (() -> Void)? = nil) -> FacePartTaps {let acts = Acts(open: open, call: call, videoCall: videoCall, message: message, email: email, next: next, previous: previous, play: play)return { part, content inswitch part {case .corner, .when, .title, .subtitle, .body, .quote, .note, .amount, .place, .people, .stars:AnyView(content.modifier(DeckColumnPart(part: part)))case .state:AnyView(content.deckStatusWord().deckSelects(part))case .group:AnyView(content.deckGroups().deckSelects(part))case .picture:AnyView(content.modifier(DeckPicturePart(open: acts.open)))case .seal, .weather:AnyView(content.modifier(DeckChoicePart(part: part)))case .call: tapped(content, acts.call)case .videoCall: tapped(content, acts.videoCall)case .message: tapped(content, acts.message)case .email: tapped(content, acts.email)case .next: tapped(content, acts.next)case .previous: tapped(content, acts.previous)case .play: tapped(content, acts.play)case .done, .scrub: content } } }/// A card's acts past its editors, held on the main actor the taps run on. @MainActor privatefinalclassActs {letopen, call, videoCall, message, email, next, previous, play: (() -> Void)?init(open: (() -> Void)?, call: (() -> Void)?, videoCall: (() -> Void)?, message: (() -> Void)?, email: (() -> Void)?, next: (() -> Void)?, previous: (() -> Void)?, play: (() -> Void)?) {self.play = playself.open = openself.call = callself.videoCall = videoCallself.message = messageself.email = emailself.next = nextself.previous = previous } }/// `content` doing `action` on a tap; as it is with none.fileprivatestaticfunc tapped(_ content: AnyView, _ action: (() -> Void)?) -> AnyView {guardlet action else { return content }returnAnyView(content.contentShape(Rectangle()).onTapGesture(perform: action).accessibilityAddTraits(.isButton)) }}/// A part that shows a column, routed to the editor the core says a tap on/// its place opens while the card is held (`DeckEditor.part`); else drawn/// as it is, its tap the card's own.privatestructDeckColumnPart: ViewModifier {let part: FacePart @Environment(\.deckEditor) privatevar editor @Environment(\.deckCardTarget) privatevar cardfunc body(content: Content) -> someView {iflet card, let place = DeckFaceParts.place(of: part), let routed = editor?.part(place, on: card.target.record) {switch (part, routed.does) {case (.corner, "days"): content.deckCorner().deckSelects(part)case (.when, "days"): content.deckWhen().deckSelects(part)case (_, "line"), (_, "page"):iflet column = routed.column { content.deckWords(column: column).deckSelects(part) } else { content }default: content } } else { content } }}/// A part drawn by its choice column (a diary's seal, its weather): where the/// core says a tap chooses it (`options`), a tap turns the fan into its/// values and the part is selected while they stand; else drawn as it is,/// its tap the card's own.privatestructDeckChoicePart: ViewModifier {let part: FacePart @Environment(\.deckEditor) privatevar editor @Environment(\.deckCardTarget) privatevar card @Environment(\.cottonHaptics) privatevar hapticsfunc body(content: Content) -> someView {iflet editor, let card, let place = DeckFaceParts.place(of: part), let routed = editor.part(place, on: card.target.record), routed.does == "options", let column = routed.column { content .contentShape(Rectangle()) .onTapGesture { haptics.press() editor.openOptions(card.target, column: column, record: card.record) } .accessibilityAddTraits(.isButton) .deckSelects(part) } else { content } }}/// A card's picture: where the core says it chooses a column (`options`), a/// tap turns the fan into its values and the picture is the selected part/// while they stand; anywhere else its tap is `open`, the viewer.privatestructDeckPicturePart: ViewModifier {letopen: (() -> Void)? @Environment(\.deckEditor) privatevar editor @Environment(\.deckCardTarget) privatevar card @Environment(\.cottonHaptics) privatevar hapticsfunc body(content: Content) -> someView {iflet editor, let card, let routed = editor.part("photo", on: card.target.record), routed.does == "options",let column = routed.column { content .contentShape(Rectangle()) .onTapGesture { haptics.press() editor.openOptions(card.target, column: column, record: card.record) } .accessibilityAddTraits(.isButton) .deckSelects(.picture) } else {DeckFaceParts.tapped(AnyView(content), open) } }}extensionView {/// A tap here selects the card's `part` for as long as the editor the/// same tap opens stands.fileprivatefunc deckSelects(_ part: FacePart) -> someView { modifier(DeckPartSelecting(part: part)) }}privatestructDeckPartSelecting: ViewModifier {let part: FacePart @Environment(\.deckEditor) privatevar editor @Environment(\.deckCardTarget) privatevar cardfunc body(content: Content) -> someView {iflet editor, let card { content.simultaneousGesture(TapGesture().onEnded { editor.select(part, record: card.target.record) }) } else { content } }}