UNPKG

@blocknote/react

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

48 lines (47 loc) 2.07 kB
import type { BlockNoteEditor } from "@blocknote/core"; export type EditorStateSnapshot<TEditor extends BlockNoteEditor<any, any, any> | null = BlockNoteEditor<any, any, any> | null> = { editor: TEditor; transactionNumber: number; }; export type UseEditorStateOptions<TSelectorResult, TEditor extends BlockNoteEditor<any, any, any> | null = BlockNoteEditor<any, any, any> | null> = { /** * The editor instance. If not provided, will use the editor from BlockNoteContext. */ editor?: TEditor; /** * A selector function to determine the value to compare for re-rendering. */ selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult; /** * A custom equality function to determine if the editor should re-render. * @default `deepEqual` from `fast-deep-equal` */ equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean; /** * The event to subscribe to. * @default "all" */ on?: "all" | "selection" | "change"; }; /** * This hook allows you to watch for changes on the editor instance. * It will allow you to select a part of the editor state and re-render the component when it changes. * @example * ```tsx * const { currentSelection } = useEditorState({ * selector: snapshot => ({ currentSelection: snapshot.editor?._tiptapEditor.state.selection }), * }) * ``` */ export declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, BlockNoteEditor<any, any, any>>): TSelectorResult; /** * This hook allows you to watch for changes on the editor instance. * It will allow you to select a part of the editor state and re-render the component when it changes. * @example * ```tsx * const { currentSelection } = useEditorState({ * selector: snapshot => ({ currentSelection: snapshot.editor?._tiptapEditor.state.selection }), * }) * ``` */ export declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, BlockNoteEditor<any, any, any> | null>): TSelectorResult | null;