{"version":3,"file":"upload.mjs","sources":["../../../../../../packages/components/upload/src/upload.ts"],"sourcesContent":["import { NOOP, buildProps, definePropType, mutable } from '@element-plus/utils'\nimport { ajaxUpload } from './ajax'\n\nimport type { Awaitable, Mutable } from '@element-plus/utils'\nimport type { UploadAjaxError } from './ajax'\nimport type { ExtractPublicPropTypes } from 'vue'\nimport type Upload from './upload.vue'\n\n/**\n * @deprecated Removed after 3.0.0, Use `UploadProps` instead.\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<string, string | Blob | [Blob, string]>\n  filename: string\n  file: UploadRawFile\n  headers: Headers | Record<string, string | number | null | undefined>\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<UploadFile, 'status' | 'uid'> &\n  Partial<Pick<UploadFile, 'status' | 'uid'>>\n\nexport type UploadFiles = UploadFile[]\nexport interface UploadRawFile extends File {\n  uid: number\n  isDirectory?: boolean\n}\nexport type UploadRequestHandler = (\n  options: UploadRequestOptions\n) => XMLHttpRequest | Promise<unknown>\nexport interface UploadHooks {\n  beforeUpload: (\n    rawFile: UploadRawFile\n  ) => Awaitable<void | undefined | null | boolean | File | Blob>\n  beforeRemove: (\n    uploadFile: UploadFile,\n    uploadFiles: UploadFiles\n  ) => Awaitable<boolean>\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<Record<string, any>>\n\nexport type ListType = 'text' | 'picture' | 'picture-card'\nexport type Crossorigin = 'anonymous' | 'use-credentials' | ''\n\nexport interface UploadBaseProps {\n  /**\n   * @description request URL\n   */\n  action?: string\n  /**\n   * @description request headers\n   */\n  headers?: Headers | Record<string, any>\n  /**\n   * @description set upload request method\n   */\n  method?: string\n  /**\n   * @description additions options of request\n   */\n  data?:\n    | Awaitable<UploadData>\n    | ((rawFile: UploadRawFile) => Awaitable<UploadData>)\n  /**\n   * @description whether uploading multiple files is permitted\n   */\n  multiple?: boolean\n  /**\n   * @description key name for uploaded file\n   */\n  name?: string\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?: boolean\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?: string\n  /**\n   * @description default uploaded files\n   */\n  fileList?: UploadUserFile[]\n  /**\n   * @description whether to auto upload file\n   */\n  autoUpload?: boolean\n  /**\n   * @description type of file list\n   */\n  listType?: ListType\n  /**\n   * @description override default xhr behavior, allowing you to implement your own upload-file's request\n   */\n  httpRequest?: UploadRequestHandler\n  /**\n   * @description whether to disable upload\n   */\n  disabled?: boolean\n  /**\n   * @description maximum number of uploads allowed\n   */\n  limit?: number\n  /**\n   * @description whether to support uploading directory\n   */\n  directory?: boolean\n}\n\nexport interface UploadProps extends 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?: UploadHooks['beforeUpload']\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?: UploadHooks['beforeRemove']\n  /**\n   * @description hook function when files are removed\n   */\n  onRemove?: UploadHooks['onRemove']\n  /**\n   * @description hook function when select file or upload file success or upload file fail\n   */\n  onChange?: UploadHooks['onChange']\n  /**\n   * @description hook function when clicking the uploaded files\n   */\n  onPreview?: UploadHooks['onPreview']\n  /**\n   * @description hook function when uploaded successfully\n   */\n  onSuccess?: UploadHooks['onSuccess']\n  /**\n   * @description hook function when some progress occurs\n   */\n  onProgress?: UploadHooks['onProgress']\n  /**\n   * @description hook function when some errors occurs\n   */\n  onError?: UploadHooks['onError']\n  /**\n   * @description hook function when limit is exceeded\n   */\n  onExceed?: UploadHooks['onExceed']\n  /**\n   * @description set HTML attribute: crossorigin.\n   */\n  crossorigin?: Crossorigin\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `UploadBaseProps` instead.\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<Headers | Record<string, any>>(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<UploadData>\n      | ((rawFile: UploadRawFile) => Awaitable<UploadData>)\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<UploadUserFile[]>(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<UploadRequestHandler>(Function),\n    default: ajaxUpload,\n  },\n  /**\n   * @description whether to disable upload\n   */\n  disabled: {\n    type: Boolean,\n    default: undefined,\n  },\n  /**\n   * @description maximum number of uploads allowed\n   */\n  limit: Number,\n  /**\n   * @description whether to support uploading directory\n   */\n  directory: Boolean,\n} as const)\n\n/**\n * @deprecated Removed after 3.0.0, Use `UploadProps` instead.\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<UploadHooks['beforeUpload']>(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<UploadHooks['beforeRemove']>(Function),\n  },\n  /**\n   * @description hook function when files are removed\n   */\n  onRemove: {\n    type: definePropType<UploadHooks['onRemove']>(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<UploadHooks['onChange']>(Function),\n    default: NOOP,\n  },\n  /**\n   * @description hook function when clicking the uploaded files\n   */\n  onPreview: {\n    type: definePropType<UploadHooks['onPreview']>(Function),\n    default: NOOP,\n  },\n  /**\n   * @description hook function when uploaded successfully\n   */\n  onSuccess: {\n    type: definePropType<UploadHooks['onSuccess']>(Function),\n    default: NOOP,\n  },\n  /**\n   * @description hook function when some progress occurs\n   */\n  onProgress: {\n    type: definePropType<UploadHooks['onProgress']>(Function),\n    default: NOOP,\n  },\n  /**\n   * @description hook function when some errors occurs\n   */\n  onError: {\n    type: definePropType<UploadHooks['onError']>(Function),\n    default: NOOP,\n  },\n  /**\n   * @description hook function when limit is exceeded\n   */\n  onExceed: {\n    type: definePropType<UploadHooks['onExceed']>(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\n/**\n * @deprecated Removed after 3.0.0, Use `UploadProps` instead.\n */\nexport type UploadPropsPublic = ExtractPublicPropTypes<typeof uploadProps>\n\nexport type UploadInstance = InstanceType<typeof Upload> & unknown\n\nexport const uploadBasePropsDefaults = {\n  action: '#',\n  method: 'post',\n  data: () => mutable({}),\n  name: 'file',\n  showFileList: true,\n  accept: '',\n  fileList: () => mutable([]),\n  autoUpload: true,\n  listType: 'text',\n  httpRequest: ajaxUpload,\n  disabled: undefined,\n} as const\n\nexport const uploadPropsDefaults = {\n  ...uploadBasePropsDefaults,\n  beforeUpload: NOOP,\n  onRemove: NOOP,\n  onChange: NOOP,\n  onPreview: NOOP,\n  onSuccess: NOOP,\n  onProgress: NOOP,\n  onError: NOOP,\n  onExceed: NOOP,\n} as const\n"],"names":[],"mappings":";;;;;AAWO,MAAM,eAAA,GAAkB,CAAC,MAAA,EAAQ,SAAA,EAAW,cAAc;AAEjE,IAAI,MAAA,GAAS,CAAA;AACN,MAAM,SAAA,GAAY,MAAM,IAAA,CAAK,GAAA,EAAI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