UNPKG

@wordpress/upload-media

Version:
96 lines 3.8 kB
/** * WordPress dependencies */ import type { createRegistry } from '@wordpress/data'; type WPDataRegistry = ReturnType<typeof createRegistry>; /** * Internal dependencies */ import type { AdditionalData, OnBatchSuccessHandler, OnChangeHandler, OnErrorHandler, OnSuccessHandler, QueueItemId, State } from './types'; import type { addItem, processItem, removeItem, revokeBlobUrls } from './private-actions'; type ActionCreators = { addItem: typeof addItem; addItems: typeof addItems; removeItem: typeof removeItem; processItem: typeof processItem; cancelItem: typeof cancelItem; retryItem: typeof retryItem; scheduleRetry: typeof scheduleRetry; executeRetry: typeof executeRetry; revokeBlobUrls: typeof revokeBlobUrls; <T = Record<string, unknown>>(args: T): void; }; type AllSelectors = typeof import('./selectors') & typeof import('./private-selectors'); type CurriedState<F> = F extends (state: State, ...args: infer P) => infer R ? (...args: P) => R : F; type Selectors = { [key in keyof AllSelectors]: CurriedState<AllSelectors[key]>; }; type ThunkArgs = { select: Selectors; dispatch: ActionCreators; registry: WPDataRegistry; }; interface AddItemsArgs { files: File[]; onChange?: OnChangeHandler; onSuccess?: OnSuccessHandler; onBatchSuccess?: OnBatchSuccessHandler; onError?: OnErrorHandler; additionalData?: AdditionalData; allowedTypes?: string[]; } /** * Adds a new item to the upload queue. * * @param $0 * @param $0.files Files * @param [$0.onChange] Function called each time a file or a temporary representation of the file is available. * @param [$0.onSuccess] Function called after the file is uploaded. * @param [$0.onBatchSuccess] Function called after a batch of files is uploaded. * @param [$0.onError] Function called when an error happens. * @param [$0.additionalData] Additional data to include in the request. * @param [$0.allowedTypes] Array with the types of media that can be uploaded, if unset all types are allowed. */ export declare function addItems({ files, onChange, onSuccess, onError, onBatchSuccess, additionalData, allowedTypes, }: AddItemsArgs): ({ select, dispatch }: ThunkArgs) => Promise<void>; /** * Cancels an item in the queue based on an error. * * If the error is retryable and the item hasn't exceeded the maximum * retry attempts, it will be scheduled for automatic retry instead * of being cancelled. * * @param id Item ID. * @param error Error instance. * @param silent Whether to cancel the item silently, * without invoking its `onError` callback. */ export declare function cancelItem(id: QueueItemId, error: Error, silent?: boolean): ({ select, dispatch }: ThunkArgs) => Promise<void>; /** * Retries a failed item in the queue. * * @param id Item ID. */ export declare function retryItem(id: QueueItemId): ({ select, dispatch }: ThunkArgs) => Promise<void>; /** * Schedules an automatic retry for a failed item. * * Uses exponential backoff with jitter to determine the retry delay. * The item will be placed in PendingRetry status and automatically * retried after the calculated delay. * * @param id Item ID. * @param error The error that caused the failure. */ export declare function scheduleRetry(id: QueueItemId, error: Error): ({ select, dispatch }: ThunkArgs) => Promise<void>; /** * Executes a scheduled retry for an item. * * This is called by the timer set in scheduleRetry. * It verifies the item is still in PendingRetry status before * proceeding with the retry. * * @param id Item ID. */ export declare function executeRetry(id: QueueItemId): ({ select, dispatch }: ThunkArgs) => Promise<void>; export {}; //# sourceMappingURL=actions.d.ts.map