@tanstack/react-router 1.97.20 → 1.97.23

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.
Files changed (182) hide show
  1. package/dist/cjs/Match.cjs +4 -5
  2. package/dist/cjs/Match.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +0 -10
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/Matches.d.cts +3 -30
  6. package/dist/cjs/RouterProvider.cjs.map +1 -1
  7. package/dist/cjs/RouterProvider.d.cts +2 -2
  8. package/dist/cjs/Transitioner.cjs +2 -2
  9. package/dist/cjs/Transitioner.cjs.map +1 -1
  10. package/dist/cjs/awaited.cjs +6 -6
  11. package/dist/cjs/awaited.cjs.map +1 -1
  12. package/dist/cjs/awaited.d.cts +1 -1
  13. package/dist/cjs/fileRoute.cjs.map +1 -1
  14. package/dist/cjs/fileRoute.d.cts +2 -3
  15. package/dist/cjs/index.cjs +136 -42
  16. package/dist/cjs/index.cjs.map +1 -1
  17. package/dist/cjs/index.d.cts +12 -26
  18. package/dist/cjs/link.cjs +8 -9
  19. package/dist/cjs/link.cjs.map +1 -1
  20. package/dist/cjs/link.d.cts +2 -49
  21. package/dist/cjs/redirects.cjs.map +1 -1
  22. package/dist/cjs/redirects.d.cts +1 -1
  23. package/dist/cjs/route.cjs +14 -15
  24. package/dist/cjs/route.cjs.map +1 -1
  25. package/dist/cjs/route.d.cts +2 -149
  26. package/dist/cjs/routeInfo.d.cts +2 -3
  27. package/dist/cjs/router.cjs +52 -71
  28. package/dist/cjs/router.cjs.map +1 -1
  29. package/dist/cjs/router.d.cts +4 -19
  30. package/dist/cjs/routerContext.d.cts +1 -1
  31. package/dist/cjs/scroll-restoration.cjs +2 -2
  32. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  33. package/dist/cjs/scroll-restoration.d.cts +1 -1
  34. package/dist/cjs/structuralSharing.d.cts +1 -4
  35. package/dist/cjs/typePrimitives.d.cts +1 -1
  36. package/dist/cjs/useLoaderData.cjs.map +1 -1
  37. package/dist/cjs/useLoaderData.d.cts +2 -1
  38. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  39. package/dist/cjs/useLoaderDeps.d.cts +2 -1
  40. package/dist/cjs/useMatch.cjs.map +1 -1
  41. package/dist/cjs/useMatch.d.cts +2 -1
  42. package/dist/cjs/useParams.cjs.map +1 -1
  43. package/dist/cjs/useParams.d.cts +2 -1
  44. package/dist/cjs/useRouteContext.cjs.map +1 -1
  45. package/dist/cjs/useRouteContext.d.cts +2 -1
  46. package/dist/cjs/useRouterState.cjs +2 -2
  47. package/dist/cjs/useRouterState.cjs.map +1 -1
  48. package/dist/cjs/useSearch.cjs.map +1 -1
  49. package/dist/cjs/useSearch.d.cts +2 -1
  50. package/dist/cjs/utils.cjs +0 -152
  51. package/dist/cjs/utils.cjs.map +1 -1
  52. package/dist/cjs/utils.d.cts +1 -81
  53. package/dist/esm/Match.js +1 -2
  54. package/dist/esm/Match.js.map +1 -1
  55. package/dist/esm/Matches.d.ts +3 -30
  56. package/dist/esm/Matches.js +0 -10
  57. package/dist/esm/Matches.js.map +1 -1
  58. package/dist/esm/RouterProvider.d.ts +2 -2
  59. package/dist/esm/RouterProvider.js.map +1 -1
  60. package/dist/esm/Transitioner.js +1 -1
  61. package/dist/esm/Transitioner.js.map +1 -1
  62. package/dist/esm/awaited.d.ts +1 -1
  63. package/dist/esm/awaited.js +1 -1
  64. package/dist/esm/awaited.js.map +1 -1
  65. package/dist/esm/fileRoute.d.ts +2 -3
  66. package/dist/esm/fileRoute.js.map +1 -1
  67. package/dist/esm/index.d.ts +12 -26
  68. package/dist/esm/index.js +5 -10
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/link.d.ts +2 -49
  71. package/dist/esm/link.js +2 -3
  72. package/dist/esm/link.js.map +1 -1
  73. package/dist/esm/redirects.d.ts +1 -1
  74. package/dist/esm/redirects.js.map +1 -1
  75. package/dist/esm/route.d.ts +2 -149
  76. package/dist/esm/route.js +1 -2
  77. package/dist/esm/route.js.map +1 -1
  78. package/dist/esm/routeInfo.d.ts +2 -3
  79. package/dist/esm/router.d.ts +4 -19
  80. package/dist/esm/router.js +2 -21
  81. package/dist/esm/router.js.map +1 -1
  82. package/dist/esm/routerContext.d.ts +1 -1
  83. package/dist/esm/scroll-restoration.d.ts +1 -1
  84. package/dist/esm/scroll-restoration.js +1 -1
  85. package/dist/esm/scroll-restoration.js.map +1 -1
  86. package/dist/esm/structuralSharing.d.ts +1 -4
  87. package/dist/esm/typePrimitives.d.ts +1 -1
  88. package/dist/esm/useLoaderData.d.ts +2 -1
  89. package/dist/esm/useLoaderData.js.map +1 -1
  90. package/dist/esm/useLoaderDeps.d.ts +2 -1
  91. package/dist/esm/useLoaderDeps.js.map +1 -1
  92. package/dist/esm/useMatch.d.ts +2 -1
  93. package/dist/esm/useMatch.js.map +1 -1
  94. package/dist/esm/useParams.d.ts +2 -1
  95. package/dist/esm/useParams.js.map +1 -1
  96. package/dist/esm/useRouteContext.d.ts +2 -1
  97. package/dist/esm/useRouteContext.js.map +1 -1
  98. package/dist/esm/useRouterState.js +1 -1
  99. package/dist/esm/useRouterState.js.map +1 -1
  100. package/dist/esm/useSearch.d.ts +2 -1
  101. package/dist/esm/useSearch.js.map +1 -1
  102. package/dist/esm/utils.d.ts +1 -81
  103. package/dist/esm/utils.js +0 -152
  104. package/dist/esm/utils.js.map +1 -1
  105. package/package.json +3 -2
  106. package/src/Match.tsx +5 -2
  107. package/src/Matches.tsx +8 -101
  108. package/src/RouterProvider.tsx +4 -2
  109. package/src/Transitioner.tsx +1 -1
  110. package/src/awaited.tsx +2 -2
  111. package/src/fileRoute.ts +6 -3
  112. package/src/index.tsx +128 -128
  113. package/src/link.tsx +27 -155
  114. package/src/redirects.ts +1 -1
  115. package/src/route.ts +41 -315
  116. package/src/routeInfo.ts +7 -3
  117. package/src/router.ts +33 -53
  118. package/src/scroll-restoration.tsx +2 -3
  119. package/src/structuralSharing.ts +5 -7
  120. package/src/typePrimitives.ts +1 -1
  121. package/src/useLoaderData.tsx +2 -1
  122. package/src/useLoaderDeps.tsx +2 -1
  123. package/src/useMatch.tsx +2 -1
  124. package/src/useParams.tsx +2 -1
  125. package/src/useRouteContext.ts +2 -1
  126. package/src/useRouterState.tsx +1 -1
  127. package/src/useSearch.tsx +2 -1
  128. package/src/utils.ts +1 -405
  129. package/dist/cjs/defer.cjs +0 -25
  130. package/dist/cjs/defer.cjs.map +0 -1
  131. package/dist/cjs/defer.d.cts +0 -20
  132. package/dist/cjs/location.d.cts +0 -12
  133. package/dist/cjs/manifest.d.cts +0 -24
  134. package/dist/cjs/path.cjs +0 -289
  135. package/dist/cjs/path.cjs.map +0 -1
  136. package/dist/cjs/path.d.cts +0 -34
  137. package/dist/cjs/qss.cjs +0 -51
  138. package/dist/cjs/qss.cjs.map +0 -1
  139. package/dist/cjs/qss.d.cts +0 -27
  140. package/dist/cjs/root.cjs +0 -5
  141. package/dist/cjs/root.cjs.map +0 -1
  142. package/dist/cjs/root.d.cts +0 -2
  143. package/dist/cjs/searchMiddleware.cjs +0 -42
  144. package/dist/cjs/searchMiddleware.cjs.map +0 -1
  145. package/dist/cjs/searchMiddleware.d.cts +0 -5
  146. package/dist/cjs/searchParams.cjs +0 -61
  147. package/dist/cjs/searchParams.cjs.map +0 -1
  148. package/dist/cjs/searchParams.d.cts +0 -7
  149. package/dist/cjs/serializer.d.cts +0 -15
  150. package/dist/cjs/validators.d.cts +0 -51
  151. package/dist/esm/defer.d.ts +0 -20
  152. package/dist/esm/defer.js +0 -25
  153. package/dist/esm/defer.js.map +0 -1
  154. package/dist/esm/location.d.ts +0 -12
  155. package/dist/esm/manifest.d.ts +0 -24
  156. package/dist/esm/path.d.ts +0 -34
  157. package/dist/esm/path.js +0 -289
  158. package/dist/esm/path.js.map +0 -1
  159. package/dist/esm/qss.d.ts +0 -27
  160. package/dist/esm/qss.js +0 -51
  161. package/dist/esm/qss.js.map +0 -1
  162. package/dist/esm/root.d.ts +0 -2
  163. package/dist/esm/root.js +0 -5
  164. package/dist/esm/root.js.map +0 -1
  165. package/dist/esm/searchMiddleware.d.ts +0 -5
  166. package/dist/esm/searchMiddleware.js +0 -42
  167. package/dist/esm/searchMiddleware.js.map +0 -1
  168. package/dist/esm/searchParams.d.ts +0 -7
  169. package/dist/esm/searchParams.js +0 -61
  170. package/dist/esm/searchParams.js.map +0 -1
  171. package/dist/esm/serializer.d.ts +0 -15
  172. package/dist/esm/validators.d.ts +0 -51
  173. package/src/defer.ts +0 -52
  174. package/src/location.ts +0 -13
  175. package/src/manifest.ts +0 -32
  176. package/src/path.ts +0 -427
  177. package/src/qss.ts +0 -91
  178. package/src/root.ts +0 -2
  179. package/src/searchMiddleware.ts +0 -54
  180. package/src/searchParams.ts +0 -77
  181. package/src/serializer.ts +0 -24
  182. package/src/validators.ts +0 -121
