SPB Git

Repository Public MIT

ComponentCatalog.swift 3.2 KB 79 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Apps/GlassStudio/Kit/Model/ComponentCatalog.swift8// Module           : GlassStudio9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344/// The Studio's catalogue: one descriptor per component, in catalogue order. Everything is compiled into45/// the app, so the catalogue works without a network connection.46@MainActor47public struct ComponentCatalog {48    public let descriptors: [ComponentDescriptor]49    private let byID: [String: Int]5051    public init(descriptors: [ComponentDescriptor]) {52        let sorted = descriptors.sorted { $0.info.number < $1.info.number }53        self.descriptors = sorted54        byID = Dictionary(sorted.enumerated().map { ($1.id, $0) }, uniquingKeysWith: { first, _ in first })55    }5657    /// The catalogue shipped with the Studio.58    public static let standard = ComponentCatalog(descriptors:59        navigationDescriptors + buttonDescriptors + formDescriptors + selectionDescriptors + containerDescriptors60            + feedbackDescriptors + dataDescriptors + mediaDescriptors + mapDescriptors + aiDescriptors61    )6263    public func descriptor(_ id: String) -> ComponentDescriptor? {64        byID[id].map { descriptors[$0] }65    }6667    public func descriptors(in category: GlassComponentCategory) -> [ComponentDescriptor] {68        descriptors.filter { $0.info.category == category }69    }7071    public func search(_ filter: CatalogFilter, favorites: Set<String> = []) -> [ComponentDescriptor] {72        descriptors.filter { filter.matches($0.info, isFavorite: favorites.contains($0.id)) }73    }7475    /// Components that can be placed in a playground composition.76    public var composable: [ComponentDescriptor] { descriptors.filter(\.isComposable) }77    public var composableIDs: Set<String> { Set(composable.map(\.id)) }78}79
Files main
Menu

Theme