oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1// Ported from the r7 mockups (RosterViews.swift): marks, bylines, cards,
2// sub-chats and messages. Fed by EquipoKit/Presentation, never by fixtures.
3import SwiftUI
4
5// MARK: - Marks and tiles
6
7/// The web's coordinator mark (chat.html "roster-mark"): an outline
8/// four-point star in a 24-unit box.
9struct SparkleShape: Shape {
10 func path(in rect: CGRect) -> Path {
11 let s = min(rect.width, rect.height) / 24
12 let ox = rect.midX - 12 * s, oy = rect.midY - 12 * s
13 func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: ox + x * s, y: oy + y * s) }
14 var path = Path()
15 path.move(to: p(12, 3))
16 path.addCurve(to: p(21, 12), control1: p(13.1, 8.8), control2: p(15.2, 10.9))
17 path.addCurve(to: p(12, 21), control1: p(15.2, 13.1), control2: p(13.1, 15.2))
18 path.addCurve(to: p(3, 12), control1: p(10.9, 15.2), control2: p(8.8, 13.1))
19 path.addCurve(to: p(12, 3), control1: p(8.8, 10.9), control2: p(10.9, 8.8))
20 path.closeSubpath()
21 return path
22 }
23}
24/// The coordinator: a bare, muted outline sparkle. No name on screen.
25struct CoordinatorMark: View {
26 var size: CGFloat = 22
27 var thinking = false
28 var body: some View {
29 SparkleShape()
30 .stroke(Palette.secondary, style: StrokeStyle(lineWidth: size / 24 * 1.6, lineCap: .round, lineJoin: .round))
31 .frame(width: size, height: size)
32 .rotationEffect(.degrees(thinking ? 45 : 0)).scaleEffect(thinking ? 0.85 : 1).opacity(thinking ? 0.5 : 1)
33 .animation(thinking ? .easeInOut(duration: 1.3).repeatForever(autoreverses: true) : nil, value: thinking)
34 .accessibilityLabel(Text(Specialist.coordinator.name))
35 }
36}
37/// A specialist: its icon centred in a tile, beside its name. Never a letter.
38struct SpecialistTile: View {
39 let who: Specialist
40 var size: CGFloat = Metric.tile
41 var body: some View {
42 let shape = RoundedRectangle(cornerRadius: size * 0.3, style: .continuous)
43 ZStack {
44 shape.fill(Palette.surface)
45 .shadow(color: Palette.contactShadow.opacity(0.08), radius: 1, y: 1)
46 shape.strokeBorder(Palette.border, lineWidth: 1)
47 Image(systemName: who.symbol)
48 .font(.system(size: size * 0.46, weight: .medium))
49 .foregroundStyle(Palette.text)
50 .frame(width: size, height: size, alignment: .center)
51 }
52 .frame(width: size, height: size)
53 .accessibilityHidden(true)
54 }
55}
56/// The author column: a tile for a specialist, the bare mark for the coordinator.
57struct Avatar: View {
58 let who: Specialist
59 var size: CGFloat = Metric.tile
60 var body: some View {
61 if who == .coordinator {
62 CoordinatorMark(size: size * 0.74).frame(width: size, height: size, alignment: .leading)
63 } else {
64 SpecialistTile(who: who, size: size)
65 }
66 }
67}
68/// A project's monogram, kept neutral: no hue, so nothing reads as purple.
69struct Monogram: View {
70 let name: String
71 var size: CGFloat = 16
72 var body: some View {
73 Text(String(name.prefix(1)).uppercased())
74 .font(.system(size: size * 0.62, weight: .bold, design: .rounded))
75 .foregroundStyle(Palette.neutral)
76 .frame(width: size, height: size)
77 .background(Palette.neutralBackground, in: RoundedRectangle(cornerRadius: size * 0.28, style: .continuous))
78 .accessibilityHidden(true)
79 }
80}
81
82// MARK: - Byline
83
84struct ProjectChip: View {
85 let name: String
86 var action: (() -> Void)?
87 var menu: Binding<Bool>?
88 @State private var hovering = false
89 var body: some View {
90 chip
91 }
92 @ViewBuilder private var chip: some View {
93 let label = HStack(spacing: 4) {
94 Monogram(name: name)
95 Text(name).lineLimit(1).truncationMode(.tail)
96 .underline(hovering && action != nil)
97 }
98 .font(Typo.bylineVerb).foregroundStyle(Palette.secondary)
99 if let action {
100 Button(action: action) { label.frame(minHeight: Metric.tile).contentShape(Rectangle()) }
101 .buttonStyle(.plain).onHover { hovering = $0 }
102 .accessibilityLabel(Text(String(localized: "project.spoken \(name)", bundle: .module)))
103 } else { label }
104 }
105}
106/// "Engineering reports · W Woodstar 11:59". The coordinator's byline is
107/// only its mark, the project and the time.
108struct Byline: View {
109 let byline: RosterByline
110 var onProject: (() -> Void)?
111 var menu: Binding<Bool>?
112 var body: some View {
113 HStack(alignment: .center, spacing: 0) {
114 Avatar(who: byline.who).frame(width: Metric.indent, alignment: .leading)
115 FlowLayout(spacing: 6, lineSpacing: 2) {
116 if byline.showsName {
117 Text(byline.who.name).font(Typo.bylineName).foregroundStyle(Palette.text)
118 Text(byline.verb).font(Typo.bylineVerb).foregroundStyle(Palette.secondary)
119 }
120 if let project = byline.project {
121 if byline.showsName { Text("·").font(Typo.bylineVerb).foregroundStyle(Palette.faint).accessibilityHidden(true) }
122 ProjectChip(name: project, action: onProject ?? {}, menu: menu)
123 }
124 if let time = byline.timeText { Text(time).font(Typo.time).foregroundStyle(Palette.faint) }
125 }
126 }
127 .frame(minHeight: Metric.tile)
128 .accessibilityElement(children: .combine)
129 .accessibilityLabel(byline.spoken)
130 }
131}
132
133// MARK: - Stage track
134
135/// Five stops edge to edge: four equal spans, the last stop only its dot.
136/// Each label centres under its dot and is only nudged in at the two ends.
137struct StageTrack: View {
138 let track: [TrackStop]
139 var allLabels: Bool
140 private let slot: CGFloat = 11
141 var body: some View {
142 VStack(alignment: .leading, spacing: 6) {
143 Canvas { context, size in
144 let y = size.height / 2
145 let xs = positions(size.width)
146 for i in 0..<(xs.count - 1) {
147 let line = Path(CGRect(x: xs[i], y: y - 1, width: xs[i + 1] - xs[i], height: 2))
148 context.fill(line, with: .color(track[i].state == .done ? Palette.positive : Palette.controlBorder))
149 }
150 for (i, stop) in track.enumerated() {
151 let c = CGPoint(x: xs[i], y: y)
152 switch stop.state {
153 case .done:
154 context.fill(Path(ellipseIn: CGRect(x: c.x - 4, y: c.y - 4, width: 8, height: 8)), with: .color(Palette.positive))
155 case .current:
156 let tone = stop.tone ?? .positive
157 context.fill(Path(ellipseIn: CGRect(x: c.x - 9.5, y: c.y - 9.5, width: 19, height: 19)), with: .color(tone.halo))
158 context.fill(Path(ellipseIn: CGRect(x: c.x - 5.5, y: c.y - 5.5, width: 11, height: 11)), with: .color(tone.dot))
159 if tone == .paused {
160 // A still pause mark in the dot: never colour alone.
161 for dx in [-1.75, 1.75] {
162 context.fill(Path(CGRect(x: c.x + dx - 0.75, y: c.y - 2.5, width: 1.5, height: 5)), with: .color(Palette.surface))
163 }
164 }
165 case .todo:
166 let dot = Path(ellipseIn: CGRect(x: c.x - 4, y: c.y - 4, width: 8, height: 8))
167 context.fill(dot, with: .color(Palette.surface))
168 context.stroke(dot, with: .color(Palette.lineStrong), lineWidth: 1)
169 }
170 }
171 }
172 .frame(height: 20)
173 TrackLabels(slot: slot) {
174 ForEach(track) { stop in
175 let current = stop.state == .current
176 Text(stop.label ?? stop.stage.label)
177 .font(current ? Typo.eyebrow : Typo.factLabel)
178 .foregroundStyle(current ? (stop.tone ?? .positive).text : Palette.secondary)
179 .fixedSize()
180 .opacity(allLabels || current ? 1 : 0)
181 }
182 }
183 }
184 .accessibilityElement()
185 .accessibilityLabel(Text(String(localized: "track.spoken \(currentLabel)", bundle: .module)))
186 .accessibilityValue(Text(String(localized: "track.position \(position) \(total)", bundle: .module)))
187 }
188 private var currentLabel: String {
189 guard let stop = track.first(where: { $0.state == .current }) else { return "" }
190 // Paused, stopped or needs you: the stage too ("In progress, Paused").
191 return stop.label.map { stop.stage.label + ", " + $0 } ?? stop.stage.label
192 }
193 private var position: String { ((track.firstIndex { $0.state == .current } ?? 0) + 1).formatted() }
194 private var total: String { track.count.formatted() }
195 private func positions(_ width: CGFloat) -> [CGFloat] {
196 let r = slot / 2
197 return track.indices.map { r + CGFloat($0) * (width - slot) / CGFloat(max(1, track.count - 1)) }
198 }
199}
200/// Places each label centred on its dot, clamped inside the track's width.
201struct TrackLabels: Layout {
202 let slot: CGFloat
203 func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
204 CGSize(width: proposal.width ?? 300, height: subviews.map { $0.sizeThatFits(.unspecified).height }.max() ?? 0)
205 }
206 func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
207 let r = slot / 2
208 for (i, view) in subviews.enumerated() {
209 let size = view.sizeThatFits(.unspecified)
210 let centre = bounds.minX + r + CGFloat(i) * (bounds.width - slot) / CGFloat(max(1, subviews.count - 1))
211 let x = min(max(bounds.minX, centre - size.width / 2), bounds.maxX - size.width)
212 view.place(at: CGPoint(x: x, y: bounds.minY), proposal: .unspecified)
213 }
214 }
215}
216extension StageTone {
217 var dot: Color {
218 switch self {
219 case .warning: return Palette.warning
220 case .negative: return Palette.negative
221 case .paused: return Palette.paused
222 case .positive: return Palette.positive
223 }
224 }
225 var halo: Color {
226 switch self {
227 case .warning: return Palette.warningBackground
228 case .negative: return Palette.negativeBackground
229 case .paused: return Palette.pausedBackground
230 case .positive: return Palette.positiveBackground
231 }
232 }
233 var text: Color { dot }
234 /// The eyebrow is coloured only when the stage needs attention.
235 var eyebrow: Color { self == .positive ? Palette.secondary : dot }
236}
237
238// MARK: - Facts, chips and links
239
240struct NeedsChip: View {
241 var body: some View {
242 HStack(spacing: 4) {
243 Image(systemName: "hand.raised").font(.system(size: 11, weight: .semibold))
244 Text(String(localized: "chip.needs_you", bundle: .module)).textCase(.uppercase).kerning(0.3)
245 }
246 .font(Typo.chip).foregroundStyle(Palette.warning)
247 .padding(.horizontal, 8).padding(.vertical, 3)
248 .background(Palette.warningBackground, in: Capsule())
249 .fixedSize()
250 }
251}
252/// A quiet text link: muted, no underline until hovered.
253struct FactsView: View {
254 let facts: [RosterFact]
255 var wide: Bool
256 var body: some View {
257 VStack(alignment: .leading, spacing: 0) {
258 Hairline()
259 if wide {
260 HStack(alignment: .top, spacing: 0) {
261 ForEach(Array(facts.enumerated()), id: \.element.id) { index, fact in
262 if index > 0 { Rectangle().fill(Palette.border).frame(width: 1) }
263 VStack(alignment: .leading, spacing: 2) {
264 Text(fact.label).font(Typo.factLabel).foregroundStyle(Palette.faint)
265 value(fact)
266 }
267 .padding(.leading, index == 0 ? 0 : 10).padding(.trailing, 10)
268 .frame(maxWidth: .infinity, alignment: .leading)
269 }
270 }.fixedSize(horizontal: false, vertical: true).padding(.top, Metric.gap)
271 } else {
272 Grid(alignment: .leadingFirstTextBaseline, horizontalSpacing: 12, verticalSpacing: 8) {
273 ForEach(facts) { fact in
274 GridRow {
275 Text(fact.label).font(Typo.factLabel).foregroundStyle(Palette.faint).frame(width: 64, alignment: .leading)
276 value(fact).frame(maxWidth: .infinity, alignment: .leading)
277 }
278 }
279 }.padding(.top, Metric.gap)
280 }
281 }
282 }
283 private func value(_ fact: RosterFact) -> some View {
284 VStack(alignment: .leading, spacing: 1) {
285 Text(fact.value).font(fact.code ? Typo.code : Typo.factValue).foregroundStyle(Palette.text)
286 .fixedSize(horizontal: false, vertical: true).textSelection(.enabled)
287 if let detail = fact.detail {
288 Text(detail).font(fact.code ? Font.system(.caption, design: .monospaced) : Typo.factLabel).foregroundStyle(Palette.secondary)
289 }
290 }.accessibilityElement(children: .combine)
291 }
292}
293struct QuietLink: View {
294 let title: String
295 var icon: String?
296 var action: () -> Void = {}
297 @State private var hovering = false
298 var body: some View {
299 Button(action: action) {
300 HStack(spacing: 3) {
301 Text(title).underline(hovering)
302 if let icon { Image(systemName: icon).font(.system(size: 10, weight: .semibold)) }
303 }
304 .font(Typo.secondary).foregroundStyle(hovering ? Palette.text : Palette.secondary)
305 .frame(minHeight: Metric.target).contentShape(Rectangle())
306 }
307 .buttonStyle(.plain).onHover { hovering = $0 }
308 }
309}
310/// Answer buttons: side by side at equal widths only when every label fits
311/// its equal share, otherwise one per line at full width. ViewThatFits kept
312/// the row whenever the labels' total fitted, then shared the width out
313/// equally, so one long option spilled out of its button.
314struct ChoiceRow: Layout {
315 var spacing: CGFloat = 10
316
317 static func fitsInRow(_ ideals: [CGFloat], width: CGFloat, spacing: CGFloat) -> Bool {
318 guard ideals.count > 1 else { return true }
319 let share = (width - spacing * CGFloat(ideals.count - 1)) / CGFloat(ideals.count)
320 return ideals.allSatisfy { $0 <= share + 0.01 }
321 }
322
323 private func share(_ width: CGFloat, _ count: Int) -> CGFloat {
324 (width - spacing * CGFloat(count - 1)) / CGFloat(count)
325 }
326
327 private func arrangement(_ width: CGFloat?, _ subviews: Subviews) -> (row: Bool, width: CGFloat) {
328 let ideals = subviews.map { $0.sizeThatFits(.unspecified).width }
329 guard let width, width.isFinite else {
330 return (true, (ideals.max() ?? 0) * CGFloat(ideals.count) + spacing * CGFloat(max(ideals.count - 1, 0)))
331 }
332 return (Self.fitsInRow(ideals, width: width, spacing: spacing), width)
333 }
334
335 func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
336 guard !subviews.isEmpty else { return .zero }
337 let (row, width) = arrangement(proposal.width, subviews)
338 if row {
339 let cell = share(width, subviews.count)
340 let height = subviews.map { $0.sizeThatFits(ProposedViewSize(width: cell, height: nil)).height }.max() ?? 0
341 return CGSize(width: width, height: height)
342 }
343 let heights = subviews.map { $0.sizeThatFits(ProposedViewSize(width: width, height: nil)).height }
344 return CGSize(width: width, height: heights.reduce(0, +) + spacing * CGFloat(heights.count - 1))
345 }
346
347 func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
348 guard !subviews.isEmpty else { return }
349 let (row, _) = arrangement(bounds.width, subviews)
350 if row {
351 let cell = share(bounds.width, subviews.count)
352 for (index, subview) in subviews.enumerated() {
353 let x = bounds.minX + CGFloat(index) * (cell + spacing)
354 subview.place(at: CGPoint(x: x, y: bounds.minY), proposal: ProposedViewSize(width: cell, height: bounds.height))
355 }
356 } else {
357 var y = bounds.minY
358 for subview in subviews {
359 let size = ProposedViewSize(width: bounds.width, height: nil)
360 subview.place(at: CGPoint(x: bounds.minX, y: y), proposal: size)
361 y += subview.sizeThatFits(size).height + spacing
362 }
363 }
364 }
365}
366
367/// A button that can show its busy label, as the web's data-busy-label does.
368struct RosterButton: View {
369 let title: String
370 var primary = false
371 var expanded = false
372 var busy: String?
373 var forced: ControlState?
374 var measure = true
375 /// Busy keeps the title's width: "Sending…" only when it fits, else the
376 /// spinner alone. A ChoiceRow decides row or stack from these widths, so a
377 /// tap must not widen the button and re-stack the row.
378 var busyInPlace = false
379 var action: () -> Void = {}
380 var body: some View {
381 let button = Button(action: action) {
382 if busyInPlace {
383 Text(title).opacity(busy == nil ? 1 : 0)
384 .multilineTextAlignment(.center)
385 .frame(maxWidth: expanded ? .infinity : nil)
386 .overlay {
387 if let busy {
388 ViewThatFits(in: .horizontal) { busyLabel(busy); spinner }
389 }
390 }
391 } else {
392 ZStack {
393 Text(title).opacity(busy == nil ? 1 : 0)
394 if let busy { busyLabel(busy) }
395 }
396 .multilineTextAlignment(.center)
397 .frame(maxWidth: expanded ? .infinity : nil)
398 }
399 }
400 .buttonStyle(EquipoButtonStyle(primary: primary, forced: forced))
401 .allowsHitTesting(busy == nil)
402 .accessibilityLabel(busy ?? title)
403 if measure { button } else { button }
404 }
405 @Environment(\.colorScheme) private var scheme
406 // The Mac draws the small spinner from the colour scheme, not the tint.
407 private var spinner: some View {
408 ProgressView().controlSize(.small).tint(primary ? .white : Palette.secondary).environment(\.colorScheme, primary ? .dark : scheme)
409 }
410 private func busyLabel(_ busy: String) -> some View {
411 HStack(spacing: 6) { spinner; Text(busy) }
412 }
413}
414
415// MARK: - Raised cards
416
417struct SetAsideButton: View {
418 var busy = false
419 var forced: ControlState?
420 var action: () -> Void
421 @State private var hovering = false
422 var body: some View {
423 Button(action: action) {
424 Group {
425 if busy {
426 Text(String(localized: "roster.setting_aside", bundle: .module)).font(Typo.caption).padding(.horizontal, 8)
427 } else {
428 Image(systemName: "xmark").font(.system(size: 13, weight: .semibold)).frame(width: 36, height: 36)
429 }
430 }
431 .foregroundStyle(Palette.secondary)
432 .frame(minWidth: Metric.target, minHeight: Metric.target)
433 .background {
434 let on = hovering || forced == .hover || forced == .pressed
435 RoundedRectangle(cornerRadius: 8, style: .continuous)
436 .fill(forced == .pressed ? Palette.controlFacePressed : on ? Palette.controlFaceHover : .clear)
437 .frame(width: busy ? nil : 32, height: 32)
438 }
439 .contentShape(Rectangle())
440 }
441 .buttonStyle(.plain).onHover { hovering = $0 }
442 .disabled(busy)
443 .accessibilityLabel(Text(String(localized: "roster.set_aside", bundle: .module)))
444 .help(Text(String(localized: "roster.set_aside", bundle: .module)))
445 }
446}
447/// Only things that need you are raised: a surface, a rim and a soft shadow.
448struct RaisedCard<Content: View>: View {
449 var flat = false
450 @ViewBuilder var content: Content
451 var body: some View {
452 let shape = RoundedRectangle(cornerRadius: Metric.raised, style: .continuous)
453 VStack(alignment: .leading, spacing: Metric.gap) { content }
454 .frame(maxWidth: .infinity, alignment: .leading)
455 .padding(Metric.raisedPadding)
456 .background {
457 shape.fill(flat ? Palette.surface2 : Palette.surface)
458 .shadow(color: Palette.contactShadow.opacity(flat ? 0 : 0.06), radius: 2, y: 2)
459 .shadow(color: Palette.contactShadow.opacity(flat ? 0 : 0.10), radius: 8, y: 6)
460 }
461 .overlay(shape.strokeBorder(flat ? Palette.border : Palette.lightRim, lineWidth: 1))
462 }
463}
464/// The first line of a card, with Set aside centred on it.
465struct CardHead: View {
466 let text: String
467 var aside: (() -> Void)?
468 var settingAside = false
469 var forced: ControlState?
470 var body: some View {
471 HStack(alignment: .top, spacing: 4) {
472 Text(text).font(Typo.cardLine).foregroundStyle(Palette.text)
473 .fixedSize(horizontal: false, vertical: true)
474 .frame(maxWidth: .infinity, alignment: .leading)
475 if let aside {
476 // A 44-point target, centred on the first line of text.
477 SetAsideButton(busy: settingAside, forced: forced, action: aside)
478 .padding(.top, -(Metric.target - lineHeight) / 2)
479 .padding(.trailing, -(Metric.target - 32) / 2 - 4)
480 .padding(.bottom, -(Metric.target - lineHeight) / 2)
481 }
482 }
483 }
484 private var lineHeight: CGFloat {
485 #if os(iOS)
486 return 22
487 #else
488 return 18
489 #endif
490 }
491}
492// MARK: - Sub-chats
493
494struct ThreadBubble: View {
495 let turn: ThreadTurn
496 var retry: () -> Void = {}
497 var body: some View {
498 if turn.own {
499 VStack(alignment: .trailing, spacing: 4) {
500 Text(turn.text).font(Typo.thread).foregroundStyle(Palette.text)
501 .fixedSize(horizontal: false, vertical: true)
502 .padding(.horizontal, 12).padding(.vertical, 8)
503 .background(Palette.soft, in: RoundedRectangle(cornerRadius: 14, style: .continuous))
504 .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Palette.lightRim, lineWidth: 1))
505 delivery
506 }
507 .padding(.leading, 32)
508 .frame(maxWidth: .infinity, alignment: .trailing)
509 .accessibilityElement(children: .combine)
510 .accessibilityLabel(Text(spoken))
511 } else {
512 let who = turn.who ?? .coordinator
513 HStack(alignment: .top, spacing: 8) {
514 if turn.person != nil {
515 Image(systemName: "person.crop.circle").font(.system(size: 20)).foregroundStyle(Palette.secondary).frame(width: 24, height: 24)
516 } else { Avatar(who: who, size: 24) }
517 VStack(alignment: .leading, spacing: 3) {
518 HStack(spacing: 6) {
519 Text(turn.person ?? who.name).font(Typo.threadWho).foregroundStyle(Palette.secondary)
520 Text(turn.timeText).font(Typo.time).foregroundStyle(Palette.faint)
521 }
522 Text(turn.text).font(Typo.thread).foregroundStyle(Palette.text).fixedSize(horizontal: false, vertical: true)
523 }
524 .padding(.horizontal, 12).padding(.top, 6).padding(.bottom, 8)
525 .background(Palette.surface, in: RoundedRectangle(cornerRadius: 14, style: .continuous))
526 .overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(Palette.border, lineWidth: 1))
527 Spacer(minLength: 24)
528 }
529 .accessibilityElement(children: .combine)
530 }
531 }
532}
533extension ThreadBubble {
534 /// Sent only once the server has it; until then, how it is going.
535 @ViewBuilder var delivery: some View {
536 switch turn.delivery {
537 case nil: Text(String(localized: "thread.sent", bundle: .module)).font(Typo.caption).foregroundStyle(Palette.faint)
538 case .sending: Text(String(localized: "message.sending", bundle: .module)).font(Typo.caption).foregroundStyle(Palette.faint)
539 case .waiting:
540 Button(action: retry) { Text(String(localized: "message.waiting", bundle: .module)).underline() }
541 .buttonStyle(.plain).font(Typo.caption).foregroundStyle(Palette.secondary).frame(minHeight: Metric.target)
542 case .failed:
543 Button(action: retry) { Text(String(localized: "message.failed", bundle: .module)).underline() }
544 .buttonStyle(.plain).font(Typo.caption).foregroundStyle(Palette.negative).frame(minHeight: Metric.target)
545 }
546 }
547 var spoken: String {
548 switch turn.delivery {
549 case nil: return String(localized: "thread.own_spoken \(turn.text)", bundle: .module)
550 case .sending: return String(localized: "message.own_spoken \(turn.text)", bundle: .module) + ". " + String(localized: "message.sending", bundle: .module)
551 case .waiting: return String(localized: "message.own_spoken \(turn.text)", bundle: .module) + ". " + String(localized: "message.waiting", bundle: .module)
552 case .failed: return String(localized: "message.own_spoken \(turn.text)", bundle: .module) + ". " + String(localized: "message.failed", bundle: .module)
553 }
554 }
555}
556struct ReadingLine: View {
557 let who: Specialist
558 var body: some View {
559 HStack(spacing: 8) {
560 HStack(spacing: 3) { ForEach(0..<3, id: \.self) { _ in Circle().frame(width: 4, height: 4) } }
561 Text(String(localized: "thread.reading \(who.name)", bundle: .module))
562 }
563 .font(Typo.secondary).foregroundStyle(Palette.secondary)
564 .accessibilityElement(children: .combine)
565 }
566}
567/// The card's composer: the main composer's pill, smaller. The send
568/// button is a 44-point target centred in a 46-point pill.
569struct MiniComposer: View {
570 var placeholder = String(localized: "task.reply", bundle: .module)
571 @State var text: String
572 var busy = false
573 var focused = false
574 var onSend: (String) -> Void = { _ in }
575 init(placeholder: String = String(localized: "task.reply", bundle: .module), text: String = "", busy: Bool = false, focused: Bool = false, onSend: @escaping (String) -> Void = { _ in }) {
576 self.placeholder = placeholder; _text = State(initialValue: text); self.busy = busy; self.focused = focused; self.onSend = onSend
577 }
578 var body: some View {
579 let has = !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
580 let shape = RoundedRectangle(cornerRadius: 23, style: .continuous)
581 HStack(alignment: .bottom, spacing: 4) {
582 TextField("", text: $text, prompt: Text(placeholder).foregroundColor(Palette.placeholder), axis: .vertical)
583 .font(Typo.body).foregroundStyle(Palette.controlText).textFieldStyle(.plain)
584 .lineLimit(1...5)
585 .focusEffectDisabled()
586 .padding(.leading, 16).padding(.vertical, 12)
587 .frame(minHeight: 46)
588 .accessibilityLabel(placeholder)
589 Button { if has { onSend(text); text = "" } } label: {
590 Group {
591 if busy {
592 HStack(spacing: 5) { ProgressView().controlSize(.mini).tint(.white); Text(String(localized: "action.sending", bundle: .module)).font(Typo.caption) }
593 .foregroundStyle(.white).padding(.horizontal, 12).frame(height: 36)
594 .background(Palette.primaryFill, in: Capsule())
595 } else {
596 Image(systemName: "arrow.up").font(.system(size: 14, weight: .bold))
597 .foregroundStyle(has ? Color.white : Palette.faint)
598 .frame(width: 36, height: 36)
599 .background(has ? Palette.primaryFill : Palette.surface2, in: Circle())
600 }
601 }
602 .frame(minWidth: 44, minHeight: 44).contentShape(Rectangle())
603 }
604 .buttonStyle(.plain).padding(.trailing, 1).padding(.bottom, 1)
605 .accessibilityLabel(Text(busy ? String(localized: "action.sending", bundle: .module) : String(localized: "composer.send", bundle: .module)))
606 .disabled(!has || busy)
607 }
608 .background(Palette.surface, in: shape)
609 .overlay(shape.strokeBorder(focused || has ? Palette.accent : Palette.controlBorder, lineWidth: 1))
610 .background(shape.stroke(Palette.accent.opacity(focused || has ? 0.18 : 0), lineWidth: 6))
611 }
612}
613
614// MARK: - Messages, the thinking line and the roll-up
615
616public struct CoordinatorMessage: View {
617 let messageID: String
618 let reply: TranscriptReply
619 let transcript: MarkdownTranscript
620 let origin: URL
621 let openTask: (String) -> Void
622 public init(reply: TranscriptReply, messageID: String, origin: URL, transcript: MarkdownTranscript, openTask: @escaping (String) -> Void) {
623 self.transcript = transcript
624 self.messageID = messageID; self.reply = reply; self.origin = origin; self.openTask = openTask
625 }
626 public var body: some View {
627 VStack(alignment: .leading, spacing: 4) {
628 HStack(spacing: 0) {
629 CoordinatorMark(size: 22).frame(width: Metric.indent, alignment: .leading)
630 Text(reply.date.formatted(date: .omitted, time: .shortened)).font(Typo.time).foregroundStyle(Palette.faint)
631 }.frame(minHeight: Metric.tile)
632 ChatMarkdownView(reply.text, draft: reply.draft, messageID: messageID, origin: origin, transcript: transcript, openTask: openTask)
633 }
634 .frame(maxWidth: .infinity, alignment: .leading)
635 .accessibilityElement(children: .contain)
636 }
637}
638struct OwnMessage: View {
639 let text: String
640 var attachments: [MessageAttachment] = []
641 var client: EquipoClient? = nil
642 var body: some View {
643 VStack(alignment: .leading, spacing: 8) {
644 if !attachments.isEmpty, let client { MessageAttachments(attachments, client: client) }
645 if !text.isEmpty { Text(text).font(Typo.message).foregroundStyle(Palette.text).fixedSize(horizontal: false, vertical: true)
646 .accessibilityLabel(Text(String(localized: "message.own_spoken \(text)", bundle: .module))) }
647 }
648 .padding(.horizontal, 14).padding(.vertical, 10)
649 .background(Palette.soft, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
650 .overlay(RoundedRectangle(cornerRadius: 18, style: .continuous).strokeBorder(Palette.lightRim.opacity(0.7), lineWidth: 1))
651 .padding(.leading, 48)
652 .frame(maxWidth: .infinity, alignment: .trailing)
653 .accessibilityElement(children: .contain)
654 }
655}
656/// One line: the mark, the real activity, elapsed time and a quiet Stop.
657struct TodayDivider: View {
658 let label: String
659 var body: some View {
660 HStack(spacing: 12) {
661 Hairline()
662 Text(label).font(Typo.caption).foregroundStyle(Palette.secondary).fixedSize()
663 Hairline()
664 }.accessibilityAddTraits(.isHeader)
665 }
666}
667// MARK: - Layout
668
669/// Wraps its children onto as many lines as they need.
670struct FlowLayout: Layout {
671 var spacing: CGFloat = 8
672 var lineSpacing: CGFloat = 4
673 func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
674 let rows = arrange(width: proposal.width ?? .infinity, subviews: subviews)
675 let width = rows.map { $0.width }.max() ?? 0
676 let height = rows.reduce(0) { $0 + $1.height } + CGFloat(max(0, rows.count - 1)) * lineSpacing
677 return CGSize(width: proposal.width.map { min($0, width) } ?? width, height: height)
678 }
679 func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
680 var y = bounds.minY
681 for row in arrange(width: bounds.width, subviews: subviews) {
682 var x = bounds.minX
683 for index in row.items {
684 let size = subviews[index].sizeThatFits(.unspecified)
685 let fitted = min(size.width, bounds.maxX - x)
686 subviews[index].place(at: CGPoint(x: x, y: y + (row.height - size.height) / 2), proposal: ProposedViewSize(width: fitted, height: size.height))
687 x += fitted + spacing
688 }
689 y += row.height + lineSpacing
690 }
691 }
692 private struct Row { var items: [Int] = []; var width: CGFloat = 0; var height: CGFloat = 0 }
693 private func arrange(width: CGFloat, subviews: Subviews) -> [Row] {
694 var rows: [Row] = [Row()]
695 for (index, view) in subviews.enumerated() {
696 let size = view.sizeThatFits(.unspecified)
697 if size.width == 0 && size.height == 0 { continue }
698 var row = rows[rows.count - 1]
699 let needed = row.items.isEmpty ? size.width : row.width + spacing + size.width
700 if needed > width && !row.items.isEmpty {
701 rows.append(Row(items: [index], width: size.width, height: size.height))
702 continue
703 }
704 row.items.append(index); row.width = needed; row.height = max(row.height, size.height)
705 rows[rows.count - 1] = row
706 }
707 return rows.filter { !$0.items.isEmpty }
708 }
709}
710
711
712/// Roster's input surface, with a persistent accessible name.
713struct RosterField: View {
714 let title: String
715 @Binding var text: String
716 var body: some View {
717 TextField("", text: $text, prompt: Text(title).foregroundStyle(Palette.placeholder))
718 .textFieldStyle(.plain).font(Typo.body).foregroundStyle(Palette.controlText)
719 .padding(12).frame(minHeight: 44)
720 .background(Palette.surface2, in: RoundedRectangle(cornerRadius: 10))
721 .overlay(RoundedRectangle(cornerRadius: 10).stroke(Palette.border, lineWidth: 1))
722 .accessibilityLabel(title)
723 }
724}
725
726struct RosterCheck: View {
727 let title: String
728 @Binding var isOn: Bool
729 var body: some View {
730 Toggle(isOn: $isOn) { Text(title).font(Typo.secondary).foregroundStyle(Palette.text) }
731 .toggleStyle(RosterCheckStyle())
732 }
733}
734
735private struct RosterCheckStyle: ToggleStyle {
736 func makeBody(configuration: Configuration) -> some View {
737 Button { configuration.isOn.toggle() } label: {
738 HStack(alignment: .firstTextBaseline, spacing: 10) {
739 Image(systemName: configuration.isOn ? "checkmark.square.fill" : "square")
740 .foregroundStyle(configuration.isOn ? Palette.accent : Palette.secondary)
741 configuration.label
742 }.frame(minHeight: 44, alignment: .leading).contentShape(Rectangle())
743 }.buttonStyle(.plain)
744 .accessibilityRepresentation {
745 Toggle(isOn: configuration.$isOn) { configuration.label }
746 .toggleStyle(.automatic)
747 }
748 }
749}
750
751// MARK: - Paused work
752
753/// Why the work waits or stopped (pause_view.go's lead): the bold part in
754/// the pause's tone, the rest, what happens next, and Run now for its
755/// creator, naming what it would use.
756struct PauseLead: View {
757 let pause: TaskPause
758 var onRunNow: ((TaskPause.RunNow) -> Void)?
759 var body: some View {
760 VStack(alignment: .leading, spacing: 8) {
761 if !pause.strong.isEmpty || !pause.rest.isEmpty {
762 Text("\(Text(pause.strong).bold().foregroundStyle(pause.tone.dot))\(Text(pause.rest).foregroundStyle(Palette.text))")
763 .font(Typo.body).fixedSize(horizontal: false, vertical: true)
764 }
765 if !pause.next.isEmpty {
766 Text(pause.next).font(Typo.factLabel).foregroundStyle(Palette.secondary).fixedSize(horizontal: false, vertical: true)
767 }
768 if let run = pause.runNow, let onRunNow {
769 VStack(alignment: .leading, spacing: 4) {
770 RosterButton(title: run.label) { onRunNow(run) }
771 if let note = pause.note { Text(note).font(Typo.factLabel).foregroundStyle(Palette.secondary) }
772 }
773 }
774 }
775 .padding(12)
776 .frame(maxWidth: .infinity, alignment: .leading)
777 .background(pause.tone.halo, in: RoundedRectangle(cornerRadius: 12))
778 .accessibilityElement(children: .contain)
779 }
780}
781