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, PropType, CSSProperties } from 'vue'; 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; 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: UploadFile[]; 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: [Boolean, String] as PropType, type: String as PropType, name: String, defaultFileList: Array as PropType>>, fileList: Array as PropType>>, action: [String, Function] as PropType< string | ((file: FileType) => string) | ((file: FileType) => PromiseLike) >, directory: { type: Boolean, default: undefined }, data: [Object, Function] as PropType< | Record | ((file: UploadFile) => Record | Promise>) >, method: String as PropType<'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch'>, headers: Object as PropType, showUploadList: { type: [Boolean, Object] as PropType, default: undefined as boolean | ShowUploadListInterface, }, multiple: { type: Boolean, default: undefined }, accept: String, beforeUpload: Function as PropType< ( file: FileType, FileList: FileType[], ) => BeforeUploadValueType | Promise >, onChange: Function as PropType<(info: UploadChangeParam) => void>, 'onUpdate:fileList': Function as PropType<(fileList: UploadChangeParam['fileList']) => void>, onDrop: Function as PropType<(event: DragEvent) => void>, listType: String as PropType, onPreview: Function as PropType<(file: UploadFile) => void>, onDownload: Function as PropType<(file: UploadFile) => void>, onReject: Function as PropType<(fileList: FileType[]) => void>, onRemove: Function as PropType< (file: UploadFile) => void | boolean | Promise >, /** @deprecated Please use `onRemove` directly */ remove: Function as PropType<(file: UploadFile) => void | boolean | Promise>, supportServerRender: { type: Boolean, default: undefined }, disabled: { type: Boolean, default: undefined }, prefixCls: String, customRequest: Function as PropType<(options: RcCustomRequestOptions) => void>, withCredentials: { type: Boolean, default: undefined }, openFileDialogOnClick: { type: Boolean, default: undefined }, locale: { type: Object as PropType, default: undefined as UploadLocale }, id: String, previewFile: Function as PropType, /** @deprecated Please use `beforeUpload` directly */ transformFile: Function as PropType, iconRender: Function as PropType< (opt: { file: UploadFile; listType?: UploadListType }) => VueNode >, isImageUrl: Function as PropType<(file: UploadFile) => boolean>, progress: Object as PropType, itemRender: Function as PropType>, /** Config max count of `fileList`. Will replace current one when `maxCount` is 1 */ maxCount: Number, height: [Number, String], removeIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>, downloadIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>, previewIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>, }; } export type UploadProps = Partial>>; export interface UploadState { fileList: UploadFile[]; dragState: string; } function uploadListProps() { return { listType: String as PropType, onPreview: Function as PropType<(file: UploadFile) => void>, onDownload: Function as PropType<(file: UploadFile) => void>, onRemove: Function as PropType<(file: UploadFile) => void | boolean>, items: Array as PropType>>, progress: Object as PropType, prefixCls: String as PropType, showRemoveIcon: { type: Boolean, default: undefined }, showDownloadIcon: { type: Boolean, default: undefined }, showPreviewIcon: { type: Boolean, default: undefined }, removeIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>, downloadIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>, previewIcon: Function as PropType<(opt: { file: UploadFile }) => VueNode>, locale: { type: Object as PropType, default: undefined as UploadLocale }, previewFile: Function as PropType, iconRender: Function as PropType< (opt: { file: UploadFile; listType?: UploadListType }) => VueNode >, isImageUrl: Function as PropType<(file: UploadFile) => boolean>, appendAction: Function as PropType<() => VueNode>, itemRender: Function as PropType>, }; } export type UploadListProps = Partial>>; export { uploadProps, uploadListProps };