react-router 7.18.0 → 8.0.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/dist/development/dom-export.d.ts +6 -172
  2. package/dist/development/dom-export.js +12 -1009
  3. package/dist/development/index-react-server-client.d.ts +7 -4
  4. package/dist/development/index-react-server-client.js +8 -52
  5. package/dist/development/index-react-server.d.ts +1650 -1641
  6. package/dist/development/index-react-server.js +2882 -3664
  7. package/dist/development/index.d.ts +42 -1476
  8. package/dist/development/index.js +36 -2553
  9. package/dist/development/lib/actions.js +50 -0
  10. package/dist/development/lib/components.d.ts +1030 -0
  11. package/dist/development/lib/components.js +841 -0
  12. package/dist/development/lib/context.d.ts +83 -0
  13. package/dist/development/lib/context.js +41 -0
  14. package/dist/development/lib/dom/dom.d.ts +119 -0
  15. package/dist/development/lib/dom/dom.js +143 -0
  16. package/dist/development/lib/dom/lib.d.ts +2053 -0
  17. package/dist/development/lib/dom/lib.js +1271 -0
  18. package/dist/development/lib/dom/server.d.ts +138 -0
  19. package/dist/development/lib/dom/server.js +301 -0
  20. package/dist/development/lib/dom/ssr/components.d.ts +198 -0
  21. package/dist/development/lib/dom/ssr/components.js +589 -0
  22. package/dist/development/lib/dom/ssr/data.js +29 -0
  23. package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
  24. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
  26. package/dist/development/lib/dom/ssr/fallback.js +33 -0
  27. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  28. package/dist/development/lib/dom/ssr/fog-of-war.js +180 -0
  29. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  30. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  31. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  32. package/dist/development/lib/dom/ssr/links.js +170 -0
  33. package/dist/development/lib/dom/ssr/markup.js +24 -0
  34. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  35. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  36. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  37. package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
  38. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  39. package/dist/development/lib/dom/ssr/routes.js +303 -0
  40. package/dist/development/lib/dom/ssr/server.d.ts +48 -0
  41. package/dist/development/lib/dom/ssr/server.js +69 -0
  42. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  43. package/dist/development/lib/dom/ssr/single-fetch.js +345 -0
  44. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  45. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  46. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  47. package/dist/development/lib/dom-export/hydrated-router.js +150 -0
  48. package/dist/development/lib/errors.js +29 -0
  49. package/dist/development/lib/hooks.d.ts +947 -0
  50. package/dist/development/lib/hooks.js +1388 -0
  51. package/dist/development/lib/href.d.ts +20 -0
  52. package/dist/development/lib/href.js +50 -0
  53. package/dist/development/lib/router/history.d.ts +258 -0
  54. package/dist/development/lib/router/history.js +372 -0
  55. package/dist/development/lib/router/instrumentation.d.ts +86 -0
  56. package/dist/development/lib/router/instrumentation.js +213 -0
  57. package/dist/development/lib/router/links.d.ts +114 -0
  58. package/dist/development/lib/router/router.d.ts +663 -0
  59. package/dist/development/lib/router/router.js +2988 -0
  60. package/dist/development/lib/router/url.js +18 -0
  61. package/dist/development/lib/router/utils.d.ts +948 -0
  62. package/dist/development/lib/router/utils.js +810 -0
  63. package/dist/development/lib/rsc/browser.d.ts +137 -0
  64. package/dist/development/lib/rsc/browser.js +603 -0
  65. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  66. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  67. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  68. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  69. package/dist/development/lib/rsc/html-stream/server.js +78 -0
  70. package/dist/development/lib/rsc/route-modules.js +27 -0
  71. package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
  72. package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
  73. package/dist/development/lib/rsc/server.ssr.js +404 -0
  74. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  75. package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
  76. package/dist/development/lib/server-runtime/cookies.js +139 -0
  77. package/dist/development/lib/server-runtime/crypto.js +43 -0
  78. package/dist/development/lib/server-runtime/data.d.ts +13 -0
  79. package/dist/development/lib/server-runtime/data.js +25 -0
  80. package/dist/development/lib/server-runtime/dev.d.ts +9 -0
  81. package/dist/development/lib/server-runtime/dev.js +26 -0
  82. package/dist/development/lib/server-runtime/entry.js +20 -0
  83. package/dist/development/lib/server-runtime/errors.js +75 -0
  84. package/dist/development/lib/server-runtime/headers.js +73 -0
  85. package/dist/development/lib/server-runtime/invariant.js +19 -0
  86. package/dist/development/lib/server-runtime/mode.d.ts +12 -0
  87. package/dist/development/lib/server-runtime/mode.js +25 -0
  88. package/dist/development/lib/server-runtime/routeMatching.js +28 -0
  89. package/dist/development/lib/server-runtime/routes.d.ts +13 -0
  90. package/dist/development/lib/server-runtime/routes.js +74 -0
  91. package/dist/development/lib/server-runtime/server.d.ts +10 -0
  92. package/dist/development/lib/server-runtime/server.js +345 -0
  93. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  94. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  95. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
  96. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  97. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
  98. package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
  99. package/dist/development/lib/server-runtime/sessions.js +98 -0
  100. package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
  101. package/dist/development/lib/server-runtime/single-fetch.js +215 -0
  102. package/dist/development/lib/server-runtime/urls.js +28 -0
  103. package/dist/development/lib/server-runtime/warnings.js +20 -0
  104. package/dist/development/lib/types/future.d.ts +9 -0
  105. package/dist/development/lib/types/internal.d.ts +26 -177
  106. package/dist/development/lib/types/internal.js +3 -2
  107. package/dist/development/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  108. package/dist/development/lib/types/route-data.d.ts +113 -0
  109. package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
  110. package/dist/development/lib/types/route-module.d.ts +19 -0
  111. package/dist/development/lib/types/serializes-to.d.ts +13 -0
  112. package/dist/development/lib/types/utils.d.ts +11 -0
  113. package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
  114. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  115. package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
  116. package/dist/development/vendor/turbo-stream-v2/utils.js +39 -0
  117. package/dist/production/dom-export.d.ts +6 -172
  118. package/dist/production/dom-export.js +12 -1009
  119. package/dist/production/index-react-server-client.d.ts +7 -4
  120. package/dist/production/index-react-server-client.js +8 -52
  121. package/dist/production/index-react-server.d.ts +1650 -1641
  122. package/dist/production/index-react-server.js +2873 -3664
  123. package/dist/production/index.d.ts +42 -1476
  124. package/dist/production/index.js +36 -2553
  125. package/dist/production/lib/actions.js +50 -0
  126. package/dist/production/lib/components.d.ts +1030 -0
  127. package/dist/production/lib/components.js +841 -0
  128. package/dist/production/lib/context.d.ts +83 -0
  129. package/dist/production/lib/context.js +41 -0
  130. package/dist/production/lib/dom/dom.d.ts +119 -0
  131. package/dist/production/lib/dom/dom.js +143 -0
  132. package/dist/production/lib/dom/lib.d.ts +2053 -0
  133. package/dist/production/lib/dom/lib.js +1271 -0
  134. package/dist/production/lib/dom/server.d.ts +138 -0
  135. package/dist/production/lib/dom/server.js +301 -0
  136. package/dist/production/lib/dom/ssr/components.d.ts +198 -0
  137. package/dist/production/lib/dom/ssr/components.js +589 -0
  138. package/dist/production/lib/dom/ssr/data.js +29 -0
  139. package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
  140. package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  141. package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
  142. package/dist/production/lib/dom/ssr/fallback.js +23 -0
  143. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
  144. package/dist/production/lib/dom/ssr/fog-of-war.js +180 -0
  145. package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
  146. package/dist/production/lib/dom/ssr/hydration.js +29 -0
  147. package/dist/production/lib/dom/ssr/invariant.js +16 -0
  148. package/dist/production/lib/dom/ssr/links.js +170 -0
  149. package/dist/production/lib/dom/ssr/markup.js +24 -0
  150. package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
  151. package/dist/production/lib/dom/ssr/routeModules.js +31 -0
  152. package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  153. package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
  154. package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
  155. package/dist/production/lib/dom/ssr/routes.js +303 -0
  156. package/dist/production/lib/dom/ssr/server.d.ts +48 -0
  157. package/dist/production/lib/dom/ssr/server.js +69 -0
  158. package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
  159. package/dist/production/lib/dom/ssr/single-fetch.js +345 -0
  160. package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
  161. package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
  162. package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
  163. package/dist/production/lib/dom-export/hydrated-router.js +150 -0
  164. package/dist/production/lib/errors.js +29 -0
  165. package/dist/production/lib/hooks.d.ts +947 -0
  166. package/dist/production/lib/hooks.js +1373 -0
  167. package/dist/production/lib/href.d.ts +20 -0
  168. package/dist/production/lib/href.js +50 -0
  169. package/dist/production/lib/router/history.d.ts +258 -0
  170. package/dist/production/lib/router/history.js +372 -0
  171. package/dist/production/lib/router/instrumentation.d.ts +86 -0
  172. package/dist/production/lib/router/instrumentation.js +213 -0
  173. package/dist/production/lib/router/links.d.ts +114 -0
  174. package/dist/production/lib/router/router.d.ts +663 -0
  175. package/dist/production/lib/router/router.js +2988 -0
  176. package/dist/production/lib/router/url.js +18 -0
  177. package/dist/production/lib/router/utils.d.ts +948 -0
  178. package/dist/production/lib/router/utils.js +801 -0
  179. package/dist/production/lib/rsc/browser.d.ts +137 -0
  180. package/dist/production/lib/rsc/browser.js +603 -0
  181. package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
  182. package/dist/production/lib/rsc/errorBoundaries.js +90 -0
  183. package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
  184. package/dist/production/lib/rsc/html-stream/browser.js +74 -0
  185. package/dist/production/lib/rsc/html-stream/server.js +78 -0
  186. package/dist/production/lib/rsc/route-modules.js +27 -0
  187. package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
  188. package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
  189. package/dist/production/lib/rsc/server.ssr.js +404 -0
  190. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  191. package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
  192. package/dist/production/lib/server-runtime/cookies.js +139 -0
  193. package/dist/production/lib/server-runtime/crypto.js +43 -0
  194. package/dist/production/lib/server-runtime/data.d.ts +13 -0
  195. package/dist/production/lib/server-runtime/data.js +25 -0
  196. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  197. package/dist/production/lib/server-runtime/dev.js +26 -0
  198. package/dist/production/lib/server-runtime/entry.js +20 -0
  199. package/dist/production/lib/server-runtime/errors.js +75 -0
  200. package/dist/production/lib/server-runtime/headers.js +73 -0
  201. package/dist/production/lib/server-runtime/invariant.js +19 -0
  202. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  203. package/dist/production/lib/server-runtime/mode.js +25 -0
  204. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  205. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  206. package/dist/production/lib/server-runtime/routes.js +74 -0
  207. package/dist/production/lib/server-runtime/server.d.ts +10 -0
  208. package/dist/production/lib/server-runtime/server.js +345 -0
  209. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  210. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  211. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
  212. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  213. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
  214. package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
  215. package/dist/production/lib/server-runtime/sessions.js +98 -0
  216. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  217. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  218. package/dist/production/lib/server-runtime/urls.js +28 -0
  219. package/dist/production/lib/server-runtime/warnings.js +20 -0
  220. package/dist/production/lib/types/future.d.ts +9 -0
  221. package/dist/production/lib/types/internal.d.ts +26 -177
  222. package/dist/production/lib/types/internal.js +3 -2
  223. package/dist/production/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  224. package/dist/production/lib/types/route-data.d.ts +113 -0
  225. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  226. package/dist/production/lib/types/route-module.d.ts +19 -0
  227. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  228. package/dist/production/lib/types/utils.d.ts +11 -0
  229. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  230. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  231. package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
  232. package/dist/production/vendor/turbo-stream-v2/utils.js +39 -0
  233. package/docs/explanation/code-splitting.md +16 -0
  234. package/docs/how-to/middleware.md +6 -41
  235. package/docs/how-to/react-server-components.md +1 -1
  236. package/docs/upgrading/future.md +0 -249
  237. package/package.json +43 -87
  238. package/dist/development/browser-B2PdsXXH.d.ts +0 -318
  239. package/dist/development/browser-DBmQ1yAR.d.mts +0 -318
  240. package/dist/development/chunk-4ZMWKKQ3.mjs +0 -11606
  241. package/dist/development/chunk-E4MTK73K.mjs +0 -2517
  242. package/dist/development/chunk-U7ORXROY.js +0 -10307
  243. package/dist/development/chunk-WW7PN6QI.js +0 -188
  244. package/dist/development/chunk-YL5M26XI.js +0 -1366
  245. package/dist/development/context-CeD5LmaF.d.mts +0 -1779
  246. package/dist/development/data-CjO11-hU.d.ts +0 -1740
  247. package/dist/development/data-DEjBmEfD.d.mts +0 -1740
  248. package/dist/development/dom-export.d.mts +0 -172
  249. package/dist/development/dom-export.mjs +0 -1010
  250. package/dist/development/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  251. package/dist/development/index-react-server-client-CACgcj2J.d.mts +0 -2614
  252. package/dist/development/index-react-server-client.d.mts +0 -4
  253. package/dist/development/index-react-server-client.mjs +0 -59
  254. package/dist/development/index-react-server.d.mts +0 -2711
  255. package/dist/development/index-react-server.mjs +0 -3803
  256. package/dist/development/index.d.mts +0 -1479
  257. package/dist/development/index.mjs +0 -275
  258. package/dist/development/instrumentation-Dkmpzd13.d.ts +0 -715
  259. package/dist/development/lib/types/internal.d.mts +0 -184
  260. package/dist/development/lib/types/internal.mjs +0 -10
  261. package/dist/development/register-CmkRspdl.d.mts +0 -30
  262. package/dist/production/browser-B2PdsXXH.d.ts +0 -318
  263. package/dist/production/browser-DBmQ1yAR.d.mts +0 -318
  264. package/dist/production/chunk-3Z6WS2WZ.js +0 -188
  265. package/dist/production/chunk-BIP66BKV.js +0 -1366
  266. package/dist/production/chunk-EGOTSXNH.mjs +0 -2517
  267. package/dist/production/chunk-IUPBOWYO.js +0 -10307
  268. package/dist/production/chunk-M7NGGUU6.mjs +0 -11606
  269. package/dist/production/context-CeD5LmaF.d.mts +0 -1779
  270. package/dist/production/data-CjO11-hU.d.ts +0 -1740
  271. package/dist/production/data-DEjBmEfD.d.mts +0 -1740
  272. package/dist/production/dom-export.d.mts +0 -172
  273. package/dist/production/dom-export.mjs +0 -1010
  274. package/dist/production/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  275. package/dist/production/index-react-server-client-CACgcj2J.d.mts +0 -2614
  276. package/dist/production/index-react-server-client.d.mts +0 -4
  277. package/dist/production/index-react-server-client.mjs +0 -59
  278. package/dist/production/index-react-server.d.mts +0 -2711
  279. package/dist/production/index-react-server.mjs +0 -3803
  280. package/dist/production/index.d.mts +0 -1479
  281. package/dist/production/index.mjs +0 -275
  282. package/dist/production/instrumentation-Dkmpzd13.d.ts +0 -715
  283. package/dist/production/lib/types/internal.d.mts +0 -184
  284. package/dist/production/lib/types/internal.mjs +0 -10
  285. package/dist/production/register-CmkRspdl.d.mts +0 -30
