UNPKG

upup-react-file-uploader

Version:
256 lines (252 loc) 8.9 kB
import React, { FC } from 'react'; import { T as Translations } from './en_US-17a3fdcf.mjs'; export { e as en_US } from './en_US-17a3fdcf.mjs'; declare enum UploadAdapter { INTERNAL = "INTERNAL", GOOGLE_DRIVE = "GOOGLE_DRIVE", ONE_DRIVE = "ONE_DRIVE", DROPBOX = "DROPBOX", LINK = "LINK", CAMERA = "CAMERA" } type GoogleDriveConfigs = { google_api_key: string; google_app_id: string; google_client_id: string; }; type OneDriveConfigs = { onedrive_client_id: string; redirectUri?: string; }; type DropboxConfigs = { dropbox_client_id?: string; dropbox_redirect_uri?: string; }; declare enum UpupProvider { AWS = "aws", Azure = "azure", BackBlaze = "backblaze", DigitalOcean = "digitalocean" } type MaxFileSizeObject = { size: number; unit: 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB' | 'EB' | 'ZB' | 'YB'; }; /** * Configuration for the optional image editor. * The editor is lazy-loaded at runtime; consumers must install * `react-filerobot-image-editor` and its peer deps separately. */ type ImageEditorOptions = { /** Whether the editor is enabled (default false). */ enabled?: boolean; /** * How the editor is displayed. * - "inline": overlays the editor on top of the uploader container (default) * - "modal": opens the editor in a full-screen modal dialog */ display?: 'inline' | 'modal'; /** * When to auto-open the editor after file selection. * - "never": never auto-open (user clicks Edit manually) * - "single": auto-open when exactly 1 new image is added * - "always": auto-open for every newly added image (queued sequentially) */ autoOpen?: 'never' | 'single' | 'always'; /** Output settings for the edited image. */ output?: { /** MIME type for the saved image (e.g. "image/png", "image/webp"). */ mimeType?: string; /** Quality 0–1 for lossy formats (jpeg/webp). */ quality?: number; /** Custom file name generator. Receives the original File. */ fileName?: (original: File) => string; }; /** * Filerobot tab keys to show. * @see https://github.com/nicedayfor/filerobot-image-editor#tabs */ tabs?: ('Adjust' | 'Annotate' | 'Filters' | 'Finetune' | 'Resize' | 'Watermark')[]; /** * Filerobot tool keys to show inside the Annotate tab. * @see https://github.com/nicedayfor/filerobot-image-editor#tools */ tools?: ('Crop' | 'Rotate' | 'Flip' | 'Brightness' | 'Contrast' | 'HSV' | 'Blur' | 'Text' | 'Line' | 'Rect' | 'Ellipse' | 'Polygon' | 'Pen' | 'Arrow' | 'Image')[]; /** Callback fired when the editor modal opens. */ onOpen?: (file: FileWithParams) => void; /** Callback fired when the user cancels editing. */ onCancel?: (file: FileWithParams) => void; /** Callback fired after the user saves an edit. */ onSave?: (editedFile: FileWithParams, originalFile: FileWithParams) => void; }; type UpupUploaderPropsClassNames = { fileIcon?: string; containerMini?: string; containerFull?: string; containerHeader?: string; containerCancelButton?: string; containerAddMoreButton?: string; adapterButtonList?: string; adapterButton?: string; adapterButtonIcon?: string; adapterButtonText?: string; adapterViewHeader?: string; adapterViewCancelButton?: string; adapterView?: string; driveLoading?: string; driveHeader?: string; driveLogoutButton?: string; driveSearchContainer?: string; driveSearchInput?: string; driveBody?: string; driveItemContainerDefault?: string; driveItemContainerSelected?: string; driveItemContainerInner?: string; driveItemInnerText?: string; driveFooter?: string; driveAddFilesButton?: string; driveCancelFilesButton?: string; urlInput?: string; urlFetchButton?: string; cameraPreviewContainer?: string; cameraDeleteButton?: string; cameraCaptureButton?: string; cameraRotateButton?: string; cameraAddButton?: string; fileListContainer?: string; fileListContainerInnerSingle?: string; fileListContainerInnerMultiple?: string; fileListFooter?: string; filePreviewPortal?: string; fileItemSingle?: string; fileItemMultiple?: string; fileThumbnailSingle?: string; fileThumbnailMultiple?: string; fileInfo?: string; fileName?: string; fileSize?: string; filePreviewButton?: string; fileDeleteButton?: string; uploadButton?: string; uploadDoneButton?: string; progressBarContainer?: string; progressBar?: string; progressBarInner?: string; progressBarText?: string; }; type UpupUploaderPropsIcons = { ContainerAddMoreIcon?: FC<{ className?: string; }>; FileDeleteIcon?: FC<{ className?: string; }>; CameraDeleteIcon?: FC<{ className?: string; }>; CameraCaptureIcon?: FC<{ className?: string; }>; CameraRotateIcon?: FC<{ className?: string; }>; LoaderIcon?: FC<{ className?: string; }>; }; type UpupUploaderProps = { provider: UpupProvider; tokenEndpoint: string; showSelectFolderButton?: boolean; enableAutoCorsConfig?: boolean; uploadAdapters?: UploadAdapter[]; driveConfigs?: { googleDrive?: GoogleDriveConfigs; oneDrive?: OneDriveConfigs; dropbox?: DropboxConfigs; }; shouldCompress?: boolean; accept?: string; limit?: number; allowPreview?: boolean; isProcessing?: boolean; mini?: boolean; maxFileSize?: MaxFileSizeObject; /** Optional image editor. Pass `true` for defaults or an `ImageEditorOptions` object. */ imageEditor?: boolean | ImageEditorOptions; customProps?: object; dark?: boolean; maxRetries?: number; resumable?: ResumableUploadOptions; classNames?: UpupUploaderPropsClassNames; icons?: UpupUploaderPropsIcons; /** A full locale pack (a `Translations` object, e.g. `ja_JP`). Defaults to `en_US`. */ localePack?: Translations; /** Per-key overrides that are deep-merged on top of the active locale. */ translations?: Partial<Translations>; onFilesSelected?: (files: FileWithParams[]) => void; onDoneClicked?: () => void; onPrepareFiles?: (files: FileWithParams[]) => Promise<FileWithParams[]>; onFileClick?: (file: FileWithParams) => void; onIntegrationClick?: (integrationType: string) => void; onFileUploadStart?: (file: FileWithParams) => void; onFileUploadComplete?: (file: FileWithParams, key: string) => void; onFilesUploadComplete?: (fileWithParams: FileWithParams[]) => void; onFileUploadProgress?: (file: FileWithParams, { loaded, total, percentage, }: { loaded: number; total: number; percentage: number; }) => void; onFilesUploadProgress?: (completedFiles: number, totalFiles: number) => void; onFileRemove?: (file: FileWithParams) => void; onFilesDragOver?: (files: File[]) => void; onFilesDragLeave?: (files: File[]) => void; onFilesDrop?: (files: File[]) => void; onFileTypeMismatch?: (file: File, acceptedTypes: string) => void; onError?: (errorMessage: string) => void; onWarn?: (warningMessage: string) => void; }; type FileWithParams = File & { id: string; url: string; key?: string; fileHash?: string | undefined; thumbnail?: { file: File; key?: string; }; }; type FileWithProgress = FileWithParams & { progress: number; }; /** * Options for resumable uploads. * Currently supports 'multipart' mode for S3-compatible providers. * 'tus' mode is reserved for future implementation. */ type ResumableUploadOptions = { mode: 'multipart'; /** Part size in bytes. Minimum 5 MiB, clamped automatically. */ chunkSizeBytes?: number; /** Persist upload sessions in localStorage for cross-refresh resume. Default: true */ persist?: boolean; } | { mode: 'tus'; /** Tus server endpoint (not implemented yet) */ endpoint: string; }; type UpupUploaderRef = { useUpload(): { error?: string; files: FileWithParams[]; loading: boolean; progress: number; upload(): Promise<FileWithParams[] | undefined>; resetState(): void; dynamicUpload(files: File[] | FileWithParams[]): Promise<FileWithParams[] | undefined>; setFiles(newFiles: File[]): void; dynamicallyReplaceFiles(files: File[] | FileWithParams[]): void; }; }; declare const _default: React.ForwardRefExoticComponent<UpupUploaderProps & React.RefAttributes<UpupUploaderRef>>; export { type FileWithParams, type FileWithProgress, type GoogleDriveConfigs, type ImageEditorOptions, type OneDriveConfigs, type ResumableUploadOptions, Translations, UploadAdapter, UpupProvider, _default as UpupUploader, type UpupUploaderRef };