@tanstack/react-router 0.0.1-beta.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/build/cjs/CatchBoundary.js +128 -0
- package/build/cjs/CatchBoundary.js.map +1 -0
- package/build/cjs/Matches.js +233 -0
- package/build/cjs/Matches.js.map +1 -0
- package/build/cjs/RouterProvider.js +170 -0
- package/build/cjs/RouterProvider.js.map +1 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/_virtual/with-selector.development.js +16 -0
- package/build/cjs/_virtual/with-selector.development.js.map +1 -0
- package/build/cjs/_virtual/with-selector.js +16 -0
- package/build/cjs/_virtual/with-selector.js.map +1 -0
- package/build/cjs/_virtual/with-selector.production.min.js +16 -0
- package/build/cjs/_virtual/with-selector.production.min.js.map +1 -0
- package/build/cjs/awaited.js +43 -0
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/build/esm/index.js +79 -0
- package/build/cjs/build/esm/index.js.map +1 -0
- package/build/cjs/defer.js +37 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/fileRoute.js +27 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +130 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/lazyRouteComponent.js +54 -0
- package/build/cjs/lazyRouteComponent.js.map +1 -0
- package/build/cjs/link.js +223 -0
- package/build/cjs/link.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js +47 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_store@0.1.3/node_modules/@tanstack/store/build/modern/index.js +70 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_store@0.1.3/node_modules/@tanstack/store/build/modern/index.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +188 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +39 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/shim/with-selector.js +26 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
- package/build/cjs/packages/react-router/src/CatchBoundary.js +123 -0
- package/build/cjs/packages/react-router/src/CatchBoundary.js.map +1 -0
- package/build/cjs/packages/react-router/src/Matches.js +235 -0
- package/build/cjs/packages/react-router/src/Matches.js.map +1 -0
- package/build/cjs/packages/react-router/src/RouterProvider.js +144 -0
- package/build/cjs/packages/react-router/src/RouterProvider.js.map +1 -0
- package/build/cjs/packages/react-router/src/awaited.js +43 -0
- package/build/cjs/packages/react-router/src/awaited.js.map +1 -0
- package/build/cjs/packages/react-router/src/defer.js +37 -0
- package/build/cjs/packages/react-router/src/defer.js.map +1 -0
- package/build/cjs/packages/react-router/src/fileRoute.js +27 -0
- package/build/cjs/packages/react-router/src/fileRoute.js.map +1 -0
- package/build/cjs/packages/react-router/src/index.js +61 -0
- package/build/cjs/packages/react-router/src/index.js.map +1 -0
- package/build/cjs/packages/react-router/src/lazyRouteComponent.js +54 -0
- package/build/cjs/packages/react-router/src/lazyRouteComponent.js.map +1 -0
- package/build/cjs/packages/react-router/src/link.js +148 -0
- package/build/cjs/packages/react-router/src/link.js.map +1 -0
- package/build/cjs/packages/react-router/src/path.js +209 -0
- package/build/cjs/packages/react-router/src/path.js.map +1 -0
- package/build/cjs/packages/react-router/src/qss.js +63 -0
- package/build/cjs/packages/react-router/src/qss.js.map +1 -0
- package/build/cjs/packages/react-router/src/react.js +634 -0
- package/build/cjs/packages/react-router/src/react.js.map +1 -0
- package/build/cjs/packages/react-router/src/redirects.js +25 -0
- package/build/cjs/packages/react-router/src/redirects.js.map +1 -0
- package/build/cjs/packages/react-router/src/route.js +134 -0
- package/build/cjs/packages/react-router/src/route.js.map +1 -0
- package/build/cjs/packages/react-router/src/router.js +1111 -0
- package/build/cjs/packages/react-router/src/router.js.map +1 -0
- package/build/cjs/packages/react-router/src/scroll-restoration.js +53 -0
- package/build/cjs/packages/react-router/src/scroll-restoration.js.map +1 -0
- package/build/cjs/packages/react-router/src/searchParams.js +81 -0
- package/build/cjs/packages/react-router/src/searchParams.js.map +1 -0
- package/build/cjs/packages/react-router/src/useBlocker.js +61 -0
- package/build/cjs/packages/react-router/src/useBlocker.js.map +1 -0
- package/build/cjs/packages/react-router/src/useNavigate.js +75 -0
- package/build/cjs/packages/react-router/src/useNavigate.js.map +1 -0
- package/build/cjs/packages/react-router/src/useParams.js +26 -0
- package/build/cjs/packages/react-router/src/useParams.js.map +1 -0
- package/build/cjs/packages/react-router/src/useSearch.js +25 -0
- package/build/cjs/packages/react-router/src/useSearch.js.map +1 -0
- package/build/cjs/packages/react-router/src/utils.js +239 -0
- package/build/cjs/packages/react-router/src/utils.js.map +1 -0
- package/build/cjs/path.js +214 -0
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/qss.js +63 -0
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/react/CatchBoundary.js +123 -0
- package/build/cjs/react/CatchBoundary.js.map +1 -0
- package/build/cjs/react/awaited.js +43 -0
- package/build/cjs/react/awaited.js.map +1 -0
- package/build/cjs/react/defer.js +37 -0
- package/build/cjs/react/defer.js.map +1 -0
- package/build/cjs/react.js +650 -0
- package/build/cjs/react.js.map +1 -0
- package/build/cjs/redirects.js +28 -0
- package/build/cjs/redirects.js.map +1 -0
- package/build/cjs/route.js +191 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +1085 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/routerConfig.js +209 -0
- package/build/cjs/routerConfig.js.map +1 -0
- package/build/cjs/scroll-restoration.js +202 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/cjs/searchParams.js +81 -0
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/src/CatchBoundary.js +126 -0
- package/build/cjs/src/CatchBoundary.js.map +1 -0
- package/build/cjs/src/Matches.js +235 -0
- package/build/cjs/src/Matches.js.map +1 -0
- package/build/cjs/src/RouterProvider.js +1051 -0
- package/build/cjs/src/RouterProvider.js.map +1 -0
- package/build/cjs/src/awaited.js +45 -0
- package/build/cjs/src/awaited.js.map +1 -0
- package/build/cjs/src/defer.js +39 -0
- package/build/cjs/src/defer.js.map +1 -0
- package/build/cjs/src/fileRoute.js +29 -0
- package/build/cjs/src/fileRoute.js.map +1 -0
- package/build/cjs/src/index.js +134 -0
- package/build/cjs/src/index.js.map +1 -0
- package/build/cjs/src/lazyRouteComponent.js +57 -0
- package/build/cjs/src/lazyRouteComponent.js.map +1 -0
- package/build/cjs/src/link.js +151 -0
- package/build/cjs/src/link.js.map +1 -0
- package/build/cjs/src/path.js +211 -0
- package/build/cjs/src/path.js.map +1 -0
- package/build/cjs/src/qss.js +65 -0
- package/build/cjs/src/qss.js.map +1 -0
- package/build/cjs/src/redirects.js +27 -0
- package/build/cjs/src/redirects.js.map +1 -0
- package/build/cjs/src/route.js +139 -0
- package/build/cjs/src/route.js.map +1 -0
- package/build/cjs/src/router.js +203 -0
- package/build/cjs/src/router.js.map +1 -0
- package/build/cjs/src/scroll-restoration.js +186 -0
- package/build/cjs/src/scroll-restoration.js.map +1 -0
- package/build/cjs/src/searchParams.js +83 -0
- package/build/cjs/src/searchParams.js.map +1 -0
- package/build/cjs/src/useBlocker.js +64 -0
- package/build/cjs/src/useBlocker.js.map +1 -0
- package/build/cjs/src/useNavigate.js +78 -0
- package/build/cjs/src/useNavigate.js.map +1 -0
- package/build/cjs/src/useParams.js +28 -0
- package/build/cjs/src/useParams.js.map +1 -0
- package/build/cjs/src/useSearch.js +27 -0
- package/build/cjs/src/useSearch.js.map +1 -0
- package/build/cjs/src/utils.js +230 -0
- package/build/cjs/src/utils.js.map +1 -0
- package/build/cjs/useBlocker.js +55 -0
- package/build/cjs/useBlocker.js.map +1 -0
- package/build/cjs/useNavigate.js +86 -0
- package/build/cjs/useNavigate.js.map +1 -0
- package/build/cjs/useParams.js +26 -0
- package/build/cjs/useParams.js.map +1 -0
- package/build/cjs/useSearch.js +25 -0
- package/build/cjs/useSearch.js.map +1 -0
- package/build/cjs/useStore.js +99 -0
- package/build/cjs/useStore.js.map +1 -0
- package/build/cjs/utils.js +241 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +2300 -2534
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +3498 -2694
- package/build/stats-react.json +1204 -44
- package/build/types/CatchBoundary.d.ts +36 -0
- package/build/types/Matches.d.ts +64 -0
- package/build/types/RouteMatch.d.ts +23 -0
- package/build/types/RouterProvider.d.ts +35 -0
- package/build/types/awaited.d.ts +9 -0
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +38 -0
- package/build/types/history.d.ts +7 -0
- package/build/types/index.d.ts +919 -58
- package/build/types/injectHtml.d.ts +0 -0
- package/build/types/lazyRouteComponent.d.ts +2 -0
- package/build/types/link.d.ts +93 -0
- package/build/types/location.d.ts +12 -0
- package/build/types/path.d.ts +17 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/react/CatchBoundary.d.ts +33 -0
- package/build/types/react/awaited.d.ts +9 -0
- package/build/types/react/defer.d.ts +19 -0
- package/build/types/react.d.ts +141 -0
- package/build/types/redirects.d.ts +11 -0
- package/build/types/route.d.ts +283 -0
- package/build/types/routeInfo.d.ts +31 -0
- package/build/types/router.d.ts +186 -0
- package/build/types/scroll-restoration.d.ts +18 -0
- package/build/types/searchParams.d.ts +7 -0
- package/build/types/useBlocker.d.ts +9 -0
- package/build/types/useNavigate.d.ts +19 -0
- package/build/types/useParams.d.ts +7 -0
- package/build/types/useSearch.d.ts +7 -0
- package/build/types/useStore.d.ts +12 -0
- package/build/types/utils.d.ts +69 -0
- package/build/umd/index.development.js +2897 -2493
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +4 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +12 -10
- package/src/CatchBoundary.tsx +101 -0
- package/src/Matches.tsx +423 -0
- package/src/RouterProvider.tsx +252 -0
- package/src/awaited.tsx +40 -0
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +152 -0
- package/src/history.ts +8 -0
- package/src/index.tsx +28 -619
- package/src/lazyRouteComponent.tsx +33 -0
- package/src/link.tsx +603 -0
- package/src/location.ts +13 -0
- package/src/path.ts +261 -0
- package/src/qss.ts +53 -0
- package/src/redirects.ts +39 -0
- package/src/route.ts +882 -0
- package/src/routeInfo.ts +84 -0
- package/src/router.ts +1671 -0
- package/src/scroll-restoration.tsx +230 -0
- package/src/searchParams.ts +79 -0
- package/src/useBlocker.tsx +27 -0
- package/src/useNavigate.tsx +111 -0
- package/src/useParams.tsx +25 -0
- package/src/useSearch.tsx +25 -0
- package/src/utils.ts +360 -0
- package/build/cjs/react-router/src/index.js +0 -458
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2524
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AnyRouteMatch } from './Matches';
|
|
3
|
+
import { NavigateOptions, ParsePathParams, ToSubOptions } from './link';
|
|
4
|
+
import { ParsedLocation } from './location';
|
|
5
|
+
import { RouteById, RouteIds, RoutePaths } from './routeInfo';
|
|
6
|
+
import { AnyRouter, RegisteredRouter } from './router';
|
|
7
|
+
import { Assign, Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
8
|
+
import { BuildLocationFn, NavigateFn } from './RouterProvider';
|
|
9
|
+
export declare const rootRouteId: "__root__";
|
|
10
|
+
export type RootRouteId = typeof rootRouteId;
|
|
11
|
+
export type AnyPathParams = {};
|
|
12
|
+
export type AnySearchSchema = {};
|
|
13
|
+
export type AnyContext = {};
|
|
14
|
+
export interface RouteContext {
|
|
15
|
+
}
|
|
16
|
+
export interface RouteMeta {
|
|
17
|
+
}
|
|
18
|
+
export type PreloadableObj = {
|
|
19
|
+
preload?: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export type RoutePathOptions<TCustomId, TPath> = {
|
|
22
|
+
path: TPath;
|
|
23
|
+
} | {
|
|
24
|
+
id: TCustomId;
|
|
25
|
+
};
|
|
26
|
+
export type RoutePathOptionsIntersection<TCustomId, TPath> = UnionToIntersection<RoutePathOptions<TCustomId, TPath>>;
|
|
27
|
+
export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
28
|
+
meta?: RouteMeta;
|
|
29
|
+
} : {
|
|
30
|
+
meta: RouteMeta;
|
|
31
|
+
};
|
|
32
|
+
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderDeps, TLoaderData> & UpdatableRouteOptions<NoInfer<TFullSearchSchema>>;
|
|
33
|
+
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
34
|
+
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
|
|
35
|
+
getParentRoute: () => TParentRoute;
|
|
36
|
+
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
37
|
+
shouldReload?: boolean | ((match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext>) => any);
|
|
38
|
+
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
39
|
+
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
40
|
+
} : {
|
|
41
|
+
beforeLoad: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
42
|
+
}) & {
|
|
43
|
+
loaderDeps?: (opts: {
|
|
44
|
+
search: TFullSearchSchema;
|
|
45
|
+
}) => TLoaderDeps;
|
|
46
|
+
loader?: RouteLoaderFn<TAllParams, NoInfer<TLoaderDeps>, NoInfer<TAllContext>, NoInfer<TRouteContext>, TLoaderData>;
|
|
47
|
+
} & ({
|
|
48
|
+
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
49
|
+
stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
|
|
50
|
+
} | {
|
|
51
|
+
stringifyParams?: never;
|
|
52
|
+
parseParams?: never;
|
|
53
|
+
});
|
|
54
|
+
type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute extends AnyRoute, TAllParams, TRouteContext> = (opts: {
|
|
55
|
+
search: TFullSearchSchema;
|
|
56
|
+
abortController: AbortController;
|
|
57
|
+
preload: boolean;
|
|
58
|
+
params: TAllParams;
|
|
59
|
+
context: TParentRoute['types']['allContext'];
|
|
60
|
+
location: ParsedLocation;
|
|
61
|
+
navigate: NavigateFn<AnyRoute>;
|
|
62
|
+
buildLocation: BuildLocationFn<TParentRoute>;
|
|
63
|
+
cause: 'preload' | 'enter' | 'stay';
|
|
64
|
+
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
65
|
+
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>> = MetaOptions & {
|
|
66
|
+
caseSensitive?: boolean;
|
|
67
|
+
wrapInSuspense?: boolean;
|
|
68
|
+
component?: RouteComponent;
|
|
69
|
+
errorComponent?: false | null | ErrorRouteComponent;
|
|
70
|
+
pendingComponent?: RouteComponent;
|
|
71
|
+
pendingMs?: number;
|
|
72
|
+
pendingMinMs?: number;
|
|
73
|
+
staleTime?: number;
|
|
74
|
+
gcTime?: number;
|
|
75
|
+
preloadStaleTime?: number;
|
|
76
|
+
preloadGcTime?: number;
|
|
77
|
+
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
78
|
+
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
79
|
+
onError?: (err: any) => void;
|
|
80
|
+
onEnter?: (match: AnyRouteMatch) => void;
|
|
81
|
+
onStay?: (match: AnyRouteMatch) => void;
|
|
82
|
+
onLeave?: (match: AnyRouteMatch) => void;
|
|
83
|
+
};
|
|
84
|
+
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
|
|
85
|
+
export type ParseParamsFn<TPath extends string, TParams> = (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
86
|
+
export type ParseParamsObj<TPath extends string, TParams> = {
|
|
87
|
+
parse?: ParseParamsFn<TPath, TParams>;
|
|
88
|
+
};
|
|
89
|
+
export type SearchSchemaValidator<TReturn> = SearchSchemaValidatorObj<TReturn> | SearchSchemaValidatorFn<TReturn>;
|
|
90
|
+
export type SearchSchemaValidatorObj<TReturn> = {
|
|
91
|
+
parse?: SearchSchemaValidatorFn<TReturn>;
|
|
92
|
+
};
|
|
93
|
+
export type SearchSchemaValidatorFn<TReturn> = (searchObj: Record<string, unknown>) => TReturn;
|
|
94
|
+
export type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
95
|
+
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
96
|
+
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
97
|
+
};
|
|
98
|
+
export type RouteLoaderFn<TAllParams = {}, TLoaderDeps extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = (match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>) => Promise<TLoaderData> | TLoaderData;
|
|
99
|
+
export interface LoaderFnContext<TAllParams = {}, TLoaderDeps extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
|
|
100
|
+
abortController: AbortController;
|
|
101
|
+
preload: boolean;
|
|
102
|
+
params: TAllParams;
|
|
103
|
+
deps: TLoaderDeps;
|
|
104
|
+
context: Expand<Assign<TAllContext, TRouteContext>>;
|
|
105
|
+
location: ParsedLocation;
|
|
106
|
+
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
107
|
+
parentMatchPromise?: Promise<void>;
|
|
108
|
+
cause: 'preload' | 'enter' | 'stay';
|
|
109
|
+
}
|
|
110
|
+
export type SearchFilter<T, U = T> = (prev: T) => U;
|
|
111
|
+
export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
|
|
112
|
+
id: infer TParentId extends string;
|
|
113
|
+
} ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId> : RootRouteId;
|
|
114
|
+
export type InferFullSearchSchema<TRoute> = TRoute extends {
|
|
115
|
+
types: {
|
|
116
|
+
fullSearchSchema: infer TFullSearchSchema;
|
|
117
|
+
};
|
|
118
|
+
} ? TFullSearchSchema : {};
|
|
119
|
+
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
|
|
120
|
+
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
121
|
+
}
|
|
122
|
+
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
|
|
123
|
+
export type ResolveAllParams<TParentRoute extends AnyRoute, TParams extends AnyPathParams> = Record<never, string> extends TParentRoute['types']['allParams'] ? TParams : Expand<UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}>;
|
|
124
|
+
export type RouteConstraints = {
|
|
125
|
+
TParentRoute: AnyRoute;
|
|
126
|
+
TPath: string;
|
|
127
|
+
TFullPath: string;
|
|
128
|
+
TCustomId: string;
|
|
129
|
+
TId: string;
|
|
130
|
+
TSearchSchema: AnySearchSchema;
|
|
131
|
+
TFullSearchSchema: AnySearchSchema;
|
|
132
|
+
TParams: Record<string, any>;
|
|
133
|
+
TAllParams: Record<string, any>;
|
|
134
|
+
TParentContext: AnyContext;
|
|
135
|
+
TRouteContext: RouteContext;
|
|
136
|
+
TAllContext: AnyContext;
|
|
137
|
+
TRouterContext: AnyContext;
|
|
138
|
+
TChildren: unknown;
|
|
139
|
+
TRouteTree: AnyRoute;
|
|
140
|
+
};
|
|
141
|
+
export declare class RouteApi<TId extends RouteIds<RegisteredRouter['routeTree']>, TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>, TFullSearchSchema extends Record<string, any> = TRoute['types']['fullSearchSchema'], TAllParams extends AnyPathParams = TRoute['types']['allParams'], TAllContext extends Record<string, any> = TRoute['types']['allContext'], TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'], TLoaderData extends any = TRoute['types']['loaderData']> {
|
|
142
|
+
id: TId;
|
|
143
|
+
constructor({ id }: {
|
|
144
|
+
id: TId;
|
|
145
|
+
});
|
|
146
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
147
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
148
|
+
} | undefined) => TSelected;
|
|
149
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
150
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
151
|
+
} | undefined) => TSelected;
|
|
152
|
+
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
153
|
+
select?: ((s: TFullSearchSchema) => TSelected) | undefined;
|
|
154
|
+
} | undefined) => TSelected;
|
|
155
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
156
|
+
select?: ((s: TAllParams) => TSelected) | undefined;
|
|
157
|
+
} | undefined) => TSelected;
|
|
158
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
159
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
160
|
+
} | undefined) => TSelected;
|
|
161
|
+
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
162
|
+
select?: ((s: TLoaderData) => TSelected) | undefined;
|
|
163
|
+
} | undefined) => TSelected;
|
|
164
|
+
}
|
|
165
|
+
export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
166
|
+
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
167
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderDeps, TLoaderData>;
|
|
168
|
+
test: Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>;
|
|
169
|
+
parentRoute: TParentRoute;
|
|
170
|
+
id: TId;
|
|
171
|
+
path: TPath;
|
|
172
|
+
fullPath: TFullPath;
|
|
173
|
+
to: TrimPathRight<TFullPath>;
|
|
174
|
+
children?: TChildren;
|
|
175
|
+
originalIndex?: number;
|
|
176
|
+
router?: AnyRouter;
|
|
177
|
+
rank: number;
|
|
178
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderDeps, TLoaderData>);
|
|
179
|
+
types: {
|
|
180
|
+
parentRoute: TParentRoute;
|
|
181
|
+
path: TPath;
|
|
182
|
+
to: TrimPathRight<TFullPath>;
|
|
183
|
+
fullPath: TFullPath;
|
|
184
|
+
customId: TCustomId;
|
|
185
|
+
id: TId;
|
|
186
|
+
searchSchema: TSearchSchema;
|
|
187
|
+
fullSearchSchema: TFullSearchSchema;
|
|
188
|
+
params: TParams;
|
|
189
|
+
allParams: TAllParams;
|
|
190
|
+
routeContext: TRouteContext;
|
|
191
|
+
allContext: TAllContext;
|
|
192
|
+
children: TChildren;
|
|
193
|
+
routeTree: TRouteTree;
|
|
194
|
+
routerContext: TRouterContext;
|
|
195
|
+
loaderData: TLoaderData;
|
|
196
|
+
loaderDeps: TLoaderDeps;
|
|
197
|
+
};
|
|
198
|
+
init: (opts: {
|
|
199
|
+
originalIndex: number;
|
|
200
|
+
}) => void;
|
|
201
|
+
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TNewChildren, TRouteTree>;
|
|
202
|
+
update: (options: UpdatableRouteOptions<TFullSearchSchema>) => this;
|
|
203
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
204
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
205
|
+
} | undefined) => TSelected;
|
|
206
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
207
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
208
|
+
} | undefined) => TSelected;
|
|
209
|
+
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
210
|
+
select?: ((search: TFullSearchSchema) => TSelected) | undefined;
|
|
211
|
+
} | undefined) => TSelected;
|
|
212
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
213
|
+
select?: ((search: TAllParams) => TSelected) | undefined;
|
|
214
|
+
} | undefined) => TSelected;
|
|
215
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
216
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
217
|
+
} | undefined) => TSelected;
|
|
218
|
+
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
219
|
+
select?: ((search: TLoaderData) => TSelected) | undefined;
|
|
220
|
+
} | undefined) => TSelected;
|
|
221
|
+
}
|
|
222
|
+
export type AnyRootRoute = RootRoute<any, any, any, any>;
|
|
223
|
+
export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteContext, TRouterContext, {}, unknown>;
|
|
224
|
+
export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> extends Route<any, // TParentRoute
|
|
225
|
+
'/', // TPath
|
|
226
|
+
'/', // TFullPath
|
|
227
|
+
string, // TCustomId
|
|
228
|
+
RootRouteId, // TId
|
|
229
|
+
TSearchSchema, // TSearchSchema
|
|
230
|
+
TSearchSchema, // TFullSearchSchema
|
|
231
|
+
{}, // TParams
|
|
232
|
+
{}, // TAllParams
|
|
233
|
+
TRouteContext, // TRouteContext
|
|
234
|
+
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
235
|
+
TRouterContext, // TRouterContext
|
|
236
|
+
TLoaderDeps, TLoaderData, any, // TChildren
|
|
237
|
+
any> {
|
|
238
|
+
constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
|
|
239
|
+
RootRouteId, // TCustomId
|
|
240
|
+
'', // TPath
|
|
241
|
+
TSearchSchema, // TSearchSchema
|
|
242
|
+
TSearchSchema, // TFullSearchSchema
|
|
243
|
+
{}, // TParams
|
|
244
|
+
{}, // TAllParams
|
|
245
|
+
TRouteContext, // TRouteContext
|
|
246
|
+
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
247
|
+
TLoaderDeps, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
248
|
+
}
|
|
249
|
+
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
250
|
+
type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
|
|
251
|
+
export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
252
|
+
export type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
253
|
+
export type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
254
|
+
export type RouteMask<TRouteTree extends AnyRoute> = {
|
|
255
|
+
routeTree: TRouteTree;
|
|
256
|
+
from: RoutePaths<TRouteTree>;
|
|
257
|
+
to?: any;
|
|
258
|
+
params?: any;
|
|
259
|
+
search?: any;
|
|
260
|
+
hash?: any;
|
|
261
|
+
state?: any;
|
|
262
|
+
unmaskOnReload?: boolean;
|
|
263
|
+
};
|
|
264
|
+
export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
|
|
265
|
+
routeTree: TRouteTree;
|
|
266
|
+
} & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
|
|
267
|
+
export type ErrorRouteProps = {
|
|
268
|
+
error: unknown;
|
|
269
|
+
info: {
|
|
270
|
+
componentStack: string;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
export type ReactNode = any;
|
|
274
|
+
export type SyncRouteComponent<TProps> = ((props: TProps) => ReactNode) | React.LazyExoticComponent<(props: TProps) => ReactNode>;
|
|
275
|
+
export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
276
|
+
preload?: () => Promise<void>;
|
|
277
|
+
};
|
|
278
|
+
export type RouteComponent<TProps = any> = SyncRouteComponent<TProps> & AsyncRouteComponent<TProps>;
|
|
279
|
+
export type ErrorRouteComponent = RouteComponent<ErrorRouteProps>;
|
|
280
|
+
export declare class NotFoundRoute<TParentRoute extends AnyRootRoute, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> extends Route<TParentRoute, '/404', '/404', '404', '404', TSearchSchema, TFullSearchSchema, {}, {}, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree> {
|
|
281
|
+
constructor(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, {}, {}, TRouteContext, TAllContext, TLoaderDeps, TLoaderData>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'>);
|
|
282
|
+
}
|
|
283
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AnyRoute, Route } from './route';
|
|
2
|
+
import { Expand, UnionToIntersection, UnionToTuple } from './utils';
|
|
3
|
+
export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
|
|
4
|
+
export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
|
|
5
|
+
[TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
|
|
6
|
+
}[string] : never : never;
|
|
7
|
+
export type RoutesById<TRouteTree extends AnyRoute> = {
|
|
8
|
+
[K in ParseRoute<TRouteTree> as K['id']]: K;
|
|
9
|
+
};
|
|
10
|
+
export type RouteById<TRouteTree extends AnyRoute, TId> = Extract<ParseRoute<TRouteTree>, {
|
|
11
|
+
id: TId;
|
|
12
|
+
}>;
|
|
13
|
+
export type RouteIds<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['id'];
|
|
14
|
+
export type RoutesByPath<TRouteTree extends AnyRoute> = {
|
|
15
|
+
[K in ParseRoute<TRouteTree> as K['fullPath']]: K;
|
|
16
|
+
};
|
|
17
|
+
export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<ParseRoute<TRouteTree>, {
|
|
18
|
+
fullPath: TPath;
|
|
19
|
+
}>;
|
|
20
|
+
export type RoutePaths<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['fullPath'] | '/';
|
|
21
|
+
type UnionizeCollisions<T, U> = {
|
|
22
|
+
[P in keyof T & keyof U]: T[P] extends U[P] ? T[P] : T[P] | U[P];
|
|
23
|
+
};
|
|
24
|
+
type Reducer<T, U, C = UnionizeCollisions<T, U>> = C & Omit<T, keyof C> & Omit<U, keyof C>;
|
|
25
|
+
type Reduce<T extends any[], Result = unknown> = T extends [
|
|
26
|
+
infer First,
|
|
27
|
+
...infer Rest
|
|
28
|
+
] ? Reduce<Rest, Reducer<Result, First>> : Result;
|
|
29
|
+
export type FullSearchSchema<TRouteTree extends AnyRoute> = Partial<Expand<Reduce<UnionToTuple<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>>>;
|
|
30
|
+
export type AllParams<TRouteTree extends AnyRoute> = Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { HistoryState, RouterHistory } from '@tanstack/history';
|
|
3
|
+
import { Store } from '@tanstack/store';
|
|
4
|
+
import { AnySearchSchema, AnyRoute, AnyContext, RouteMask } from './route';
|
|
5
|
+
import { FullSearchSchema, RoutesById, RoutesByPath } from './routeInfo';
|
|
6
|
+
import { PickAsRequired, Updater, NonNullableUpdater, Timeout } from './utils';
|
|
7
|
+
import { RouteComponent } from './route';
|
|
8
|
+
import { AnyRouteMatch, RouteMatch } from './Matches';
|
|
9
|
+
import { ParsedLocation } from './location';
|
|
10
|
+
import { SearchSerializer, SearchParser } from './searchParams';
|
|
11
|
+
import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, MatchRouteFn, NavigateFn } from './RouterProvider';
|
|
12
|
+
import { ToOptions } from './link';
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
__TSR_DEHYDRATED__?: HydrationCtx;
|
|
16
|
+
__TSR_ROUTER_CONTEXT__?: React.Context<Router<any>>;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export interface Register {
|
|
20
|
+
}
|
|
21
|
+
export type AnyRouter = Router<AnyRoute, any>;
|
|
22
|
+
export type RegisteredRouter = Register extends {
|
|
23
|
+
router: infer TRouter extends AnyRouter;
|
|
24
|
+
} ? TRouter : AnyRouter;
|
|
25
|
+
export type HydrationCtx = {
|
|
26
|
+
router: DehydratedRouter;
|
|
27
|
+
payload: Record<string, any>;
|
|
28
|
+
};
|
|
29
|
+
export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends TRouteTree['types']['routerContext'] ? {
|
|
30
|
+
context?: TRouteTree['types']['routerContext'];
|
|
31
|
+
} : {
|
|
32
|
+
context: TRouteTree['types']['routerContext'];
|
|
33
|
+
};
|
|
34
|
+
export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
35
|
+
history?: RouterHistory;
|
|
36
|
+
stringifySearch?: SearchSerializer;
|
|
37
|
+
parseSearch?: SearchParser;
|
|
38
|
+
defaultPreload?: false | 'intent';
|
|
39
|
+
defaultPreloadDelay?: number;
|
|
40
|
+
defaultComponent?: RouteComponent;
|
|
41
|
+
defaultErrorComponent?: RouteComponent;
|
|
42
|
+
defaultPendingComponent?: RouteComponent;
|
|
43
|
+
defaultPendingMs?: number;
|
|
44
|
+
defaultPendingMinMs?: number;
|
|
45
|
+
defaultStaleTime?: number;
|
|
46
|
+
defaultPreloadStaleTime?: number;
|
|
47
|
+
defaultPreloadGcTime?: number;
|
|
48
|
+
defaultGcTime?: number;
|
|
49
|
+
caseSensitive?: boolean;
|
|
50
|
+
routeTree?: TRouteTree;
|
|
51
|
+
basepath?: string;
|
|
52
|
+
context?: TRouteTree['types']['routerContext'];
|
|
53
|
+
dehydrate?: () => TDehydrated;
|
|
54
|
+
hydrate?: (dehydrated: TDehydrated) => void;
|
|
55
|
+
routeMasks?: RouteMask<TRouteTree>[];
|
|
56
|
+
unmaskOnReload?: boolean;
|
|
57
|
+
Wrap?: (props: {
|
|
58
|
+
children: any;
|
|
59
|
+
}) => JSX.Element;
|
|
60
|
+
InnerWrap?: (props: {
|
|
61
|
+
children: any;
|
|
62
|
+
}) => JSX.Element;
|
|
63
|
+
notFoundRoute?: AnyRoute;
|
|
64
|
+
}
|
|
65
|
+
export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
|
|
66
|
+
status: 'pending' | 'idle';
|
|
67
|
+
isLoading: boolean;
|
|
68
|
+
isTransitioning: boolean;
|
|
69
|
+
matches: RouteMatch<TRouteTree>[];
|
|
70
|
+
pendingMatches?: RouteMatch<TRouteTree>[];
|
|
71
|
+
cachedMatches: RouteMatch<TRouteTree>[];
|
|
72
|
+
location: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
73
|
+
resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
74
|
+
lastUpdated: number;
|
|
75
|
+
}
|
|
76
|
+
export type ListenerFn<TEvent extends RouterEvent> = (event: TEvent) => void;
|
|
77
|
+
export interface BuildNextOptions {
|
|
78
|
+
to?: string | number | null;
|
|
79
|
+
params?: true | Updater<unknown>;
|
|
80
|
+
search?: true | Updater<unknown>;
|
|
81
|
+
hash?: true | Updater<string>;
|
|
82
|
+
state?: true | NonNullableUpdater<HistoryState>;
|
|
83
|
+
mask?: {
|
|
84
|
+
to?: string | number | null;
|
|
85
|
+
params?: true | Updater<unknown>;
|
|
86
|
+
search?: true | Updater<unknown>;
|
|
87
|
+
hash?: true | Updater<string>;
|
|
88
|
+
state?: true | NonNullableUpdater<HistoryState>;
|
|
89
|
+
unmaskOnReload?: boolean;
|
|
90
|
+
};
|
|
91
|
+
from?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface DehydratedRouterState {
|
|
94
|
+
dehydratedMatches: DehydratedRouteMatch[];
|
|
95
|
+
}
|
|
96
|
+
export type DehydratedRouteMatch = Pick<RouteMatch, 'id' | 'status' | 'updatedAt'>;
|
|
97
|
+
export interface DehydratedRouter {
|
|
98
|
+
state: DehydratedRouterState;
|
|
99
|
+
}
|
|
100
|
+
export type RouterConstructorOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & RouterContextOptions<TRouteTree>;
|
|
101
|
+
export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent"];
|
|
102
|
+
export type RouterEvents = {
|
|
103
|
+
onBeforeLoad: {
|
|
104
|
+
type: 'onBeforeLoad';
|
|
105
|
+
fromLocation: ParsedLocation;
|
|
106
|
+
toLocation: ParsedLocation;
|
|
107
|
+
pathChanged: boolean;
|
|
108
|
+
};
|
|
109
|
+
onLoad: {
|
|
110
|
+
type: 'onLoad';
|
|
111
|
+
fromLocation: ParsedLocation;
|
|
112
|
+
toLocation: ParsedLocation;
|
|
113
|
+
pathChanged: boolean;
|
|
114
|
+
};
|
|
115
|
+
onResolved: {
|
|
116
|
+
type: 'onResolved';
|
|
117
|
+
fromLocation: ParsedLocation;
|
|
118
|
+
toLocation: ParsedLocation;
|
|
119
|
+
pathChanged: boolean;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export type RouterEvent = RouterEvents[keyof RouterEvents];
|
|
123
|
+
export type RouterListener<TRouterEvent extends RouterEvent> = {
|
|
124
|
+
eventType: TRouterEvent['type'];
|
|
125
|
+
fn: ListenerFn<TRouterEvent>;
|
|
126
|
+
};
|
|
127
|
+
export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
128
|
+
tempLocationKey: string | undefined;
|
|
129
|
+
resetNextScroll: boolean;
|
|
130
|
+
navigateTimeout: Timeout | null;
|
|
131
|
+
latestLoadPromise: Promise<void>;
|
|
132
|
+
subscribers: Set<RouterListener<RouterEvent>>;
|
|
133
|
+
injectedHtml: InjectedHtmlEntry[];
|
|
134
|
+
dehydratedData?: TDehydrated;
|
|
135
|
+
__store: Store<RouterState<TRouteTree>>;
|
|
136
|
+
options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
|
|
137
|
+
history: RouterHistory;
|
|
138
|
+
latestLocation: ParsedLocation;
|
|
139
|
+
basepath: string;
|
|
140
|
+
routeTree: TRouteTree;
|
|
141
|
+
routesById: RoutesById<TRouteTree>;
|
|
142
|
+
routesByPath: RoutesByPath<TRouteTree>;
|
|
143
|
+
flatRoutes: AnyRoute[];
|
|
144
|
+
constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
|
|
145
|
+
startReactTransition: (fn: () => void) => void;
|
|
146
|
+
update: (newOptions: RouterConstructorOptions<TRouteTree, TDehydrated>) => void;
|
|
147
|
+
get state(): RouterState<TRouteTree>;
|
|
148
|
+
buildRouteTree: () => void;
|
|
149
|
+
subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
|
|
150
|
+
emit: (routerEvent: RouterEvent) => void;
|
|
151
|
+
checkLatest: (promise: Promise<void>) => undefined | Promise<void>;
|
|
152
|
+
parseLocation: (previousLocation?: ParsedLocation) => ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
153
|
+
resolvePathWithBase: (from: string, path: string) => string;
|
|
154
|
+
get looseRoutesById(): Record<string, AnyRoute>;
|
|
155
|
+
matchRoutes: <TRouteTree_1 extends AnyRoute>(pathname: string, locationSearch: AnySearchSchema, opts?: {
|
|
156
|
+
throwOnError?: boolean;
|
|
157
|
+
debug?: boolean;
|
|
158
|
+
}) => RouteMatch<TRouteTree_1, import("./routeInfo").ParseRoute<TRouteTree_1>["id"]>[];
|
|
159
|
+
cancelMatch: (id: string) => void;
|
|
160
|
+
cancelMatches: () => void;
|
|
161
|
+
buildLocation: BuildLocationFn<TRouteTree>;
|
|
162
|
+
commitLocation: ({ startTransition, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
|
|
163
|
+
buildAndCommitLocation: ({ replace, resetScroll, startTransition, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
|
|
164
|
+
navigate: NavigateFn<TRouteTree>;
|
|
165
|
+
loadMatches: ({ checkLatest, matches, preload, }: {
|
|
166
|
+
checkLatest: () => Promise<void> | undefined;
|
|
167
|
+
matches: AnyRouteMatch[];
|
|
168
|
+
preload?: boolean | undefined;
|
|
169
|
+
}) => Promise<RouteMatch[]>;
|
|
170
|
+
invalidate: () => void;
|
|
171
|
+
load: () => Promise<void>;
|
|
172
|
+
cleanCache: () => void;
|
|
173
|
+
preloadRoute: (navigateOpts?: ToOptions<TRouteTree>) => Promise<RouteMatch<AnyRoute, any>[]>;
|
|
174
|
+
matchRoute: MatchRouteFn<TRouteTree>;
|
|
175
|
+
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
176
|
+
dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
177
|
+
hydrateData: <T extends unknown = unknown>(key: any) => T | undefined;
|
|
178
|
+
dehydrate: () => DehydratedRouter;
|
|
179
|
+
hydrate: (__do_not_use_server_ctx?: HydrationCtx) => Promise<void>;
|
|
180
|
+
}
|
|
181
|
+
export declare function lazyFn<T extends Record<string, (...args: any[]) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<ReturnType<T[TKey]>>;
|
|
182
|
+
export declare class SearchParamError extends Error {
|
|
183
|
+
}
|
|
184
|
+
export declare class PathParamError extends Error {
|
|
185
|
+
}
|
|
186
|
+
export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ParsedLocation } from './location';
|
|
2
|
+
export type ScrollRestorationOptions = {
|
|
3
|
+
getKey?: (location: ParsedLocation) => string;
|
|
4
|
+
};
|
|
5
|
+
export declare function useScrollRestoration(options?: ScrollRestorationOptions): void;
|
|
6
|
+
export declare function ScrollRestoration(props: ScrollRestorationOptions): null;
|
|
7
|
+
export declare function useElementScrollRestoration(options: ({
|
|
8
|
+
id: string;
|
|
9
|
+
getElement?: () => Element | undefined | null;
|
|
10
|
+
} | {
|
|
11
|
+
id?: string;
|
|
12
|
+
getElement: () => Element | undefined | null;
|
|
13
|
+
}) & {
|
|
14
|
+
getKey?: (location: ParsedLocation) => string;
|
|
15
|
+
}): {
|
|
16
|
+
scrollX: number;
|
|
17
|
+
scrollY: number;
|
|
18
|
+
} | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnySearchSchema } from './route';
|
|
2
|
+
export declare const defaultParseSearch: (searchStr: string) => AnySearchSchema;
|
|
3
|
+
export declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
4
|
+
export declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
5
|
+
export declare function stringifySearchWith(stringify: (search: any) => string, parser?: (str: string) => any): (search: Record<string, any>) => string;
|
|
6
|
+
export type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
7
|
+
export type SearchParser = (searchStr: string) => Record<string, any>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from './route';
|
|
2
|
+
import { BlockerFn } from '@tanstack/history';
|
|
3
|
+
export declare function useBlocker(blockerFn: BlockerFn, condition?: boolean | any): void;
|
|
4
|
+
export declare function Block({ blocker, condition, children }: PromptProps): any;
|
|
5
|
+
export type PromptProps = {
|
|
6
|
+
blocker: BlockerFn;
|
|
7
|
+
condition?: boolean | any;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LinkOptions, NavigateOptions } from './link';
|
|
3
|
+
import { AnyRoute } from './route';
|
|
4
|
+
import { RoutePaths } from './routeInfo';
|
|
5
|
+
import { RegisteredRouter } from './router';
|
|
6
|
+
export declare function useNavigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDefaultFrom extends RoutePaths<TRouteTree> = '/'>(defaultOpts?: {
|
|
7
|
+
from?: TDefaultFrom;
|
|
8
|
+
}): <TFrom extends RoutePaths<TRouteTree> = TDefaultFrom, TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "">(opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> | undefined) => Promise<void>;
|
|
9
|
+
export declare function Navigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): null;
|
|
10
|
+
export type UseLinkPropsOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
11
|
+
export type LinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ActiveLinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
12
|
+
children?: React.ReactNode | ((state: {
|
|
13
|
+
isActive: boolean;
|
|
14
|
+
}) => React.ReactNode);
|
|
15
|
+
};
|
|
16
|
+
export type ActiveLinkOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = LinkOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
17
|
+
activeProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
18
|
+
inactiveProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RouteIds, RouteById, AllParams } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TDefaultSelected = AllParams<TRouteTree> & RouteById<TRouteTree, TFrom>['types']['allParams'], TSelected = TDefaultSelected>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (search: TDefaultSelected) => TSelected;
|
|
7
|
+
}): TSelected;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyRoute } from './route';
|
|
2
|
+
import { RouteIds, RouteById } from './routeInfo';
|
|
3
|
+
import { RegisteredRouter } from './router';
|
|
4
|
+
import { StrictOrFrom } from './utils';
|
|
5
|
+
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TSearch = RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], TSelected = TSearch>(opts: StrictOrFrom<TFrom> & {
|
|
6
|
+
select?: (search: TSearch) => TSelected;
|
|
7
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NonNullableUpdater } from './utils';
|
|
2
|
+
export type Store<T> = {
|
|
3
|
+
getState: () => T;
|
|
4
|
+
setState: (updater: NonNullableUpdater<T>, opts?: {
|
|
5
|
+
notify?: boolean;
|
|
6
|
+
}) => void;
|
|
7
|
+
subscribe: (listener: (state: T) => void) => () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const createStore: <T>(createState: (setState: (nextState: T) => void, getState: () => T, api: Store<T>) => T, opts?: {
|
|
10
|
+
onUpdate?: ((nextState: T, prevState: T) => T) | undefined;
|
|
11
|
+
} | undefined) => Store<T>;
|
|
12
|
+
export declare function useStore<State, Slice>(store: Store<State>, selector_?: (state: State) => Slice): Slice;
|