mirror of
https://github.com/OFFIS-ESC/constellation-analyzer
synced 2026-01-26 23:43:40 +00:00
4.7 KiB
4.7 KiB
Workspace Persistence Architecture
Overview
The workspace manager now functions as a persistent document library. Documents are stored permanently in localStorage and remain available even after their tabs are closed.
Key Concepts
Document States
- Created Documents: All documents created, imported, or opened are stored persistently in localStorage
- Open Documents: Documents with active tabs (tracked in
documentOrder) - Closed Documents: Documents stored in localStorage but without active tabs
Data Structure
// Workspace State (saved to localStorage)
{
workspaceId: string;
workspaceName: string;
documentOrder: string[]; // IDs of documents with open tabs
activeDocumentId: string | null; // Currently visible document
settings: WorkspaceSettings;
}
// Document Metadata (lightweight, one per document)
{
id: string;
title: string;
isDirty: boolean;
lastModified: string;
viewport?: { x, y, zoom }; // Persisted viewport state
}
// In-Memory State
{
documents: Map<string, ConstellationDocument>; // Loaded documents (performance optimization)
documentMetadata: Map<string, DocumentMetadata>; // All document metadata
}
User Flows
Creating a Document
- User clicks "New Document"
- Document is created and saved to localStorage
- Document ID is added to
documentOrder(opens as tab) - Document metadata is added to
documentMetadata - Document is loaded into memory (
documentsMap)
Closing a Tab
- User closes a document tab (X button)
closeDocument()is called- Document ID is removed from
documentOrder(tab disappears) - Document remains in localStorage (persistent storage)
- Document metadata remains in
documentMetadata - Document is unloaded from memory (performance optimization)
Opening a Closed Document
- User opens Document Manager
- All documents from
documentMetadataare displayed (including closed ones) - Closed documents are visually indicated (no "Open" badge)
- User clicks on a closed document
switchToDocument()is called- Document is loaded from localStorage into memory
- Document ID is added back to
documentOrder(tab appears) - Document becomes active
Deleting a Document
- User clicks Delete in Document Manager
- Confirmation dialog appears
- If confirmed,
deleteDocument()is called - Document is removed from localStorage (permanent deletion)
- Document is removed from
documentOrder(if open) - Document metadata is removed from
documentMetadata - Document is unloaded from memory
Implementation Details
Key Functions
closeDocument(documentId)
- Removes from
documentOrder(closes tab) - Keeps in localStorage (persistent)
- Checks for unsaved changes before closing
switchToDocument(documentId)
- Loads document from localStorage if not in memory
- Adds to
documentOrderif not already there (reopens tab) - Sets as
activeDocumentId
deleteDocument(documentId)
- Permanently removes from localStorage
- Removes from
documentOrder - Removes from
documentMetadata - Requires confirmation
Document Manager Display
- Shows all documents from
documentMetadata(not justdocumentOrder) - Visual indicators:
- Blue border + "Open" badge: Document has an active tab
- Orange dot: Document has unsaved changes
- Search: Filters across all documents
- Footer shows: "X documents in workspace • Y open"
Performance Optimizations
- Lazy Loading: Documents are only loaded into memory when needed
- Unload: Closed documents are removed from memory (but stay in storage)
- Viewport Persistence: Each document's viewport state is saved and restored
History Management
- History stacks are per-document but not persisted to localStorage
- History is reset when a document is closed and reopened
- This is intentional to avoid localStorage bloat
Storage Keys
// Workspace state
'constellation:workspace:v1'
// Individual document
'constellation:document:v1:{documentId}'
// Document metadata
'constellation:meta:v1:{documentId}'
Migration Notes
- Old single-document format is automatically migrated on first load
- Migration creates a workspace with the legacy document as the first document
- Migration is one-way (cannot downgrade)
Future Enhancements
Potential improvements for future versions:
- Recent Documents List: Show recently accessed documents separately
- Favorites: Star/pin frequently used documents
- Document Tags: Categorize documents with user-defined tags
- Trash/Archive: Soft delete with recovery option
- Cloud Sync: Synchronize workspace across devices
- History Persistence: Optionally save undo/redo stacks (with size limits)