Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Drive pour iPhone et iPad9// File : Features/MyDrive/ItemActionSheet.swift10// Description : The contextual bottom sheet of a file or folder (iPhone11// first): what it is and its state at the top, the four12// actions the thumb reaches first, then everything else.13// Medium detent by default, large on demand or at14// accessibility text sizes.15// Module : Features16// Repository : https://git.spboucher.ai/sp-drive-ios17// Created : 2026-11-1918// Last Modified : 2026-11-1919//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : None specified (no license file in this repository)85// Maintainer : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import SwiftUI9394struct ItemActionSheet: View {95 @Environment(AppModel.self) private var model96 @Environment(\.dismiss) private var dismiss97 @Environment(\.dynamicTypeSize) private var typeSize98 private let initial: DriveItem99 let actions: ItemActions100101 init(item: DriveItem, actions: ItemActions) { initial = item; self.actions = actions }102103 var body: some View {104 let _ = model.itemsVersion105 let item = model.store.item(initial.id) ?? initial106 let badge = model.badge(item)107 let pinned = model.store.localState(item.id)?.pinned == true108 ScrollView {109 VStack(alignment: .leading, spacing: SPDTheme.Space.lg) {110 header(item, badge)111 quickActions(item, pinned: pinned)112 VStack(spacing: 0) {113 if !item.isFolder {114 if item.isEditableText { row("Modifier le texte", "square.and.pencil", id: "editText") { actions.editText(item, model: model) } }115 if item.kind == .pdf { row("Annoter le PDF", "pencil.tip.crop.circle", id: "annotate") { actions.annotate(item, model: model) } }116 row("Ouvrir dans une autre app…", "square.and.arrow.up", id: "export") { actions.export(item, model: model) }117 }118 // SP Drive 2.0: each row exists only when the server can do it119 if !item.isLocalOnly, model.network.online {120 if model.next.has(.ai) { row(item.isFolder ? "Interroger ce dossier" : "Interroger ce document", "sparkles", id: "ask") { actions.sheet = .ask(item) } }121 if !item.isFolder, model.next.meta.api >= 2 { row("Étiquettes…", "tag", id: "tags") { actions.sheet = .tags(item) } }122 if !item.isFolder, model.next.meta.api >= 2 { row("Versions : comparer, restaurer", "clock.arrow.circlepath", id: "versions") { actions.sheet = .versions(item) } }123 if item.isFolder, model.next.has(.collab) { row("Membres et rôles…", "person.2", id: "members") { actions.sheet = .members(item) } }124 if model.next.has(.activity) { row("Activité", "clock", id: "activity") { actions.sheet = .activity(item) } }125 }126 if item.isFolder, !item.isLocalOnly { row("Lien de dépôt…", "tray.and.arrow.down", id: "deposit") { actions.sheet = .deposit(item) } }127 row("Renommer", "pencil", id: "rename") { actions.sheet = nil; actions.beginRename(item) }128 row("Déplacer…", "folder", id: "move") { actions.sheet = .move([item]) }129 if !item.isLocalOnly { row("Dupliquer", "plus.square.on.square", id: "duplicate") { actions.sheet = nil; actions.duplicate([item], model: model) } }130 if !item.isFolder, !pinned, badge == .available { row("Retirer de cet appareil", "iphone.slash", id: "evict") { actions.sheet = nil; actions.removeDownload(item, model: model) } }131 row("Informations et versions", "info.circle", id: "details", last: true) { actions.details(item) }132 }133 .spdCard()134 Button(role: .destructive) { actions.sheet = nil; actions.confirmingTrash = [item] } label: {135 Label("Supprimer du Drive", systemImage: "trash").frame(maxWidth: .infinity, minHeight: 44)136 }137 .buttonStyle(.bordered).tint(SPDTheme.Palette.critical)138 .accessibilityIdentifier("sheet.trash")139 }140 .padding(SPDTheme.Space.lg)141 }142 .background(SPDTheme.Palette.surface)143 .presentationDetents(typeSize.isAccessibilitySize ? [.large] : [.medium, .large])144 .presentationDragIndicator(.visible)145 .accessibilityIdentifier("itemSheet")146 }147148 private func header(_ item: DriveItem, _ badge: SyncBadge) -> some View {149 HStack(alignment: .top, spacing: SPDTheme.Space.md) {150 ItemThumbnail(item: item, size: 60)151 VStack(alignment: .leading, spacing: 4) {152 Text(item.name).font(SPDTheme.Typo.headline).fixedSize(horizontal: false, vertical: true)153 Text("\(item.kind.label) · \(item.summary(model: model))").font(SPDTheme.Typo.caption).foregroundStyle(.secondary)154 if let chip = badge.chipLabel {155 Label { Text(chip) } icon: { if badge == .none { Image(systemName: "checkmark.icloud") } else { SyncBadgeView(badge: badge) } }156 .font(SPDTheme.Typo.caption.weight(.medium))157 .padding(.horizontal, 8).padding(.vertical, 4)158 .background(.quaternary.opacity(0.6), in: Capsule())159 .accessibilityIdentifier("sheet.state")160 }161 }162 Spacer(minLength: 0)163 }164 .accessibilityElement(children: .combine)165 }166167 private func quickActions(_ item: DriveItem, pinned: Bool) -> some View {168 let layout = typeSize.isAccessibilitySize ? AnyLayout(VStackLayout(spacing: SPDTheme.Space.sm)) : AnyLayout(HStackLayout(spacing: SPDTheme.Space.sm))169 return layout {170 if !item.isFolder { quick("Ouvrir", "eye.fill", id: "open") { actions.sheet = nil; actions.open(item, model: model) } }171 if !item.isLocalOnly { quick("Partager", "link", id: "share") { actions.sheet = .share(item) } }172 quick(item.starred ? "Retirer" : "Favori", item.starred ? "star.slash.fill" : "star.fill", id: "star") { actions.toggleStar([item], model: model) }173 if !item.isLocalOnly { quick(pinned ? "En ligne" : "Hors ligne", pinned ? "icloud" : "arrow.down.circle.fill", id: "offline") { actions.setOffline(item, !pinned, model: model) } }174 }175 }176177 private func quick(_ title: LocalizedStringKey, _ symbol: String, id: String, action: @escaping () -> Void) -> some View {178 Button(action: action) {179 if typeSize.isAccessibilitySize {180 Label(title, systemImage: symbol).font(SPDTheme.Typo.callout.weight(.medium)).frame(maxWidth: .infinity, minHeight: 48, alignment: .leading).padding(.horizontal, SPDTheme.Space.md)181 } else {182 VStack(spacing: 6) {183 Image(systemName: symbol).font(.title3).frame(height: 26)184 Text(title).font(SPDTheme.Typo.caption.weight(.medium)).lineLimit(1).minimumScaleFactor(0.8)185 }186 .frame(maxWidth: .infinity, minHeight: 64)187 }188 }189 .buttonStyle(.plain)190 .foregroundStyle(SPDTheme.Palette.brand)191 .spdCard()192 .hoverEffect(.highlight)193 .accessibilityIdentifier("sheet.\(id)")194 }195196 private func row(_ title: LocalizedStringKey, _ symbol: String, id: String, last: Bool = false, action: @escaping () -> Void) -> some View {197 VStack(spacing: 0) {198 Button(action: action) {199 HStack(spacing: SPDTheme.Space.md) {200 Image(systemName: symbol).foregroundStyle(SPDTheme.Palette.brand).frame(width: 26)201 Text(title).foregroundStyle(.primary).multilineTextAlignment(.leading)202 Spacer(minLength: 0)203 }204 .frame(minHeight: 48)205 .padding(.horizontal, SPDTheme.Space.md)206 .contentShape(Rectangle())207 }208 .buttonStyle(.plain)209 .hoverEffect(.highlight)210 .accessibilityIdentifier("sheet.\(id)")211 if !last { Divider().padding(.leading, 50) }212 }213 }214}215