UNPKG

@opentiny/fluent-editor

Version:

A rich text editor based on Quill 2.0, which extends rich modules and formats on the basis of Quill. It's powerful and out-of-the-box.

67 lines (66 loc) 2.68 kB
import { Range, default as Quill } from 'quill'; import { default as TypeUploader } from 'quill/modules/uploader'; import { default as FluentEditor } from '../core/fluent-editor'; declare const Uploader: typeof TypeUploader; export type UploadKind = 'image' | 'video' | 'file'; export type MimeTypesConfig = string[] | Partial<Record<UploadKind, string[]>>; export type MaxSizeConfig = number | Partial<Record<UploadKind, number>>; export type MultipleConfig = boolean | Partial<Record<UploadKind, boolean>>; interface UploaderOptions { mimetypes: string[]; handler: (this: { quill: Quill; }, range: Range, files: File[]) => void; } export interface FileUploaderOptions { /** * 支持单个 MIME type、模糊匹配子类型和后缀名三种格式 * - 全局配置:`string[]` * - 根据文件/图片/视频单独配置:`{ file?: string[]; image?: string[]; video?: string[] }` */ mimetypes: MimeTypesConfig; /** * 最大文件大小限制(字节) * - 全局配置:`number` * - 根据文件/图片/视频单独配置:`{ file?: number; image?: number; video?: number }` */ maxSize: MaxSizeConfig; /** * 是否允许多选文件 * - 全局配置:`boolean` * - 根据文件/图片/视频单独配置:`{ file?: boolean; image?: boolean; video?: boolean }` */ multiple: MultipleConfig; handler: (this: { quill: FluentEditor; }, range: Range, files: File[]) => Promise<(string | false)[]> | (string | false)[]; success: (this: { quill: FluentEditor; }, file: File, range: Range) => void; fail: (this: { quill: FluentEditor; }, file: File, range: Range) => void; } export declare class FileUploader extends Uploader { quill: FluentEditor; static DEFAULTS: any; options: Partial<UploaderOptions> & FileUploaderOptions; constructor(quill: FluentEditor, options: Partial<FileUploaderOptions>); resolveOptions(options?: Partial<FileUploaderOptions>): { mimetypes: string[]; maxSize: number; multiple: boolean; handler(range: Range, files: File[]): string[]; success(): void; fail(): void; } & Partial<FileUploaderOptions>; private inferKind; private filterFromArray; getAccept(kind: UploadKind): string[]; getMaxSize(kind: UploadKind): number; getMultiple(kind: UploadKind): boolean; validateFile(file: File, kind?: UploadKind): boolean; getFileUrls(files: File[], range: Range, kind?: UploadKind): Promise<(string | false)[]>; upload(range: Range, files: FileList | File[], kind?: UploadKind): Promise<void>; } export {};