UNPKG

modulo-editor

Version:

A flexible and extensible block-based editor for React applications

198 lines (197 loc) 5.67 kB
import { ComponentType } from "react"; import { IconComponent } from "./icon"; import { ToolbarItem } from "./toolbar"; export type ListStyle = "ordered" | "ordered-alpha" | "ordered-roman" | "unordered" | "checklist" | "dashed" | "arrow" | "star" | "circle" | "check" | "question" | "warning" | "info"; export type UploadMode = "immediate" | "onSave"; export type OnUpload = (file: File) => Promise<{ url: string; id: string; } | null>; export type OnRemove = (id: string) => Promise<void>; export interface ImageToolConfig { withCaption?: boolean; uploadMode?: UploadMode; onUpload?: OnUpload; onRemove?: OnRemove; } export interface GalleryToolConfig { withCaption?: boolean; uploadMode?: UploadMode; onUpload?: OnUpload; onRemove?: OnRemove; } interface CustomInputCodeProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, "value" | "onChange"> { value: string; onChange: (newValue: string) => void; } export interface RawHTMLConfig { InputCode?: React.ComponentType<CustomInputCodeProps>; } export interface AttachmentDataType { url: string; title: string; type: string; size: string; config?: AttachmentToolConfig; } export declare enum AttachmentFileType { PDF = "application/pdf", WORD_DOC = "application/msword", WORD_DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", EXCEL_XLS = "application/vnd.ms-excel", EXCEL_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", TEXT = "text/plain", CSV = "text/csv", RTF = "application/rtf" } export interface AttachmentToolConfig { display?: "embed" | "icon"; acceptedFileTypes?: AttachmentFileType[]; maxFileSizeMB?: number; allowDownload?: boolean; allowOpen?: boolean; allowPreview?: boolean; onDownload?: (data: AttachmentDataType) => void; onOpen?: (data: AttachmentDataType) => void; onPreview?: (data: AttachmentDataType) => void; uploadMode?: UploadMode; onUpload?: OnUpload; onRemove?: OnRemove; } export interface ListToolConfig { min?: number; max?: number; } export interface BlockToolProps<TConfig extends Record<string, any> | undefined = undefined> { id: string; data: Record<string, any>; readOnly?: boolean; onChange: (data: Record<string, any>) => void; onFocus?: () => void; onBlur?: () => void; config?: TConfig; toolbox?: { title: string; icon: IconComponent; }; type?: string; } interface BaseBlockTool { component: ComponentType<BlockToolProps<any>>; isInline?: boolean; toolbar?: { items: ToolbarItem[]; }; type: string; } export interface ListBlockTool extends BaseBlockTool { type: "list"; config?: ListToolConfig; toolbox: { title: string; icon: IconComponent; }; } export interface HeadingBlockTool extends BaseBlockTool { type: "heading"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface ParagraphBlockTool extends BaseBlockTool { type: "paragraph"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface ImageBlockTool extends BaseBlockTool { type: "image"; config?: ImageToolConfig; toolbox: { title: string; icon: IconComponent; }; } export interface AttachmentBlockTool extends BaseBlockTool { type: "attachment"; config?: AttachmentToolConfig; toolbox: { title: string; icon: IconComponent; }; } export interface TableBlockTool extends BaseBlockTool { type: "table"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface EmbedBlockTool extends BaseBlockTool { type: "embed"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface LinkBlockTool extends BaseBlockTool { type: "link"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface QuoteBlockTool extends BaseBlockTool { type: "quote"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface DelimiterBlockTool extends BaseBlockTool { type: "delimiter"; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export interface RawHtmlBlockTool extends BaseBlockTool { type: "rawHtml"; config?: RawHTMLConfig; toolbox: { title: string; icon: IconComponent; }; } export interface GalleryBlockTool extends BaseBlockTool { type: "gallery"; config?: GalleryToolConfig; toolbox: { title: string; icon: IconComponent; }; } export interface GenericBlockTool extends BaseBlockTool { type: Exclude<string, "list" | "heading" | "paragraph" | "image" | "attachment" | "table" | "embed" | "link" | "quote" | "delimiter" | "rawHtml" | "gallery">; config?: Record<string, any>; toolbox: { title: string; icon: IconComponent; }; } export type BlockTool = ImageBlockTool | ListBlockTool | HeadingBlockTool | ParagraphBlockTool | AttachmentBlockTool | TableBlockTool | EmbedBlockTool | LinkBlockTool | QuoteBlockTool | DelimiterBlockTool | RawHtmlBlockTool | GalleryBlockTool | GenericBlockTool; export interface BlockTypeActions { uploadMode?: UploadMode; onUpload?: OnUpload; onRemove?: OnRemove; } export {};