@tanstack/react-router 0.0.1-beta.223 → 0.0.1-beta.225

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.
Files changed (65) hide show
  1. package/build/cjs/CatchBoundary.js +3 -6
  2. package/build/cjs/CatchBoundary.js.map +1 -1
  3. package/build/cjs/Matches.js +8 -15
  4. package/build/cjs/Matches.js.map +1 -1
  5. package/build/cjs/RouterProvider.js +61 -968
  6. package/build/cjs/RouterProvider.js.map +1 -1
  7. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -3
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  9. package/build/cjs/awaited.js +0 -2
  10. package/build/cjs/awaited.js.map +1 -1
  11. package/build/cjs/defer.js +0 -2
  12. package/build/cjs/defer.js.map +1 -1
  13. package/build/cjs/fileRoute.js +0 -2
  14. package/build/cjs/fileRoute.js.map +1 -1
  15. package/build/cjs/index.js +3 -16
  16. package/build/cjs/index.js.map +1 -1
  17. package/build/cjs/lazyRouteComponent.js +3 -6
  18. package/build/cjs/lazyRouteComponent.js.map +1 -1
  19. package/build/cjs/link.js +4 -7
  20. package/build/cjs/link.js.map +1 -1
  21. package/build/cjs/path.js +0 -2
  22. package/build/cjs/path.js.map +1 -1
  23. package/build/cjs/qss.js +0 -2
  24. package/build/cjs/qss.js.map +1 -1
  25. package/build/cjs/redirects.js +0 -2
  26. package/build/cjs/redirects.js.map +1 -1
  27. package/build/cjs/route.js +2 -7
  28. package/build/cjs/route.js.map +1 -1
  29. package/build/cjs/router.js +949 -42
  30. package/build/cjs/router.js.map +1 -1
  31. package/build/cjs/scroll-restoration.js +8 -15
  32. package/build/cjs/scroll-restoration.js.map +1 -1
  33. package/build/cjs/searchParams.js +0 -2
  34. package/build/cjs/searchParams.js.map +1 -1
  35. package/build/cjs/useBlocker.js +3 -6
  36. package/build/cjs/useBlocker.js.map +1 -1
  37. package/build/cjs/useNavigate.js +3 -6
  38. package/build/cjs/useNavigate.js.map +1 -1
  39. package/build/cjs/useParams.js +0 -2
  40. package/build/cjs/useParams.js.map +1 -1
  41. package/build/cjs/useSearch.js +0 -2
  42. package/build/cjs/useSearch.js.map +1 -1
  43. package/build/cjs/utils.js +9 -6
  44. package/build/cjs/utils.js.map +1 -1
  45. package/build/esm/index.js +889 -878
  46. package/build/esm/index.js.map +1 -1
  47. package/build/stats-html.html +3494 -2700
  48. package/build/stats-react.json +374 -368
  49. package/build/types/CatchBoundary.d.ts +2 -2
  50. package/build/types/Matches.d.ts +3 -3
  51. package/build/types/RouterProvider.d.ts +4 -23
  52. package/build/types/awaited.d.ts +1 -0
  53. package/build/types/fileRoute.d.ts +4 -3
  54. package/build/types/route.d.ts +1 -0
  55. package/build/types/router.d.ts +50 -5
  56. package/build/umd/index.development.js +865 -857
  57. package/build/umd/index.development.js.map +1 -1
  58. package/build/umd/index.production.js +2 -2
  59. package/build/umd/index.production.js.map +1 -1
  60. package/package.json +2 -2
  61. package/src/RouterProvider.tsx +57 -1314
  62. package/src/fileRoute.ts +1 -1
  63. package/src/route.ts +23 -0
  64. package/src/router.ts +1320 -45
  65. package/src/scroll-restoration.tsx +5 -5
