@tanstack/react-router 1.97.19 → 1.97.21
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/Match.cjs +4 -5
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +0 -10
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +3 -30
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +2 -2
- package/dist/cjs/Transitioner.cjs +2 -2
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/awaited.cjs +6 -6
- package/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/awaited.d.cts +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -3
- package/dist/cjs/index.cjs +136 -42
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +12 -26
- package/dist/cjs/link.cjs +8 -9
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +2 -49
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +1 -1
- package/dist/cjs/route.cjs +14 -15
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +4 -151
- package/dist/cjs/routeInfo.d.cts +2 -3
- package/dist/cjs/router.cjs +51 -70
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +4 -19
- package/dist/cjs/routerContext.d.cts +1 -1
- package/dist/cjs/scroll-restoration.cjs +2 -2
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -1
- package/dist/cjs/structuralSharing.d.cts +1 -4
- package/dist/cjs/typePrimitives.d.cts +1 -1
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +2 -1
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +2 -1
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +2 -1
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +2 -1
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +2 -1
- package/dist/cjs/useRouterState.cjs +2 -2
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +2 -1
- package/dist/cjs/utils.cjs +0 -152
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -79
- package/dist/esm/Match.js +1 -2
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +3 -30
- package/dist/esm/Matches.js +0 -10
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +2 -2
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/Transitioner.js +1 -1
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/awaited.d.ts +1 -1
- package/dist/esm/awaited.js +1 -1
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +2 -3
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +12 -26
- package/dist/esm/index.js +5 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/link.d.ts +2 -49
- package/dist/esm/link.js +2 -3
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirects.d.ts +1 -1
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +4 -151
- package/dist/esm/route.js +1 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +2 -3
- package/dist/esm/router.d.ts +4 -19
- package/dist/esm/router.js +1 -20
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -1
- package/dist/esm/scroll-restoration.js +1 -1
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/structuralSharing.d.ts +1 -4
- package/dist/esm/typePrimitives.d.ts +1 -1
- package/dist/esm/useLoaderData.d.ts +2 -1
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +2 -1
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useMatch.d.ts +2 -1
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useParams.d.ts +2 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +2 -1
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useRouterState.js +1 -1
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.d.ts +2 -1
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -79
- package/dist/esm/utils.js +0 -152
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/Match.tsx +5 -2
- package/src/Matches.tsx +8 -101
- package/src/RouterProvider.tsx +4 -2
- package/src/Transitioner.tsx +1 -1
- package/src/awaited.tsx +2 -2
- package/src/fileRoute.ts +6 -3
- package/src/index.tsx +128 -127
- package/src/link.tsx +27 -155
- package/src/redirects.ts +1 -1
- package/src/route.ts +43 -316
- package/src/routeInfo.ts +7 -3
- package/src/router.ts +32 -52
- package/src/scroll-restoration.tsx +2 -3
- package/src/structuralSharing.ts +5 -7
- package/src/typePrimitives.ts +1 -1
- package/src/useLoaderData.tsx +2 -1
- package/src/useLoaderDeps.tsx +2 -1
- package/src/useMatch.tsx +2 -1
- package/src/useParams.tsx +2 -1
- package/src/useRouteContext.ts +2 -1
- package/src/useRouterState.tsx +1 -1
- package/src/useSearch.tsx +2 -1
- package/src/utils.ts +1 -389
- package/dist/cjs/defer.cjs +0 -25
- package/dist/cjs/defer.cjs.map +0 -1
- package/dist/cjs/defer.d.cts +0 -20
- package/dist/cjs/location.d.cts +0 -12
- package/dist/cjs/manifest.d.cts +0 -24
- package/dist/cjs/path.cjs +0 -289
- package/dist/cjs/path.cjs.map +0 -1
- package/dist/cjs/path.d.cts +0 -34
- package/dist/cjs/qss.cjs +0 -51
- package/dist/cjs/qss.cjs.map +0 -1
- package/dist/cjs/qss.d.cts +0 -27
- package/dist/cjs/root.cjs +0 -5
- package/dist/cjs/root.cjs.map +0 -1
- package/dist/cjs/root.d.cts +0 -2
- package/dist/cjs/searchMiddleware.cjs +0 -42
- package/dist/cjs/searchMiddleware.cjs.map +0 -1
- package/dist/cjs/searchMiddleware.d.cts +0 -5
- package/dist/cjs/searchParams.cjs +0 -61
- package/dist/cjs/searchParams.cjs.map +0 -1
- package/dist/cjs/searchParams.d.cts +0 -7
- package/dist/cjs/serializer.d.cts +0 -15
- package/dist/cjs/validators.d.cts +0 -51
- package/dist/esm/defer.d.ts +0 -20
- package/dist/esm/defer.js +0 -25
- package/dist/esm/defer.js.map +0 -1
- package/dist/esm/location.d.ts +0 -12
- package/dist/esm/manifest.d.ts +0 -24
- package/dist/esm/path.d.ts +0 -34
- package/dist/esm/path.js +0 -289
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/qss.d.ts +0 -27
- package/dist/esm/qss.js +0 -51
- package/dist/esm/qss.js.map +0 -1
- package/dist/esm/root.d.ts +0 -2
- package/dist/esm/root.js +0 -5
- package/dist/esm/root.js.map +0 -1
- package/dist/esm/searchMiddleware.d.ts +0 -5
- package/dist/esm/searchMiddleware.js +0 -42
- package/dist/esm/searchMiddleware.js.map +0 -1
- package/dist/esm/searchParams.d.ts +0 -7
- package/dist/esm/searchParams.js +0 -61
- package/dist/esm/searchParams.js.map +0 -1
- package/dist/esm/serializer.d.ts +0 -15
- package/dist/esm/validators.d.ts +0 -51
- package/src/defer.ts +0 -52
- package/src/location.ts +0 -13
- package/src/manifest.ts +0 -32
- package/src/path.ts +0 -427
- package/src/qss.ts +0 -91
- package/src/root.ts +0 -2
- package/src/searchMiddleware.ts +0 -54
- package/src/searchParams.ts +0 -77
- package/src/serializer.ts +0 -24
- package/src/validators.ts +0 -121
package/src/routeInfo.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { InferFileRouteTypes } from './fileRoute'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
AddTrailingSlash,
|
|
4
|
+
PartialMergeAll,
|
|
5
|
+
RemoveTrailingSlashes,
|
|
6
|
+
TrailingSlashOption,
|
|
7
|
+
} from '@tanstack/router-core'
|
|
3
8
|
import type { AnyRoute } from './route'
|
|
4
|
-
import type { AnyRouter
|
|
5
|
-
import type { PartialMergeAll } from './utils'
|
|
9
|
+
import type { AnyRouter } from './router'
|
|
6
10
|
|
|
7
11
|
export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
|
|
8
12
|
types: { children: infer TChildren }
|
package/src/router.ts
CHANGED
|
@@ -5,30 +5,28 @@ import {
|
|
|
5
5
|
} from '@tanstack/history'
|
|
6
6
|
import { Store, batch } from '@tanstack/react-store'
|
|
7
7
|
import invariant from 'tiny-invariant'
|
|
8
|
-
import { rootRouteId } from './root'
|
|
9
|
-
import { defaultParseSearch, defaultStringifySearch } from './searchParams'
|
|
10
8
|
import {
|
|
9
|
+
cleanPath,
|
|
11
10
|
createControlledPromise,
|
|
12
11
|
deepEqual,
|
|
12
|
+
defaultParseSearch,
|
|
13
|
+
defaultStringifySearch,
|
|
13
14
|
functionalUpdate,
|
|
14
|
-
last,
|
|
15
|
-
pick,
|
|
16
|
-
replaceEqualDeep,
|
|
17
|
-
} from './utils'
|
|
18
|
-
import {
|
|
19
|
-
cleanPath,
|
|
20
15
|
interpolatePath,
|
|
21
16
|
joinPaths,
|
|
17
|
+
last,
|
|
22
18
|
matchPathname,
|
|
23
19
|
parsePathname,
|
|
20
|
+
pick,
|
|
21
|
+
replaceEqualDeep,
|
|
24
22
|
resolvePath,
|
|
23
|
+
rootRouteId,
|
|
25
24
|
trimPath,
|
|
26
25
|
trimPathLeft,
|
|
27
26
|
trimPathRight,
|
|
28
|
-
} from '
|
|
27
|
+
} from '@tanstack/router-core'
|
|
29
28
|
import { isRedirect, isResolvedRedirect } from './redirects'
|
|
30
29
|
import { isNotFound } from './not-found'
|
|
31
|
-
import type { StartSerializer } from './serializer'
|
|
32
30
|
import type * as React from 'react'
|
|
33
31
|
import type {
|
|
34
32
|
HistoryLocation,
|
|
@@ -37,9 +35,27 @@ import type {
|
|
|
37
35
|
RouterHistory,
|
|
38
36
|
} from '@tanstack/history'
|
|
39
37
|
import type { NoInfer } from '@tanstack/react-store'
|
|
40
|
-
|
|
38
|
+
|
|
41
39
|
import type {
|
|
42
40
|
AnyContext,
|
|
41
|
+
AnySchema,
|
|
42
|
+
AnyValidator,
|
|
43
|
+
CommitLocationOptions,
|
|
44
|
+
ControlledPromise,
|
|
45
|
+
Manifest,
|
|
46
|
+
NonNullableUpdater,
|
|
47
|
+
ParsedLocation,
|
|
48
|
+
PickAsRequired,
|
|
49
|
+
ResolveRelativePath,
|
|
50
|
+
SearchMiddleware,
|
|
51
|
+
SearchParser,
|
|
52
|
+
SearchSerializer,
|
|
53
|
+
StartSerializer,
|
|
54
|
+
TrailingSlashOption,
|
|
55
|
+
Updater,
|
|
56
|
+
ViewTransitionOptions,
|
|
57
|
+
} from '@tanstack/router-core'
|
|
58
|
+
import type {
|
|
43
59
|
AnyRoute,
|
|
44
60
|
AnyRouteWithContext,
|
|
45
61
|
BeforeLoadContextOptions,
|
|
@@ -50,8 +66,8 @@ import type {
|
|
|
50
66
|
RouteComponent,
|
|
51
67
|
RouteContextOptions,
|
|
52
68
|
RouteMask,
|
|
53
|
-
SearchMiddleware,
|
|
54
69
|
} from './route'
|
|
70
|
+
|
|
55
71
|
import type {
|
|
56
72
|
FullSearchSchema,
|
|
57
73
|
RouteById,
|
|
@@ -59,29 +75,18 @@ import type {
|
|
|
59
75
|
RoutesById,
|
|
60
76
|
RoutesByPath,
|
|
61
77
|
} from './routeInfo'
|
|
62
|
-
import type {
|
|
63
|
-
ControlledPromise,
|
|
64
|
-
NonNullableUpdater,
|
|
65
|
-
PickAsRequired,
|
|
66
|
-
Updater,
|
|
67
|
-
} from './utils'
|
|
68
78
|
import type {
|
|
69
79
|
AnyRouteMatch,
|
|
70
80
|
MakeRouteMatch,
|
|
71
81
|
MakeRouteMatchUnion,
|
|
72
82
|
MatchRouteOptions,
|
|
73
83
|
} from './Matches'
|
|
74
|
-
|
|
75
|
-
import type {
|
|
76
|
-
|
|
77
|
-
BuildLocationFn,
|
|
78
|
-
CommitLocationOptions,
|
|
79
|
-
NavigateFn,
|
|
80
|
-
} from './RouterProvider'
|
|
84
|
+
|
|
85
|
+
import type { BuildLocationFn, NavigateFn } from './RouterProvider'
|
|
86
|
+
|
|
81
87
|
import type { AnyRedirect, ResolvedRedirect } from './redirects'
|
|
82
88
|
import type { NotFoundError } from './not-found'
|
|
83
|
-
import type { NavigateOptions,
|
|
84
|
-
import type { AnySchema, AnyValidator } from './validators'
|
|
89
|
+
import type { NavigateOptions, ToOptions } from './link'
|
|
85
90
|
|
|
86
91
|
declare global {
|
|
87
92
|
interface Window {
|
|
@@ -137,8 +142,6 @@ export type RouterContextOptions<TRouteTree extends AnyRoute> =
|
|
|
137
142
|
context: InferRouterContext<TRouteTree>
|
|
138
143
|
}
|
|
139
144
|
|
|
140
|
-
export type TrailingSlashOption = 'always' | 'never' | 'preserve'
|
|
141
|
-
|
|
142
145
|
export type InjectedHtmlEntry = Promise<string>
|
|
143
146
|
|
|
144
147
|
export interface RouterOptions<
|
|
@@ -498,10 +501,6 @@ export interface MatchedRoutesResult {
|
|
|
498
501
|
routeParams: Record<string, string>
|
|
499
502
|
}
|
|
500
503
|
|
|
501
|
-
export interface ViewTransitionOptions {
|
|
502
|
-
types: Array<string>
|
|
503
|
-
}
|
|
504
|
-
|
|
505
504
|
export type RouterConstructorOptions<
|
|
506
505
|
TRouteTree extends AnyRoute,
|
|
507
506
|
TTrailingSlashOption extends TrailingSlashOption,
|
|
@@ -3029,22 +3028,3 @@ export function getInitialRouterState(
|
|
|
3029
3028
|
statusCode: 200,
|
|
3030
3029
|
}
|
|
3031
3030
|
}
|
|
3032
|
-
|
|
3033
|
-
export function defaultSerializeError(err: unknown) {
|
|
3034
|
-
if (err instanceof Error) {
|
|
3035
|
-
const obj = {
|
|
3036
|
-
name: err.name,
|
|
3037
|
-
message: err.message,
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
|
-
if (process.env.NODE_ENV === 'development') {
|
|
3041
|
-
;(obj as any).stack = err.stack
|
|
3042
|
-
}
|
|
3043
|
-
|
|
3044
|
-
return obj
|
|
3045
|
-
}
|
|
3046
|
-
|
|
3047
|
-
return {
|
|
3048
|
-
data: err,
|
|
3049
|
-
}
|
|
3050
|
-
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
+
import { functionalUpdate } from '@tanstack/router-core'
|
|
2
3
|
import { useRouter } from './useRouter'
|
|
3
|
-
import {
|
|
4
|
-
import type { ParsedLocation } from './location'
|
|
5
|
-
import type { NonNullableUpdater } from './utils'
|
|
4
|
+
import type { NonNullableUpdater, ParsedLocation } from '@tanstack/router-core'
|
|
6
5
|
|
|
7
6
|
const useLayoutEffect =
|
|
8
7
|
typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
package/src/structuralSharing.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Constrain,
|
|
3
|
+
OptionalStructuralSharing,
|
|
4
|
+
ValidateJSON,
|
|
5
|
+
} from '@tanstack/router-core'
|
|
2
6
|
import type { AnyRouter } from './router'
|
|
3
7
|
|
|
4
8
|
export type DefaultStructuralSharingEnabled<TRouter extends AnyRouter> =
|
|
@@ -8,12 +12,6 @@ export type DefaultStructuralSharingEnabled<TRouter extends AnyRouter> =
|
|
|
8
12
|
false
|
|
9
13
|
: NonNullable<TRouter['options']['defaultStructuralSharing']>
|
|
10
14
|
|
|
11
|
-
export interface OptionalStructuralSharing<TStructuralSharing, TConstraint> {
|
|
12
|
-
readonly structuralSharing?:
|
|
13
|
-
| Constrain<TStructuralSharing, TConstraint>
|
|
14
|
-
| undefined
|
|
15
|
-
}
|
|
16
|
-
|
|
17
15
|
export interface RequiredStructuralSharing<TStructuralSharing, TConstraint> {
|
|
18
16
|
readonly structuralSharing: Constrain<TStructuralSharing, TConstraint>
|
|
19
17
|
}
|
package/src/typePrimitives.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { RouteIds } from './routeInfo'
|
|
|
10
10
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
11
11
|
import type { UseParamsOptions, UseParamsResult } from './useParams'
|
|
12
12
|
import type { UseSearchOptions, UseSearchResult } from './useSearch'
|
|
13
|
-
import type { Constrain, ConstrainLiteral } from '
|
|
13
|
+
import type { Constrain, ConstrainLiteral } from '@tanstack/router-core'
|
|
14
14
|
|
|
15
15
|
export type ValidateFromPath<
|
|
16
16
|
TFrom,
|
package/src/useLoaderData.tsx
CHANGED
|
@@ -5,7 +5,8 @@ import type {
|
|
|
5
5
|
} from './structuralSharing'
|
|
6
6
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
7
7
|
import type { AllLoaderData, RouteById } from './routeInfo'
|
|
8
|
-
import type {
|
|
8
|
+
import type { StrictOrFrom } from './utils'
|
|
9
|
+
import type { Expand } from '@tanstack/router-core'
|
|
9
10
|
|
|
10
11
|
export interface UseLoaderDataBaseOptions<
|
|
11
12
|
TRouter extends AnyRouter,
|
package/src/useLoaderDeps.tsx
CHANGED
|
@@ -5,7 +5,8 @@ import type {
|
|
|
5
5
|
} from './structuralSharing'
|
|
6
6
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
7
7
|
import type { RouteById } from './routeInfo'
|
|
8
|
-
import type {
|
|
8
|
+
import type { StrictOrFrom } from './utils'
|
|
9
|
+
import type { Expand } from '@tanstack/router-core'
|
|
9
10
|
|
|
10
11
|
export interface UseLoaderDepsBaseOptions<
|
|
11
12
|
TRouter extends AnyRouter,
|
package/src/useMatch.tsx
CHANGED
|
@@ -8,7 +8,8 @@ import type {
|
|
|
8
8
|
} from './structuralSharing'
|
|
9
9
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
10
10
|
import type { MakeRouteMatch, MakeRouteMatchUnion } from './Matches'
|
|
11
|
-
import type { StrictOrFrom
|
|
11
|
+
import type { StrictOrFrom } from './utils'
|
|
12
|
+
import type { ThrowOrOptional } from '@tanstack/router-core'
|
|
12
13
|
|
|
13
14
|
export interface UseMatchBaseOptions<
|
|
14
15
|
TRouter extends AnyRouter,
|
package/src/useParams.tsx
CHANGED
|
@@ -5,7 +5,8 @@ import type {
|
|
|
5
5
|
} from './structuralSharing'
|
|
6
6
|
import type { AllParams, RouteById } from './routeInfo'
|
|
7
7
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
8
|
-
import type {
|
|
8
|
+
import type { StrictOrFrom } from './utils'
|
|
9
|
+
import type { Expand } from '@tanstack/router-core'
|
|
9
10
|
|
|
10
11
|
export interface UseParamsBaseOptions<
|
|
11
12
|
TRouter extends AnyRouter,
|
package/src/useRouteContext.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useMatch } from './useMatch'
|
|
2
2
|
import type { AllContext, RouteById } from './routeInfo'
|
|
3
3
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
4
|
-
import type {
|
|
4
|
+
import type { StrictOrFrom } from './utils'
|
|
5
|
+
import type { Expand } from '@tanstack/router-core'
|
|
5
6
|
|
|
6
7
|
export interface UseRouteContextBaseOptions<
|
|
7
8
|
TRouter extends AnyRouter,
|
package/src/useRouterState.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useStore } from '@tanstack/react-store'
|
|
2
2
|
import { useRef } from 'react'
|
|
3
|
+
import { replaceEqualDeep } from '@tanstack/router-core'
|
|
3
4
|
import { useRouter } from './useRouter'
|
|
4
|
-
import { replaceEqualDeep } from './utils'
|
|
5
5
|
import type {
|
|
6
6
|
StructuralSharingOption,
|
|
7
7
|
ValidateSelected,
|
package/src/useSearch.tsx
CHANGED
|
@@ -5,7 +5,8 @@ import type {
|
|
|
5
5
|
} from './structuralSharing'
|
|
6
6
|
import type { FullSearchSchema, RouteById } from './routeInfo'
|
|
7
7
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
8
|
-
import type {
|
|
8
|
+
import type { StrictOrFrom } from './utils'
|
|
9
|
+
import type { Expand } from '@tanstack/router-core'
|
|
9
10
|
|
|
10
11
|
export interface UseSearchBaseOptions<
|
|
11
12
|
TRouter extends AnyRouter,
|
package/src/utils.ts
CHANGED
|
@@ -1,311 +1,7 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import type { RouteIds } from './routeInfo'
|
|
3
3
|
import type { AnyRouter } from './router'
|
|
4
|
-
|
|
5
|
-
export type NoInfer<T> = [T][T extends any ? 0 : never]
|
|
6
|
-
export type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue
|
|
7
|
-
? TYesResult
|
|
8
|
-
: TNoResult
|
|
9
|
-
|
|
10
|
-
export type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<
|
|
11
|
-
TValue,
|
|
12
|
-
TKey
|
|
13
|
-
> &
|
|
14
|
-
Required<Pick<TValue, TKey>>
|
|
15
|
-
|
|
16
|
-
export type PickRequired<T> = {
|
|
17
|
-
[K in keyof T as undefined extends T[K] ? never : K]: T[K]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type PickOptional<T> = {
|
|
21
|
-
[K in keyof T as undefined extends T[K] ? K : never]: T[K]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// from https://stackoverflow.com/a/76458160
|
|
25
|
-
export type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never
|
|
26
|
-
|
|
27
|
-
// export type Expand<T> = T
|
|
28
|
-
export type Expand<T> = T extends object
|
|
29
|
-
? T extends infer O
|
|
30
|
-
? O extends Function
|
|
31
|
-
? O
|
|
32
|
-
: { [K in keyof O]: O[K] }
|
|
33
|
-
: never
|
|
34
|
-
: T
|
|
35
|
-
|
|
36
|
-
export type DeepPartial<T> = T extends object
|
|
37
|
-
? {
|
|
38
|
-
[P in keyof T]?: DeepPartial<T[P]>
|
|
39
|
-
}
|
|
40
|
-
: T
|
|
41
|
-
|
|
42
|
-
export type MakeDifferenceOptional<TLeft, TRight> = Omit<
|
|
43
|
-
TRight,
|
|
44
|
-
keyof TLeft
|
|
45
|
-
> & {
|
|
46
|
-
[K in keyof TLeft & keyof TRight]?: TRight[K]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// from https://stackoverflow.com/a/53955431
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
51
|
-
export type IsUnion<T, U extends T = T> = (
|
|
52
|
-
T extends any ? (U extends T ? false : true) : never
|
|
53
|
-
) extends false
|
|
54
|
-
? false
|
|
55
|
-
: true
|
|
56
|
-
|
|
57
|
-
export type Assign<TLeft, TRight> = TLeft extends any
|
|
58
|
-
? TRight extends any
|
|
59
|
-
? keyof TLeft extends never
|
|
60
|
-
? TRight
|
|
61
|
-
: keyof TRight extends never
|
|
62
|
-
? TLeft
|
|
63
|
-
: keyof TLeft & keyof TRight extends never
|
|
64
|
-
? TLeft & TRight
|
|
65
|
-
: Omit<TLeft, keyof TRight> & TRight
|
|
66
|
-
: never
|
|
67
|
-
: never
|
|
68
|
-
|
|
69
|
-
export type Timeout = ReturnType<typeof setTimeout>
|
|
70
|
-
|
|
71
|
-
export type Updater<TPrevious, TResult = TPrevious> =
|
|
72
|
-
| TResult
|
|
73
|
-
| ((prev?: TPrevious) => TResult)
|
|
74
|
-
|
|
75
|
-
export type NonNullableUpdater<TPrevious, TResult = TPrevious> =
|
|
76
|
-
| TResult
|
|
77
|
-
| ((prev: TPrevious) => TResult)
|
|
78
|
-
|
|
79
|
-
export type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive
|
|
80
|
-
? never
|
|
81
|
-
: TUnion
|
|
82
|
-
|
|
83
|
-
export type PartialMergeAllObject<TUnion> =
|
|
84
|
-
ExtractObjects<TUnion> extends infer TObj
|
|
85
|
-
? {
|
|
86
|
-
[TKey in TObj extends any ? keyof TObj : never]?: TObj extends any
|
|
87
|
-
? TKey extends keyof TObj
|
|
88
|
-
? TObj[TKey]
|
|
89
|
-
: never
|
|
90
|
-
: never
|
|
91
|
-
}
|
|
92
|
-
: never
|
|
93
|
-
|
|
94
|
-
export type MergeAllPrimitive =
|
|
95
|
-
| ReadonlyArray<any>
|
|
96
|
-
| number
|
|
97
|
-
| string
|
|
98
|
-
| bigint
|
|
99
|
-
| boolean
|
|
100
|
-
| symbol
|
|
101
|
-
| undefined
|
|
102
|
-
| null
|
|
103
|
-
|
|
104
|
-
export type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive
|
|
105
|
-
? TUnion
|
|
106
|
-
: TUnion extends object
|
|
107
|
-
? never
|
|
108
|
-
: TUnion
|
|
109
|
-
|
|
110
|
-
export type PartialMergeAll<TUnion> =
|
|
111
|
-
| ExtractPrimitives<TUnion>
|
|
112
|
-
| PartialMergeAllObject<TUnion>
|
|
113
|
-
|
|
114
|
-
export type Constrain<T, TConstraint, TDefault = TConstraint> =
|
|
115
|
-
| (T extends TConstraint ? T : never)
|
|
116
|
-
| TDefault
|
|
117
|
-
|
|
118
|
-
export type ConstrainLiteral<T, TConstraint, TDefault = TConstraint> =
|
|
119
|
-
| (T & TConstraint)
|
|
120
|
-
| TDefault
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* To be added to router types
|
|
124
|
-
*/
|
|
125
|
-
export type UnionToIntersection<T> = (
|
|
126
|
-
T extends any ? (arg: T) => any : never
|
|
127
|
-
) extends (arg: infer T) => any
|
|
128
|
-
? T
|
|
129
|
-
: never
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Merges everything in a union into one object.
|
|
133
|
-
* This mapped type is homomorphic which means it preserves stuff! :)
|
|
134
|
-
*/
|
|
135
|
-
export type MergeAllObjects<
|
|
136
|
-
TUnion,
|
|
137
|
-
TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,
|
|
138
|
-
> = [keyof TIntersected] extends [never]
|
|
139
|
-
? never
|
|
140
|
-
: {
|
|
141
|
-
[TKey in keyof TIntersected]: TUnion extends any
|
|
142
|
-
? TUnion[TKey & keyof TUnion]
|
|
143
|
-
: never
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export type MergeAll<TUnion> =
|
|
147
|
-
| MergeAllObjects<TUnion>
|
|
148
|
-
| ExtractPrimitives<TUnion>
|
|
149
|
-
|
|
150
|
-
export type ValidateJSON<T> = ((...args: Array<any>) => any) extends T
|
|
151
|
-
? unknown extends T
|
|
152
|
-
? never
|
|
153
|
-
: 'Function is not serializable'
|
|
154
|
-
: { [K in keyof T]: ValidateJSON<T[K]> }
|
|
155
|
-
|
|
156
|
-
export function last<T>(arr: Array<T>) {
|
|
157
|
-
return arr[arr.length - 1]
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function isFunction(d: any): d is Function {
|
|
161
|
-
return typeof d === 'function'
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function functionalUpdate<TPrevious, TResult = TPrevious>(
|
|
165
|
-
updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>,
|
|
166
|
-
previous: TPrevious,
|
|
167
|
-
): TResult {
|
|
168
|
-
if (isFunction(updater)) {
|
|
169
|
-
return updater(previous)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return updater
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function pick<TValue, TKey extends keyof TValue>(
|
|
176
|
-
parent: TValue,
|
|
177
|
-
keys: Array<TKey>,
|
|
178
|
-
): Pick<TValue, TKey> {
|
|
179
|
-
return keys.reduce((obj: any, key: TKey) => {
|
|
180
|
-
obj[key] = parent[key]
|
|
181
|
-
return obj
|
|
182
|
-
}, {} as any)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* This function returns `prev` if `_next` is deeply equal.
|
|
187
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
188
|
-
* This can be used for structural sharing between immutable JSON values for example.
|
|
189
|
-
* Do not use this with signals
|
|
190
|
-
*/
|
|
191
|
-
export function replaceEqualDeep<T>(prev: any, _next: T): T {
|
|
192
|
-
if (prev === _next) {
|
|
193
|
-
return prev
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const next = _next as any
|
|
197
|
-
|
|
198
|
-
const array = isPlainArray(prev) && isPlainArray(next)
|
|
199
|
-
|
|
200
|
-
if (array || (isPlainObject(prev) && isPlainObject(next))) {
|
|
201
|
-
const prevItems = array ? prev : Object.keys(prev)
|
|
202
|
-
const prevSize = prevItems.length
|
|
203
|
-
const nextItems = array ? next : Object.keys(next)
|
|
204
|
-
const nextSize = nextItems.length
|
|
205
|
-
const copy: any = array ? [] : {}
|
|
206
|
-
|
|
207
|
-
let equalItems = 0
|
|
208
|
-
|
|
209
|
-
for (let i = 0; i < nextSize; i++) {
|
|
210
|
-
const key = array ? i : (nextItems[i] as any)
|
|
211
|
-
if (
|
|
212
|
-
((!array && prevItems.includes(key)) || array) &&
|
|
213
|
-
prev[key] === undefined &&
|
|
214
|
-
next[key] === undefined
|
|
215
|
-
) {
|
|
216
|
-
copy[key] = undefined
|
|
217
|
-
equalItems++
|
|
218
|
-
} else {
|
|
219
|
-
copy[key] = replaceEqualDeep(prev[key], next[key])
|
|
220
|
-
if (copy[key] === prev[key] && prev[key] !== undefined) {
|
|
221
|
-
equalItems++
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return prevSize === nextSize && equalItems === prevSize ? prev : copy
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return next
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
233
|
-
export function isPlainObject(o: any) {
|
|
234
|
-
if (!hasObjectPrototype(o)) {
|
|
235
|
-
return false
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// If has modified constructor
|
|
239
|
-
const ctor = o.constructor
|
|
240
|
-
if (typeof ctor === 'undefined') {
|
|
241
|
-
return true
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// If has modified prototype
|
|
245
|
-
const prot = ctor.prototype
|
|
246
|
-
if (!hasObjectPrototype(prot)) {
|
|
247
|
-
return false
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// If constructor does not have an Object-specific method
|
|
251
|
-
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
252
|
-
return false
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Most likely a plain Object
|
|
256
|
-
return true
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function hasObjectPrototype(o: any) {
|
|
260
|
-
return Object.prototype.toString.call(o) === '[object Object]'
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function isPlainArray(value: unknown): value is Array<unknown> {
|
|
264
|
-
return Array.isArray(value) && value.length === Object.keys(value).length
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function getObjectKeys(obj: any, ignoreUndefined: boolean) {
|
|
268
|
-
let keys = Object.keys(obj)
|
|
269
|
-
if (ignoreUndefined) {
|
|
270
|
-
keys = keys.filter((key) => obj[key] !== undefined)
|
|
271
|
-
}
|
|
272
|
-
return keys
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function deepEqual(
|
|
276
|
-
a: any,
|
|
277
|
-
b: any,
|
|
278
|
-
opts?: { partial?: boolean; ignoreUndefined?: boolean },
|
|
279
|
-
): boolean {
|
|
280
|
-
if (a === b) {
|
|
281
|
-
return true
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (typeof a !== typeof b) {
|
|
285
|
-
return false
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (isPlainObject(a) && isPlainObject(b)) {
|
|
289
|
-
const ignoreUndefined = opts?.ignoreUndefined ?? true
|
|
290
|
-
const aKeys = getObjectKeys(a, ignoreUndefined)
|
|
291
|
-
const bKeys = getObjectKeys(b, ignoreUndefined)
|
|
292
|
-
|
|
293
|
-
if (!opts?.partial && aKeys.length !== bKeys.length) {
|
|
294
|
-
return false
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return bKeys.every((key) => deepEqual(a[key], b[key], opts))
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
301
|
-
if (a.length !== b.length) {
|
|
302
|
-
return false
|
|
303
|
-
}
|
|
304
|
-
return !a.some((item, index) => !deepEqual(item, b[index], opts))
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return false
|
|
308
|
-
}
|
|
4
|
+
import type { ConstrainLiteral } from '@tanstack/router-core'
|
|
309
5
|
|
|
310
6
|
export function useStableCallback<T extends (...args: Array<any>) => any>(
|
|
311
7
|
fn: T,
|
|
@@ -317,42 +13,6 @@ export function useStableCallback<T extends (...args: Array<any>) => any>(
|
|
|
317
13
|
return ref.current as T
|
|
318
14
|
}
|
|
319
15
|
|
|
320
|
-
export function shallow<T>(objA: T, objB: T) {
|
|
321
|
-
if (Object.is(objA, objB)) {
|
|
322
|
-
return true
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (
|
|
326
|
-
typeof objA !== 'object' ||
|
|
327
|
-
objA === null ||
|
|
328
|
-
typeof objB !== 'object' ||
|
|
329
|
-
objB === null
|
|
330
|
-
) {
|
|
331
|
-
return false
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const keysA = Object.keys(objA)
|
|
335
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
336
|
-
return false
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
for (const item of keysA) {
|
|
340
|
-
if (
|
|
341
|
-
!Object.prototype.hasOwnProperty.call(objB, item) ||
|
|
342
|
-
!Object.is(objA[item as keyof T], objB[item as keyof T])
|
|
343
|
-
) {
|
|
344
|
-
return false
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return true
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export type StringLiteral<T> = T extends string
|
|
351
|
-
? string extends T
|
|
352
|
-
? string
|
|
353
|
-
: T
|
|
354
|
-
: never
|
|
355
|
-
|
|
356
16
|
export type StrictOrFrom<
|
|
357
17
|
TRouter extends AnyRouter,
|
|
358
18
|
TFrom,
|
|
@@ -367,57 +27,9 @@ export type StrictOrFrom<
|
|
|
367
27
|
strict?: TStrict
|
|
368
28
|
}
|
|
369
29
|
|
|
370
|
-
export type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true
|
|
371
|
-
? T
|
|
372
|
-
: T | undefined
|
|
373
|
-
|
|
374
30
|
export const useLayoutEffect =
|
|
375
31
|
typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
|
376
32
|
|
|
377
|
-
/**
|
|
378
|
-
*
|
|
379
|
-
* @deprecated use `jsesc` instead
|
|
380
|
-
*/
|
|
381
|
-
export function escapeJSON(jsonString: string) {
|
|
382
|
-
return jsonString
|
|
383
|
-
.replace(/\\/g, '\\\\') // Escape backslashes
|
|
384
|
-
.replace(/'/g, "\\'") // Escape single quotes
|
|
385
|
-
.replace(/"/g, '\\"') // Escape double quotes
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
export type ControlledPromise<T> = Promise<T> & {
|
|
389
|
-
resolve: (value: T) => void
|
|
390
|
-
reject: (value: any) => void
|
|
391
|
-
status: 'pending' | 'resolved' | 'rejected'
|
|
392
|
-
value?: T
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
export function createControlledPromise<T>(onResolve?: (value: T) => void) {
|
|
396
|
-
let resolveLoadPromise!: (value: T) => void
|
|
397
|
-
let rejectLoadPromise!: (value: any) => void
|
|
398
|
-
|
|
399
|
-
const controlledPromise = new Promise<T>((resolve, reject) => {
|
|
400
|
-
resolveLoadPromise = resolve
|
|
401
|
-
rejectLoadPromise = reject
|
|
402
|
-
}) as ControlledPromise<T>
|
|
403
|
-
|
|
404
|
-
controlledPromise.status = 'pending'
|
|
405
|
-
|
|
406
|
-
controlledPromise.resolve = (value: T) => {
|
|
407
|
-
controlledPromise.status = 'resolved'
|
|
408
|
-
controlledPromise.value = value
|
|
409
|
-
resolveLoadPromise(value)
|
|
410
|
-
onResolve?.(value)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
controlledPromise.reject = (e) => {
|
|
414
|
-
controlledPromise.status = 'rejected'
|
|
415
|
-
rejectLoadPromise(e)
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return controlledPromise
|
|
419
|
-
}
|
|
420
|
-
|
|
421
33
|
/**
|
|
422
34
|
* Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3
|
|
423
35
|
*/
|