Repository navigation
Expand file tree
/
Copy pathNoteRow.swift
More file actions
111 lines (98 loc) · 3.49 KB
/
Copy pathNoteRow.swift
File metadata and controls
111 lines (98 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import SwiftUI
import CoreData
#if os(macOS)
import AppKit
#endif
/// ✨ NoteRow avec stroke de sélection
struct NoteRow: View {
@Environment(\.colorScheme) private var colorScheme
@ObservedObject var note: NoteItem
// ✅ Détecte si la row est sélectionnée
var isSelected: Bool = false
var body: some View {
VStack(alignment: .leading, spacing: 6) {
titleView
.frame(maxWidth: .infinity, alignment: .leading)
Text(dateLine)
.font(.footnote)
.foregroundStyle(.secondary)
.lineLimit(1)
}
.padding(.vertical, 4)
.padding(.horizontal, 12)
// ✅ NOUVEAU: Stroke au lieu de background
.background(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Color.clear)
)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(selectionStrokeStyle, lineWidth: 2)
)
}
// ✅ Style de stroke unifié (évite erreur de type)
private var selectionStrokeStyle: some ShapeStyle {
if isSelected {
return AnyShapeStyle(selectionStrokeGradient)
} else {
return AnyShapeStyle(Color.clear)
}
}
// ✅ Stroke gradient selon light/dark mode
private var selectionStrokeGradient: LinearGradient {
if colorScheme == .dark {
// Dark mode: Violet-bleu (comme titre manuscrit tâche)
return LinearGradient.primaryGradient
} else {
// Light mode: Jaune-orangé (comme note manuscrit tâche)
return LinearGradient.doingGradient
}
}
@ViewBuilder
private var titleView: some View {
if shouldShowHandwrittenTitle {
#if os(iOS)
if let data = note.titleDrawingData, !data.isEmpty {
HandwrittenTitleRowView(drawingData: data, height: 30)
.padding(.vertical, 2)
}
#elseif os(macOS)
if let png = note.titleDrawingPreviewPNG,
let nsImage = NSImage(data: png) {
Image(nsImage: nsImage)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 32)
.padding(.vertical, 2)
}
#endif
} else {
Text(effectiveTitle.isEmpty ? "—" : effectiveTitle)
.font(.system(.body, weight: .semibold))
.foregroundStyle(.primary)
.lineLimit(1)
}
}
private var shouldShowHandwrittenTitle: Bool {
let typed = (note.typedTitle ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
guard typed.isEmpty else { return false }
#if os(iOS)
return (note.titleDrawingData?.isEmpty == false)
#elseif os(macOS)
return (note.titleDrawingPreviewPNG?.isEmpty == false)
#else
return false
#endif
}
private var effectiveTitle: String {
let typed = (note.typedTitle ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
if !typed.isEmpty { return typed }
let recognized = (note.recognizedTitle ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
if !recognized.isEmpty { return recognized }
return ""
}
private var dateLine: String {
let d = note.createdAt ?? note.updatedAt ?? Date()
return d.compactRelativeFormat()
}
}