@@ -4,7 +4,7 @@ export declare function CatchBoundary(props: {
4
4
  children: any;
5
5
  errorComponent?: any;
6
6
  onCatch: (error: any) => void;
7
- }): JSX.Element;
7
+ }): React.JSX.Element;
8
8
  export declare class CatchBoundaryImpl extends React.Component<{
9
9
  resetKey: string;
10
10
  children: (props: {
@@ -30,4 +30,4 @@ export declare class CatchBoundaryImpl extends React.Component<{
30
30
  }
31
31
  export declare function ErrorComponent({ error }: {
32
32
  error: any;
33
- }): JSX.Element;
33
+ }): React.JSX.Element;
@@ -28,11 +28,11 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
28
28
  cause: 'enter' | 'stay';
29
29
  }
30
30
  export type AnyRouteMatch = RouteMatch<any>;
31
- export declare function Matches(): JSX.Element;
31
+ export declare function Matches(): React.JSX.Element;
32
32
  export declare function Match({ matches }: {
33
33
  matches: RouteMatch[];
34
- }): JSX.Element;
35
- export declare function Outlet(): JSX.Element | null;
34
+ }): React.JSX.Element;
35
+ export declare function Outlet(): React.JSX.Element | null;
36
36
  export interface MatchRouteOptions {
37
37
  pending?: boolean;
38
38
  caseSensitive?: boolean;
@@ -1,9 +1,8 @@
1
- import { RouterHistory } from '@tanstack/history';
2
1
  import * as React from 'react';
3
2
  import { LinkInfo, LinkOptions, NavigateOptions, ResolveRelativePath, ToOptions } from './link';
4
3
  import { ParsedLocation } from './location';
5
4
  import { AnyRoute } from './route';
6
- import { RouteById, RoutePaths, RoutesById } from './routeInfo';
5
+ import { RouteById, RoutePaths } from './routeInfo';
7
6
  import { BuildNextOptions, DehydratedRouteMatch, RegisteredRouter, Router, RouterOptions, RouterState } from './router';
8
7
  import { NoInfer } from './utils';
9
8
  import { MatchRouteOptions } from './Matches';
@@ -29,31 +28,13 @@ export type LoadFn = (opts?: {
29
28
  }) => Promise<void>;
30
29
  export type BuildLocationFn<TRouteTree extends AnyRoute> = (opts: BuildNextOptions) => ParsedLocation;
31
30
  export type InjectedHtmlEntry = string | (() => Promise<string> | string);
32
- export type RouterContext<TRouteTree extends AnyRoute> = {
33
- buildLink: BuildLinkFn<TRouteTree>;
34
- state: RouterState<TRouteTree>;
35
- navigate: NavigateFn<TRouteTree>;
36
- matchRoute: MatchRouteFn<TRouteTree>;
37
- routeTree: TRouteTree;
38
- routesById: RoutesById<TRouteTree>;
39
- options: RouterOptions<TRouteTree>;
40
- history: RouterHistory;
41
- load: LoadFn;
42
- buildLocation: BuildLocationFn<TRouteTree>;
43
- subscribe: Router<TRouteTree>['subscribe'];
44
- resetNextScrollRef: React.MutableRefObject<boolean>;
45
- injectedHtmlRef: React.MutableRefObject<InjectedHtmlEntry[]>;
46
- injectHtml: (entry: InjectedHtmlEntry) => void;
47
- dehydrateData: <T>(key: any, getData: T | (() => Promise<T> | T)) => () => void;
48
- hydrateData: <T>(key: any) => T | undefined;
49
- };
50
- export declare const routerContext: React.Context<RouterContext<any>>;
31
+ export declare const routerContext: React.Context<Router<any, Record<string, any>>>;
51
32
  export declare class SearchParamError extends Error {
52
33
  }
53
34
  export declare class PathParamError extends Error {
54
35
  }
55
36
  export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
56
- export declare function RouterProvider<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>): JSX.Element;
37
+ export declare function RouterProvider<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>): React.JSX.Element;
57
38
  export declare function getRouteMatch<TRouteTree extends AnyRoute>(state: RouterState<TRouteTree>, id: string): undefined | RouteMatch<TRouteTree>;
