import { MutableRefObject } from 'react'; import { Crepe } from '@milkdown/crepe'; import { CollabService } from '@milkdown/plugin-collab'; import { Awareness } from 'y-protocols/awareness'; import { PostDispatchFn } from '../../useEditorReady'; import type * as Y from 'yjs'; export interface CollabState { ydoc: Y.Doc; awareness: Awareness; } /** * Binds the editor to a Y.Doc for real-time collaboration. * Connects the collab service after the editor mounts. * Stores collabService in serviceRef so it can be disconnected before editor teardown. * * Single dispatch wrapper (when postDispatchRef provided): swallows "not found" teardown * errors and invokes postDispatchRef after each dispatch. useEditorReady registers * its heading/tracking logic via this ref instead of layering a second wrapper. * * Initial markdown is NOT applied here. Milkdown `applyTemplate` targets the wrong * fragment name for Platform (`prosemirror` vs `default`), and applying before remote * sync races with server state (duplicate content). Collaborative documents are seeded * from the Hocuspocus/Y.Doc server state. */ export declare function setupCollaboration(crepe: Crepe, ydoc: Y.Doc, awareness: Awareness, _initialMarkdown: string, serviceRef: MutableRefObject, postDispatchRef: MutableRefObject, localEditPendingRef: MutableRefObject, onReadyRef?: MutableRefObject<(() => void) | undefined>): void; /** * Subscribe to serialized markdown updates and invoke the callback (collab dirty tracking, Storybook, etc.). * * In collab mode, only local edits propagate — remote Yjs sync must not mutate platform draftText. */ export declare function setupCollabContentChange(crepe: Crepe, onContentChangeRef: React.MutableRefObject<((markdown: string) => void) | undefined>, localEditPendingRef?: MutableRefObject): void;