@tanstack/react-router 1.34.5 → 1.34.7
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/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +5 -8
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +11 -11
- package/dist/cjs/routeInfo.d.cts +6 -13
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -2
- package/dist/cjs/useBlocker.cjs +15 -14
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +3 -2
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +3 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +4 -3
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +5 -4
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +3 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +12 -9
- package/dist/esm/Matches.d.ts +5 -8
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +2 -2
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/route.d.ts +11 -11
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +6 -13
- package/dist/esm/router.d.ts +2 -2
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useBlocker.js +15 -14
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +3 -2
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useMatch.d.ts +3 -2
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useParams.d.ts +4 -3
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +5 -4
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useSearch.d.ts +3 -2
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +12 -9
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +21 -27
- package/src/fileRoute.ts +1 -1
- package/src/route.ts +13 -17
- package/src/routeInfo.ts +17 -23
- package/src/router.ts +2 -2
- package/src/useBlocker.tsx +14 -17
- package/src/useLoaderData.tsx +18 -9
- package/src/useMatch.tsx +12 -7
- package/src/useParams.tsx +14 -10
- package/src/useRouteContext.ts +16 -6
- package/src/useSearch.tsx +15 -10
- package/src/utils.ts +40 -18
package/dist/cjs/useBlocker.cjs
CHANGED
|
@@ -32,29 +32,30 @@ function useBlocker(blockerFnOrOpts, condition) {
|
|
|
32
32
|
reset: () => {
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
-
const createPromise = () => new Promise((resolve) => {
|
|
36
|
-
setResolver({
|
|
37
|
-
status: "idle",
|
|
38
|
-
proceed: () => resolve(true),
|
|
39
|
-
reset: () => resolve(false)
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
const [promise, setPromise] = React__namespace.useState(createPromise);
|
|
43
35
|
React__namespace.useEffect(() => {
|
|
44
36
|
const blockerFnComposed = async () => {
|
|
45
37
|
if (blockerFn) {
|
|
46
38
|
return await blockerFn();
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
const promise = new Promise((resolve) => {
|
|
41
|
+
setResolver({
|
|
42
|
+
status: "blocked",
|
|
43
|
+
proceed: () => resolve(true),
|
|
44
|
+
reset: () => resolve(false)
|
|
45
|
+
});
|
|
46
|
+
});
|
|
52
47
|
const canNavigateAsync = await promise;
|
|
53
|
-
|
|
48
|
+
setResolver({
|
|
49
|
+
status: "idle",
|
|
50
|
+
proceed: () => {
|
|
51
|
+
},
|
|
52
|
+
reset: () => {
|
|
53
|
+
}
|
|
54
|
+
});
|
|
54
55
|
return canNavigateAsync;
|
|
55
56
|
};
|
|
56
57
|
return !blockerCondition ? void 0 : history.block(blockerFnComposed);
|
|
57
|
-
}, [blockerFn, blockerCondition, history
|
|
58
|
+
}, [blockerFn, blockerCondition, history]);
|
|
58
59
|
return resolver;
|
|
59
60
|
}
|
|
60
61
|
function Block({ blockerFn, condition, children }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlocker.cjs","sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type { BlockerFn } from '@tanstack/history'\nimport type { ReactNode } from './route'\n\ntype BlockerResolver = {\n status: 'idle' | 'blocked'\n proceed: () => void\n reset: () => void\n}\n\ntype BlockerOpts = {\n blockerFn?: BlockerFn\n condition?: boolean | any\n}\n\nexport function useBlocker(blockerFnOrOpts?: BlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the BlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: BlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n blockerFnOrOpts?: BlockerFn | BlockerOpts,\n condition?: boolean | any,\n): BlockerResolver {\n const { blockerFn, blockerCondition } = blockerFnOrOpts\n ? typeof blockerFnOrOpts === 'function'\n ? { blockerFn: blockerFnOrOpts, blockerCondition: condition ?? true }\n : {\n blockerFn: blockerFnOrOpts.blockerFn,\n blockerCondition: blockerFnOrOpts.condition ?? true,\n }\n : { blockerFn: undefined, blockerCondition: condition ?? true }\n const { history } = useRouter()\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n proceed: () => {},\n reset: () => {},\n })\n\n
|
|
1
|
+
{"version":3,"file":"useBlocker.cjs","sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type { BlockerFn } from '@tanstack/history'\nimport type { ReactNode } from './route'\n\ntype BlockerResolver = {\n status: 'idle' | 'blocked'\n proceed: () => void\n reset: () => void\n}\n\ntype BlockerOpts = {\n blockerFn?: BlockerFn\n condition?: boolean | any\n}\n\nexport function useBlocker(blockerFnOrOpts?: BlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the BlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: BlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n blockerFnOrOpts?: BlockerFn | BlockerOpts,\n condition?: boolean | any,\n): BlockerResolver {\n const { blockerFn, blockerCondition } = blockerFnOrOpts\n ? typeof blockerFnOrOpts === 'function'\n ? { blockerFn: blockerFnOrOpts, blockerCondition: condition ?? true }\n : {\n blockerFn: blockerFnOrOpts.blockerFn,\n blockerCondition: blockerFnOrOpts.condition ?? true,\n }\n : { blockerFn: undefined, blockerCondition: condition ?? true }\n const { history } = useRouter()\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n proceed: () => {},\n reset: () => {},\n })\n\n React.useEffect(() => {\n const blockerFnComposed = async () => {\n // If a function is provided, it takes precedence over the promise blocker\n if (blockerFn) {\n return await blockerFn()\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n proceed: () => resolve(true),\n reset: () => resolve(false),\n })\n })\n\n const canNavigateAsync = await promise\n\n setResolver({\n status: 'idle',\n proceed: () => {},\n reset: () => {},\n })\n\n return canNavigateAsync\n }\n\n return !blockerCondition ? undefined : history.block(blockerFnComposed)\n }, [blockerFn, blockerCondition, history])\n\n return resolver\n}\n\nexport function Block({ blockerFn, condition, children }: PromptProps) {\n const resolver = useBlocker({ blockerFn, condition })\n return children\n ? typeof children === 'function'\n ? children(resolver)\n : children\n : null\n}\n\nexport type PromptProps = {\n blockerFn?: BlockerFn\n condition?: boolean | any\n children?: ReactNode | (({ proceed, reset }: BlockerResolver) => ReactNode)\n}\n"],"names":["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@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoaderData.cjs","sources":["../../src/useLoaderData.tsx"],"sourcesContent":["import { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n
|
|
1
|
+
{"version":3,"file":"useLoaderData.cjs","sources":["../../src/useLoaderData.tsx"],"sourcesContent":["import { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseLoaderDataOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n}\n\nexport function useLoaderData<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch extends MakeRouteMatch<\n TRouteTree,\n TFrom,\n TStrict\n > = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = Required<TRouteMatch>['loaderData'],\n>(\n opts: UseLoaderDataOptions<TFrom, TStrict, TRouteMatch, TSelected>,\n): TSelected {\n return useMatch<TRouteTree, TFrom, TStrict, TRouteMatch, TSelected>({\n ...opts,\n select: (s) => {\n return typeof opts.select === 'function'\n ? opts.select(s.loaderData as TRouteMatch)\n : (s.loaderData as TSelected)\n },\n })\n}\n"],"names":["useMatch"],"mappings":";;;AAgBO,SAAS,cAWd,MACW;AACX,SAAOA,kBAA6D;AAAA,IAClE,GAAG;AAAA,IACH,QAAQ,CAAC,MAAM;AACN,aAAA,OAAO,KAAK,WAAW,aAC1B,KAAK,OAAO,EAAE,UAAyB,IACtC,EAAE;AAAA,IACT;AAAA,EAAA,CACD;AACH;;"}
|
|
@@ -4,6 +4,7 @@ import { MakeRouteMatch } from './Matches.cjs';
|
|
|
4
4
|
import { RouteIds } from './routeInfo.cjs';
|
|
5
5
|
import { StrictOrFrom } from './utils.cjs';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export type UseLoaderDataOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
8
8
|
select?: (match: TRouteMatch) => TSelected;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
|
+
export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict> = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = Required<TRouteMatch>['loaderData']>(opts: UseLoaderDataOptions<TFrom, TStrict, TRouteMatch, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.cjs","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './Matches'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n
|
|
1
|
+
{"version":3,"file":"useMatch.cjs","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './Matches'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = TRouteMatch,\n>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected>): TSelected {\n const nearestMatchId = React.useContext(matchContext)\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = state.matches.find((d) =>\n opts.from ? opts.from === d.routeId : d.id === nearestMatchId,\n )\n\n invariant(\n match,\n `Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n\n return opts.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as TSelected\n}\n"],"names":["React","matchContext","useRouterState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,SAMd,MAA0E;AACpE,QAAA,iBAAiBA,iBAAM,WAAWC,QAAY,YAAA;AAEpD,QAAM,iBAAiBC,eAAAA,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAU;AACX,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MAAA;AAGjD;AAAA,QACE;AAAA,QACA,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAAA;AAG1F,aAAO,KAAK,SAAS,KAAK,OAAO,KAAY,IAAI;AAAA,IACnD;AAAA,EAAA,CACD;AAEM,SAAA;AACT;;"}
|
package/dist/cjs/useMatch.d.cts
CHANGED
|
@@ -4,6 +4,7 @@ import { MakeRouteMatch } from './Matches.cjs';
|
|
|
4
4
|
import { RouteIds } from './routeInfo.cjs';
|
|
5
5
|
import { StrictOrFrom } from './utils.cjs';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export type UseMatchOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
8
8
|
select?: (match: TRouteMatch) => TSelected;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
|
+
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = TRouteMatch>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParams.cjs","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { AllParams, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type {
|
|
1
|
+
{"version":3,"file":"useParams.cjs","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { AllParams, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseParamsOptions<\n TFrom,\n TStrict extends boolean,\n TParams,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (params: TParams) => TSelected\n}\n\nexport function useParams<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TParams = TStrict extends false\n ? AllParams<TRouteTree>\n : RouteById<TRouteTree, TFrom>['types']['allParams'],\n TSelected = TParams,\n>(opts: UseParamsOptions<TFrom, TStrict, TParams, TSelected>): TSelected {\n return useMatch({\n ...opts,\n select: (match) => {\n return opts.select ? opts.select(match.params as TParams) : match.params\n },\n }) as TSelected\n}\n"],"names":["useMatch"],"mappings":";;;AAeO,SAAS,UAQd,MAAuE;AACvE,SAAOA,kBAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAAU;AACjB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAiB,IAAI,MAAM;AAAA,IACpE;AAAA,EAAA,CACD;AACH;;"}
|
package/dist/cjs/useParams.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AnyRoute } from './route.cjs';
|
|
2
2
|
import { AllParams, RouteById, RouteIds } from './routeInfo.cjs';
|
|
3
3
|
import { RegisteredRouter } from './router.cjs';
|
|
4
|
-
import {
|
|
4
|
+
import { StrictOrFrom } from './utils.cjs';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type UseParamsOptions<TFrom, TStrict extends boolean, TParams, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
7
7
|
select?: (params: TParams) => TSelected;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
|
+
export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TParams = TStrict extends false ? AllParams<TRouteTree> : RouteById<TRouteTree, TFrom>['types']['allParams'], TSelected = TParams>(opts: UseParamsOptions<TFrom, TStrict, TParams, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteContext.cjs","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { AnyRoute } from './route'\nimport type { RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { StrictOrFrom } from './utils'\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext']
|
|
1
|
+
{"version":3,"file":"useRouteContext.cjs","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { AnyRoute } from './route'\nimport type { AllContext, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { Expand, StrictOrFrom } from './utils'\n\nexport type UseRouteContextOptions<\n TFrom,\n TStrict extends boolean,\n TRouteContext,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TRouteContext) => TSelected\n}\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteContext = TStrict extends false\n ? AllContext<TRouteTree>\n : Expand<RouteById<TRouteTree, TFrom>['types']['allContext']>,\n TSelected = TRouteContext,\n>(\n opts: UseRouteContextOptions<TFrom, TStrict, TRouteContext, TSelected>,\n): TSelected {\n return useMatch({\n ...(opts as any),\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) =>\n opts.select ? opts.select(match.context) : match.context,\n })\n}\n"],"names":["useMatch"],"mappings":";;;AAgBO,SAAS,gBASd,MACW;AACX,SAAOA,kBAAS;AAAA,IACd,GAAI;AAAA,IACJ,QAAQ,CAAC,UACP,KAAK,SAAS,KAAK,OAAO,MAAM,OAAO,IAAI,MAAM;AAAA,EAAA,CACpD;AACH;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AnyRoute } from './route.cjs';
|
|
2
|
-
import { RouteById, RouteIds } from './routeInfo.cjs';
|
|
2
|
+
import { AllContext, RouteById, RouteIds } from './routeInfo.cjs';
|
|
3
3
|
import { RegisteredRouter } from './router.cjs';
|
|
4
|
-
import { StrictOrFrom } from './utils.cjs';
|
|
4
|
+
import { Expand, StrictOrFrom } from './utils.cjs';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type UseRouteContextOptions<TFrom, TStrict extends boolean, TRouteContext, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
7
7
|
select?: (search: TRouteContext) => TSelected;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
|
+
export declare function useRouteContext<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteContext = TStrict extends false ? AllContext<TRouteTree> : Expand<RouteById<TRouteTree, TFrom>['types']['allContext']>, TSelected = TRouteContext>(opts: UseRouteContextOptions<TFrom, TStrict, TRouteContext, TSelected>): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.cjs","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute, RootSearchSchema } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { StrictOrFrom } from './utils'\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n
|
|
1
|
+
{"version":3,"file":"useSearch.cjs","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute, RootSearchSchema } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseSearchOptions<\n TFrom,\n TStrict extends boolean,\n TSearch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TSearch) => TSelected\n}\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TSearch = TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : Exclude<\n RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],\n RootSearchSchema\n >,\n TSelected = TSearch,\n>(opts: UseSearchOptions<TFrom, TStrict, TSearch, TSelected>): TSelected {\n return useMatch({\n ...opts,\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n })\n}\n"],"names":["useMatch"],"mappings":";;;AAgBO,SAAS,UAWd,MAAuE;AACvE,SAAOA,kBAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAA6C;AACpD,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IACzD;AAAA,EAAA,CACD;AACH;;"}
|
package/dist/cjs/useSearch.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ import { FullSearchSchema, RouteById, RouteIds } from './routeInfo.cjs';
|
|
|
3
3
|
import { RegisteredRouter } from './router.cjs';
|
|
4
4
|
import { StrictOrFrom } from './utils.cjs';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type UseSearchOptions<TFrom, TStrict extends boolean, TSearch, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
7
7
|
select?: (search: TSearch) => TSelected;
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
|
+
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TSearch = TStrict extends false ? FullSearchSchema<TRouteTree> : Exclude<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], RootSearchSchema>, TSelected = TSearch>(opts: UseSearchOptions<TFrom, TStrict, TSearch, TSelected>): TSelected;
|
package/dist/cjs/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<T> = (\n T extends any ? (k: T) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = Omit<\n TRight,\n keyof TLeft\n> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n}\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type Assign<TLeft, TRight> = keyof TLeft extends never\n ? TRight\n : keyof TRight extends never\n ? TLeft\n : Omit<TLeft, keyof TRight> & TRight\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\n// from https://github.com/type-challenges/type-challenges/issues/737\ntype LastInUnion<T> =\n UnionToIntersection<T extends unknown ? (x: T) => 0 : never> extends (\n x: infer L,\n ) => 0\n ? L\n : never\nexport type UnionToTuple<T, TLast = LastInUnion<T>> = [T] extends [never]\n ? []\n : [...UnionToTuple<Exclude<T, TLast>>, TLast]\n\n//\n\nexport function last<T>(arr: Array<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nexport function pick<TValue, TKey extends keyof TValue>(\n parent: TValue,\n keys: Array<TKey>,\n): Pick<TValue, TKey> {\n return keys.reduce((obj: any, key: TKey) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevItems = array ? prev : Object.keys(prev)\n const prevSize = prevItems.length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n if (\n ((!array && prevItems.includes(key)) || array) &&\n prev[key] === undefined &&\n next[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key] && prev[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\nexport function deepEqual(a: any, b: any, partial: boolean = false): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n\n if (!partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return !bKeys.some(\n (key) => !(key in a) || !deepEqual(a[key], b[key], partial),\n )\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return !a.some((item, index) => !deepEqual(item, b[index], partial))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (const item of keysA) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, item) ||\n !Object.is(objA[item as keyof T], objB[item as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type StrictOrFrom<TFrom, TReturnIntersection extends boolean = false> =\n | {\n from: StringLiteral<TFrom> | TFrom\n strict?: true\n }\n | {\n from?: never\n strict: false\n experimental_returnIntersection?: TReturnIntersection\n }\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n *\n * @deprecated use `jsesc` instead\n */\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n\nexport function removeTrailingSlash(value: string): string {\n if (value.endsWith('/') && value !== '/') {\n return value.slice(0, -1)\n }\n return value\n}\n\n// intended to only compare path name\n// see the usage in the isActive under useLinkProps\n// /sample/path1 = /sample/path1/\n// /sample/path1/some <> /sample/path1\nexport function exactPathTest(pathName1: string, pathName2: string): boolean {\n return removeTrailingSlash(pathName1) === removeTrailingSlash(pathName2)\n}\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n}\n\nexport function createControlledPromise<T>(onResolve?: () => void) {\n let resolveLoadPromise!: () => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<void>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = () => {\n controlledPromise.status = 'resolved'\n resolveLoadPromise()\n onResolve?.()\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\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,QAAM,oBAAoB,IAAI,QAAc,CAAC,SAAS,WAAW;AAC1C,yBAAA;AACD,wBAAA;AAAA,EAAA,CACrB;AAED,oBAAkB,SAAS;AAE3B,oBAAkB,UAAU,MAAM;AAChC,sBAAkB,SAAS;AACR;AACP;AAAA,EAAA;AAGI,oBAAA,SAAS,CAAC,MAAM;AAChC,sBAAkB,SAAS;AAC3B,sBAAkB,CAAC;AAAA,EAAA;AAGd,SAAA;AACT;AAKO,SAAS,YAAe,OAAoB;AAE3C,QAAA,MAAMA,iBAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAEK,QAAA,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<T> = (\n T extends any ? (k: T) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = Omit<\n TRight,\n keyof TLeft\n> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n}\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type Assign<TLeft, TRight> = keyof TLeft extends never\n ? TRight\n : keyof TRight extends never\n ? TLeft\n : Omit<TLeft, keyof TRight> & TRight\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type MergeUnionObjects<TUnion> = TUnion extends MergeUnionPrimitive\n ? never\n : TUnion\n\nexport type MergeUnionObject<TUnion> =\n MergeUnionObjects<TUnion> extends infer TObj\n ? {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeUnionPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n\nexport type MergeUnionPrimitives<TUnion> = TUnion extends MergeUnionPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type MergeUnion<TUnion> =\n | MergeUnionPrimitives<TUnion>\n | MergeUnionObject<MergeUnionObjects<TUnion>>\n\nexport function last<T>(arr: Array<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nexport function pick<TValue, TKey extends keyof TValue>(\n parent: TValue,\n keys: Array<TKey>,\n): Pick<TValue, TKey> {\n return keys.reduce((obj: any, key: TKey) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevItems = array ? prev : Object.keys(prev)\n const prevSize = prevItems.length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n if (\n ((!array && prevItems.includes(key)) || array) &&\n prev[key] === undefined &&\n next[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key] && prev[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\nexport function deepEqual(a: any, b: any, partial: boolean = false): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n\n if (!partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return !bKeys.some(\n (key) => !(key in a) || !deepEqual(a[key], b[key], partial),\n )\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return !a.some((item, index) => !deepEqual(item, b[index], partial))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (const item of keysA) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, item) ||\n !Object.is(objA[item as keyof T], objB[item as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type StrictOrFrom<\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: StringLiteral<TFrom> | TFrom\n strict?: TStrict\n }\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n *\n * @deprecated use `jsesc` instead\n */\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n\nexport function removeTrailingSlash(value: string): string {\n if (value.endsWith('/') && value !== '/') {\n return value.slice(0, -1)\n }\n return value\n}\n\n// intended to only compare path name\n// see the usage in the isActive under useLinkProps\n// /sample/path1 = /sample/path1/\n// /sample/path1/some <> /sample/path1\nexport function exactPathTest(pathName1: string, pathName2: string): boolean {\n return removeTrailingSlash(pathName1) === removeTrailingSlash(pathName2)\n}\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n}\n\nexport function createControlledPromise<T>(onResolve?: () => void) {\n let resolveLoadPromise!: () => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<void>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = () => {\n controlledPromise.status = 'resolved'\n resolveLoadPromise()\n onResolve?.()\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwGO,SAAS,KAAQ,KAAe;AAC9B,SAAA,IAAI,IAAI,SAAS,CAAC;AAC3B;AAEA,SAAS,WAAW,GAAuB;AACzC,SAAO,OAAO,MAAM;AACtB;AAEgB,SAAA,iBACd,SACA,UACS;AACL,MAAA,WAAW,OAAO,GAAG;AACvB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEO,SAAA;AACT;AAEgB,SAAA,KACd,QACA,MACoB;AACpB,SAAO,KAAK,OAAO,CAAC,KAAU,QAAc;AACtC,QAAA,GAAG,IAAI,OAAO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AI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/utils.d.cts
CHANGED
|
@@ -21,8 +21,13 @@ export type Assign<TLeft, TRight> = keyof TLeft extends never ? TRight : keyof T
|
|
|
21
21
|
export type Timeout = ReturnType<typeof setTimeout>;
|
|
22
22
|
export type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
23
23
|
export type NonNullableUpdater<TPrevious, TResult = TPrevious> = TResult | ((prev: TPrevious) => TResult);
|
|
24
|
-
type
|
|
25
|
-
export type
|
|
24
|
+
export type MergeUnionObjects<TUnion> = TUnion extends MergeUnionPrimitive ? never : TUnion;
|
|
25
|
+
export type MergeUnionObject<TUnion> = MergeUnionObjects<TUnion> extends infer TObj ? {
|
|
26
|
+
[TKey in TObj extends any ? keyof TObj : never]?: TObj extends any ? TKey extends keyof TObj ? TObj[TKey] : never : never;
|
|
27
|
+
} : never;
|
|
28
|
+
export type MergeUnionPrimitive = ReadonlyArray<any> | number | string | bigint | boolean | symbol;
|
|
29
|
+
export type MergeUnionPrimitives<TUnion> = TUnion extends MergeUnionPrimitive ? TUnion : TUnion extends object ? never : TUnion;
|
|
30
|
+
export type MergeUnion<TUnion> = MergeUnionPrimitives<TUnion> | MergeUnionObject<MergeUnionObjects<TUnion>>;
|
|
26
31
|
export declare function last<T>(arr: Array<T>): T | undefined;
|
|
27
32
|
export declare function functionalUpdate<TResult>(updater: Updater<TResult> | NonNullableUpdater<TResult>, previous: TResult): TResult;
|
|
28
33
|
export declare function pick<TValue, TKey extends keyof TValue>(parent: TValue, keys: Array<TKey>): Pick<TValue, TKey>;
|
|
@@ -39,13 +44,12 @@ export declare function deepEqual(a: any, b: any, partial?: boolean): boolean;
|
|
|
39
44
|
export declare function useStableCallback<T extends (...args: Array<any>) => any>(fn: T): T;
|
|
40
45
|
export declare function shallow<T>(objA: T, objB: T): boolean;
|
|
41
46
|
export type StringLiteral<T> = T extends string ? string extends T ? string : T : never;
|
|
42
|
-
export type StrictOrFrom<TFrom,
|
|
43
|
-
from: StringLiteral<TFrom> | TFrom;
|
|
44
|
-
strict?: true;
|
|
45
|
-
} | {
|
|
47
|
+
export type StrictOrFrom<TFrom, TStrict extends boolean = true> = TStrict extends false ? {
|
|
46
48
|
from?: never;
|
|
47
|
-
strict:
|
|
48
|
-
|
|
49
|
+
strict: TStrict;
|
|
50
|
+
} : {
|
|
51
|
+
from: StringLiteral<TFrom> | TFrom;
|
|
52
|
+
strict?: TStrict;
|
|
49
53
|
};
|
|
50
54
|
export declare const useLayoutEffect: typeof React.useLayoutEffect;
|
|
51
55
|
/**
|
|
@@ -65,4 +69,3 @@ export declare function createControlledPromise<T>(onResolve?: () => void): Cont
|
|
|
65
69
|
* Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3
|
|
66
70
|
*/
|
|
67
71
|
export declare function usePrevious<T>(value: T): T | null;
|
|
68
|
-
export {};
|
package/dist/esm/Matches.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyRouter, RegisteredRouter } from './router.js';
|
|
2
2
|
import { AnyRoute, ReactNode, StaticDataRouteOption } from './route.js';
|
|
3
3
|
import { ResolveRelativePath, ToOptions } from './link.js';
|
|
4
|
-
import { AllParams, FullSearchSchema, ParseRoute, RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo.js';
|
|
4
|
+
import { AllContext, AllLoaderData, AllParams, FullSearchSchema, ParseRoute, RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo.js';
|
|
5
5
|
import { ControlledPromise, DeepPartial, NoInfer } from './utils.js';
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
export declare const matchContext: React.Context<string | undefined>;
|
|
@@ -36,7 +36,7 @@ export interface RouteMatch<TRouteId, TAllParams, TFullSearchSchema, TLoaderData
|
|
|
36
36
|
staticData: StaticDataRouteOption;
|
|
37
37
|
minPendingPromise?: ControlledPromise<void>;
|
|
38
38
|
}
|
|
39
|
-
export type MakeRouteMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId = ParseRoute<TRouteTree>['id'],
|
|
39
|
+
export type MakeRouteMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId = ParseRoute<TRouteTree>['id'], TStrict extends boolean = true, TTypes extends AnyRoute['types'] = RouteById<TRouteTree, TRouteId>['types'], TAllParams = TStrict extends false ? AllParams<TRouteTree> : TTypes['allParams'], TFullSearchSchema = TStrict extends false ? FullSearchSchema<TRouteTree> : TTypes['fullSearchSchema'], TLoaderData = TStrict extends false ? AllLoaderData<TRouteTree> : TTypes['loaderData'], TAllContext = TStrict extends false ? AllContext<TRouteTree> : TTypes['allContext'], TRouteContext = TTypes['routeContext'], TLoaderDeps = TTypes['loaderDeps']> = RouteMatch<TRouteId, TAllParams, TFullSearchSchema, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>;
|
|
40
40
|
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>;
|
|
41
41
|
export declare function Matches(): React.JSX.Element;
|
|
42
42
|
export declare function Match({ matchId }: {
|
|
@@ -55,17 +55,14 @@ export type MakeMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter,
|
|
|
55
55
|
children?: ((params?: RouteByPath<TRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
|
|
56
56
|
};
|
|
57
57
|
export declare function MatchRoute<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<TRouter['routeTree']>, TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom, TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any;
|
|
58
|
-
export declare function useMatches<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
58
|
+
export declare function useMatches<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'], TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>, T = Array<TRouteMatch>>(opts?: {
|
|
59
59
|
select?: (matches: Array<TRouteMatch>) => T;
|
|
60
|
-
experimental_returnIntersection?: TReturnIntersection;
|
|
61
60
|
}): T;
|
|
62
|
-
export declare function useParentMatches<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
61
|
+
export declare function useParentMatches<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'], TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>, T = Array<TRouteMatch>>(opts?: {
|
|
63
62
|
select?: (matches: Array<TRouteMatch>) => T;
|
|
64
|
-
experimental_returnIntersection?: TReturnIntersection;
|
|
65
63
|
}): T;
|
|
66
|
-
export declare function useChildMatches<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
64
|
+
export declare function useChildMatches<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'], TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>, T = Array<TRouteMatch>>(opts?: {
|
|
67
65
|
select?: (matches: Array<TRouteMatch>) => T;
|
|
68
|
-
experimental_returnIntersection?: TReturnIntersection;
|
|
69
66
|
}): T;
|
|
70
67
|
export declare function isServerSideError(error: unknown): error is {
|
|
71
68
|
__isServerError: true;
|
package/dist/esm/Matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { createControlledPromise, pick } from './utils'\nimport { CatchNotFound, DefaultGlobalNotFound, isNotFound } from './not-found'\nimport { isRedirect } from './redirects'\nimport { type AnyRouter, type RegisteredRouter } from './router'\nimport { Transitioner } from './Transitioner'\nimport {\n type AnyRoute,\n type ReactNode,\n type StaticDataRouteOption,\n} from './route'\nimport { rootRouteId } from './root'\nimport type { ResolveRelativePath, ToOptions } from './link'\nimport type {\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport type { ControlledPromise, DeepPartial, NoInfer } from './utils'\n\nexport const matchContext = React.createContext<string | undefined>(undefined)\n\nexport interface RouteMatch<\n TRouteId,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps,\n> {\n id: string\n routeId: TRouteId\n pathname: string\n params: TAllParams\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: false | 'beforeLoad' | 'loader'\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise: ControlledPromise<void>\n loaderPromise: Promise<TLoaderData>\n loaderData?: TLoaderData\n routeContext: TRouteContext\n context: TAllContext\n search: TFullSearchSchema\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: TLoaderDeps\n preload: boolean\n invalid: boolean\n meta?: Array<React.JSX.IntrinsicElements['meta']>\n links?: Array<React.JSX.IntrinsicElements['link']>\n scripts?: Array<React.JSX.IntrinsicElements['script']>\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n minPendingPromise?: ControlledPromise<void>\n}\n\nexport type MakeRouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TTypes extends AnyRoute['types'] = RouteById<TRouteTree, TRouteId>['types'],\n TAllParams = TReturnIntersection extends false\n ? TTypes['allParams']\n : Partial<AllParams<TRouteTree>>,\n TFullSearchSchema = TReturnIntersection extends false\n ? TTypes['fullSearchSchema']\n : Partial<FullSearchSchema<TRouteTree>>,\n TLoaderData = TTypes['loaderData'],\n TAllContext = TTypes['allContext'],\n TRouteContext = TTypes['routeContext'],\n TLoaderDeps = TTypes['loaderDeps'],\n> = RouteMatch<\n TRouteId,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n>\n\nexport type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>\n\nexport function Matches() {\n const router = useRouter()\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n const ResolvedSuspense = !router.state.matches.length\n ? React.Suspense\n : SafeFragment\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n <Transitioner />\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const matchId = useRouterState({\n select: (s) => {\n return s.matches[0]?.id\n },\n })\n\n const resetKey = useRouterState({\n select: (s) => s.resolvedLocation.state.key!,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={(error) => {\n warning(\n false,\n `The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n warning(false, error.message || error.toString())\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction SafeFragment(props: any) {\n return <>{props.children}</>\n}\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route: AnyRoute = router.routesById[routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component\n : route.options.notFoundComponent\n\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n (route.options.errorComponent as any)?.preload)\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const resetKey = useRouterState({\n select: (s) => s.resolvedLocation.state.key!,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n <MatchInner matchId={matchId} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction MatchInner({ matchId }: { matchId: string }): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const match = useRouterState({\n select: (s) =>\n pick(s.matches.find((d) => d.id === matchId)!, [\n 'id',\n 'status',\n 'error',\n 'loadPromise',\n 'minPendingPromise',\n ]),\n })\n\n const RouteErrorComponent =\n (route.options.errorComponent ?? router.options.defaultErrorComponent) ||\n ErrorComponent\n\n if (match.status === 'notFound') {\n let error: unknown\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n\n error = deserializeError(match.error.data)\n } else {\n error = match.error\n }\n\n invariant(isNotFound(error), 'Expected a notFound error')\n\n return renderRouteNotFound(router, route, error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n\n throw match.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (router.isServer) {\n return (\n <RouteErrorComponent\n error={match.error}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n\n if (pendingMinMs && !match.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n\n match.minPendingPromise = createControlledPromise()\n\n if (!router.isServer) {\n Promise.resolve().then(() => {\n router.__store.setState((s) => ({\n ...s,\n matches: s.matches.map((d) =>\n d.id === match.id\n ? { ...d, minPendingPromise: createControlledPromise() }\n : d,\n ),\n }))\n })\n\n setTimeout(() => {\n // We've handled the minPendingPromise, so we can delete it\n router.__store.setState((s) => {\n return {\n ...s,\n matches: s.matches.map((d) =>\n d.id === match.id\n ? {\n ...d,\n minPendingPromise:\n (d.minPendingPromise?.resolve(), undefined),\n }\n : d,\n ),\n }\n })\n }, pendingMinMs)\n }\n }\n\n throw match.loadPromise\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (match.status === 'success') {\n const Comp = route.options.component ?? router.options.defaultComponent\n\n if (Comp) {\n return <Comp />\n }\n\n return <Outlet />\n }\n\n invariant(\n false,\n 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const { parentGlobalNotFound } = useRouterState({\n select: (s) => {\n const matches = s.matches\n const parentMatch = matches.find((d) => d.id === matchId)\n invariant(\n parentMatch,\n `Could not find parent match for matchId \"${matchId}\"`,\n )\n return {\n parentGlobalNotFound: parentMatch.globalNotFound,\n }\n },\n })\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = s.matches\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (matchId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n\nfunction renderRouteNotFound(router: AnyRouter, route: AnyRoute, data: any) {\n if (!route.options.notFoundComponent) {\n if (router.options.defaultNotFoundComponent) {\n return <router.options.defaultNotFoundComponent data={data} />\n }\n\n if (process.env.NODE_ENV === 'development') {\n warning(\n route.options.notFoundComponent,\n `A notFoundError was encountered on the route with ID \"${route.id}\", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`,\n )\n }\n\n return <DefaultGlobalNotFound />\n }\n\n return <route.options.notFoundComponent data={data} />\n}\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n TOptions extends ToOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n TRelaxedOptions = Omit<TOptions, 'search' | 'params'> &\n DeepPartial<Pick<TOptions, 'search' | 'params'>>,\n> = TRelaxedOptions & MatchRouteOptions\n\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | RouteById<TRouter['routeTree'], TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouter['routeTree'],\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n}\n\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any)\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return params ? props.children : null\n}\n\nexport function useMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = Array<TRouteMatch>,\n>(opts?: {\n select?: (matches: Array<TRouteMatch>) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n return useRouterState({\n select: (state) => {\n const matches = state.matches\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = Array<TRouteMatch>,\n>(opts?: {\n select?: (matches: Array<TRouteMatch>) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useChildMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TReturnIntersection extends boolean = false,\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId, TReturnIntersection>,\n T = Array<TRouteMatch>,\n>(opts?: {\n select?: (matches: Array<TRouteMatch>) => T\n experimental_returnIntersection?: TReturnIntersection\n}): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function isServerSideError(error: unknown): error is {\n __isServerError: true\n data: Record<string, any>\n} {\n if (!(typeof error === 'object' && error && 'data' in error)) return false\n if (!('__isServerError' in error && error.__isServerError)) return false\n if (!(typeof error.data === 'object' && error.data)) return false\n\n return error.__isServerError === true\n}\n\nexport function defaultDeserializeError(serializedData: Record<string, any>) {\n if ('name' in serializedData && 'message' in serializedData) {\n const error = new Error(serializedData.message)\n error.name = serializedData.name\n if (process.env.NODE_ENV === 'development') {\n error.stack = serializedData.stack\n }\n return error\n }\n\n return serializedData.data\n}\n"],"names":["_a","Outlet"],"mappings":";;;;;;;;;;;;AA6Ba,MAAA,eAAe,MAAM,cAAkC,MAAS;AAqEtE,SAAS,UAAU;AACxB,QAAM,SAAS;AAET,QAAA,iBAAiB,OAAO,QAAQ,8CACnC,OAAO,QAAQ,yBAAf,CAAuC,CAAA,IACtC;AAEJ,QAAM,mBAAmB,CAAC,OAAO,MAAM,QAAQ,SAC3C,MAAM,WACN;AAEJ,QAAM,QACJ,qBAAC,kBAAiB,EAAA,UAAU,gBAC1B,UAAA;AAAA,IAAA,oBAAC,cAAa,EAAA;AAAA,wBACb,cAAa,EAAA;AAAA,EAChB,EAAA,CAAA;AAGK,SAAA,OAAO,QAAQ,YACpB,oBAAC,OAAO,QAAQ,WAAf,EAA0B,UAAA,MAAM,CAAA,IAEjC;AAEJ;AAEA,SAAS,eAAe;AACtB,QAAM,UAAU,eAAe;AAAA,IAC7B,QAAQ,CAAC,MAAM;;AACN,cAAA,OAAE,QAAQ,CAAC,MAAX,mBAAc;AAAA,IACvB;AAAA,EAAA,CACD;AAED,QAAM,WAAW,eAAe;AAAA,IAC9B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,MAAM;AAAA,EAAA,CACzC;AAED,SACG,oBAAA,aAAa,UAAb,EAAsB,OAAO,SAC5B,UAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAa,MAAM;AAAA,MACnB,gBAAgB;AAAA,MAChB,SAAS,CAAC,UAAU;AAClB;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAEF,gBAAQ,OAAO,MAAM,WAAW,MAAM,UAAU;AAAA,MAClD;AAAA,MAEC,UAAU,UAAA,oBAAC,OAAM,EAAA,QAAkB,CAAA,IAAK;AAAA,IAAA;AAAA,EAE7C,EAAA,CAAA;AAEJ;AAEA,SAAS,aAAa,OAAY;AACzB,SAAA,oBAAA,UAAA,E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B;"}
|
|
1
|
+
{"version":3,"file":"Matches.js","sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { createControlledPromise, pick } from './utils'\nimport { CatchNotFound, DefaultGlobalNotFound, isNotFound } from './not-found'\nimport { isRedirect } from './redirects'\nimport { type AnyRouter, type RegisteredRouter } from './router'\nimport { Transitioner } from './Transitioner'\nimport {\n type AnyRoute,\n type ReactNode,\n type StaticDataRouteOption,\n} from './route'\nimport { rootRouteId } from './root'\nimport type { ResolveRelativePath, ToOptions } from './link'\nimport type {\n AllContext,\n AllLoaderData,\n AllParams,\n FullSearchSchema,\n ParseRoute,\n RouteById,\n RouteByPath,\n RouteIds,\n RoutePaths,\n} from './routeInfo'\nimport type { ControlledPromise, DeepPartial, NoInfer } from './utils'\n\nexport const matchContext = React.createContext<string | undefined>(undefined)\n\nexport interface RouteMatch<\n TRouteId,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps,\n> {\n id: string\n routeId: TRouteId\n pathname: string\n params: TAllParams\n status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'\n isFetching: false | 'beforeLoad' | 'loader'\n error: unknown\n paramsError: unknown\n searchError: unknown\n updatedAt: number\n loadPromise: ControlledPromise<void>\n loaderPromise: Promise<TLoaderData>\n loaderData?: TLoaderData\n routeContext: TRouteContext\n context: TAllContext\n search: TFullSearchSchema\n fetchCount: number\n abortController: AbortController\n cause: 'preload' | 'enter' | 'stay'\n loaderDeps: TLoaderDeps\n preload: boolean\n invalid: boolean\n meta?: Array<React.JSX.IntrinsicElements['meta']>\n links?: Array<React.JSX.IntrinsicElements['link']>\n scripts?: Array<React.JSX.IntrinsicElements['script']>\n headers?: Record<string, string>\n globalNotFound?: boolean\n staticData: StaticDataRouteOption\n minPendingPromise?: ControlledPromise<void>\n}\n\nexport type MakeRouteMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId = ParseRoute<TRouteTree>['id'],\n TStrict extends boolean = true,\n TTypes extends AnyRoute['types'] = RouteById<TRouteTree, TRouteId>['types'],\n TAllParams = TStrict extends false\n ? AllParams<TRouteTree>\n : TTypes['allParams'],\n TFullSearchSchema = TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : TTypes['fullSearchSchema'],\n TLoaderData = TStrict extends false\n ? AllLoaderData<TRouteTree>\n : TTypes['loaderData'],\n TAllContext = TStrict extends false\n ? AllContext<TRouteTree>\n : TTypes['allContext'],\n TRouteContext = TTypes['routeContext'],\n TLoaderDeps = TTypes['loaderDeps'],\n> = RouteMatch<\n TRouteId,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n>\n\nexport type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>\n\nexport function Matches() {\n const router = useRouter()\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n const ResolvedSuspense = !router.state.matches.length\n ? React.Suspense\n : SafeFragment\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n <Transitioner />\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const matchId = useRouterState({\n select: (s) => {\n return s.matches[0]?.id\n },\n })\n\n const resetKey = useRouterState({\n select: (s) => s.resolvedLocation.state.key!,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={(error) => {\n warning(\n false,\n `The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n warning(false, error.message || error.toString())\n }}\n >\n {matchId ? <Match matchId={matchId} /> : null}\n </CatchBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction SafeFragment(props: any) {\n return <>{props.children}</>\n}\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route: AnyRoute = router.routesById[routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component\n : route.options.notFoundComponent\n\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n (route.options.errorComponent as any)?.preload)\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const resetKey = useRouterState({\n select: (s) => s.resolvedLocation.state.key!,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n <MatchInner matchId={matchId} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\n\nfunction MatchInner({ matchId }: { matchId: string }): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const match = useRouterState({\n select: (s) =>\n pick(s.matches.find((d) => d.id === matchId)!, [\n 'id',\n 'status',\n 'error',\n 'loadPromise',\n 'minPendingPromise',\n ]),\n })\n\n const RouteErrorComponent =\n (route.options.errorComponent ?? router.options.defaultErrorComponent) ||\n ErrorComponent\n\n if (match.status === 'notFound') {\n let error: unknown\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n\n error = deserializeError(match.error.data)\n } else {\n error = match.error\n }\n\n invariant(isNotFound(error), 'Expected a notFound error')\n\n return renderRouteNotFound(router, route, error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n\n throw match.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (router.isServer) {\n return (\n <RouteErrorComponent\n error={match.error}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n\n if (pendingMinMs && !match.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n\n match.minPendingPromise = createControlledPromise()\n\n if (!router.isServer) {\n Promise.resolve().then(() => {\n router.__store.setState((s) => ({\n ...s,\n matches: s.matches.map((d) =>\n d.id === match.id\n ? { ...d, minPendingPromise: createControlledPromise() }\n : d,\n ),\n }))\n })\n\n setTimeout(() => {\n // We've handled the minPendingPromise, so we can delete it\n router.__store.setState((s) => {\n return {\n ...s,\n matches: s.matches.map((d) =>\n d.id === match.id\n ? {\n ...d,\n minPendingPromise:\n (d.minPendingPromise?.resolve(), undefined),\n }\n : d,\n ),\n }\n })\n }, pendingMinMs)\n }\n }\n\n throw match.loadPromise\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (match.status === 'success') {\n const Comp = route.options.component ?? router.options.defaultComponent\n\n if (Comp) {\n return <Comp />\n }\n\n return <Outlet />\n }\n\n invariant(\n false,\n 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!',\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const { parentGlobalNotFound } = useRouterState({\n select: (s) => {\n const matches = s.matches\n const parentMatch = matches.find((d) => d.id === matchId)\n invariant(\n parentMatch,\n `Could not find parent match for matchId \"${matchId}\"`,\n )\n return {\n parentGlobalNotFound: parentMatch.globalNotFound,\n }\n },\n })\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = s.matches\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (matchId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n\nfunction renderRouteNotFound(router: AnyRouter, route: AnyRoute, data: any) {\n if (!route.options.notFoundComponent) {\n if (router.options.defaultNotFoundComponent) {\n return <router.options.defaultNotFoundComponent data={data} />\n }\n\n if (process.env.NODE_ENV === 'development') {\n warning(\n route.options.notFoundComponent,\n `A notFoundError was encountered on the route with ID \"${route.id}\", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`,\n )\n }\n\n return <DefaultGlobalNotFound />\n }\n\n return <route.options.notFoundComponent data={data} />\n}\n\nexport interface MatchRouteOptions {\n pending?: boolean\n caseSensitive?: boolean\n includeSearch?: boolean\n fuzzy?: boolean\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n TOptions extends ToOptions<\n TRouter,\n TFrom,\n TTo,\n TMaskFrom,\n TMaskTo\n > = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n TRelaxedOptions = Omit<TOptions, 'search' | 'params'> &\n DeepPartial<Pick<TOptions, 'search' | 'params'>>,\n> = TRelaxedOptions & MatchRouteOptions\n\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n return React.useCallback(\n <\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | RouteById<TRouter['routeTree'], TResolved>['types']['allParams'] => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: RouteByPath<\n TRouter['routeTree'],\n ResolveRelativePath<TFrom, NoInfer<TTo>>\n >['types']['allParams'],\n ) => ReactNode)\n | React.ReactNode\n}\n\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> = RoutePaths<\n TRouter['routeTree']\n >,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom,\n TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any)\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return params ? props.children : null\n}\n\nexport function useMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n return useRouterState({\n select: (state) => {\n const matches = state.matches\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useParentMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function useChildMatches<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],\n TRouteMatch = MakeRouteMatch<TRouteTree, TRouteId>,\n T = Array<TRouteMatch>,\n>(opts?: { select?: (matches: Array<TRouteMatch>) => T }): T {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select\n ? opts.select(matches as Array<TRouteMatch>)\n : (matches as T)\n },\n })\n}\n\nexport function isServerSideError(error: unknown): error is {\n __isServerError: true\n data: Record<string, any>\n} {\n if (!(typeof error === 'object' && error && 'data' in error)) return false\n if (!('__isServerError' in error && error.__isServerError)) return false\n if (!(typeof error.data === 'object' && error.data)) return false\n\n return error.__isServerError === true\n}\n\nexport function defaultDeserializeError(serializedData: Record<string, any>) {\n if ('name' in serializedData && 'message' in serializedData) {\n const error = new Error(serializedData.message)\n error.name = serializedData.name\n if (process.env.NODE_ENV === 'development') {\n error.stack = serializedData.stack\n }\n return error\n }\n\n return serializedData.data\n}\n"],"names":["_a","Outlet"],"mappings":";;;;;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
9
9
|
export interface FileRoutesByPath {
|
|
10
10
|
}
|
|
11
|
-
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path: TFilePath): <TSearchSchemaInput = {}, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TFullSearchSchemaInput = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams = Record<ParsePathParams<TPath, never>, string>, TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>, TRouterContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn =
|
|
11
|
+
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path: TFilePath): <TSearchSchemaInput = {}, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TFullSearchSchemaInput = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams = Record<ParsePathParams<TPath, never>, string>, TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>, TRouterContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown>(options?: (FileBaseRouteOptions<TParentRoute, TPath, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & {
|
|
12
12
|
caseSensitive?: boolean | undefined;
|
|
13
13
|
wrapInSuspense?: boolean | undefined;
|
|
14
14
|
component?: import('./route').RouteComponent<any> | undefined;
|
|
@@ -51,7 +51,7 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
|
|
|
51
51
|
constructor(path: TFilePath, _opts?: {
|
|
52
52
|
silent: boolean;
|
|
53
53
|
});
|
|
54
|
-
createRoute: <TSearchSchemaInput = {}, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TFullSearchSchemaInput = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams = Record<ParsePathParams<TPath>, string>, TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, TRouterContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn =
|
|
54
|
+
createRoute: <TSearchSchemaInput = {}, TSearchSchema = {}, TSearchSchemaUsed = ResolveSearchSchemaUsed<TSearchSchemaInput, TSearchSchema>, TFullSearchSchemaInput = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams = Record<ParsePathParams<TPath>, string>, TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, TRouterContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown>(options?: FileBaseRouteOptions<TParentRoute, TPath, TSearchSchemaInput, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & UpdatableRouteOptions<TId, TAllParams, TFullSearchSchema, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren>;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
@deprecated It's recommended not to split loaders into separate files.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport type { ParsePathParams } from './link'\nimport type {\n AnyContext,\n AnyPathParams,\n AnyRoute,\n AnySearchSchema,\n FileBaseRouteOptions,\n ResolveAllContext,\n ResolveAllParamsFromParent,\n ResolveFullSearchSchema,\n ResolveFullSearchSchemaInput,\n ResolveLoaderData,\n ResolveRouteContext,\n ResolveSearchSchemaUsed,\n Route,\n RouteConstraints,\n RouteContext,\n RouteLoaderFn,\n SearchSchemaInput,\n TrimPathLeft,\n UpdatableRouteOptions,\n} from './route'\nimport type { Assign, IsAny } from './utils'\nimport type { MakeRouteMatch } from './Matches'\nimport type { NoInfer } from '@tanstack/react-store'\nimport type { RegisteredRouter } from './router'\nimport type { RouteById, RouteIds } from './routeInfo'\nimport type { RootRouteId } from './root'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n>(path: TFilePath) {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchSchemaInput = {},\n TSearchSchema = {},\n TSearchSchemaUsed = ResolveSearchSchemaUsed<\n TSearchSchemaInput,\n TSearchSchema\n >,\n TFullSearchSchemaInput = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,\n TParams = Record<ParsePathParams<TPath>, string>,\n TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n TRouteContextReturn = RouteContext,\n TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,\n TRouterContext = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = unknown,\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n >(\n options?: FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn\n > &\n UpdatableRouteOptions<\n TId,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n NoInfer<TLoaderData>\n> {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<\n string,\n AnyPathParams,\n AnySearchSchema,\n {},\n AnyContext,\n AnyContext,\n {}\n >,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatch = MakeRouteMatch<\n RegisteredRouter['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = () => {\n return useNavigate({ from: this.options.id })\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(path: TFilePath) {\n const id = removeGroups(path)\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')\n}\n"],"names":["opts"],"mappings":";;;;;;;;AA2CO,SAAS,gBAOd,MAAiB;AACV,SAAA,IAAI,UAA0D,MAAM;AAAA,IACzE,QAAQ;AAAA,EACT,CAAA,EAAE;AACL;AAMO,MAAM,UAOX;AAAA,EAGA,YACS,MACP,OACA;AAFO,SAAA,OAAA;AAMT,SAAA,cAAc,CAuBZ,YA6CG;AACH;AAAA,QACE,KAAK;AAAA,QACL;AAAA,MAAA;AAEI,YAAA,QAAQ,YAAY,OAAc;AACtC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AA9EP,SAAK,SAAS,+BAAO;AAAA,EACvB;AA+EF;AAOO,SAAS,gBAId,OAeA;AACA;AAAA,IACE;AAAA,IACA;AAAA,EAAA;AAEF,SAAO,CAAC,aAAa;AACvB;AAeO,MAAM,UAAmC;AAAA,EAK9C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S,aAAa,GAAW;AAC/B,SAAO,EAAE,WAAW,wBAAwB,EAAE,EAAE,WAAW,MAAM,GAAG;AACtE;"}
|
|
1
|
+
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport type { ParsePathParams } from './link'\nimport type {\n AnyContext,\n AnyPathParams,\n AnyRoute,\n AnySearchSchema,\n FileBaseRouteOptions,\n ResolveAllContext,\n ResolveAllParamsFromParent,\n ResolveFullSearchSchema,\n ResolveFullSearchSchemaInput,\n ResolveLoaderData,\n ResolveRouteContext,\n ResolveSearchSchemaUsed,\n Route,\n RouteConstraints,\n RouteContext,\n RouteLoaderFn,\n SearchSchemaInput,\n TrimPathLeft,\n UpdatableRouteOptions,\n} from './route'\nimport type { Assign, IsAny } from './utils'\nimport type { MakeRouteMatch } from './Matches'\nimport type { NoInfer } from '@tanstack/react-store'\nimport type { RegisteredRouter } from './router'\nimport type { RouteById, RouteIds } from './routeInfo'\nimport type { RootRouteId } from './root'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n>(path: TFilePath) {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchSchemaInput = {},\n TSearchSchema = {},\n TSearchSchemaUsed = ResolveSearchSchemaUsed<\n TSearchSchemaInput,\n TSearchSchema\n >,\n TFullSearchSchemaInput = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,\n TParams = Record<ParsePathParams<TPath>, string>,\n TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n TRouteContextReturn = RouteContext,\n TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,\n TRouterContext = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n >(\n options?: FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn\n > &\n UpdatableRouteOptions<\n TId,\n TAllParams,\n TFullSearchSchema,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n NoInfer<TLoaderData>\n> {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<\n string,\n AnyPathParams,\n AnySearchSchema,\n {},\n AnyContext,\n AnyContext,\n {}\n >,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatch = MakeRouteMatch<\n RegisteredRouter['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = () => {\n return useNavigate({ from: this.options.id })\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(path: TFilePath) {\n const id = removeGroups(path)\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n\nconst routeGroupPatternRegex = /\\(.+\\)/g\n\nfunction removeGroups(s: string) {\n return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/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