UNPKG

9 kBTypeScriptView Raw
1import { R as RouteModule, t as LinkDescriptor, L as Location, u as Func, v as Pretty, w as MetaDescriptor, G as GetLoaderData, x as ServerDataFunctionArgs, y as MiddlewareNextFunction, z as ClientDataFunctionArgs, B as DataStrategyResult, E as ServerDataFrom, N as Normalize, I as GetActionData } from '../../routeModules-CM_clkdE.js';
2import { R as RouteFiles, P as Pages } from '../../register-D1WlEpq9.js';
3import 'react';
4
5type MaybePromise<T> = T | Promise<T>;
6type Props = {
7 params: unknown;
8 loaderData: unknown;
9 actionData: unknown;
10};
11type RouteInfo = Props & {
12 module: RouteModule;
13 matches: Array<MatchInfo>;
14};
15type MatchInfo = {
16 id: string;
17 module: RouteModule;
18};
19type MetaMatch<T extends MatchInfo> = Pretty<{
20 id: T["id"];
21 params: Record<string, string | undefined>;
22 pathname: string;
23 meta: MetaDescriptor[];
24 /** @deprecated Use `MetaMatch.loaderData` instead */
25 data: GetLoaderData<T["module"]>;
26 loaderData: GetLoaderData<T["module"]>;
27 handle?: unknown;
28 error?: unknown;
29}>;
30type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : Array<MetaMatch<MatchInfo> | undefined>;
31type HasErrorBoundary<T extends RouteInfo> = T["module"] extends {
32 ErrorBoundary: Func;
33} ? true : false;
34type CreateMetaArgs<T extends RouteInfo> = {
35 /** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */
36 location: Location;
37 /** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
38 params: T["params"];
39 /**
40 * The return value for this route's server loader function
41 *
42 * @deprecated Use `Route.MetaArgs.loaderData` instead
43 */
44 data: T["loaderData"] | (HasErrorBoundary<T> extends true ? undefined : never);
45 /** The return value for this route's server loader function */
46 loaderData: T["loaderData"] | (HasErrorBoundary<T> extends true ? undefined : never);
47 /** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
48 error?: unknown;
49 /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react-router.UIMatch.html route matches}, including parent route matches. */
50 matches: MetaMatches<T["matches"]>;
51};
52type MetaDescriptors = MetaDescriptor[];
53type HeadersArgs = {
54 loaderHeaders: Headers;
55 parentHeaders: Headers;
56 actionHeaders: Headers;
57 errorHeaders: Headers | undefined;
58};
59type CreateServerMiddlewareFunction<T extends RouteInfo> = (args: ServerDataFunctionArgs<T["params"]>, next: MiddlewareNextFunction<Response>) => MaybePromise<Response | void>;
60type CreateClientMiddlewareFunction<T extends RouteInfo> = (args: ClientDataFunctionArgs<T["params"]>, next: MiddlewareNextFunction<Record<string, DataStrategyResult>>) => MaybePromise<Record<string, DataStrategyResult> | void>;
61type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T["params"]>;
62type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T["params"]> & {
63 /** This is an asynchronous function to get the data from the server loader for this route. On client-side navigations, this will make a {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server loader. If you opt-into running your clientLoader on hydration, then this function will return the data that was already loaded on the server (via Promise.resolve). */
64 serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
65};
66type CreateServerActionArgs<T extends RouteInfo> = ServerDataFunctionArgs<T["params"]>;
67type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T["params"]> & {
68 /** This is an asynchronous function that makes the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server action for this route. */
69 serverAction: () => Promise<ServerDataFrom<T["module"]["action"]>>;
70};
71type CreateHydrateFallbackProps<T extends RouteInfo, RSCEnabled extends boolean> = {
72 params: T["params"];
73} & (RSCEnabled extends true ? {
74 /** The data returned from the `loader` */
75 loaderData?: ServerDataFrom<T["module"]["loader"]>;
76 /** The data returned from the `action` following an action submission. */
77 actionData?: ServerDataFrom<T["module"]["action"]>;
78} : {
79 /** The data returned from the `loader` or `clientLoader` */
80 loaderData?: T["loaderData"];
81 /** The data returned from the `action` or `clientAction` following an action submission. */
82 actionData?: T["actionData"];
83});
84type Match<T extends MatchInfo> = Pretty<{
85 id: T["id"];
86 params: Record<string, string | undefined>;
87 pathname: string;
88 /** @deprecated Use `Match.loaderData` instead */
89 data: GetLoaderData<T["module"]>;
90 loaderData: GetLoaderData<T["module"]>;
91 handle: unknown;
92}>;
93type Matches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [Match<F>, ...Matches<R>] : Array<Match<MatchInfo> | undefined>;
94type CreateComponentProps<T extends RouteInfo, RSCEnabled extends boolean> = {
95 /**
96 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
97 * @example
98 * // app/routes.ts
99 * route("teams/:teamId", "./team.tsx"),
100 *
101 * // app/team.tsx
102 * export default function Component({
103 * params,
104 * }: Route.ComponentProps) {
105 * params.teamId;
106 * // ^ string
107 * }
108 **/
109 params: T["params"];
110 /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react-router.UIMatch.html route matches}, including parent route matches. */
111 matches: Matches<T["matches"]>;
112} & (RSCEnabled extends true ? {
113 /** The data returned from the `loader` */
114 loaderData: ServerDataFrom<T["module"]["loader"]>;
115 /** The data returned from the `action` following an action submission. */
116 actionData?: ServerDataFrom<T["module"]["action"]>;
117} : {
118 /** The data returned from the `loader` or `clientLoader` */
119 loaderData: T["loaderData"];
120 /** The data returned from the `action` or `clientAction` following an action submission. */
121 actionData?: T["actionData"];
122});
123type CreateErrorBoundaryProps<T extends RouteInfo, RSCEnabled extends boolean> = {
124 /**
125 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
126 * @example
127 * // app/routes.ts
128 * route("teams/:teamId", "./team.tsx"),
129 *
130 * // app/team.tsx
131 * export function ErrorBoundary({
132 * params,
133 * }: Route.ErrorBoundaryProps) {
134 * params.teamId;
135 * // ^ string
136 * }
137 **/
138 params: T["params"];
139 error: unknown;
140} & (RSCEnabled extends true ? {
141 /** The data returned from the `loader` */
142 loaderData?: ServerDataFrom<T["module"]["loader"]>;
143 /** The data returned from the `action` following an action submission. */
144 actionData?: ServerDataFrom<T["module"]["action"]>;
145} : {
146 /** The data returned from the `loader` or `clientLoader` */
147 loaderData?: T["loaderData"];
148 /** The data returned from the `action` or `clientAction` following an action submission. */
149 actionData?: T["actionData"];
150});
151type GetAnnotations<Info extends RouteInfo> = {
152 LinkDescriptors: LinkDescriptor[];
153 LinksFunction: () => LinkDescriptor[];
154 MetaArgs: CreateMetaArgs<Info>;
155 MetaDescriptors: MetaDescriptors;
156 MetaFunction: (args: CreateMetaArgs<Info>) => MetaDescriptors;
157 HeadersArgs: HeadersArgs;
158 HeadersFunction: (args: HeadersArgs) => Headers | HeadersInit;
159 MiddlewareFunction: CreateServerMiddlewareFunction<Info>;
160 ClientMiddlewareFunction: CreateClientMiddlewareFunction<Info>;
161 LoaderArgs: CreateServerLoaderArgs<Info>;
162 ClientLoaderArgs: CreateClientLoaderArgs<Info>;
163 ActionArgs: CreateServerActionArgs<Info>;
164 ClientActionArgs: CreateClientActionArgs<Info>;
165 HydrateFallbackProps: CreateHydrateFallbackProps<Info, false>;
166 ServerHydrateFallbackProps: CreateHydrateFallbackProps<Info, true>;
167 ComponentProps: CreateComponentProps<Info, false>;
168 ServerComponentProps: CreateComponentProps<Info, true>;
169 ErrorBoundaryProps: CreateErrorBoundaryProps<Info, false>;
170 ServerErrorBoundaryProps: CreateErrorBoundaryProps<Info, true>;
171};
172
173type Params<RouteFile extends keyof RouteFiles> = Normalize<Pages[RouteFiles[RouteFile]["page"]]["params"]>;
174
175type GetInfo<T extends {
176 file: keyof RouteFiles;
177 module: RouteModule;
178}> = {
179 params: Params<T["file"]>;
180 loaderData: GetLoaderData<T["module"]>;
181 actionData: GetActionData<T["module"]>;
182};
183
184export type { GetAnnotations, GetInfo };