Repository Public
1// SP Notes iOS2// File: Features/Editor/Blocks/BlockDetailProviding.swift3// Description: The seam between the editor and the detail screens of the 3.0 blocks (SPEC §2, §8). The editor draws a card for4// each block atom; a tap asks `BlockDetails` for a screen. Providers are tried in order: the Pencil screens that5// belong to this app for good (drawing, PDF annotation), then the screens of `SPNotesFeatures` once that library6// is merged, then the minimal in-app ones. Swapping an implementation never touches the editor.7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10import SPNotesCore11import SwiftUI1213/// What a block detail screen can do with the note it was opened from.14@MainActor15struct BlockDetailContext {16 let app: AppModel17 let noteId: String18 /// False for a note in the trash or a read-only presentation: the screen shows, and does not offer to change.19 let isEditable: Bool20 /// Writes the edited node back in place of the block (nil deletes the block). May be called several times.21 let commit: (PMNode?) -> Void22 /// Inserts Markdown as new blocks right below the block (recognised handwriting, an AI result the user chose to insert…).23 let insertMarkdownBelow: (String) -> Void24 /// Navigates (a block reference, a citation source, a canvas).25 let open: (AppRoute) -> Void26 let dismiss: () -> Void27}2829enum BlockDetailStyle: Equatable { case sheet, fullScreen }3031@MainActor32protocol BlockDetailProviding {33 func canPresent(_ node: PMNode) -> Bool34 func style(for node: PMNode) -> BlockDetailStyle35 func view(for node: PMNode, context: BlockDetailContext) -> AnyView36}3738/// The registry. `providers` is ordered by priority; `register(_:priority:)` keeps it sorted (higher first).39@MainActor40enum BlockDetails {41 enum Priority: Int, Comparable {42 /// Minimal screens shipped in the app until SPNotesFeatures is merged.43 case inApp = 044 /// Screens of the shared SPNotesFeatures library.45 case features = 1046 /// Screens that belong to this app for good (PencilKit drawing, PDF annotation with Pencil).47 case platform = 2048 static func < (a: Priority, b: Priority) -> Bool { a.rawValue < b.rawValue }49 }5051 private static var entries: [(priority: Priority, provider: any BlockDetailProviding)] = []5253 static func register(_ provider: any BlockDetailProviding, priority: Priority) {54 entries.append((priority, provider))55 entries.sort { $0.priority > $1.priority }56 }5758 static func provider(for node: PMNode) -> (any BlockDetailProviding)? {59 installDefaultsIfNeeded()60 return entries.first { $0.provider.canPresent(node) }?.provider61 }6263 /// Each feature area adds its providers here (one line each), so the registration does not depend on launch order.64 private static var installed = false65 static func installDefaultsIfNeeded() {66 guard !installed else { return }67 installed = true68 BlockDetails.register(PencilBlockDetails(), priority: .platform) // Features/Drawing, Features/PDF69 BlockDetails.register(VoiceBlockDetails(), priority: .platform) // Features/Voice70 BlockDetails.register(FeaturesBlockDetails(), priority: .features) // SPNotesFeatures: chart, queryView, blockRef, bibliography, runCode71 BlockDetails.register(InAppBlockDetails(), priority: .inApp) // Features/Editor/Blocks/InAppBlockDetails.swift72 }7374 /// Tests only.75 static func resetForTests() { entries.removeAll(); installed = false }76}77