| 1 |
|
| 2 | import { Location } from "../../router/history.js";
|
| 3 | import { ActionFunction, ActionFunctionArgs, DataRouteMatch, DataStrategyResult, LoaderFunction, LoaderFunctionArgs, MiddlewareFunction, Params, ShouldRevalidateFunction } from "../../router/utils.js";
|
| 4 | import { LinkDescriptor } from "../../router/links.js";
|
| 5 | import { SerializeFrom } from "../../types/route-data.js";
|
| 6 | import { ComponentType, ReactElement } from "react";
|
| 7 |
|
| 8 |
|
| 9 | interface RouteModules {
|
| 10 | [routeId: string]: RouteModule | undefined;
|
| 11 | }
|
| 12 | |
| 13 | |
| 14 |
|
| 15 | interface RouteModule {
|
| 16 | clientAction?: ClientActionFunction;
|
| 17 | clientLoader?: ClientLoaderFunction;
|
| 18 | clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
|
| 19 | ErrorBoundary?: ErrorBoundaryComponent;
|
| 20 | HydrateFallback?: HydrateFallbackComponent;
|
| 21 | Layout?: LayoutComponent;
|
| 22 | default: RouteComponent;
|
| 23 | handle?: RouteHandle;
|
| 24 | links?: LinksFunction;
|
| 25 | meta?: MetaFunction;
|
| 26 | shouldRevalidate?: ShouldRevalidateFunction;
|
| 27 | }
|
| 28 | |
| 29 | |
| 30 |
|
| 31 | interface ServerRouteModule extends RouteModule {
|
| 32 | action?: ActionFunction;
|
| 33 | headers?: HeadersFunction | {
|
| 34 | [name: string]: string;
|
| 35 | };
|
| 36 | loader?: LoaderFunction;
|
| 37 | middleware?: MiddlewareFunction<Response>[];
|
| 38 | }
|
| 39 | |
| 40 | |
| 41 |
|
| 42 | type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
|
| 43 | |
| 44 | |
| 45 |
|
| 46 | type ClientActionFunctionArgs = ActionFunctionArgs & {
|
| 47 | serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
|
| 48 | };
|
| 49 | |
| 50 | |
| 51 |
|
| 52 | type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
|
| 53 | hydrate?: boolean;
|
| 54 | };
|
| 55 | /**
|
| 56 | * Arguments passed to a route `clientLoader` function
|
| 57 | */
|
| 58 | type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
|
| 59 | serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
|
| 60 | };
|
| 61 | |
| 62 | |
| 63 |
|
| 64 | type ErrorBoundaryComponent = ComponentType;
|
| 65 | type HeadersArgs = {
|
| 66 | loaderHeaders: Headers;
|
| 67 | parentHeaders: Headers;
|
| 68 | actionHeaders: Headers;
|
| 69 | errorHeaders: Headers | undefined;
|
| 70 | };
|
| 71 | |
| 72 | |
| 73 | |
| 74 |
|
| 75 | interface HeadersFunction {
|
| 76 | (args: HeadersArgs): Headers | HeadersInit;
|
| 77 | }
|
| 78 | |
| 79 | |
| 80 | |
| 81 |
|
| 82 | type HydrateFallbackComponent = ComponentType;
|
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 |
|
| 88 | type LayoutComponent = ComponentType<{
|
| 89 | children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
|
| 90 | }>;
|
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 |
|
| 97 | interface LinksFunction {
|
| 98 | (): LinkDescriptor[];
|
| 99 | }
|
| 100 | interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
|
| 101 | id: RouteId;
|
| 102 | pathname: DataRouteMatch["pathname"];
|
| 103 | loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
|
| 104 | handle?: RouteHandle;
|
| 105 | params: DataRouteMatch["params"];
|
| 106 | meta: MetaDescriptor[];
|
| 107 | error?: unknown;
|
| 108 | }
|
| 109 | type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{ [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]> }[keyof MatchLoaders]>;
|
| 110 | interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
| 111 | loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
| 112 | params: Params;
|
| 113 | location: Location;
|
| 114 | matches: MetaMatches<MatchLoaders>;
|
| 115 | error?: unknown;
|
| 116 | }
|
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 |
|
| 167 | interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
| 168 | (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
|
| 169 | }
|
| 170 | type MetaDescriptor = {
|
| 171 | charSet: "utf-8";
|
| 172 | } | {
|
| 173 | title: string;
|
| 174 | } | {
|
| 175 | name: string;
|
| 176 | content: string;
|
| 177 | } | {
|
| 178 | property: string;
|
| 179 | content: string;
|
| 180 | } | {
|
| 181 | httpEquiv: string;
|
| 182 | content: string;
|
| 183 | } | {
|
| 184 | "script:ld+json": LdJsonObject | LdJsonObject[];
|
| 185 | } | {
|
| 186 | tagName: "meta" | "link";
|
| 187 | [name: string]: string;
|
| 188 | } | {
|
| 189 | [name: string]: unknown;
|
| 190 | };
|
| 191 | type LdJsonObject = { [Key in string]: LdJsonValue } & { [Key in string]?: LdJsonValue | undefined };
|
| 192 | type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
|
| 193 | type LdJsonPrimitive = string | number | boolean | null;
|
| 194 | type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
| 195 | |
| 196 | |
| 197 |
|
| 198 | type RouteComponent = ComponentType<{}>;
|
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 |
|
| 204 | type RouteHandle = unknown;
|
| 205 |
|
| 206 | export { ClientActionFunction, ClientActionFunctionArgs, ClientLoaderFunction, ClientLoaderFunctionArgs, HeadersArgs, HeadersFunction, LinksFunction, MetaArgs, MetaDescriptor, MetaFunction, RouteModules, ServerRouteModule }; |
| \ | No newline at end of file |