{"version":3,"file":"upload.js","sources":["../../../../../../packages/components/upload/src/upload.ts"],"sourcesContent":["import { NOOP, buildProps, definePropType, mutable } from '@element-plus/utils'\nimport { ajaxUpload } from './ajax'\nimport type { Awaitable, Mutable } from '@element-plus/utils'\n\nimport type { UploadAjaxError } from './ajax'\nimport type { ExtractPropTypes } from 'vue'\nimport type Upload from './upload.vue'\n\nexport const uploadListTypes = ['text', 'picture', 'picture-card'] as const\n\nlet fileId = 1\nexport const genFileId = () => Date.now() + fileId++\n\nexport type UploadStatus = 'ready' | 'uploading' | 'success' | 'fail'\nexport interface UploadProgressEvent extends ProgressEvent {\n percent: number\n}\n\nexport interface UploadRequestOptions {\n action: string\n method: string\n data: Record\n filename: string\n file: UploadRawFile\n headers: Headers | Record\n onError: (evt: UploadAjaxError) => void\n onProgress: (evt: UploadProgressEvent) => void\n onSuccess: (response: any) => void\n withCredentials: boolean\n}\nexport interface UploadFile {\n name: string\n percentage?: number\n status: UploadStatus\n size?: number\n response?: unknown\n uid: number\n url?: string\n raw?: UploadRawFile\n}\nexport type UploadUserFile = Omit &\n Partial>\n\nexport type UploadFiles = UploadFile[]\nexport interface UploadRawFile extends File {\n uid: number\n}\nexport type UploadRequestHandler = (\n options: UploadRequestOptions\n) => XMLHttpRequest | Promise\nexport interface UploadHooks {\n beforeUpload: (\n rawFile: UploadRawFile\n ) => Awaitable\n beforeRemove: (\n uploadFile: UploadFile,\n uploadFiles: UploadFiles\n ) => Awaitable\n onRemove: (uploadFile: UploadFile, uploadFiles: UploadFiles) => void\n onChange: (uploadFile: UploadFile, uploadFiles: UploadFiles) => void\n onPreview: (uploadFile: UploadFile) => void\n onSuccess: (\n response: any,\n uploadFile: UploadFile,\n uploadFiles: UploadFiles\n ) => void\n onProgress: (\n evt: UploadProgressEvent,\n uploadFile: UploadFile,\n uploadFiles: UploadFiles\n ) => void\n onError: (\n error: Error,\n uploadFile: UploadFile,\n uploadFiles: UploadFiles\n ) => void\n onExceed: (files: File[], uploadFiles: UploadUserFile[]) => void\n}\n\nexport type UploadData = Mutable>\n\nexport const uploadBaseProps = buildProps({\n /**\n * @description request URL\n */\n action: {\n type: String,\n default: '#',\n },\n /**\n * @description request headers\n */\n headers: {\n type: definePropType>(Object),\n },\n /**\n * @description set upload request method\n */\n method: {\n type: String,\n default: 'post',\n },\n /**\n * @description additions options of request\n */\n data: {\n type: definePropType<\n | Awaitable\n | ((rawFile: UploadRawFile) => Awaitable)\n >([Object, Function, Promise]),\n default: () => mutable({} as const),\n },\n /**\n * @description whether uploading multiple files is permitted\n */\n multiple: Boolean,\n /**\n * @description key name for uploaded file\n */\n name: {\n type: String,\n default: 'file',\n },\n /**\n * @description whether to activate drag and drop mode\n */\n drag: Boolean,\n /**\n * @description whether cookies are sent\n */\n withCredentials: Boolean,\n /**\n * @description whether to show the uploaded file list\n */\n showFileList: {\n type: Boolean,\n default: true,\n },\n /**\n * @description accepted [file types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept), will not work when `thumbnail-mode === true`\n */\n accept: {\n type: String,\n default: '',\n },\n /**\n * @description default uploaded files\n */\n fileList: {\n type: definePropType(Array),\n default: () => mutable([] as const),\n },\n /**\n * @description whether to auto upload file\n */\n autoUpload: {\n type: Boolean,\n default: true,\n },\n /**\n * @description type of file list\n */\n listType: {\n type: String,\n values: uploadListTypes,\n default: 'text',\n },\n /**\n * @description override default xhr behavior, allowing you to implement your own upload-file's request\n */\n httpRequest: {\n type: definePropType(Function),\n default: ajaxUpload,\n },\n /**\n * @description whether to disable upload\n */\n disabled: Boolean,\n /**\n * @description maximum number of uploads allowed\n */\n limit: Number,\n} as const)\n\nexport const uploadProps = buildProps({\n ...uploadBaseProps,\n /**\n * @description hook function before uploading with the file to be uploaded as its parameter. If `false` is returned or a `Promise` is returned and then is rejected, uploading will be aborted\n */\n beforeUpload: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function before removing a file with the file and file list as its parameters. If `false` is returned or a `Promise` is returned and then is rejected, removing will be aborted\n */\n beforeRemove: {\n type: definePropType(Function),\n },\n /**\n * @description hook function when files are removed\n */\n onRemove: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function when select file or upload file success or upload file fail\n */\n onChange: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function when clicking the uploaded files\n */\n onPreview: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function when uploaded successfully\n */\n onSuccess: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function when some progress occurs\n */\n onProgress: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function when some errors occurs\n */\n onError: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description hook function when limit is exceeded\n */\n onExceed: {\n type: definePropType(Function),\n default: NOOP,\n },\n /**\n * @description set HTML attribute: crossorigin.\n */\n crossorigin: {\n type: definePropType<'anonymous' | 'use-credentials' | ''>(String),\n },\n} as const)\n\nexport type UploadProps = ExtractPropTypes\n\nexport type UploadInstance = InstanceType\n"],"names":["buildProps","definePropType","mutable","ajaxUpload","NOOP"],"mappings":";;;;;;;;;;AAEY,MAAC,eAAe,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE;AACnE,IAAI,MAAM,GAAG,CAAC,CAAC;AACH,MAAC,SAAS,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,GAAG;AACzC,MAAC,eAAe,GAAGA,kBAAU,CAAC;AAC1C,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,GAAG;AAChB,GAAG;AACH,EAAE,OAAO,EAAE;AACX,IAAI,IAAI,EAAEC,sBAAc,CAAC,MAAM,CAAC;AAChC,GAAG;AACH,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,MAAM;AACnB,GAAG;AACH,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EA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