// Ported from the r7 mockups (RosterViews.swift): marks, bylines, cards, // sub-chats and messages. Fed by EquipoKit/Presentation, never by fixtures. import SwiftUI // MARK: - Marks and tiles /// The web's coordinator mark (chat.html "roster-mark"): an outline /// four-point star in a 24-unit box. struct SparkleShape: Shape { func path(in rect: CGRect) -> Path { let s = min(rect.width, rect.height) / 24 let ox = rect.midX - 12 * s, oy = rect.midY - 12 * s func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: ox + x * s, y: oy + y * s) } var path = Path() path.move(to: p(12, 3)) path.addCurve(to: p(21, 12), control1: p(13.1, 8.8), control2: p(15.2, 10.9)) path.addCurve(to: p(12, 21), control1: p(15.2, 13.1), control2: p(13.1, 15.2)) path.addCurve(to: p(3, 12), control1: p(10.9, 15.2), control2: p(8.8, 13.1)) path.addCurve(to: p(12, 3), control1: p(8.8, 10.9), control2: p(10.9, 8.8)) path.closeSubpath() return path } } /// The coordinator: a bare, muted outline sparkle. No name on screen. struct CoordinatorMark: View { var size: CGFloat = 22 var thinking = false var body: some View { SparkleShape() .stroke(Palette.secondary, style: StrokeStyle(lineWidth: size / 24 * 1.6, lineCap: .round, lineJoin: .round)) .frame(width: size, height: size) .rotationEffect(.degrees(thinking ? 45 : 0)).scaleEffect(thinking ? 0.85 : 1).opacity(thinking ? 0.5 : 1) .animation(thinking ? .easeInOut(duration: 1.3).repeatForever(autoreverses: true) : nil, value: thinking) .accessibilityLabel(Text(Specialist.coordinator.name)) } } /// A specialist: its icon centred in a tile, beside its name. Never a letter. struct SpecialistTile: View { let who: Specialist var size: CGFloat = Metric.tile var body: some View { let shape = RoundedRectangle(cornerRadius: size * 0.3, style: .continuous) ZStack { shape.fill(Palette.surface) .shadow(color: Palette.contactShadow.opacity(0.08), radius: 1, y: 1) shape.strokeBorder(Palette.border, lineWidth: 1) Image(systemName: who.symbol) .font(.system(size: size * 0.46, weight: .medium)) .foregroundStyle(Palette.text) .frame(width: size, height: size, alignment: .center) } .frame(width: size, height: size) .accessibilityHidden(true) } } /// The author column: a tile for a specialist, the bare mark for the coordinator. struct Avatar: View { let who: Specialist var size: CGFloat = Metric.tile var body: some View { if who == .coordinator { CoordinatorMark(size: size * 0.74).frame(width: size, height: size, alignment: .leading) } else { SpecialistTile(who: who, size: size) } } } /// A project's monogram, kept neutral: no hue, so nothing reads as purple. struct Monogram: View { let name: String var size: CGFloat = 16 var body: some View { Text(String(name.prefix(1)).uppercased()) .font(.system(size: size * 0.62, weight: .bold, design: .rounded)) .foregroundStyle(Palette.neutral) .frame(width: size, height: size) .background(Palette.neutralBackground, in: RoundedRectangle(cornerRadius: size * 0.28, style: .continuous)) .accessibilityHidden(true) } } // MARK: - Byline struct ProjectChip: View { let name: String var action: (() -> Void)? var menu: Binding? @State private var hovering = false var body: some View { chip } @ViewBuilder private var chip: some View { let label = HStack(spacing: 4) { Monogram(name: name) Text(name).lineLimit(1).truncationMode(.tail) .underline(hovering && action != nil) } .font(Typo.bylineVerb).foregroundStyle(Palette.secondary) if let action { Button(action: action) { label.frame(minHeight: Metric.tile).contentShape(Rectangle()) } .buttonStyle(.plain).onHover { hovering = $0 } .accessibilityLabel(Text(String(localized: "project.spoken \(name)", bundle: .module))) } else { label } } } /// "Engineering reports · W Woodstar 11:59". The coordinator's byline is /// only its mark, the project and the time. struct Byline: View { let byline: RosterByline var onProject: (() -> Void)? var menu: Binding? var body: some View { HStack(alignment: .center, spacing: 0) { Avatar(who: byline.who).frame(width: Metric.indent, alignment: .leading) FlowLayout(spacing: 6, lineSpacing: 2) { if byline.showsName { Text(byline.who.name).font(Typo.bylineName).foregroundStyle(Palette.text) Text(byline.verb).font(Typo.bylineVerb).foregroundStyle(Palette.secondary) } if let project = byline.project { if byline.showsName { Text("·").font(Typo.bylineVerb).foregroundStyle(Palette.faint).accessibilityHidden(true) } ProjectChip(name: project, action: onProject ?? {}, menu: menu) } if let time = byline.timeText { Text(time).font(Typo.time).foregroundStyle(Palette.faint) } } } .frame(minHeight: Metric.tile) .accessibilityElement(children: .combine) .accessibilityLabel(byline.spoken) } } // MARK: - Stage track /// Five stops edge to edge: four equal spans, the last stop only its dot. /// Each label centres under its dot and is only nudged in at the two ends. struct StageTrack: View { let track: [TrackStop] var allLabels: Bool private let slot: CGFloat = 11 var body: some View { VStack(alignment: .leading, spacing: 6) { Canvas { context, size in let y = size.height / 2 let xs = positions(size.width) for i in 0..<(xs.count - 1) { let line = Path(CGRect(x: xs[i], y: y - 1, width: xs[i + 1] - xs[i], height: 2)) context.fill(line, with: .color(track[i].state == .done ? Palette.positive : Palette.controlBorder)) } for (i, stop) in track.enumerated() { let c = CGPoint(x: xs[i], y: y) switch stop.state { case .done: context.fill(Path(ellipseIn: CGRect(x: c.x - 4, y: c.y - 4, width: 8, height: 8)), with: .color(Palette.positive)) case .current: let tone = stop.tone ?? .positive context.fill(Path(ellipseIn: CGRect(x: c.x - 9.5, y: c.y - 9.5, width: 19, height: 19)), with: .color(tone.halo)) context.fill(Path(ellipseIn: CGRect(x: c.x - 5.5, y: c.y - 5.5, width: 11, height: 11)), with: .color(tone.dot)) if tone == .paused { // A still pause mark in the dot: never colour alone. for dx in [-1.75, 1.75] { context.fill(Path(CGRect(x: c.x + dx - 0.75, y: c.y - 2.5, width: 1.5, height: 5)), with: .color(Palette.surface)) } } case .todo: let dot = Path(ellipseIn: CGRect(x: c.x - 4, y: c.y - 4, width: 8, height: 8)) context.fill(dot, with: .color(Palette.surface)) context.stroke(dot, with: .color(Palette.lineStrong), lineWidth: 1) } } } .frame(height: 20) TrackLabels(slot: slot) { ForEach(track) { stop in let current = stop.state == .current Text(stop.label ?? stop.stage.label) .font(current ? Typo.eyebrow : Typo.factLabel) .foregroundStyle(current ? (stop.tone ?? .positive).text : Palette.secondary) .fixedSize() .opacity(allLabels || current ? 1 : 0) } } } .accessibilityElement() .accessibilityLabel(Text(String(localized: "track.spoken \(currentLabel)", bundle: .module))) .accessibilityValue(Text(String(localized: "track.position \(position) \(total)", bundle: .module))) } private var currentLabel: String { guard let stop = track.first(where: { $0.state == .current }) else { return "" } // Paused, stopped or needs you: the stage too ("In progress, Paused"). return stop.label.map { stop.stage.label + ", " + $0 } ?? stop.stage.label } private var position: String { ((track.firstIndex { $0.state == .current } ?? 0) + 1).formatted() } private var total: String { track.count.formatted() } private func positions(_ width: CGFloat) -> [CGFloat] { let r = slot / 2 return track.indices.map { r + CGFloat($0) * (width - slot) / CGFloat(max(1, track.count - 1)) } } } /// Places each label centred on its dot, clamped inside the track's width. struct TrackLabels: Layout { let slot: CGFloat func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { CGSize(width: proposal.width ?? 300, height: subviews.map { $0.sizeThatFits(.unspecified).height }.max() ?? 0) } func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { let r = slot / 2 for (i, view) in subviews.enumerated() { let size = view.sizeThatFits(.unspecified) let centre = bounds.minX + r + CGFloat(i) * (bounds.width - slot) / CGFloat(max(1, subviews.count - 1)) let x = min(max(bounds.minX, centre - size.width / 2), bounds.maxX - size.width) view.place(at: CGPoint(x: x, y: bounds.minY), proposal: .unspecified) } } } extension StageTone { var dot: Color { switch self { case .warning: return Palette.warning case .negative: return Palette.negative case .paused: return Palette.paused case .positive: return Palette.positive } } var halo: Color { switch self { case .warning: return Palette.warningBackground case .negative: return Palette.negativeBackground case .paused: return Palette.pausedBackground case .positive: return Palette.positiveBackground } } var text: Color { dot } /// The eyebrow is coloured only when the stage needs attention. var eyebrow: Color { self == .positive ? Palette.secondary : dot } } // MARK: - Facts, chips and links struct NeedsChip: View { var body: some View { HStack(spacing: 4) { Image(systemName: "hand.raised").font(.system(size: 11, weight: .semibold)) Text(String(localized: "chip.needs_you", bundle: .module)).textCase(.uppercase).kerning(0.3) } .font(Typo.chip).foregroundStyle(Palette.warning) .padding(.horizontal, 8).padding(.vertical, 3) .background(Palette.warningBackground, in: Capsule()) .fixedSize() } } /// A quiet text link: muted, no underline until hovered. struct FactsView: View { let facts: [RosterFact] var wide: Bool var body: some View { VStack(alignment: .leading, spacing: 0) { Hairline() if wide { HStack(alignment: .top, spacing: 0) { ForEach(Array(facts.enumerated()), id: \.element.id) { index, fact in if index > 0 { Rectangle().fill(Palette.border).frame(width: 1) } VStack(alignment: .leading, spacing: 2) { Text(fact.label).font(Typo.factLabel).foregroundStyle(Palette.faint) value(fact) } .padding(.leading, index == 0 ? 0 : 10).padding(.trailing, 10) .frame(maxWidth: .infinity, alignment: .leading) } }.fixedSize(horizontal: false, vertical: true).padding(.top, Metric.gap) } else { Grid(alignment: .leadingFirstTextBaseline, horizontalSpacing: 12, verticalSpacing: 8) { ForEach(facts) { fact in GridRow { Text(fact.label).font(Typo.factLabel).foregroundStyle(Palette.faint).frame(width: 64, alignment: .leading) value(fact).frame(maxWidth: .infinity, alignment: .leading) } } }.padding(.top, Metric.gap) } } } private func value(_ fact: RosterFact) -> some View { VStack(alignment: .leading, spacing: 1) { Text(fact.value).font(fact.code ? Typo.code : Typo.factValue).foregroundStyle(Palette.text) .fixedSize(horizontal: false, vertical: true).textSelection(.enabled) if let detail = fact.detail { Text(detail).font(fact.code ? Font.system(.caption, design: .monospaced) : Typo.factLabel).foregroundStyle(Palette.secondary) } }.accessibilityElement(children: .combine) } } struct QuietLink: View { let title: String var icon: String? var action: () -> Void = {} @State private var hovering = false var body: some View { Button(action: action) { HStack(spacing: 3) { Text(title).underline(hovering) if let icon { Image(systemName: icon).font(.system(size: 10, weight: .semibold)) } } .font(Typo.secondary).foregroundStyle(hovering ? Palette.text : Palette.secondary) .frame(minHeight: Metric.target).contentShape(Rectangle()) } .buttonStyle(.plain).onHover { hovering = $0 } } } /// Answer buttons: side by side at equal widths only when every label fits /// its equal share, otherwise one per line at full width. ViewThatFits kept /// the row whenever the labels' total fitted, then shared the width out /// equally, so one long option spilled out of its button. struct ChoiceRow: Layout { var spacing: CGFloat = 10 static func fitsInRow(_ ideals: [CGFloat], width: CGFloat, spacing: CGFloat) -> Bool { guard ideals.count > 1 else { return true } let share = (width - spacing * CGFloat(ideals.count - 1)) / CGFloat(ideals.count) return ideals.allSatisfy { $0 <= share + 0.01 } } private func share(_ width: CGFloat, _ count: Int) -> CGFloat { (width - spacing * CGFloat(count - 1)) / CGFloat(count) } private func arrangement(_ width: CGFloat?, _ subviews: Subviews) -> (row: Bool, width: CGFloat) { let ideals = subviews.map { $0.sizeThatFits(.unspecified).width } guard let width, width.isFinite else { return (true, (ideals.max() ?? 0) * CGFloat(ideals.count) + spacing * CGFloat(max(ideals.count - 1, 0))) } return (Self.fitsInRow(ideals, width: width, spacing: spacing), width) } func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { guard !subviews.isEmpty else { return .zero } let (row, width) = arrangement(proposal.width, subviews) if row { let cell = share(width, subviews.count) let height = subviews.map { $0.sizeThatFits(ProposedViewSize(width: cell, height: nil)).height }.max() ?? 0 return CGSize(width: width, height: height) } let heights = subviews.map { $0.sizeThatFits(ProposedViewSize(width: width, height: nil)).height } return CGSize(width: width, height: heights.reduce(0, +) + spacing * CGFloat(heights.count - 1)) } func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { guard !subviews.isEmpty else { return } let (row, _) = arrangement(bounds.width, subviews) if row { let cell = share(bounds.width, subviews.count) for (index, subview) in subviews.enumerated() { let x = bounds.minX + CGFloat(index) * (cell + spacing) subview.place(at: CGPoint(x: x, y: bounds.minY), proposal: ProposedViewSize(width: cell, height: bounds.height)) } } else { var y = bounds.minY for subview in subviews { let size = ProposedViewSize(width: bounds.width, height: nil) subview.place(at: CGPoint(x: bounds.minX, y: y), proposal: size) y += subview.sizeThatFits(size).height + spacing } } } } /// A button that can show its busy label, as the web's data-busy-label does. struct RosterButton: View { let title: String var primary = false var expanded = false var busy: String? var forced: ControlState? var measure = true /// Busy keeps the title's width: "Sending…" only when it fits, else the /// spinner alone. A ChoiceRow decides row or stack from these widths, so a /// tap must not widen the button and re-stack the row. var busyInPlace = false var action: () -> Void = {} var body: some View { let button = Button(action: action) { if busyInPlace { Text(title).opacity(busy == nil ? 1 : 0) .multilineTextAlignment(.center) .frame(maxWidth: expanded ? .infinity : nil) .overlay { if let busy { ViewThatFits(in: .horizontal) { busyLabel(busy); spinner } } } } else { ZStack { Text(title).opacity(busy == nil ? 1 : 0) if let busy { busyLabel(busy) } } .multilineTextAlignment(.center) .frame(maxWidth: expanded ? .infinity : nil) } } .buttonStyle(EquipoButtonStyle(primary: primary, forced: forced)) .allowsHitTesting(busy == nil) .accessibilityLabel(busy ?? title) if measure { button } else { button } } @Environment(\.colorScheme) private var scheme // The Mac draws the small spinner from the colour scheme, not the tint. private var spinner: some View { ProgressView().controlSize(.small).tint(primary ? .white : Palette.secondary).environment(\.colorScheme, primary ? .dark : scheme) } private func busyLabel(_ busy: String) -> some View { HStack(spacing: 6) { spinner; Text(busy) } } } // MARK: - Raised cards struct SetAsideButton: View { var busy = false var forced: ControlState? var action: () -> Void @State private var hovering = false var body: some View { Button(action: action) { Group { if busy { Text(String(localized: "roster.setting_aside", bundle: .module)).font(Typo.caption).padding(.horizontal, 8) } else { Image(systemName: "xmark").font(.system(size: 13, weight: .semibold)).frame(width: 36, height: 36) } } .foregroundStyle(Palette.secondary) .frame(minWidth: Metric.target, minHeight: Metric.target) .background { let on = hovering || forced == .hover || forced == .pressed RoundedRectangle(cornerRadius: 8, style: .continuous) .fill(forced == .pressed ? Palette.controlFacePressed : on ? Palette.controlFaceHover : .clear) .frame(width: busy ? nil : 32, height: 32) } .contentShape(Rectangle()) } .buttonStyle(.plain).onHover { hovering = $0 } .disabled(busy) .accessibilityLabel(Text(String(localized: "roster.set_aside", bundle: .module))) .help(Text(String(localized: "roster.set_aside", bundle: .module))) } } /// Only things that need you are raised: a surface, a rim and a soft shadow. struct RaisedCard: View { var flat = false @ViewBuilder var content: Content var body: some View { let shape = RoundedRectangle(cornerRadius: Metric.raised, style: .continuous) VStack(alignment: .leading, spacing: Metric.gap) { content } .frame(maxWidth: .infinity, alignment: .leading) .padding(Metric.raisedPadding) .background { shape.fill(flat ? Palette.surface2 : Palette.surface) .shadow(color: Palette.contactShadow.opacity(flat ? 0 : 0.06), radius: 2, y: 2) .shadow(color: Palette.contactShadow.opacity(flat ? 0 : 0.10), radius: 8, y: 6) } .overlay(shape.strokeBorder(flat ? Palette.border : Palette.lightRim, lineWidth: 1)) } } /// The first line of a card, with Set aside centred on it. struct CardHead: View { let text: String var aside: (() -> Void)? var settingAside = false var forced: ControlState? var body: some View { HStack(alignment: .top, spacing: 4) { Text(text).font(Typo.cardLine).foregroundStyle(Palette.text) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading) if let aside { // A 44-point target, centred on the first line of text. SetAsideButton(busy: settingAside, forced: forced, action: aside) .padding(.top, -(Metric.target - lineHeight) / 2) .padding(.trailing, -(Metric.target - 32) / 2 - 4) .padding(.bottom, -(Metric.target - lineHeight) / 2) } } } private var lineHeight: CGFloat { #if os(iOS) return 22 #else return 18 #endif } } // MARK: - Sub-chats struct ThreadBubble: View { let turn: ThreadTurn var retry: () -> Void = {} var body: some View { if turn.own { VStack(alignment: .trailing, spacing: 4) { Text(turn.text).font(Typo.thread).foregroundStyle(Palette.text) .fixedSize(horizontal: false, vertical: true) .padding(.horizontal, 12).padding(.vertical, 8) .background(Palette.soft, in: RoundedRectangle(cornerRadius: 14, style: .continuous)) .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Palette.lightRim, lineWidth: 1)) delivery } .padding(.leading, 32) .frame(maxWidth: .infinity, alignment: .trailing) .accessibilityElement(children: .combine) .accessibilityLabel(Text(spoken)) } else { let who = turn.who ?? .coordinator HStack(alignment: .top, spacing: 8) { if turn.person != nil { Image(systemName: "person.crop.circle").font(.system(size: 20)).foregroundStyle(Palette.secondary).frame(width: 24, height: 24) } else { Avatar(who: who, size: 24) } VStack(alignment: .leading, spacing: 3) { HStack(spacing: 6) { Text(turn.person ?? who.name).font(Typo.threadWho).foregroundStyle(Palette.secondary) Text(turn.timeText).font(Typo.time).foregroundStyle(Palette.faint) } Text(turn.text).font(Typo.thread).foregroundStyle(Palette.text).fixedSize(horizontal: false, vertical: true) } .padding(.horizontal, 12).padding(.top, 6).padding(.bottom, 8) .background(Palette.surface, in: RoundedRectangle(cornerRadius: 14, style: .continuous)) .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Palette.border, lineWidth: 1)) Spacer(minLength: 24) } .accessibilityElement(children: .combine) } } } extension ThreadBubble { /// Sent only once the server has it; until then, how it is going. @ViewBuilder var delivery: some View { switch turn.delivery { case nil: Text(String(localized: "thread.sent", bundle: .module)).font(Typo.caption).foregroundStyle(Palette.faint) case .sending: Text(String(localized: "message.sending", bundle: .module)).font(Typo.caption).foregroundStyle(Palette.faint) case .waiting: Button(action: retry) { Text(String(localized: "message.waiting", bundle: .module)).underline() } .buttonStyle(.plain).font(Typo.caption).foregroundStyle(Palette.secondary).frame(minHeight: Metric.target) case .failed: Button(action: retry) { Text(String(localized: "message.failed", bundle: .module)).underline() } .buttonStyle(.plain).font(Typo.caption).foregroundStyle(Palette.negative).frame(minHeight: Metric.target) } } var spoken: String { switch turn.delivery { case nil: return String(localized: "thread.own_spoken \(turn.text)", bundle: .module) case .sending: return String(localized: "message.own_spoken \(turn.text)", bundle: .module) + ". " + String(localized: "message.sending", bundle: .module) case .waiting: return String(localized: "message.own_spoken \(turn.text)", bundle: .module) + ". " + String(localized: "message.waiting", bundle: .module) case .failed: return String(localized: "message.own_spoken \(turn.text)", bundle: .module) + ". " + String(localized: "message.failed", bundle: .module) } } } struct ReadingLine: View { let who: Specialist var body: some View { HStack(spacing: 8) { HStack(spacing: 3) { ForEach(0..<3, id: \.self) { _ in Circle().frame(width: 4, height: 4) } } Text(String(localized: "thread.reading \(who.name)", bundle: .module)) } .font(Typo.secondary).foregroundStyle(Palette.secondary) .accessibilityElement(children: .combine) } } /// The card's composer: the main composer's pill, smaller. The send /// button is a 44-point target centred in a 46-point pill. struct MiniComposer: View { var placeholder = String(localized: "task.reply", bundle: .module) @State var text: String var busy = false var focused = false var onSend: (String) -> Void = { _ in } init(placeholder: String = String(localized: "task.reply", bundle: .module), text: String = "", busy: Bool = false, focused: Bool = false, onSend: @escaping (String) -> Void = { _ in }) { self.placeholder = placeholder; _text = State(initialValue: text); self.busy = busy; self.focused = focused; self.onSend = onSend } var body: some View { let has = !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty let shape = RoundedRectangle(cornerRadius: 23, style: .continuous) HStack(alignment: .bottom, spacing: 4) { TextField("", text: $text, prompt: Text(placeholder).foregroundColor(Palette.placeholder), axis: .vertical) .font(Typo.body).foregroundStyle(Palette.controlText).textFieldStyle(.plain) .lineLimit(1...5) .focusEffectDisabled() .padding(.leading, 16).padding(.vertical, 12) .frame(minHeight: 46) .accessibilityLabel(placeholder) Button { if has { onSend(text); text = "" } } label: { Group { if busy { HStack(spacing: 5) { ProgressView().controlSize(.mini).tint(.white); Text(String(localized: "action.sending", bundle: .module)).font(Typo.caption) } .foregroundStyle(.white).padding(.horizontal, 12).frame(height: 36) .background(Palette.primaryFill, in: Capsule()) } else { Image(systemName: "arrow.up").font(.system(size: 14, weight: .bold)) .foregroundStyle(has ? Color.white : Palette.faint) .frame(width: 36, height: 36) .background(has ? Palette.primaryFill : Palette.surface2, in: Circle()) } } .frame(minWidth: 44, minHeight: 44).contentShape(Rectangle()) } .buttonStyle(.plain).padding(.trailing, 1).padding(.bottom, 1) .accessibilityLabel(Text(busy ? String(localized: "action.sending", bundle: .module) : String(localized: "composer.send", bundle: .module))) .disabled(!has || busy) } .background(Palette.surface, in: shape) .overlay(shape.strokeBorder(focused || has ? Palette.accent : Palette.controlBorder, lineWidth: 1)) .background(shape.stroke(Palette.accent.opacity(focused || has ? 0.18 : 0), lineWidth: 6)) } } // MARK: - Messages, the thinking line and the roll-up public struct CoordinatorMessage: View { let messageID: String let reply: TranscriptReply let transcript: MarkdownTranscript let origin: URL let openTask: (String) -> Void public init(reply: TranscriptReply, messageID: String, origin: URL, transcript: MarkdownTranscript, openTask: @escaping (String) -> Void) { self.transcript = transcript self.messageID = messageID; self.reply = reply; self.origin = origin; self.openTask = openTask } public var body: some View { VStack(alignment: .leading, spacing: 4) { HStack(spacing: 0) { CoordinatorMark(size: 22).frame(width: Metric.indent, alignment: .leading) Text(reply.date.formatted(date: .omitted, time: .shortened)).font(Typo.time).foregroundStyle(Palette.faint) }.frame(minHeight: Metric.tile) ChatMarkdownView(reply.text, draft: reply.draft, messageID: messageID, origin: origin, transcript: transcript, openTask: openTask) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .contain) } } struct OwnMessage: View { let text: String var attachments: [MessageAttachment] = [] var client: EquipoClient? = nil var body: some View { VStack(alignment: .leading, spacing: 8) { if !attachments.isEmpty, let client { MessageAttachments(attachments, client: client) } if !text.isEmpty { Text(text).font(Typo.message).foregroundStyle(Palette.text).fixedSize(horizontal: false, vertical: true) .accessibilityLabel(Text(String(localized: "message.own_spoken \(text)", bundle: .module))) } } .padding(.horizontal, 14).padding(.vertical, 10) .background(Palette.soft, in: RoundedRectangle(cornerRadius: 18, style: .continuous)) .overlay(RoundedRectangle(cornerRadius: 18, style: .continuous).strokeBorder(Palette.lightRim.opacity(0.7), lineWidth: 1)) .padding(.leading, 48) .frame(maxWidth: .infinity, alignment: .trailing) .accessibilityElement(children: .contain) } } /// One line: the mark, the real activity, elapsed time and a quiet Stop. struct TodayDivider: View { let label: String var body: some View { HStack(spacing: 12) { Hairline() Text(label).font(Typo.caption).foregroundStyle(Palette.secondary).fixedSize() Hairline() }.accessibilityAddTraits(.isHeader) } } // MARK: - Layout /// Wraps its children onto as many lines as they need. struct FlowLayout: Layout { var spacing: CGFloat = 8 var lineSpacing: CGFloat = 4 func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { let rows = arrange(width: proposal.width ?? .infinity, subviews: subviews) let width = rows.map { $0.width }.max() ?? 0 let height = rows.reduce(0) { $0 + $1.height } + CGFloat(max(0, rows.count - 1)) * lineSpacing return CGSize(width: proposal.width.map { min($0, width) } ?? width, height: height) } func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { var y = bounds.minY for row in arrange(width: bounds.width, subviews: subviews) { var x = bounds.minX for index in row.items { let size = subviews[index].sizeThatFits(.unspecified) let fitted = min(size.width, bounds.maxX - x) subviews[index].place(at: CGPoint(x: x, y: y + (row.height - size.height) / 2), proposal: ProposedViewSize(width: fitted, height: size.height)) x += fitted + spacing } y += row.height + lineSpacing } } private struct Row { var items: [Int] = []; var width: CGFloat = 0; var height: CGFloat = 0 } private func arrange(width: CGFloat, subviews: Subviews) -> [Row] { var rows: [Row] = [Row()] for (index, view) in subviews.enumerated() { let size = view.sizeThatFits(.unspecified) if size.width == 0 && size.height == 0 { continue } var row = rows[rows.count - 1] let needed = row.items.isEmpty ? size.width : row.width + spacing + size.width if needed > width && !row.items.isEmpty { rows.append(Row(items: [index], width: size.width, height: size.height)) continue } row.items.append(index); row.width = needed; row.height = max(row.height, size.height) rows[rows.count - 1] = row } return rows.filter { !$0.items.isEmpty } } } /// Roster's input surface, with a persistent accessible name. struct RosterField: View { let title: String @Binding var text: String var body: some View { TextField("", text: $text, prompt: Text(title).foregroundStyle(Palette.placeholder)) .textFieldStyle(.plain).font(Typo.body).foregroundStyle(Palette.controlText) .padding(12).frame(minHeight: 44) .background(Palette.surface2, in: RoundedRectangle(cornerRadius: 10)) .overlay(RoundedRectangle(cornerRadius: 10).stroke(Palette.border, lineWidth: 1)) .accessibilityLabel(title) } } struct RosterCheck: View { let title: String @Binding var isOn: Bool var body: some View { Toggle(isOn: $isOn) { Text(title).font(Typo.secondary).foregroundStyle(Palette.text) } .toggleStyle(RosterCheckStyle()) } } private struct RosterCheckStyle: ToggleStyle { func makeBody(configuration: Configuration) -> some View { Button { configuration.isOn.toggle() } label: { HStack(alignment: .firstTextBaseline, spacing: 10) { Image(systemName: configuration.isOn ? "checkmark.square.fill" : "square") .foregroundStyle(configuration.isOn ? Palette.accent : Palette.secondary) configuration.label }.frame(minHeight: 44, alignment: .leading).contentShape(Rectangle()) }.buttonStyle(.plain) .accessibilityRepresentation { Toggle(isOn: configuration.$isOn) { configuration.label } .toggleStyle(.automatic) } } } // MARK: - Paused work /// Why the work waits or stopped (pause_view.go's lead): the bold part in /// the pause's tone, the rest, what happens next, and Run now for its /// creator, naming what it would use. struct PauseLead: View { let pause: TaskPause var onRunNow: ((TaskPause.RunNow) -> Void)? var body: some View { VStack(alignment: .leading, spacing: 8) { if !pause.strong.isEmpty || !pause.rest.isEmpty { Text("\(Text(pause.strong).bold().foregroundStyle(pause.tone.dot))\(Text(pause.rest).foregroundStyle(Palette.text))") .font(Typo.body).fixedSize(horizontal: false, vertical: true) } if !pause.next.isEmpty { Text(pause.next).font(Typo.factLabel).foregroundStyle(Palette.secondary).fixedSize(horizontal: false, vertical: true) } if let run = pause.runNow, let onRunNow { VStack(alignment: .leading, spacing: 4) { RosterButton(title: run.label) { onRunNow(run) } if let note = pause.note { Text(note).font(Typo.factLabel).foregroundStyle(Palette.secondary) } } } } .padding(12) .frame(maxWidth: .infinity, alignment: .leading) .background(pause.tone.halo, in: RoundedRectangle(cornerRadius: 12)) .accessibilityElement(children: .contain) } }