@tanstack/react-router 1.7.1 → 1.8.1
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/CatchBoundary.cjs +106 -0
- package/dist/cjs/CatchBoundary.cjs.map +1 -0
- package/dist/cjs/Matches.cjs +278 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +71 -0
- package/{build/cjs/RouterProvider.js → dist/cjs/RouterProvider.cjs} +55 -58
- package/dist/cjs/RouterProvider.cjs.map +1 -0
- package/dist/cjs/RouterProvider.d.cts +29 -0
- package/dist/cjs/awaited.cjs +51 -0
- package/dist/cjs/awaited.cjs.map +1 -0
- package/dist/cjs/defer.cjs +30 -0
- package/dist/cjs/defer.cjs.map +1 -0
- package/dist/cjs/fileRoute.cjs +19 -0
- package/dist/cjs/fileRoute.cjs.map +1 -0
- package/dist/cjs/history.d.cts +7 -0
- package/{build/cjs/index.js → dist/cjs/index.cjs} +39 -51
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/lazyRouteComponent.cjs +40 -0
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -0
- package/dist/cjs/link.cjs +196 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +85 -0
- package/{build/cjs/path.js → dist/cjs/path.cjs} +87 -95
- package/dist/cjs/path.cjs.map +1 -0
- package/dist/cjs/path.d.cts +24 -0
- package/dist/cjs/qss.cjs +45 -0
- package/dist/cjs/qss.cjs.map +1 -0
- package/dist/cjs/redirects.cjs +15 -0
- package/dist/cjs/redirects.cjs.map +1 -0
- package/dist/cjs/route.cjs +143 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/router.cjs +1089 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/routerContext.cjs +29 -0
- package/dist/cjs/routerContext.cjs.map +1 -0
- package/{build/cjs/scroll-restoration.js → dist/cjs/scroll-restoration.cjs} +58 -75
- package/dist/cjs/scroll-restoration.cjs.map +1 -0
- package/{build/cjs/searchParams.js → dist/cjs/searchParams.cjs} +18 -36
- package/dist/cjs/searchParams.cjs.map +1 -0
- package/dist/cjs/useBlocker.cjs +36 -0
- package/dist/cjs/useBlocker.cjs.map +1 -0
- package/dist/cjs/useNavigate.cjs +55 -0
- package/dist/cjs/useNavigate.cjs.map +1 -0
- package/dist/cjs/useParams.cjs +16 -0
- package/dist/cjs/useParams.cjs.map +1 -0
- package/dist/cjs/useRouteContext.cjs +11 -0
- package/dist/cjs/useRouteContext.cjs.map +1 -0
- package/dist/cjs/useRouter.cjs +33 -0
- package/dist/cjs/useRouter.cjs.map +1 -0
- package/dist/cjs/useRouterState.cjs +12 -0
- package/dist/cjs/useRouterState.cjs.map +1 -0
- package/dist/cjs/useSearch.cjs +13 -0
- package/dist/cjs/useSearch.cjs.map +1 -0
- package/{build/cjs/utils.js → dist/cjs/utils.cjs} +25 -116
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +50 -0
- package/dist/esm/CatchBoundary.d.ts +36 -0
- package/dist/esm/CatchBoundary.js +89 -0
- package/dist/esm/CatchBoundary.js.map +1 -0
- package/{build/types → dist/esm}/Matches.d.ts +3 -3
- package/dist/esm/Matches.js +261 -0
- package/dist/esm/Matches.js.map +1 -0
- package/{build/types → dist/esm}/RouterProvider.d.ts +3 -1
- package/dist/esm/RouterProvider.js +136 -0
- package/dist/esm/RouterProvider.js.map +1 -0
- package/dist/esm/awaited.d.ts +9 -0
- package/dist/esm/awaited.js +51 -0
- package/dist/esm/awaited.js.map +1 -0
- package/dist/esm/defer.d.ts +22 -0
- package/dist/esm/defer.js +30 -0
- package/{build/cjs → dist/esm}/defer.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +21 -0
- package/dist/esm/fileRoute.js +19 -0
- package/dist/esm/fileRoute.js.map +1 -0
- package/{build/types → dist/esm}/history.d.ts +1 -1
- package/dist/esm/index.d.ts +30 -0
- package/dist/esm/index.js +118 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lazyRouteComponent.d.ts +2 -0
- package/dist/esm/lazyRouteComponent.js +23 -0
- package/{build/cjs → dist/esm}/lazyRouteComponent.js.map +1 -1
- package/{build/types → dist/esm}/link.d.ts +3 -1
- package/dist/esm/link.js +179 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/location.d.ts +12 -0
- package/{build/types → dist/esm}/path.d.ts +8 -1
- package/dist/esm/path.js +209 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/qss.d.ts +2 -0
- package/dist/esm/qss.js +45 -0
- package/dist/esm/qss.js.map +1 -0
- package/dist/esm/redirects.d.ts +11 -0
- package/dist/esm/redirects.js +15 -0
- package/{build/cjs → dist/esm}/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +300 -0
- package/dist/esm/route.js +143 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/routeInfo.d.ts +31 -0
- package/dist/esm/router.d.ts +201 -0
- package/dist/esm/router.js +1089 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/routerContext.d.ts +3 -0
- package/dist/esm/routerContext.js +13 -0
- package/{build/cjs → dist/esm}/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +18 -0
- package/dist/esm/scroll-restoration.js +168 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/searchParams.d.ts +7 -0
- package/dist/esm/searchParams.js +63 -0
- package/{build/cjs → dist/esm}/searchParams.js.map +1 -1
- package/dist/esm/useBlocker.d.ts +9 -0
- package/dist/esm/useBlocker.js +19 -0
- package/{build/cjs → dist/esm}/useBlocker.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +20 -0
- package/dist/esm/useNavigate.js +38 -0
- package/{build/cjs → dist/esm}/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +7 -0
- package/dist/esm/useParams.js +16 -0
- package/{build/cjs → dist/esm}/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +7 -0
- package/dist/esm/useRouteContext.js +11 -0
- package/{build/cjs → dist/esm}/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.d.ts +5 -0
- package/dist/esm/useRouter.js +16 -0
- package/{build/cjs → dist/esm}/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.d.ts +6 -0
- package/dist/esm/useRouterState.js +12 -0
- package/{build/cjs → dist/esm}/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.d.ts +7 -0
- package/dist/esm/useSearch.js +13 -0
- package/dist/esm/useSearch.js.map +1 -0
- package/{build/types → dist/esm}/utils.d.ts +4 -0
- package/dist/esm/utils.js +137 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +43 -22
- package/src/Matches.tsx +10 -6
- package/src/RouterProvider.tsx +3 -1
- package/src/fileRoute.ts +4 -5
- package/src/link.tsx +5 -4
- package/src/path.ts +16 -5
- package/src/route.ts +5 -6
- package/src/router.ts +25 -8
- package/src/useSearch.tsx +5 -2
- package/src/utils.ts +9 -0
- package/build/cjs/CatchBoundary.js +0 -128
- package/build/cjs/CatchBoundary.js.map +0 -1
- package/build/cjs/Matches.js +0 -260
- package/build/cjs/Matches.js.map +0 -1
- package/build/cjs/RouterProvider.js.map +0 -1
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -29
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/awaited.js +0 -60
- package/build/cjs/awaited.js.map +0 -1
- package/build/cjs/defer.js +0 -42
- package/build/cjs/fileRoute.js +0 -31
- package/build/cjs/fileRoute.js.map +0 -1
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/lazyRouteComponent.js +0 -54
- package/build/cjs/link.js +0 -224
- package/build/cjs/link.js.map +0 -1
- package/build/cjs/path.js.map +0 -1
- package/build/cjs/qss.js +0 -63
- package/build/cjs/qss.js.map +0 -1
- package/build/cjs/redirects.js +0 -28
- package/build/cjs/route.js +0 -292
- package/build/cjs/route.js.map +0 -1
- package/build/cjs/router.js +0 -1116
- package/build/cjs/router.js.map +0 -1
- package/build/cjs/routerContext.js +0 -42
- package/build/cjs/scroll-restoration.js.map +0 -1
- package/build/cjs/useBlocker.js +0 -55
- package/build/cjs/useNavigate.js +0 -88
- package/build/cjs/useParams.js +0 -27
- package/build/cjs/useRouteContext.js +0 -23
- package/build/cjs/useRouter.js +0 -44
- package/build/cjs/useRouterState.js +0 -24
- package/build/cjs/useSearch.js +0 -25
- package/build/cjs/useSearch.js.map +0 -1
- package/build/cjs/utils.js.map +0 -1
- package/build/esm/index.js +0 -2874
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4838
- package/build/stats-react.json +0 -1471
- package/build/umd/index.development.js +0 -3573
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -22
- package/build/umd/index.production.js.map +0 -1
- /package/{build/types/CatchBoundary.d.ts → dist/cjs/CatchBoundary.d.cts} +0 -0
- /package/{build/types/awaited.d.ts → dist/cjs/awaited.d.cts} +0 -0
- /package/{build/types/defer.d.ts → dist/cjs/defer.d.cts} +0 -0
- /package/{build/types/fileRoute.d.ts → dist/cjs/fileRoute.d.cts} +0 -0
- /package/{build/types/index.d.ts → dist/cjs/index.d.cts} +0 -0
- /package/{build/types/lazyRouteComponent.d.ts → dist/cjs/lazyRouteComponent.d.cts} +0 -0
- /package/{build/types/location.d.ts → dist/cjs/location.d.cts} +0 -0
- /package/{build/types/qss.d.ts → dist/cjs/qss.d.cts} +0 -0
- /package/{build/types/redirects.d.ts → dist/cjs/redirects.d.cts} +0 -0
- /package/{build/types/route.d.ts → dist/cjs/route.d.cts} +0 -0
- /package/{build/types/routeInfo.d.ts → dist/cjs/routeInfo.d.cts} +0 -0
- /package/{build/types/router.d.ts → dist/cjs/router.d.cts} +0 -0
- /package/{build/types/routerContext.d.ts → dist/cjs/routerContext.d.cts} +0 -0
- /package/{build/types/scroll-restoration.d.ts → dist/cjs/scroll-restoration.d.cts} +0 -0
- /package/{build/types/searchParams.d.ts → dist/cjs/searchParams.d.cts} +0 -0
- /package/{build/types/useBlocker.d.ts → dist/cjs/useBlocker.d.cts} +0 -0
- /package/{build/types/useNavigate.d.ts → dist/cjs/useNavigate.d.cts} +0 -0
- /package/{build/types/useParams.d.ts → dist/cjs/useParams.d.cts} +0 -0
- /package/{build/types/useRouteContext.d.ts → dist/cjs/useRouteContext.d.cts} +0 -0
- /package/{build/types/useRouter.d.ts → dist/cjs/useRouter.d.cts} +0 -0
- /package/{build/types/useRouterState.d.ts → dist/cjs/useRouterState.d.cts} +0 -0
- /package/{build/types/useSearch.d.ts → dist/cjs/useSearch.d.cts} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NoInfer } from '@tanstack/react-store';
|
|
2
|
+
import { ParsePathParams } from './link';
|
|
3
|
+
import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints, ResolveFullSearchSchemaInput, SearchSchemaInput, RouteLoaderFn } from './route';
|
|
4
|
+
import { Assign, Expand, IsAny } from './utils';
|
|
5
|
+
export interface FileRoutesByPath {
|
|
6
|
+
}
|
|
7
|
+
type Replace<S extends string, From extends string, To extends string> = S extends `${infer Start}${From}${infer Rest}` ? `${Start}${To}${Replace<Rest, From, To>}` : S;
|
|
8
|
+
export type TrimLeft<T extends string, S extends string> = T extends `${S}${infer U}` ? U : T;
|
|
9
|
+
export type TrimRight<T extends string, S extends string> = T extends `${infer U}${S}` ? U : T;
|
|
10
|
+
export type Trim<T extends string, S extends string> = TrimLeft<TrimRight<T, S>, S>;
|
|
11
|
+
export type RemoveUnderScores<T extends string> = Replace<Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>, '/_', '/'>;
|
|
12
|
+
type ReplaceFirstOccurrence<T extends string, Search extends string, Replacement extends string> = T extends `${infer Prefix}${Search}${infer Suffix}` ? `${Prefix}${Replacement}${Suffix}` : T;
|
|
13
|
+
export type ResolveFilePath<TParentRoute extends AnyRoute, TFilePath extends string> = TParentRoute['id'] extends RootRouteId ? TrimPathLeft<TFilePath> : ReplaceFirstOccurrence<TrimPathLeft<TFilePath>, TrimPathLeft<TParentRoute['types']['customId']>, ''>;
|
|
14
|
+
export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends string> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}` ? '' : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}` ? '' : ResolveFilePath<TParentRoute, TFilePath>;
|
|
15
|
+
export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
|
|
16
|
+
path: TFilePath;
|
|
17
|
+
constructor(path: TFilePath);
|
|
18
|
+
createRoute: <TSearchSchemaInput extends import("./route").AnySearchSchema = {}, TSearchSchema extends import("./route").AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends import("./route").AnySearchSchema = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends import("./route").AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & UpdatableRouteOptions<TFullSearchSchema>) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
|
|
19
|
+
}
|
|
20
|
+
export declare function FileRouteLoader<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(_path: TFilePath): <TLoaderData extends any>(loaderFn: RouteLoaderFn<TRoute['types']['allParams'], TRoute['types']['loaderDeps'], TRoute['types']['allContext'], TRoute['types']['routeContext'], TLoaderData>) => RouteLoaderFn<TRoute['types']['allParams'], TRoute['types']['loaderDeps'], TRoute['types']['allContext'], TRoute['types']['routeContext'], NoInfer<TLoaderData>>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Route } from "./route.js";
|
|
2
|
+
class FileRoute {
|
|
3
|
+
constructor(path) {
|
|
4
|
+
this.path = path;
|
|
5
|
+
this.createRoute = (options) => {
|
|
6
|
+
const route = new Route(options);
|
|
7
|
+
route.isRoot = false;
|
|
8
|
+
return route;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function FileRouteLoader(_path) {
|
|
13
|
+
return (loaderFn) => loaderFn;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
FileRoute,
|
|
17
|
+
FileRouteLoader
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=fileRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { NoInfer } from '@tanstack/react-store'\nimport { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n UpdatableRouteOptions,\n Route,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n ResolveFullSearchSchemaInput,\n SearchSchemaInput,\n LoaderFnContext,\n RouteLoaderFn,\n} from './route'\nimport { Assign, Expand, IsAny } from './utils'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\ntype ReplaceFirstOccurrence<\n T extends string,\n Search extends string,\n Replacement extends string,\n> = T extends `${infer Prefix}${Search}${infer Suffix}`\n ? `${Prefix}${Replacement}${Suffix}`\n : T\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : ReplaceFirstOccurrence<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchemaUsed extends Record<\n string,\n any\n > = TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : TSearchSchema,\n TFullSearchSchemaInput extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContextReturn extends\n RouteConstraints['TRouteContext'] = RouteContext,\n TRouteContext extends RouteConstraints['TRouteContext'] = [\n TRouteContextReturn,\n ] extends [never]\n ? RouteContext\n : TRouteContextReturn,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options?: Omit<\n RouteOptions<\n TParentRoute,\n string,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<TFullSearchSchema>,\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 TLoaderData,\n TChildren,\n TRouteTree\n > => {\n const route = new Route(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData extends any>(\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 return (loaderFn) => loaderFn\n}\n"],"names":[],"mappings":";AAqFO,MAAM,UAYX;AAAA,EACA,YAAmB,MAAiB;AAAjB,SAAA,OAAA;AAEnB,SAAA,cAAc,CA4CZ,YA2CG;AACG,YAAA,QAAQ,IAAI,MAAM,OAAc;AACpC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AAAA,EA5F4B;AA8FvC;AAEO,SAAS,gBAId,OAeA;AACA,SAAO,CAAC,aAAa;AACvB;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export * from '@tanstack/history';
|
|
2
|
+
export { default as invariant } from 'tiny-invariant';
|
|
3
|
+
export { default as warning } from 'tiny-warning';
|
|
4
|
+
export * from './awaited';
|
|
5
|
+
export * from './defer';
|
|
6
|
+
export * from './CatchBoundary';
|
|
7
|
+
export * from './fileRoute';
|
|
8
|
+
export * from './history';
|
|
9
|
+
export * from './lazyRouteComponent';
|
|
10
|
+
export * from './link';
|
|
11
|
+
export * from './location';
|
|
12
|
+
export * from './Matches';
|
|
13
|
+
export * from './path';
|
|
14
|
+
export * from './qss';
|
|
15
|
+
export * from './redirects';
|
|
16
|
+
export * from './route';
|
|
17
|
+
export * from './routeInfo';
|
|
18
|
+
export * from './router';
|
|
19
|
+
export * from './RouterProvider';
|
|
20
|
+
export * from './scroll-restoration';
|
|
21
|
+
export * from './searchParams';
|
|
22
|
+
export * from './useBlocker';
|
|
23
|
+
export * from './useNavigate';
|
|
24
|
+
export * from './useParams';
|
|
25
|
+
export * from './useSearch';
|
|
26
|
+
export * from './routerContext';
|
|
27
|
+
export * from './useRouteContext';
|
|
28
|
+
export * from './useRouter';
|
|
29
|
+
export * from './useRouterState';
|
|
30
|
+
export * from './utils';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export * from "@tanstack/history";
|
|
2
|
+
import { default as default2 } from "tiny-invariant";
|
|
3
|
+
import { default as default3 } from "tiny-warning";
|
|
4
|
+
import { Await, useAwaited } from "./awaited.js";
|
|
5
|
+
import { defer, isDehydratedDeferred } from "./defer.js";
|
|
6
|
+
import { CatchBoundary, CatchBoundaryImpl, ErrorComponent } from "./CatchBoundary.js";
|
|
7
|
+
import { FileRoute, FileRouteLoader } from "./fileRoute.js";
|
|
8
|
+
import { lazyRouteComponent } from "./lazyRouteComponent.js";
|
|
9
|
+
import { Link, useLinkProps } from "./link.js";
|
|
10
|
+
import { Match, MatchRoute, Matches, Outlet, defaultDeserializeError, getRenderedMatches, isServerSideError, matchContext, useLoaderData, useLoaderDeps, useMatch, useMatchRoute, useMatches, useParentMatches } from "./Matches.js";
|
|
11
|
+
import { cleanPath, interpolatePath, joinPaths, matchByPath, matchPathname, parsePathname, removeBasepath, resolvePath, trimPath, trimPathLeft, trimPathRight } from "./path.js";
|
|
12
|
+
import { decode, encode } from "./qss.js";
|
|
13
|
+
import { isRedirect, redirect } from "./redirects.js";
|
|
14
|
+
import { NotFoundRoute, RootRoute, Route, RouteApi, createRouteMask, rootRouteId, rootRouteWithContext } from "./route.js";
|
|
15
|
+
import { PathParamError, Router, SearchParamError, componentTypes, defaultSerializeError, getInitialRouterState, lazyFn } from "./router.js";
|
|
16
|
+
import { RouterProvider, getRouteMatch } from "./RouterProvider.js";
|
|
17
|
+
import { ScrollRestoration, useElementScrollRestoration, useScrollRestoration } from "./scroll-restoration.js";
|
|
18
|
+
import { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith } from "./searchParams.js";
|
|
19
|
+
import { Block, useBlocker } from "./useBlocker.js";
|
|
20
|
+
import { Navigate, useNavigate } from "./useNavigate.js";
|
|
21
|
+
import { useParams } from "./useParams.js";
|
|
22
|
+
import { useSearch } from "./useSearch.js";
|
|
23
|
+
import { routerContext } from "./routerContext.js";
|
|
24
|
+
import { useRouteContext } from "./useRouteContext.js";
|
|
25
|
+
import { useRouter } from "./useRouter.js";
|
|
26
|
+
import { useRouterState } from "./useRouterState.js";
|
|
27
|
+
import { deepEqual, escapeJSON, functionalUpdate, isPlainArray, isPlainObject, isServer, last, pick, replaceEqualDeep, shallow, useLayoutEffect, useStableCallback } from "./utils.js";
|
|
28
|
+
export {
|
|
29
|
+
Await,
|
|
30
|
+
Block,
|
|
31
|
+
CatchBoundary,
|
|
32
|
+
CatchBoundaryImpl,
|
|
33
|
+
ErrorComponent,
|
|
34
|
+
FileRoute,
|
|
35
|
+
FileRouteLoader,
|
|
36
|
+
Link,
|
|
37
|
+
Match,
|
|
38
|
+
MatchRoute,
|
|
39
|
+
Matches,
|
|
40
|
+
Navigate,
|
|
41
|
+
NotFoundRoute,
|
|
42
|
+
Outlet,
|
|
43
|
+
PathParamError,
|
|
44
|
+
RootRoute,
|
|
45
|
+
Route,
|
|
46
|
+
RouteApi,
|
|
47
|
+
Router,
|
|
48
|
+
RouterProvider,
|
|
49
|
+
ScrollRestoration,
|
|
50
|
+
SearchParamError,
|
|
51
|
+
cleanPath,
|
|
52
|
+
componentTypes,
|
|
53
|
+
createRouteMask,
|
|
54
|
+
decode,
|
|
55
|
+
deepEqual,
|
|
56
|
+
defaultDeserializeError,
|
|
57
|
+
defaultParseSearch,
|
|
58
|
+
defaultSerializeError,
|
|
59
|
+
defaultStringifySearch,
|
|
60
|
+
defer,
|
|
61
|
+
encode,
|
|
62
|
+
escapeJSON,
|
|
63
|
+
functionalUpdate,
|
|
64
|
+
getInitialRouterState,
|
|
65
|
+
getRenderedMatches,
|
|
66
|
+
getRouteMatch,
|
|
67
|
+
interpolatePath,
|
|
68
|
+
default2 as invariant,
|
|
69
|
+
isDehydratedDeferred,
|
|
70
|
+
isPlainArray,
|
|
71
|
+
isPlainObject,
|
|
72
|
+
isRedirect,
|
|
73
|
+
isServer,
|
|
74
|
+
isServerSideError,
|
|
75
|
+
joinPaths,
|
|
76
|
+
last,
|
|
77
|
+
lazyFn,
|
|
78
|
+
lazyRouteComponent,
|
|
79
|
+
matchByPath,
|
|
80
|
+
matchContext,
|
|
81
|
+
matchPathname,
|
|
82
|
+
parsePathname,
|
|
83
|
+
parseSearchWith,
|
|
84
|
+
pick,
|
|
85
|
+
redirect,
|
|
86
|
+
removeBasepath,
|
|
87
|
+
replaceEqualDeep,
|
|
88
|
+
resolvePath,
|
|
89
|
+
rootRouteId,
|
|
90
|
+
rootRouteWithContext,
|
|
91
|
+
routerContext,
|
|
92
|
+
shallow,
|
|
93
|
+
stringifySearchWith,
|
|
94
|
+
trimPath,
|
|
95
|
+
trimPathLeft,
|
|
96
|
+
trimPathRight,
|
|
97
|
+
useAwaited,
|
|
98
|
+
useBlocker,
|
|
99
|
+
useElementScrollRestoration,
|
|
100
|
+
useLayoutEffect,
|
|
101
|
+
useLinkProps,
|
|
102
|
+
useLoaderData,
|
|
103
|
+
useLoaderDeps,
|
|
104
|
+
useMatch,
|
|
105
|
+
useMatchRoute,
|
|
106
|
+
useMatches,
|
|
107
|
+
useNavigate,
|
|
108
|
+
useParams,
|
|
109
|
+
useParentMatches,
|
|
110
|
+
useRouteContext,
|
|
111
|
+
useRouter,
|
|
112
|
+
useRouterState,
|
|
113
|
+
useScrollRestoration,
|
|
114
|
+
useSearch,
|
|
115
|
+
useStableCallback,
|
|
116
|
+
default3 as warning
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AsyncRouteComponent } from './route';
|
|
2
|
+
export declare function lazyRouteComponent<T extends Record<string, any>, TKey extends keyof T = 'default'>(importer: () => Promise<T>, exportName?: TKey): T[TKey] extends (props: infer TProps) => any ? AsyncRouteComponent<TProps> : never;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function lazyRouteComponent(importer, exportName) {
|
|
3
|
+
let loadPromise;
|
|
4
|
+
const load = () => {
|
|
5
|
+
if (!loadPromise) {
|
|
6
|
+
loadPromise = importer();
|
|
7
|
+
}
|
|
8
|
+
return loadPromise;
|
|
9
|
+
};
|
|
10
|
+
const lazyComp = React.lazy(async () => {
|
|
11
|
+
const moduleExports = await load();
|
|
12
|
+
const comp = moduleExports[exportName ?? "default"];
|
|
13
|
+
return {
|
|
14
|
+
default: comp
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
lazyComp.preload = load;
|
|
18
|
+
return lazyComp;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
lazyRouteComponent
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=lazyRouteComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AsyncRouteComponent } from './route'\n\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any>\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n }\n\n return loadPromise\n }\n\n const lazyComp = React.lazy(async () => {\n const moduleExports = await load()\n const comp = moduleExports[exportName ?? 'default']\n return {\n default: comp,\n }\n })\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AsyncRouteComponent } from './route'\n\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any>\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n }\n\n return loadPromise\n }\n\n const lazyComp = React.lazy(async () => {\n const moduleExports = await load()\n const comp = moduleExports[exportName ?? 'default']\n return {\n default: comp,\n }\n })\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":[],"mappings":";AAGgB,SAAA,mBAId,UACA,YAGQ;AACJ,MAAA;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS;AAAA,IACzB;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAW,MAAM,KAAK,YAAY;AAChC,UAAA,gBAAgB,MAAM;AACtB,UAAA,OAAO,cAAc,cAAc,SAAS;AAC3C,WAAA;AAAA,MACL,SAAS;AAAA,IAAA;AAAA,EACX,CACD;AACC,WAAiB,UAAU;AAEtB,SAAA;AACT;"}
|
|
@@ -45,7 +45,9 @@ export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTr
|
|
|
45
45
|
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TTo, TResolved>;
|
|
46
46
|
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
47
47
|
type ParamVariant = 'PATH' | 'SEARCH';
|
|
48
|
-
type ExcludeRootSearchSchema<T, Excluded = Exclude<T, RootSearchSchema>> = [
|
|
48
|
+
type ExcludeRootSearchSchema<T, Excluded = Exclude<T, RootSearchSchema>> = [
|
|
49
|
+
Excluded
|
|
50
|
+
] extends [never] ? {} : Excluded;
|
|
49
51
|
type PostProcessParams<T, TParamVariant extends ParamVariant> = TParamVariant extends 'SEARCH' ? ExcludeRootSearchSchema<T> : T;
|
|
50
52
|
export type ParamOptions<TRouteTree extends AnyRoute, TFrom, TTo extends string, TResolved, TParamVariant extends ParamVariant, TFromRouteType extends 'allParams' | 'fullSearchSchema' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema', TToRouteType extends 'allParams' | 'fullSearchSchemaInput' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput', TFromParams = PostProcessParams<RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType], TParamVariant>, TToIndex = TTo extends '' ? '' : RouteByPath<TRouteTree, `${TTo}/`> extends never ? TTo : `${TTo}/`, TToParams = TToIndex extends '' ? TFromParams : never extends TResolved ? PostProcessParams<RouteByPath<TRouteTree, TToIndex>['types'][TToRouteType], TParamVariant> : PostProcessParams<RouteByPath<TRouteTree, TResolved>['types'][TToRouteType], TParamVariant>, TReducer = ParamsReducer<TFromParams, TToParams>> = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never ? Partial<MakeParamOption<TParamVariant, true | TReducer>> : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>> ? MakeParamOption<TParamVariant, true | TReducer> : MakeParamOption<TParamVariant, TReducer>;
|
|
51
53
|
type MakeParamOption<TParamVariant extends ParamVariant, T> = TParamVariant extends 'PATH' ? MakePathParamOptions<T> : MakeSearchParamOptions<T>;
|
package/dist/esm/link.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useMatch } from "./Matches.js";
|
|
4
|
+
import { useRouterState } from "./useRouterState.js";
|
|
5
|
+
import { useRouter } from "./useRouter.js";
|
|
6
|
+
import { deepEqual, functionalUpdate } from "./utils.js";
|
|
7
|
+
const preloadWarning = "Error preloading route! ☝️";
|
|
8
|
+
function useLinkProps(options) {
|
|
9
|
+
const router = useRouter();
|
|
10
|
+
const matchPathname = useMatch({
|
|
11
|
+
strict: false,
|
|
12
|
+
select: (s) => s.pathname
|
|
13
|
+
});
|
|
14
|
+
const {
|
|
15
|
+
// custom props
|
|
16
|
+
children,
|
|
17
|
+
target,
|
|
18
|
+
activeProps = () => ({ className: "active" }),
|
|
19
|
+
inactiveProps = () => ({}),
|
|
20
|
+
activeOptions,
|
|
21
|
+
disabled,
|
|
22
|
+
hash,
|
|
23
|
+
search,
|
|
24
|
+
params,
|
|
25
|
+
to,
|
|
26
|
+
state,
|
|
27
|
+
mask,
|
|
28
|
+
preload: userPreload,
|
|
29
|
+
preloadDelay: userPreloadDelay,
|
|
30
|
+
replace,
|
|
31
|
+
startTransition,
|
|
32
|
+
resetScroll,
|
|
33
|
+
// element props
|
|
34
|
+
style,
|
|
35
|
+
className,
|
|
36
|
+
onClick,
|
|
37
|
+
onFocus,
|
|
38
|
+
onMouseEnter,
|
|
39
|
+
onMouseLeave,
|
|
40
|
+
onTouchStart,
|
|
41
|
+
...rest
|
|
42
|
+
} = options;
|
|
43
|
+
const dest = {
|
|
44
|
+
from: options.to ? matchPathname : void 0,
|
|
45
|
+
...options
|
|
46
|
+
};
|
|
47
|
+
let type = "internal";
|
|
48
|
+
try {
|
|
49
|
+
new URL(`${to}`);
|
|
50
|
+
type = "external";
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
if (type === "external") {
|
|
54
|
+
return {
|
|
55
|
+
href: to
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const next = router.buildLocation(dest);
|
|
59
|
+
const preload = userPreload ?? router.options.defaultPreload;
|
|
60
|
+
const preloadDelay = userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0;
|
|
61
|
+
const isActive = useRouterState({
|
|
62
|
+
select: (s) => {
|
|
63
|
+
const currentPathSplit = s.location.pathname.split("/");
|
|
64
|
+
const nextPathSplit = next.pathname.split("/");
|
|
65
|
+
const pathIsFuzzyEqual = nextPathSplit.every(
|
|
66
|
+
(d, i) => d === currentPathSplit[i]
|
|
67
|
+
);
|
|
68
|
+
const pathTest = (activeOptions == null ? void 0 : activeOptions.exact) ? s.location.pathname === next.pathname : pathIsFuzzyEqual;
|
|
69
|
+
const hashTest = (activeOptions == null ? void 0 : activeOptions.includeHash) ? s.location.hash === next.hash : true;
|
|
70
|
+
const searchTest = (activeOptions == null ? void 0 : activeOptions.includeSearch) ?? true ? deepEqual(s.location.search, next.search, !(activeOptions == null ? void 0 : activeOptions.exact)) : true;
|
|
71
|
+
return pathTest && hashTest && searchTest;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const handleClick = (e) => {
|
|
75
|
+
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === "_self") && e.button === 0) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
router.commitLocation({ ...next, replace, resetScroll, startTransition });
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const handleFocus = (e) => {
|
|
81
|
+
if (preload) {
|
|
82
|
+
router.preloadRoute(dest).catch((err) => {
|
|
83
|
+
console.warn(err);
|
|
84
|
+
console.warn(preloadWarning);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const handleTouchStart = (e) => {
|
|
89
|
+
if (preload) {
|
|
90
|
+
router.preloadRoute(dest).catch((err) => {
|
|
91
|
+
console.warn(err);
|
|
92
|
+
console.warn(preloadWarning);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const handleEnter = (e) => {
|
|
97
|
+
const target2 = e.target || {};
|
|
98
|
+
if (preload) {
|
|
99
|
+
if (target2.preloadTimeout) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
target2.preloadTimeout = setTimeout(() => {
|
|
103
|
+
target2.preloadTimeout = null;
|
|
104
|
+
router.preloadRoute(dest).catch((err) => {
|
|
105
|
+
console.warn(err);
|
|
106
|
+
console.warn(preloadWarning);
|
|
107
|
+
});
|
|
108
|
+
}, preloadDelay);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const handleLeave = (e) => {
|
|
112
|
+
const target2 = e.target || {};
|
|
113
|
+
if (target2.preloadTimeout) {
|
|
114
|
+
clearTimeout(target2.preloadTimeout);
|
|
115
|
+
target2.preloadTimeout = null;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const composeHandlers = (handlers) => (e) => {
|
|
119
|
+
if (e.persist)
|
|
120
|
+
e.persist();
|
|
121
|
+
handlers.filter(Boolean).forEach((handler) => {
|
|
122
|
+
if (e.defaultPrevented)
|
|
123
|
+
return;
|
|
124
|
+
handler(e);
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
|
|
128
|
+
const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
|
|
129
|
+
return {
|
|
130
|
+
...resolvedActiveProps,
|
|
131
|
+
...resolvedInactiveProps,
|
|
132
|
+
...rest,
|
|
133
|
+
href: disabled ? void 0 : next.maskedLocation ? next.maskedLocation.href : next.href,
|
|
134
|
+
onClick: composeHandlers([onClick, handleClick]),
|
|
135
|
+
onFocus: composeHandlers([onFocus, handleFocus]),
|
|
136
|
+
onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
|
|
137
|
+
onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
|
|
138
|
+
onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
|
|
139
|
+
target,
|
|
140
|
+
style: {
|
|
141
|
+
...style,
|
|
142
|
+
...resolvedActiveProps.style,
|
|
143
|
+
...resolvedInactiveProps.style
|
|
144
|
+
},
|
|
145
|
+
className: [
|
|
146
|
+
className,
|
|
147
|
+
resolvedActiveProps.className,
|
|
148
|
+
resolvedInactiveProps.className
|
|
149
|
+
].filter(Boolean).join(" ") || void 0,
|
|
150
|
+
...disabled ? {
|
|
151
|
+
role: "link",
|
|
152
|
+
"aria-disabled": true
|
|
153
|
+
} : void 0,
|
|
154
|
+
["data-status"]: isActive ? "active" : void 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const Link = React.forwardRef((props, ref) => {
|
|
158
|
+
const linkProps = useLinkProps(props);
|
|
159
|
+
return /* @__PURE__ */ jsx(
|
|
160
|
+
"a",
|
|
161
|
+
{
|
|
162
|
+
...{
|
|
163
|
+
ref,
|
|
164
|
+
...linkProps,
|
|
165
|
+
children: typeof props.children === "function" ? props.children({
|
|
166
|
+
isActive: linkProps["data-status"] === "active"
|
|
167
|
+
}) : props.children
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
function isCtrlEvent(e) {
|
|
173
|
+
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
Link,
|
|
177
|
+
useLinkProps
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../src/link.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { Trim } from './fileRoute'\nimport { AnyRoute, ReactNode, RootSearchSchema } from './route'\nimport { RouteByPath, RouteIds, RoutePaths } from './routeInfo'\nimport { RegisteredRouter } from './router'\nimport { LinkProps, UseLinkPropsOptions } from './useNavigate'\nimport {\n Expand,\n NoInfer,\n NonNullableUpdater,\n PickRequired,\n StringLiteral,\n Updater,\n WithoutEmpty,\n deepEqual,\n functionalUpdate,\n} from './utils'\nimport { HistoryState } from '@tanstack/history'\n\nexport type CleanPath<T extends string> = T extends `${infer L}//${infer R}`\n ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>\n : T extends `${infer L}//`\n ? `${CleanPath<L>}/`\n : T extends `//${infer L}`\n ? `/${CleanPath<L>}`\n : T\n\nexport type Split<S, TIncludeTrailingSlash = true> = S extends unknown\n ? string extends S\n ? string[]\n : S extends string\n ? CleanPath<S> extends ''\n ? []\n : TIncludeTrailingSlash extends true\n ? CleanPath<S> extends `${infer T}/`\n ? [...Split<T>, '/']\n : CleanPath<S> extends `/${infer U}`\n ? Split<U>\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : [S]\n : CleanPath<S> extends `${infer T}/${infer U}`\n ? [...Split<T>, ...Split<U>]\n : S extends string\n ? [S]\n : never\n : never\n : never\n\nexport type ParsePathParams<T extends string> = keyof {\n [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}`\n ? L extends ''\n ? '_splat'\n : L\n : never]: K\n}\n\nexport type Join<T, Delimiter extends string = '/'> = T extends []\n ? ''\n : T extends [infer L extends string]\n ? L\n : T extends [infer L extends string, ...infer Tail extends [...string[]]]\n ? CleanPath<`${L}${Delimiter}${Join<Tail>}`>\n : never\n\nexport type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never\n\nexport type RelativeToPathAutoComplete<\n AllPaths extends string,\n TFrom extends string,\n TTo extends string,\n SplitPaths extends string[] = Split<AllPaths, false>,\n> = TTo extends `..${infer _}`\n ? SplitPaths extends [\n ...Split<ResolveRelativePath<TFrom, TTo>, false>,\n ...infer TToRest,\n ]\n ? `${CleanPath<\n Join<\n [\n ...Split<TTo, false>,\n ...(\n | TToRest\n | (Split<\n ResolveRelativePath<TFrom, TTo>,\n false\n >['length'] extends 1\n ? never\n : ['../'])\n ),\n ]\n >\n >}`\n : never\n : TTo extends `./${infer RestTTo}`\n ? SplitPaths extends [\n ...Split<TFrom, false>,\n ...Split<RestTTo, false>,\n ...infer RestPath,\n ]\n ? `${TTo}${Join<RestPath>}`\n : never\n :\n | (TFrom extends `/`\n ? never\n : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]\n ? Join<RestPath> extends { length: 0 }\n ? never\n : './'\n : never)\n | (TFrom extends `/` ? never : '../')\n | AllPaths\n\nexport type NavigateOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n replace?: boolean\n resetScroll?: boolean\n // If set to `true`, the link's underlying navigate() call will be wrapped in a `React.startTransition` call. Defaults to `true`.\n startTransition?: boolean\n}\n\nexport type ToOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TFrom, TTo> & {\n mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TMaskFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,\n TMaskTo extends string = '',\n> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n> = {\n to?: ToPathOption<TRouteTree, TFrom, TTo>\n // The new has string or a function to update it\n hash?: true | Updater<string>\n // State to pass to the history stack\n state?: true | NonNullableUpdater<HistoryState>\n // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required\n from?: StringLiteral<TFrom>\n // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path\n} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &\n SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &\n PathParamOptions<TRouteTree, TFrom, TTo, TResolved>\n\ntype ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)\n\ntype ParamVariant = 'PATH' | 'SEARCH'\ntype ExcludeRootSearchSchema<T, Excluded = Exclude<T, RootSearchSchema>> = [\n Excluded,\n] extends [never]\n ? {}\n : Excluded\n\ntype PostProcessParams<\n T,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'SEARCH' ? ExcludeRootSearchSchema<T> : T\n\nexport type ParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo extends string,\n TResolved,\n TParamVariant extends ParamVariant,\n TFromRouteType extends\n | 'allParams'\n | 'fullSearchSchema' = TParamVariant extends 'PATH'\n ? 'allParams'\n : 'fullSearchSchema',\n TToRouteType extends\n | 'allParams'\n | 'fullSearchSchemaInput' = TParamVariant extends 'PATH'\n ? 'allParams'\n : 'fullSearchSchemaInput',\n TFromParams = PostProcessParams<\n RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType],\n TParamVariant\n >,\n TToIndex = TTo extends ''\n ? ''\n : RouteByPath<TRouteTree, `${TTo}/`> extends never\n ? TTo\n : `${TTo}/`,\n TToParams = TToIndex extends ''\n ? TFromParams\n : never extends TResolved\n ? PostProcessParams<\n RouteByPath<TRouteTree, TToIndex>['types'][TToRouteType],\n TParamVariant\n >\n : PostProcessParams<\n RouteByPath<TRouteTree, TResolved>['types'][TToRouteType],\n TParamVariant\n >,\n TReducer = ParamsReducer<TFromParams, TToParams>,\n> = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never\n ? Partial<MakeParamOption<TParamVariant, true | TReducer>>\n : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>>\n ? MakeParamOption<TParamVariant, true | TReducer>\n : MakeParamOption<TParamVariant, TReducer>\n\ntype MakeParamOption<\n TParamVariant extends ParamVariant,\n T,\n> = TParamVariant extends 'PATH'\n ? MakePathParamOptions<T>\n : MakeSearchParamOptions<T>\ntype MakeSearchParamOptions<T> = { search: T }\ntype MakePathParamOptions<T> = { params: T }\n\nexport type SearchParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo extends string,\n TResolved,\n> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'SEARCH'>\n\nexport type PathParamOptions<\n TRouteTree extends AnyRoute,\n TFrom,\n TTo extends string,\n TResolved,\n> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'PATH'>\n\nexport type ToPathOption<\n TRouteTree extends AnyRoute = AnyRoute,\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n> =\n | TTo\n | RelativeToPathAutoComplete<\n RoutePaths<TRouteTree>,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n}\n\nexport type LinkOptions<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // The standard anchor tag target attribute\n target?: HTMLAnchorElement['target']\n // Defaults to `{ exact: false, includeHash: false }`\n activeOptions?: ActiveOptions\n // If set, will preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n preload?: false | 'intent'\n // Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.\n preloadDelay?: number\n // If true, will render the link without the href attribute\n disabled?: boolean\n}\n\nexport type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<\n TPath,\n RoutePaths<TRouteTree>\n> extends never\n ? TPass\n : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>\n\nexport type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {\n to: RoutePaths<TRouteTree>\n}\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string\n ? TTo extends string\n ? TTo extends '.'\n ? TFrom\n : TTo extends `./`\n ? Join<[TFrom, '/']>\n : TTo extends `./${infer TRest}`\n ? ResolveRelativePath<TFrom, TRest>\n : TTo extends `/${infer TRest}`\n ? TTo\n : Split<TTo> extends ['..', ...infer ToRest]\n ? Split<TFrom> extends [...infer FromRest, infer FromTail]\n ? ToRest extends ['/']\n ? Join<[...FromRest, '/']>\n : ResolveRelativePath<Join<FromRest>, Join<ToRest>>\n : never\n : Split<TTo> extends ['.', ...infer ToRest]\n ? ToRest extends ['/']\n ? Join<[TFrom, '/']>\n : ResolveRelativePath<TFrom, Join<ToRest>>\n : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>\n : never\n : never\n\ntype LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nconst preloadWarning = 'Error preloading route! ☝️'\n\nexport function useLinkProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): React.AnchorHTMLAttributes<HTMLAnchorElement> {\n const router = useRouter()\n const matchPathname = useMatch({\n strict: false,\n select: (s) => s.pathname,\n })\n\n const {\n // custom props\n children,\n target,\n activeProps = () => ({ className: 'active' }),\n inactiveProps = () => ({}),\n activeOptions,\n disabled,\n hash,\n search,\n params,\n to,\n state,\n mask,\n preload: userPreload,\n preloadDelay: userPreloadDelay,\n replace,\n startTransition,\n resetScroll,\n // element props\n style,\n className,\n onClick,\n onFocus,\n onMouseEnter,\n onMouseLeave,\n onTouchStart,\n ...rest\n } = options\n\n // If this link simply reloads the current route,\n // make sure it has a new key so it will trigger a data refresh\n\n // If this `to` is a valid external URL, return\n // null for LinkUtils\n\n const dest = {\n from: options.to ? matchPathname : undefined,\n ...options,\n }\n\n let type: 'internal' | 'external' = 'internal'\n\n try {\n new URL(`${to}`)\n type = 'external'\n } catch {}\n\n if (type === 'external') {\n return {\n href: to,\n }\n }\n\n const next = router.buildLocation(dest as any)\n const preload = userPreload ?? router.options.defaultPreload\n const preloadDelay =\n userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = useRouterState({\n select: (s) => {\n // Compare path/hash for matches\n const currentPathSplit = s.location.pathname.split('/')\n const nextPathSplit = next.pathname.split('/')\n const pathIsFuzzyEqual = nextPathSplit.every(\n (d, i) => d === currentPathSplit[i],\n )\n // Combine the matches based on user router.options\n const pathTest = activeOptions?.exact\n ? s.location.pathname === next.pathname\n : pathIsFuzzyEqual\n const hashTest = activeOptions?.includeHash\n ? s.location.hash === next.hash\n : true\n const searchTest =\n activeOptions?.includeSearch ?? true\n ? deepEqual(s.location.search, next.search, !activeOptions?.exact)\n : true\n\n // The final \"active\" test\n return pathTest && hashTest && searchTest\n },\n })\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n if (\n !disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!target || target === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n // All is well? Navigate!\n router.commitLocation({ ...next, replace, resetScroll, startTransition })\n }\n }\n\n // The click handler\n const handleFocus = (e: MouseEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleTouchStart = (e: TouchEvent) => {\n if (preload) {\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }\n }\n\n const handleEnter = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (preload) {\n if (target.preloadTimeout) {\n return\n }\n\n target.preloadTimeout = setTimeout(() => {\n target.preloadTimeout = null\n router.preloadRoute(dest as any).catch((err) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n }, preloadDelay)\n }\n }\n\n const handleLeave = (e: MouseEvent) => {\n const target = (e.target || {}) as LinkCurrentTargetElement\n\n if (target.preloadTimeout) {\n clearTimeout(target.preloadTimeout)\n target.preloadTimeout = null\n }\n }\n\n const composeHandlers =\n (handlers: (undefined | ((e: any) => void))[]) =>\n (e: React.SyntheticEvent) => {\n if (e.persist) e.persist()\n handlers.filter(Boolean).forEach((handler) => {\n if (e.defaultPrevented) return\n handler!(e)\n })\n }\n\n // Get the active props\n const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> = isActive\n ? functionalUpdate(activeProps as any, {}) ?? {}\n : {}\n\n // Get the inactive props\n const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =\n isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}\n\n return {\n ...resolvedActiveProps,\n ...resolvedInactiveProps,\n ...rest,\n href: disabled\n ? undefined\n : next.maskedLocation\n ? next.maskedLocation.href\n : next.href,\n onClick: composeHandlers([onClick, handleClick]),\n onFocus: composeHandlers([onFocus, handleFocus]),\n onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),\n onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),\n onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),\n target,\n style: {\n ...style,\n ...resolvedActiveProps.style,\n ...resolvedInactiveProps.style,\n },\n className:\n [\n className,\n resolvedActiveProps.className,\n resolvedInactiveProps.className,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n ...(disabled\n ? {\n role: 'link',\n 'aria-disabled': true,\n }\n : undefined),\n ['data-status']: isActive ? 'active' : undefined,\n }\n}\n\nexport interface LinkComponent<TProps extends Record<string, any> = {}> {\n <\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n >(\n props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> &\n TProps &\n React.RefAttributes<HTMLAnchorElement>,\n ): ReactNode\n}\n\nexport const Link: LinkComponent = React.forwardRef((props: any, ref) => {\n const linkProps = useLinkProps(props)\n\n return (\n <a\n {...{\n ref: ref as any,\n ...linkProps,\n children:\n typeof props.children === 'function'\n ? props.children({\n isActive: (linkProps as any)['data-status'] === 'active',\n })\n : props.children,\n }}\n />\n )\n}) as any\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n"],"names":["target"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HistoryState } from '@tanstack/history';
|
|
2
|
+
import { AnySearchSchema } from './route';
|
|
3
|
+
export interface ParsedLocation<TSearchObj extends AnySearchSchema = {}> {
|
|
4
|
+
href: string;
|
|
5
|
+
pathname: string;
|
|
6
|
+
search: TSearchObj;
|
|
7
|
+
searchStr: string;
|
|
8
|
+
state: HistoryState;
|
|
9
|
+
hash: string;
|
|
10
|
+
maskedLocation?: ParsedLocation<TSearchObj>;
|
|
11
|
+
unmaskOnReload?: boolean;
|
|
12
|
+
}
|
|
@@ -11,7 +11,14 @@ export declare function trimPathRight(path: string): string;
|
|
|
11
11
|
export declare function trimPath(path: string): string;
|
|
12
12
|
export declare function resolvePath(basepath: string, base: string, to: string): string;
|
|
13
13
|
export declare function parsePathname(pathname?: string): Segment[];
|
|
14
|
-
|
|
14
|
+
interface InterpolatePathOptions {
|
|
15
|
+
path?: string;
|
|
16
|
+
params: any;
|
|
17
|
+
leaveWildcards?: boolean;
|
|
18
|
+
leaveParams?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function interpolatePath({ path, params, leaveWildcards, leaveParams, }: InterpolatePathOptions): string;
|
|
15
21
|
export declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
|
16
22
|
export declare function removeBasepath(basepath: string, pathname: string): string;
|
|
17
23
|
export declare function matchByPath(basepath: string, from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
|
|
24
|
+
export {};
|