mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
type: update upload fileList type (#40585)
This commit is contained in:
parent
e5c4bbc693
commit
2b29093c52
@ -15,9 +15,9 @@ export function file2Obj(file: RcFile): InternalUploadFile {
|
||||
}
|
||||
|
||||
/** Upload fileList. Replace file if exist or just push into it. */
|
||||
export function updateFileList(file: UploadFile<any>, fileList: UploadFile<any>[]) {
|
||||
export function updateFileList(file: UploadFile, fileList: (UploadFile | Readonly<UploadFile>)[]) {
|
||||
const nextFileList = [...fileList];
|
||||
const fileIndex = nextFileList.findIndex(({ uid }: UploadFile) => uid === file.uid);
|
||||
const fileIndex = nextFileList.findIndex(({ uid }) => uid === file.uid);
|
||||
if (fileIndex === -1) {
|
||||
nextFileList.push(file);
|
||||
} else {
|
||||
@ -26,12 +26,12 @@ export function updateFileList(file: UploadFile<any>, fileList: UploadFile<any>[
|
||||
return nextFileList;
|
||||
}
|
||||
|
||||
export function getFileItem(file: RcFile, fileList: UploadFile[]) {
|
||||
export function getFileItem(file: RcFile, fileList: (UploadFile | Readonly<UploadFile>)[]) {
|
||||
const matchKey = file.uid !== undefined ? 'uid' : 'name';
|
||||
return fileList.filter((item) => item[matchKey] === file[matchKey])[0];
|
||||
}
|
||||
|
||||
export function removeFileItem(file: UploadFile, fileList: UploadFile[]) {
|
||||
export function removeFileItem(file: UploadFile, fileList: (UploadFile | Readonly<UploadFile>)[]) {
|
||||
const matchKey = file.uid !== undefined ? 'uid' : 'name';
|
||||
const removed = fileList.filter((item) => item[matchKey] !== file[matchKey]);
|
||||
if (removed.length === fileList.length) {
|
||||
@ -74,6 +74,7 @@ export const isImageUrl = (file: UploadFile): boolean => {
|
||||
};
|
||||
|
||||
const MEASURE_SIZE = 200;
|
||||
|
||||
export function previewImage(file: File | Blob): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
if (!file.type || !isImageFileType(file.type)) {
|
||||
|
Loading…
Reference in New Issue
Block a user