@@ -0,0 +1,20 @@
1
+
2
+ import { Equal } from "./types/utils.js";
3
+ import { Pages } from "./types/register.js";
4
+
5
+ //#region lib/href.d.ts
6
+ type Args = { [K in keyof Pages]: ToArgs<Pages[K]["params"]> };
7
+ type ToArgs<Params extends Record<string, string | undefined>> = Equal<Params, {}> extends true ? [] : Partial<Params> extends Params ? [Params] | [] : [Params];
8
+ /**
9
+ Returns a resolved URL path for the specified route.
10
+
11
+ ```tsx
12
+ const h = href("/:lang?/about", { lang: "en" })
13
+ // -> `/en/about`
14
+
15
+ <Link to={href("/products/:id", { id: "abc123" })} />
16
+ ```
17
+ */
18
+ declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
19
+ //#endregion
20
+ export { href };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
3
+ *
4
+ * Copyright (c) Remix Software Inc.
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
+ //#region lib/href.ts
12
+ /**
13
+ Returns a resolved URL path for the specified route.
14
+
15
+ ```tsx
16
+ const h = href("/:lang?/about", { lang: "en" })
17
+ // -> `/en/about`
18
+
19
+ <Link to={href("/products/:id", { id: "abc123" })} />
20
+ ```
21
+ */
22
+ function href(path, ...args) {
23
+ let params = args[0];
24
+ let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
25
+ const isRequired = questionMark === void 0;
26
+ const value = params?.[param];
27
+ if (isRequired && value === void 0) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
28
+ return value === void 0 ? "" : "/" + value;
29
+ });
30
+ if (path.endsWith("*")) {
31
+ const value = params?.["*"];
32
+ if (value !== void 0) result += "/" + value;
33
+ }
34
+ return result || "/";
35
+ }
36
+ /**
37
+ * Removes a trailing splat and any number of slashes from the end of the path.
38
+ *
39
+ * Benchmarked to be faster than `path.replace(/\/*\*?$/, "")`, which backtracks.
40
+ */
41
+ function trimTrailingSplat(path) {
42
+ let i = path.length - 1;
43
+ let char = path[i];
44
+ if (char !== "*" && char !== "/") return path;
45
+ i--;
46
+ for (; i >= 0; i--) if (path[i] !== "/") break;
47
+ return path.slice(0, i + 1);
48
+ }
49
+ //#endregion
50
+ export { href };
@@ -0,0 +1,258 @@
1
+
2
+ //#region lib/router/history.d.ts
3
+ /**
4
+ * Actions represent the type of change to a location value.
5
+ */
6
+ declare enum Action {
7
+ /**
8
+ * A POP indicates a change to an arbitrary index in the history stack, such
9
+ * as a back or forward navigation. It does not describe the direction of the
10
+ * navigation, only that the current index changed.
11
+ *
12
+ * Note: This is the default action for newly created history objects.
13
+ */
14
+ Pop = "POP",
15
+ /**
16
+ * A PUSH indicates a new entry being added to the history stack, such as when
17
+ * a link is clicked and a new page loads. When this happens, all subsequent
18
+ * entries in the stack are lost.
19
+ */
20
+ Push = "PUSH",
21
+ /**
22
+ * A REPLACE indicates the entry at the current index in the history stack
23
+ * being replaced by a new one.
24
+ */
25
+ Replace = "REPLACE"
26
+ }
27
+ /**
28
+ * The pathname, search, and hash values of a URL.
29
+ */
30
+ interface Path {
31
+ /**
32
+ * A URL pathname, beginning with a /.
33
+ */
34
+ pathname: string;
35
+ /**
36
+ * A URL search string, beginning with a ?.
37
+ */
38
+ search: string;
39
+ /**
40
+ * A URL fragment identifier, beginning with a #.
41
+ */
42
+ hash: string;
43
+ }
44
+ /**
45
+ * An entry in a history stack. A location contains information about the
46
+ * URL path, as well as possibly some arbitrary state and a key.
47
+ */
48
+ interface Location<State = any> extends Path {
49
+ /**
50
+ * A value of arbitrary data associated with this location.
51
+ */
52
+ state: State;
53
+ /**
54
+ * A unique string associated with this location. May be used to safely store
55
+ * and retrieve data in some other storage API, like `localStorage`.
56
+ *
57
+ * Note: This value is always "default" on the initial location.
58
+ */
59
+ key: string;
60
+ /**
61
+ * The masked location displayed in the URL bar, which differs from the URL the
62
+ * router is operating on
63
+ */
64
+ mask?: Path;
65
+ }
66
+ /**
67
+ * A change to the current location.
68
+ */
69
+ interface Update {
70
+ /**
71
+ * The action that triggered the change.
72
+ */
73
+ action: Action;
74
+ /**
75
+ * The new location.
76
+ */
77
+ location: Location;
78
+ /**
79
+ * The delta between this location and the former location in the history stack
80
+ */
81
+ delta: number | null;
82
+ }
83
+ /**
84
+ * A function that receives notifications about location changes.
85
+ */
86
+ interface Listener {
87
+ (update: Update): void;
88
+ }
89
+ /**
90
+ * Describes a location that is the destination of some navigation used in
91
+ * {@link Link}, {@link useNavigate}, etc.
92
+ */
93
+ type To = string | Partial<Path>;
94
+ /**
95
+ * A history is an interface to the navigation stack. The history serves as the
96
+ * source of truth for the current location, as well as provides a set of
97
+ * methods that may be used to change it.
98
+ *
99
+ * It is similar to the DOM's `window.history` object, but with a smaller, more
100
+ * focused API.
101
+ */
102
+ interface History {
103
+ /**
104
+ * The last action that modified the current location. This will always be
105
+ * Action.Pop when a history instance is first created. This value is mutable.
106
+ */
107
+ readonly action: Action;
108
+ /**
109
+ * The current location. This value is mutable.
110
+ */
111
+ readonly location: Location;
112
+ /**
113
+ * Returns a valid href for the given `to` value that may be used as
114
+ * the value of an <a href> attribute.
115
+ *
116
+ * @param to - The destination URL
117
+ */
118
+ createHref(to: To): string;
119
+ /**
120
+ * Returns a URL for the given `to` value
121
+ *
122
+ * @param to - The destination URL
123
+ */
124
+ createURL(to: To): URL;
125
+ /**
126
+ * Encode a location the same way window.history would do (no-op for memory
127
+ * history) so we ensure our PUSH/REPLACE navigations for data routers
128
+ * behave the same as POP
129
+ *
130
+ * @param to Unencoded path
131
+ */
132
+ encodeLocation(to: To): Path;
133
+ /**
134
+ * Pushes a new location onto the history stack, increasing its length by one.
135
+ * If there were any entries in the stack after the current one, they are
136
+ * lost.
137
+ *
138
+ * @param to - The new URL
139
+ * @param state - Data to associate with the new location
140
+ */
141
+ push(to: To, state?: any): void;
142
+ /**
143
+ * Replaces the current location in the history stack with a new one. The
144
+ * location that was replaced will no longer be available.
145
+ *
146
+ * @param to - The new URL
147
+ * @param state - Data to associate with the new location
148
+ */
149
+ replace(to: To, state?: any): void;
150
+ /**
151
+ * Navigates `n` entries backward/forward in the history stack relative to the
152
+ * current index. For example, a "back" navigation would use go(-1).
153
+ *
154
+ * @param delta - The delta in the stack index
155
+ */
156
+ go(delta: number): void;
157
+ /**
158
+ * Sets up a listener that will be called whenever the current location
159
+ * changes.
160
+ *
161
+ * @param listener - A function that will be called when the location changes
162
+ * @returns unlisten - A function that may be used to stop listening
163
+ */
164
+ listen(listener: Listener): () => void;
165
+ }
166
+ /**
167
+ * A user-supplied object that describes a location. Used when providing
168
+ * entries to `createMemoryHistory` via its `initialEntries` option.
169
+ */
170
+ type InitialEntry = string | Partial<Location>;
171
+ type MemoryHistoryOptions = {
172
+ initialEntries?: InitialEntry[];
173
+ initialIndex?: number;
174
+ v5Compat?: boolean;
175
+ };
176
+ /**
177
+ * A memory history stores locations in memory. This is useful in stateful
178
+ * environments where there is no web browser, such as node tests or React
179
+ * Native.
180
+ */
181
+ interface MemoryHistory extends History {
182
+ /**
183
+ * The current index in the history stack.
184
+ */
185
+ readonly index: number;
186
+ }
187
+ /**
188
+ * Memory history stores the current location in memory. It is designed for use
189
+ * in stateful non-browser environments like tests and React Native.
190
+ */
191
+ declare function createMemoryHistory(options?: MemoryHistoryOptions): MemoryHistory;
192
+ /**
193
+ * A browser history stores the current location in regular URLs in a web
194
+ * browser environment. This is the standard for most web apps and provides the
195
+ * cleanest URLs the browser's address bar.
196
+ *
197
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
198
+ */
199
+ interface BrowserHistory extends UrlHistory {}
200
+ type BrowserHistoryOptions = UrlHistoryOptions;
201
+ /**
202
+ * Browser history stores the location in regular URLs. This is the standard for
203
+ * most web apps, but it requires some configuration on the server to ensure you
204
+ * serve the same app at multiple URLs.
205
+ *
206
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
207
+ */
208
+ declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
209
+ /**
210
+ * A hash history stores the current location in the fragment identifier portion
211
+ * of the URL in a web browser environment.
212
+ *
213
+ * This is ideal for apps that do not control the server for some reason
214
+ * (because the fragment identifier is never sent to the server), including some
215
+ * shared hosting environments that do not provide fine-grained controls over
216
+ * which pages are served at which URLs.
217
+ *
218
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
219
+ */
220
+ interface HashHistory extends UrlHistory {}
221
+ type HashHistoryOptions = UrlHistoryOptions;
222
+ /**
223
+ * Hash history stores the location in window.location.hash. This makes it ideal
224
+ * for situations where you don't want to send the location to the server for
225
+ * some reason, either because you do cannot configure it or the URL space is
226
+ * reserved for something else.
227
+ *
228
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
229
+ */
230
+ declare function createHashHistory(options?: HashHistoryOptions): HashHistory;
231
+ /**
232
+ * @private
233
+ */
234
+ declare function invariant(value: boolean, message?: string): asserts value;
235
+ declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
236
+ /**
237
+ * Creates a string URL path from the given pathname, search, and hash components.
238
+ *
239
+ * @category Utils
240
+ */
241
+ declare function createPath({
242
+ pathname,
243
+ search,
244
+ hash
245
+ }: Partial<Path>): string;
246
+ /**
247
+ * Parses a string URL path into its separate pathname, search, and hash components.
248
+ *
249
+ * @category Utils
250
+ */
251
+ declare function parsePath(path: string): Partial<Path>;
252
+ interface UrlHistory extends History {}
253
+ type UrlHistoryOptions = {
254
+ window?: Window;
255
+ v5Compat?: boolean;
256
+ };
257
+ //#endregion
258
+ export { Action, History, InitialEntry, Location, Path, To, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, invariant, parsePath };
@@ -0,0 +1,372 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
3
+ *
4
+ * Copyright (c) Remix Software Inc.
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
+ import { PROTOCOL_RELATIVE_URL_REGEX } from "./url.js";
12
+ //#region lib/router/history.ts
13
+ /**
14
+ * Actions represent the type of change to a location value.
15
+ */
16
+ let Action = /* @__PURE__ */ function(Action) {
17
+ /**
18
+ * A POP indicates a change to an arbitrary index in the history stack, such
19
+ * as a back or forward navigation. It does not describe the direction of the
20
+ * navigation, only that the current index changed.
21
+ *
22
+ * Note: This is the default action for newly created history objects.
23
+ */
24
+ Action["Pop"] = "POP";
25
+ /**
26
+ * A PUSH indicates a new entry being added to the history stack, such as when
27
+ * a link is clicked and a new page loads. When this happens, all subsequent
28
+ * entries in the stack are lost.
29
+ */
30
+ Action["Push"] = "PUSH";
31
+ /**
32
+ * A REPLACE indicates the entry at the current index in the history stack
33
+ * being replaced by a new one.
34
+ */
35
+ Action["Replace"] = "REPLACE";
36
+ return Action;
37
+ }({});
38
+ const PopStateEventType = "popstate";
39
+ function isLocation(obj) {
40
+ return typeof obj === "object" && obj != null && "pathname" in obj && "search" in obj && "hash" in obj && "state" in obj && "key" in obj;
41
+ }
42
+ /**
43
+ * Memory history stores the current location in memory. It is designed for use
44
+ * in stateful non-browser environments like tests and React Native.
45
+ */
46
+ function createMemoryHistory(options = {}) {
47
+ let { initialEntries = ["/"], initialIndex, v5Compat = false } = options;
48
+ let entries;
49
+ entries = initialEntries.map((entry, index) => createMemoryLocation(entry, typeof entry === "string" ? null : entry.state, index === 0 ? "default" : void 0, typeof entry === "string" ? void 0 : entry.mask));
50
+ let index = clampIndex(initialIndex == null ? entries.length - 1 : initialIndex);
51
+ let action = "POP";
52
+ let listener = null;
53
+ function clampIndex(n) {
54
+ return Math.min(Math.max(n, 0), entries.length - 1);
55
+ }
56
+ function getCurrentLocation() {
57
+ return entries[index];
58
+ }
59
+ function createMemoryLocation(to, state = null, key, mask) {
60
+ let location = createLocation(entries ? getCurrentLocation().pathname : "/", to, state, key, mask);
61
+ warning(location.pathname.charAt(0) === "/", `relative pathnames are not supported in memory history: ${JSON.stringify(to)}`);
62
+ return location;
63
+ }
64
+ function createHref(to) {
65
+ return typeof to === "string" ? to : createPath(to);
66
+ }
67
+ return {
68
+ get index() {
69
+ return index;
70
+ },
71
+ get action() {
72
+ return action;
73
+ },
74
+ get location() {
75
+ return getCurrentLocation();
76
+ },
77
+ createHref,
78
+ createURL(to) {
79
+ return new URL(createHref(to), "http://localhost");
80
+ },
81
+ encodeLocation(to) {
82
+ let path = typeof to === "string" ? parsePath(to) : to;
83
+ return {
84
+ pathname: path.pathname || "",
85
+ search: path.search || "",
86
+ hash: path.hash || ""
87
+ };
88
+ },
89
+ push(to, state) {
90
+ action = "PUSH";
91
+ let nextLocation = isLocation(to) ? to : createMemoryLocation(to, state);
92
+ index += 1;
93
+ entries.splice(index, entries.length, nextLocation);
94
+ if (v5Compat && listener) listener({
95
+ action,
96
+ location: nextLocation,
97
+ delta: 1
98
+ });
99
+ },
100
+ replace(to, state) {
101
+ action = "REPLACE";
102
+ let nextLocation = isLocation(to) ? to : createMemoryLocation(to, state);
103
+ entries[index] = nextLocation;
104
+ if (v5Compat && listener) listener({
105
+ action,
106
+ location: nextLocation,
107
+ delta: 0
108
+ });
109
+ },
110
+ go(delta) {
111
+ action = "POP";
112
+ let nextIndex = clampIndex(index + delta);
113
+ let nextLocation = entries[nextIndex];
114
+ index = nextIndex;
115
+ if (listener) listener({
116
+ action,
117
+ location: nextLocation,
118
+ delta
119
+ });
120
+ },
121
+ listen(fn) {
122
+ listener = fn;
123
+ return () => {
124
+ listener = null;
125
+ };
126
+ }
127
+ };
128
+ }
129
+ /**
130
+ * Browser history stores the location in regular URLs. This is the standard for
131
+ * most web apps, but it requires some configuration on the server to ensure you
132
+ * serve the same app at multiple URLs.
133
+ *
134
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
135
+ */
136
+ function createBrowserHistory(options = {}) {
137
+ function createBrowserLocation(window, globalHistory) {
138
+ let maskedLocation = globalHistory.state?.masked;
139
+ let { pathname, search, hash } = maskedLocation || window.location;
140
+ return createLocation("", {
141
+ pathname,
142
+ search,
143
+ hash
144
+ }, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default", maskedLocation ? {
145
+ pathname: window.location.pathname,
146
+ search: window.location.search,
147
+ hash: window.location.hash
148
+ } : void 0);
149
+ }
150
+ function createBrowserHref(window, to) {
151
+ return typeof to === "string" ? to : createPath(to);
152
+ }
153
+ return getUrlBasedHistory(createBrowserLocation, createBrowserHref, null, options);
154
+ }
155
+ /**
156
+ * Hash history stores the location in window.location.hash. This makes it ideal
157
+ * for situations where you don't want to send the location to the server for
158
+ * some reason, either because you do cannot configure it or the URL space is
159
+ * reserved for something else.
160
+ *
161
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
162
+ */
163
+ function createHashHistory(options = {}) {
164
+ function createHashLocation(window, globalHistory) {
165
+ let { pathname = "/", search = "", hash = "" } = parsePath(window.location.hash.substring(1));
166
+ if (!pathname.startsWith("/") && !pathname.startsWith(".")) pathname = "/" + pathname;
167
+ return createLocation("", {
168
+ pathname,
169
+ search,
170
+ hash
171
+ }, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default");
172
+ }
173
+ function createHashHref(window, to) {
174
+ let base = window.document.querySelector("base");
175
+ let href = "";
176
+ if (base && base.getAttribute("href")) {
177
+ let url = window.location.href;
178
+ let hashIndex = url.indexOf("#");
179
+ href = hashIndex === -1 ? url : url.slice(0, hashIndex);
180
+ }
181
+ return href + "#" + (typeof to === "string" ? to : createPath(to));
182
+ }
183
+ function validateHashLocation(location, to) {
184
+ warning(location.pathname.charAt(0) === "/", `relative pathnames are not supported in hash history.push(${JSON.stringify(to)})`);
185
+ }
186
+ return getUrlBasedHistory(createHashLocation, createHashHref, validateHashLocation, options);
187
+ }
188
+ function invariant(value, message) {
189
+ if (value === false || value === null || typeof value === "undefined") throw new Error(message);
190
+ }
191
+ function warning(cond, message) {
192
+ if (!cond) {
193
+ if (typeof console !== "undefined") console.warn(message);
194
+ try {
195
+ throw new Error(message);
196
+ } catch (e) {}
197
+ }
198
+ }
199
+ function createKey() {
200
+ return Math.random().toString(36).substring(2, 10);
201
+ }
202
+ /**
203
+ * For browser-based histories, we combine the state and key into an object
204
+ */
205
+ function getHistoryState(location, index) {
206
+ return {
207
+ usr: location.state,
208
+ key: location.key,
209
+ idx: index,
210
+ masked: location.mask ? {
211
+ pathname: location.pathname,
212
+ search: location.search,
213
+ hash: location.hash
214
+ } : void 0
215
+ };
216
+ }
217
+ /**
218
+ * Creates a Location object with a unique key from the given Path
219
+ */
220
+ function createLocation(current, to, state = null, key, mask) {
221
+ return {
222
+ pathname: typeof current === "string" ? current : current.pathname,
223
+ search: "",
224
+ hash: "",
225
+ ...typeof to === "string" ? parsePath(to) : to,
226
+ state,
227
+ key: to && to.key || key || createKey(),
228
+ mask
229
+ };
230
+ }
231
+ /**
232
+ * Creates a string URL path from the given pathname, search, and hash components.
233
+ *
234
+ * @category Utils
235
+ */
236
+ function createPath({ pathname = "/", search = "", hash = "" }) {
237
+ if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search;
238
+ if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
239
+ return pathname;
240
+ }
241
+ /**
242
+ * Parses a string URL path into its separate pathname, search, and hash components.
243
+ *
244
+ * @category Utils
245
+ */
246
+ function parsePath(path) {
247
+ let parsedPath = {};
248
+ if (path) {
249
+ let hashIndex = path.indexOf("#");
250
+ if (hashIndex >= 0) {
251
+ parsedPath.hash = path.substring(hashIndex);
252
+ path = path.substring(0, hashIndex);
253
+ }
254
+ let searchIndex = path.indexOf("?");
255
+ if (searchIndex >= 0) {
256
+ parsedPath.search = path.substring(searchIndex);
257
+ path = path.substring(0, searchIndex);
258
+ }
259
+ if (path) parsedPath.pathname = path;
260
+ }
261
+ return parsedPath;
262
+ }
263
+ function getUrlBasedHistory(getLocation, createHref, validateLocation, options = {}) {
264
+ let { window = document.defaultView, v5Compat = false } = options;
265
+ let globalHistory = window.history;
266
+ let action = "POP";
267
+ let listener = null;
268
+ let index = getIndex();
269
+ if (index == null) {
270
+ index = 0;
271
+ globalHistory.replaceState({
272
+ ...globalHistory.state,
273
+ idx: index
274
+ }, "");
275
+ }
276
+ function getIndex() {
277
+ return (globalHistory.state || { idx: null }).idx;
278
+ }
279
+ function handlePop() {
280
+ action = "POP";
281
+ let nextIndex = getIndex();
282
+ let delta = nextIndex == null ? null : nextIndex - index;
283
+ index = nextIndex;
284
+ if (listener) listener({
285
+ action,
286
+ location: history.location,
287
+ delta
288
+ });
289
+ }
290
+ function push(to, state) {
291
+ action = "PUSH";
292
+ let location = isLocation(to) ? to : createLocation(history.location, to, state);
293
+ if (validateLocation) validateLocation(location, to);
294
+ index = getIndex() + 1;
295
+ let historyState = getHistoryState(location, index);
296
+ let url = history.createHref(location.mask || location);
297
+ try {
298
+ globalHistory.pushState(historyState, "", url);
299
+ } catch (error) {
300
+ if (error instanceof DOMException && error.name === "DataCloneError") throw error;
301
+ window.location.assign(url);
302
+ }
303
+ if (v5Compat && listener) listener({
304
+ action,
305
+ location: history.location,
306
+ delta: 1
307
+ });
308
+ }
309
+ function replace(to, state) {
310
+ action = "REPLACE";
311
+ let location = isLocation(to) ? to : createLocation(history.location, to, state);
312
+ if (validateLocation) validateLocation(location, to);
313
+ index = getIndex();
314
+ let historyState = getHistoryState(location, index);
315
+ let url = history.createHref(location.mask || location);
316
+ globalHistory.replaceState(historyState, "", url);
317
+ if (v5Compat && listener) listener({
318
+ action,
319
+ location: history.location,
320
+ delta: 0
321
+ });
322
+ }
323
+ function createURL(to) {
324
+ return createBrowserURLImpl(window, to);
325
+ }
326
+ let history = {
327
+ get action() {
328
+ return action;
329
+ },
330
+ get location() {
331
+ return getLocation(window, globalHistory);
332
+ },
333
+ listen(fn) {
334
+ if (listener) throw new Error("A history only accepts one active listener");
335
+ window.addEventListener(PopStateEventType, handlePop);
336
+ listener = fn;
337
+ return () => {
338
+ window.removeEventListener(PopStateEventType, handlePop);
339
+ listener = null;
340
+ };
341
+ },
342
+ createHref(to) {
343
+ return createHref(window, to);
344
+ },
345
+ createURL,
346
+ encodeLocation(to) {
347
+ let url = createURL(to);
348
+ return {
349
+ pathname: url.pathname,
350
+ search: url.search,
351
+ hash: url.hash
352
+ };
353
+ },
354
+ push,
355
+ replace,
356
+ go(n) {
357
+ return globalHistory.go(n);
358
+ }
359
+ };
360
+ return history;
361
+ }
362
+ function createBrowserURLImpl(windowImpl, to, isAbsolute = false) {
363
+ let base = "http://localhost";
364
+ if (windowImpl) base = windowImpl.location.origin !== "null" ? windowImpl.location.origin : windowImpl.location.href;
365
+ invariant(base, "No window.location.(origin|href) available to create URL");
366
+ let href = typeof to === "string" ? to : createPath(to);
367
+ href = href.replace(/ $/, "%20");
368
+ if (!isAbsolute && PROTOCOL_RELATIVE_URL_REGEX.test(href)) href = base + href;
369
+ return new URL(href, base);
370
+ }
371
+ //#endregion
372
+ export { Action, createBrowserHistory, createBrowserURLImpl, createHashHistory, createLocation, createMemoryHistory, createPath, invariant, parsePath, warning };