package/src/qss.ts DELETED
@@ -1,91 +0,0 @@
1
- /**
2
- * Program uses a modified version of the `qss` package:
3
- * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
4
- * https://github.com/lukeed/qss/blob/master/license.md
5
- */
6
-
7
- /**
8
- * Encodes an object into a query string.
9
- * @param obj - The object to encode into a query string.
10
- * @param [pfx] - An optional prefix to add before the query string.
11
- * @returns The encoded query string.
12
- * @example
13
- * ```
14
- * // Example input: encode({ token: 'foo', key: 'value' })
15
- * // Expected output: "token=foo&key=value"
16
- * ```
17
- */
18
- export function encode(obj: any, pfx?: string) {
19
- let k,
20
- i,
21
- tmp,
22
- str = ''
23
-
24
- for (k in obj) {
25
- if ((tmp = obj[k]) !== void 0) {
26
- if (Array.isArray(tmp)) {
27
- for (i = 0; i < tmp.length; i++) {
28
- str && (str += '&')
29
- str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])
30
- }
31
- } else {
32
- str && (str += '&')
33
- str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)
34
- }
35
- }
36
- }
37
-
38
- return (pfx || '') + str
39
- }
40
-
41
- /**
42
- * Converts a string value to its appropriate type (string, number, boolean).
43
- * @param mix - The string value to convert.
44
- * @returns The converted value.
45
- * @example
46
- * // Example input: toValue("123")
47
- * // Expected output: 123
48
- */
49
- function toValue(mix: any) {
50
- if (!mix) return ''
51
- const str = decodeURIComponent(mix)
52
- if (str === 'false') return false
53
- if (str === 'true') return true
54
- return +str * 0 === 0 && +str + '' === str ? +str : str
55
- }
56
-
57
- /**
58
- * Decodes a query string into an object.
59
- * @param str - The query string to decode.
60
- * @param [pfx] - An optional prefix to filter out from the query string.
61
- * @returns The decoded key-value pairs in an object format.
62
- * @example
63
- * // Example input: decode("token=foo&key=value")
64
- * // Expected output: { "token": "foo", "key": "value" }
65
- */
66
- export function decode(str: any, pfx?: string) {
67
- let tmp, k
68
- const out: any = {},
69
- arr = (pfx ? str.substr(pfx.length) : str).split('&')
70
-
71
- while ((tmp = arr.shift())) {
72
- const equalIndex = tmp.indexOf('=')
73
- if (equalIndex !== -1) {
74
- k = tmp.slice(0, equalIndex)
75
- k = decodeURIComponent(k)
76
- const value = tmp.slice(equalIndex + 1)
77
- if (out[k] !== void 0) {
78
- // @ts-expect-error
79
- out[k] = [].concat(out[k], toValue(value))
80
- } else {
81
- out[k] = toValue(value)
82
- }
83
- } else {
84
- k = tmp
85
- k = decodeURIComponent(k)
86
- out[k] = ''
87
- }
88
- }
89
-
90
- return out
91
- }
package/src/root.ts DELETED
@@ -1,2 +0,0 @@
1
- export const rootRouteId = '__root__'
2
- export type RootRouteId = typeof rootRouteId
@@ -1,54 +0,0 @@
1
- import { deepEqual } from './utils'
2
- import type { NoInfer, PickOptional } from './utils'
3
- import type { SearchMiddleware } from './route'
4
- import type { IsRequiredParams } from './link'
5
-
6
- export function retainSearchParams<TSearchSchema extends object>(
7
- keys: Array<keyof TSearchSchema> | true,
8
- ): SearchMiddleware<TSearchSchema> {
9
- return ({ search, next }) => {
10
- const result = next(search)
11
- if (keys === true) {
12
- return { ...search, ...result }
13
- }
14
- // add missing keys from search to result
15
- keys.forEach((key) => {
16
- if (!(key in result)) {
17
- result[key] = search[key]
18
- }
19
- })
20
- return result
21
- }
22
- }
23
-
24
- export function stripSearchParams<
25
- TSearchSchema,
26
- TOptionalProps = PickOptional<NoInfer<TSearchSchema>>,
27
- const TValues =
28
- | Partial<NoInfer<TOptionalProps>>
29
- | Array<keyof TOptionalProps>,
30
- const TInput = IsRequiredParams<TSearchSchema> extends never
31
- ? TValues | true
32
- : TValues,
33
- >(input: NoInfer<TInput>): SearchMiddleware<TSearchSchema> {
34
- return ({ search, next }) => {
35
- if (input === true) {
36
- return {}
37
- }
38
- const result = next(search) as Record<string, unknown>
39
- if (Array.isArray(input)) {
40
- input.forEach((key) => {
41
- delete result[key]
42
- })
43
- } else {
44
- Object.entries(input as Record<string, unknown>).forEach(
45
- ([key, value]) => {
46
- if (deepEqual(result[key], value)) {
47
- delete result[key]
48
- }
49
- },
50
- )
51
- }
52
- return result as any
53
- }
54
- }
@@ -1,77 +0,0 @@
1
- import { decode, encode } from './qss'
2
- import type { AnySchema } from './validators'
3
-
4
- export const defaultParseSearch = parseSearchWith(JSON.parse)
5
- export const defaultStringifySearch = stringifySearchWith(
6
- JSON.stringify,
7
- JSON.parse,
8
- )
9
-
10
- export function parseSearchWith(parser: (str: string) => any) {
11
- return (searchStr: string): AnySchema => {
12
- if (searchStr.substring(0, 1) === '?') {
13
- searchStr = searchStr.substring(1)
14
- }
15
-
16
- const query: Record<string, unknown> = decode(searchStr)
17
-
18
- // Try to parse any query params that might be json
19
- for (const key in query) {
20
- const value = query[key]
21
- if (typeof value === 'string') {
22
- try {
23
- query[key] = parser(value)
24
- } catch (err) {
25
- //
26
- }
27
- }
28
- }
29
-
30
- return query
31
- }
32
- }
33
-
34
- export function stringifySearchWith(
35
- stringify: (search: any) => string,
36
- parser?: (str: string) => any,
37
- ) {
38
- function stringifyValue(val: any) {
39
- if (typeof val === 'object' && val !== null) {
40
- try {
41
- return stringify(val)
42
- } catch (err) {
43
- // silent
44
- }
45
- } else if (typeof val === 'string' && typeof parser === 'function') {
46
- try {
47
- // Check if it's a valid parseable string.
48
- // If it is, then stringify it again.
49
- parser(val)
50
- return stringify(val)
51
- } catch (err) {
52
- // silent
53
- }
54
- }
55
- return val
56
- }
57
-
58
- return (search: Record<string, any>) => {
59
- search = { ...search }
60
-
61
- Object.keys(search).forEach((key) => {
62
- const val = search[key]
63
- if (typeof val === 'undefined' || val === undefined) {
64
- delete search[key]
65
- } else {
66
- search[key] = stringifyValue(val)
67
- }
68
- })
69
-
70
- const searchStr = encode(search as Record<string, string>).toString()
71
-
72
- return searchStr ? `?${searchStr}` : ''
73
- }
74
- }
75
-
76
- export type SearchSerializer = (searchObj: Record<string, any>) => string
77
- export type SearchParser = (searchStr: string) => Record<string, any>
package/src/serializer.ts DELETED
@@ -1,24 +0,0 @@
1
- export interface StartSerializer {
2
- stringify: (obj: unknown) => string
3
- parse: (str: string) => unknown
4
- encode: <T>(value: T) => T
5
- decode: <T>(value: T) => T
6
- }
7
-
8
- export type SerializerStringifyBy<T, TSerializable> = T extends TSerializable
9
- ? T
10
- : T extends (...args: Array<any>) => any
11
- ? 'Function is not serializable'
12
- : { [K in keyof T]: SerializerStringifyBy<T[K], TSerializable> }
13
-
14
- export type SerializerParseBy<T, TSerializable> = T extends TSerializable
15
- ? T
16
- : T extends React.JSX.Element
17
- ? ReadableStream
18
- : { [K in keyof T]: SerializerParseBy<T[K], TSerializable> }
19
-
20
- export type Serializable = Date | undefined | Error | FormData
21
-
22
- export type SerializerStringify<T> = SerializerStringifyBy<T, Serializable>
23
-
24
- export type SerializerParse<T> = SerializerParseBy<T, Serializable>
package/src/validators.ts DELETED
@@ -1,121 +0,0 @@
1
- import type { SearchSchemaInput } from './route'
2
-
3
- export interface StandardSchemaValidatorProps<TInput, TOutput> {
4
- readonly types?: StandardSchemaValidatorTypes<TInput, TOutput> | undefined
5
- readonly validate: AnyStandardSchemaValidate
6
- }
7
-
8
- export interface StandardSchemaValidator<TInput, TOutput> {
9
- readonly '~standard': StandardSchemaValidatorProps<TInput, TOutput>
10
- }
11
-
12
- export type AnyStandardSchemaValidator = StandardSchemaValidator<any, any>
13
-
14
- export interface StandardSchemaValidatorTypes<TInput, TOutput> {
15
- readonly input: TInput
16
- readonly output: TOutput
17
- }
18
-
19
- export interface AnyStandardSchemaValidateSuccess {
20
- readonly value: any
21
- readonly issues?: undefined
22
- }
23
-
24
- export interface AnyStandardSchemaValidateFailure {
25
- readonly issues: ReadonlyArray<AnyStandardSchemaValidateIssue>
26
- }
27
-
28
- export interface AnyStandardSchemaValidateIssue {
29
- readonly message: string
30
- }
31
-
32
- export interface AnyStandardSchemaValidateInput {
33
- readonly value: any
34
- }
35
-
36
- export type AnyStandardSchemaValidate = (
37
- value: unknown,
38
- ) =>
39
- | (AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure)
40
- | Promise<AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure>
41
-
42
- export interface ValidatorObj<TInput, TOutput> {
43
- parse: ValidatorFn<TInput, TOutput>
44
- }
45
-
46
- export type AnyValidatorObj = ValidatorObj<any, any>
47
-
48
- export interface ValidatorAdapter<TInput, TOutput> {
49
- types: {
50
- input: TInput
51
- output: TOutput
52
- }
53
- parse: (input: unknown) => TOutput
54
- }
55
-
56
- export type AnyValidatorAdapter = ValidatorAdapter<any, any>
57
-
58
- export type AnyValidatorFn = ValidatorFn<any, any>
59
-
60
- export type ValidatorFn<TInput, TOutput> = (input: TInput) => TOutput
61
-
62
- export type Validator<TInput, TOutput> =
63
- | ValidatorObj<TInput, TOutput>
64
- | ValidatorFn<TInput, TOutput>
65
- | ValidatorAdapter<TInput, TOutput>
66
- | StandardSchemaValidator<TInput, TOutput>
67
- | undefined
68
-
69
- export type AnyValidator = Validator<any, any>
70
-
71
- export type AnySchema = {}
72
-
73
- export type DefaultValidator = Validator<Record<string, unknown>, AnySchema>
74
-
75
- export type ResolveSearchValidatorInputFn<TValidator> = TValidator extends (
76
- input: infer TSchemaInput,
77
- ) => any
78
- ? TSchemaInput extends SearchSchemaInput
79
- ? Omit<TSchemaInput, keyof SearchSchemaInput>
80
- : ResolveValidatorOutputFn<TValidator>
81
- : AnySchema
82
-
83
- export type ResolveSearchValidatorInput<TValidator> =
84
- TValidator extends AnyStandardSchemaValidator
85
- ? NonNullable<TValidator['~standard']['types']>['input']
86
- : TValidator extends AnyValidatorAdapter
87
- ? TValidator['types']['input']
88
- : TValidator extends AnyValidatorObj
89
- ? ResolveSearchValidatorInputFn<TValidator['parse']>
90
- : ResolveSearchValidatorInputFn<TValidator>
91
-
92
- export type ResolveValidatorInputFn<TValidator> = TValidator extends (
93
- input: infer TInput,
94
- ) => any
95
- ? TInput
96
- : undefined
97
-
98
- export type ResolveValidatorInput<TValidator> =
99
- TValidator extends AnyStandardSchemaValidator
100
- ? NonNullable<TValidator['~standard']['types']>['input']
101
- : TValidator extends AnyValidatorAdapter
102
- ? TValidator['types']['input']
103
- : TValidator extends AnyValidatorObj
104
- ? ResolveValidatorInputFn<TValidator['parse']>
105
- : ResolveValidatorInputFn<TValidator>
106
-
107
- export type ResolveValidatorOutputFn<TValidator> = TValidator extends (
108
- ...args: any
109
- ) => infer TSchema
110
- ? TSchema
111
- : AnySchema
112
-
113
- export type ResolveValidatorOutput<TValidator> = unknown extends TValidator
114
- ? TValidator
115
- : TValidator extends AnyStandardSchemaValidator
116
- ? NonNullable<TValidator['~standard']['types']>['output']
117
- : TValidator extends AnyValidatorAdapter
118
- ? TValidator['types']['output']
119
- : TValidator extends AnyValidatorObj
120
- ? ResolveValidatorOutputFn<TValidator['parse']>
121
- : ResolveValidatorOutputFn<TValidator>