import { MutableRefObject } from 'react'; import { EditorView } from '@milkdown/kit/prose/view'; import { Heading } from './lib/getHeadings'; export { normalizeMarkdown } from './normalizeMarkdown'; export type ReplaceContentFn = (markdown: string) => void; /** Transaction-like shape for post-dispatch callback (avoids PM import). */ export type PostDispatchFn = (tr: { docChanged?: boolean; }) => void; interface UseEditorReadyOptions { /** Ref to be set with replaceContent function when editor is ready */ replaceContentRef?: MutableRefObject; /** Ref to be set with refreshHeadings function when editor is ready */ refreshHeadingsRef?: MutableRefObject<(() => void) | null>; /** Standalone: view wired. Collab: fired from setupCollaboration after Y.Doc apply. */ onReady?: () => void; /** Called when document headings change (on ready and content updates) */ onHeadingsChange?: (headings: Heading[]) => void; /** Ref holding the collab service — disconnected on cleanup to prevent late dispatches */ collabServiceRef?: MutableRefObject<{ disconnect(): unknown; } | null>; /** * When set (e.g. when collab is enabled), register post-dispatch logic here instead of * wrapping view.dispatch. Caller installs a single wrapper that calls this after each dispatch. */ postDispatchRef?: MutableRefObject; /** Live ProseMirror view for slash-menu gating (cleared on detach). */ editorViewRef?: MutableRefObject; /** Live selected channel for variable-content heading resolution. */ selectedChannelIdRef?: MutableRefObject; } /** * Hook that runs **synchronously** when the Milkdown editor's container mounts. * * Returns a callback ref to attach to the container div. Unlike a useEffect-based * approach, this runs during the React commit phase — before any async effects or * scheduled callbacks — so the dispatch wrapper is in place before collab can fire. * * Responsibilities: * 1. Exposes ProseMirror view on DOM element (for testing) * 2. Provides replaceContent function (for revision restore) * 3. Tracks headings and fires onHeadingsChange callback (for TOC) * 4. When collab: registers post-dispatch via postDispatchRef (single wrapper in EditorCore). * When no collab: wraps view.dispatch to track heading changes and guard teardown races. */ export declare function useEditorReady({ replaceContentRef, refreshHeadingsRef, onReady, onHeadingsChange, collabServiceRef, postDispatchRef, editorViewRef, selectedChannelIdRef, }: UseEditorReadyOptions): (node: HTMLDivElement | null) => void;