import type { RcFile as OriRcFile, UploadRequestOption as RcCustomRequestOptions, } from '../vc-upload/interface'; import type { ProgressProps } from '../progress'; import type { VueNode } from '../_util/type'; import type { ExtractPropTypes, CSSProperties, ImgHTMLAttributes } from 'vue'; import { booleanType, stringType, functionType, arrayType, objectType, someType, } from '../_util/type'; export interface FileType extends OriRcFile { readonly lastModifiedDate: Date; } export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading' | 'removed'; export interface HttpRequestHeader { [key: string]: string; } export interface UploadFile { uid: string; size?: number; name: string; fileName?: string; lastModified?: number; lastModifiedDate?: Date; url?: string; status?: UploadFileStatus; percent?: number; thumbUrl?: string; crossOrigin?: ImgHTMLAttributes['crossorigin']; originFileObj?: FileType; response?: T; error?: any; linkProps?: any; type?: string; xhr?: T; preview?: string; } export interface InternalUploadFile extends UploadFile { originFileObj: FileType; } export interface ShowUploadListInterface { showRemoveIcon?: boolean; showPreviewIcon?: boolean; showDownloadIcon?: boolean; } export interface UploadChangeParam { // https://github.com/ant-design/ant-design/issues/14420 file: T; fileList: T[]; event?: { percent: number }; } export interface UploadLocale { uploading?: string; removeFile?: string; downloadFile?: string; uploadError?: string; previewFile?: string; } export type UploadType = 'drag' | 'select'; export type UploadListType = 'text' | 'picture' | 'picture-card'; export type UploadListProgressProps = Omit & { class?: string; style?: CSSProperties; }; export type ItemRender = (opt: { originNode: VueNode; file: UploadFile; fileList: Array>; actions: { download: () => void; preview: () => void; remove: () => void; }; }) => VueNode; type PreviewFileHandler = (file: FileType | Blob) => PromiseLike; type TransformFileHandler = ( file: FileType, ) => string | Blob | FileType | PromiseLike; type BeforeUploadValueType = void | boolean | string | Blob | FileType; function uploadProps() { return { capture: someType([Boolean, String]), type: stringType(), name: String, defaultFileList: arrayType>>(), fileList: arrayType>>(), action: someType< string | ((file: FileType) => string) | ((file: FileType) => PromiseLike) >([String, Function]), directory: booleanType(), data: someType< | Record | ((file: UploadFile) => Record | Promise>) >([Object, Function]), method: stringType<'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch'>(), headers: objectType(), showUploadList: someType([Boolean, Object]), multiple: booleanType(), accept: String, beforeUpload: functionType< ( file: FileType, FileList: FileType[], ) => BeforeUploadValueType | Promise >(), onChange: functionType<(info: UploadChangeParam>) => void>(), 'onUpdate:fileList': functionType<(fileList: UploadChangeParam>['fileList']) => void>(), onDrop: functionType<(event: DragEvent) => void>(), listType: stringType(), onPreview: functionType<(file: UploadFile) => void>(), onDownload: functionType<(file: UploadFile) => void>(), onReject: functionType<(fileList: FileType[]) => void>(), onRemove: functionType<(file: UploadFile) => void | boolean | Promise>(), /** @deprecated Please use `onRemove` directly */ remove: functionType<(file: UploadFile) => void | boolean | Promise>(), supportServerRender: booleanType(), disabled: booleanType(), prefixCls: String, customRequest: functionType<(options: RcCustomRequestOptions) => void>(), withCredentials: booleanType(), openFileDialogOnClick: booleanType(), locale: objectType(), id: String, previewFile: functionType(), /** @deprecated Please use `beforeUpload` directly */ transformFile: functionType(), iconRender: functionType<(opt: { file: UploadFile; listType?: UploadListType }) => VueNode>(), isImageUrl: functionType<(file: UploadFile) => boolean>(), progress: objectType(), itemRender: functionType>(), /** Config max count of `fileList`. Will replace current one when `maxCount` is 1 */ maxCount: Number, height: someType([Number, String]), removeIcon: functionType<(opt: { file: UploadFile }) => VueNode>(), downloadIcon: functionType<(opt: { file: UploadFile }) => VueNode>(), previewIcon: functionType<(opt: { file: UploadFile }) => VueNode>(), }; } export type UploadProps = Partial>>; export interface UploadState { fileList: UploadFile[]; dragState: string; } function uploadListProps() { return { listType: stringType(), onPreview: functionType<(file: UploadFile) => void>(), onDownload: functionType<(file: UploadFile) => void>(), onRemove: functionType<(file: UploadFile) => void | boolean>(), items: arrayType>>(), progress: objectType(), prefixCls: stringType(), showRemoveIcon: booleanType(), showDownloadIcon: booleanType(), showPreviewIcon: booleanType(), removeIcon: functionType<(opt: { file: UploadFile }) => VueNode>(), downloadIcon: functionType<(opt: { file: UploadFile }) => VueNode>(), previewIcon: functionType<(opt: { file: UploadFile }) => VueNode>(), locale: objectType(undefined as UploadLocale), previewFile: functionType(), iconRender: functionType<(opt: { file: UploadFile; listType?: UploadListType }) => VueNode>(), isImageUrl: functionType<(file: UploadFile) => boolean>(), appendAction: functionType<() => VueNode>(), appendActionVisible: booleanType(), itemRender: functionType>(), }; } export type UploadListProps = Partial>>; export { uploadProps, uploadListProps };