/** * @author xh * @date 2022/09/06 11:26 * @description 基于wangEditor的富文本编辑器 */ import React, { ReactNode } from 'react'; import { LabelTooltipProps } from '../Label'; import { IDomEditor } from '@wangeditor/editor'; import { HelperTextDetailProps } from '../HelperText'; import './index.scss'; import '@wangeditor/editor/dist/css/style.css'; type InsertFnType = (url: string, alt: string, href: string) => void; export interface IMenuGroup { key: string; title: string; iconSvg?: string; menuKeys: string[]; } export interface UpLoadImgConfig { /** form-data fieldName ,默认值 'wangeditor-uploaded-image' */ fieldName: string; /** 单个文件的最大体积限制,默认为 2M */ /** 1 * 1024 * 1024(1M) */ maxFileSize: number; /** 最多可上传几个文件,默认为 100) */ maxNumberOfFiles: number; /** 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 [] */ allowedFileTypes: string[]; /** 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。*/ meta: object; /** 将 meta 拼接到 url 参数中,默认 false */ metaWithUrl: boolean; /** 自定义增加 http header */ headers: object; /** 跨域是否传递 cookie ,默认为 false */ withCredentials: boolean; /** 超时时间,默认为 10 秒 */ /** 5 * 1000(5秒) */ timeout: number; /** 小于该值就插入 base64 格式(而不上传),默认为 0 */ /** 5 * 1024(5kb) */ base64LimitSize: number; /** 单个文件上传成功之后 */ onSuccess: (file: File, res: any) => void; /** 单个文件上传失败 */ onFailed: (file: File, res: any) => void; /** 上传进度回调 */ onProgress: (progress: number) => void; /** 上传之前触发 */ onBeforeUpload: (file: File) => any; /** 上传错误,或者触发 timeout 超时 */ onError: (file: File, err: any, res: any) => void; /** 用户自定义图片上传 */ customUpload: (file: File, insertFn: InsertFnType) => void; /** 用户自定义图片插入 */ customInsert: (res: any, insertFn: InsertFnType) => void; } export type UpLoadVideoConfig = Omit; export interface TextEditorProps extends HelperTextDetailProps { /** 样式class */ className?: string; /** style */ style?: React.CSSProperties; /** toolbarStyle */ toolbarStyle?: React.CSSProperties; /** editorStyle */ editorStyle?: React.CSSProperties; /** 富文本的最大长度 */ max?: number; /** 标题 */ label?: ReactNode; /** 标题提示 */ labelSign?: ReactNode; /** 帮组提示信息 */ labelTooltip?: LabelTooltipProps; /** 提示语 */ placeholder?: string; /** 编辑器是否默认聚焦 */ autoFocus?: boolean; /** 只读 */ readOnly?: boolean; /** 是否必填 */ required?: boolean; /** 默认值 不受控 */ defaultValue?: string; /** 默认值 受控 */ value?: string; /** 工具栏菜单配置*/ toolbarKeys?: Array; /** 工具栏不需要的配置 */ excludeKeys?: string[]; /** 工具栏插入新菜单 */ insertKeys?: { index: number; keys: string | Array; }; /** 文件上传的服务地址 */ server: string; /** 上传图片配置 */ uploadImage?: Partial; /** 上传视频配置 */ uploadVideo?: Partial; /** 国际化 */ in18?: 'en' | 'zh-CN'; /** 改变事件 */ onChange?: (value: string, text: string) => void; /** 失去焦点 */ onBlur?: (editor: IDomEditor) => void; /** 得到焦点 */ onFocus?: (editor: IDomEditor) => void; /** 编辑器销毁钩子 */ onDestroyed?: (editor: IDomEditor) => void; /** 是否禁用 */ disabled?: boolean; } export interface TextEditorRef { /** 获取html内容 */ getContent: () => string | undefined; /** 获取纯文本内容 */ getText: () => string | undefined; /** 清空编辑器 */ clearEditor: () => void; /** 设置content */ setContent: (content: string) => void; /** 获取编辑器实例 */ getEditor: () => IDomEditor | null; } declare const TextEditor: React.ForwardRefExoticComponent>; export default TextEditor;