import { MutableRefObject } from 'react'; import { HocuspocusProvider } from '@hocuspocus/provider'; import { IndexeddbPersistence } from 'y-indexeddb'; import { Awareness } from 'y-protocols/awareness'; import { ConnectionStatus } from '../types'; import type * as Y from 'yjs'; /** Helpers passed to onSynced callback */ export interface SyncedHelpers { replaceContent: (markdown: string) => void; /** Manually trigger headings extraction (useful after sync when TOC needs updating) */ refreshHeadings: () => void; } export interface SyncRefs { local: MutableRefObject; remote: MutableRefObject; called: MutableRefObject; onSynced: MutableRefObject<((helpers: SyncedHelpers) => void) | undefined>; onConnection: MutableRefObject<((status: ConnectionStatus) => void) | undefined>; onAwareness: MutableRefObject<((states: Map>) => void) | undefined>; onAuthenticationFailed: MutableRefObject<((payload: { reason: string; hasUnsyncedChanges: boolean; }) => void) | undefined>; replaceContent: MutableRefObject<((markdown: string) => void) | null>; refreshHeadings: MutableRefObject<(() => void) | null>; } export interface CollabState { ydoc: Y.Doc; provider: HocuspocusProvider; /** Null when IndexedDB was skipped after a failed pre-connect clear. */ persistence: IndexeddbPersistence | null; awareness: Awareness; } export interface UseCollaborationResult { collabState: CollabState | null; isCollabEnabled: boolean; /** Ref to be set by the editor with the replaceContent function */ replaceContentRef: MutableRefObject<((markdown: string) => void) | null>; /** Ref to be set by the editor with the refreshHeadings function */ refreshHeadingsRef: MutableRefObject<(() => void) | null>; }