Repository Public
1// SP Notes Core2// File: Sources/SPNotesFeatures/Work/Database/DatabaseLayouts.swift3// Description: The six layouts of a database view. Regular: a real table with inline editing, a horizontal board, a4// month grid, a Gantt-like timeline. Compact (phone): cards with a property sheet, stacked board sections,5// a month strip with the agenda of the chosen day, a vertical timeline.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import SPNotesAPI10import SPNotesDesign11import SPNotesSync12import SwiftUI1314/// The selection mark of a row (visible in selection mode, or always in the regular table).15struct DatabaseSelectionMark: View {16 let model: DatabaseModel17 let row: DatabaseRowValues1819 var body: some View {20 let on = model.selection.contains(row.id)21 Button { model.toggleSelection(row.id) } label: {22 Image(systemName: on ? "checkmark.circle.fill" : "circle")23 .font(.system(size: 17))24 .foregroundStyle(on ? NVColor.accent : NVColor.fgMuted)25 .frame(minWidth: 32, minHeight: 32)26 .contentShape(Rectangle())27 }28 .buttonStyle(.plain)29 .accessibilityLabel(on ? LF("Désélectionner « %@ »", row.title) : LF("Sélectionner « %@ »", row.title))30 }31}3233/// What a tap on a row does: toggles the selection in selection mode, opens the row editor otherwise.34@MainActor35func databaseActivate(_ model: DatabaseModel, _ row: DatabaseRowValues) {36 if model.isSelecting { model.toggleSelection(row.id) } else { model.inspector = .row(row.id) }37}3839// MARK: - Table (regular)4041struct DatabaseTableView: View {42 let model: DatabaseModel4344 private func width(_ property: DatabaseProperty) -> CGFloat {45 CGFloat(min(max(property.width ?? (property.type == DatabasePropertyType.title ? 260 : 170), 110), 420))46 }4748 var body: some View {49 let properties = model.visibleProperties50 ScrollView([.horizontal, .vertical]) {51 LazyVStack(alignment: .leading, spacing: 0, pinnedViews: [.sectionHeaders]) {52 Section {53 ForEach(model.rows) { row in54 HStack(spacing: 0) {55 DatabaseSelectionMark(model: model, row: row).frame(width: 40)56 ForEach(properties) { property in57 DatabaseTableCell(model: model, row: row, property: property)58 .frame(width: width(property), alignment: .leading)59 }60 FeatureIconButton("sidebar.right", label: LF("Ouvrir le détail de « %@ »", row.title)) { model.inspector = .row(row.id) }61 .padding(.horizontal, NVSpace.xs)62 }63 .frame(minHeight: 40)64 .background(model.selection.contains(row.id) ? NVColor.accentSoft : NVColor.bgElevated)65 .overlay(alignment: .bottom) { Rectangle().fill(NVColor.line).frame(height: 1) }66 }67 } header: {68 HStack(spacing: 0) {69 Button { if model.selection.count == model.rows.count { model.selection = [] } else { model.selectAll() } } label: {70 Image(systemName: model.selection.count == model.rows.count && !model.rows.isEmpty ? "checkmark.circle.fill" : "circle")71 .foregroundStyle(NVColor.fgMuted).frame(width: 40, height: 32).contentShape(Rectangle())72 }73 .buttonStyle(.plain)74 .accessibilityLabel(L("Tout sélectionner"))75 ForEach(properties) { property in76 Label(property.name, systemImage: DatabaseCellFormat.typeSymbol(property.type))77 .nvFont(.micro).foregroundStyle(NVColor.fgMuted).lineLimit(1)78 .padding(.horizontal, NVSpace.sm)79 .frame(width: width(property), alignment: .leading)80 }81 Color.clear.frame(width: 40, height: 1)82 }83 .frame(minHeight: 34)84 .background(NVColor.bgSunken)85 .overlay(alignment: .bottom) { Rectangle().fill(NVColor.lineStrong).frame(height: 1) }86 }87 }88 .overlay(NVRadius.shape(NVRadius.sm).strokeBorder(NVColor.line, lineWidth: 1))89 .clipShape(NVRadius.shape(NVRadius.sm))90 .padding(.horizontal, NVSpace.xl)91 .padding(.bottom, 96)92 }93 }94}9596struct DatabaseTableCell: View {97 let model: DatabaseModel98 let row: DatabaseRowValues99 let property: DatabaseProperty100101 var body: some View {102 let ref = DatabaseModel.CellRef(rowId: row.id, propertyId: property.id)103 let editable = model.isEditable(property)104 Group {105 if editable, model.editingCell == ref || property.type == DatabasePropertyType.checkbox {106 DatabaseCellEditor(model: model, row: row, property: property)107 } else {108 Button {109 if editable { model.editingCell = ref } else { model.inspector = .row(row.id) }110 } label: {111 DatabaseCellView(display: DatabaseCellFormat.display(property, row), openURL: nil)112 .frame(maxWidth: .infinity, minHeight: 32, alignment: .leading)113 .contentShape(Rectangle())114 }115 .buttonStyle(.plain)116 .accessibilityHint(editable ? L("Modifier la valeur") : L("Lecture seule ; ouvre le détail"))117 }118 }119 .padding(.horizontal, NVSpace.sm)120 .padding(.vertical, NVSpace.xs)121 .overlay(alignment: .leading) { Rectangle().fill(NVColor.line).frame(width: 1) }122 }123}124125// MARK: - Cards (compact table) and list126127/// The table on a phone: one card per row with its first properties; a tap opens the property sheet.128struct DatabaseCardList: View {129 let model: DatabaseModel130131 var body: some View {132 ScrollView {133 LazyVStack(spacing: NVSpace.sm) {134 ForEach(Array(model.rows.enumerated()), id: \.element.id) { index, row in135 DatabaseRowCard(model: model, row: row, showsLabels: true).nvBlockReveal(index: index)136 }137 }138 .padding(.horizontal, NVSpace.lg)139 .padding(.bottom, 96)140 }141 }142}143144struct DatabaseRowCard: View {145 let model: DatabaseModel146 let row: DatabaseRowValues147 var showsLabels = false148 var moveTargets: [DatabaseGroup] = []149150 /// The non-empty first properties of the card; in a board the grouping property is the column, not repeated.151 private var cardItems: [(property: DatabaseProperty, display: DatabaseCellDisplay)] {152 let skipped = moveTargets.isEmpty ? nil : model.groupProperty?.id153 return model.cardProperties.filter { $0.id != skipped }.map { ($0, DatabaseCellFormat.display($0, row)) }.filter { $0.display.kind != .empty }154 }155156 var body: some View {157 HStack(alignment: .top, spacing: NVSpace.sm) {158 if model.isSelecting { DatabaseSelectionMark(model: model, row: row) }159 Button { databaseActivate(model, row) } label: {160 VStack(alignment: .leading, spacing: NVSpace.xs) {161 Text(row.title.isEmpty ? L("Sans titre") : row.title).nvFont(.uiStrong).foregroundStyle(NVColor.fg).multilineTextAlignment(.leading)162 let items = cardItems163 let chips = items.filter { if case .options = $0.display.kind { return true }; return false }164 let others = items.filter { if case .options = $0.display.kind { return false }; return true }165 if !chips.isEmpty {166 WorkFlow(spacing: NVSpace.xs) {167 ForEach(chips, id: \.property.id) { item in DatabaseCellView(display: item.display) }168 }169 }170 if showsLabels {171 ForEach(others, id: \.property.id) { item in172 HStack(alignment: .firstTextBaseline, spacing: NVSpace.sm) {173 Text(item.property.name).nvFont(.micro).foregroundStyle(NVColor.fgMuted).frame(width: 84, alignment: .leading)174 DatabaseCellView(display: item.display)175 Spacer(minLength: 0)176 }177 }178 } else if !others.isEmpty {179 Text(others.map(\.display.text).joined(separator: " · ")).nvFont(.micro).foregroundStyle(NVColor.fgMuted).lineLimit(2).multilineTextAlignment(.leading)180 }181 }182 .frame(maxWidth: .infinity, alignment: .leading)183 .contentShape(Rectangle())184 }185 .buttonStyle(.plain)186 .accessibilityHint(L("Ouvre les propriétés de la ligne"))187 if !moveTargets.isEmpty, model.canWrite {188 Menu {189 ForEach(moveTargets) { group in190 Button(group.label.isEmpty ? L("Sans valeur") : group.label) { Task { await model.move(rowId: row.id, toGroup: group.id) } }191 }192 } label: { Image(systemName: "arrow.left.arrow.right").foregroundStyle(NVColor.fgMuted).frame(minWidth: 32, minHeight: 32) }193 .menuStyle(.borderlessButton).fixedSize()194 .accessibilityLabel(LF("Déplacer « %@ » vers une autre colonne", row.title))195 }196 }197 .padding(NVSpace.md)198 .background(model.selection.contains(row.id) ? NVColor.accentSoft : NVColor.bgElevated, in: NVRadius.shape(NVRadius.md))199 .overlay(NVRadius.shape(NVRadius.md).strokeBorder(model.selection.contains(row.id) ? NVColor.accent.opacity(0.5) : NVColor.line, lineWidth: 1))200 }201}202203struct DatabaseListView: View {204 let model: DatabaseModel205 let compact: Bool206207 var body: some View {208 ScrollView {209 LazyVStack(alignment: .leading, spacing: NVSpace.lg) {210 if model.groups.isEmpty {211 rows(model.rows)212 } else {213 ForEach(model.groups) { group in214 VStack(alignment: .leading, spacing: NVSpace.xs) {215 DatabaseGroupHeader(group: group)216 rows(group.rows)217 }218 }219 }220 }221 .padding(.horizontal, compact ? NVSpace.lg : NVSpace.xl)222 .padding(.bottom, 96)223 .frame(maxWidth: compact ? .infinity : 900, alignment: .leading)224 .frame(maxWidth: .infinity, alignment: .leading)225 }226 }227228 private func rows(_ rows: [DatabaseRowValues]) -> some View {229 VStack(spacing: 0) {230 ForEach(Array(rows.enumerated()), id: \.element.id) { index, row in231 if index > 0 { Divider().overlay(NVColor.line) }232 HStack(spacing: NVSpace.sm) {233 if model.isSelecting { DatabaseSelectionMark(model: model, row: row) }234 Button { databaseActivate(model, row) } label: {235 HStack(spacing: NVSpace.md) {236 Text(row.title.isEmpty ? L("Sans titre") : row.title).nvFont(.body).foregroundStyle(NVColor.fg).lineLimit(compact ? 2 : 1).multilineTextAlignment(.leading)237 Spacer(minLength: NVSpace.sm)238 ForEach(model.cardProperties.prefix(compact ? 1 : 3)) { property in239 let display = DatabaseCellFormat.display(property, row)240 if display.kind != .empty { DatabaseCellView(display: display).fixedSize() }241 }242 Image(systemName: "chevron.right").font(.system(size: 12, weight: .semibold)).foregroundStyle(NVColor.fgFaint).accessibilityHidden(true)243 }244 .frame(minHeight: 44)245 .contentShape(Rectangle())246 }247 .buttonStyle(.plain)248 }249 .padding(.horizontal, NVSpace.md)250 .background(model.selection.contains(row.id) ? NVColor.accentSoft : .clear)251 }252 }253 .nvCard(radius: NVRadius.md)254 }255}256257struct DatabaseGroupHeader: View {258 let group: DatabaseGroup259260 var body: some View {261 HStack(spacing: NVSpace.sm) {262 NVChip(group.label.isEmpty ? L("Sans valeur") : group.label, tone: WorkTone.tone(group.color))263 Text("\(group.rows.count)").nvFont(.micro).foregroundStyle(NVColor.fgMuted)264 }265 .accessibilityElement(children: .combine)266 .accessibilityAddTraits(.isHeader)267 .accessibilityLabel(LF("%@, %lld lignes", group.label.isEmpty ? L("Sans valeur") : group.label, group.rows.count))268 }269}270271// MARK: - Board272273struct DatabaseBoardView: View {274 let model: DatabaseModel275 let compact: Bool276277 var body: some View {278 if model.groups.isEmpty {279 NVEmptyState(systemImage: "rectangle.split.3x1", title: L("Aucune propriété pour les colonnes"),280 message: L("Choisissez un groupement (statut, choix, case à cocher) dans « Filtrer et trier »."))281 .frame(maxWidth: .infinity, maxHeight: .infinity)282 } else if compact {283 // Phone: the columns become stacked sections; a card moves with its menu.284 ScrollView {285 LazyVStack(alignment: .leading, spacing: NVSpace.lg) {286 ForEach(model.groups) { group in287 VStack(alignment: .leading, spacing: NVSpace.sm) {288 DatabaseGroupHeader(group: group)289 if group.rows.isEmpty {290 Text(L("Aucune ligne")).nvFont(.ui).foregroundStyle(NVColor.fgMuted)291 }292 ForEach(group.rows) { row in293 DatabaseRowCard(model: model, row: row, moveTargets: model.groups.filter { $0.id != group.id })294 }295 }296 }297 }298 .padding(.horizontal, NVSpace.lg)299 .padding(.bottom, 96)300 }301 } else {302 ScrollView([.horizontal, .vertical]) {303 HStack(alignment: .top, spacing: NVSpace.md) {304 ForEach(model.groups) { group in305 VStack(alignment: .leading, spacing: NVSpace.sm) {306 DatabaseGroupHeader(group: group)307 ForEach(group.rows) { row in308 DatabaseRowCard(model: model, row: row, moveTargets: model.groups.filter { $0.id != group.id })309 }310 if group.rows.isEmpty {311 Text(L("Aucune ligne")).nvFont(.ui).foregroundStyle(NVColor.fgMuted).frame(maxWidth: .infinity, minHeight: 48)312 }313 }314 .padding(NVSpace.sm)315 .frame(width: 272, alignment: .topLeading)316 .background(NVColor.bgSunken, in: NVRadius.shape(NVRadius.md))317 }318 }319 .padding(.horizontal, NVSpace.xl)320 .padding(.bottom, 96)321 }322 }323 }324}325326// MARK: - Gallery327328struct DatabaseGalleryView: View {329 let model: DatabaseModel330 let compact: Bool331332 var body: some View {333 ScrollView {334 LazyVGrid(columns: [GridItem(.adaptive(minimum: compact ? 150 : 220), spacing: NVSpace.md, alignment: .top)], alignment: .leading, spacing: NVSpace.md) {335 ForEach(model.rows) { row in336 Button { databaseActivate(model, row) } label: {337 VStack(alignment: .leading, spacing: 0) {338 ZStack(alignment: .topTrailing) {339 NVColor.accentSoft340 Text(String(row.title.trimmingCharacters(in: .whitespaces).prefix(1)).uppercased())341 .nvFont(.display).foregroundStyle(NVColor.accent.opacity(0.55))342 .frame(maxWidth: .infinity, maxHeight: .infinity)343 .accessibilityHidden(true)344 if model.isSelecting {345 Image(systemName: model.selection.contains(row.id) ? "checkmark.circle.fill" : "circle")346 .foregroundStyle(model.selection.contains(row.id) ? NVColor.accent : NVColor.fgMuted).padding(NVSpace.sm)347 }348 }349 .frame(height: compact ? 72 : 96)350 VStack(alignment: .leading, spacing: NVSpace.xs) {351 Text(row.title.isEmpty ? L("Sans titre") : row.title).nvFont(.uiStrong).foregroundStyle(NVColor.fg).lineLimit(2).multilineTextAlignment(.leading)352 ForEach(model.cardProperties.prefix(3)) { property in353 let display = DatabaseCellFormat.display(property, row)354 if display.kind != .empty { DatabaseCellView(display: display) }355 }356 }357 .padding(NVSpace.md)358 .frame(maxWidth: .infinity, alignment: .leading)359 }360 .background(NVColor.bgElevated)361 .clipShape(NVRadius.shape(NVRadius.md))362 .overlay(NVRadius.shape(NVRadius.md).strokeBorder(model.selection.contains(row.id) ? NVColor.accent : NVColor.line, lineWidth: 1))363 .contentShape(Rectangle())364 }365 .buttonStyle(.plain)366 }367 }368 .padding(.horizontal, compact ? NVSpace.lg : NVSpace.xl)369 .padding(.bottom, 96)370 }371 }372}373374// MARK: - Calendar375376struct DatabaseCalendarView: View {377 @Bindable var model: DatabaseModel378 let compact: Bool379380 var body: some View {381 if let property = model.dateProperty {382 let byDay = model.rowsByDay383 VStack(alignment: .leading, spacing: NVSpace.sm) {384 HStack(spacing: NVSpace.sm) {385 FeatureIconButton("chevron.left", label: L("Mois précédent")) { model.calendarMonth = model.calendarMonth.adding(-1) }386 Text(model.calendarMonth.title).nvFont(.h3).foregroundStyle(NVColor.fg).frame(minWidth: 150, alignment: .leading)387 FeatureIconButton("chevron.right", label: L("Mois suivant")) { model.calendarMonth = model.calendarMonth.adding(1) }388 Spacer(minLength: NVSpace.sm)389 Label(property.name, systemImage: "calendar").nvFont(.micro).foregroundStyle(NVColor.fgMuted)390 }391 weekdayHeader392 if compact {393 grid(byDay, cellHeight: 44)394 agenda(byDay)395 } else {396 grid(byDay, cellHeight: nil)397 }398 }399 .padding(.horizontal, compact ? NVSpace.lg : NVSpace.xl)400 .padding(.bottom, NVSpace.lg)401 } else {402 NVEmptyState(systemImage: "calendar", title: L("Aucune propriété de date"), message: L("Ajoutez une propriété de type Date pour utiliser le calendrier."))403 .frame(maxWidth: .infinity, maxHeight: .infinity)404 }405 }406407 private var weekdayHeader: some View {408 HStack(spacing: 0) {409 ForEach(Array(DatabaseMonth.weekdaySymbols().enumerated()), id: \.offset) { _, symbol in410 Text(symbol).nvFont(.micro).foregroundStyle(NVColor.fgMuted).frame(maxWidth: .infinity)411 }412 }413 .accessibilityHidden(true)414 }415416 private func grid(_ byDay: [String: [DatabaseRowValues]], cellHeight: CGFloat?) -> some View {417 VStack(spacing: 0) {418 ForEach(Array(model.calendarMonth.weeks().enumerated()), id: \.offset) { _, week in419 HStack(spacing: 0) {420 ForEach(Array(week.enumerated()), id: \.offset) { _, day in421 if let day {422 dayCell(day, rows: byDay[model.calendarMonth.key(day: day)] ?? [], compactHeight: cellHeight)423 } else {424 Color.clear.frame(maxWidth: .infinity, maxHeight: cellHeight ?? .infinity)425 .overlay(alignment: .topLeading) { Rectangle().fill(cellHeight == nil ? NVColor.line : .clear).frame(height: 1) }426 .overlay(alignment: .leading) { Rectangle().fill(cellHeight == nil ? NVColor.line : .clear).frame(width: 1) }427 }428 }429 }430 .frame(maxHeight: cellHeight ?? .infinity)431 }432 }433 .frame(maxHeight: cellHeight == nil ? .infinity : nil)434 .background(NVColor.bgElevated, in: NVRadius.shape(NVRadius.md))435 .overlay(NVRadius.shape(NVRadius.md).strokeBorder(NVColor.line, lineWidth: 1))436 }437438 @ViewBuilder439 private func dayCell(_ day: Int, rows: [DatabaseRowValues], compactHeight: CGFloat?) -> some View {440 let key = model.calendarMonth.key(day: day)441 let isToday = key == model.todayDay442 let isSelected = key == model.calendarSelectedDay443 if let compactHeight {444 Button { model.calendarSelectedDay = key } label: {445 VStack(spacing: 3) {446 Text("\(day)").nvFont(.ui)447 .foregroundStyle(isSelected ? NVColor.accentFg : (isToday ? NVColor.accent : NVColor.fg))448 .frame(width: 28, height: 28)449 .background(isSelected ? NVColor.accent : .clear, in: Circle())450 Circle().fill(rows.isEmpty ? Color.clear : NVColor.accent).frame(width: 5, height: 5)451 }452 .frame(maxWidth: .infinity, minHeight: compactHeight)453 .contentShape(Rectangle())454 }455 .buttonStyle(.plain)456 .accessibilityLabel(rows.isEmpty ? LF("Le %lld, aucune ligne", day) : LF("Le %lld, %lld lignes", day, rows.count))457 .accessibilityAddTraits(isSelected ? .isSelected : [])458 } else {459 VStack(alignment: .leading, spacing: 2) {460 Text("\(day)").nvFont(.micro)461 .foregroundStyle(isToday ? NVColor.accentFg : NVColor.fgMuted)462 .padding(.horizontal, 6).padding(.vertical, 1)463 .background(isToday ? NVColor.accent : .clear, in: Capsule())464 ForEach(rows.prefix(3)) { row in465 Button { databaseActivate(model, row) } label: {466 Text(row.title.isEmpty ? L("Sans titre") : row.title).nvFont(.micro).foregroundStyle(NVColor.accent).lineLimit(1)467 .padding(.horizontal, 6).padding(.vertical, 2)468 .frame(maxWidth: .infinity, alignment: .leading)469 .background(NVColor.accentSoft, in: NVRadius.shape(NVRadius.xs))470 }471 .buttonStyle(.plain)472 }473 if rows.count > 3 { Text(LF("+ %lld", rows.count - 3)).nvFont(.micro).foregroundStyle(NVColor.fgMuted) }474 Spacer(minLength: 0)475 }476 .padding(4)477 .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)478 .overlay(alignment: .topLeading) { Rectangle().fill(NVColor.line).frame(height: 1) }479 .overlay(alignment: .leading) { Rectangle().fill(NVColor.line).frame(width: 1) }480 }481 }482483 /// Phone: the rows of the chosen day (or of the whole month) under the grid.484 private func agenda(_ byDay: [String: [DatabaseRowValues]]) -> some View {485 let days: [String] = model.calendarSelectedDay.map { [$0] } ?? (1...model.calendarMonth.dayCount).map { model.calendarMonth.key(day: $0) }.filter { byDay[$0] != nil }486 return ScrollView {487 LazyVStack(alignment: .leading, spacing: NVSpace.md) {488 if model.calendarSelectedDay != nil {489 Button(L("Voir tout le mois")) { model.calendarSelectedDay = nil }.buttonStyle(.plain).nvFont(.uiStrong).foregroundStyle(NVColor.accent)490 }491 if days.allSatisfy({ (byDay[$0] ?? []).isEmpty }) {492 Text(L("Aucune ligne à cette date.")).nvFont(.ui).foregroundStyle(NVColor.fgMuted)493 }494 ForEach(days, id: \.self) { day in495 if let rows = byDay[day], !rows.isEmpty {496 VStack(alignment: .leading, spacing: NVSpace.xs) {497 Text(WorkDay.date(day, hour: 12, timeZone: WorkDay.utc).map { FeatureFormat.day($0, timeZone: WorkDay.utc) } ?? day)498 .nvFont(.uiStrong).foregroundStyle(NVColor.fgMuted).accessibilityAddTraits(.isHeader)499 ForEach(rows) { row in DatabaseRowCard(model: model, row: row) }500 }501 }502 }503 }504 .padding(.bottom, 96)505 }506 }507}508509// MARK: - Timeline510511struct DatabaseTimelineView: View {512 let model: DatabaseModel513 let compact: Bool514515 var body: some View {516 if let timeline = model.timeline, !timeline.bars.isEmpty {517 ScrollView {518 VStack(alignment: .leading, spacing: compact ? NVSpace.md : 0) {519 if !compact { axis(timeline) }520 ForEach(timeline.bars) { bar in521 if compact { compactRow(bar) } else { regularRow(bar) }522 }523 if !timeline.undated.isEmpty {524 Text(timeline.undated.count > 1 ? LF("%lld lignes sans date de début ne sont pas placées.", timeline.undated.count) : L("1 ligne sans date de début n'est pas placée."))525 .nvFont(.micro).foregroundStyle(NVColor.fgMuted).padding(.top, NVSpace.md)526 }527 }528 .padding(.horizontal, compact ? NVSpace.lg : NVSpace.xl)529 .padding(.bottom, 96)530 }531 } else {532 NVEmptyState(systemImage: "chart.bar.xaxis", title: L("Rien à placer sur la chronologie"), message: L("Il faut une propriété de date renseignée pour au moins une ligne."))533 .frame(maxWidth: .infinity, maxHeight: .infinity)534 }535 }536537 private func range(_ bar: DatabaseTimelineLayout.Bar) -> String {538 let start = WorkDay.date(bar.startDay, hour: 12, timeZone: WorkDay.utc).map { FeatureFormat.day($0, timeZone: WorkDay.utc) } ?? bar.startDay539 guard bar.endDay != bar.startDay else { return start }540 let end = WorkDay.date(bar.endDay, hour: 12, timeZone: WorkDay.utc).map { FeatureFormat.day($0, timeZone: WorkDay.utc) } ?? bar.endDay541 return LF("%@ → %@", start, end)542 }543544 private func axis(_ timeline: DatabaseTimelineLayout.Result) -> some View {545 HStack(spacing: 0) {546 Color.clear.frame(width: 240, height: 1)547 GeometryReader { proxy in548 ForEach(Array(timeline.ticks.enumerated()), id: \.offset) { _, tick in549 Text(tick.label).nvFont(.micro).foregroundStyle(NVColor.fgMuted).fixedSize()550 .offset(x: proxy.size.width * tick.position + 4)551 Rectangle().fill(NVColor.line).frame(width: 1, height: 28).offset(x: proxy.size.width * tick.position)552 }553 }554 .frame(height: 28)555 }556 .accessibilityHidden(true)557 }558559 private func regularRow(_ bar: DatabaseTimelineLayout.Bar) -> some View {560 Button { if let row = model.row(bar.id) { databaseActivate(model, row) } } label: {561 HStack(spacing: 0) {562 VStack(alignment: .leading, spacing: 1) {563 Text(bar.title.isEmpty ? L("Sans titre") : bar.title).nvFont(.ui).foregroundStyle(NVColor.fg).lineLimit(1)564 Text(range(bar)).nvFont(.micro).foregroundStyle(NVColor.fgMuted).lineLimit(1)565 }566 .frame(width: 240, alignment: .leading)567 GeometryReader { proxy in568 NVRadius.shape(NVRadius.xs)569 .fill(NVColor.accent)570 .frame(width: max(8, proxy.size.width * bar.width), height: 14)571 .offset(x: proxy.size.width * bar.start, y: (proxy.size.height - 14) / 2)572 }573 }574 .frame(minHeight: 44)575 .overlay(alignment: .bottom) { Rectangle().fill(NVColor.line).frame(height: 1) }576 .background(model.selection.contains(bar.id) ? NVColor.accentSoft : .clear)577 .contentShape(Rectangle())578 }579 .buttonStyle(.plain)580 .accessibilityLabel(LF("%@, %@", bar.title, range(bar)))581 }582583 /// Phone: one card per row, the dates in words and a thin bar showing where it sits in the whole range.584 private func compactRow(_ bar: DatabaseTimelineLayout.Bar) -> some View {585 Button { if let row = model.row(bar.id) { databaseActivate(model, row) } } label: {586 VStack(alignment: .leading, spacing: NVSpace.xs) {587 Text(bar.title.isEmpty ? L("Sans titre") : bar.title).nvFont(.uiStrong).foregroundStyle(NVColor.fg).multilineTextAlignment(.leading)588 Label(range(bar), systemImage: "calendar").nvFont(.micro).foregroundStyle(NVColor.fgMuted)589 GeometryReader { proxy in590 ZStack(alignment: .leading) {591 Capsule().fill(NVColor.bgSunken)592 Capsule().fill(NVColor.accent).frame(width: max(6, proxy.size.width * bar.width)).offset(x: min(proxy.size.width - 6, proxy.size.width * bar.start))593 }594 }595 .frame(height: 6)596 .accessibilityHidden(true)597 }598 .padding(NVSpace.md)599 .frame(maxWidth: .infinity, alignment: .leading)600 .background(model.selection.contains(bar.id) ? NVColor.accentSoft : NVColor.bgElevated, in: NVRadius.shape(NVRadius.md))601 .overlay(NVRadius.shape(NVRadius.md).strokeBorder(NVColor.line, lineWidth: 1))602 .contentShape(Rectangle())603 }604 .buttonStyle(.plain)605 .accessibilityLabel(LF("%@, %@", bar.title, range(bar)))606 }607}608