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

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.
@@ -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,25 +28,7 @@ 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 {
@@ -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>;
@@ -12,7 +12,7 @@ export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends strin
12
12
  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
13
  path: TFilePath;
14
14
  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"> & {
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
16
  meta?: import("./route").RouteMeta | undefined;
17
17
  } & {
18
18
  caseSensitive?: boolean | undefined;
@@ -27,6 +27,6 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
27
27
  onTransition?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
28
28
  onLeave?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
29
29
  reloadOnWindowFocus?: boolean | undefined;
30
- }) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderData, TChildren, TRouteTree>;
30
+ }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderData, TChildren, TRouteTree>;
31
31
  }
32
32
  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]>>;