Repository Public
1//2// SP Chat iOS3// File: SPChat-iOS/Components/ChatComposer.swift4// Description: The message composer: multi-line field, attachments with progress, dictation, send / stop.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8//910import PhotosUI11import SwiftUI12import UIKit1314/// What the composer proposes while the owner types `/…` (commands) or `@…` (models).15enum ComposerSuggestion: Identifiable, Equatable {16 case prompt(SavedPrompt)17 case preset(Preset)18 case model(AIModel)19 case action(id: String, title: String, symbol: String)20 var id: String {21 switch self { case .prompt(let p): "p-\(p.id)"; case .preset(let p): "s-\(p.id)"; case .model(let m): "m-\(m.id)"; case .action(let id, _, _): "a-\(id)" }22 }2324 enum Trigger: Equatable { case command(String), model(String) }25 /// `/` as the first character opens the commands; `@word` at the end of the text picks a model.26 static func trigger(in text: String) -> Trigger? {27 if text.hasPrefix("/"), !text.contains("\n"), text.count <= 40 { return .command(String(text.dropFirst()).trimmingCharacters(in: .whitespaces)) }28 if let at = text.lastIndex(of: "@") {29 let before = at == text.startIndex ? " " : String(text[text.index(before: at)])30 let query = text[text.index(after: at)...]31 if (before == " " || before == "\n"), !query.contains(where: { $0 == " " || $0 == "\n" }), query.count <= 30 { return .model(String(query)) }32 }33 return nil34 }35}3637struct ChatComposer: View {38 @Bindable var session: ChatSession39 let onSend: () -> Void40 let onShowPrompts: () -> Void41 let onShowModels: () -> Void42 let onShowOptions: () -> Void43 let onUsePrompt: (SavedPrompt) -> Void44 var focusToken: Int = 045 var dropTargeted = false4647 @Environment(AppEnvironment.self) private var env48 @Environment(\.accessibilityReduceMotion) private var reduceMotion49 @FocusState private var focused: Bool50 @State private var recorder: VoiceRecorder?51 @State private var showPhotos = false52 @State private var photoItems: [PhotosPickerItem] = []53 @State private var showFiles = false54 @State private var showCamera = false55 @State private var suggestion: RouteSuggestion?56 @State private var dismissedSuggestionFor: String?5758 private var intake: AttachmentIntake { AttachmentIntake(session: session, compress: env.preferences.compressImages) }59 private var isRecording: Bool { if let r = recorder { return r.state != .idle } else { return false } }60 private var currentModel: AIModel? { env.preferences.routingMode == .manual ? env.catalog.model(env.catalog.effectiveModelId(preferred: env.preferences.modelId)) : nil }6162 var body: some View {63 let suggestions = self.suggestions64 VStack(alignment: .leading, spacing: 6) {65 if !session.composerAttachments.isEmpty { attachmentTray.transition(.opacity.combined(with: .offset(y: 6))) }66 if !suggestions.isEmpty { suggestionList(suggestions).transition(.opacity.combined(with: .offset(y: 6))) }67 else if let s = suggestion, let m = env.catalog.model(s.selected) { suggestedModel(s, m).transition(.opacity) }68 if let r = recorder, r.state != .idle { recordingRow(r) } else { field }69 controlRow70 }71 .padding(.horizontal, 10).padding(.top, 10).padding(.bottom, 8)72 .floatSurface(cornerRadius: Radius.float, highlighted: dropTargeted)73 // Streaming Presence: the lumen travels along the top hairline while a model generates74 .overlay(alignment: .top) { LumenLine(active: session.isBusy).animation(Motion.fade, value: session.isBusy) }75 // Intelligent Composer: the capsule grows and shrinks with its content; the control row never jumps76 .animation(Motion.smooth(reduceMotion), value: session.composerAttachments.count)77 .animation(Motion.smooth(reduceMotion), value: suggestions.map(\.id))78 .animation(Motion.smooth(reduceMotion), value: suggestion)79 .animation(Motion.smooth(reduceMotion), value: isRecording)80 .animation(Motion.snappy(reduceMotion), value: session.composerText.count)81 .padding(.horizontal, 12).padding(.bottom, 8).padding(.top, 4)82 .frame(maxWidth: 760)83 .frame(maxWidth: .infinity)84 .photosPicker(isPresented: $showPhotos, selection: $photoItems, maxSelectionCount: 10, matching: .images)85 .onChange(of: photoItems) { _, items in86 guard !items.isEmpty else { return }87 photoItems = []88 Task { await intake.add(photos: items) }89 }90 .fileImporter(isPresented: $showFiles, allowedContentTypes: AttachmentIntake.importTypes, allowsMultipleSelection: true) { result in91 if case .success(let urls) = result { intake.add(fileURLs: urls) }92 }93 .fullScreenCover(isPresented: $showCamera) { CameraPicker { intake.add(image: $0) }.ignoresSafeArea() }94 .onChange(of: focusToken) { focused = true }95 .task(id: suggestionKey) { await refreshSuggestion() }96 }9798 // MARK: text99100 private var field: some View {101 TextField("Message", text: $session.composerText, axis: .vertical)102 .lineLimit(1...8)103 .font(.body)104 .focused($focused)105 .padding(.horizontal, 6).padding(.vertical, 6)106 .frame(minHeight: 36)107 // the whole padded area focuses the field, not only the line of text108 .contentShape(.rect)109 .onTapGesture { focused = true }110 .onKeyPress(keys: [.return], phases: .down) { press in111 // hardware keyboard: Return sends, Shift-Return (and Option-Return) inserts a line break112 guard env.preferences.sendWithReturn, !press.modifiers.contains(.shift), !press.modifiers.contains(.option) else { return .ignored }113 guard session.canSend else { return .handled }114 onSend(); return .handled115 }116 .accessibilityIdentifier("composer.field")117 }118119 // MARK: control row — [+] [tools] [web] … [ModelChip] [options] [mic | send | stop]120121 private var controlRow: some View {122 HStack(spacing: 2) {123 Menu {124 Button { showPhotos = true } label: { Label("Photothèque", systemImage: "photo.on.rectangle") }125 if UIImagePickerController.isSourceTypeAvailable(.camera) { Button { showCamera = true } label: { Label("Prendre une photo", systemImage: "camera") } }126 Button { showFiles = true } label: { Label("Fichiers", systemImage: "folder") }127 if UIPasteboard.general.hasImages { Button { if let img = UIPasteboard.general.image { intake.add(image: img) } } label: { Label("Coller l’image", systemImage: "doc.on.clipboard") } }128 Divider()129 Button(action: onShowPrompts) { Label("Prompts enregistrés", systemImage: "text.book.closed") }130 } label: { controlIcon("plus", active: false) }131 .accessibilityLabel(String(localized: "Joindre"))132 .accessibilityIdentifier("composer.attach")133134 toolsMenu135 webToggle136 // the chip takes what is left of the row, so its widest readable form is chosen137 modelButton.frame(maxWidth: .infinity, alignment: .trailing)138 Button(action: onShowOptions) { controlIcon("slider.horizontal.3", active: env.preferences.effort != nil || env.preferences.temperature != nil || env.preferences.maxOutputTokens != nil) }139 .buttonStyle(PressScale())140 .accessibilityLabel(String(localized: "Effort et options avancées"))141 .accessibilityIdentifier("composer.options")142 trailingButton.padding(.leading, 4)143 }144 }145146 private func controlIcon(_ symbol: String, active: Bool) -> some View {147 Image(systemName: symbol).font(.system(size: 15, weight: .medium))148 .foregroundStyle(active ? Color.accentColor : Color.textSecondary)149 .frame(width: 34, height: 34)150 .background(active ? Color.accentSoft : Color.clear, in: .circle)151 .frame(width: 38, height: 44).contentShape(.rect)152 }153154 /// Per-turn tool picker (`toolNames`): every tool of the server, each switchable; the menu stays open while toggling.155 private var toolsMenu: some View {156 @Bindable var prefs = env.preferences157 let tools = env.settings.tools158 let restricted = !prefs.toolsEnabled || tools.contains { prefs.disabledTools.contains($0.name) }159 return Menu {160 Toggle(isOn: $prefs.toolsEnabled) { Label("Outils", systemImage: "wrench.and.screwdriver") }161 if prefs.toolsEnabled {162 Section("Pour les prochains messages") {163 ForEach(tools) { t in164 Toggle(isOn: Binding(get: { !prefs.disabledTools.contains(t.name) }, set: { on in if on { prefs.disabledTools.remove(t.name) } else { prefs.disabledTools.insert(t.name) } })) { Label(t.label, systemImage: t.symbol) }165 }166 }167 }168 } label: {169 controlIcon(prefs.toolsEnabled ? "wrench.and.screwdriver" : "wrench.and.screwdriver.fill", active: false)170 .opacity(prefs.toolsEnabled ? 1 : 0.45)171 .overlay(alignment: .topTrailing) { if restricted && prefs.toolsEnabled { Circle().fill(Color.accentColor).frame(width: 6, height: 6).offset(x: -6, y: 10) } }172 }173 .menuActionDismissBehavior(.disabled)174 .accessibilityLabel(String(localized: "Outils"))175 .accessibilityValue(!prefs.toolsEnabled ? String(localized: "désactivés") : restricted ? String(localized: "sélection partielle") : String(localized: "tous activés"))176 .accessibilityIdentifier("composer.tools")177 }178179 /// « Recherche web » : the model must search before answering (`settings.webSearch`).180 private var webToggle: some View {181 let on = env.preferences.webSearch182 return Button {183 env.haptics.selection()184 withAnimation(Motion.snappy(reduceMotion)) { env.preferences.webSearch.toggle() }185 } label: {186 HStack(spacing: 4) {187 Image(systemName: "globe").font(.system(size: 15, weight: .medium)).symbolEffect(.bounce, value: on)188 }189 .foregroundStyle(on ? Color.accentColor : Color.textSecondary)190 .frame(minWidth: 34, minHeight: 34)191 .background(on ? Color.accentSoft : Color.clear, in: .circle)192 .frame(minWidth: 38, minHeight: 44).contentShape(.rect)193 }194 .buttonStyle(PressScale())195 .accessibilityLabel(String(localized: "Recherche web"))196 .accessibilityValue(on ? String(localized: "activée") : String(localized: "désactivée"))197 .accessibilityAddTraits(on ? .isSelected : [])198 .accessibilityIdentifier("composer.web")199 }200201 /// ModelChip → model sheet. Long press: the Favorites Dock (quick switch without opening the sheet).202 private var modelButton: some View {203 Button(action: onShowModels) {204 Group {205 if let label = routingLabel {206 HStack(spacing: 5) { Image(systemName: "sparkles").font(.system(size: 12, weight: .semibold)).foregroundStyle(Color.accentColor); Text(label).font(.spCaption).foregroundStyle(Color.textPrimary).lineLimit(1) }207 } else if currentModel == nil {208 HStack(spacing: 5) { Image(systemName: "square.stack.3d.up").font(.system(size: 12, weight: .medium)).foregroundStyle(Color.muted); Text("Modèle").font(.spCaption).foregroundStyle(Color.textSecondary) }209 } else {210 // the exact name comes first: when the row is tight the route badge shortens to « OR », never the name211 ViewThatFits(in: .horizontal) {212 ModelChip(model: currentModel, markSize: 15, font: .spCaption, breathing: session.isBusy).fixedSize()213 compactChip(name: currentModel?.displayName ?? String(localized: "Modèle")).fixedSize()214 compactChip(name: currentModel?.shortName ?? String(localized: "Modèle"))215 }216 }217 }218 .padding(.horizontal, 10).frame(minHeight: 32)219 .background(Color.textPrimary.opacity(0.07), in: .capsule)220 .frame(minHeight: 44).contentShape(.rect)221 }222 .buttonStyle(PressScale(scale: 0.96))223 .contextMenu {224 let dock = env.catalog.dockModels225 if !dock.isEmpty {226 Section("Favoris") {227 ForEach(dock) { m in Button { env.haptics.selection(); withAnimation(Motion.smooth(reduceMotion)) { env.select(model: m.id) } } label: { Text(m.nameWithRoute) } }228 }229 }230 Button(action: onShowModels) { Label("Tous les modèles…", systemImage: "square.stack.3d.up") }231 }232 .accessibilityLabel(String(localized: "Modèle : \(routingLabel ?? currentModel?.displayName ?? String(localized: "aucun"))"))233 .accessibilityHint(String(localized: "Changer de modèle ou de mode de routage"))234 .accessibilityIdentifier("chat.modelButton")235 }236237 private func compactChip(name: String) -> some View {238 HStack(spacing: 5) {239 ModelChip(logo: currentModel?.logo, creatorName: currentModel?.creatorName ?? "?", name: name, route: nil, markSize: 15, font: .spCaption, breathing: session.isBusy)240 if currentModel?.isOpenRouter == true || currentModel?.isLocal == true {241 Text(verbatim: currentModel?.isLocal == true ? "LOCAL" : "OR").font(.system(size: 9, weight: .semibold)).tracking(0.5).foregroundStyle(Color.muted)242 .padding(.horizontal, 4).padding(.vertical, 2).overlay(Capsule().strokeBorder(Color.hairline, lineWidth: 0.75)).fixedSize()243 .accessibilityHidden(true)244 }245 }246 }247248 private var routingLabel: String? {249 if let p = env.catalog.preset(env.preferences.presetId) { return p.name }250 switch env.preferences.routingMode {251 case .manual: return nil252 case .auto: return String(localized: "Automatique")253 case .fast: return String(localized: "Rapide")254 case .quality: return String(localized: "Qualité")255 case .economy: return String(localized: "Économie")256 }257 }258259 @ViewBuilder private var trailingButton: some View {260 if session.isBusy {261 Button { env.haptics.tap(); session.stop() } label: {262 Image(systemName: "stop.fill").font(.system(size: 13, weight: .bold)).foregroundStyle(Color.appBackground)263 .frame(width: 34, height: 34).background(Color.textPrimary, in: .circle).frame(width: 38, height: 44).contentShape(.rect)264 }265 .buttonStyle(PressScale())266 .transition(.scale(scale: 0.7).combined(with: .opacity))267 .accessibilityLabel(String(localized: "Arrêter la réponse"))268 .accessibilityIdentifier("composer.stop")269 } else if session.composerText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && session.composerAttachments.isEmpty {270 Button { Task { await startDictation() } } label: { controlIcon("mic", active: false) }271 .buttonStyle(PressScale())272 .accessibilityLabel(String(localized: "Dicter"))273 .accessibilityIdentifier("composer.mic")274 } else {275 Button { focused = false; onSend() } label: {276 Image(systemName: "arrow.up").font(.system(size: 15, weight: .bold)).foregroundStyle(Color.white)277 .frame(width: 34, height: 34).background(session.canSend ? Color.accentColor : Color.muted.opacity(0.5), in: .circle).frame(width: 38, height: 44).contentShape(.rect)278 }279 .buttonStyle(PressScale())280 .disabled(!session.canSend)281 .keyboardShortcut(.return, modifiers: .command)282 .transition(.scale(scale: 0.7).combined(with: .opacity))283 .accessibilityLabel(String(localized: "Envoyer"))284 .accessibilityIdentifier("composer.send")285 }286 }287288 // MARK: quick commands (`/`) and model mentions (`@`)289290 private var suggestions: [ComposerSuggestion] {291 guard !session.isBusy, let trigger = ComposerSuggestion.trigger(in: session.composerText) else { return [] }292 switch trigger {293 case .command(let q):294 var out: [ComposerSuggestion] = env.prompts.matching(q).prefix(4).map(ComposerSuggestion.prompt)295 out += env.catalog.presets.filter { q.isEmpty || $0.name.localizedStandardContains(q) }.prefix(3).map(ComposerSuggestion.preset)296 let actions: [(String, String, String)] = [("arena", String(localized: "Arène : comparer des modèles"), "square.split.2x1"), ("web", env.preferences.webSearch ? String(localized: "Désactiver la recherche web") : String(localized: "Activer la recherche web"), "globe"),297 ("model", String(localized: "Changer de modèle"), "square.stack.3d.up"), ("prompts", String(localized: "Bibliothèque de prompts"), "text.book.closed")]298 out += actions.filter { q.isEmpty || $0.1.localizedStandardContains(q) || $0.0.hasPrefix(q.lowercased()) }.map { ComposerSuggestion.action(id: $0.0, title: $0.1, symbol: $0.2) }299 return Array(out.prefix(7))300 case .model(let q):301 var query = ModelQuery(); query.text = q302 return query.apply(to: env.catalog.selectable).prefix(5).map(ComposerSuggestion.model)303 }304 }305306 private func suggestionList(_ items: [ComposerSuggestion]) -> some View {307 VStack(spacing: 0) {308 ForEach(items) { item in309 Button { apply(item) } label: {310 HStack(spacing: 10) {311 switch item {312 case .prompt(let p):313 Image(systemName: p.favorite ? "star.fill" : "text.quote").font(.system(size: 13)).foregroundStyle(p.favorite ? Color.warning : Color.muted).frame(width: 22)314 VStack(alignment: .leading, spacing: 1) {315 Text(p.title).font(.subheadline.weight(.medium)).foregroundStyle(Color.textPrimary).lineLimit(1)316 Text(p.variables.isEmpty ? p.body : p.variables.map { "{{\($0)}}" }.joined(separator: " ")).font(.caption).foregroundStyle(Color.muted).lineLimit(1)317 }318 case .preset(let p):319 Image(systemName: "dial.medium").font(.system(size: 13)).foregroundStyle(Color.muted).frame(width: 22)320 Text(String(localized: "Profil · \(p.name)")).font(.subheadline.weight(.medium)).foregroundStyle(Color.textPrimary).lineLimit(1)321 case .model(let m):322 ModelMark(m, size: 18).frame(width: 22)323 ModelChip(model: m, markSize: 0.01, font: .subheadline.weight(.medium))324 case .action(_, let title, let symbol):325 Image(systemName: symbol).font(.system(size: 13)).foregroundStyle(Color.accentColor).frame(width: 22)326 Text(title).font(.subheadline.weight(.medium)).foregroundStyle(Color.textPrimary).lineLimit(1)327 }328 Spacer(minLength: 0)329 }330 .padding(.horizontal, 8).frame(minHeight: 44).contentShape(.rect)331 }332 .buttonStyle(.plain)333 .accessibilityIdentifier("composer.suggestion")334 }335 }336 .background(Color.surface2.opacity(0.55), in: .rect(cornerRadius: Radius.card, style: .continuous))337 }338339 private func apply(_ item: ComposerSuggestion) {340 env.haptics.selection()341 switch item {342 case .prompt(let p): session.composerText = ""; onUsePrompt(p)343 case .preset(let p): session.composerText = ""; env.preferences.presetId = p.id344 case .model(let m):345 if let at = session.composerText.lastIndex(of: "@") { session.composerText = String(session.composerText[..<at]) }346 withAnimation(Motion.smooth(reduceMotion)) { env.select(model: m.id) }347 case .action(let id, _, _):348 session.composerText = ""349 switch id {350 case "arena": env.router.arenaSeed = ArenaSeed(conversationId: nil, projectId: session.projectId); env.router.sheet = .arena351 case "web": env.preferences.webSearch.toggle()352 case "model": onShowModels()353 default: onShowPrompts()354 }355 }356 }357358 // MARK: suggested model (Smart Model Router, advisory — never switches by itself)359360 private var suggestionKey: String {361 let t = session.composerText362 guard env.preferences.suggestModel, env.preferences.routingMode == .manual, env.preferences.presetId == nil, t.count >= 40, !t.hasPrefix("/") else { return "" }363 // one request per pause in typing and per ~80 characters written364 return "\(t.count / 80)|\(session.composerAttachments.count)|\(currentModel?.id ?? "")"365 }366367 private func refreshSuggestion() async {368 guard !suggestionKey.isEmpty else { suggestion = nil; return }369 try? await Task.sleep(for: .milliseconds(1100))370 guard !Task.isCancelled else { return }371 let hasImages = session.composerAttachments.contains { $0.mime.hasPrefix("image/") }372 guard let s = try? await env.api.routeSuggestion(text: session.composerText, hasImages: hasImages, wantsTools: env.preferences.toolsEnabled), !Task.isCancelled else { return }373 suggestion = (s.selected != currentModel?.id && s.selected != dismissedSuggestionFor && env.catalog.model(s.selected) != nil) ? s : nil374 }375376 private func suggestedModel(_ s: RouteSuggestion, _ m: AIModel) -> some View {377 HStack(spacing: 8) {378 Button {379 env.haptics.selection()380 withAnimation(Motion.smooth(reduceMotion)) { env.select(model: m.id); suggestion = nil }381 } label: {382 HStack(spacing: 6) {383 Text("Modèle suggéré").font(.spMicro).foregroundStyle(Color.muted).textCase(.uppercase)384 ModelChip(model: m, markSize: 14, font: .spCaption)385 if let r = s.reason { Text(r).font(.caption2).foregroundStyle(Color.muted).lineLimit(1) }386 }387 .frame(minHeight: 36).contentShape(.rect)388 }389 .buttonStyle(.plain)390 .accessibilityLabel(String(localized: "Modèle suggéré : \(m.displayName). \(s.reason ?? "")"))391 .accessibilityHint(String(localized: "Sélectionne ce modèle ; rien n’est envoyé"))392 Spacer(minLength: 0)393 Button { dismissedSuggestionFor = s.selected; suggestion = nil } label: { Image(systemName: "xmark").font(.system(size: 10, weight: .bold)).foregroundStyle(Color.muted).frame(width: 36, height: 36).contentShape(.rect) }394 .buttonStyle(.plain).accessibilityLabel(String(localized: "Ignorer la suggestion"))395 }396 .padding(.leading, 6)397 .accessibilityIdentifier("composer.suggestedModel")398 }399400 // MARK: dictation401402 private func startDictation() async {403 let r = recorder ?? VoiceRecorder(api: env.api)404 recorder = r405 env.haptics.tap()406 await r.start()407 if let e = r.lastError { session.error = e }408 }409410 private func recordingRow(_ r: VoiceRecorder) -> some View {411 HStack(spacing: 10) {412 Button { r.cancel() } label: { Image(systemName: "xmark").font(.system(size: 13, weight: .semibold)).foregroundStyle(Color.textSecondary).frame(width: 34, height: 34).background(Color.surface2, in: .circle) }413 .accessibilityLabel(String(localized: "Annuler la dictée"))414 if case .recording(let since) = r.state {415 Image(systemName: "waveform").foregroundStyle(Color.accentColor).symbolEffect(.variableColor.iterative, isActive: true)416 Text(since, style: .timer).font(.body.monospacedDigit()).foregroundStyle(Color.textPrimary)417 Text("Enregistrement…").font(.subheadline).foregroundStyle(Color.muted)418 } else {419 ProgressView()420 Text("Transcription…").font(.subheadline).foregroundStyle(Color.muted)421 }422 Spacer(minLength: 0)423 if r.isRecording {424 Button {425 Task {426 let text = await r.finish(language: env.preferences.dictationLanguage)427 if let e = r.lastError { session.error = e }428 guard let text, !text.isEmpty else { return }429 session.composerText += (session.composerText.isEmpty ? "" : " ") + text430 if env.preferences.dictationAutoSend, session.canSend { onSend() } else { focused = true }431 }432 } label: { Image(systemName: "checkmark").font(.system(size: 16, weight: .bold)).foregroundStyle(Color.white).frame(width: 34, height: 34).background(Color.accentColor, in: .circle) }433 .accessibilityLabel(String(localized: "Terminer la dictée"))434 }435 }436 .frame(minHeight: 36).padding(.horizontal, 4)437 }438439 // MARK: attachments tray440441 private var attachmentTray: some View {442 ScrollView(.horizontal, showsIndicators: false) {443 HStack(spacing: 8) {444 ForEach(session.composerAttachments) { item in445 HStack(spacing: 8) {446 Group {447 if let t = item.thumbnail { Image(uiImage: t).resizable().scaledToFill() }448 else { Image(systemName: "doc.fill").font(.body).foregroundStyle(Color.accentColor).frame(maxWidth: .infinity, maxHeight: .infinity).background(Color.surface2) }449 }450 .frame(width: 40, height: 40).clipShape(.rect(cornerRadius: 9, style: .continuous))451 VStack(alignment: .leading, spacing: 2) {452 Text(item.filename).font(.caption.weight(.medium)).lineLimit(1).frame(maxWidth: 130, alignment: .leading)453 switch item.state {454 case .uploading(let p): ProgressView(value: p).frame(width: 90).tint(.accentColor).accessibilityLabel(String(localized: "Envoi \(Int(p * 100)) %"))455 case .uploaded: Text(Format.bytes(item.size)).font(.caption2).foregroundStyle(Color.muted)456 case .failed(let m): Text(m).font(.caption2).foregroundStyle(Color.danger).lineLimit(2).frame(maxWidth: 150, alignment: .leading)457 }458 }459 Button { session.removeAttachment(item) } label: { Image(systemName: "xmark.circle.fill").font(.body).foregroundStyle(Color.muted).frame(width: 30, height: 40).contentShape(.rect) }460 .buttonStyle(.plain).accessibilityLabel(String(localized: "Retirer \(item.filename)"))461 }462 .padding(.leading, 6).padding(.vertical, 5)463 .background(Color.surface2.opacity(0.8), in: .rect(cornerRadius: 13, style: .continuous))464 }465 }466 .padding(.horizontal, 2)467 }468 }469}470