@tanstack/react-router 0.0.1-beta.276 → 0.0.1-beta.278
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/build/cjs/Matches.js +16 -3
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +12 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +2 -2
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +30 -6
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/Matches.d.ts +3 -0
- package/build/types/route.d.ts +12 -6
- package/build/umd/index.development.js +30 -5
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +30 -3
- package/src/route.ts +19 -6
- package/src/router.ts +2 -2
package/build/types/Matches.d.ts
CHANGED
|
@@ -55,6 +55,9 @@ export declare function useMatches<T = RouteMatch[]>(opts?: {
|
|
|
55
55
|
export declare function useParentMatches<T = RouteMatch[]>(opts?: {
|
|
56
56
|
select?: (matches: RouteMatch[]) => T;
|
|
57
57
|
}): T;
|
|
58
|
+
export declare function useLoaderDeps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<TRouteTree, TFrom>, TSelected = Required<TRouteMatch>['loaderDeps']>(opts: StrictOrFrom<TFrom> & {
|
|
59
|
+
select?: (match: TRouteMatch) => TSelected;
|
|
60
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
58
61
|
export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<TRouteTree, TFrom>, TSelected = Required<TRouteMatch>['loaderData']>(opts: StrictOrFrom<TFrom> & {
|
|
59
62
|
select?: (match: TRouteMatch) => TSelected;
|
|
60
63
|
}): TStrict extends true ? TSelected : TSelected | undefined;
|
package/build/types/route.d.ts
CHANGED
|
@@ -134,25 +134,28 @@ export type RouteConstraints = {
|
|
|
134
134
|
TChildren: unknown;
|
|
135
135
|
TRouteTree: AnyRoute;
|
|
136
136
|
};
|
|
137
|
-
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'], TLoaderData extends any = TRoute['types']['loaderData']> {
|
|
137
|
+
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']> {
|
|
138
138
|
id: TId;
|
|
139
139
|
constructor({ id }: {
|
|
140
140
|
id: TId;
|
|
141
141
|
});
|
|
142
142
|
useMatch: <TSelected = TAllContext>(opts?: {
|
|
143
|
-
select?: ((
|
|
143
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
144
144
|
} | undefined) => TSelected;
|
|
145
145
|
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
146
|
-
select?: ((
|
|
146
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
147
147
|
} | undefined) => TSelected;
|
|
148
148
|
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
149
|
-
select?: ((
|
|
149
|
+
select?: ((s: TFullSearchSchema) => TSelected) | undefined;
|
|
150
150
|
} | undefined) => TSelected;
|
|
151
151
|
useParams: <TSelected = TAllParams>(opts?: {
|
|
152
|
-
select?: ((
|
|
152
|
+
select?: ((s: TAllParams) => TSelected) | undefined;
|
|
153
|
+
} | undefined) => TSelected;
|
|
154
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
155
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
153
156
|
} | undefined) => TSelected;
|
|
154
157
|
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
155
|
-
select?: ((
|
|
158
|
+
select?: ((s: TLoaderData) => TSelected) | undefined;
|
|
156
159
|
} | undefined) => TSelected;
|
|
157
160
|
}
|
|
158
161
|
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> {
|
|
@@ -205,6 +208,9 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
205
208
|
useParams: <TSelected = TAllParams>(opts?: {
|
|
206
209
|
select?: ((search: TAllParams) => TSelected) | undefined;
|
|
207
210
|
} | undefined) => TSelected;
|
|
211
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
212
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
213
|
+
} | undefined) => TSelected;
|
|
208
214
|
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
209
215
|
select?: ((search: TLoaderData) => TSelected) | undefined;
|
|
210
216
|
} | undefined) => TSelected;
|
|
@@ -942,13 +942,14 @@
|
|
|
942
942
|
invariant(routeId, `Could not find routeId for matchId "${matchId}". Please file an issue!`);
|
|
943
943
|
const route = router.routesById[routeId];
|
|
944
944
|
const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
|
|
945
|
+
const pendingElement = PendingComponent ? /*#__PURE__*/React__namespace.createElement(PendingComponent, null) : null;
|
|
945
946
|
const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent ?? ErrorComponent;
|
|
946
947
|
const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? PendingComponent ?? route.options.component?.preload ?? route.options.pendingComponent?.preload ?? route.options.errorComponent?.preload ? React__namespace.Suspense : SafeFragment;
|
|
947
948
|
const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
|
|
948
949
|
return /*#__PURE__*/React__namespace.createElement(matchContext.Provider, {
|
|
949
950
|
value: matchId
|
|
950
951
|
}, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
|
|
951
|
-
fallback:
|
|
952
|
+
fallback: pendingElement
|
|
952
953
|
}, /*#__PURE__*/React__namespace.createElement(ResolvedCatchBoundary, {
|
|
953
954
|
getResetKey: () => router.state.resolvedLocation.state?.key,
|
|
954
955
|
errorComponent: routeErrorComponent,
|
|
@@ -957,7 +958,7 @@
|
|
|
957
958
|
}
|
|
958
959
|
}, /*#__PURE__*/React__namespace.createElement(MatchInner, {
|
|
959
960
|
matchId: matchId,
|
|
960
|
-
pendingElement:
|
|
961
|
+
pendingElement: pendingElement
|
|
961
962
|
}))));
|
|
962
963
|
}
|
|
963
964
|
function MatchInner({
|
|
@@ -977,7 +978,7 @@
|
|
|
977
978
|
}
|
|
978
979
|
if (match.status === 'pending') {
|
|
979
980
|
if (match.showPending) {
|
|
980
|
-
return pendingElement
|
|
981
|
+
return pendingElement;
|
|
981
982
|
}
|
|
982
983
|
throw match.loadPromise;
|
|
983
984
|
}
|
|
@@ -1007,6 +1008,9 @@
|
|
|
1007
1008
|
});
|
|
1008
1009
|
});
|
|
1009
1010
|
function useMatchRoute() {
|
|
1011
|
+
useRouterState({
|
|
1012
|
+
select: s => [s.location, s.resolvedLocation]
|
|
1013
|
+
});
|
|
1010
1014
|
const {
|
|
1011
1015
|
matchRoute
|
|
1012
1016
|
} = useRouter();
|
|
@@ -1071,6 +1075,14 @@
|
|
|
1071
1075
|
}
|
|
1072
1076
|
});
|
|
1073
1077
|
}
|
|
1078
|
+
function useLoaderDeps(opts) {
|
|
1079
|
+
return useMatch({
|
|
1080
|
+
...opts,
|
|
1081
|
+
select: s => {
|
|
1082
|
+
return typeof opts.select === 'function' ? opts.select(s?.loaderDeps) : s?.loaderDeps;
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1074
1086
|
function useLoaderData(opts) {
|
|
1075
1087
|
return useMatch({
|
|
1076
1088
|
...opts,
|
|
@@ -1497,6 +1509,12 @@
|
|
|
1497
1509
|
from: this.id
|
|
1498
1510
|
});
|
|
1499
1511
|
};
|
|
1512
|
+
useLoaderDeps = opts => {
|
|
1513
|
+
return useLoaderDeps({
|
|
1514
|
+
...opts,
|
|
1515
|
+
from: this.id
|
|
1516
|
+
});
|
|
1517
|
+
};
|
|
1500
1518
|
useLoaderData = opts => {
|
|
1501
1519
|
return useLoaderData({
|
|
1502
1520
|
...opts,
|
|
@@ -1583,6 +1601,12 @@
|
|
|
1583
1601
|
from: this.id
|
|
1584
1602
|
});
|
|
1585
1603
|
};
|
|
1604
|
+
useLoaderDeps = opts => {
|
|
1605
|
+
return useLoaderDeps({
|
|
1606
|
+
...opts,
|
|
1607
|
+
from: this.id
|
|
1608
|
+
});
|
|
1609
|
+
};
|
|
1586
1610
|
useLoaderData = opts => {
|
|
1587
1611
|
return useLoaderData({
|
|
1588
1612
|
...opts,
|
|
@@ -2518,9 +2542,9 @@
|
|
|
2518
2542
|
let latestPromise;
|
|
2519
2543
|
let firstBadMatchIndex;
|
|
2520
2544
|
const updateMatch = match => {
|
|
2521
|
-
const isPreload = this.state.preloadMatches.find(d => d.id === match.id)
|
|
2545
|
+
// const isPreload = this.state.preloadMatches.find((d) => d.id === match.id)
|
|
2522
2546
|
const isPending = this.state.pendingMatches?.find(d => d.id === match.id);
|
|
2523
|
-
const matchesKey =
|
|
2547
|
+
const matchesKey = preload ? 'preloadMatches' : isPending ? 'pendingMatches' : 'matches';
|
|
2524
2548
|
this.__store.setState(s => ({
|
|
2525
2549
|
...s,
|
|
2526
2550
|
[matchesKey]: s[matchesKey]?.map(d => d.id === match.id ? match : d)
|
|
@@ -3328,6 +3352,7 @@
|
|
|
3328
3352
|
exports.useLayoutEffect = useLayoutEffect$1;
|
|
3329
3353
|
exports.useLinkProps = useLinkProps;
|
|
3330
3354
|
exports.useLoaderData = useLoaderData;
|
|
3355
|
+
exports.useLoaderDeps = useLoaderDeps;
|
|
3331
3356
|
exports.useMatch = useMatch;
|
|
3332
3357
|
exports.useMatchRoute = useMatchRoute;
|
|
3333
3358
|
exports.useMatches = useMatches;
|