rich-text-editor
Version:
Rich text editor
68 lines (67 loc) • 2.6 kB
TypeScript
import { TextAreaProps } from './components/text-area';
import type { Answer } from './utility';
export type { Answer, TextAreaProps };
export type RichTextEditorHandle = {
setValue: (value: string) => void;
};
export type RichTextEditorProps = {
allowedFileTypes?: string[];
baseUrl?: string;
/**
* Callback that's called when the user pastes an image to the text area.
* The function is given a `File` Blob and is expected to return a string
* that can be used as the `src` attribute of an `<img />` tag.
*/
getPasteSource?: (file: File) => Promise<string>;
initialValue?: string;
language?: 'FI' | 'SV';
onValueChange?: (answer: Answer) => void;
textAreaProps?: TextAreaProps;
/** The toolbars will be rendered in this root via a React Portal */
toolbarRoot?: HTMLElement;
invalidImageSelector?: string;
/**
* Overrides the default latex update handler.
*
* By default the handler sets the alt and src attributes on the <img>
* element `img`:
* ```
* (img: HTMLImageElement, latex: string) => {
* img.setAttribute('src', `${baseUrl}/math.svg?latex=${encodeURIComponent(latex)}`)
* img.setAttribute('alt', latex)
* }
* ```
*/
onLatexUpdate?: (img: HTMLImageElement, latex: string) => void;
} & TextAreaProps;
declare const RichTextEditor: import("react").ForwardRefExoticComponent<{
allowedFileTypes?: string[];
baseUrl?: string;
/**
* Callback that's called when the user pastes an image to the text area.
* The function is given a `File` Blob and is expected to return a string
* that can be used as the `src` attribute of an `<img />` tag.
*/
getPasteSource?: (file: File) => Promise<string>;
initialValue?: string;
language?: "FI" | "SV";
onValueChange?: (answer: Answer) => void;
textAreaProps?: TextAreaProps;
/** The toolbars will be rendered in this root via a React Portal */
toolbarRoot?: HTMLElement;
invalidImageSelector?: string;
/**
* Overrides the default latex update handler.
*
* By default the handler sets the alt and src attributes on the <img>
* element `img`:
* ```
* (img: HTMLImageElement, latex: string) => {
* img.setAttribute('src', `${baseUrl}/math.svg?latex=${encodeURIComponent(latex)}`)
* img.setAttribute('alt', latex)
* }
* ```
*/
onLatexUpdate?: (img: HTMLImageElement, latex: string) => void;
} & TextAreaProps & import("react").RefAttributes<RichTextEditorHandle>>;
export default RichTextEditor;