spb/prisme Public MIT
Navigateur iOS intelligent — chaque page comprise localement avant d'être affichée. SwiftUI · WebKit · Foundation Models, 100% on-device.
Swift 96.7%
JavaScript 3.3%
1//2// TabStore.swift3// Prisme4//5// Author: Simon-Pierre Boucher <contact@spboucher.ai>6//78import Foundation9import Observation1011/// Ordered collection of open tabs plus the active selection.12/// Grouping by intention (P0) will layer on top of this later — the store13/// itself stays a dumb, predictable list.14@MainActor15@Observable16final class TabStore {17 private(set) var tabs: [Tab] = []18 var activeTabID: Tab.ID?1920 var activeTab: Tab? {21 guard let id = activeTabID else { return nil }22 return tabs.first { $0.id == id }23 }2425 func tabs(in containerID: IdentityContainer.ID) -> [Tab] {26 tabs.filter { $0.containerID == containerID }27 }2829 func mostRecentTab(in containerID: IdentityContainer.ID) -> Tab? {30 tabs(in: containerID).max { $0.lastActivatedAt < $1.lastActivatedAt }31 }3233 @discardableResult34 func open(_ url: URL?, in containerID: IdentityContainer.ID, activate: Bool = true) -> Tab {35 let tab = Tab(initialURL: url, containerID: containerID)36 tabs.append(tab)37 if activate {38 self.activate(tab)39 }40 return tab41 }4243 func activate(_ tab: Tab) {44 tab.lastActivatedAt = Date()45 activeTabID = tab.id46 }4748 func close(_ tab: Tab) {49 guard let index = tabs.firstIndex(where: { $0.id == tab.id }) else { return }50 tabs.remove(at: index)51 guard activeTabID == tab.id else { return }52 // Prefer a neighbour from the same container, else none.53 let siblings = tabs(in: tab.containerID)54 activeTabID = siblings.last?.id55 }56}57