import { EventEmitter } from "../../stencil-public-runtime"; import { FormComponent, ThemeableComponent } from "../../common"; import { DuetHeadingLevel, DuetMargin, DuetTheme, StatusMessage } from "../../common-types"; import { DuetLangObject } from "../../utils/language-utils"; import { DuetEditableTableActions } from "../duet-editable-table/duet-editable-table"; import { UploadActionButtonTitles } from "../duet-upload-item/duet-upload-item"; import { DuetUploadErrorCode } from "./errorcodes.utils"; import { DuetXhrRequest, DuetXhrRequestOptions, failureHandler, progressTracker, successHandler } from "./xhr.helpers"; export type DuetUploadEvent = { originalEvent?: Event; data?: Record; metaData?: Record; component: "duet-upload"; }; export type DuetFileListItem = { uid: string; item: File | null; size: number; meta?: Record; uploaded: boolean; error: DuetUploadErrorCode; progress: number; deleted: boolean; valid: boolean; xhr: DuetXhrRequest | false; url: string | false; group?: string; html?: string; status?: number; pending?: boolean | undefined; }; export type DuetUploadQueueItem = { uid: string; item: File; name: string; metadata: string; }; export type XHRMiddlewareOptions = { payload: Record; options: Partial; onFailure: failureHandler; onSuccess: successHandler; onProgress: progressTracker; }; export type XHRInternalMiddleWare = (XHRMiddlewareOptions: any) => XHRMiddlewareOptions; export interface StringMap { [key: string]: any; } export type DuetUploadTableGroupName = { id: string; label: DuetLangObject; actionLabel?: DuetLangObject; }; /** * @slot header - named slot - to place content after description / caption (if caption is on top) * @slot fileheader - named slot - to place content above "filelist" (only displayed when "filelist" contains items) * @slot filefooter - named slot - to place content below "filelist" (only displayed when "filelist" contains items) * @slot uploadfooter - named slot - to place content below filefooter * @slot afterfooter - named slot - to place content below "footer" / caption (if caption is on bottom) * @part ${this.identifier}-empty-state : duet-upload-empty-state - named part - can be used to style the empty notification area or hide it completely * @part ${this.identifier}-editable-table : duet-upload-editable-table - named part - can be used to style the editable-table * @part ${this.identifier}-error-notification : duet-upload-error-notification - named part - can be used to style any error notifications occurring internally */ export declare class DuetUpload implements ThemeableComponent, FormComponent { /** * Reference to host HTML element. */ element: HTMLElement; /** * State() variables */ tick: number; /** * Indicates the id of a related component’s visually focused element. */ accessibleActiveDescendant: string; /** * Indicates the id of a component that describes the upload component. */ accessibleDescribedBy: string; /** * Use this prop to add an aria-controls attribute. Use the attribute to * indicate the id of a component controlled by this component. */ accessibleControls: string; /** * Indicates the id of a component owned by the input. */ accessibleOwns: string; /** * If external is set to true, the upload component will not actually upload the files, but only keep states * it will be up to you to handle the upload and return progress information to the upload-component */ external: boolean; /** * If internal upload method is used, and this has been set to a function - it will be called with the XHR options before the reqeust is sent, return an updated XHR options object in order to manipulate the request */ middleware: XHRInternalMiddleWare; /** * If defer-upload is true, duet-upload will not (as recommended) instantly upload files but await a call to uploadPending() */ deferUpload: boolean; /** * If set the upload component will not display an upload button, you will have to create one yourself * and call the exposed method startUpload to open the upload dialog */ hideButton: boolean; /** * Default actions added to the internally used duet-editable-table */ actions: DuetEditableTableActions; /** * Endpoint URI that is capable of receiving the files */ uri: string; /** * If enabled the editable-table will display links on successfully uploaded items, * this requires the server can respond with link URIs in the correct format * and that the files are accessible to the user */ showLinks: boolean; /** * Caption (underneath label) that can be set as a way of adding extra information */ caption: string; /** * Property to change the aria upload progress text read aloud by screenreaders * @default { * fi: { * inProgress: "Lähetetään {filesUploaded}, yhteensä lähetettävänä {filesTotal}.", * inProgressWithErrors: * "Lähetetään {filesInProgress}, lähetetty {filesUploaded}, yhteensä lähetettävänä {filesTotal}, {filesWithErrors} epäonnistui", * done: "Lähetys valmis, {filesTotal} lisätty onnistuneesti", * doneWithErrors: "Lähetys valmis, {filesUploaded} lisätty onnistuneesti, {filesWithErrors} epäonnistui", * files: "tiedostoa", * file: "tiedosto", * }, * sv: { * inProgress: "Laddar upp {filesUploaded} av {filesTotal}", * inProgressWithErrors: * "Laddar upp {filesInProgress}, {filesUploaded} uppladdad av {filesTotal}, {filesWithErrors} misslyckades", * done: "Uppladdningen slutförd, {filesTotal} har lagts till", * doneWithErrors: "Uppladdningen slutförd, {filesUploaded} har lagts till, {filesWithErrors} misslyckades", * files: "filer", * file: "fil", * }, * en: { * inProgress: "Uploading {filesUploaded} of {filesTotal}", * inProgressWithErrors: * "Uploading {filesInProgress}, {filesUploaded} uploaded of {filesTotal}, {filesWithErrors} failed", * done: "Upload completed, {filesTotal} added successfully", * doneWithErrors: "Upload completed, {filesUploaded} added successfully, {filesWithErrors} failed.", * files: "files", * file: "file", * }, * } */ statusLabelDefaults: DuetLangObject | string; /** * Strings used for the status aria-label */ statusMessageLabel: StatusMessage | string; /** * Property to change button label defaults on the component. * @default { fi: "Lisää liite", sv: "Lägg till en bilaga", en: "Add an attachment", } */ buttonLabelDefaults: DuetLangObject | string; /** * Label of button * @default { fi: "Lisää liite", sv: "Lägg till en bilaga", en: "Add an attachment" } */ buttonLabel: string; /** * accessible aria-Label of button */ accessibleButtonLabel: string; /** * Theme of the input. */ theme: DuetTheme; /** * Makes the input component disabled. This prevents users from being able to * interact with the upload component, and conveys its inactive state to assistive technologies. */ disabled: boolean; /** * Adds a unique identifier for the upload component. */ identifier: string; /** * Controls the margin of the component. */ margin: DuetMargin; /** * Set whether the input is required or not. Please note that this is necessary for * accessible inputs when the user is required to fill them. When using this property * you need to also set “novalidate” attribute to your form element to prevent * browser from displaying its own validation errors. */ required: boolean; /** * Key used to set vertical alignment of action buttons */ alignment: string; /** * Visually hides the groups labels in the editable table list used to display the list of files */ hideGroups: boolean; /** * Map of string that contain list of uploaded files. */ files: StringMap; /** * Property to read if the internally used editable-table contains errors or not */ valid: boolean; /** * Property to change labelDefaults defaults on the component. * normally you would handle these strings on an application level and override label when needed * @default { fi: "Lisää liite",sv: "Lägg till en bilaga",en: "Add attachments"} */ labelDefaults: DuetLangObject | string; /** * Label for the input. * @default { fi: "Lisää liite",sv: "Lägg till en bilaga",en: "Add attachments"} */ label: string; /** * Property to change descriptionDefaults defaults on the component. * @default { * en: "You may attach the following filetypes: {filetypes} - as well as the most common video files. You can upload {maxbytestotal} of files at a time, and add up to {maxfiles} attachments at a time each no larger than {maxbytes}.", * sv: "Du kan bifoga följande filtyper: {filetypes} - samt de vanligaste videofilerna. Du kan ladda upp {maxbytestotal} av filer åt gången, och lägga till upp till {maxfiles} bilagor åt gången varje inte större än {maxbytes}.", * fi: "Voit liittää seuraavat tiedostotyypit: {filetypes} - sekä yleisimmät videotiedostot. Voit lähettää {maxbytestotal} tiedostoa kerrallaan, ja lisätä enintään {maxfiles} liitettä kerrallaan, jokainen enintään {maxbytes} kokoisena.", * } */ descriptionDefaults: DuetLangObject | string; /** * Description for the upload component. * @default { * en: "You may attach the following filetypes: {filetypes} - as well as the most common video files. You can upload {maxbytestotal} of files at a time, and add up to {maxfiles} attachments at a time each no larger than {maxbytes}.", * sv: "Du kan bifoga följande filtyper: {filetypes} - samt de vanligaste videofilerna. Du kan ladda upp {maxbytestotal} av filer åt gången, och lägga till upp till {maxfiles} bilagor åt gången varje inte större än {maxbytes}.", * fi: "Voit liittää seuraavat tiedostotyypit: {filetypes} - sekä yleisimmät videotiedostot. Voit lähettää {maxbytestotal} tiedostoa kerrallaan, ja lisätä enintään {maxfiles} liitettä kerrallaan, jokainen enintään {maxbytes} kokoisena.", * } */ description: string; /** * Defaults for the filelist's empty state. * @default { fi: "Ei vielä lisättyjä tiedostoja.", sv: "Inga filer har lagts till ännu.", en: "No files added yet.", } */ fileListEmptyDefaults: DuetLangObject | string; /** * Label for the filelist's empty state. * @default { fi: "Ei vielä lisättyjä tiedostoja.",sv: "Inga filer har lagts till ännu.",en: "No files added yet."} */ fileListEmpty: string; /** * Display the input in error state along with an error message. */ error: string; /** * Default errorcodes used by the component, modifiable via javascript */ errorCodes: DuetUploadErrorCode[]; /** * Name of the upload component. */ name: string; /** * Use maxBytes to specify the maximum size in Bytes of a file that can be uploaded. */ maxBytes: number; /** * Use maxBytesTotal to specify the maximum size in Bytes of All files combined that can be uploaded. */ maxBytesTotal: number; /** * Use maxFiles to specify the maximum amount of files that can be uploaded */ maxFiles: number; /** * A string of commaseperated file type values that are allowed * @example: .pdf,.doc,.docx */ allowedExtensions: string; /** * A string of commaseperated mime type values that are allowed * @example: image/*,application/msword, */ allowedMimetypes: string; /** * Use multiple to allow the user to select multiple files when uploading */ multiple: boolean; /** * Use limitSelection to enforce the value in allowedExtension & allowedMimetypes when selecting files, * by default this is off, setting this to true will limit the users choices to what has been explicitly set */ limitSelection: boolean; /** * Use hideCancelButton to hide cancel button for pending and in progress uploads */ hideCancelButton: boolean; /** * Value of the input. */ value: string; /** * Id of external uploadButton of the input used for setting accessibility attributes. */ externalUploadButtonId: string; /** * If true the input caption will be placed below file list and footer */ captionOnBottom: boolean; /** * Use show-uploaded-items-header to show single, generic, header for uploaded items */ showUploadedItemsHeader: boolean; /** * Property to change single uploaded items header label * @default { * fi: "Ladattu tiedosto.", * sv: "Nedladdad fil.", * en: "Uploaded file.", * } */ uploadedItemsHeaderLabel: DuetLangObject; /** * Heading level for the label in the legend element. This is only used to give screen readers better logical structure. * This does not affect visual appearance. */ headerHeadingLevel: DuetHeadingLevel; /** * Use hide-header to hide upload component header and caption (if caption is not on bottom) */ hideHeader: boolean; /** * If link-click-event is set to true then upload component * will emit an event on uploaded file link click (check linkClick event). */ emitEvent: boolean; /** * Map action name to DuetLangObject or boolean. Sets upload item action buttons titles * (show as DOM tooltip when hovering). */ actionButtonTitles: string | UploadActionButtonTitles; /** * Use rename-duplicates to auto rename files with the same name instead of replacing them. */ renameDuplicates: boolean; /** * Emitted when the value has changed. */ duetChange: EventEmitter; /** * Emitted when the input loses focus. */ duetBlur: EventEmitter; /** * Emitted when the input has focus. */ duetFocus: EventEmitter; /** * Emitted when the component is finished initializing */ duetReady: EventEmitter; /** * Emitted when the current upload batch finishes */ duetDone: EventEmitter; /** * Emitted when the current validation state changes internally */ duetState: EventEmitter; /** * Emitted when a user clicks delete to delete an uploaded file, or a file entry with error */ duetDelete: EventEmitter; /** * Emitted when a user clicks cancel on an upload in progress */ duetCancel: EventEmitter; /** * Emitted when the file progress is updated. */ duetProgress: EventEmitter; /** * Emitted when the user clicks the upload button */ duetUpload: EventEmitter; /** * Emitted when the user clicks the uploaded file link and link-click-event prop is set to true */ linkClick: EventEmitter; /** * Own Properties */ private buttonId; private labelId; private uploadId; private filesInProgress; private fileMaxReached; private bytesMaxReached; private filesToUploadExceedsLimit; private filesToUploadTotalSizeIsAboveMax; private internalStatusMessageLabel; private metaData; private nativeInput?; private externalUploadButton?; private itemRefs; private processedButtonTitles; /** * Properties */ private DefaultGroups; /** * Array of group names that you want the editable table to use to display files * @required * @example [{ id: "success", label: {fi: "Onnistunut", en: "Success", sv: "Alt klart", }}] */ groups: DuetUploadTableGroupName[]; private kick; private categoryLabel; watchValidHandler(newValue: boolean, oldValue: boolean): void; /** * Component lifecycle events. */ componentWillLoad(): void; componentWillRender(): void; /** * Sets focus on the specified `duet-input`. Use this method instead of the global * `input.focus()`. */ setFocus(options?: FocusOptions): Promise; /** * Method for invoking the upload sequence */ upload(metaData?: any | undefined): Promise; /** * Method for uploading pending files */ uploadPending(): Promise; /** * Method for forcing a render of the upload list, element.files can be changed externally * But it will only rerender on a new Map or a top Level change - this can be used to update * the tabular data if the automatic re-render is no sufficient */ refresh(): Promise; /** * Get list of files, divided in errors and valid sections */ getFiles(): Promise; /** * Convenience method for updating the value of a key:value inside an item in the files attribute */ updateValue(item: string, key: string, value: any): Promise; /** * focusActionButton. */ focusActionButton(uid: string): Promise; /** * render() function * Always the last one in the class. */ render(): any; /** * Private functions */ private listenForActionEvents; private verifyValidity; private getGroupFromItemData; private mapFilesToUploadItems; private genHashName; private updateValueInMap; private updateProgress; private trackProgress; private getFilesAsArray; private resetFormFields; private startUpload; /** * Eventlisteners for the XHR requests */ private transferComplete; private transferDone; private transferDoneWithFailure; private transferFailed; private transferCanceled; private validateTotals; /** * XHR request utilities */ private makeXHRPostRequest; private makeXHRDeleteRequest; private escapeSpecialCharacters; private getRenamedFileName; private renameFiles; /** * Component event handling. */ private onChange; private uploadFile; private uploadPendingFiles; private getItemFromUID; private handleExternalUploadButton; private onDelete; private onCancel; private onUpload; private onBlur; private onProgress; private onFocus; private onReady; private onDone; /** * @description This functions return sorted map items byg condition which are: */ private filterMap; private getActions; private renderUploadedItems; }