modulo-editor
Version:
A flexible and extensible block-based editor for React applications
173 lines (172 loc) • 4.61 kB
TypeScript
import { EditorContent } from "./block";
export interface EditorEvent {
id: string;
timestamp: number;
type: EditorEventType;
data: EditorEventData;
}
export declare enum EditorEventType {
BLOCK_CREATED = "block.created",
BLOCK_MOVED = "block.moved",
BLOCK_DELETED = "block.deleted",
BLOCK_UPDATED = "block.updated",
BLOCK_SELECTED = "block.selected",
BLOCK_DESELECTED = "block.deselected",
FILE_UPLOADED = "file.uploaded",
FILE_REMOVED = "file.removed",
FILE_UPLOADING_ERROR = "file.uploading.error",
FILE_REMOVING_ERROR = "file.uploading.error",
FILE_INVALID_TYPE = "file.invalid.type",
FILE_MAX_SIZE_EXCEEDED = "file.max.size.exceeded",
EDITOR_SAVING = "editor.saving",
EDITOR_SAVED = "editor.saved",
EDITOR_SAVE_ERROR = "editor.save.error",
EDITOR_LOADED = "editor.loaded",
EDITOR_FOCUS = "editor.focus",
EDITOR_BLUR = "editor.blur",
EDITOR_TOGGLE_MODE = "editor.toggle.mode",
ERROR_OCCURRED = "error.occurred",
USER_UNDO = "user.undo",
USER_REDO = "user.redo",
USER_COPY = "user.copy",
USER_PASTE = "user.paste"
}
export interface BlockCreatedData {
blockId: string;
blockType: string;
position: number;
content: any;
}
export interface BlockMovedData {
blockId: string;
fromPosition: number;
toPosition: number;
content: any;
}
export interface BlockDeletedData {
blockId: string;
blockType: string;
position: number;
content: any;
}
export interface BlockUpdatedData {
blockId: string;
blockType: string;
oldContent: any;
newContent: any;
}
export interface BlockSelectedData {
blockId: string;
blockType: string;
}
export interface BlockDeselectedData {
blockId: string;
blockType: string;
}
export interface FileUploadedData {
fileId: string;
fileUrl: string;
blockId: string;
blockType: string;
isPending: boolean;
isPendingRemovalCanceled: boolean;
}
export interface FileUploadDataError {
fileTempId: string;
fileName: string;
fileSize: number;
fileType: string;
blobUrl: string;
blockId: string;
blockType: string;
error: unknown;
}
export interface FileRemovedData {
fileId?: string;
fileTempId?: string;
fileName: string;
blockId: string;
blockType: string;
isPending: boolean;
isPendingUploadCanceled: boolean;
}
export interface FileRemovedDataError {
fileId?: string;
fileTempId?: string;
fileName: string;
blockId: string;
blockType: string;
error: unknown;
}
export interface FileInvalidTypeError {
fileTempId: string;
fileName: string;
fileType: string;
allowedTypes: string[];
blockId: string;
blockType: string;
}
export interface FileMaxSizeExceededError {
fileTempId: string;
fileName: string;
fileSize: number;
maxAllowedSize: number;
blockId: string;
blockType: string;
}
export interface EditorToggleMode {
readOnly: boolean;
}
export interface EditorSavingData {
saveId: string;
totalBlocks: number;
startTime: number;
content: EditorContent;
}
export interface EditorSavedData {
saveId: string;
duration: number;
blocksCount: number;
success: boolean;
oldContent?: EditorContent;
newContent?: EditorContent;
}
export interface EditorSaveErrorData {
saveId: string;
error: string | string[];
blocksCount: number;
content: EditorContent;
}
export interface EditorLoadedData {
blocksCount: number;
version: string;
}
export interface EditorFocusData {
blockId?: string;
}
export interface EditorBlurData {
blockId?: string;
}
export interface ErrorOccurredData {
error: string;
context?: string;
blockId?: string;
}
export interface UserUndoData {
action: string;
affectedBlocks: string[];
}
export interface UserRedoData {
action: string;
affectedBlocks: string[];
}
export interface UserCopyData {
blockIds: string[];
content: any;
}
export interface UserPasteData {
blockIds: string[];
position: number;
content: any;
}
export type EditorEventData = BlockCreatedData | BlockMovedData | BlockDeletedData | BlockUpdatedData | BlockSelectedData | BlockDeselectedData | EditorSavingData | EditorSavedData | EditorSaveErrorData | EditorLoadedData | EditorFocusData | EditorBlurData | ErrorOccurredData | UserUndoData | UserRedoData | UserCopyData | UserPasteData | EditorToggleMode | FileUploadedData | FileUploadDataError | FileRemovedData | FileRemovedDataError | FileInvalidTypeError | FileMaxSizeExceededError;