/** * Unified Document Store (TriDoc) * TASKSET 6.1: Zustand store for managing multi-view state, variables, and layout * * Manages state for unified documents that contain: * - Multiple views (editor, calc, slides) * - Shared variables across views * - Layout configuration * - Cross-view synchronization state */ /** View types in a unified document */ export type ViewType = 'editor' | 'calc' | 'slides'; /** Layout options for displaying views */ export type ViewLayout = 'single' | 'split_horizontal' | 'split_vertical' | 'grid'; /** Variable types for shared variables */ export type VariableType = 'string' | 'number' | 'boolean' | 'date' | 'cellref' | 'formula'; /** Priority levels for cross-view synchronization */ export type SyncPriority = 'low' | 'normal' | 'high' | 'immediate'; /** Source location for a variable */ export interface VariableSource { /** Which view defines this variable */ view: ViewType; /** Location within the view (view-specific format) */ location?: Record; } /** Shared variable that can be referenced across views */ export interface SharedVariable { /** Variable name (unique within document) */ name: string; /** Variable type for validation/coercion */ type: VariableType; /** Current value */ value: unknown; /** Where this variable is defined */ source?: VariableSource; } /** Content and metadata for a single view */ export interface ViewContent { viewType: ViewType; content: unknown; version: number; lastUpdated: string; lastUpdatedBy?: string; isDirty: boolean; } /** Cross-view sync state */ export interface CrossViewSyncState { /** Whether sync is currently in progress */ isSyncing: boolean; /** Variables pending sync */ pendingVariables: string[]; /** Source view that triggered sync */ sourceView?: ViewType; /** Target views that need updates */ targetViews: ViewType[]; /** Last sync error */ lastError?: Error; } /** Unified document state */ export interface UnifiedDocumentState { /** Document ID */ documentId: string | null; /** Workspace ID */ workspaceId: string | null; /** Document title */ title: string; /** Currently active view */ activeView: ViewType; /** Enabled views for this document */ enabledViews: ViewType[]; /** Default view when opening document */ defaultView: ViewType; /** Current layout mode */ viewLayout: ViewLayout; /** Content for each view */ viewContents: Record; /** Shared variables */ variables: Map; /** Cross-view sync state */ syncState: CrossViewSyncState; /** Whether the document is loading */ isLoading: boolean; /** Whether the document has been modified */ isDirty: boolean; /** Last error */ error: Error | null; } /** Actions for the unified document store */ export interface UnifiedDocumentActions { initializeDocument: (params: { documentId: string; workspaceId: string; title: string; enabledViews: ViewType[]; defaultView: ViewType; viewLayout?: ViewLayout; initialVariables?: SharedVariable[]; }) => void; resetDocument: () => void; setLoading: (isLoading: boolean) => void; setError: (error: Error | null) => void; setActiveView: (view: ViewType) => void; setViewLayout: (layout: ViewLayout) => void; setEnabledViews: (views: ViewType[]) => void; setDefaultView: (view: ViewType) => void; setViewContent: (view: ViewType, content: unknown, version: number) => void; updateViewContent: (view: ViewType, content: unknown) => void; markViewClean: (view: ViewType) => void; markViewDirty: (view: ViewType) => void; getViewContent: (view: ViewType) => ViewContent | null; createVariable: (variable: SharedVariable) => void; updateVariable: (name: string, value: unknown) => void; deleteVariable: (name: string) => void; getVariable: (name: string) => SharedVariable | undefined; getVariablesByView: (view: ViewType) => SharedVariable[]; getAllVariables: () => SharedVariable[]; startCrossViewSync: (sourceView: ViewType, changedVariables: string[], targetViews: ViewType[]) => void; completeCrossViewSync: () => void; failCrossViewSync: (error: Error) => void; handleViewUpdated: (data: { viewType: ViewType; version: number; content?: unknown; updatedBy: string; updatedAt: string; }) => void; handleVariableCreated: (variable: SharedVariable) => void; handleVariableUpdated: (name: string, variable: SharedVariable) => void; handleVariableDeleted: (name: string) => void; handleLayoutChanged: (layout: ViewLayout) => void; handleEnabledViewsChanged: (views: ViewType[], defaultView: ViewType) => void; handleCrossViewSync: (data: { sourceView: ViewType; targetViews: ViewType[]; changedVariables: string[]; priority: SyncPriority; }) => void; } export type UnifiedDocumentStore = UnifiedDocumentState & UnifiedDocumentActions; export declare const useUnifiedDocumentStore: import("zustand").UseBoundStore, "subscribe"> & { subscribe: { (listener: (selectedState: UnifiedDocumentStore, previousSelectedState: UnifiedDocumentStore) => void): () => void; (selector: (state: UnifiedDocumentStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: { equalityFn?: (a: U, b: U) => boolean; fireImmediately?: boolean; }): () => void; }; }>; /** Select current active view */ export declare const selectActiveView: (state: UnifiedDocumentStore) => ViewType; /** Select enabled views */ export declare const selectEnabledViews: (state: UnifiedDocumentStore) => ViewType[]; /** Select current view layout */ export declare const selectViewLayout: (state: UnifiedDocumentStore) => ViewLayout; /** Select all variables as array */ export declare const selectVariables: (state: UnifiedDocumentStore) => SharedVariable[]; /** Select variable by name */ export declare const selectVariableByName: (name: string) => (state: UnifiedDocumentStore) => SharedVariable; /** Select variables for a specific view */ export declare const selectVariablesByView: (view: ViewType) => (state: UnifiedDocumentStore) => SharedVariable[]; /** Select content for a specific view */ export declare const selectViewContent: (view: ViewType) => (state: UnifiedDocumentStore) => ViewContent; /** Select whether document has unsaved changes */ export declare const selectIsDirty: (state: UnifiedDocumentStore) => boolean; /** Select sync state */ export declare const selectSyncState: (state: UnifiedDocumentStore) => CrossViewSyncState; /** Select document info */ export declare const selectDocumentInfo: (state: UnifiedDocumentStore) => { documentId: string; workspaceId: string; title: string; }; export default useUnifiedDocumentStore; //# sourceMappingURL=unifiedDocumentStore.d.ts.map