@tanstack/react-router 1.7.1 → 1.8.0
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/{build/cjs/RouterProvider.js → dist/cjs/RouterProvider.cjs} +55 -58
- package/dist/cjs/RouterProvider.cjs.map +1 -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} +77 -94
- package/dist/cjs/path.cjs.map +1 -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 +1070 -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/esm/CatchBoundary.d.ts +36 -0
- package/dist/esm/CatchBoundary.js +89 -0
- package/dist/esm/CatchBoundary.js.map +1 -0
- package/dist/esm/Matches.d.ts +71 -0
- package/dist/esm/Matches.js +261 -0
- package/{build/cjs → dist/esm}/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +27 -0
- package/dist/esm/RouterProvider.js +136 -0
- package/{build/cjs → dist/esm}/RouterProvider.js.map +1 -1
- 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/dist/esm/path.d.ts +17 -0
- package/dist/esm/path.js +200 -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 +1070 -0
- package/{build/cjs → dist/esm}/router.js.map +1 -1
- 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/dist/esm/utils.d.ts +46 -0
- package/dist/esm/utils.js +137 -0
- package/{build/cjs → dist/esm}/utils.js.map +1 -1
- package/package.json +43 -22
- package/src/fileRoute.ts +4 -5
- package/src/link.tsx +5 -4
- package/src/route.ts +5 -6
- package/src/useSearch.tsx +5 -2
- 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/_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/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/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/Matches.d.ts → dist/cjs/Matches.d.cts} +0 -0
- /package/{build/types/RouterProvider.d.ts → dist/cjs/RouterProvider.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/path.d.ts → dist/cjs/path.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
- /package/{build/types/utils.d.ts → dist/cjs/utils.d.cts} +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Trim } from './fileRoute';
|
|
3
|
+
import { AnyRoute, ReactNode, RootSearchSchema } from './route';
|
|
4
|
+
import { RouteByPath, RoutePaths } from './routeInfo';
|
|
5
|
+
import { RegisteredRouter } from './router';
|
|
6
|
+
import { LinkProps, UseLinkPropsOptions } from './useNavigate';
|
|
7
|
+
import { Expand, NoInfer, NonNullableUpdater, PickRequired, StringLiteral, Updater, WithoutEmpty } from './utils';
|
|
8
|
+
import { HistoryState } from '@tanstack/history';
|
|
9
|
+
export type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
|
|
10
|
+
export type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
|
|
11
|
+
export type ParsePathParams<T extends string> = keyof {
|
|
12
|
+
[K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L extends '' ? '_splat' : L : never]: K;
|
|
13
|
+
};
|
|
14
|
+
export type Join<T, Delimiter extends string = '/'> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}${Delimiter}${Join<Tail>}`> : never;
|
|
15
|
+
export type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never;
|
|
16
|
+
export type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
17
|
+
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
18
|
+
...infer TToRest
|
|
19
|
+
] ? `${CleanPath<Join<[
|
|
20
|
+
...Split<TTo, false>,
|
|
21
|
+
...(TToRest | (Split<ResolveRelativePath<TFrom, TTo>, false>['length'] extends 1 ? never : ['../']))
|
|
22
|
+
]>>}` : never : TTo extends `./${infer RestTTo}` ? SplitPaths extends [
|
|
23
|
+
...Split<TFrom, false>,
|
|
24
|
+
...Split<RestTTo, false>,
|
|
25
|
+
...infer RestPath
|
|
26
|
+
] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
|
|
27
|
+
length: 0;
|
|
28
|
+
} ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
|
|
29
|
+
export type NavigateOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>, TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
30
|
+
replace?: boolean;
|
|
31
|
+
resetScroll?: boolean;
|
|
32
|
+
startTransition?: boolean;
|
|
33
|
+
};
|
|
34
|
+
export type ToOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>, TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TFrom, TTo> & {
|
|
35
|
+
mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>;
|
|
36
|
+
};
|
|
37
|
+
export type ToMaskOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TMaskFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>, TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
|
|
38
|
+
unmaskOnReload?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>, TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
41
|
+
to?: ToPathOption<TRouteTree, TFrom, TTo>;
|
|
42
|
+
hash?: true | Updater<string>;
|
|
43
|
+
state?: true | NonNullableUpdater<HistoryState>;
|
|
44
|
+
from?: StringLiteral<TFrom>;
|
|
45
|
+
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TTo, TResolved>;
|
|
46
|
+
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
47
|
+
type ParamVariant = 'PATH' | 'SEARCH';
|
|
48
|
+
type ExcludeRootSearchSchema<T, Excluded = Exclude<T, RootSearchSchema>> = [
|
|
49
|
+
Excluded
|
|
50
|
+
] extends [never] ? {} : Excluded;
|
|
51
|
+
type PostProcessParams<T, TParamVariant extends ParamVariant> = TParamVariant extends 'SEARCH' ? ExcludeRootSearchSchema<T> : T;
|
|
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>;
|
|
53
|
+
type MakeParamOption<TParamVariant extends ParamVariant, T> = TParamVariant extends 'PATH' ? MakePathParamOptions<T> : MakeSearchParamOptions<T>;
|
|
54
|
+
type MakeSearchParamOptions<T> = {
|
|
55
|
+
search: T;
|
|
56
|
+
};
|
|
57
|
+
type MakePathParamOptions<T> = {
|
|
58
|
+
params: T;
|
|
59
|
+
};
|
|
60
|
+
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo extends string, TResolved> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'SEARCH'>;
|
|
61
|
+
export type PathParamOptions<TRouteTree extends AnyRoute, TFrom, TTo extends string, TResolved> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'PATH'>;
|
|
62
|
+
export type ToPathOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RoutePaths<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
63
|
+
export interface ActiveOptions {
|
|
64
|
+
exact?: boolean;
|
|
65
|
+
includeHash?: boolean;
|
|
66
|
+
includeSearch?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export type LinkOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
69
|
+
target?: HTMLAnchorElement['target'];
|
|
70
|
+
activeOptions?: ActiveOptions;
|
|
71
|
+
preload?: false | 'intent';
|
|
72
|
+
preloadDelay?: number;
|
|
73
|
+
disabled?: boolean;
|
|
74
|
+
};
|
|
75
|
+
export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<TPath, RoutePaths<TRouteTree>> extends never ? TPass : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>;
|
|
76
|
+
export type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
77
|
+
to: RoutePaths<TRouteTree>;
|
|
78
|
+
};
|
|
79
|
+
export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string ? TTo extends string ? TTo extends '.' ? TFrom : TTo extends `./` ? Join<[TFrom, '/']> : TTo extends `./${infer TRest}` ? ResolveRelativePath<TFrom, TRest> : TTo extends `/${infer TRest}` ? TTo : Split<TTo> extends ['..', ...infer ToRest] ? Split<TFrom> extends [...infer FromRest, infer FromTail] ? ToRest extends ['/'] ? Join<[...FromRest, '/']> : ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ToRest extends ['/'] ? Join<[TFrom, '/']> : ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
|
|
80
|
+
export declare function useLinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
81
|
+
export interface LinkComponent<TProps extends Record<string, any> = {}> {
|
|
82
|
+
<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & TProps & React.RefAttributes<HTMLAnchorElement>): ReactNode;
|
|
83
|
+
}
|
|
84
|
+
export declare const Link: LinkComponent;
|
|
85
|
+
export {};
|
|
@@ -1,60 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var utils = require('./utils.js');
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utils = require("./utils.cjs");
|
|
15
4
|
function joinPaths(paths) {
|
|
16
|
-
return cleanPath(paths.filter(Boolean).join(
|
|
5
|
+
return cleanPath(paths.filter(Boolean).join("/"));
|
|
17
6
|
}
|
|
18
7
|
function cleanPath(path) {
|
|
19
|
-
|
|
20
|
-
return path.replace(/\/{2,}/g, '/');
|
|
8
|
+
return path.replace(/\/{2,}/g, "/");
|
|
21
9
|
}
|
|
22
10
|
function trimPathLeft(path) {
|
|
23
|
-
return path ===
|
|
11
|
+
return path === "/" ? path : path.replace(/^\/{1,}/, "");
|
|
24
12
|
}
|
|
25
13
|
function trimPathRight(path) {
|
|
26
|
-
return path ===
|
|
14
|
+
return path === "/" ? path : path.replace(/\/{1,}$/, "");
|
|
27
15
|
}
|
|
28
16
|
function trimPath(path) {
|
|
29
17
|
return trimPathRight(trimPathLeft(path));
|
|
30
18
|
}
|
|
31
19
|
function resolvePath(basepath, base, to) {
|
|
32
|
-
base = base.replace(new RegExp(`^${basepath}`),
|
|
33
|
-
to = to.replace(new RegExp(`^${basepath}`),
|
|
20
|
+
base = base.replace(new RegExp(`^${basepath}`), "/");
|
|
21
|
+
to = to.replace(new RegExp(`^${basepath}`), "/");
|
|
34
22
|
let baseSegments = parsePathname(base);
|
|
35
23
|
const toSegments = parsePathname(to);
|
|
36
24
|
toSegments.forEach((toSegment, index) => {
|
|
37
|
-
|
|
25
|
+
var _a;
|
|
26
|
+
if (toSegment.value === "/") {
|
|
38
27
|
if (!index) {
|
|
39
|
-
// Leading slash
|
|
40
28
|
baseSegments = [toSegment];
|
|
41
29
|
} else if (index === toSegments.length - 1) {
|
|
42
|
-
// Trailing Slash
|
|
43
30
|
baseSegments.push(toSegment);
|
|
44
|
-
} else
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (baseSegments.length > 1 && utils.last(baseSegments)
|
|
31
|
+
} else
|
|
32
|
+
;
|
|
33
|
+
} else if (toSegment.value === "..") {
|
|
34
|
+
if (baseSegments.length > 1 && ((_a = utils.last(baseSegments)) == null ? void 0 : _a.value) === "/") {
|
|
48
35
|
baseSegments.pop();
|
|
49
36
|
}
|
|
50
37
|
baseSegments.pop();
|
|
51
|
-
} else if (toSegment.value ===
|
|
38
|
+
} else if (toSegment.value === ".") {
|
|
52
39
|
return;
|
|
53
40
|
} else {
|
|
54
41
|
baseSegments.push(toSegment);
|
|
55
42
|
}
|
|
56
43
|
});
|
|
57
|
-
const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
|
|
44
|
+
const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)]);
|
|
58
45
|
return cleanPath(joined);
|
|
59
46
|
}
|
|
60
47
|
function parsePathname(pathname) {
|
|
@@ -63,90 +50,88 @@ function parsePathname(pathname) {
|
|
|
63
50
|
}
|
|
64
51
|
pathname = cleanPath(pathname);
|
|
65
52
|
const segments = [];
|
|
66
|
-
if (pathname.slice(0, 1) ===
|
|
53
|
+
if (pathname.slice(0, 1) === "/") {
|
|
67
54
|
pathname = pathname.substring(1);
|
|
68
55
|
segments.push({
|
|
69
|
-
type:
|
|
70
|
-
value:
|
|
56
|
+
type: "pathname",
|
|
57
|
+
value: "/"
|
|
71
58
|
});
|
|
72
59
|
}
|
|
73
60
|
if (!pathname) {
|
|
74
61
|
return segments;
|
|
75
62
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
const split = pathname.split("/").filter(Boolean);
|
|
64
|
+
segments.push(
|
|
65
|
+
...split.map((part) => {
|
|
66
|
+
if (part === "$" || part === "*") {
|
|
67
|
+
return {
|
|
68
|
+
type: "wildcard",
|
|
69
|
+
value: part
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (part.charAt(0) === "$") {
|
|
73
|
+
return {
|
|
74
|
+
type: "param",
|
|
75
|
+
value: part
|
|
76
|
+
};
|
|
77
|
+
}
|
|
87
78
|
return {
|
|
88
|
-
type:
|
|
79
|
+
type: "pathname",
|
|
89
80
|
value: part
|
|
90
81
|
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
value: part
|
|
95
|
-
};
|
|
96
|
-
}));
|
|
97
|
-
if (pathname.slice(-1) === '/') {
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
if (pathname.slice(-1) === "/") {
|
|
98
85
|
pathname = pathname.substring(1);
|
|
99
86
|
segments.push({
|
|
100
|
-
type:
|
|
101
|
-
value:
|
|
87
|
+
type: "pathname",
|
|
88
|
+
value: "/"
|
|
102
89
|
});
|
|
103
90
|
}
|
|
104
91
|
return segments;
|
|
105
92
|
}
|
|
106
93
|
function interpolatePath(path, params, leaveWildcards = false) {
|
|
107
94
|
const interpolatedPathSegments = parsePathname(path);
|
|
108
|
-
return joinPaths(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
95
|
+
return joinPaths(
|
|
96
|
+
interpolatedPathSegments.map((segment) => {
|
|
97
|
+
if (segment.type === "wildcard") {
|
|
98
|
+
const value = params[segment.value];
|
|
99
|
+
if (leaveWildcards)
|
|
100
|
+
return `${segment.value}${value ?? ""}`;
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
if (segment.type === "param") {
|
|
104
|
+
return params[segment.value.substring(1)] ?? "undefined";
|
|
105
|
+
}
|
|
106
|
+
return segment.value;
|
|
107
|
+
})
|
|
108
|
+
);
|
|
119
109
|
}
|
|
120
110
|
function matchPathname(basepath, currentPathname, matchLocation) {
|
|
121
111
|
const pathParams = matchByPath(basepath, currentPathname, matchLocation);
|
|
122
|
-
// const searchMatched = matchBySearch(location.search, matchLocation)
|
|
123
|
-
|
|
124
112
|
if (matchLocation.to && !pathParams) {
|
|
125
113
|
return;
|
|
126
114
|
}
|
|
127
115
|
return pathParams ?? {};
|
|
128
116
|
}
|
|
129
117
|
function removeBasepath(basepath, pathname) {
|
|
130
|
-
return basepath !=
|
|
118
|
+
return basepath != "/" ? pathname.substring(basepath.length) : pathname;
|
|
131
119
|
}
|
|
132
120
|
function matchByPath(basepath, from, matchLocation) {
|
|
133
|
-
// Remove the base path from the pathname
|
|
134
121
|
from = removeBasepath(basepath, from);
|
|
135
|
-
|
|
136
|
-
const to = `${matchLocation.to ?? '$'}`;
|
|
137
|
-
// Parse the from and to
|
|
122
|
+
const to = `${matchLocation.to ?? "$"}`;
|
|
138
123
|
const baseSegments = parsePathname(from);
|
|
139
124
|
const routeSegments = parsePathname(to);
|
|
140
|
-
if (!from.startsWith(
|
|
125
|
+
if (!from.startsWith("/")) {
|
|
141
126
|
baseSegments.unshift({
|
|
142
|
-
type:
|
|
143
|
-
value:
|
|
127
|
+
type: "pathname",
|
|
128
|
+
value: "/"
|
|
144
129
|
});
|
|
145
130
|
}
|
|
146
|
-
if (!to.startsWith(
|
|
131
|
+
if (!to.startsWith("/")) {
|
|
147
132
|
routeSegments.unshift({
|
|
148
|
-
type:
|
|
149
|
-
value:
|
|
133
|
+
type: "pathname",
|
|
134
|
+
value: "/"
|
|
150
135
|
});
|
|
151
136
|
}
|
|
152
137
|
const params = {};
|
|
@@ -157,18 +142,17 @@ function matchByPath(basepath, from, matchLocation) {
|
|
|
157
142
|
const isLastBaseSegment = i >= baseSegments.length - 1;
|
|
158
143
|
const isLastRouteSegment = i >= routeSegments.length - 1;
|
|
159
144
|
if (routeSegment) {
|
|
160
|
-
if (routeSegment.type ===
|
|
161
|
-
if (baseSegment
|
|
162
|
-
const _splat = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
163
|
-
|
|
164
|
-
params[
|
|
165
|
-
params['_splat'] = _splat;
|
|
145
|
+
if (routeSegment.type === "wildcard") {
|
|
146
|
+
if (baseSegment == null ? void 0 : baseSegment.value) {
|
|
147
|
+
const _splat = joinPaths(baseSegments.slice(i).map((d) => d.value));
|
|
148
|
+
params["*"] = _splat;
|
|
149
|
+
params["_splat"] = _splat;
|
|
166
150
|
return true;
|
|
167
151
|
}
|
|
168
152
|
return false;
|
|
169
153
|
}
|
|
170
|
-
if (routeSegment.type ===
|
|
171
|
-
if (routeSegment.value ===
|
|
154
|
+
if (routeSegment.type === "pathname") {
|
|
155
|
+
if (routeSegment.value === "/" && !(baseSegment == null ? void 0 : baseSegment.value)) {
|
|
172
156
|
return true;
|
|
173
157
|
}
|
|
174
158
|
if (baseSegment) {
|
|
@@ -184,25 +168,24 @@ function matchByPath(basepath, from, matchLocation) {
|
|
|
184
168
|
if (!baseSegment) {
|
|
185
169
|
return false;
|
|
186
170
|
}
|
|
187
|
-
if (routeSegment.type ===
|
|
188
|
-
if (baseSegment
|
|
171
|
+
if (routeSegment.type === "param") {
|
|
172
|
+
if ((baseSegment == null ? void 0 : baseSegment.value) === "/") {
|
|
189
173
|
return false;
|
|
190
174
|
}
|
|
191
|
-
if (baseSegment.value.charAt(0) !==
|
|
175
|
+
if (baseSegment.value.charAt(0) !== "$") {
|
|
192
176
|
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
193
177
|
}
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
180
|
if (!isLastBaseSegment && isLastRouteSegment) {
|
|
197
|
-
params[
|
|
198
|
-
return !!matchLocation.fuzzy && routeSegment
|
|
181
|
+
params["**"] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value));
|
|
182
|
+
return !!matchLocation.fuzzy && (routeSegment == null ? void 0 : routeSegment.value) !== "/";
|
|
199
183
|
}
|
|
200
184
|
}
|
|
201
185
|
return true;
|
|
202
186
|
})();
|
|
203
|
-
return isMatch ? params :
|
|
187
|
+
return isMatch ? params : void 0;
|
|
204
188
|
}
|
|
205
|
-
|
|
206
189
|
exports.cleanPath = cleanPath;
|
|
207
190
|
exports.interpolatePath = interpolatePath;
|
|
208
191
|
exports.joinPaths = joinPaths;
|
|
@@ -214,4 +197,4 @@ exports.resolvePath = resolvePath;
|
|
|
214
197
|
exports.trimPath = trimPath;
|
|
215
198
|
exports.trimPathLeft = trimPathLeft;
|
|
216
199
|
exports.trimPathRight = trimPathRight;
|
|
217
|
-
//# sourceMappingURL=path.
|
|
200
|
+
//# sourceMappingURL=path.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.cjs","sources":["../../src/path.ts"],"sourcesContent":["import { MatchLocation } from './RouterProvider'\nimport { AnyPathParams } from './route'\nimport { last } from './utils'\n\nexport interface Segment {\n type: 'pathname' | 'param' | 'wildcard'\n value: string\n}\n\nexport function joinPaths(paths: (string | undefined)[]) {\n return cleanPath(paths.filter(Boolean).join('/'))\n}\n\nexport function cleanPath(path: string) {\n // remove double slashes\n return path.replace(/\\/{2,}/g, '/')\n}\n\nexport function trimPathLeft(path: string) {\n return path === '/' ? path : path.replace(/^\\/{1,}/, '')\n}\n\nexport function trimPathRight(path: string) {\n return path === '/' ? path : path.replace(/\\/{1,}$/, '')\n}\n\nexport function trimPath(path: string) {\n return trimPathRight(trimPathLeft(path))\n}\n\nexport function resolvePath(basepath: string, base: string, to: string) {\n base = base.replace(new RegExp(`^${basepath}`), '/')\n to = to.replace(new RegExp(`^${basepath}`), '/')\n\n let baseSegments = parsePathname(base)\n const toSegments = parsePathname(to)\n\n toSegments.forEach((toSegment, index) => {\n if (toSegment.value === '/') {\n if (!index) {\n // Leading slash\n baseSegments = [toSegment]\n } else if (index === toSegments.length - 1) {\n // Trailing Slash\n baseSegments.push(toSegment)\n } else {\n // ignore inter-slashes\n }\n } else if (toSegment.value === '..') {\n // Extra trailing slash? pop it off\n if (baseSegments.length > 1 && last(baseSegments)?.value === '/') {\n baseSegments.pop()\n }\n baseSegments.pop()\n } else if (toSegment.value === '.') {\n return\n } else {\n baseSegments.push(toSegment)\n }\n })\n\n const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)])\n\n return cleanPath(joined)\n}\n\nexport function parsePathname(pathname?: string): Segment[] {\n if (!pathname) {\n return []\n }\n\n pathname = cleanPath(pathname)\n\n const segments: Segment[] = []\n\n if (pathname.slice(0, 1) === '/') {\n pathname = pathname.substring(1)\n segments.push({\n type: 'pathname',\n value: '/',\n })\n }\n\n if (!pathname) {\n return segments\n }\n\n // Remove empty segments and '.' segments\n const split = pathname.split('/').filter(Boolean)\n\n segments.push(\n ...split.map((part): Segment => {\n if (part === '$' || part === '*') {\n return {\n type: 'wildcard',\n value: part,\n }\n }\n\n if (part.charAt(0) === '$') {\n return {\n type: 'param',\n value: part,\n }\n }\n\n return {\n type: 'pathname',\n value: part,\n }\n }),\n )\n\n if (pathname.slice(-1) === '/') {\n pathname = pathname.substring(1)\n segments.push({\n type: 'pathname',\n value: '/',\n })\n }\n\n return segments\n}\n\nexport function interpolatePath(\n path: string | undefined,\n params: any,\n leaveWildcards: boolean = false,\n) {\n const interpolatedPathSegments = parsePathname(path)\n\n return joinPaths(\n interpolatedPathSegments.map((segment) => {\n if (segment.type === 'wildcard') {\n const value = params[segment.value]\n if (leaveWildcards) return `${segment.value}${value ?? ''}`\n return value\n }\n\n if (segment.type === 'param') {\n return params![segment.value.substring(1)] ?? 'undefined'\n }\n\n return segment.value\n }),\n )\n}\n\nexport function matchPathname(\n basepath: string,\n currentPathname: string,\n matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,\n): AnyPathParams | undefined {\n const pathParams = matchByPath(basepath, currentPathname, matchLocation)\n // const searchMatched = matchBySearch(location.search, matchLocation)\n\n if (matchLocation.to && !pathParams) {\n return\n }\n\n return pathParams ?? {}\n}\n\nexport function removeBasepath(basepath: string, pathname: string) {\n return basepath != '/' ? pathname.substring(basepath.length) : pathname\n}\n\nexport function matchByPath(\n basepath: string,\n from: string,\n matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,\n): Record<string, string> | undefined {\n // Remove the base path from the pathname\n from = removeBasepath(basepath, from)\n // Default to to $ (wildcard)\n const to = `${matchLocation.to ?? '$'}`\n // Parse the from and to\n const baseSegments = parsePathname(from)\n const routeSegments = parsePathname(to)\n\n if (!from.startsWith('/')) {\n baseSegments.unshift({\n type: 'pathname',\n value: '/',\n })\n }\n\n if (!to.startsWith('/')) {\n routeSegments.unshift({\n type: 'pathname',\n value: '/',\n })\n }\n\n const params: Record<string, string> = {}\n\n let isMatch = (() => {\n for (\n let i = 0;\n i < Math.max(baseSegments.length, routeSegments.length);\n i++\n ) {\n const baseSegment = baseSegments[i]\n const routeSegment = routeSegments[i]\n\n const isLastBaseSegment = i >= baseSegments.length - 1\n const isLastRouteSegment = i >= routeSegments.length - 1\n\n if (routeSegment) {\n if (routeSegment.type === 'wildcard') {\n if (baseSegment?.value) {\n const _splat = joinPaths(baseSegments.slice(i).map((d) => d.value))\n // TODO: Deprecate *\n params['*'] = _splat\n params['_splat'] = _splat\n return true\n }\n return false\n }\n\n if (routeSegment.type === 'pathname') {\n if (routeSegment.value === '/' && !baseSegment?.value) {\n return true\n }\n\n if (baseSegment) {\n if (matchLocation.caseSensitive) {\n if (routeSegment.value !== baseSegment.value) {\n return false\n }\n } else if (\n routeSegment.value.toLowerCase() !==\n baseSegment.value.toLowerCase()\n ) {\n return false\n }\n }\n }\n\n if (!baseSegment) {\n return false\n }\n\n if (routeSegment.type === 'param') {\n if (baseSegment?.value === '/') {\n return false\n }\n if (baseSegment.value.charAt(0) !== '$') {\n params[routeSegment.value.substring(1)] = baseSegment.value\n }\n }\n }\n\n if (!isLastBaseSegment && isLastRouteSegment) {\n params['**'] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value))\n return !!matchLocation.fuzzy && routeSegment?.value !== '/'\n }\n }\n\n return true\n })()\n\n return isMatch ? (params as Record<string, string>) : undefined\n}\n"],"names":["last"],"mappings":";;;AASO,SAAS,UAAU,OAA+B;AACvD,SAAO,UAAU,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AAClD;AAEO,SAAS,UAAU,MAAc;AAE/B,SAAA,KAAK,QAAQ,WAAW,GAAG;AACpC;AAEO,SAAS,aAAa,MAAc;AACzC,SAAO,SAAS,MAAM,OAAO,KAAK,QAAQ,WAAW,EAAE;AACzD;AAEO,SAAS,cAAc,MAAc;AAC1C,SAAO,SAAS,MAAM,OAAO,KAAK,QAAQ,WAAW,EAAE;AACzD;AAEO,SAAS,SAAS,MAAc;AAC9B,SAAA,cAAc,aAAa,IAAI,CAAC;AACzC;AAEgB,SAAA,YAAY,UAAkB,MAAc,IAAY;AAC/D,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AA,QACT;AAEI,YAAA,aAAa,SAAS,SAAS;AAC7B,eAAA,2CAAa,WAAU,KAAK;AACvB,mBAAA;AAAA,UACT;AACA,cAAI,YAAY,MAAM,OAAO,CAAC,MAAM,KAAK;AACvC,mBAAO,aAAa,MAAM,UAAU,CAAC,CAAC,IAAI,YAAY;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AAEI,UAAA,CAAC,qBAAqB,oBAAoB;AAC5C,eAAO,IAAI,IAAI,UAAU,aAAa,MAAM,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AACtE,eAAO,CAAC,CAAC,cAAc,UAAS,6CAAc,WAAU;AAAA,MAC1D;AAAA,IACF;AAEO,WAAA;AAAA,EAAA;AAGT,SAAO,UAAW,SAAoC;AACxD;;;;;;;;;;;;"}
|
package/dist/cjs/qss.cjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function encode(obj, pfx) {
|
|
4
|
+
var k, i, tmp, str = "";
|
|
5
|
+
for (k in obj) {
|
|
6
|
+
if ((tmp = obj[k]) !== void 0) {
|
|
7
|
+
if (Array.isArray(tmp)) {
|
|
8
|
+
for (i = 0; i < tmp.length; i++) {
|
|
9
|
+
str && (str += "&");
|
|
10
|
+
str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]);
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
str && (str += "&");
|
|
14
|
+
str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return (pfx || "") + str;
|
|
19
|
+
}
|
|
20
|
+
function toValue(mix) {
|
|
21
|
+
if (!mix)
|
|
22
|
+
return "";
|
|
23
|
+
var str = decodeURIComponent(mix);
|
|
24
|
+
if (str === "false")
|
|
25
|
+
return false;
|
|
26
|
+
if (str === "true")
|
|
27
|
+
return true;
|
|
28
|
+
return +str * 0 === 0 && +str + "" === str ? +str : str;
|
|
29
|
+
}
|
|
30
|
+
function decode(str) {
|
|
31
|
+
var tmp, k, out = {}, arr = str.split("&");
|
|
32
|
+
while (tmp = arr.shift()) {
|
|
33
|
+
tmp = tmp.split("=");
|
|
34
|
+
k = tmp.shift();
|
|
35
|
+
if (out[k] !== void 0) {
|
|
36
|
+
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
37
|
+
} else {
|
|
38
|
+
out[k] = toValue(tmp.shift());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
exports.decode = decode;
|
|
44
|
+
exports.encode = encode;
|
|
45
|
+
//# sourceMappingURL=qss.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qss.cjs","sources":["../../src/qss.ts"],"sourcesContent":["// @ts-nocheck\n\n// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.\n\nexport function encode(obj, pfx?: string) {\n var k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\nfunction toValue(mix) {\n if (!mix) return ''\n var str = decodeURIComponent(mix)\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\nexport function decode(str) {\n var tmp,\n k,\n out = {},\n arr = str.split('&')\n\n while ((tmp = arr.shift())) {\n tmp = tmp.split('=')\n k = tmp.shift()\n if (out[k] !== void 0) {\n out[k] = [].concat(out[k], toValue(tmp.shift()))\n } else {\n out[k] = toValue(tmp.shift())\n }\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});
|
|
3
|
+
function redirect(opts) {
|
|
4
|
+
opts.isRedirect = true;
|
|
5
|
+
if (opts.throw) {
|
|
6
|
+
throw opts;
|
|
7
|
+
}
|
|
8
|
+
return opts;
|
|
9
|
+
}
|
|
10
|
+
function isRedirect(obj) {
|
|
11
|
+
return !!(obj == null ? void 0 : obj.isRedirect);
|
|
12
|
+
}
|
|
13
|
+
exports.isRedirect = isRedirect;
|
|
14
|
+
exports.redirect = redirect;
|
|
15
|
+
//# sourceMappingURL=redirects.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirects.cjs","sources":["../../src/redirects.ts"],"sourcesContent":["import { NavigateOptions } from './link'\nimport { AnyRoute } from './route'\nimport { RoutePaths } from './routeInfo'\nimport { RegisteredRouter } from './router'\n\n// Detect if we're in the DOM\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\nexport type Redirect<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n> = {\n code?: number\n throw?: any\n} & NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport function redirect<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> = TFrom,\n TMaskTo extends string = '',\n>(\n opts: Redirect<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> {\n ;(opts as any).isRedirect = true\n if (opts.throw) {\n throw opts\n }\n return opts\n}\n\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return !!obj?.isRedirect\n}\n"],"names":[],"mappings":";;AAoBO,SAAS,SAOd,MACsD;AACpD,OAAa,aAAa;AAC5B,MAAI,KAAK,OAAO;AACR,UAAA;AAAA,EACR;AACO,SAAA;AACT;AAEO,SAAS,WAAW,KAA8B;AAChD,SAAA,CAAC,EAAC,2BAAK;AAChB;;;"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const invariant = require("tiny-invariant");
|
|
4
|
+
const Matches = require("./Matches.cjs");
|
|
5
|
+
const path = require("./path.cjs");
|
|
6
|
+
const useParams = require("./useParams.cjs");
|
|
7
|
+
const useSearch = require("./useSearch.cjs");
|
|
8
|
+
const rootRouteId = "__root__";
|
|
9
|
+
class RouteApi {
|
|
10
|
+
constructor({ id }) {
|
|
11
|
+
this.useMatch = (opts) => {
|
|
12
|
+
return Matches.useMatch({ select: opts == null ? void 0 : opts.select, from: this.id });
|
|
13
|
+
};
|
|
14
|
+
this.useRouteContext = (opts) => {
|
|
15
|
+
return Matches.useMatch({
|
|
16
|
+
from: this.id,
|
|
17
|
+
select: (d) => (opts == null ? void 0 : opts.select) ? opts.select(d.context) : d.context
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
this.useSearch = (opts) => {
|
|
21
|
+
return useSearch.useSearch({ ...opts, from: this.id });
|
|
22
|
+
};
|
|
23
|
+
this.useParams = (opts) => {
|
|
24
|
+
return useParams.useParams({ ...opts, from: this.id });
|
|
25
|
+
};
|
|
26
|
+
this.useLoaderDeps = (opts) => {
|
|
27
|
+
return Matches.useLoaderDeps({ ...opts, from: this.id });
|
|
28
|
+
};
|
|
29
|
+
this.useLoaderData = (opts) => {
|
|
30
|
+
return Matches.useLoaderData({ ...opts, from: this.id });
|
|
31
|
+
};
|
|
32
|
+
this.id = id;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class Route {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.init = (opts) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
this.originalIndex = opts.originalIndex;
|
|
40
|
+
const options2 = this.options;
|
|
41
|
+
const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id);
|
|
42
|
+
this.parentRoute = (_b = (_a = this.options) == null ? void 0 : _a.getParentRoute) == null ? void 0 : _b.call(_a);
|
|
43
|
+
if (isRoot) {
|
|
44
|
+
this.path = rootRouteId;
|
|
45
|
+
} else {
|
|
46
|
+
invariant(
|
|
47
|
+
this.parentRoute,
|
|
48
|
+
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
let path$1 = isRoot ? rootRouteId : options2.path;
|
|
52
|
+
if (path$1 && path$1 !== "/") {
|
|
53
|
+
path$1 = path.trimPath(path$1);
|
|
54
|
+
}
|
|
55
|
+
const customId = (options2 == null ? void 0 : options2.id) || path$1;
|
|
56
|
+
let id = isRoot ? rootRouteId : path.joinPaths([
|
|
57
|
+
this.parentRoute.id === rootRouteId ? "" : this.parentRoute.id,
|
|
58
|
+
customId
|
|
59
|
+
]);
|
|
60
|
+
if (path$1 === rootRouteId) {
|
|
61
|
+
path$1 = "/";
|
|
62
|
+
}
|
|
63
|
+
if (id !== rootRouteId) {
|
|
64
|
+
id = path.joinPaths(["/", id]);
|
|
65
|
+
}
|
|
66
|
+
const fullPath = id === rootRouteId ? "/" : path.joinPaths([this.parentRoute.fullPath, path$1]);
|
|
67
|
+
this.path = path$1;
|
|
68
|
+
this.id = id;
|
|
69
|
+
this.fullPath = fullPath;
|
|
70
|
+
this.to = fullPath;
|
|
71
|
+
};
|
|
72
|
+
this.addChildren = (children) => {
|
|
73
|
+
this.children = children;
|
|
74
|
+
return this;
|
|
75
|
+
};
|
|
76
|
+
this.updateLoader = (options2) => {
|
|
77
|
+
Object.assign(this.options, options2);
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
this.update = (options2) => {
|
|
81
|
+
Object.assign(this.options, options2);
|
|
82
|
+
return this;
|
|
83
|
+
};
|
|
84
|
+
this.useMatch = (opts) => {
|
|
85
|
+
return Matches.useMatch({ ...opts, from: this.id });
|
|
86
|
+
};
|
|
87
|
+
this.useRouteContext = (opts) => {
|
|
88
|
+
return Matches.useMatch({
|
|
89
|
+
...opts,
|
|
90
|
+
from: this.id,
|
|
91
|
+
select: (d) => (opts == null ? void 0 : opts.select) ? opts.select(d.context) : d.context
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
this.useSearch = (opts) => {
|
|
95
|
+
return useSearch.useSearch({ ...opts, from: this.id });
|
|
96
|
+
};
|
|
97
|
+
this.useParams = (opts) => {
|
|
98
|
+
return useParams.useParams({ ...opts, from: this.id });
|
|
99
|
+
};
|
|
100
|
+
this.useLoaderDeps = (opts) => {
|
|
101
|
+
return Matches.useLoaderDeps({ ...opts, from: this.id });
|
|
102
|
+
};
|
|
103
|
+
this.useLoaderData = (opts) => {
|
|
104
|
+
return Matches.useLoaderData({ ...opts, from: this.id });
|
|
105
|
+
};
|
|
106
|
+
this.options = options || {};
|
|
107
|
+
this.isRoot = !(options == null ? void 0 : options.getParentRoute);
|
|
108
|
+
invariant(
|
|
109
|
+
!((options == null ? void 0 : options.id) && (options == null ? void 0 : options.path)),
|
|
110
|
+
`Route cannot have both an 'id' and a 'path' option.`
|
|
111
|
+
);
|
|
112
|
+
this.$$typeof = Symbol.for("react.memo");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function rootRouteWithContext() {
|
|
116
|
+
return (options) => {
|
|
117
|
+
return new RootRoute(options);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
class RootRoute extends Route {
|
|
121
|
+
constructor(options) {
|
|
122
|
+
super(options);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function createRouteMask(opts) {
|
|
126
|
+
return opts;
|
|
127
|
+
}
|
|
128
|
+
class NotFoundRoute extends Route {
|
|
129
|
+
constructor(options) {
|
|
130
|
+
super({
|
|
131
|
+
...options,
|
|
132
|
+
id: "404"
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.NotFoundRoute = NotFoundRoute;
|
|
137
|
+
exports.RootRoute = RootRoute;
|
|
138
|
+
exports.Route = Route;
|
|
139
|
+
exports.RouteApi = RouteApi;
|
|
140
|
+
exports.createRouteMask = createRouteMask;
|
|
141
|
+
exports.rootRouteId = rootRouteId;
|
|
142
|
+
exports.rootRouteWithContext = rootRouteWithContext;
|
|
143
|
+
//# sourceMappingURL=route.cjs.map
|