import type { DragEvent as ReactDragEvent } from 'react'; import type { FileInsertHandler, MediaStatus, MediaUploadOptions } from '@rtif-sdk/web'; import type { EditorHandle } from './use-editor.js'; /** * Options for {@link useMediaUpload}. Same as the web * {@link MediaUploadOptions}, but `accept` is an HTML-`accept` string (used both * as the file-picker filter and to reject non-matching dropped/picked files); * the hook supplies `onStatusChange` itself to track per-block state. * * **Create-time config:** like `useEditor`, the upload options are read once * when the hook first runs (the returned `handler` must be stable to pass to * `useEditor`). `retry` reads the latest `onUpload`/`onError`; everything else * is captured on first render. */ export interface UseMediaUploadOptions extends Omit { /** HTML `accept` string for the picker and the file filter (e.g. `'image/*,.pdf'`). */ readonly accept?: string; /** * Whether to wire uploads (default true). When false the hook registers no * handler and `openPicker`/drop are inert — useful in a shared wrapper that * always calls the hook but enables media only for some editors. Requires the * matching media block feature(s) to be registered when enabled. */ readonly enabled?: boolean; } /** One tracked upload's live state, for rendering progress / a retry button. */ export interface MediaUploadState { readonly blockId: string; readonly file: File; readonly status: MediaStatus; readonly error?: Error; } /** Drag handlers to spread onto an optional larger drop target around the editor. */ export interface MediaDropZoneProps { onDragOver(event: ReactDragEvent): void; onDragEnter(event: ReactDragEvent): void; onDragLeave(event: ReactDragEvent): void; onDrop(event: ReactDragEvent): void; } /** What {@link useMediaUpload} returns. */ export interface MediaUploadApi { /** Pass to `useEditor({ media: { handleFiles } })` so editor paste/drop uploads. */ readonly handler: FileInsertHandler; /** Open a file dialog and upload the chosen files (toolbar "insert" button). */ openPicker(): void; /** Props for an optional drop zone (the editor already handles its own drop). */ getDropZoneProps(): MediaDropZoneProps; /** Whether a drag is currently over the drop zone. */ readonly isDragging: boolean; /** Live per-block upload states (for spinners, error/retry UI). */ readonly uploads: readonly MediaUploadState[]; /** Re-run a failed (or any tracked) upload by block id. */ retry(blockId: string): void; } /** * Headless media uploads for React (architecture §5.2). Wraps * `createMediaUploadHandler` and tracks per-block upload state so a component * can render spinners, errors, and a retry button. Three input paths share one * pipeline: the editor's own paste/drop (via the returned `handler` passed to * `useEditor`), a toolbar `openPicker()`, and an optional `getDropZoneProps()` * target. * * @param editor - The handle from {@link useEditor}. * @param options - Upload function plus UX/validation hooks. * @returns The {@link MediaUploadApi}. * * @example * ```tsx * const media = useMediaUpload(editor, { accept: 'image/*', onUpload }); * const editor = useEditor({ media: { handleFiles: media.handler } }); * * ``` */ export declare function useMediaUpload(editor: EditorHandle, options: UseMediaUploadOptions): MediaUploadApi; //# sourceMappingURL=use-media-upload.d.ts.map