58
39
  export declare function useRouterState<TSelected = RouterState<RegisteredRouter['routeTree']>>(opts?: {
59
40
  select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected;
@@ -62,4 +43,4 @@ export type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTre
62
43
  router: Router<TRouteTree>;
63
44
  context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
64
45
  };
65
- export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): RouterContext<TRouteTree>;
46
+ export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): Router<TRouteTree>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { DeferredPromise } from './defer';
2
3
  export type AwaitOptions<T> = {
3
4
  promise: DeferredPromise<T>;
@@ -1,4 +1,5 @@
1
- import { AnyRoute, ResolveFullPath, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, AnyPathParams, RootRouteId, TrimPathLeft, RouteConstraints } from './route';
1
+ import { ParsePathParams } from './link';
2
+ import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, AnyPathParams, RootRouteId, TrimPathLeft, RouteConstraints } from './route';
2
3
  import { Assign, Expand, IsAny } from './utils';
3
4
  export interface FileRoutesByPath {
4
5
  }
@@ -12,7 +13,7 @@ export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends strin
12
13
  export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
13
14
  path: TFilePath;
14
15
  constructor(path: TFilePath);
15
- createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = Expand<Assign<import("./route").InferFullSearchSchema<TParentRoute>, TSearchSchema>>, TParams extends Record<string, any> = (TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never) extends never ? AnyPathParams : Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never, string>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContext extends RouteContext = RouteContext, TContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TLoaderData>, "path" | "id" | "getParentRoute"> & {
16
+ createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = ParsePathParams<TPath> extends never ? AnyPathParams : Record<ParsePathParams<TPath>, string>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContext extends RouteContext = RouteContext, TContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TLoaderData>, "path" | "id" | "getParentRoute"> & {
16
17
  meta?: import("./route").RouteMeta | undefined;
17
18
  } & {
18
19
  caseSensitive?: boolean | undefined;
@@ -27,6 +28,6 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
27
28
  onTransition?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
28
29
  onLeave?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
29
30
  reloadOnWindowFocus?: boolean | undefined;
30
- }) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderData, TChildren, TRouteTree>;
31
+ }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderData, TChildren, TRouteTree>;
31
32
  }
32
33
  export {};
@@ -268,4 +268,5 @@ export type RouteComponent<TFullSearchSchema extends Record<string, any>, TAllPa
268
268
  export type ErrorRouteComponent<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = AsyncRouteComponent<ErrorRouteProps<TFullSearchSchema, TAllParams, TAllContext>>;
269
269
  export type PendingRouteComponent<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends Record<string, any>> = AsyncRouteComponent<PendingRouteProps<TFullSearchSchema, TAllParams, TAllContext>>;
270
270
  export type AnyRouteComponent = RouteComponent<any, any, any, any>;
271
+ export type ComponentPropsFromRoute<TRoute> = TRoute extends (() => infer T extends AnyRoute) ? ComponentPropsFromRoute<T> : TRoute extends Route<infer TParentRoute, infer TPath, infer TFullPath, infer TCustomId, infer TId, infer TSearchSchema, infer TFullSearchSchema, infer TParams, infer TAllParams, infer TRouteContext, infer TAllContext, infer TRouterContext, infer TLoaderData, infer TChildren> ? RouteProps<TFullSearchSchema, TAllParams, TAllContext, TLoaderData> : {};
271
272
  export {};
@@ -1,18 +1,19 @@
1
1
  /// <reference types="react" />
2
+ /// <reference types="node" />
2
3
  import { RouterHistory } from '@tanstack/history';
3
4
  import { AnySearchSchema, AnyRoute, AnyContext, AnyPathParams, RouteMask } from './route';
4
- import { FullSearchSchema } from './routeInfo';
5
+ import { FullSearchSchema, RoutesById, RoutesByPath } from './routeInfo';
5
6
  import { PickAsRequired, Updater, NonNullableUpdater } from './utils';
6
7
  import { ErrorRouteComponent, PendingRouteComponent, RouteComponent } from './route';
7
- import { RouteMatch } from './Matches';
8
+ import { AnyRouteMatch, RouteMatch } from './Matches';
8
9
  import { ParsedLocation } from './location';
