import { ClassListMerger, ErrorMessage, ExpandedRouteConfig, ExtendObjectIf, FetchEsque, MaybePromise, ProgressGranularity, UploadThingError } from "@uploadthing/shared"; import * as uploadthing_types0 from "uploadthing/types"; import { AnyFileRoute, ClientUploadedFileData, EndpointArg, FileRouter, inferEndpointInput, inferEndpointOutput, inferErrorShape } from "uploadthing/types"; //#region src/types.d.ts interface GenerateTypedHelpersOptions { /** * URL to the UploadThing API endpoint * @example "/api/uploadthing" * @example "https://www.example.com/api/uploadthing" * * If relative, host will be inferred from either the `VERCEL_URL` environment variable or `window.location.origin` * * @default (VERCEL_URL ?? window.location.origin) + "/api/uploadthing" */ url?: string | URL; /** * Provide a custom fetch implementation. * @default `globalThis.fetch` * @example * ```ts * fetch: (input, init) => { * if (input.toString().startsWith(MY_SERVER_URL)) { * // Include cookies in the request to your API * return fetch(input, { * ...init, * credentials: "include", * }); * } * * return fetch(input, init); * } * ``` */ fetch?: FetchEsque | undefined; } type UseUploadthingProps> = { /** * Called when the upload is submitted and the server is about to be queried for presigned URLs * Can be used to modify the files before they are uploaded, e.g. renaming them */ onBeforeUploadBegin?: ((files: File[]) => Promise | File[]) | undefined; /** * Called when presigned URLs have been retrieved and the file upload is about to begin */ onUploadBegin?: ((fileName: string) => void) | undefined; /** * Control how granular the upload progress is reported * - "all" - No filtering is applied, all progress events are reported * - "fine" - Progress is reported in increments of 1% * - "coarse" - Progress is reported in increments of 10% * @default "coarse" */ uploadProgressGranularity?: ProgressGranularity | undefined; /** * Called continuously as the file is uploaded to the storage provider */ onUploadProgress?: ((p: number) => void) | undefined; /** * This option has been moved to your serverside route config. * Please opt-in by setting `awaitServerData: false` in your route * config instead. * ### Example * ```ts * f( * { image: { maxFileSize: "1MB" } }, * { awaitServerData: false } * ).middleware(...) * ``` * @deprecated * @see https://docs.uploadthing.com/api-reference/server#route-options */ skipPolling?: ErrorMessage<"This option has been moved to your serverside route config. Please use `awaitServerData` in your route config instead.">; /** * Called when the file uploads are completed * @remarks If `RouteOptions.awaitServerData` is `true`, this will be * called after the serverside `onUploadComplete` callback has finished */ onClientUploadComplete?: ((res: ClientUploadedFileData[]) => MaybePromise) | undefined; /** * Called if the upload fails */ onUploadError?: ((e: UploadThingError>) => MaybePromise) | undefined; /** * Set custom headers that'll get sent with requests * to your server */ headers?: HeadersInit | (() => MaybePromise) | undefined; /** * An AbortSignal to cancel the upload * Calling `abort()` on the parent AbortController will cause the * upload to throw an `UploadAbortedError`. In a future version * the function will not throw in favor of an `onUploadAborted` callback. */ signal?: AbortSignal | undefined; }; type UploadthingComponentProps = Omit, /** * Signal is omitted, component has its own AbortController * If you need to control the interruption with more granularity, * create your own component and pass your own signal to * `useUploadThing` * @see https://github.com/pingdotgg/uploadthing/pull/838#discussion_r1624189818 */ "signal"> & { /** * Called when the upload is aborted */ onUploadAborted?: (() => MaybePromise) | undefined; /** * The endpoint from your FileRouter to use for the upload */ endpoint: EndpointArg; /** * URL to the UploadThing API endpoint * @example URL { /api/uploadthing } * @example URL { https://www.example.com/api/uploadthing } * * If relative, host will be inferred from either the `VERCEL_URL` environment variable or `window.location.origin` * * @default (VERCEL_URL ?? window.location.origin) + "/api/uploadthing" */ url?: string | URL; /** * Provide a custom fetch implementation. * @default `globalThis.fetch` * @example * ```ts * fetch: (input, init) => { * if (input.toString().startsWith(MY_SERVER_URL)) { * // Include cookies in the request to your API * return fetch(input, { * ...init, * credentials: "include", * }); * } * * return fetch(input, init); * } * ``` */ fetch?: FetchEsque | undefined; config?: { mode?: "auto" | "manual"; appendOnPaste?: boolean; /** * Override the default class name merger, with e.g. tailwind-merge * This may be required if you're customizing the component * appearance with additional TailwindCSS classes to ensure * classes are sorted and applied in the correct order */ cn?: ClassListMerger; }; disabled?: boolean; /** * Callback called when files are selected * * @param acceptedFiles - The files that were accepted. */ onChange?: (files: File[]) => void; } & ExtendObjectIf, { /** * The input to the endpoint, as defined using `.input()` on the FileRouter endpoint * @see https://docs.uploadthing.com/api-reference/server#input */ input: inferEndpointInput; }>; //#endregion //#region src/use-uploadthing.d.ts /** * @internal - This is an internal function. Use `generateReactHelpers` instead. * The actual hook we export for public usage is generated from `generateReactHelpers` * which has the URL and FileRouter generic pre-bound. */ declare function useUploadThingInternal(url: URL, endpoint: EndpointArg, fetch: FetchEsque, opts?: UseUploadthingProps): { readonly startUpload: (...args: undefined extends inferEndpointInput ? [files: File[], input?: undefined] : [files: File[], input: inferEndpointInput]) => Promise>[] | undefined>; readonly isUploading: boolean; readonly routeConfig: ExpandedRouteConfig | undefined; }; /** @internal - This is an internal function. Use `generateReactHelpers` instead. */ declare const __useUploadThingInternal: typeof useUploadThingInternal; declare const generateReactHelpers: (initOpts?: GenerateTypedHelpersOptions) => { /** * Get the config for a given endpoint outside of React context. * @remarks Can only be used if the NextSSRPlugin is used in the app. */ readonly getRouteConfig: (slug: EndpointArg) => ExpandedRouteConfig; readonly uploadFiles: (slug: EndpointArg, opts: Omit, keyof uploadthing_types0.GenerateUploaderOptions>) => Promise>[]>; readonly createUpload: >(slug: EndpointArg, opts: Omit, keyof uploadthing_types0.GenerateUploaderOptions>) => Promise<{ pauseUpload: (file?: File) => void; resumeUpload: (file?: File) => void; done: (file?: T | undefined) => Promise : uploadthing_types0.ClientUploadedFileData[]>; }>; readonly routeRegistry: uploadthing_types0.RouteRegistry; readonly useUploadThing: (endpoint: EndpointArg, opts?: UseUploadthingProps) => { readonly startUpload: (...args: undefined extends inferEndpointInput ? [files: File[], input?: inferEndpointInput & undefined] : [files: File[], input: inferEndpointInput]) => Promise>[] | undefined>; readonly isUploading: boolean; readonly routeConfig: ExpandedRouteConfig | undefined; }; }; //#endregion export { GenerateTypedHelpersOptions, UploadthingComponentProps, UseUploadthingProps, __useUploadThingInternal, generateReactHelpers }; //# sourceMappingURL=use-uploadthing-CkqJn3G-.d.ts.map