@depup/tanstack__react-router 1.166.4-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/dist/cjs/Asset.cjs +177 -0
  4. package/dist/cjs/Asset.cjs.map +1 -0
  5. package/dist/cjs/Asset.d.cts +5 -0
  6. package/dist/cjs/CatchBoundary.cjs +114 -0
  7. package/dist/cjs/CatchBoundary.cjs.map +1 -0
  8. package/dist/cjs/CatchBoundary.d.cts +12 -0
  9. package/dist/cjs/ClientOnly.cjs +21 -0
  10. package/dist/cjs/ClientOnly.cjs.map +1 -0
  11. package/dist/cjs/ClientOnly.d.cts +49 -0
  12. package/dist/cjs/HeadContent.cjs +15 -0
  13. package/dist/cjs/HeadContent.cjs.map +1 -0
  14. package/dist/cjs/HeadContent.d.cts +6 -0
  15. package/dist/cjs/HeadContent.dev.cjs +41 -0
  16. package/dist/cjs/HeadContent.dev.cjs.map +1 -0
  17. package/dist/cjs/HeadContent.dev.d.cts +10 -0
  18. package/dist/cjs/Match.cjs +255 -0
  19. package/dist/cjs/Match.cjs.map +1 -0
  20. package/dist/cjs/Match.d.cts +14 -0
  21. package/dist/cjs/Matches.cjs +138 -0
  22. package/dist/cjs/Matches.cjs.map +1 -0
  23. package/dist/cjs/Matches.d.cts +68 -0
  24. package/dist/cjs/RouterProvider.cjs +32 -0
  25. package/dist/cjs/RouterProvider.cjs.map +1 -0
  26. package/dist/cjs/RouterProvider.d.cts +23 -0
  27. package/dist/cjs/SafeFragment.cjs +8 -0
  28. package/dist/cjs/SafeFragment.cjs.map +1 -0
  29. package/dist/cjs/SafeFragment.d.cts +1 -0
  30. package/dist/cjs/ScriptOnce.cjs +22 -0
  31. package/dist/cjs/ScriptOnce.cjs.map +1 -0
  32. package/dist/cjs/ScriptOnce.d.cts +6 -0
  33. package/dist/cjs/Scripts.cjs +56 -0
  34. package/dist/cjs/Scripts.cjs.map +1 -0
  35. package/dist/cjs/Scripts.d.cts +5 -0
  36. package/dist/cjs/ScrollRestoration.cjs +38 -0
  37. package/dist/cjs/ScrollRestoration.cjs.map +1 -0
  38. package/dist/cjs/ScrollRestoration.d.cts +14 -0
  39. package/dist/cjs/Transitioner.cjs +119 -0
  40. package/dist/cjs/Transitioner.cjs.map +1 -0
  41. package/dist/cjs/Transitioner.d.cts +1 -0
  42. package/dist/cjs/awaited.cjs +51 -0
  43. package/dist/cjs/awaited.cjs.map +1 -0
  44. package/dist/cjs/awaited.d.cts +14 -0
  45. package/dist/cjs/fileRoute.cjs +109 -0
  46. package/dist/cjs/fileRoute.cjs.map +1 -0
  47. package/dist/cjs/fileRoute.d.cts +87 -0
  48. package/dist/cjs/headContentUtils.cjs +185 -0
  49. package/dist/cjs/headContentUtils.cjs.map +1 -0
  50. package/dist/cjs/headContentUtils.d.cts +7 -0
  51. package/dist/cjs/history.d.cts +8 -0
  52. package/dist/cjs/index.cjs +241 -0
  53. package/dist/cjs/index.cjs.map +1 -0
  54. package/dist/cjs/index.d.cts +51 -0
  55. package/dist/cjs/index.dev.cjs +241 -0
  56. package/dist/cjs/index.dev.cjs.map +1 -0
  57. package/dist/cjs/index.dev.d.cts +2 -0
  58. package/dist/cjs/lazyRouteComponent.cjs +70 -0
  59. package/dist/cjs/lazyRouteComponent.cjs.map +1 -0
  60. package/dist/cjs/lazyRouteComponent.d.cts +11 -0
  61. package/dist/cjs/link.cjs +573 -0
  62. package/dist/cjs/link.cjs.map +1 -0
  63. package/dist/cjs/link.d.cts +98 -0
  64. package/dist/cjs/matchContext.cjs +27 -0
  65. package/dist/cjs/matchContext.cjs.map +1 -0
  66. package/dist/cjs/matchContext.d.cts +3 -0
  67. package/dist/cjs/not-found.cjs +38 -0
  68. package/dist/cjs/not-found.cjs.map +1 -0
  69. package/dist/cjs/not-found.d.cts +9 -0
  70. package/dist/cjs/renderRouteNotFound.cjs +22 -0
  71. package/dist/cjs/renderRouteNotFound.cjs.map +1 -0
  72. package/dist/cjs/renderRouteNotFound.d.cts +10 -0
  73. package/dist/cjs/route.cjs +198 -0
  74. package/dist/cjs/route.cjs.map +1 -0
  75. package/dist/cjs/route.d.cts +142 -0
  76. package/dist/cjs/router.cjs +22 -0
  77. package/dist/cjs/router.cjs.map +1 -0
  78. package/dist/cjs/router.d.cts +83 -0
  79. package/dist/cjs/routerContext.cjs +23 -0
  80. package/dist/cjs/routerContext.cjs.map +1 -0
  81. package/dist/cjs/routerContext.d.cts +3 -0
  82. package/dist/cjs/scroll-restoration.cjs +39 -0
  83. package/dist/cjs/scroll-restoration.cjs.map +1 -0
  84. package/dist/cjs/scroll-restoration.d.cts +1 -0
  85. package/dist/cjs/ssr/RouterClient.cjs +25 -0
  86. package/dist/cjs/ssr/RouterClient.cjs.map +1 -0
  87. package/dist/cjs/ssr/RouterClient.d.cts +4 -0
  88. package/dist/cjs/ssr/RouterServer.cjs +9 -0
  89. package/dist/cjs/ssr/RouterServer.cjs.map +1 -0
  90. package/dist/cjs/ssr/RouterServer.d.cts +4 -0
  91. package/dist/cjs/ssr/client.cjs +12 -0
  92. package/dist/cjs/ssr/client.cjs.map +1 -0
  93. package/dist/cjs/ssr/client.d.cts +2 -0
  94. package/dist/cjs/ssr/defaultRenderHandler.cjs +15 -0
  95. package/dist/cjs/ssr/defaultRenderHandler.cjs.map +1 -0
  96. package/dist/cjs/ssr/defaultRenderHandler.d.cts +1 -0
  97. package/dist/cjs/ssr/defaultStreamHandler.cjs +16 -0
  98. package/dist/cjs/ssr/defaultStreamHandler.cjs.map +1 -0
  99. package/dist/cjs/ssr/defaultStreamHandler.d.cts +1 -0
  100. package/dist/cjs/ssr/renderRouterToStream.cjs +73 -0
  101. package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -0
  102. package/dist/cjs/ssr/renderRouterToStream.d.cts +8 -0
  103. package/dist/cjs/ssr/renderRouterToString.cjs +31 -0
  104. package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -0
  105. package/dist/cjs/ssr/renderRouterToString.d.cts +7 -0
  106. package/dist/cjs/ssr/serializer.d.cts +6 -0
  107. package/dist/cjs/ssr/server.cjs +20 -0
  108. package/dist/cjs/ssr/server.cjs.map +1 -0
  109. package/dist/cjs/ssr/server.d.cts +6 -0
  110. package/dist/cjs/structuralSharing.d.cts +8 -0
  111. package/dist/cjs/typePrimitives.d.cts +16 -0
  112. package/dist/cjs/useBlocker.cjs +171 -0
  113. package/dist/cjs/useBlocker.cjs.map +1 -0
  114. package/dist/cjs/useBlocker.d.cts +66 -0
  115. package/dist/cjs/useCanGoBack.cjs +8 -0
  116. package/dist/cjs/useCanGoBack.cjs.map +1 -0
  117. package/dist/cjs/useCanGoBack.d.cts +1 -0
  118. package/dist/cjs/useLoaderData.cjs +15 -0
  119. package/dist/cjs/useLoaderData.cjs.map +1 -0
  120. package/dist/cjs/useLoaderData.d.cts +19 -0
  121. package/dist/cjs/useLoaderDeps.cjs +14 -0
  122. package/dist/cjs/useLoaderDeps.cjs.map +1 -0
  123. package/dist/cjs/useLoaderDeps.d.cts +19 -0
  124. package/dist/cjs/useLocation.cjs +10 -0
  125. package/dist/cjs/useLocation.cjs.map +1 -0
  126. package/dist/cjs/useLocation.d.cts +18 -0
  127. package/dist/cjs/useMatch.cjs +47 -0
  128. package/dist/cjs/useMatch.cjs.map +1 -0
  129. package/dist/cjs/useMatch.d.cts +14 -0
  130. package/dist/cjs/useNavigate.cjs +49 -0
  131. package/dist/cjs/useNavigate.cjs.map +1 -0
  132. package/dist/cjs/useNavigate.d.cts +28 -0
  133. package/dist/cjs/useParams.cjs +17 -0
  134. package/dist/cjs/useParams.cjs.map +1 -0
  135. package/dist/cjs/useParams.d.cts +21 -0
  136. package/dist/cjs/useRouteContext.cjs +11 -0
  137. package/dist/cjs/useRouteContext.cjs.map +1 -0
  138. package/dist/cjs/useRouteContext.d.cts +3 -0
  139. package/dist/cjs/useRouter.cjs +32 -0
  140. package/dist/cjs/useRouter.cjs.map +1 -0
  141. package/dist/cjs/useRouter.d.cts +14 -0
  142. package/dist/cjs/useRouterState.cjs +38 -0
  143. package/dist/cjs/useRouterState.cjs.map +1 -0
  144. package/dist/cjs/useRouterState.d.cts +20 -0
  145. package/dist/cjs/useSearch.cjs +16 -0
  146. package/dist/cjs/useSearch.cjs.map +1 -0
  147. package/dist/cjs/useSearch.d.cts +21 -0
  148. package/dist/cjs/utils.cjs +62 -0
  149. package/dist/cjs/utils.cjs.map +1 -0
  150. package/dist/cjs/utils.d.cts +54 -0
  151. package/dist/esm/Asset.d.ts +5 -0
  152. package/dist/esm/Asset.js +160 -0
  153. package/dist/esm/Asset.js.map +1 -0
  154. package/dist/esm/CatchBoundary.d.ts +12 -0
  155. package/dist/esm/CatchBoundary.js +97 -0
  156. package/dist/esm/CatchBoundary.js.map +1 -0
  157. package/dist/esm/ClientOnly.d.ts +49 -0
  158. package/dist/esm/ClientOnly.js +21 -0
  159. package/dist/esm/ClientOnly.js.map +1 -0
  160. package/dist/esm/HeadContent.d.ts +6 -0
  161. package/dist/esm/HeadContent.dev.d.ts +10 -0
  162. package/dist/esm/HeadContent.dev.js +25 -0
  163. package/dist/esm/HeadContent.dev.js.map +1 -0
  164. package/dist/esm/HeadContent.js +15 -0
  165. package/dist/esm/HeadContent.js.map +1 -0
  166. package/dist/esm/Match.d.ts +14 -0
  167. package/dist/esm/Match.js +238 -0
  168. package/dist/esm/Match.js.map +1 -0
  169. package/dist/esm/Matches.d.ts +68 -0
  170. package/dist/esm/Matches.js +121 -0
  171. package/dist/esm/Matches.js.map +1 -0
  172. package/dist/esm/RouterProvider.d.ts +23 -0
  173. package/dist/esm/RouterProvider.js +32 -0
  174. package/dist/esm/RouterProvider.js.map +1 -0
  175. package/dist/esm/SafeFragment.d.ts +1 -0
  176. package/dist/esm/SafeFragment.js +8 -0
  177. package/dist/esm/SafeFragment.js.map +1 -0
  178. package/dist/esm/ScriptOnce.d.ts +6 -0
  179. package/dist/esm/ScriptOnce.js +22 -0
  180. package/dist/esm/ScriptOnce.js.map +1 -0
  181. package/dist/esm/Scripts.d.ts +5 -0
  182. package/dist/esm/Scripts.js +56 -0
  183. package/dist/esm/Scripts.js.map +1 -0
  184. package/dist/esm/ScrollRestoration.d.ts +14 -0
  185. package/dist/esm/ScrollRestoration.js +38 -0
  186. package/dist/esm/ScrollRestoration.js.map +1 -0
  187. package/dist/esm/Transitioner.d.ts +1 -0
  188. package/dist/esm/Transitioner.js +102 -0
  189. package/dist/esm/Transitioner.js.map +1 -0
  190. package/dist/esm/awaited.d.ts +14 -0
  191. package/dist/esm/awaited.js +34 -0
  192. package/dist/esm/awaited.js.map +1 -0
  193. package/dist/esm/fileRoute.d.ts +87 -0
  194. package/dist/esm/fileRoute.js +109 -0
  195. package/dist/esm/fileRoute.js.map +1 -0
  196. package/dist/esm/headContentUtils.d.ts +7 -0
  197. package/dist/esm/headContentUtils.js +168 -0
  198. package/dist/esm/headContentUtils.js.map +1 -0
  199. package/dist/esm/history.d.ts +8 -0
  200. package/dist/esm/index.d.ts +51 -0
  201. package/dist/esm/index.dev.d.ts +2 -0
  202. package/dist/esm/index.dev.js +133 -0
  203. package/dist/esm/index.dev.js.map +1 -0
  204. package/dist/esm/index.js +133 -0
  205. package/dist/esm/index.js.map +1 -0
  206. package/dist/esm/lazyRouteComponent.d.ts +11 -0
  207. package/dist/esm/lazyRouteComponent.js +53 -0
  208. package/dist/esm/lazyRouteComponent.js.map +1 -0
  209. package/dist/esm/link.d.ts +98 -0
  210. package/dist/esm/link.js +556 -0
  211. package/dist/esm/link.js.map +1 -0
  212. package/dist/esm/matchContext.d.ts +3 -0
  213. package/dist/esm/matchContext.js +10 -0
  214. package/dist/esm/matchContext.js.map +1 -0
  215. package/dist/esm/not-found.d.ts +9 -0
  216. package/dist/esm/not-found.js +38 -0
  217. package/dist/esm/not-found.js.map +1 -0
  218. package/dist/esm/renderRouteNotFound.d.ts +10 -0
  219. package/dist/esm/renderRouteNotFound.js +22 -0
  220. package/dist/esm/renderRouteNotFound.js.map +1 -0
  221. package/dist/esm/route.d.ts +142 -0
  222. package/dist/esm/route.js +198 -0
  223. package/dist/esm/route.js.map +1 -0
  224. package/dist/esm/router.d.ts +83 -0
  225. package/dist/esm/router.js +22 -0
  226. package/dist/esm/router.js.map +1 -0
  227. package/dist/esm/routerContext.d.ts +3 -0
  228. package/dist/esm/routerContext.js +6 -0
  229. package/dist/esm/routerContext.js.map +1 -0
  230. package/dist/esm/scroll-restoration.d.ts +1 -0
  231. package/dist/esm/scroll-restoration.js +39 -0
  232. package/dist/esm/scroll-restoration.js.map +1 -0
  233. package/dist/esm/ssr/RouterClient.d.ts +4 -0
  234. package/dist/esm/ssr/RouterClient.js +25 -0
  235. package/dist/esm/ssr/RouterClient.js.map +1 -0
  236. package/dist/esm/ssr/RouterServer.d.ts +4 -0
  237. package/dist/esm/ssr/RouterServer.js +9 -0
  238. package/dist/esm/ssr/RouterServer.js.map +1 -0
  239. package/dist/esm/ssr/client.d.ts +2 -0
  240. package/dist/esm/ssr/client.js +6 -0
  241. package/dist/esm/ssr/client.js.map +1 -0
  242. package/dist/esm/ssr/defaultRenderHandler.d.ts +1 -0
  243. package/dist/esm/ssr/defaultRenderHandler.js +15 -0
  244. package/dist/esm/ssr/defaultRenderHandler.js.map +1 -0
  245. package/dist/esm/ssr/defaultStreamHandler.d.ts +1 -0
  246. package/dist/esm/ssr/defaultStreamHandler.js +16 -0
  247. package/dist/esm/ssr/defaultStreamHandler.js.map +1 -0
  248. package/dist/esm/ssr/renderRouterToStream.d.ts +8 -0
  249. package/dist/esm/ssr/renderRouterToStream.js +73 -0
  250. package/dist/esm/ssr/renderRouterToStream.js.map +1 -0
  251. package/dist/esm/ssr/renderRouterToString.d.ts +7 -0
  252. package/dist/esm/ssr/renderRouterToString.js +31 -0
  253. package/dist/esm/ssr/renderRouterToString.js.map +1 -0
  254. package/dist/esm/ssr/serializer.d.ts +6 -0
  255. package/dist/esm/ssr/server.d.ts +6 -0
  256. package/dist/esm/ssr/server.js +14 -0
  257. package/dist/esm/ssr/server.js.map +1 -0
  258. package/dist/esm/structuralSharing.d.ts +8 -0
  259. package/dist/esm/typePrimitives.d.ts +16 -0
  260. package/dist/esm/useBlocker.d.ts +66 -0
  261. package/dist/esm/useBlocker.js +154 -0
  262. package/dist/esm/useBlocker.js.map +1 -0
  263. package/dist/esm/useCanGoBack.d.ts +1 -0
  264. package/dist/esm/useCanGoBack.js +8 -0
  265. package/dist/esm/useCanGoBack.js.map +1 -0
  266. package/dist/esm/useLoaderData.d.ts +19 -0
  267. package/dist/esm/useLoaderData.js +15 -0
  268. package/dist/esm/useLoaderData.js.map +1 -0
  269. package/dist/esm/useLoaderDeps.d.ts +19 -0
  270. package/dist/esm/useLoaderDeps.js +14 -0
  271. package/dist/esm/useLoaderDeps.js.map +1 -0
  272. package/dist/esm/useLocation.d.ts +18 -0
  273. package/dist/esm/useLocation.js +10 -0
  274. package/dist/esm/useLocation.js.map +1 -0
  275. package/dist/esm/useMatch.d.ts +14 -0
  276. package/dist/esm/useMatch.js +30 -0
  277. package/dist/esm/useMatch.js.map +1 -0
  278. package/dist/esm/useNavigate.d.ts +28 -0
  279. package/dist/esm/useNavigate.js +32 -0
  280. package/dist/esm/useNavigate.js.map +1 -0
  281. package/dist/esm/useParams.d.ts +21 -0
  282. package/dist/esm/useParams.js +17 -0
  283. package/dist/esm/useParams.js.map +1 -0
  284. package/dist/esm/useRouteContext.d.ts +3 -0
  285. package/dist/esm/useRouteContext.js +11 -0
  286. package/dist/esm/useRouteContext.js.map +1 -0
  287. package/dist/esm/useRouter.d.ts +14 -0
  288. package/dist/esm/useRouter.js +15 -0
  289. package/dist/esm/useRouter.js.map +1 -0
  290. package/dist/esm/useRouterState.d.ts +20 -0
  291. package/dist/esm/useRouterState.js +38 -0
  292. package/dist/esm/useRouterState.js.map +1 -0
  293. package/dist/esm/useSearch.d.ts +21 -0
  294. package/dist/esm/useSearch.js +16 -0
  295. package/dist/esm/useSearch.js.map +1 -0
  296. package/dist/esm/utils.d.ts +54 -0
  297. package/dist/esm/utils.js +45 -0
  298. package/dist/esm/utils.js.map +1 -0
  299. package/dist/llms/index.d.ts +3 -0
  300. package/dist/llms/index.js +43 -0
  301. package/dist/llms/rules/api.d.ts +2 -0
  302. package/dist/llms/rules/api.js +4612 -0
  303. package/dist/llms/rules/guide.d.ts +2 -0
  304. package/dist/llms/rules/guide.js +10690 -0
  305. package/dist/llms/rules/installation.d.ts +2 -0
  306. package/dist/llms/rules/installation.js +1285 -0
  307. package/dist/llms/rules/routing.d.ts +2 -0
  308. package/dist/llms/rules/routing.js +1984 -0
  309. package/dist/llms/rules/setup-and-architecture.d.ts +2 -0
  310. package/dist/llms/rules/setup-and-architecture.js +920 -0
  311. package/package.json +142 -0
  312. package/src/Asset.tsx +219 -0
  313. package/src/CatchBoundary.tsx +120 -0
  314. package/src/ClientOnly.tsx +68 -0
  315. package/src/HeadContent.dev.tsx +46 -0
  316. package/src/HeadContent.tsx +22 -0
  317. package/src/Match.tsx +360 -0
  318. package/src/Matches.tsx +313 -0
  319. package/src/RouterProvider.tsx +92 -0
  320. package/src/SafeFragment.tsx +5 -0
  321. package/src/ScriptOnce.tsx +21 -0
  322. package/src/Scripts.tsx +80 -0
  323. package/src/ScrollRestoration.tsx +69 -0
  324. package/src/Transitioner.tsx +134 -0
  325. package/src/awaited.tsx +55 -0
  326. package/src/fileRoute.ts +313 -0
  327. package/src/headContentUtils.tsx +217 -0
  328. package/src/history.ts +9 -0
  329. package/src/index.dev.tsx +6 -0
  330. package/src/index.tsx +341 -0
  331. package/src/lazyRouteComponent.tsx +96 -0
  332. package/src/link.tsx +984 -0
  333. package/src/matchContext.tsx +8 -0
  334. package/src/not-found.tsx +43 -0
  335. package/src/renderRouteNotFound.tsx +35 -0
  336. package/src/route.tsx +740 -0
  337. package/src/router.ts +127 -0
  338. package/src/routerContext.tsx +4 -0
  339. package/src/scroll-restoration.tsx +45 -0
  340. package/src/ssr/RouterClient.tsx +22 -0
  341. package/src/ssr/RouterServer.tsx +9 -0
  342. package/src/ssr/client.ts +2 -0
  343. package/src/ssr/defaultRenderHandler.tsx +12 -0
  344. package/src/ssr/defaultStreamHandler.tsx +13 -0
  345. package/src/ssr/renderRouterToStream.tsx +90 -0
  346. package/src/ssr/renderRouterToString.tsx +36 -0
  347. package/src/ssr/serializer.ts +7 -0
  348. package/src/ssr/server.ts +6 -0
  349. package/src/structuralSharing.ts +47 -0
  350. package/src/typePrimitives.ts +84 -0
  351. package/src/useBlocker.tsx +320 -0
  352. package/src/useCanGoBack.ts +5 -0
  353. package/src/useLoaderData.tsx +91 -0
  354. package/src/useLoaderDeps.tsx +69 -0
  355. package/src/useLocation.tsx +52 -0
  356. package/src/useMatch.tsx +123 -0
  357. package/src/useNavigate.tsx +78 -0
  358. package/src/useParams.tsx +107 -0
  359. package/src/useRouteContext.ts +30 -0
  360. package/src/useRouter.tsx +25 -0
  361. package/src/useRouterState.tsx +86 -0
  362. package/src/useSearch.tsx +105 -0
  363. package/src/utils.ts +125 -0
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const useMatch = require("./useMatch.cjs");
4
+ function useRouteContext(opts) {
5
+ return useMatch.useMatch({
6
+ ...opts,
7
+ select: (match) => opts.select ? opts.select(match.context) : match.context
8
+ });
9
+ }
10
+ exports.useRouteContext = useRouteContext;
11
+ //# sourceMappingURL=useRouteContext.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRouteContext.cjs","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type {\n AnyRouter,\n RegisteredRouter,\n UseRouteContextBaseOptions,\n UseRouteContextOptions,\n UseRouteContextResult,\n} from '@tanstack/router-core'\n\nexport type UseRouteContextRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>,\n) => UseRouteContextResult<TRouter, TFrom, true, TSelected>\n\nexport function useRouteContext<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TSelected = unknown,\n>(\n opts: UseRouteContextOptions<TRouter, TFrom, TStrict, TSelected>,\n): UseRouteContextResult<TRouter, TFrom, TStrict, TSelected> {\n return useMatch({\n ...(opts as any),\n select: (match) =>\n opts.select ? opts.select(match.context) : match.context,\n }) as UseRouteContextResult<TRouter, TFrom, TStrict, TSelected>\n}\n"],"names":["useMatch"],"mappings":";;;AAgBO,SAAS,gBAMd,MAC2D;AAC3D,SAAOA,kBAAS;AAAA,IACd,GAAI;AAAA,IACJ,QAAQ,CAAC,UACP,KAAK,SAAS,KAAK,OAAO,MAAM,OAAO,IAAI,MAAM;AAAA,EAAA,CACpD;AACH;;"}
@@ -0,0 +1,3 @@
1
+ import { AnyRouter, RegisteredRouter, UseRouteContextBaseOptions, UseRouteContextOptions, UseRouteContextResult } from '@tanstack/router-core';
2
+ export type UseRouteContextRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: UseRouteContextBaseOptions<TRouter, TFrom, true, TSelected>) => UseRouteContextResult<TRouter, TFrom, true, TSelected>;
3
+ export declare function useRouteContext<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TSelected = unknown>(opts: UseRouteContextOptions<TRouter, TFrom, TStrict, TSelected>): UseRouteContextResult<TRouter, TFrom, TStrict, TSelected>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ const warning = require("tiny-warning");
5
+ const routerContext = require("./routerContext.cjs");
6
+ function _interopNamespaceDefault(e) {
7
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
+ if (e) {
9
+ for (const k in e) {
10
+ if (k !== "default") {
11
+ const d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: () => e[k]
15
+ });
16
+ }
17
+ }
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
23
+ function useRouter(opts) {
24
+ const value = React__namespace.useContext(routerContext.routerContext);
25
+ warning(
26
+ !((opts?.warn ?? true) && !value),
27
+ "useRouter must be used inside a <RouterProvider> component!"
28
+ );
29
+ return value;
30
+ }
31
+ exports.useRouter = useRouter;
32
+ //# sourceMappingURL=useRouter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRouter.cjs","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(routerContext)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":["React","routerContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeO,SAAS,UAAwD,MAE5D;AACV,QAAM,QAAQA,iBAAM,WAAWC,2BAAa;AAC5C;AAAA,IACE,GAAG,MAAM,QAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEF,SAAO;AACT;;"}
@@ -0,0 +1,14 @@
1
+ import { AnyRouter, RegisteredRouter } from '@tanstack/router-core';
2
+ /**
3
+ * Access the current TanStack Router instance from React context.
4
+ * Must be used within a `RouterProvider`.
5
+ *
6
+ * Options:
7
+ * - `warn`: Log a warning if no router context is found (default: true).
8
+ *
9
+ * @returns The registered router instance.
10
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
11
+ */
12
+ export declare function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
13
+ warn?: boolean;
14
+ }): TRouter;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const reactStore = require("@tanstack/react-store");
4
+ const React = require("react");
5
+ const routerCore = require("@tanstack/router-core");
6
+ const isServer = require("@tanstack/router-core/isServer");
7
+ const useRouter = require("./useRouter.cjs");
8
+ function useRouterState(opts) {
9
+ const contextRouter = useRouter.useRouter({
10
+ warn: opts?.router === void 0
11
+ });
12
+ const router = opts?.router || contextRouter;
13
+ const _isServer = isServer.isServer ?? router.isServer;
14
+ if (_isServer) {
15
+ const state = router.state;
16
+ return opts?.select ? opts.select(state) : state;
17
+ }
18
+ const previousResult = (
19
+ // eslint-disable-next-line react-hooks/rules-of-hooks
20
+ React.useRef(void 0)
21
+ );
22
+ return reactStore.useStore(router.__store, (state) => {
23
+ if (opts?.select) {
24
+ if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {
25
+ const newSlice = routerCore.replaceEqualDeep(
26
+ previousResult.current,
27
+ opts.select(state)
28
+ );
29
+ previousResult.current = newSlice;
30
+ return newSlice;
31
+ }
32
+ return opts.select(state);
33
+ }
34
+ return state;
35
+ });
36
+ }
37
+ exports.useRouterState = useRouterState;
38
+ //# sourceMappingURL=useRouterState.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRouterState.cjs","sources":["../../src/useRouterState.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { useRef } from 'react'\nimport { replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\n\nexport type UseRouterStateOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> = {\n router?: TRouter\n select?: (\n state: RouterState<TRouter['routeTree']>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n} & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseRouterStateResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected\n\n/**\n * Subscribe to the router's state store with optional selection and\n * structural sharing for render optimization.\n *\n * Options:\n * - `select`: Project the full router state to a derived slice\n * - `structuralSharing`: Replace-equal semantics for stable references\n * - `router`: Read state from a specific router instance instead of context\n *\n * @returns The selected router state (or the full state by default).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook\n */\nexport function useRouterState<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,\n): UseRouterStateResult<TRouter, TSelected> {\n const contextRouter = useRouter<TRouter>({\n warn: opts?.router === undefined,\n })\n const router = opts?.router || contextRouter\n\n // During SSR we render exactly once and do not need reactivity.\n // Avoid subscribing to the store (and any structural sharing work) on the server.\n const _isServer = isServer ?? router.isServer\n if (_isServer) {\n const state = router.state as RouterState<TRouter['routeTree']>\n return (opts?.select ? opts.select(state) : state) as UseRouterStateResult<\n TRouter,\n TSelected\n >\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.__store, (state) => {\n if (opts?.select) {\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const newSlice = replaceEqualDeep(\n previousResult.current,\n opts.select(state),\n )\n previousResult.current = newSlice\n return newSlice\n }\n return opts.select(state)\n }\n return state\n }) as UseRouterStateResult<TRouter, TSelected>\n}\n"],"names":["useRouter","isServer","useRef","useStore","replaceEqualDeep"],"mappings":";;;;;;;AA2CO,SAAS,eAKd,MAC0C;AAC1C,QAAM,gBAAgBA,UAAAA,UAAmB;AAAA,IACvC,MAAM,MAAM,WAAW;AAAA,EAAA,CACxB;AACD,QAAM,SAAS,MAAM,UAAU;AAI/B,QAAM,YAAYC,qBAAY,OAAO;AACrC,MAAI,WAAW;AACb,UAAM,QAAQ,OAAO;AACrB,WAAQ,MAAM,SAAS,KAAK,OAAO,KAAK,IAAI;AAAA,EAI9C;AAEA,QAAM;AAAA;AAAA,IAEJC,MAAAA,OAAiE,MAAS;AAAA;AAG5E,SAAOC,oBAAS,OAAO,SAAS,CAAC,UAAU;AACzC,QAAI,MAAM,QAAQ;AAChB,UAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;AACrE,cAAM,WAAWC,WAAAA;AAAAA,UACf,eAAe;AAAA,UACf,KAAK,OAAO,KAAK;AAAA,QAAA;AAEnB,uBAAe,UAAU;AACzB,eAAO;AAAA,MACT;AACA,aAAO,KAAK,OAAO,KAAK;AAAA,IAC1B;AACA,WAAO;AAAA,EACT,CAAC;AACH;;"}
@@ -0,0 +1,20 @@
1
+ import { AnyRouter, RegisteredRouter, RouterState } from '@tanstack/router-core';
2
+ import { StructuralSharingOption, ValidateSelected } from './structuralSharing.cjs';
3
+ export type UseRouterStateOptions<TRouter extends AnyRouter, TSelected, TStructuralSharing> = {
4
+ router?: TRouter;
5
+ select?: (state: RouterState<TRouter['routeTree']>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
6
+ } & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
7
+ export type UseRouterStateResult<TRouter extends AnyRouter, TSelected> = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected;
8
+ /**
9
+ * Subscribe to the router's state store with optional selection and
10
+ * structural sharing for render optimization.
11
+ *
12
+ * Options:
13
+ * - `select`: Project the full router state to a derived slice
14
+ * - `structuralSharing`: Replace-equal semantics for stable references
15
+ * - `router`: Read state from a specific router instance instead of context
16
+ *
17
+ * @returns The selected router state (or the full state by default).
18
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
19
+ */
20
+ export declare function useRouterState<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>): UseRouterStateResult<TRouter, TSelected>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const useMatch = require("./useMatch.cjs");
4
+ function useSearch(opts) {
5
+ return useMatch.useMatch({
6
+ from: opts.from,
7
+ strict: opts.strict,
8
+ shouldThrow: opts.shouldThrow,
9
+ structuralSharing: opts.structuralSharing,
10
+ select: (match) => {
11
+ return opts.select ? opts.select(match.search) : match.search;
12
+ }
13
+ });
14
+ }
15
+ exports.useSearch = useSearch;
16
+ //# sourceMappingURL=useSearch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSearch.cjs","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n RegisteredRouter,\n ResolveUseSearch,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n UseSearchResult,\n} from '@tanstack/router-core'\n\nexport interface UseSearchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n state: ResolveUseSearch<TRouter, TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseSearchOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseSearchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseSearchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseSearchBaseOptions<\n TRouter,\n TFrom,\n /* TStrict */ true,\n /* TThrow */ true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseSearchResult<TRouter, TFrom, true, TSelected>\n\n/**\n * Read and select the current route's search parameters with type-safety.\n *\n * Options:\n * - `from`/`strict`: Control which route's search is read and how strictly it's typed\n * - `select`: Map the search object to a derived value for render optimization\n * - `structuralSharing`: Enable structural sharing for stable references\n * - `shouldThrow`: Throw when the route is not found (strict contexts)\n *\n * @returns The search object (or selected value) for the matched route.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook\n */\nexport function useSearch<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string | undefined = undefined,\n TStrict extends boolean = true,\n TThrow extends boolean = true,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts: UseSearchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<\n UseSearchResult<TRouter, TFrom, TStrict, TSelected>,\n TThrow\n> {\n return useMatch({\n from: opts.from!,\n strict: opts.strict,\n shouldThrow: opts.shouldThrow,\n structuralSharing: opts.structuralSharing,\n select: (match: any) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n }) as any\n}\n"],"names":["useMatch"],"mappings":";;;AA2EO,SAAS,UAQd,MAWA;AACA,SAAOA,kBAAS;AAAA,IACd,MAAM,KAAK;AAAA,IACX,QAAQ,KAAK;AAAA,IACb,aAAa,KAAK;AAAA,IAClB,mBAAmB,KAAK;AAAA,IACxB,QAAQ,CAAC,UAAe;AACtB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IACzD;AAAA,EAAA,CACD;AACH;;"}
@@ -0,0 +1,21 @@
1
+ import { StructuralSharingOption, ValidateSelected } from './structuralSharing.cjs';
2
+ import { AnyRouter, RegisteredRouter, ResolveUseSearch, StrictOrFrom, ThrowConstraint, ThrowOrOptional, UseSearchResult } from '@tanstack/router-core';
3
+ export interface UseSearchBaseOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> {
4
+ select?: (state: ResolveUseSearch<TRouter, TFrom, TStrict>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
5
+ shouldThrow?: TThrow;
6
+ }
7
+ export type UseSearchOptions<TRouter extends AnyRouter, TFrom, TStrict extends boolean, TThrow extends boolean, TSelected, TStructuralSharing> = StrictOrFrom<TRouter, TFrom, TStrict> & UseSearchBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
8
+ export type UseSearchRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseSearchBaseOptions<TRouter, TFrom, true, true, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>) => UseSearchResult<TRouter, TFrom, true, TSelected>;
9
+ /**
10
+ * Read and select the current route's search parameters with type-safety.
11
+ *
12
+ * Options:
13
+ * - `from`/`strict`: Control which route's search is read and how strictly it's typed
14
+ * - `select`: Map the search object to a derived value for render optimization
15
+ * - `structuralSharing`: Enable structural sharing for stable references
16
+ * - `shouldThrow`: Throw when the route is not found (strict contexts)
17
+ *
18
+ * @returns The search object (or selected value) for the matched route.
19
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
20
+ */
21
+ export declare function useSearch<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string | undefined = undefined, TStrict extends boolean = true, TThrow extends boolean = true, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts: UseSearchOptions<TRouter, TFrom, TStrict, ThrowConstraint<TStrict, TThrow>, TSelected, TStructuralSharing>): ThrowOrOptional<UseSearchResult<TRouter, TFrom, TStrict, TSelected>, TThrow>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const React = require("react");
4
+ function _interopNamespaceDefault(e) {
5
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
6
+ if (e) {
7
+ for (const k in e) {
8
+ if (k !== "default") {
9
+ const d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: () => e[k]
13
+ });
14
+ }
15
+ }
16
+ }
17
+ n.default = e;
18
+ return Object.freeze(n);
19
+ }
20
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
21
+ const REACT_USE = "use";
22
+ const reactUse = React__namespace[REACT_USE];
23
+ const useLayoutEffect = typeof window !== "undefined" ? React__namespace.useLayoutEffect : React__namespace.useEffect;
24
+ function usePrevious(value) {
25
+ const ref = React__namespace.useRef({
26
+ value,
27
+ prev: null
28
+ });
29
+ const current = ref.current.value;
30
+ if (value !== current) {
31
+ ref.current = {
32
+ value,
33
+ prev: current
34
+ };
35
+ }
36
+ return ref.current.prev;
37
+ }
38
+ function useIntersectionObserver(ref, callback, intersectionObserverOptions = {}, options = {}) {
39
+ React__namespace.useEffect(() => {
40
+ if (!ref.current || options.disabled || typeof IntersectionObserver !== "function") {
41
+ return;
42
+ }
43
+ const observer = new IntersectionObserver(([entry]) => {
44
+ callback(entry);
45
+ }, intersectionObserverOptions);
46
+ observer.observe(ref.current);
47
+ return () => {
48
+ observer.disconnect();
49
+ };
50
+ }, [callback, intersectionObserverOptions, options.disabled, ref]);
51
+ }
52
+ function useForwardedRef(ref) {
53
+ const innerRef = React__namespace.useRef(null);
54
+ React__namespace.useImperativeHandle(ref, () => innerRef.current, []);
55
+ return innerRef;
56
+ }
57
+ exports.reactUse = reactUse;
58
+ exports.useForwardedRef = useForwardedRef;
59
+ exports.useIntersectionObserver = useIntersectionObserver;
60
+ exports.useLayoutEffect = useLayoutEffect;
61
+ exports.usePrevious = usePrevious;
62
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\n\n// Safe version of React.use() that will not cause compilation errors against\n// React 18 with Webpack, which statically analyzes imports and fails when it\n// sees React.use referenced (since 'use' is not exported from React 18).\n// This uses a dynamic string lookup to avoid the static analysis.\nconst REACT_USE = 'use'\n\n/**\n * React.use if available (React 19+), undefined otherwise.\n * Use dynamic lookup to avoid Webpack compilation errors with React 18.\n */\nexport const reactUse:\n | (<T>(usable: Promise<T> | React.Context<T>) => T)\n | undefined = (React as any)[REACT_USE]\n\nexport function useStableCallback<T extends (...args: Array<any>) => any>(\n fn: T,\n): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: Array<any>) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\n/**\n * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3\n */\nexport function usePrevious<T>(value: T): T | null {\n // initialise the ref with previous and current values\n const ref = React.useRef<{ value: T; prev: T | null }>({\n value: value,\n prev: null,\n })\n\n const current = ref.current.value\n\n // if the value passed into hook doesn't match what we store as \"current\"\n // move the \"current\" to the \"previous\"\n // and store the passed value as \"current\"\n if (value !== current) {\n ref.current = {\n value: value,\n prev: current,\n }\n }\n\n // return the previous value only\n return ref.current.prev\n}\n\n/**\n * React hook to wrap `IntersectionObserver`.\n *\n * This hook will create an `IntersectionObserver` and observe the ref passed to it.\n *\n * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.\n *\n * @param ref - The ref to observe\n * @param intersectionObserverOptions - The options to pass to the IntersectionObserver\n * @param options - The options to pass to the hook\n * @param callback - The callback to call when the intersection changes\n * @returns The IntersectionObserver instance\n * @example\n * ```tsx\n * const MyComponent = () => {\n * const ref = React.useRef<HTMLDivElement>(null)\n * useIntersectionObserver(\n * ref,\n * (entry) => { doSomething(entry) },\n * { rootMargin: '10px' },\n * { disabled: false }\n * )\n * return <div ref={ref} />\n * ```\n */\nexport function useIntersectionObserver<T extends Element>(\n ref: React.RefObject<T | null>,\n callback: (entry: IntersectionObserverEntry | undefined) => void,\n intersectionObserverOptions: IntersectionObserverInit = {},\n options: { disabled?: boolean } = {},\n) {\n React.useEffect(() => {\n if (\n !ref.current ||\n options.disabled ||\n typeof IntersectionObserver !== 'function'\n ) {\n return\n }\n\n const observer = new IntersectionObserver(([entry]) => {\n callback(entry)\n }, intersectionObserverOptions)\n\n observer.observe(ref.current)\n\n return () => {\n observer.disconnect()\n }\n }, [callback, intersectionObserverOptions, options.disabled, ref])\n}\n\n/**\n * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.\n *\n * @param ref - The forwarded ref\n * @returns The inner ref returned by `useRef`\n * @example\n * ```tsx\n * const MyComponent = React.forwardRef((props, ref) => {\n * const innerRef = useForwardedRef(ref)\n * return <div ref={innerRef} />\n * })\n * ```\n */\nexport function useForwardedRef<T>(ref?: React.ForwardedRef<T>) {\n const innerRef = React.useRef<T>(null)\n React.useImperativeHandle(ref, () => innerRef.current!, [])\n return innerRef\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,MAAM,YAAY;AAMX,MAAM,WAEIA,iBAAc,SAAS;AAYjC,MAAM,kBACX,OAAO,WAAW,cAAcA,iBAAM,kBAAkBA,iBAAM;AAKzD,SAAS,YAAe,OAAoB;AAEjD,QAAM,MAAMA,iBAAM,OAAqC;AAAA,IACrD;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,QAAM,UAAU,IAAI,QAAQ;AAK5B,MAAI,UAAU,SAAS;AACrB,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,MAAM;AAAA,IAAA;AAAA,EAEV;AAGA,SAAO,IAAI,QAAQ;AACrB;AA2BO,SAAS,wBACd,KACA,UACA,8BAAwD,CAAA,GACxD,UAAkC,IAClC;AACAA,mBAAM,UAAU,MAAM;AACpB,QACE,CAAC,IAAI,WACL,QAAQ,YACR,OAAO,yBAAyB,YAChC;AACA;AAAA,IACF;AAEA,UAAM,WAAW,IAAI,qBAAqB,CAAC,CAAC,KAAK,MAAM;AACrD,eAAS,KAAK;AAAA,IAChB,GAAG,2BAA2B;AAE9B,aAAS,QAAQ,IAAI,OAAO;AAE5B,WAAO,MAAM;AACX,eAAS,WAAA;AAAA,IACX;AAAA,EACF,GAAG,CAAC,UAAU,6BAA6B,QAAQ,UAAU,GAAG,CAAC;AACnE;AAeO,SAAS,gBAAmB,KAA6B;AAC9D,QAAM,WAAWA,iBAAM,OAAU,IAAI;AACrCA,mBAAM,oBAAoB,KAAK,MAAM,SAAS,SAAU,CAAA,CAAE;AAC1D,SAAO;AACT;;;;;;"}
@@ -0,0 +1,54 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * React.use if available (React 19+), undefined otherwise.
4
+ * Use dynamic lookup to avoid Webpack compilation errors with React 18.
5
+ */
6
+ export declare const reactUse: (<T>(usable: Promise<T> | React.Context<T>) => T) | undefined;
7
+ export declare function useStableCallback<T extends (...args: Array<any>) => any>(fn: T): T;
8
+ export declare const useLayoutEffect: typeof React.useLayoutEffect;
9
+ /**
10
+ * Taken from https://www.developerway.com/posts/implementing-advanced-use-previous-hook#part3
11
+ */
12
+ export declare function usePrevious<T>(value: T): T | null;
13
+ /**
14
+ * React hook to wrap `IntersectionObserver`.
15
+ *
16
+ * This hook will create an `IntersectionObserver` and observe the ref passed to it.
17
+ *
18
+ * When the intersection changes, the callback will be called with the `IntersectionObserverEntry`.
19
+ *
20
+ * @param ref - The ref to observe
21
+ * @param intersectionObserverOptions - The options to pass to the IntersectionObserver
22
+ * @param options - The options to pass to the hook
23
+ * @param callback - The callback to call when the intersection changes
24
+ * @returns The IntersectionObserver instance
25
+ * @example
26
+ * ```tsx
27
+ * const MyComponent = () => {
28
+ * const ref = React.useRef<HTMLDivElement>(null)
29
+ * useIntersectionObserver(
30
+ * ref,
31
+ * (entry) => { doSomething(entry) },
32
+ * { rootMargin: '10px' },
33
+ * { disabled: false }
34
+ * )
35
+ * return <div ref={ref} />
36
+ * ```
37
+ */
38
+ export declare function useIntersectionObserver<T extends Element>(ref: React.RefObject<T | null>, callback: (entry: IntersectionObserverEntry | undefined) => void, intersectionObserverOptions?: IntersectionObserverInit, options?: {
39
+ disabled?: boolean;
40
+ }): void;
41
+ /**
42
+ * React hook to take a `React.ForwardedRef` and returns a `ref` that can be used on a DOM element.
43
+ *
44
+ * @param ref - The forwarded ref
45
+ * @returns The inner ref returned by `useRef`
46
+ * @example
47
+ * ```tsx
48
+ * const MyComponent = React.forwardRef((props, ref) => {
49
+ * const innerRef = useForwardedRef(ref)
50
+ * return <div ref={innerRef} />
51
+ * })
52
+ * ```
53
+ */
54
+ export declare function useForwardedRef<T>(ref?: React.ForwardedRef<T>): React.RefObject<T | null>;
@@ -0,0 +1,5 @@
1
+ import { RouterManagedTag } from '@tanstack/router-core';
2
+ import * as React from 'react';
3
+ export declare function Asset({ tag, attrs, children, nonce, }: RouterManagedTag & {
4
+ nonce?: string;
5
+ }): React.ReactElement | null;
@@ -0,0 +1,160 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { isServer } from "@tanstack/router-core/isServer";
4
+ import { useRouter } from "./useRouter.js";
5
+ import { useHydrated } from "./ClientOnly.js";
6
+ function Asset({
7
+ tag,
8
+ attrs,
9
+ children,
10
+ nonce
11
+ }) {
12
+ switch (tag) {
13
+ case "title":
14
+ return /* @__PURE__ */ jsx("title", { ...attrs, suppressHydrationWarning: true, children });
15
+ case "meta":
16
+ return /* @__PURE__ */ jsx("meta", { ...attrs, suppressHydrationWarning: true });
17
+ case "link":
18
+ return /* @__PURE__ */ jsx("link", { ...attrs, nonce, suppressHydrationWarning: true });
19
+ case "style":
20
+ return /* @__PURE__ */ jsx(
21
+ "style",
22
+ {
23
+ ...attrs,
24
+ dangerouslySetInnerHTML: { __html: children },
25
+ nonce
26
+ }
27
+ );
28
+ case "script":
29
+ return /* @__PURE__ */ jsx(Script, { attrs, children });
30
+ default:
31
+ return null;
32
+ }
33
+ }
34
+ function Script({
35
+ attrs,
36
+ children
37
+ }) {
38
+ const router = useRouter();
39
+ const hydrated = useHydrated();
40
+ const dataScript = typeof attrs?.type === "string" && attrs.type !== "" && attrs.type !== "text/javascript" && attrs.type !== "module";
41
+ if (process.env.NODE_ENV !== "production" && attrs?.src && typeof children === "string" && children.trim().length) {
42
+ console.warn(
43
+ "[TanStack Router] <Script> received both `src` and `children`. The `children` content will be ignored. Remove `children` or remove `src`."
44
+ );
45
+ }
46
+ React.useEffect(() => {
47
+ if (dataScript) return;
48
+ if (attrs?.src) {
49
+ const normSrc = (() => {
50
+ try {
51
+ const base = document.baseURI || window.location.href;
52
+ return new URL(attrs.src, base).href;
53
+ } catch {
54
+ return attrs.src;
55
+ }
56
+ })();
57
+ const existingScript = Array.from(
58
+ document.querySelectorAll("script[src]")
59
+ ).find((el) => el.src === normSrc);
60
+ if (existingScript) {
61
+ return;
62
+ }
63
+ const script = document.createElement("script");
64
+ for (const [key, value] of Object.entries(attrs)) {
65
+ if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
66
+ script.setAttribute(
67
+ key,
68
+ typeof value === "boolean" ? "" : String(value)
69
+ );
70
+ }
71
+ }
72
+ document.head.appendChild(script);
73
+ return () => {
74
+ if (script.parentNode) {
75
+ script.parentNode.removeChild(script);
76
+ }
77
+ };
78
+ }
79
+ if (typeof children === "string") {
80
+ const typeAttr = typeof attrs?.type === "string" ? attrs.type : "text/javascript";
81
+ const nonceAttr = typeof attrs?.nonce === "string" ? attrs.nonce : void 0;
82
+ const existingScript = Array.from(
83
+ document.querySelectorAll("script:not([src])")
84
+ ).find((el) => {
85
+ if (!(el instanceof HTMLScriptElement)) return false;
86
+ const sType = el.getAttribute("type") ?? "text/javascript";
87
+ const sNonce = el.getAttribute("nonce") ?? void 0;
88
+ return el.textContent === children && sType === typeAttr && sNonce === nonceAttr;
89
+ });
90
+ if (existingScript) {
91
+ return;
92
+ }
93
+ const script = document.createElement("script");
94
+ script.textContent = children;
95
+ if (attrs) {
96
+ for (const [key, value] of Object.entries(attrs)) {
97
+ if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
98
+ script.setAttribute(
99
+ key,
100
+ typeof value === "boolean" ? "" : String(value)
101
+ );
102
+ }
103
+ }
104
+ }
105
+ document.head.appendChild(script);
106
+ return () => {
107
+ if (script.parentNode) {
108
+ script.parentNode.removeChild(script);
109
+ }
110
+ };
111
+ }
112
+ return void 0;
113
+ }, [attrs, children, dataScript]);
114
+ if (isServer ?? router.isServer) {
115
+ if (attrs?.src) {
116
+ return /* @__PURE__ */ jsx("script", { ...attrs, suppressHydrationWarning: true });
117
+ }
118
+ if (typeof children === "string") {
119
+ return /* @__PURE__ */ jsx(
120
+ "script",
121
+ {
122
+ ...attrs,
123
+ dangerouslySetInnerHTML: { __html: children },
124
+ suppressHydrationWarning: true
125
+ }
126
+ );
127
+ }
128
+ return null;
129
+ }
130
+ if (dataScript && typeof children === "string") {
131
+ return /* @__PURE__ */ jsx(
132
+ "script",
133
+ {
134
+ ...attrs,
135
+ suppressHydrationWarning: true,
136
+ dangerouslySetInnerHTML: { __html: children }
137
+ }
138
+ );
139
+ }
140
+ if (!hydrated) {
141
+ if (attrs?.src) {
142
+ return /* @__PURE__ */ jsx("script", { ...attrs, suppressHydrationWarning: true });
143
+ }
144
+ if (typeof children === "string") {
145
+ return /* @__PURE__ */ jsx(
146
+ "script",
147
+ {
148
+ ...attrs,
149
+ dangerouslySetInnerHTML: { __html: children },
150
+ suppressHydrationWarning: true
151
+ }
152
+ );
153
+ }
154
+ }
155
+ return null;
156
+ }
157
+ export {
158
+ Asset
159
+ };
160
+ //# sourceMappingURL=Asset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Asset.js","sources":["../../src/Asset.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport { useHydrated } from './ClientOnly'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\ninterface ScriptAttrs {\n [key: string]: string | boolean | undefined\n src?: string\n suppressHydrationWarning?: boolean\n}\n\nexport function Asset({\n tag,\n attrs,\n children,\n nonce,\n}: RouterManagedTag & { nonce?: string }): React.ReactElement | null {\n switch (tag) {\n case 'title':\n return (\n <title {...attrs} suppressHydrationWarning>\n {children}\n </title>\n )\n case 'meta':\n return <meta {...attrs} suppressHydrationWarning />\n case 'link':\n return <link {...attrs} nonce={nonce} suppressHydrationWarning />\n case 'style':\n return (\n <style\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children as string }}\n nonce={nonce}\n />\n )\n case 'script':\n return <Script attrs={attrs}>{children}</Script>\n default:\n return null\n }\n}\n\nfunction Script({\n attrs,\n children,\n}: {\n attrs?: ScriptAttrs\n children?: string\n}) {\n const router = useRouter()\n const hydrated = useHydrated()\n const dataScript =\n typeof attrs?.type === 'string' &&\n attrs.type !== '' &&\n attrs.type !== 'text/javascript' &&\n attrs.type !== 'module'\n\n if (\n process.env.NODE_ENV !== 'production' &&\n attrs?.src &&\n typeof children === 'string' &&\n children.trim().length\n ) {\n console.warn(\n '[TanStack Router] <Script> received both `src` and `children`. The `children` content will be ignored. Remove `children` or remove `src`.',\n )\n }\n\n React.useEffect(() => {\n if (dataScript) return\n\n if (attrs?.src) {\n const normSrc = (() => {\n try {\n const base = document.baseURI || window.location.href\n return new URL(attrs.src, base).href\n } catch {\n return attrs.src\n }\n })()\n const existingScript = Array.from(\n document.querySelectorAll('script[src]'),\n ).find((el) => (el as HTMLScriptElement).src === normSrc)\n\n if (existingScript) {\n return\n }\n\n const script = document.createElement('script')\n\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(\n key,\n typeof value === 'boolean' ? '' : String(value),\n )\n }\n }\n\n document.head.appendChild(script)\n\n return () => {\n if (script.parentNode) {\n script.parentNode.removeChild(script)\n }\n }\n }\n\n if (typeof children === 'string') {\n const typeAttr =\n typeof attrs?.type === 'string' ? attrs.type : 'text/javascript'\n const nonceAttr =\n typeof attrs?.nonce === 'string' ? attrs.nonce : undefined\n const existingScript = Array.from(\n document.querySelectorAll('script:not([src])'),\n ).find((el) => {\n if (!(el instanceof HTMLScriptElement)) return false\n const sType = el.getAttribute('type') ?? 'text/javascript'\n const sNonce = el.getAttribute('nonce') ?? undefined\n return (\n el.textContent === children &&\n sType === typeAttr &&\n sNonce === nonceAttr\n )\n })\n\n if (existingScript) {\n return\n }\n\n const script = document.createElement('script')\n script.textContent = children\n\n if (attrs) {\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(\n key,\n typeof value === 'boolean' ? '' : String(value),\n )\n }\n }\n }\n\n document.head.appendChild(script)\n\n return () => {\n if (script.parentNode) {\n script.parentNode.removeChild(script)\n }\n }\n }\n\n return undefined\n }, [attrs, children, dataScript])\n\n // --- Server rendering ---\n if (isServer ?? router.isServer) {\n if (attrs?.src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n\n if (typeof children === 'string') {\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children }}\n suppressHydrationWarning\n />\n )\n }\n\n return null\n }\n\n // --- Client rendering ---\n\n // Data scripts (e.g. application/ld+json) are rendered in the tree;\n // the useEffect intentionally skips them.\n if (dataScript && typeof children === 'string') {\n return (\n <script\n {...attrs}\n suppressHydrationWarning\n dangerouslySetInnerHTML={{ __html: children }}\n />\n )\n }\n\n // During hydration (before useEffect has fired), render the script element\n // to match the server-rendered HTML and avoid structural hydration mismatches.\n // After hydration, return null — the useEffect handles imperative injection.\n if (!hydrated) {\n if (attrs?.src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n if (typeof children === 'string') {\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children }}\n suppressHydrationWarning\n />\n )\n }\n }\n\n return null\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,12 @@
1
+ import { ErrorRouteComponent } from './route.js';
2
+ import { ErrorInfo } from 'react';
3
+ import * as React from 'react';
4
+ export declare function CatchBoundary(props: {
5
+ getResetKey: () => number | string;
6
+ children: React.ReactNode;
7
+ errorComponent?: ErrorRouteComponent;
8
+ onCatch?: (error: Error, errorInfo: ErrorInfo) => void;
9
+ }): import("react/jsx-runtime").JSX.Element;
10
+ export declare function ErrorComponent({ error }: {
11
+ error: any;
12
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,97 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ function CatchBoundary(props) {
4
+ const errorComponent = props.errorComponent ?? ErrorComponent;
5
+ return /* @__PURE__ */ jsx(
6
+ CatchBoundaryImpl,
7
+ {
8
+ getResetKey: props.getResetKey,
9
+ onCatch: props.onCatch,
10
+ children: ({ error, reset }) => {
11
+ if (error) {
12
+ return React.createElement(errorComponent, {
13
+ error,
14
+ reset
15
+ });
16
+ }
17
+ return props.children;
18
+ }
19
+ }
20
+ );
21
+ }
22
+ class CatchBoundaryImpl extends React.Component {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.state = { error: null };
26
+ }
27
+ static getDerivedStateFromProps(props) {
28
+ return { resetKey: props.getResetKey() };
29
+ }
30
+ static getDerivedStateFromError(error) {
31
+ return { error };
32
+ }
33
+ reset() {
34
+ this.setState({ error: null });
35
+ }
36
+ componentDidUpdate(prevProps, prevState) {
37
+ if (prevState.error && prevState.resetKey !== this.state.resetKey) {
38
+ this.reset();
39
+ }
40
+ }
41
+ componentDidCatch(error, errorInfo) {
42
+ if (this.props.onCatch) {
43
+ this.props.onCatch(error, errorInfo);
44
+ }
45
+ }
46
+ render() {
47
+ return this.props.children({
48
+ error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
49
+ reset: () => {
50
+ this.reset();
51
+ }
52
+ });
53
+ }
54
+ }
55
+ function ErrorComponent({ error }) {
56
+ const [show, setShow] = React.useState(process.env.NODE_ENV !== "production");
57
+ return /* @__PURE__ */ jsxs("div", { style: { padding: ".5rem", maxWidth: "100%" }, children: [
58
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: ".5rem" }, children: [
59
+ /* @__PURE__ */ jsx("strong", { style: { fontSize: "1rem" }, children: "Something went wrong!" }),
60
+ /* @__PURE__ */ jsx(
61
+ "button",
62
+ {
63
+ style: {
64
+ appearance: "none",
65
+ fontSize: ".6em",
66
+ border: "1px solid currentColor",
67
+ padding: ".1rem .2rem",
68
+ fontWeight: "bold",
69
+ borderRadius: ".25rem"
70
+ },
71
+ onClick: () => setShow((d) => !d),
72
+ children: show ? "Hide Error" : "Show Error"
73
+ }
74
+ )
75
+ ] }),
76
+ /* @__PURE__ */ jsx("div", { style: { height: ".25rem" } }),
77
+ show ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
78
+ "pre",
79
+ {
80
+ style: {
81
+ fontSize: ".7em",
82
+ border: "1px solid red",
83
+ borderRadius: ".25rem",
84
+ padding: ".3rem",
85
+ color: "red",
86
+ overflow: "auto"
87
+ },
88
+ children: error.message ? /* @__PURE__ */ jsx("code", { children: error.message }) : null
89
+ }
90
+ ) }) : null
91
+ ] });
92
+ }
93
+ export {
94
+ CatchBoundary,
95
+ ErrorComponent
96
+ };
97
+ //# sourceMappingURL=CatchBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CatchBoundary.js","sources":["../../src/CatchBoundary.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { ErrorRouteComponent } from './route'\nimport type { ErrorInfo } from 'react'\n\nexport function CatchBoundary(props: {\n getResetKey: () => number | string\n children: React.ReactNode\n errorComponent?: ErrorRouteComponent\n onCatch?: (error: Error, errorInfo: ErrorInfo) => void\n}) {\n const errorComponent = props.errorComponent ?? ErrorComponent\n\n return (\n <CatchBoundaryImpl\n getResetKey={props.getResetKey}\n onCatch={props.onCatch}\n children={({ error, reset }) => {\n if (error) {\n return React.createElement(errorComponent, {\n error,\n reset,\n })\n }\n\n return props.children\n }}\n />\n )\n}\n\nclass CatchBoundaryImpl extends React.Component<{\n getResetKey: () => number | string\n children: (props: {\n error: Error | null\n reset: () => void\n }) => React.ReactNode\n onCatch?: (error: Error, errorInfo: ErrorInfo) => void\n}> {\n state = { error: null } as { error: Error | null; resetKey: string }\n static getDerivedStateFromProps(props: any) {\n return { resetKey: props.getResetKey() }\n }\n static getDerivedStateFromError(error: Error) {\n return { error }\n }\n reset() {\n this.setState({ error: null })\n }\n componentDidUpdate(\n prevProps: Readonly<{\n getResetKey: () => string\n children: (props: { error: any; reset: () => void }) => any\n onCatch?: ((error: any, info: any) => void) | undefined\n }>,\n prevState: any,\n ): void {\n if (prevState.error && prevState.resetKey !== this.state.resetKey) {\n this.reset()\n }\n }\n componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n if (this.props.onCatch) {\n this.props.onCatch(error, errorInfo)\n }\n }\n render() {\n // If the resetKey has changed, don't render the error\n return this.props.children({\n error:\n this.state.resetKey !== this.props.getResetKey()\n ? null\n : this.state.error,\n reset: () => {\n this.reset()\n },\n })\n }\n}\n\nexport function ErrorComponent({ error }: { error: any }) {\n const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production')\n\n return (\n <div style={{ padding: '.5rem', maxWidth: '100%' }}>\n <div style={{ display: 'flex', alignItems: 'center', gap: '.5rem' }}>\n <strong style={{ fontSize: '1rem' }}>Something went wrong!</strong>\n <button\n style={{\n appearance: 'none',\n fontSize: '.6em',\n border: '1px solid currentColor',\n padding: '.1rem .2rem',\n fontWeight: 'bold',\n borderRadius: '.25rem',\n }}\n onClick={() => setShow((d) => !d)}\n >\n {show ? 'Hide Error' : 'Show Error'}\n </button>\n </div>\n <div style={{ height: '.25rem' }} />\n {show ? (\n <div>\n <pre\n style={{\n fontSize: '.7em',\n border: '1px solid red',\n borderRadius: '.25rem',\n padding: '.3rem',\n color: 'red',\n overflow: 'auto',\n }}\n >\n {error.message ? <code>{error.message}</code> : null}\n </pre>\n </div>\n ) : null}\n </div>\n )\n}\n"],"names":[],"mappings":";;AAIO,SAAS,cAAc,OAK3B;AACD,QAAM,iBAAiB,MAAM,kBAAkB;AAE/C,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,aAAa,MAAM;AAAA,MACnB,SAAS,MAAM;AAAA,MACf,UAAU,CAAC,EAAE,OAAO,YAAY;AAC9B,YAAI,OAAO;AACT,iBAAO,MAAM,cAAc,gBAAgB;AAAA,YACzC;AAAA,YACA;AAAA,UAAA,CACD;AAAA,QACH;AAEA,eAAO,MAAM;AAAA,MACf;AAAA,IAAA;AAAA,EAAA;AAGN;AAEA,MAAM,0BAA0B,MAAM,UAOnC;AAAA,EAPH,cAAA;AAAA,UAAA,GAAA,SAAA;AAQE,SAAA,QAAQ,EAAE,OAAO,KAAA;AAAA,EAAK;AAAA,EACtB,OAAO,yBAAyB,OAAY;AAC1C,WAAO,EAAE,UAAU,MAAM,cAAY;AAAA,EACvC;AAAA,EACA,OAAO,yBAAyB,OAAc;AAC5C,WAAO,EAAE,MAAA;AAAA,EACX;AAAA,EACA,QAAQ;AACN,SAAK,SAAS,EAAE,OAAO,KAAA,CAAM;AAAA,EAC/B;AAAA,EACA,mBACE,WAKA,WACM;AACN,QAAI,UAAU,SAAS,UAAU,aAAa,KAAK,MAAM,UAAU;AACjE,WAAK,MAAA;AAAA,IACP;AAAA,EACF;AAAA,EACA,kBAAkB,OAAc,WAAsB;AACpD,QAAI,KAAK,MAAM,SAAS;AACtB,WAAK,MAAM,QAAQ,OAAO,SAAS;AAAA,IACrC;AAAA,EACF;AAAA,EACA,SAAS;AAEP,WAAO,KAAK,MAAM,SAAS;AAAA,MACzB,OACE,KAAK,MAAM,aAAa,KAAK,MAAM,gBAC/B,OACA,KAAK,MAAM;AAAA,MACjB,OAAO,MAAM;AACX,aAAK,MAAA;AAAA,MACP;AAAA,IAAA,CACD;AAAA,EACH;AACF;AAEO,SAAS,eAAe,EAAE,SAAyB;AACxD,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,QAAQ,IAAI,aAAa,YAAY;AAE5E,SACE,qBAAC,SAAI,OAAO,EAAE,SAAS,SAAS,UAAU,UACxC,UAAA;AAAA,IAAA,qBAAC,OAAA,EAAI,OAAO,EAAE,SAAS,QAAQ,YAAY,UAAU,KAAK,QAAA,GACxD,UAAA;AAAA,MAAA,oBAAC,YAAO,OAAO,EAAE,UAAU,OAAA,GAAU,UAAA,yBAAqB;AAAA,MAC1D;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,OAAO;AAAA,YACL,YAAY;AAAA,YACZ,UAAU;AAAA,YACV,QAAQ;AAAA,YACR,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,cAAc;AAAA,UAAA;AAAA,UAEhB,SAAS,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;AAAA,UAE/B,iBAAO,eAAe;AAAA,QAAA;AAAA,MAAA;AAAA,IACzB,GACF;AAAA,wBACC,OAAA,EAAI,OAAO,EAAE,QAAQ,YAAY;AAAA,IACjC,2BACE,OAAA,EACC,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,QAAQ;AAAA,UACR,cAAc;AAAA,UACd,SAAS;AAAA,UACT,OAAO;AAAA,UACP,UAAU;AAAA,QAAA;AAAA,QAGX,gBAAM,UAAU,oBAAC,QAAA,EAAM,UAAA,MAAM,SAAQ,IAAU;AAAA,MAAA;AAAA,IAAA,GAEpD,IACE;AAAA,EAAA,GACN;AAEJ;"}