UNPKG

@banx9x/react-editor

Version:

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

114 lines (105 loc) 2.79 kB
import { JSX as JSX_2 } from 'react/jsx-runtime'; import { LexicalEditor } from 'lexical'; declare function Editor({ initialValue, disabled, height, maxLength, uploadConfig, onChange, onError, getEditorRef, markupColor, autoFocus, placeholder, }: EditorProps): JSX_2.Element; export default Editor; export declare type EditorProps = { /** * Initial text render in editor */ initialValue?: string; /** * Editor height (exclude toolbar), default is 300px */ height?: number; /** * Max length of content (count by word), default is unlimited */ maxLength?: number; /** * Disable editor (hide toolbar) */ disabled?: boolean; /** * Set color for text */ /** * Config for upload image plugin */ uploadConfig?: UploadConfig; /** * Emit when text change * @param value Editor content * @returns */ onChange?: (value: string) => void; /** * Emit when something wrong * @param error Error * @returns */ onError?: (error: Error) => void; /** * Get Editor ref and can use for manual update editor * @param editor Editor ref * @returns * @example * ```tsx * getEditorRef={(editor) => { * const data = new DataTransfer(); * data.setData('text/html', '<h1>Thử thôi mà</h1>'); * * editor.dispatchCommand( * PASTE_COMMAND, * new ClipboardEvent('patse', { * clipboardData: data, * }), * ); * }} * ``` */ getEditorRef?: (editor: LexicalEditor) => void; /** * Markup text color, default is red */ markupColor?: string; /** * Auto focus on editor, default is true */ autoFocus?: boolean; /** * Placeholder text * @default "Write something ..." */ placeholder?: string; }; export { LexicalEditor } declare type LoaderFunction = (url: string) => Promise<string>; declare type UploadConfig = { /** * Max size in MB, default is 1MB */ maxSize?: number; /** * Limit width for first time */ defaultWidth?: number; /** * Accepted file types, default is .jpg, .jpeg, .png */ acceptedFileTypes?: string[]; /** * Custom upload function, should return a promise with UploadResult or throw an error * @param file File * @returns */ uploadFn?: UploadFunction; loaderFn?: LoaderFunction; }; declare type UploadFunction = (file: File) => Promise<UploadResult>; declare type UploadResult = { filename: string; src: string; width: number; height: number; }; export { }