SPB Git

Repository Public

KnowledgeVocabulary.swift 13.0 KB 311 lines swift

1// SP Notes Core2// File: Sources/SPNotesFeatures/Knowledge/KnowledgeVocabulary.swift3// Description: The words and symbols of the knowledge screens: graph views, node kinds, relation types, journal event4//              families, and small rows shared by the graph, health, brief and timeline screens.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SPNotesAPI9import SPNotesDesign10import SwiftUI1112public enum KnowledgeVocabulary {13    public static func viewTitle(_ view: String) -> String {14        switch view {15        case GraphView.global: return L("Global")16        case GraphView.local: return L("Local")17        case GraphView.project: return L("Projet")18        case GraphView.timeline: return L("Chronologie")19        case GraphView.concepts: return L("Concepts")20        case GraphView.documents: return L("Documents")21        case GraphView.references: return L("Références")22        default: return view23        }24    }2526    public static func viewSymbol(_ view: String) -> String {27        switch view {28        case GraphView.global: return "globe"29        case GraphView.local: return "scope"30        case GraphView.project: return "folder"31        case GraphView.timeline: return "calendar"32        case GraphView.concepts: return "lightbulb"33        case GraphView.documents: return "doc.on.doc"34        case GraphView.references: return "books.vertical"35        default: return "circle.grid.cross"36        }37    }3839    public static func nodeKindTitle(_ kind: String) -> String {40        switch kind {41        case GraphNodeKind.page: return L("Page")42        case GraphNodeKind.database: return L("Base de données")43        case GraphNodeKind.research: return L("Recherche")44        case GraphNodeKind.row: return L("Ligne")45        case GraphNodeKind.canvas: return L("Canvas")46        case GraphNodeKind.reference: return L("Référence")47        case GraphNodeKind.concept: return L("Concept")48        case GraphNodeKind.attachment: return L("Pièce jointe")49        case GraphNodeKind.tag: return L("Étiquette")50        default: return kind51        }52    }5354    public static func nodeSymbol(_ kind: String) -> String {55        switch kind {56        case GraphNodeKind.database: return "tablecells"57        case GraphNodeKind.research: return "graduationcap"58        case GraphNodeKind.row: return "list.bullet.rectangle"59        case GraphNodeKind.canvas: return "rectangle.3.group"60        case GraphNodeKind.reference: return "book.closed"61        case GraphNodeKind.concept: return "lightbulb"62        case GraphNodeKind.attachment: return "paperclip"63        case GraphNodeKind.tag: return "number"64        default: return "doc.text"65        }66    }6768    public static func nodeColor(_ kind: String, isAI: Bool = false) -> Color {69        if isAI { return NVColor.ai }70        switch kind {71        case GraphNodeKind.concept: return NVColor.warning72        case GraphNodeKind.reference: return NVColor.success73        case GraphNodeKind.attachment, GraphNodeKind.tag: return NVColor.fgFaint74        case GraphNodeKind.database, GraphNodeKind.row: return NVColor.fgMuted75        default: return NVColor.accent76        }77    }7879    public static func relationTitle(_ type: String?) -> String {80        switch type {81        case RelationType.related?: return L("lié à")82        case RelationType.supports?: return L("appuie")83        case RelationType.contradicts?: return L("contredit")84        case RelationType.extends?: return L("prolonge")85        case RelationType.exampleOf?: return L("exemple de")86        case RelationType.partOf?: return L("partie de")87        case RelationType.cites?: return L("cite")88        case RelationType.precedes?: return L("précède")89        case RelationType.follows?: return L("suit")90        case RelationType.about?: return L("à propos de")91        case RelationType.answers?: return L("répond à")92        case RelationType.duplicates?: return L("doublon de")93        default: return type ?? L("lien")94        }95    }9697    public static func edgeKindTitle(_ kind: String) -> String {98        switch kind {99        case GraphEdgeKind.link: return L("Lien du document")100        case GraphEdgeKind.typed: return L("Relation typée")101        case GraphEdgeKind.aiSuggested: return L("Lien suggéré")102        case GraphEdgeKind.cites: return L("Citation")103        case GraphEdgeKind.reference: return L("Référence attachée")104        case GraphEdgeKind.about: return L("Concept")105        case GraphEdgeKind.relation: return L("Relation de base de données")106        case GraphEdgeKind.attachment: return L("Pièce jointe")107        default: return kind108        }109    }110111    public static func insightTitle(_ kind: String) -> String {112        switch kind {113        case InsightKind.contradiction: return L("Contradiction")114        case InsightKind.openQuestion: return L("Question ouverte")115        case InsightKind.cluster: return L("Regroupement")116        case InsightKind.recurringTopic: return L("Sujet récurrent")117        case InsightKind.duplicate: return L("Doublon")118        default: return kind119        }120    }121122    public static func insightSymbol(_ kind: String) -> String {123        switch kind {124        case InsightKind.contradiction: return "arrow.left.arrow.right"125        case InsightKind.openQuestion: return "questionmark.circle"126        case InsightKind.cluster: return "circle.hexagongrid"127        case InsightKind.recurringTopic: return "repeat"128        case InsightKind.duplicate: return "doc.on.doc"129        default: return "sparkle"130        }131    }132133    /// The journal families offered as filters, in display order.134    public static let eventFamilies = ["page", "task", "relation", "link", "tag", "reference", "attachment", "capture", "decision", "canvas", "ai", "agent"]135136    public static func familyTitle(_ family: String) -> String {137        switch family {138        case "page": return L("Pages")139        case "task": return L("Tâches")140        case "relation": return L("Relations")141        case "link": return L("Liens")142        case "tag": return L("Étiquettes")143        case "reference": return L("Références")144        case "attachment": return L("Pièces jointes")145        case "capture": return L("Captures")146        case "decision": return L("Décisions")147        case "canvas": return L("Canvas")148        case "ai": return L("IA")149        case "agent": return L("Agents")150        default: return family151        }152    }153154    public static func eventTitle(_ kind: String) -> String {155        switch kind {156        case EventKind.pageCreated: return L("Page créée")157        case EventKind.pageRenamed: return L("Page renommée")158        case EventKind.pageEdited: return L("Page modifiée")159        case EventKind.pageMoved: return L("Page déplacée")160        case EventKind.pageArchived: return L("Page archivée")161        case EventKind.pageUnarchived: return L("Page désarchivée")162        case EventKind.pageTrashed: return L("Page mise à la corbeille")163        case EventKind.pageRestored: return L("Page restaurée")164        case EventKind.pagePurged: return L("Page supprimée définitivement")165        case EventKind.pageVersion: return L("Version enregistrée")166        case EventKind.tagAdded: return L("Étiquette ajoutée")167        case EventKind.tagRemoved: return L("Étiquette retirée")168        case EventKind.linkAdded: return L("Lien ajouté")169        case EventKind.linkRemoved: return L("Lien retiré")170        case EventKind.relationCreated: return L("Relation créée")171        case EventKind.relationAccepted: return L("Relation acceptée")172        case EventKind.relationRejected: return L("Relation refusée")173        case EventKind.relationRemoved: return L("Relation retirée")174        case EventKind.referenceAdded: return L("Référence ajoutée")175        case EventKind.referenceLinked: return L("Référence liée")176        case EventKind.attachmentAdded: return L("Pièce jointe ajoutée")177        case EventKind.taskCreated: return L("Tâche créée")178        case EventKind.taskCompleted: return L("Tâche terminée")179        case EventKind.taskReopened: return L("Tâche rouverte")180        case EventKind.captureCreated: return L("Capture créée")181        case EventKind.captureFiled: return L("Capture classée")182        case EventKind.aiApplied: return L("Résultat IA inséré")183        case EventKind.agentApplied: return L("Proposition d'agent appliquée")184        case EventKind.decisionRecorded: return L("Décision consignée")185        case EventKind.canvasEdited: return L("Canvas modifié")186        default: return kind187        }188    }189190    public static func eventSymbol(_ kind: String) -> String {191        switch kind.split(separator: ".").first.map(String.init) ?? kind {192        case "page": return kind == EventKind.pageVersion ? "clock.arrow.circlepath" : "doc.text"193        case "task": return "checkmark.circle"194        case "relation": return "arrow.triangle.branch"195        case "link": return "link"196        case "tag": return "number"197        case "reference": return "book.closed"198        case "attachment": return "paperclip"199        case "capture": return "tray.and.arrow.down"200        case "decision": return "scalemass"201        case "canvas": return "rectangle.3.group"202        case "ai": return "sparkles"203        case "agent": return "cpu"204        default: return "circle"205        }206    }207208    public static func priorityTitle(_ priority: String?) -> String? {209        switch priority {210        case "high"?: return L("Priorité haute")211        case "medium"?: return L("Priorité moyenne")212        case "low"?: return L("Priorité basse")213        default: return nil214        }215    }216217    /// A page title as shown: the server's « Untitled » and empty titles read « Sans titre ».218    public static func title(_ raw: String?) -> String {219        guard let raw, !raw.trimmingCharacters(in: .whitespaces).isEmpty, raw != "Untitled" else { return L("Sans titre") }220        return raw221    }222}223224/// A tappable row: leading symbol or emoji, title, detail, trailing accessory. At least 44 pt tall when compact.225struct KnowledgeRow<Trailing: View>: View {226    @Environment(\.featureSizeClass) private var sizeClass227    let symbol: String228    var icon: String?229    var tint: Color = NVColor.fgMuted230    let title: String231    var detail: String?232    var action: (() -> Void)?233    @ViewBuilder var trailing: () -> Trailing234235    var body: some View {236        let row = HStack(alignment: .center, spacing: NVSpace.md) {237            Group {238                if let icon, !icon.isEmpty {239                    Text(icon).font(.system(size: 17))240                } else {241                    Image(systemName: symbol).font(.system(size: 15, weight: .medium)).foregroundStyle(tint)242                }243            }244            .frame(width: 26)245            .accessibilityHidden(true)246            VStack(alignment: .leading, spacing: NVSpace.xxs) {247                Text(title).nvFont(.body).foregroundStyle(NVColor.fg).lineLimit(2).multilineTextAlignment(.leading)248                if let detail, !detail.isEmpty {249                    Text(detail).nvFont(.ui).foregroundStyle(NVColor.fgMuted).lineLimit(3).multilineTextAlignment(.leading)250                }251            }252            Spacer(minLength: NVSpace.sm)253            trailing()254            if action != nil {255                Image(systemName: "chevron.right").font(.system(size: 12, weight: .semibold)).foregroundStyle(NVColor.fgFaint).accessibilityHidden(true)256            }257        }258        .padding(.vertical, NVSpace.sm)259        .frame(minHeight: sizeClass.isCompact ? 44 : 36)260        .contentShape(Rectangle())261        if let action {262            Button(action: action) { row }.buttonStyle(.plain)263        } else {264            row.accessibilityElement(children: .combine)265        }266    }267}268269extension KnowledgeRow where Trailing == EmptyView {270    init(symbol: String, icon: String? = nil, tint: Color = NVColor.fgMuted, title: String, detail: String? = nil, action: (() -> Void)? = nil) {271        self.init(symbol: symbol, icon: icon, tint: tint, title: title, detail: detail, action: action, trailing: { EmptyView() })272    }273}274275/// A titled card grouping rows, with a count on the right.276struct KnowledgeSection<Content: View>: View {277    let title: String278    var subtitle: String?279    var count: Int?280    var tone: NVTone = .neutral281    @ViewBuilder var content: () -> Content282283    var body: some View {284        VStack(alignment: .leading, spacing: NVSpace.xs) {285            NVSectionHeader(title, subtitle: subtitle) {286                if let count { NVChip(String(count), tone: count == 0 ? .neutral : tone) }287            }288            content()289        }290        .padding(NVSpace.lg)291        .frame(maxWidth: .infinity, alignment: .leading)292        .nvCard()293    }294}295296/// A big number with its caption.297struct KnowledgeStat: View {298    let value: String299    let label: String300    var tint: Color = NVColor.fg301302    var body: some View {303        VStack(alignment: .leading, spacing: NVSpace.xxs) {304            Text(value).nvFont(.h2).foregroundStyle(tint)305            Text(label).nvFont(.micro).foregroundStyle(NVColor.fgMuted)306        }307        .frame(maxWidth: .infinity, alignment: .leading)308        .accessibilityElement(children: .combine)309    }310}311
Files main
Menu

Theme