forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.tsx
executable file
·194 lines (178 loc) · 6.62 KB
/
interface.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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<T = any> {
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<T = any> extends UploadFile<T> {
originFileObj: FileType;
}
export interface ShowUploadListInterface {
showRemoveIcon?: boolean;
showPreviewIcon?: boolean;
showDownloadIcon?: boolean;
}
export interface UploadChangeParam<T = UploadFile> {
// 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<ProgressProps, 'percent' | 'type'> & {
class?: string;
style?: CSSProperties;
};
export type ItemRender<T = any> = (opt: {
originNode: VueNode;
file: UploadFile;
fileList: Array<UploadFile<T>>;
actions: {
download: () => void;
preview: () => void;
remove: () => void;
};
}) => VueNode;
type PreviewFileHandler = (file: FileType | Blob) => PromiseLike<string>;
type TransformFileHandler = (
file: FileType,
) => string | Blob | FileType | PromiseLike<string | Blob | FileType>;
type BeforeUploadValueType = void | boolean | string | Blob | FileType;
function uploadProps<T = any>() {
return {
capture: someType<boolean | 'user' | 'environment'>([Boolean, String]),
type: stringType<UploadType>(),
name: String,
defaultFileList: arrayType<Array<UploadFile<T>>>(),
fileList: arrayType<Array<UploadFile<T>>>(),
action: someType<
string | ((file: FileType) => string) | ((file: FileType) => PromiseLike<string>)
>([String, Function]),
directory: booleanType(),
data: someType<
| Record<string, unknown>
| ((file: UploadFile<T>) => Record<string, unknown> | Promise<Record<string, unknown>>)
>([Object, Function]),
method: stringType<'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch'>(),
headers: objectType<HttpRequestHeader>(),
showUploadList: someType<boolean | ShowUploadListInterface>([Boolean, Object]),
multiple: booleanType(),
accept: String,
beforeUpload:
functionType<
(
file: FileType,
FileList: FileType[],
) => BeforeUploadValueType | Promise<BeforeUploadValueType>
>(),
onChange: functionType<(info: UploadChangeParam<UploadFile<T>>) => void>(),
'onUpdate:fileList':
functionType<(fileList: UploadChangeParam<UploadFile<T>>['fileList']) => void>(),
onDrop: functionType<(event: DragEvent) => void>(),
listType: stringType<UploadListType>(),
onPreview: functionType<(file: UploadFile<T>) => void>(),
onDownload: functionType<(file: UploadFile<T>) => void>(),
onReject: functionType<(fileList: FileType[]) => void>(),
onRemove: functionType<(file: UploadFile<T>) => void | boolean | Promise<void | boolean>>(),
/** @deprecated Please use `onRemove` directly */
remove: functionType<(file: UploadFile<T>) => void | boolean | Promise<void | boolean>>(),
supportServerRender: booleanType(),
disabled: booleanType(),
prefixCls: String,
customRequest: functionType<(options: RcCustomRequestOptions) => void>(),
withCredentials: booleanType(),
openFileDialogOnClick: booleanType(),
locale: objectType<UploadLocale>(),
id: String,
previewFile: functionType<PreviewFileHandler>(),
/** @deprecated Please use `beforeUpload` directly */
transformFile: functionType<TransformFileHandler>(),
iconRender:
functionType<(opt: { file: UploadFile<T>; listType?: UploadListType }) => VueNode>(),
isImageUrl: functionType<(file: UploadFile) => boolean>(),
progress: objectType<UploadListProgressProps>(),
itemRender: functionType<ItemRender<T>>(),
/** 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<ExtractPropTypes<ReturnType<typeof uploadProps>>>;
export interface UploadState<T = any> {
fileList: UploadFile<T>[];
dragState: string;
}
function uploadListProps<T = any>() {
return {
listType: stringType<UploadListType>(),
onPreview: functionType<(file: UploadFile<T>) => void>(),
onDownload: functionType<(file: UploadFile<T>) => void>(),
onRemove: functionType<(file: UploadFile<T>) => void | boolean>(),
items: arrayType<Array<UploadFile<T>>>(),
progress: objectType<UploadListProgressProps>(),
prefixCls: stringType<string>(),
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<UploadLocale>(undefined as UploadLocale),
previewFile: functionType<PreviewFileHandler>(),
iconRender:
functionType<(opt: { file: UploadFile<T>; listType?: UploadListType }) => VueNode>(),
isImageUrl: functionType<(file: UploadFile) => boolean>(),
appendAction: functionType<() => VueNode>(),
appendActionVisible: booleanType(),
itemRender: functionType<ItemRender<T>>(),
};
}
export type UploadListProps = Partial<ExtractPropTypes<ReturnType<typeof uploadListProps>>>;
export { uploadProps, uploadListProps };