/** * useDocumentCollaboration Hook * Complete real-time document collaboration with OT integration * * Features: * - Operational Transform with core engine integration * - WebSocket communication via MessageRouter * - Operation queuing and synchronization * - Presence tracking and cursor positions * - Undo/redo with operation history */ import type { OTOperation, VectorClock } from '@materi.ai/frame/core/types'; import type { UserPresence } from './types'; /** Collaboration state for a document */ export interface DocumentCollaborationState { /** Current document content */ content: string; /** Current document version (server-side) */ serverVersion: number; /** Local vector clock */ vectorClock: VectorClock; /** Whether we're connected to the server */ isConnected: boolean; /** Whether there are pending local changes */ hasPendingChanges: boolean; /** Whether we're currently syncing */ isSyncing: boolean; /** Last sync error */ syncError: Error | null; /** Active collaborators */ collaborators: UserPresence[]; /** Local user presence */ localPresence: UserPresence | null; } /** Options for useDocumentCollaboration hook */ export interface UseDocumentCollaborationOptions { /** Document ID */ documentId: string; /** Current user ID */ userId: string; /** Initial document content */ initialContent?: string; /** WebSocket URL (defaults to current host) */ wsUrl?: string; /** User display name */ userName?: string; /** User cursor color */ userColor?: string; /** Auto-connect on mount */ autoConnect?: boolean; /** Sync interval in ms */ syncInterval?: number; /** Max operations to keep in history */ maxHistorySize?: number; /** Callback when content changes (from local or remote) */ onContentChange?: (content: string) => void; /** Callback when operation is applied */ onOperationApplied?: (op: OTOperation, isLocal: boolean) => void; /** Callback on error */ onError?: (error: Error) => void; /** Callback when collaborators change */ onCollaboratorsChange?: (collaborators: UserPresence[]) => void; } /** Return type for useDocumentCollaboration hook */ export interface UseDocumentCollaborationReturn extends DocumentCollaborationState { /** Apply a local change (will be transformed and synced) */ applyLocalChange: (newContent: string) => void; /** Insert text at position */ insertText: (position: number, text: string) => void; /** Delete text at position */ deleteText: (position: number, length: number) => void; /** Replace text at position */ replaceText: (position: number, length: number, newText: string) => void; /** Undo last local operation */ undo: () => boolean; /** Redo last undone operation */ redo: () => boolean; /** Force sync with server */ syncNow: () => Promise; /** Update local presence (cursor position, selection) */ updatePresence: (presence: Partial) => void; /** Connect to collaboration server */ connect: () => void; /** Disconnect from collaboration server */ disconnect: () => void; /** Reset content (e.g., when loading new document) */ reset: (content: string) => void; } /** * Hook for real-time document collaboration with OT */ export declare const useDocumentCollaboration: (options: UseDocumentCollaborationOptions) => UseDocumentCollaborationReturn; export type { UserPresence }; //# sourceMappingURL=useDocumentCollaboration.d.ts.map