primevue-mirror/components/lib/fileupload/FileUpload.d.ts

634 lines
16 KiB
TypeScript
Raw Normal View History

2023-03-01 15:18:57 +00:00
/**
*
* FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.
*
* [Live Demo](https://www.primevue.org/fileupload/)
*
* @module fileupload
*
*/
2022-09-06 12:03:37 +00:00
import { VNode } from 'vue';
import { BadgePassThroughOptions } from '../badge';
2023-07-06 11:17:08 +00:00
import { ComponentHooks } from '../basecomponent';
2023-04-28 16:03:29 +00:00
import { ButtonPassThroughOptions } from '../button';
import { MessagePassThroughOptions } from '../message';
2023-09-05 08:50:46 +00:00
import { PassThroughOptions } from '../passthrough';
import { ClassComponent, GlobalComponentConstructor, PassThrough } from '../ts-helpers';
2022-09-06 12:03:37 +00:00
export declare type FileUploadPassThroughOptionType = FileUploadPassThroughAttributes | ((options: FileUploadPassThroughMethodOptions) => FileUploadPassThroughAttributes | string) | string | null | undefined;
2023-04-28 16:03:29 +00:00
/**
* Custom passthrough(pt) option method.
*/
export interface FileUploadPassThroughMethodOptions {
/**
* Defines instance.
*/
2023-07-06 12:01:33 +00:00
instance: any;
/**
* Defines valid properties.
*/
2023-04-28 16:03:29 +00:00
props: FileUploadProps;
/**
* Defines current inline state.
*/
2023-04-28 16:03:29 +00:00
state: FileUploadState;
/**
* Defines valid attributes.
*/
attrs: any;
/**
* Defines parent options.
*/
parent: any;
2023-09-05 08:50:46 +00:00
/**
* Defines passthrough(pt) options in global config.
*/
global: object | undefined;
2023-04-28 16:03:29 +00:00
}
/**
* Custom shared passthrough(pt) option method.
*/
export interface FileUploadPassThroughMethodOptions {
/**
* Defines valid properties.
*/
props: FileUploadProps;
/**
* Defines current inline state.
*/
state: FileUploadState;
}
2023-03-01 15:18:57 +00:00
/**
* Custom select event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits.select}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadSelectEvent {
/**
* Browser event.
*/
originalEvent: Event;
/**
* List of selected files.
*/
files: any;
}
2023-03-01 15:18:57 +00:00
/**
* Custom before upload event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits['before-upload']}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadBeforeUploadEvent {
/**
* XmlHttpRequest instance.
*/
xhr: XMLHttpRequest;
/**
* FormData object.
*/
formData: FormData;
}
2023-03-01 15:18:57 +00:00
/**
* Custom progress event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits.progress }
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadProgressEvent {
/**
* Browser event.
*/
originalEvent: Event;
/**
* Calculated progress value.
*/
progress: number;
}
2023-03-01 15:18:57 +00:00
/**
* Custom upload event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits.upload}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadUploadEvent {
/**
* XmlHttpRequest instance.
*/
xhr: XMLHttpRequest;
/**
* Files that are not uploaded.
*/
files: File | File[];
}
2023-03-01 15:18:57 +00:00
/**
* Custom uploader event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits.uploader}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadUploaderEvent {
/**
* List of selected files.
*/
files: File | File[];
}
2023-03-01 15:18:57 +00:00
/**
* Custom error event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits.error}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadErrorEvent {
/**
* XmlHttpRequest instance.
*/
xhr: XMLHttpRequest;
/**
* Files that are not uploaded.
*/
files: File | File[];
}
2023-03-01 15:18:57 +00:00
/**
* Custom before send event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits['before-send']}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadBeforeSendEvent {
/**
* XmlHttpRequest instance.
*/
xhr: XMLHttpRequest;
/**
* FormData object.
*/
formData: FormData;
}
2023-03-01 15:18:57 +00:00
/**
* Custom remove event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits.remove}
2023-03-01 15:18:57 +00:00
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadRemoveEvent {
/**
* Removed file.
*/
file: File;
/**
* Remaining files to be uploaded.
*/
files: File[];
}
2023-03-01 15:18:57 +00:00
/**
* Custom remove upload file event.
2023-03-06 20:35:39 +00:00
* @see {@link FileUploadEmits['remove-uploaded-file']}
2023-03-01 15:18:57 +00:00
*/
2022-12-08 11:04:25 +00:00
export interface FileUploadRemoveUploadedFile {
/**
* Removed file.
*/
file: File;
/**
* Remaining files to be uploaded.
*/
files: File[];
}
2023-04-28 16:03:29 +00:00
/**
* Custom passthrough(pt) options.
* @see {@link FileUploadProps.pt}
*/
export interface FileUploadPassThroughOptions {
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the root's DOM element.
2023-04-28 16:03:29 +00:00
*/
root?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the input's DOM element.
2023-04-28 16:03:29 +00:00
*/
input?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the buttonbar's DOM element.
2023-04-28 16:03:29 +00:00
*/
buttonbar?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the choose button's DOM element.
2023-04-28 16:03:29 +00:00
*/
2023-05-03 14:15:56 +00:00
chooseButton?: FileUploadPassThroughOptionType;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the choose icon's DOM element.
2023-04-28 16:03:29 +00:00
*/
chooseIcon?: FileUploadPassThroughOptionType;
2023-05-03 14:15:56 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the choose button label's DOM element.
2023-05-03 14:15:56 +00:00
*/
chooseButtonLabel?: FileUploadPassThroughOptionType;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the upload button's DOM element.
2023-04-28 16:05:48 +00:00
* @see {@link ButtonPassThroughOptions}
2023-04-28 16:03:29 +00:00
*/
uploadButton?: ButtonPassThroughOptions<FileUploadPassThroughMethodOptions>;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the cancel button's DOM element.
2023-04-28 16:05:48 +00:00
* @see {@link ButtonPassThroughOptions}
2023-04-28 16:03:29 +00:00
*/
cancelButton?: ButtonPassThroughOptions<FileUploadPassThroughMethodOptions>;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the content's DOM element.
2023-04-28 16:03:29 +00:00
*/
content?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the progressbar's DOM element.
2023-04-28 16:03:29 +00:00
*/
progressbar?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the messages' DOM element.
2023-04-28 16:05:48 +00:00
* @see {@link MessagePassThroughOptions}
2023-04-28 16:03:29 +00:00
*/
message?: MessagePassThroughOptions<FileUploadPassThroughMethodOptions>;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the file's DOM element.
2023-04-28 16:03:29 +00:00
*/
file?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the thumbnail's DOM element.
2023-04-28 16:03:29 +00:00
*/
thumbnail?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the details's DOM element.
2023-04-28 16:03:29 +00:00
*/
details?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the fileName's DOM element.
2023-04-28 16:03:29 +00:00
*/
fileName?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the fileSize's DOM element.
2023-04-28 16:03:29 +00:00
*/
fileSize?: FileUploadPassThroughOptionType;
/**
* Used to pass attributes to the Badge component.
* @see {@link BadgePassThroughOptions}
2023-04-28 16:03:29 +00:00
*/
badge?: BadgePassThroughOptions<FileUploadPassThroughMethodOptions>;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the actions's DOM element.
2023-04-28 16:03:29 +00:00
*/
actions?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the remove button's DOM element.
2023-04-28 16:05:48 +00:00
* @see {@link ButtonPassThroughOptions}
2023-04-28 16:03:29 +00:00
*/
removeButton?: ButtonPassThroughOptions<FileUploadPassThroughMethodOptions>;
2023-05-03 14:15:56 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the empty's DOM element.
2023-05-03 14:15:56 +00:00
*/
empty?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the label's DOM element.
2023-05-03 14:15:56 +00:00
*/
label?: FileUploadPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the upload icon's DOM element.
2023-05-03 14:15:56 +00:00
*/
uploadIcon?: FileUploadPassThroughOptionType;
2023-07-06 11:09:01 +00:00
/**
2023-11-07 06:16:39 +00:00
* Used to manage all lifecycle hooks.
2023-07-06 11:09:01 +00:00
* @see {@link BaseComponent.ComponentHooks}
*/
hooks?: ComponentHooks;
2023-04-28 16:03:29 +00:00
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface FileUploadPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in FileUpload component.
*/
export interface FileUploadState {
/**
* Current uploaded file count state as a number.
* @defaultValue 0
*/
uploadedFileCount: number;
/**
* Current files.
*/
files: any[];
/**
* Current messages.
*/
messages: any[];
/**
* Current progress state as a number.
*/
progress: number;
/**
* Current uploaded files.
*/
uploadedFiles: any[];
}
2023-03-01 15:18:57 +00:00
/**
* Defines valid properties in FileUpload component.
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadProps {
/**
* Name of the request parameter to identify the files at backend.
*/
name?: string | undefined;
/**
* Remote url to upload the files.
*/
url?: string | undefined;
/**
* Defines the UI of the component, possible values are 'advanced' and 'basic'.
2023-03-08 10:51:52 +00:00
* @defaultValue advanced
2022-09-06 12:03:37 +00:00
*/
2023-03-01 15:18:57 +00:00
mode?: 'advanced' | 'basic' | undefined;
2022-09-06 12:03:37 +00:00
/**
* Used to select multiple files at once from file dialog.
2023-03-01 15:18:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
multiple?: boolean | undefined;
/**
* Pattern to restrict the allowed file types such as 'image/*'.
*/
accept?: string | undefined;
/**
* Disables the upload functionality.
2023-03-01 15:18:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
disabled?: boolean | undefined;
/**
* When enabled, upload begins automatically after selection is completed.
2023-03-01 15:18:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
auto?: boolean | undefined;
/**
* Maximum file size allowed in bytes.
*/
maxFileSize?: number | undefined;
/**
* Message of the invalid fize size.
2023-03-08 10:51:52 +00:00
* @defaultValue {0}: Invalid file size, file size should be smaller than {1.}
2022-09-06 12:03:37 +00:00
*/
invalidFileSizeMessage?: string | undefined;
/**
* Message to display when number of files to be uploaded exceeeds the limit.
2023-03-08 10:51:52 +00:00
* @defaultValue Maximum number of files to be uploaded is {0.}
2022-09-06 12:03:37 +00:00
*/
invalidFileLimitMessage?: string | undefined;
/**
* Message of the invalid fize type.
2023-03-08 11:02:08 +00:00
* @defaultValue '{0}: Invalid file type.'
2022-09-06 12:03:37 +00:00
*/
invalidFileTypeMessage?: string | undefined;
/**
* Maximum number of files that can be uploaded.
*/
fileLimit?: number | undefined;
/**
* Cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
2023-03-01 15:18:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
withCredentials?: boolean | undefined;
/**
* Width of the image thumbnail in pixels.
2023-03-01 15:18:57 +00:00
* @defaultValue 50
2022-09-06 12:03:37 +00:00
*/
previewWidth?: number | undefined;
/**
* Label of the choose button. Defaults to PrimeVue Locale configuration.
*/
chooseLabel?: string | undefined;
/**
* Label of the upload button. Defaults to PrimeVue Locale configuration.
*/
uploadLabel?: string | undefined;
/**
* Label of the cancel button. Defaults to PrimeVue Locale configuration.
2023-03-01 15:18:57 +00:00
* @defaultValue Cancel
2022-09-06 12:03:37 +00:00
*/
cancelLabel?: string | undefined;
/**
* Whether to use the default upload or a manual implementation defined in uploadHandler callback. Defaults to PrimeVue Locale configuration.
*/
customUpload?: boolean | undefined;
/**
* Whether to show the upload button.
2023-03-01 15:18:57 +00:00
* @defaultValue true
2022-09-06 12:03:37 +00:00
*/
showUploadButton?: boolean | undefined;
/**
* Whether to show the cancel button.
2023-03-01 15:18:57 +00:00
* @defaultValue true
2022-09-06 12:03:37 +00:00
*/
showCancelButton?: boolean | undefined;
/**
* Icon of the choose button.
* @deprecated since v3.27.0. Use 'chooseicon' slot.
2022-09-06 12:03:37 +00:00
*/
chooseIcon?: string | undefined;
/**
* Icon of the upload button.
* @deprecated since v3.27.0. Use 'updateicon' slot.
2022-09-06 12:03:37 +00:00
*/
uploadIcon?: string | undefined;
/**
* Icon of the cancel button.
* @deprecated since v3.27.0. Use 'cancelicon' slot.
2022-09-06 12:03:37 +00:00
*/
cancelIcon?: string | undefined;
/**
* Inline style of the component.
*/
style?: any;
/**
* Style class of the component.
*/
class?: any;
2023-04-28 16:03:29 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to DOM elements inside the component.
2023-04-28 16:03:29 +00:00
* @type {FileUploadPassThroughOptions}
*/
pt?: PassThrough<FileUploadPassThroughOptions>;
2023-09-05 08:50:46 +00:00
/**
* Used to configure passthrough(pt) options of the component.
* @type {PassThroughOptions}
*/
ptOptions?: PassThroughOptions;
2023-05-31 08:53:28 +00:00
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
2022-09-06 12:03:37 +00:00
}
2023-03-01 15:18:57 +00:00
/**
* Defines valid slots in FileUpload slots.
*/
2022-09-06 12:03:37 +00:00
export interface FileUploadSlots {
/**
2022-12-08 11:04:25 +00:00
* Custom header content template.
2023-08-17 07:16:25 +00:00
* @param {Object} scope - header slot's params.
2022-12-08 11:04:25 +00:00
*/
2023-03-01 15:18:57 +00:00
header(scope: {
2022-12-08 11:04:25 +00:00
/**
* Files to upload.
*/
files: File[];
/**
* Uploaded files.
*/
uploadedFiles: File[];
/**
* Choose function
*/
2023-08-17 07:16:25 +00:00
chooseCallback: () => void;
2022-12-08 11:04:25 +00:00
/**
* Upload function
*/
2023-08-17 07:16:25 +00:00
uploadCallback: () => void;
2022-12-08 11:04:25 +00:00
/**
* Clear function
*/
2023-08-17 07:16:25 +00:00
clearCallback: () => void;
2023-03-01 15:18:57 +00:00
}): VNode[];
2022-12-08 11:04:25 +00:00
/**
* Custom uploaded content template.
2023-08-17 07:16:25 +00:00
* @param {Object} scope - content slot's params.
2022-12-08 11:04:25 +00:00
*/
2023-03-01 15:18:57 +00:00
content(scope: {
2022-12-08 11:04:25 +00:00
/**
* Files to upload.
*/
files: File[];
/**
* Uploaded files.
*/
uploadedFiles: File[];
/**
* Function to remove an uploaded file.
2023-08-17 07:16:25 +00:00
* @param {number} index - Index of the uploaded file
2022-12-08 11:04:25 +00:00
*/
2023-08-17 07:16:25 +00:00
removeUploadedFileCallback: (index: number) => void;
2022-12-08 11:04:25 +00:00
/**
* Function to remove a file.
2023-08-17 07:16:25 +00:00
* @param {number} index - Index of the removed file
2022-12-08 11:04:25 +00:00
*/
2023-08-17 07:16:25 +00:00
removeFileCallback: (index: number) => void;
2022-12-08 11:04:25 +00:00
/**
* Uploaded progress as number.
*/
progress: number;
/**
* Status messages about upload process.
*/
messages: string | undefined;
2023-03-01 15:18:57 +00:00
}): VNode[];
2022-12-08 11:04:25 +00:00
/**
* Custom content when there is no selected file.
2022-09-06 12:03:37 +00:00
*/
2023-03-01 15:18:57 +00:00
empty(): VNode[];
/**
* Custom choose icon template.
*/
chooseicon(): VNode[];
/**
* Custom upload icon template.
*/
uploadicon(): VNode[];
/**
* Custom cancel icon template.
*/
cancelicon(): VNode[];
/**
* Custom remove icon template for each file.
2023-08-17 07:16:25 +00:00
* @param {Object} scope - fileremoveicon slot's params.
*/
fileremoveicon(scope: {
/**
* File to upload.
*/
file: File;
/**
* The index of file
*/
index: number;
}): VNode[];
2022-09-06 12:03:37 +00:00
}
2023-03-01 15:18:57 +00:00
export interface FileUploadEmits {
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when files are selected.
* @param {FileUploadSelectEvent} event - Custom select event.
*/
2023-03-01 15:18:57 +00:00
select(event: FileUploadSelectEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke before file upload begins to customize the request such as post parameters before the files.
* @param {FileUploadBeforeUploadEvent} event - Custom before upload event.
*/
2023-03-01 15:18:57 +00:00
'before-upload'(event: FileUploadBeforeUploadEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when files are being uploaded.
* @param {FileUploadProgressEvent} event - Custom progress event.
*/
2023-03-01 15:18:57 +00:00
progress(event: FileUploadProgressEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when file upload is complete.
* @param {FileUploadUploadEvent} event - Custom upload event.
*/
2023-03-01 15:18:57 +00:00
upload(event: FileUploadUploadEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke to implement a custom upload.
* @param {FileUploadUploaderEvent} event - Custom uploader event.
*/
2023-03-01 15:18:57 +00:00
uploader(event: FileUploadUploaderEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke if file upload fails.
* @param {FileUploadErrorEvent} event - Custom error event.
*/
2023-03-01 15:18:57 +00:00
error(event: FileUploadErrorEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke before file send begins to customize the request such as adding headers.
* @param {FileUploadBeforeSendEvent} event - Custom before send event.
*/
2023-03-01 15:18:57 +00:00
'before-send'(event: FileUploadBeforeSendEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when files in queue are removed without uploading.
*/
2023-03-01 15:18:57 +00:00
clear(): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when a singe file is removed from the list.
* @param {FileUploadRemoveEvent} event - Custom remove event.
*/
2023-03-01 15:18:57 +00:00
remove(event: FileUploadRemoveEvent): void;
2022-12-08 11:04:25 +00:00
/**
* Callback to invoke when a single uploaded file is removed from the uploaded file list.
* @param {FileUploadRemoveUploadedFile} event - Custom uploaded file remove event.
*/
2023-03-01 15:18:57 +00:00
removeUploadedFile(event: FileUploadRemoveUploadedFile): void;
}
2022-09-06 12:03:37 +00:00
2023-03-01 15:18:57 +00:00
/**
* **PrimeVue - FileUpload**
*
* _FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations._
*
* [Live Demo](https://www.primevue.org/fileupload/)
* --- ---
2023-03-03 10:55:20 +00:00
* ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png)
2023-03-01 15:18:57 +00:00
*
* @group Component
*
*/
2022-09-14 11:26:01 +00:00
declare class FileUpload extends ClassComponent<FileUploadProps, FileUploadSlots, FileUploadEmits> {}
2022-09-06 12:03:37 +00:00
declare module '@vue/runtime-core' {
interface GlobalComponents {
2022-09-14 11:26:01 +00:00
FileUpload: GlobalComponentConstructor<FileUpload>;
2022-09-06 12:03:37 +00:00
}
}
export default FileUpload;