UNPKG

rich-text-editor

Version:
56 lines (55 loc) 2.68 kB
import { PropsWithChildren, ReactPortal } from 'react'; import { HistoryActionResult } from './history'; import { MathEditorHandle } from '../components/math-editor'; import FI from '../../FI'; import { CaretPosition } from '../utility'; import { RichTextEditorProps } from '../index'; export type EditorState = { /** Ref to the main text-area (which is a `contenteditable` `<div />`) */ ref: React.RefObject<HTMLDivElement>; mathEditorPortal: [portalRoot: Node, portal: ReactPortal] | null; spawnMathEditorAtCursor(): void; spawnMathEditorInNewLine(afterElement: Element): void; isToolbarOpen: boolean; isMathToolbarOpen: boolean; showToolbar: () => void; hideToolbar: () => void; isToolbarExpanded: boolean; expandToolbar: () => void; collapseToolbar: () => void; persistValidImages: () => Promise<void>; handlePastedImage: NonNullable<RichTextEditorProps['getPasteSource']>; allowedFileTypes: NonNullable<RichTextEditorProps['allowedFileTypes']>; invalidImageSelector: NonNullable<RichTextEditorProps['invalidImageSelector']>; isHelpDialogOpen: boolean; showHelpDialog: () => void; hideHelpDialog: () => void; setActiveMathEditor: (handle: MathEditorHandle | null) => void; activeMathEditor: MathEditorHandle | null; /** * Finds all math-editor boxes in the text area and makes them interactive. * Should be called after e.g. pasting in new content. */ initMathImages: () => void; t: typeof FI; /** Called when answer has changed. This needs to happen on this level, * as programmatic changes to the answer (e.g. creating and editing equations) * do not trigger the main text area's `onInput` event so we need a mechanism to * trigger this from multiple places */ onAnswerChange: (caretPosition?: CaretPosition, shouldUpdateHistory?: boolean) => void; initialValue?: string; baseUrl: string; undoEquation: () => string | undefined; redoEquation: () => string | undefined; canUndoEquation: boolean; canRedoEquation: boolean; undoEditor: () => HistoryActionResult | undefined; redoEditor: () => HistoryActionResult | undefined; canUndoEditor: boolean; canRedoEditor: boolean; }; export default function useEditorState(): EditorState; type EditorStateProps = PropsWithChildren<Omit<RichTextEditorProps, 'textAreaProps' | 'toolbarRoot'>>; export declare function EditorStateProvider({ children, language, getPasteSource, allowedFileTypes, invalidImageSelector, onValueChange, initialValue, baseUrl, onLatexUpdate: _onLatexUpdate, }: EditorStateProps): import("react/jsx-runtime").JSX.Element; export {};