Repository Public
1// SP Notes iOS2// File: Features/Editor/Blocks/InAppBlockDetails.swift3// Description: The minimal in-app detail screens of the 3.0 blocks, behind `BlockDetailProviding` (priority `.inApp`): each one is4// small and real — it edits the block through the Core's typed view and commits the node back, keeping every5// attribute it does not know. The shared SPNotesFeatures screens and the Pencil screens replace them by registering6// a provider with a higher priority; nothing in the editor changes.7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10import SPNotesCore11import SPNotesDesign12import SwiftUI1314@MainActor15struct InAppBlockDetails: BlockDetailProviding {16 func canPresent(_ node: PMNode) -> Bool { node.typed != nil }1718 func style(for node: PMNode) -> BlockDetailStyle {19 switch node.typed {20 case .pdf?, .drawing?: .fullScreen21 default: .sheet22 }23 }2425 func view(for node: PMNode, context: BlockDetailContext) -> AnyView {26 guard let typed = node.typed else { return AnyView(EmptyView()) }27 switch typed {28 case .mermaid(let block): return AnyView(MermaidBlockSheet(block: block, context: context))29 case .chart(let block): return AnyView(ChartBlockSheet(block: block, context: context))30 case .queryView(let block): return AnyView(QueryViewBlockSheet(block: block, context: context))31 case .blockRef(let block): return AnyView(BlockRefSheet(block: block, context: context))32 case .runCode(let block): return AnyView(RunCodeBlockSheet(block: block, context: context))33 case .bibliography(let block): return AnyView(BibliographySheet(block: block, context: context))34 case .canvasLink(let block): return AnyView(CanvasLinkSheet(block: block, context: context))35 case .citation(let block): return AnyView(CitationSheet(citation: block, isNew: false, app: context.app, isEditable: context.isEditable, onDone: { edited in36 if edited.node() != block.node() { context.commit(edited.node()) }37 context.dismiss()38 }, onDelete: { context.commit(nil); context.dismiss() }, onCancel: context.dismiss))39 case .audio(let block): return AnyView(AudioBlockSheet(block: block, context: context))40 case .pdf(let block): return AnyView(PDFBlockViewer(block: block, context: context))41 case .drawing(let block): return AnyView(DrawingBlockViewer(block: block, context: context))42 }43 }44}4546/// The frame every block sheet shares: title, Cancel / OK, an optional delete action, the app's background.47struct BlockSheetScaffold<Content: View>: View {48 let title: String49 var isEditable = true50 var hasChanges = true51 let onCancel: () -> Void52 var onDone: (() -> Void)?53 var onDelete: (() -> Void)?54 @ViewBuilder var content: Content55 @State private var confirmsDelete = false5657 var body: some View {58 NavigationStack {59 content60 .scrollContentBackground(.hidden)61 .background(NVColor.bg)62 .navigationTitle(title)63 .navigationBarTitleDisplayMode(.inline)64 .toolbar {65 ToolbarItem(placement: .cancellationAction) {66 Button(isEditable && onDone != nil ? "Annuler" : "Fermer", action: onCancel).accessibilityIdentifier("block-sheet-cancel")67 }68 if isEditable, let onDone {69 ToolbarItem(placement: .confirmationAction) {70 Button("OK", action: onDone).fontWeight(.semibold).accessibilityIdentifier("block-sheet-done")71 }72 }73 if isEditable, onDelete != nil {74 ToolbarItem(placement: .bottomBar) {75 Button(role: .destructive) { confirmsDelete = true } label: { Label("Supprimer le bloc", systemImage: "trash") }76 .accessibilityIdentifier("block-sheet-delete")77 }78 }79 }80 .confirmationDialog("Supprimer ce bloc ?", isPresented: $confirmsDelete, titleVisibility: .visible) {81 Button("Supprimer", role: .destructive) { onDelete?() }82 Button("Annuler", role: .cancel) {}83 }84 }85 .accessibilityIdentifier("block-sheet")86 }87}8889/// A tinted line that states a limit or a state inside a sheet (same wording as on the cards).90struct BlockNotice: View {91 let text: String92 var symbol = "info.circle"93 var isAI = false9495 var body: some View {96 Label(text, systemImage: symbol)97 .nvFont(.ui)98 .foregroundStyle(isAI ? NVColor.ai : NVColor.fgMuted)99 .frame(maxWidth: .infinity, alignment: .leading)100 .padding(NVSpace.md)101 .background(isAI ? NVColor.aiSoft : NVColor.bgSunken, in: NVRadius.shape(NVRadius.md))102 }103}104105extension BlockDetailContext {106 /// Commits `node` when it differs from `original`, then closes.107 func finish(_ node: PMNode, original: PMNode) {108 if node != original { commit(node) }109 dismiss()110 }111 func delete() { commit(nil); dismiss() }112}113