9
10
  import { LocationState } from './location';
10
11
  import { SearchSerializer, SearchParser } from './searchParams';
11
- import { RouterContext } from './RouterProvider';
12
+ import { BuildLinkFn, BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, LoadFn, MatchRouteFn, NavigateFn } from './RouterProvider';
12
13
  declare global {
13
14
  interface Window {
14
15
  __TSR_DEHYDRATED__?: HydrationCtx;
15
- __TSR_ROUTER_CONTEXT__?: React.Context<RouterContext<any>>;
16
+ __TSR_ROUTER_CONTEXT__?: React.Context<Router<any>>;
16
17
  }
17
18
  }
18
19
  export interface Register {
@@ -113,11 +114,55 @@ export type RouterListener<TRouterEvent extends RouterEvent> = {
113
114
  fn: ListenerFn<TRouterEvent>;
114
115
  };
115
116
  export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
117
+ tempLocationKey: string | undefined;
118
+ resetNextScroll: boolean;
119
+ navigateTimeout: NodeJS.Timeout | null;
120
+ latestLoadPromise: Promise<void>;
121
+ subscribers: Set<RouterListener<RouterEvent>>;
122
+ pendingMatches: AnyRouteMatch[];
123
+ injectedHtml: InjectedHtmlEntry[];
124
+ dehydratedData?: TDehydrated;
125
+ state: RouterState<TRouteTree>;
116
126
  options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
127
+ history: RouterHistory;
128
+ latestLocation: ParsedLocation;
129
+ basepath: string;
117
130
  routeTree: TRouteTree;
131
+ routesById: RoutesById<TRouteTree>;
132
+ routesByPath: RoutesByPath<TRouteTree>;
133
+ flatRoutes: AnyRoute[];
118
134
  constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
119
- subscribers: Set<RouterListener<RouterEvent>>;
135
+ startReactTransition: (fn: () => void) => void;
136
+ setState: (fn: (s: RouterState<TRouteTree>) => RouterState<TRouteTree>) => void;
137
+ updateOptions: (newOptions: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>) => void;
138
+ buildRouteTree: () => void;
120
139
  subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
121
140
  emit: (routerEvent: RouterEvent) => void;
141
+ checkLatest: (promise: Promise<void>) => undefined | Promise<void>;
142
+ parseLocation: (previousLocation?: ParsedLocation) => ParsedLocation<FullSearchSchema<TRouteTree>>;
143
+ resolvePathWithBase: (from: string, path: string) => string;
144
+ get looseRoutesById(): Record<string, AnyRoute>;
145
+ matchRoutes: <TRouteTree_1 extends AnyRoute>(pathname: string, locationSearch: AnySearchSchema, opts?: {
146
+ throwOnError?: boolean;
147
+ debug?: boolean;
148
+ }) => RouteMatch<TRouteTree_1, import("./routeInfo").ParseRoute<TRouteTree_1>["id"]>[];
149
+ cancelMatch: (id: string) => void;
150
+ cancelMatches: () => void;
151
+ buildLocation: BuildLocationFn<TRouteTree>;
152
+ commitLocation: ({ startTransition, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
153
+ buildAndCommitLocation: ({ replace, resetScroll, startTransition, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
154
+ navigate: NavigateFn<TRouteTree>;
155
+ loadMatches: ({ checkLatest, matches, preload, }: {
156
+ checkLatest: () => Promise<void> | undefined;
157
+ matches: AnyRouteMatch[];
158
+ preload?: boolean | undefined;
159
+ }) => Promise<RouteMatch[]>;
160
+ load: LoadFn;
161
+ preloadRoute: (navigateOpts?: BuildNextOptions) => Promise<readonly [RouteMatch<AnyRoute, any>, RouteMatch<AnyRoute, any>[]]>;
162
+ buildLink: BuildLinkFn<TRouteTree>;
163
+ matchRoute: MatchRouteFn<TRouteTree>;
164
+ injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
165
+ dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
166
+ hydrateData: <T extends unknown = unknown>(key: any) => T | undefined;
122
167
  }
123
168
  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]>>;