Workspace System
The Workspace class is the central orchestrator in Opal Editor, managing the lifecycle and operations of markdown editing projects. It coordinates between the storage layer (Disk), version control (GitRepo), and user interface.Architecture Overview
The Workspace system follows a layered architecture:Core Class: Workspace
Location:~/workspace/source/src/workspace/Workspace.ts
Class Definition
Key Properties
| Property | Type | Description |
|---|---|---|
guid | string | Unique identifier for the workspace |
name | string | Slugified workspace name |
disk | Disk | Main storage abstraction for files |
thumbs | Disk | Separate disk for thumbnail storage |
repo | GitRepo | Git repository instance |
imageCache | ImageCache | Browser cache for optimized image loading |
remoteAuths | RemoteAuthDAO[] | Authentication for deployment providers |
Creating Workspaces
Factory Methods
CreateNew - Create from scratch
name: Workspace identifier (will be slugified)files: Initial file tree (object or iterable)diskType: Storage backend typediskOptions: Optional configuration for diskbuildStrategy: Build system strategy (“freeform” | “eleventy”)
FromDAO - Restore from database
FromName - Load by name
Initialization
Workspaces must be initialized before use:- Initialize disk and file indexing
- Initialize Git repository
- Set up event listeners (cross-tab sync)
- Recover from non-OK status if needed
File Operations
Creating Files
Reading Files
Renaming Files
Deleting Files
Trash Operations
File Tree Navigation
Accessing Nodes
Image Handling
Upload Images
Thumbnails
Event System
Workspaces use both local and remote event emitters for cross-tab synchronization.Listening to File Changes
Workspace Lifecycle Events
Git Events
Workspace Management
Rename Workspace
Destroy Workspace
Tear Down (Cleanup)
URL Resolution
Parse Workspace Paths
Copy Operations
Serialization
Integration with Git
Workspaces integrate tightly with Git:Best Practices
Always Initialize
Clean Up Resources
Use Path Helpers
Handle Cross-Tab Events
Common Patterns
Workspace with OPFS Directory Mount
Search Workspace Content
Get All Images
Error Handling
Related Systems
- Storage System - Disk abstraction layer
- Git System - Version control integration
- Build System - Static site generation