import React, { ReactNode } from 'react'; import { BATCH_STATES } from '../consts'; export type PreviewItem = { id: string; url: string; name: string; props: Record; }; export type PreviewData = { previews: PreviewItem[]; clearPreviews: () => void; }; export type PreviewComponentPropsMethod = (item: BatchItem, url: string) => Record; export type PreviewMethods = { clear: () => void; }; export type PreviewBatchItemsMethod = (cb: (batch: { items: BatchItem[]; }) => void) => void; export interface PreviewOptions { rememberPreviousBatches?: boolean; loadFirstOnly?: boolean; previewComponentProps?: PreviewComponentPropsMethod; } export interface PreviewProps extends PreviewOptions { PreviewComponent: any; previewMethodsRef?: React.RefObject; onPreviewsChanged?: (previews: PreviewItem[]) => void; } export type UploadPreviewType = (props: PreviewProps) => any; export type PreviewsLoaderHook = (props: PreviewOptions) => PreviewData; export type UploaderCreateOptions = CreateOptionsWithAbort & { send?: SendMethod | null; }; export type ItemsSender = { send: (batchItems: BatchItem[], batch: Batch, options: UploaderCreateOptions) => SendResult; on: OnAndOnceMethod; }; export type UploaderProcessor = { abort: (id?: string) => void; abortBatch: (batchId: string) => void; addNewBatch: (files: BatchItem | Array, uploaderId: string, processOptions: UploaderCreateOptions) => Promise; clearPendingBatches: () => void; process: (batch: Batch, batchOptions?: UploaderCreateOptions) => void; processPendingBatches: (uploadOptions: UploadOptions) => void; runCancellable: Cancellable; }; export type UploadyUploaderType = UploaderType; export type ItemInfo = { id: string; uploadUrl?: string; size: number; offset: number; abort?: () => boolean; parallelChunks: string[]; }; export type InitData = { uploadUrl?: string; offset?: number; isNew?: boolean; isDone?: boolean; canResume?: boolean; }; export type InitUploadResult = { request: Promise; abort: () => boolean; }; export interface TusOptions extends ChunkedOptions { version?: string; featureDetection?: boolean; featureDetectionUrl?: string | null; onFeaturesDetected?: (extensions: string[]) => TusOptions | void; resume?: boolean; deferLength?: boolean; overrideMethod?: boolean; sendDataOnCreate?: boolean; storagePrefix?: string; lockedRetryDelay?: number; forgetOnSuccess?: boolean; ignoreModifiedDateInStorage?: boolean; } export type RequestResult = { request: Promise; abort: () => boolean; }; export type TusStateData = { options: TusOptions; items: Record; featureDetection: { extensions: string | null | undefined; version: string | null | undefined; processed: boolean; }; }; export type TusState = { getState: () => TusStateData; updateState: (arg0: (arg0: TusStateData) => void) => TusStateData; }; export type SimpleState = { state: T; update: (arg0: (arg0: T) => void) => T; unwrap: (arg0: Record | null | undefined) => T | Record; }; export type PreSendData = { items: BatchItem[]; options: UploaderCreateOptions; }; type EventHook = (cb: (obj: T) => void, id?: string) => void; type CancellableHook = (cb: (obj: T) => boolean | void, id?: string) => void; type EventHookWithState = (cb?: (obj: T) => void, id?: string) => T; export type ItemEventHook = EventHook; export type ItemCancellableEventHook = CancellableHook; export type ItemEventHookWithState = EventHookWithState; export type BatchEventHook = EventHook; export type BatchCancellableEventHook = CancellableHook; export type BatchEventHookWithState = EventHookWithState; export type RefObject = { current: null | void | T; }; export type AddUploadFunction = (files: BatchItem | BatchItem[], addOptions: UploadOptions) => void; export type UploadyContextType = { hasUploader: () => boolean; upload: AddUploadFunction; processPending: (uploadOptions?: UploadOptions) => void; clearPending: () => void; setOptions: (options: UploaderCreateOptions) => void; getOptions: () => UploaderCreateOptions; on: OnAndOnceMethod; once: OnAndOnceMethod; off: OffMethod; abort: (id?: string) => void; abortBatch: (id: string) => void; getExtension: (name: string | symbol) => Record; }; export type UploaderListeners = { [key: string]: EventCallback; }; export type NoDomUploadyProps = UploaderCreateOptions & { debug?: boolean; listeners?: UploaderListeners; children?: ReactNode; }; export type UploadyProps = NoDomUploadyProps; export type Destination = { url?: string; filesParamName?: string; params?: Record; headers?: Record; method?: string; }; export type $Values = O[keyof O]; export type BatchState = $Values; export type FileState = $Values; export type UploadData = { status: number; state: FileState; response: any; }; export type FormatParamGroupNameMethod = (arg0: number, arg1: string) => string; export type Headers = Record; export type FormatServerResponseMethod = (arg0: string, arg1: number, headers: Headers) => any; export type IsSuccessfulCall = (xhr: XMLHttpRequest) => boolean; declare enum FILE_STATES { PENDING = "pending", ADDED = "added", UPLOADING = "uploading", CANCELLED = "cancelled", FINISHED = "finished", ERROR = "error", ABORTED = "aborted" } export type Batch = { id: string; uploaderId: string; items: BatchItem[]; state: BatchState; completed: number; loaded: number; orgItemCount: number; additionalInfo: string; }; export type UploadOptions = { autoUpload?: boolean; clearPendingOnAdd?: boolean; destination?: Destination | null; inputFieldName?: string; formatGroupParamName?: FormatParamGroupNameMethod; grouped?: boolean; maxGroupSize?: number; method?: string; params?: Record; forceJsonResponse?: boolean; withCredentials?: boolean; sendWithFormData?: boolean; formDataAllowUndefined?: boolean; formatServerResponse?: FormatServerResponseMethod; isSuccessfulCall?: IsSuccessfulCall; fastAbortThreshold?: number; }; export type Trigger = (arg0: string, ...args: any[]) => Promise[]; export type Cancellable = (arg0: string, ...args: any[]) => Promise; export type TriggerCancellableOutcome = Promise | Cancellable; export type Updater = (arg0: string, ...args: any[]) => Promise; export interface RequestOptions { method?: string; headers?: Record; withCredentials?: boolean; preSend?: (xhr: XMLHttpRequest) => void; } export type SendOptions = { method: string; paramName: string; params: Record; headers?: Record; forceJsonResponse: boolean; withCredentials: boolean; formatGroupParamName: FormatParamGroupNameMethod; sendWithFormData?: boolean; formDataAllowUndefined?: boolean; formatServerResponse?: FormatServerResponseMethod; isSuccessfulCall?: IsSuccessfulCall; }; export type SenderProgressEvent = { total: number; loaded: number; }; export type OnProgress = (e: SenderProgressEvent, objs: Record[]) => void; export type XhrSendConfig = { preRequestHandler: (issueRequest: (requestUrl?: string, requestData?: any, requestOptions?: Record) => Promise, items: BatchItem[], url: string, options: SendOptions, onProgress: OnProgress, config: XhrSendConfig) => Promise; getRequestData: (items: BatchItem[], options: SendOptions) => any; }; export type SendResult = { request: Promise; abort: () => boolean; senderType: string; }; export type SendMethod = (item: BatchItem[], url: string, options: SendOptions, onProgress: OnProgress) => SendResult; export type SafeStorage = { length: number; getItem(key: string): string; setItem(key: string, data: string): void; clear(): void; removeItem(key: string): void; key(index: number): string; isSupported: boolean; }; export interface RawCreateOptions extends UploadOptions { enhancer?: RawUploaderEnhancer; concurrent?: boolean; maxConcurrent?: number; } export type PendingBatch = { batch: Batch; uploadOptions: RawCreateOptions; }; export type UploadAddMethod = (files: BatchItem | BatchItem[], addOptions?: UploadOptions) => Promise; export type RegisterExtensionMethod = (name: unknown, methods: { [key: string]: (...args: any[]) => void | unknown; }) => void; export type RawUploaderType = { id: string; update: (updateOptions: RawCreateOptions) => RawUploaderType; add: UploadAddMethod; upload: (uploadOptions?: UploadOptions) => void; abort: (id?: string) => void; abortBatch: (id: string) => void; getOptions: () => RawCreateOptions; getPending?: () => PendingBatch[]; clearPending: () => void; on: OnAndOnceMethod; once: OnAndOnceMethod; off: OffMethod; registerExtension: RegisterExtensionMethod; getExtension: (name: unknown) => Record; }; export type RawUploaderEnhancer = (uploader: RawUploaderType, trigger: Trigger) => RawUploaderType; export type UploaderEnhancer = (uploader: UploaderType, trigger: Trigger) => UploaderType; type BatchItemBase = { id: string; batchId: string; state: FileState; uploadResponse?: any; uploadStatus: number; completed: number; loaded: number; recycled: boolean; previousBatch?: string; }; export type FileLike = { name: string; size: number; type: string; lastModified: number; }; type BatchUrl = BatchItemBase & { url: string; }; type BatchFile = BatchItemBase & { file: FileLike; }; export type BatchItem = BatchUrl & BatchFile; export type UploadInfo = string | Record | BatchItem; export type UploaderType = { id: string; update: (updateOptions: T) => UploaderType; add: (files: UploadInfo | UploadInfo[], addOptions?: UploadOptions | null | undefined) => Promise; upload: (uploadOptions?: UploadOptions | null | undefined) => void; abort: (id?: string) => void; abortBatch: (id: string) => void; getOptions: () => T; clearPending: () => void; on: OnAndOnceMethod; once: OnAndOnceMethod; off: OffMethod; registerExtension: (arg0: any, arg1: Record) => void; getExtension: (arg0: any) => Record | null | undefined; }; export type BatchData = { batch: Batch; batchOptions: UploaderCreateOptions; finishedCounter: number; }; export type QueueStateData = { itemQueue: Record; batchQueue: string[]; currentBatch: string | null | undefined; batches: Record; items: Record; activeIds: Array; aborts: AbortsMap; }; type UpdateStateMethod = (arg0: (arg0: QueueStateData) => void) => void; type GetStateMethod = () => QueueStateData; export type QueueState = { uploaderId: string; getOptions: () => UploaderCreateOptions; getState: GetStateMethod; getCurrentActiveCount: () => number; updateState: UpdateStateMethod; trigger: TriggerMethod; runCancellable: Cancellable; sender: ItemsSender; handleItemProgress: (arg0: BatchItem, arg1: number, arg2: number) => void; clearAllUploads: () => void; clearBatchUploads: (arg0: string) => void; }; export type UploaderQueue = { updateState: UpdateStateMethod; getState: GetStateMethod; runCancellable: Cancellable; uploadBatch: (batch: Batch, batchOptions: UploaderCreateOptions | null | undefined) => void; addBatch: (batch: Batch, batchOptions: UploaderCreateOptions) => Batch; abortItem: (id: string) => boolean; abortBatch: (id: string) => void; abortAll: () => void; clearPendingBatches: () => void; uploadPendingBatches: (uploadOptions: UploadOptions | null | undefined) => void; }; export type ProcessNextMethod = (arg0: QueueState) => Promise | void; export type MergeOptions = { undefinedOverwrites?: boolean; withSymbols?: boolean; predicate?: (arg0: unknown, arg1: any) => boolean; }; export type MergeMethod = (target: T, ...sources: Array) => T; export type EventCallback = (...args: any[]) => unknown | void; export type OffMethod = (name: unknown, cb?: EventCallback) => void; export type OnAndOnceMethod = (name: unknown, cb: EventCallback) => OffMethod; export interface LifeEventsOptions { allowRegisterNonExistent?: boolean; canAddEvents?: boolean; canRemoveEvents?: boolean; collectStats?: boolean; } export type TriggerMethod = (name: string, ...args: unknown[]) => unknown; export interface WithLife { on: OnAndOnceMethod; once: OnAndOnceMethod; off: OffMethod; } export interface LifeEventsAPI { target: T & WithLife; trigger: TriggerMethod; addEvent: (name: unknown) => void; removeEvent: (name: unknown) => void; hasEvent: (name: unknown) => boolean; hasEventRegistrations: (name: unknown) => boolean; } export type RegItem = { name: any; cb: EventCallback; once: boolean; }; export type ItemsSendData = { items: BatchItem[]; options: UploaderCreateOptions; cancelled?: boolean; }; export type Chunk = { id: string; start: number; end: number; data: Blob; attempt: number; uploaded: number; index: number; }; export type ChunkedSenderState = MandatoryChunkedOptions & { finished: boolean; aborted: boolean; error: boolean; requests: { [key: string]: { abort: () => boolean; }; }; responses: any[]; chunks: Chunk[]; uploaded: { [key: string]: number; }; url: string; sendOptions: SendOptions; chunkCount: number; startByte: number; }; type ChunkedStateUpdateStateMethod = (value: (state: ChunkedSenderState) => void) => void; type ChunkedStateGetStateMethod = () => ChunkedSenderState; export type ChunkedState = { getState: ChunkedStateGetStateMethod; updateState: ChunkedStateUpdateStateMethod; }; export type ChunksSendResponse = { sendPromise: Promise; abort: () => boolean; }; export type FinalizeRequestMethod = (id: string, data: UploadData) => void; export type AbortMethod = () => boolean; export type AbortsMap = { [key: string]: AbortMethod; }; export type ItemsQueue = { [key: string]: string[]; }; export type AbortResult = { isFast: boolean; }; export type AbortBatchMethod = (batch: Batch, batchOptions: UploadOptions, aborts: AbortsMap, queue: ItemsQueue, finalizeItem: FinalizeRequestMethod, options: UploadOptions) => AbortResult; export type AbortAllMethod = (items: { [p: string]: BatchItem; }, aborts: AbortsMap, queue: ItemsQueue, finalizeItem: FinalizeRequestMethod, options: UploadOptions) => AbortResult; export type AbortItemMethod = (id: string, items: { [p: string]: BatchItem; }, aborts: AbortsMap, finalizeItem: FinalizeRequestMethod) => boolean; export type AbortMethodsOptions = { abortAll?: AbortAllMethod; abortBatch?: AbortBatchMethod; abortItem?: AbortItemMethod; }; export type ChunkedOptions = { chunked?: boolean; chunkSize?: number; retries?: number; parallel?: number; }; export type ChunkedSendOptions = SendOptions & { startByte?: number; }; export type MandatoryChunkedOptions = { chunked: boolean; chunkSize: number; retries: number; parallel: number; }; export type ChunkedSender = { send: SendMethod; }; export type ChunkEventData = { id: string; start: number; end: number; index: number; attempt: number; }; export type ChunkStartEventData = { item: BatchItem; chunk: ChunkEventData; chunkItem: BatchItem; sendOptions: SendOptions; url: string; remainingCount: number; totalCount: number; onProgress: OnProgress; }; export type ChunkFinishEventData = { item: BatchItem; chunk: ChunkEventData; uploadData: UploadData; }; export type CreateOptionsWithAbort = RawCreateOptions & AbortMethodsOptions & {}; export type TusUploadyProps = UploadyProps & TusOptions & {}; export {}; //# sourceMappingURL=index.d.ts.map