@benjavicente/router-core 1.168.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/bin/intent.js +25 -0
- package/dist/cjs/Matches.cjs +17 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +139 -0
- package/dist/cjs/RouterProvider.d.cts +27 -0
- package/dist/cjs/config.cjs +11 -0
- package/dist/cjs/config.cjs.map +1 -0
- package/dist/cjs/config.d.cts +17 -0
- package/dist/cjs/defer.cjs +41 -0
- package/dist/cjs/defer.cjs.map +1 -0
- package/dist/cjs/defer.d.cts +37 -0
- package/dist/cjs/fileRoute.d.cts +24 -0
- package/dist/cjs/global.d.cts +7 -0
- package/dist/cjs/hash-scroll.cjs +20 -0
- package/dist/cjs/hash-scroll.cjs.map +1 -0
- package/dist/cjs/hash-scroll.d.cts +7 -0
- package/dist/cjs/history.d.cts +8 -0
- package/dist/cjs/index.cjs +96 -0
- package/dist/cjs/index.d.cts +53 -0
- package/dist/cjs/invariant.cjs +8 -0
- package/dist/cjs/invariant.cjs.map +1 -0
- package/dist/cjs/invariant.d.cts +1 -0
- package/dist/cjs/isServer/client.cjs +7 -0
- package/dist/cjs/isServer/client.cjs.map +1 -0
- package/dist/cjs/isServer/client.d.cts +1 -0
- package/dist/cjs/isServer/development.cjs +7 -0
- package/dist/cjs/isServer/development.cjs.map +1 -0
- package/dist/cjs/isServer/development.d.cts +1 -0
- package/dist/cjs/isServer/server.cjs +7 -0
- package/dist/cjs/isServer/server.cjs.map +1 -0
- package/dist/cjs/isServer/server.d.cts +1 -0
- package/dist/cjs/link.cjs +6 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +221 -0
- package/dist/cjs/load-matches.cjs +659 -0
- package/dist/cjs/load-matches.cjs.map +1 -0
- package/dist/cjs/load-matches.d.cts +18 -0
- package/dist/cjs/location.d.cts +50 -0
- package/dist/cjs/lru-cache.cjs +70 -0
- package/dist/cjs/lru-cache.cjs.map +1 -0
- package/dist/cjs/lru-cache.d.cts +6 -0
- package/dist/cjs/manifest.cjs +18 -0
- package/dist/cjs/manifest.cjs.map +1 -0
- package/dist/cjs/manifest.d.cts +35 -0
- package/dist/cjs/new-process-route-tree.cjs +754 -0
- package/dist/cjs/new-process-route-tree.cjs.map +1 -0
- package/dist/cjs/new-process-route-tree.d.cts +236 -0
- package/dist/cjs/not-found.cjs +26 -0
- package/dist/cjs/not-found.cjs.map +1 -0
- package/dist/cjs/not-found.d.cts +32 -0
- package/dist/cjs/path.cjs +252 -0
- package/dist/cjs/path.cjs.map +1 -0
- package/dist/cjs/path.d.cts +56 -0
- package/dist/cjs/qss.cjs +70 -0
- package/dist/cjs/qss.cjs.map +1 -0
- package/dist/cjs/qss.d.cts +33 -0
- package/dist/cjs/redirect.cjs +56 -0
- package/dist/cjs/redirect.cjs.map +1 -0
- package/dist/cjs/redirect.d.cts +77 -0
- package/dist/cjs/rewrite.cjs +68 -0
- package/dist/cjs/rewrite.cjs.map +1 -0
- package/dist/cjs/rewrite.d.cts +30 -0
- package/dist/cjs/root.cjs +7 -0
- package/dist/cjs/root.cjs.map +1 -0
- package/dist/cjs/root.d.cts +3 -0
- package/dist/cjs/route.cjs +100 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/route.d.cts +552 -0
- package/dist/cjs/routeInfo.d.cts +54 -0
- package/dist/cjs/router.cjs +1173 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/router.d.cts +734 -0
- package/dist/cjs/scroll-restoration-inline.cjs +6 -0
- package/dist/cjs/scroll-restoration-inline.cjs.map +1 -0
- package/dist/cjs/scroll-restoration-inline.d.cts +6 -0
- package/dist/cjs/scroll-restoration-script/client.cjs +9 -0
- package/dist/cjs/scroll-restoration-script/client.cjs.map +1 -0
- package/dist/cjs/scroll-restoration-script/client.d.cts +2 -0
- package/dist/cjs/scroll-restoration-script/server.cjs +30 -0
- package/dist/cjs/scroll-restoration-script/server.cjs.map +1 -0
- package/dist/cjs/scroll-restoration-script/server.d.cts +2 -0
- package/dist/cjs/scroll-restoration.cjs +191 -0
- package/dist/cjs/scroll-restoration.cjs.map +1 -0
- package/dist/cjs/scroll-restoration.d.cts +38 -0
- package/dist/cjs/searchMiddleware.cjs +55 -0
- package/dist/cjs/searchMiddleware.cjs.map +1 -0
- package/dist/cjs/searchMiddleware.d.cts +25 -0
- package/dist/cjs/searchParams.cjs +65 -0
- package/dist/cjs/searchParams.cjs.map +1 -0
- package/dist/cjs/searchParams.d.cts +31 -0
- package/dist/cjs/ssr/client.cjs +7 -0
- package/dist/cjs/ssr/client.d.cts +6 -0
- package/dist/cjs/ssr/constants.cjs +8 -0
- package/dist/cjs/ssr/constants.cjs.map +1 -0
- package/dist/cjs/ssr/constants.d.cts +3 -0
- package/dist/cjs/ssr/createRequestHandler.cjs +44 -0
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -0
- package/dist/cjs/ssr/createRequestHandler.d.cts +9 -0
- package/dist/cjs/ssr/handlerCallback.cjs +8 -0
- package/dist/cjs/ssr/handlerCallback.cjs.map +1 -0
- package/dist/cjs/ssr/handlerCallback.d.cts +9 -0
- package/dist/cjs/ssr/headers.cjs +21 -0
- package/dist/cjs/ssr/headers.cjs.map +1 -0
- package/dist/cjs/ssr/headers.d.cts +3 -0
- package/dist/cjs/ssr/json.cjs +11 -0
- package/dist/cjs/ssr/json.cjs.map +1 -0
- package/dist/cjs/ssr/json.d.cts +10 -0
- package/dist/cjs/ssr/serializer/RawStream.cjs +287 -0
- package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -0
- package/dist/cjs/ssr/serializer/RawStream.d.cts +64 -0
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +32 -0
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -0
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.d.cts +9 -0
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs +13 -0
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -0
- package/dist/cjs/ssr/serializer/seroval-plugins.d.cts +2 -0
- package/dist/cjs/ssr/serializer/transformer.cjs +53 -0
- package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -0
- package/dist/cjs/ssr/serializer/transformer.d.cts +91 -0
- package/dist/cjs/ssr/server.cjs +13 -0
- package/dist/cjs/ssr/server.d.cts +6 -0
- package/dist/cjs/ssr/ssr-client.cjs +183 -0
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -0
- package/dist/cjs/ssr/ssr-client.d.cts +10 -0
- package/dist/cjs/ssr/ssr-match-id.cjs +12 -0
- package/dist/cjs/ssr/ssr-match-id.cjs.map +1 -0
- package/dist/cjs/ssr/ssr-match-id.d.cts +2 -0
- package/dist/cjs/ssr/ssr-server.cjs +279 -0
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -0
- package/dist/cjs/ssr/ssr-server.d.cts +42 -0
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +327 -0
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -0
- package/dist/cjs/ssr/transformStreamWithRouter.d.cts +11 -0
- package/dist/cjs/ssr/tsrScript.cjs +6 -0
- package/dist/cjs/ssr/tsrScript.cjs.map +1 -0
- package/dist/cjs/ssr/tsrScript.d.cts +1 -0
- package/dist/cjs/ssr/types.d.cts +30 -0
- package/dist/cjs/stores.cjs +148 -0
- package/dist/cjs/stores.cjs.map +1 -0
- package/dist/cjs/stores.d.cts +70 -0
- package/dist/cjs/structuralSharing.d.cts +4 -0
- package/dist/cjs/typePrimitives.d.cts +65 -0
- package/dist/cjs/useLoaderData.d.cts +5 -0
- package/dist/cjs/useLoaderDeps.d.cts +5 -0
- package/dist/cjs/useNavigate.d.cts +3 -0
- package/dist/cjs/useParams.d.cts +5 -0
- package/dist/cjs/useRouteContext.d.cts +9 -0
- package/dist/cjs/useSearch.d.cts +5 -0
- package/dist/cjs/utils.cjs +339 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +178 -0
- package/dist/cjs/validators.d.cts +51 -0
- package/dist/esm/Matches.d.ts +139 -0
- package/dist/esm/Matches.js +17 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +27 -0
- package/dist/esm/config.d.ts +17 -0
- package/dist/esm/config.js +11 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/defer.d.ts +37 -0
- package/dist/esm/defer.js +40 -0
- package/dist/esm/defer.js.map +1 -0
- package/dist/esm/fileRoute.d.ts +24 -0
- package/dist/esm/global.d.ts +7 -0
- package/dist/esm/hash-scroll.d.ts +7 -0
- package/dist/esm/hash-scroll.js +20 -0
- package/dist/esm/hash-scroll.js.map +1 -0
- package/dist/esm/history.d.ts +8 -0
- package/dist/esm/index.d.ts +53 -0
- package/dist/esm/index.js +24 -0
- package/dist/esm/invariant.d.ts +1 -0
- package/dist/esm/invariant.js +8 -0
- package/dist/esm/invariant.js.map +1 -0
- package/dist/esm/isServer/client.d.ts +1 -0
- package/dist/esm/isServer/client.js +6 -0
- package/dist/esm/isServer/client.js.map +1 -0
- package/dist/esm/isServer/development.d.ts +1 -0
- package/dist/esm/isServer/development.js +6 -0
- package/dist/esm/isServer/development.js.map +1 -0
- package/dist/esm/isServer/server.d.ts +1 -0
- package/dist/esm/isServer/server.js +6 -0
- package/dist/esm/isServer/server.js.map +1 -0
- package/dist/esm/link.d.ts +221 -0
- package/dist/esm/link.js +6 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/load-matches.d.ts +18 -0
- package/dist/esm/load-matches.js +657 -0
- package/dist/esm/load-matches.js.map +1 -0
- package/dist/esm/location.d.ts +50 -0
- package/dist/esm/lru-cache.d.ts +6 -0
- package/dist/esm/lru-cache.js +70 -0
- package/dist/esm/lru-cache.js.map +1 -0
- package/dist/esm/manifest.d.ts +35 -0
- package/dist/esm/manifest.js +17 -0
- package/dist/esm/manifest.js.map +1 -0
- package/dist/esm/new-process-route-tree.d.ts +236 -0
- package/dist/esm/new-process-route-tree.js +749 -0
- package/dist/esm/new-process-route-tree.js.map +1 -0
- package/dist/esm/not-found.d.ts +32 -0
- package/dist/esm/not-found.js +25 -0
- package/dist/esm/not-found.js.map +1 -0
- package/dist/esm/path.d.ts +56 -0
- package/dist/esm/path.js +243 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/qss.d.ts +33 -0
- package/dist/esm/qss.js +69 -0
- package/dist/esm/qss.js.map +1 -0
- package/dist/esm/redirect.d.ts +77 -0
- package/dist/esm/redirect.js +53 -0
- package/dist/esm/redirect.js.map +1 -0
- package/dist/esm/rewrite.d.ts +30 -0
- package/dist/esm/rewrite.js +65 -0
- package/dist/esm/rewrite.js.map +1 -0
- package/dist/esm/root.d.ts +3 -0
- package/dist/esm/root.js +7 -0
- package/dist/esm/root.js.map +1 -0
- package/dist/esm/route.d.ts +552 -0
- package/dist/esm/route.js +98 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/routeInfo.d.ts +54 -0
- package/dist/esm/router.d.ts +734 -0
- package/dist/esm/router.js +1165 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/scroll-restoration-inline.d.ts +6 -0
- package/dist/esm/scroll-restoration-inline.js +6 -0
- package/dist/esm/scroll-restoration-inline.js.map +1 -0
- package/dist/esm/scroll-restoration-script/client.d.ts +2 -0
- package/dist/esm/scroll-restoration-script/client.js +8 -0
- package/dist/esm/scroll-restoration-script/client.js.map +1 -0
- package/dist/esm/scroll-restoration-script/server.d.ts +2 -0
- package/dist/esm/scroll-restoration-script/server.js +29 -0
- package/dist/esm/scroll-restoration-script/server.js.map +1 -0
- package/dist/esm/scroll-restoration.d.ts +38 -0
- package/dist/esm/scroll-restoration.js +187 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/searchMiddleware.d.ts +25 -0
- package/dist/esm/searchMiddleware.js +54 -0
- package/dist/esm/searchMiddleware.js.map +1 -0
- package/dist/esm/searchParams.d.ts +31 -0
- package/dist/esm/searchParams.js +62 -0
- package/dist/esm/searchParams.js.map +1 -0
- package/dist/esm/ssr/client.d.ts +6 -0
- package/dist/esm/ssr/client.js +4 -0
- package/dist/esm/ssr/constants.d.ts +3 -0
- package/dist/esm/ssr/constants.js +7 -0
- package/dist/esm/ssr/constants.js.map +1 -0
- package/dist/esm/ssr/createRequestHandler.d.ts +9 -0
- package/dist/esm/ssr/createRequestHandler.js +44 -0
- package/dist/esm/ssr/createRequestHandler.js.map +1 -0
- package/dist/esm/ssr/handlerCallback.d.ts +9 -0
- package/dist/esm/ssr/handlerCallback.js +8 -0
- package/dist/esm/ssr/handlerCallback.js.map +1 -0
- package/dist/esm/ssr/headers.d.ts +3 -0
- package/dist/esm/ssr/headers.js +21 -0
- package/dist/esm/ssr/headers.js.map +1 -0
- package/dist/esm/ssr/json.d.ts +10 -0
- package/dist/esm/ssr/json.js +11 -0
- package/dist/esm/ssr/json.js.map +1 -0
- package/dist/esm/ssr/serializer/RawStream.d.ts +64 -0
- package/dist/esm/ssr/serializer/RawStream.js +282 -0
- package/dist/esm/ssr/serializer/RawStream.js.map +1 -0
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.d.ts +9 -0
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js +33 -0
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -0
- package/dist/esm/ssr/serializer/seroval-plugins.d.ts +2 -0
- package/dist/esm/ssr/serializer/seroval-plugins.js +13 -0
- package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -0
- package/dist/esm/ssr/serializer/transformer.d.ts +91 -0
- package/dist/esm/ssr/serializer/transformer.js +51 -0
- package/dist/esm/ssr/serializer/transformer.js.map +1 -0
- package/dist/esm/ssr/server.d.ts +6 -0
- package/dist/esm/ssr/server.js +5 -0
- package/dist/esm/ssr/ssr-client.d.ts +10 -0
- package/dist/esm/ssr/ssr-client.js +183 -0
- package/dist/esm/ssr/ssr-client.js.map +1 -0
- package/dist/esm/ssr/ssr-match-id.d.ts +2 -0
- package/dist/esm/ssr/ssr-match-id.js +11 -0
- package/dist/esm/ssr/ssr-match-id.js.map +1 -0
- package/dist/esm/ssr/ssr-server.d.ts +42 -0
- package/dist/esm/ssr/ssr-server.js +277 -0
- package/dist/esm/ssr/ssr-server.js.map +1 -0
- package/dist/esm/ssr/transformStreamWithRouter.d.ts +11 -0
- package/dist/esm/ssr/transformStreamWithRouter.js +325 -0
- package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -0
- package/dist/esm/ssr/tsrScript.d.ts +0 -0
- package/dist/esm/ssr/tsrScript.js +6 -0
- package/dist/esm/ssr/tsrScript.js.map +1 -0
- package/dist/esm/ssr/types.d.ts +30 -0
- package/dist/esm/stores.d.ts +70 -0
- package/dist/esm/stores.js +146 -0
- package/dist/esm/stores.js.map +1 -0
- package/dist/esm/structuralSharing.d.ts +4 -0
- package/dist/esm/typePrimitives.d.ts +65 -0
- package/dist/esm/useLoaderData.d.ts +5 -0
- package/dist/esm/useLoaderDeps.d.ts +5 -0
- package/dist/esm/useNavigate.d.ts +3 -0
- package/dist/esm/useParams.d.ts +5 -0
- package/dist/esm/useRouteContext.d.ts +9 -0
- package/dist/esm/useSearch.d.ts +5 -0
- package/dist/esm/utils.d.ts +178 -0
- package/dist/esm/utils.js +322 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/validators.d.ts +51 -0
- package/package.json +200 -0
- package/skills/router-core/SKILL.md +139 -0
- package/skills/router-core/auth-and-guards/SKILL.md +458 -0
- package/skills/router-core/code-splitting/SKILL.md +322 -0
- package/skills/router-core/data-loading/SKILL.md +485 -0
- package/skills/router-core/navigation/SKILL.md +448 -0
- package/skills/router-core/not-found-and-errors/SKILL.md +435 -0
- package/skills/router-core/path-params/SKILL.md +382 -0
- package/skills/router-core/search-params/SKILL.md +349 -0
- package/skills/router-core/search-params/references/validation-patterns.md +379 -0
- package/skills/router-core/ssr/SKILL.md +437 -0
- package/skills/router-core/type-safety/SKILL.md +497 -0
- package/src/Matches.ts +291 -0
- package/src/RouterProvider.ts +47 -0
- package/src/config.ts +42 -0
- package/src/defer.ts +69 -0
- package/src/fileRoute.ts +164 -0
- package/src/global.ts +9 -0
- package/src/hash-scroll.ts +21 -0
- package/src/history.ts +9 -0
- package/src/index.ts +471 -0
- package/src/invariant.ts +3 -0
- package/src/isServer/client.ts +1 -0
- package/src/isServer/development.ts +2 -0
- package/src/isServer/server.ts +1 -0
- package/src/link.ts +704 -0
- package/src/load-matches.ts +1281 -0
- package/src/location.ts +51 -0
- package/src/lru-cache.ts +74 -0
- package/src/manifest.ts +68 -0
- package/src/new-process-route-tree.ts +1387 -0
- package/src/not-found.ts +41 -0
- package/src/path.ts +436 -0
- package/src/qss.ts +81 -0
- package/src/redirect.ts +179 -0
- package/src/rewrite.ts +93 -0
- package/src/root.ts +3 -0
- package/src/route.ts +2235 -0
- package/src/routeInfo.ts +235 -0
- package/src/router.ts +3207 -0
- package/src/scroll-restoration-inline.ts +81 -0
- package/src/scroll-restoration-script/client.ts +5 -0
- package/src/scroll-restoration-script/server.ts +64 -0
- package/src/scroll-restoration.ts +357 -0
- package/src/searchMiddleware.ts +76 -0
- package/src/searchParams.ts +90 -0
- package/src/ssr/client.ts +6 -0
- package/src/ssr/constants.ts +3 -0
- package/src/ssr/createRequestHandler.ts +98 -0
- package/src/ssr/handlerCallback.ts +15 -0
- package/src/ssr/headers.ts +40 -0
- package/src/ssr/json.ts +16 -0
- package/src/ssr/serializer/RawStream.ts +464 -0
- package/src/ssr/serializer/ShallowErrorPlugin.ts +43 -0
- package/src/ssr/serializer/seroval-plugins.ts +12 -0
- package/src/ssr/serializer/transformer.ts +312 -0
- package/src/ssr/server.ts +14 -0
- package/src/ssr/ssr-client.ts +313 -0
- package/src/ssr/ssr-match-id.ts +7 -0
- package/src/ssr/ssr-server.ts +425 -0
- package/src/ssr/transformStreamWithRouter.ts +493 -0
- package/src/ssr/tsrScript.ts +20 -0
- package/src/ssr/types.ts +41 -0
- package/src/stores.ts +342 -0
- package/src/structuralSharing.ts +7 -0
- package/src/typePrimitives.ts +181 -0
- package/src/useLoaderData.ts +20 -0
- package/src/useLoaderDeps.ts +13 -0
- package/src/useNavigate.ts +13 -0
- package/src/useParams.ts +20 -0
- package/src/useRouteContext.ts +39 -0
- package/src/useSearch.ts +20 -0
- package/src/utils.ts +708 -0
- package/src/validators.ts +121 -0
- package/src/vite-env.d.ts +4 -0
package/src/stores.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { createLRUCache } from './lru-cache'
|
|
2
|
+
import { arraysEqual } from './utils'
|
|
3
|
+
|
|
4
|
+
import type { AnyRoute } from './route'
|
|
5
|
+
import type { RouterState } from './router'
|
|
6
|
+
import type { FullSearchSchema } from './routeInfo'
|
|
7
|
+
import type { ParsedLocation } from './location'
|
|
8
|
+
import type { AnyRedirect } from './redirect'
|
|
9
|
+
import type { AnyRouteMatch } from './Matches'
|
|
10
|
+
|
|
11
|
+
export interface RouterReadableStore<TValue> {
|
|
12
|
+
readonly state: TValue
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RouterWritableStore<
|
|
16
|
+
TValue,
|
|
17
|
+
> extends RouterReadableStore<TValue> {
|
|
18
|
+
setState: (updater: (prev: TValue) => TValue) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type RouterBatchFn = (fn: () => void) => void
|
|
22
|
+
|
|
23
|
+
export type MutableStoreFactory = <TValue>(
|
|
24
|
+
initialValue: TValue,
|
|
25
|
+
) => RouterWritableStore<TValue>
|
|
26
|
+
|
|
27
|
+
export type ReadonlyStoreFactory = <TValue>(
|
|
28
|
+
read: () => TValue,
|
|
29
|
+
) => RouterReadableStore<TValue>
|
|
30
|
+
|
|
31
|
+
export type GetStoreConfig = (opts: { isServer?: boolean }) => StoreConfig
|
|
32
|
+
|
|
33
|
+
export type StoreConfig = {
|
|
34
|
+
createMutableStore: MutableStoreFactory
|
|
35
|
+
createReadonlyStore: ReadonlyStoreFactory
|
|
36
|
+
batch: RouterBatchFn
|
|
37
|
+
init?: (stores: RouterStores<AnyRoute>) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type MatchStore = RouterWritableStore<AnyRouteMatch> & {
|
|
41
|
+
routeId?: string
|
|
42
|
+
}
|
|
43
|
+
type ReadableStore<TValue> = RouterReadableStore<TValue>
|
|
44
|
+
|
|
45
|
+
/** SSR non-reactive createMutableStore */
|
|
46
|
+
export function createNonReactiveMutableStore<TValue>(
|
|
47
|
+
initialValue: TValue,
|
|
48
|
+
): RouterWritableStore<TValue> {
|
|
49
|
+
let value = initialValue
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
get state() {
|
|
53
|
+
return value
|
|
54
|
+
},
|
|
55
|
+
setState(updater: (prev: TValue) => TValue) {
|
|
56
|
+
value = updater(value)
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** SSR non-reactive createReadonlyStore */
|
|
62
|
+
export function createNonReactiveReadonlyStore<TValue>(
|
|
63
|
+
read: () => TValue,
|
|
64
|
+
): RouterReadableStore<TValue> {
|
|
65
|
+
return {
|
|
66
|
+
get state() {
|
|
67
|
+
return read()
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface RouterStores<in out TRouteTree extends AnyRoute> {
|
|
73
|
+
status: RouterWritableStore<RouterState<TRouteTree>['status']>
|
|
74
|
+
loadedAt: RouterWritableStore<number>
|
|
75
|
+
isLoading: RouterWritableStore<boolean>
|
|
76
|
+
isTransitioning: RouterWritableStore<boolean>
|
|
77
|
+
location: RouterWritableStore<ParsedLocation<FullSearchSchema<TRouteTree>>>
|
|
78
|
+
resolvedLocation: RouterWritableStore<
|
|
79
|
+
ParsedLocation<FullSearchSchema<TRouteTree>> | undefined
|
|
80
|
+
>
|
|
81
|
+
statusCode: RouterWritableStore<number>
|
|
82
|
+
redirect: RouterWritableStore<AnyRedirect | undefined>
|
|
83
|
+
matchesId: RouterWritableStore<Array<string>>
|
|
84
|
+
pendingMatchesId: RouterWritableStore<Array<string>>
|
|
85
|
+
/** @internal */
|
|
86
|
+
cachedMatchesId: RouterWritableStore<Array<string>>
|
|
87
|
+
activeMatchesSnapshot: ReadableStore<Array<AnyRouteMatch>>
|
|
88
|
+
pendingMatchesSnapshot: ReadableStore<Array<AnyRouteMatch>>
|
|
89
|
+
cachedMatchesSnapshot: ReadableStore<Array<AnyRouteMatch>>
|
|
90
|
+
firstMatchId: ReadableStore<string | undefined>
|
|
91
|
+
hasPendingMatches: ReadableStore<boolean>
|
|
92
|
+
matchRouteReactivity: ReadableStore<{
|
|
93
|
+
locationHref: string
|
|
94
|
+
resolvedLocationHref: string | undefined
|
|
95
|
+
status: RouterState<TRouteTree>['status']
|
|
96
|
+
}>
|
|
97
|
+
__store: RouterReadableStore<RouterState<TRouteTree>>
|
|
98
|
+
|
|
99
|
+
activeMatchStoresById: Map<string, MatchStore>
|
|
100
|
+
pendingMatchStoresById: Map<string, MatchStore>
|
|
101
|
+
cachedMatchStoresById: Map<string, MatchStore>
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get a computed store that resolves a routeId to its current match state.
|
|
105
|
+
* Returns the same cached store instance for repeated calls with the same key.
|
|
106
|
+
* The computed depends on matchesId + the individual match store, so
|
|
107
|
+
* subscribers are only notified when the resolved match state changes.
|
|
108
|
+
*/
|
|
109
|
+
getMatchStoreByRouteId: (
|
|
110
|
+
routeId: string,
|
|
111
|
+
) => RouterReadableStore<AnyRouteMatch | undefined>
|
|
112
|
+
|
|
113
|
+
setActiveMatches: (nextMatches: Array<AnyRouteMatch>) => void
|
|
114
|
+
setPendingMatches: (nextMatches: Array<AnyRouteMatch>) => void
|
|
115
|
+
setCachedMatches: (nextMatches: Array<AnyRouteMatch>) => void
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function createRouterStores<TRouteTree extends AnyRoute>(
|
|
119
|
+
initialState: RouterState<TRouteTree>,
|
|
120
|
+
config: StoreConfig,
|
|
121
|
+
): RouterStores<TRouteTree> {
|
|
122
|
+
const { createMutableStore, createReadonlyStore, batch, init } = config
|
|
123
|
+
|
|
124
|
+
// non reactive utilities
|
|
125
|
+
const activeMatchStoresById = new Map<string, MatchStore>()
|
|
126
|
+
const pendingMatchStoresById = new Map<string, MatchStore>()
|
|
127
|
+
const cachedMatchStoresById = new Map<string, MatchStore>()
|
|
128
|
+
|
|
129
|
+
// atoms
|
|
130
|
+
const status = createMutableStore(initialState.status)
|
|
131
|
+
const loadedAt = createMutableStore(initialState.loadedAt)
|
|
132
|
+
const isLoading = createMutableStore(initialState.isLoading)
|
|
133
|
+
const isTransitioning = createMutableStore(initialState.isTransitioning)
|
|
134
|
+
const location = createMutableStore(initialState.location)
|
|
135
|
+
const resolvedLocation = createMutableStore(initialState.resolvedLocation)
|
|
136
|
+
const statusCode = createMutableStore(initialState.statusCode)
|
|
137
|
+
const redirect = createMutableStore(initialState.redirect)
|
|
138
|
+
const matchesId = createMutableStore<Array<string>>([])
|
|
139
|
+
const pendingMatchesId = createMutableStore<Array<string>>([])
|
|
140
|
+
const cachedMatchesId = createMutableStore<Array<string>>([])
|
|
141
|
+
|
|
142
|
+
// 1st order derived stores
|
|
143
|
+
const activeMatchesSnapshot = createReadonlyStore(() =>
|
|
144
|
+
readPoolMatches(activeMatchStoresById, matchesId.state),
|
|
145
|
+
)
|
|
146
|
+
const pendingMatchesSnapshot = createReadonlyStore(() =>
|
|
147
|
+
readPoolMatches(pendingMatchStoresById, pendingMatchesId.state),
|
|
148
|
+
)
|
|
149
|
+
const cachedMatchesSnapshot = createReadonlyStore(() =>
|
|
150
|
+
readPoolMatches(cachedMatchStoresById, cachedMatchesId.state),
|
|
151
|
+
)
|
|
152
|
+
const firstMatchId = createReadonlyStore(() => matchesId.state[0])
|
|
153
|
+
const hasPendingMatches = createReadonlyStore(() =>
|
|
154
|
+
matchesId.state.some((matchId) => {
|
|
155
|
+
const store = activeMatchStoresById.get(matchId)
|
|
156
|
+
return store?.state.status === 'pending'
|
|
157
|
+
}),
|
|
158
|
+
)
|
|
159
|
+
const matchRouteReactivity = createReadonlyStore(() => ({
|
|
160
|
+
locationHref: location.state.href,
|
|
161
|
+
resolvedLocationHref: resolvedLocation.state?.href,
|
|
162
|
+
status: status.state,
|
|
163
|
+
}))
|
|
164
|
+
|
|
165
|
+
// compatibility "big" state store
|
|
166
|
+
const __store = createReadonlyStore(() => ({
|
|
167
|
+
status: status.state,
|
|
168
|
+
loadedAt: loadedAt.state,
|
|
169
|
+
isLoading: isLoading.state,
|
|
170
|
+
isTransitioning: isTransitioning.state,
|
|
171
|
+
matches: activeMatchesSnapshot.state,
|
|
172
|
+
location: location.state,
|
|
173
|
+
resolvedLocation: resolvedLocation.state,
|
|
174
|
+
statusCode: statusCode.state,
|
|
175
|
+
redirect: redirect.state,
|
|
176
|
+
}))
|
|
177
|
+
|
|
178
|
+
// Per-routeId computed store cache.
|
|
179
|
+
// Each entry resolves routeId → match state through the signal graph,
|
|
180
|
+
// giving consumers a single store to subscribe to instead of the
|
|
181
|
+
// two-level byRouteId → matchStore pattern.
|
|
182
|
+
//
|
|
183
|
+
// 64 max size is arbitrary, this is only for active matches anyway so
|
|
184
|
+
// it should be plenty. And we already have a 32 limit due to route
|
|
185
|
+
// matching bitmask anyway.
|
|
186
|
+
const matchStoreByRouteIdCache = createLRUCache<
|
|
187
|
+
string,
|
|
188
|
+
RouterReadableStore<AnyRouteMatch | undefined>
|
|
189
|
+
>(64)
|
|
190
|
+
|
|
191
|
+
function getMatchStoreByRouteId(
|
|
192
|
+
routeId: string,
|
|
193
|
+
): RouterReadableStore<AnyRouteMatch | undefined> {
|
|
194
|
+
let cached = matchStoreByRouteIdCache.get(routeId)
|
|
195
|
+
if (!cached) {
|
|
196
|
+
cached = createReadonlyStore(() => {
|
|
197
|
+
// Reading matchesId.state tracks it as a dependency.
|
|
198
|
+
// When matchesId changes (navigation), this computed re-evaluates.
|
|
199
|
+
const ids = matchesId.state
|
|
200
|
+
for (const id of ids) {
|
|
201
|
+
const matchStore = activeMatchStoresById.get(id)
|
|
202
|
+
if (matchStore && matchStore.routeId === routeId) {
|
|
203
|
+
// Reading matchStore.state tracks it as a dependency.
|
|
204
|
+
// When the match store's state changes, this re-evaluates.
|
|
205
|
+
return matchStore.state
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return undefined
|
|
209
|
+
})
|
|
210
|
+
matchStoreByRouteIdCache.set(routeId, cached)
|
|
211
|
+
}
|
|
212
|
+
return cached
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const store = {
|
|
216
|
+
// atoms
|
|
217
|
+
status,
|
|
218
|
+
loadedAt,
|
|
219
|
+
isLoading,
|
|
220
|
+
isTransitioning,
|
|
221
|
+
location,
|
|
222
|
+
resolvedLocation,
|
|
223
|
+
statusCode,
|
|
224
|
+
redirect,
|
|
225
|
+
matchesId,
|
|
226
|
+
pendingMatchesId,
|
|
227
|
+
cachedMatchesId,
|
|
228
|
+
|
|
229
|
+
// derived
|
|
230
|
+
activeMatchesSnapshot,
|
|
231
|
+
pendingMatchesSnapshot,
|
|
232
|
+
cachedMatchesSnapshot,
|
|
233
|
+
firstMatchId,
|
|
234
|
+
hasPendingMatches,
|
|
235
|
+
matchRouteReactivity,
|
|
236
|
+
|
|
237
|
+
// non-reactive state
|
|
238
|
+
activeMatchStoresById,
|
|
239
|
+
pendingMatchStoresById,
|
|
240
|
+
cachedMatchStoresById,
|
|
241
|
+
|
|
242
|
+
// compatibility "big" state
|
|
243
|
+
__store,
|
|
244
|
+
|
|
245
|
+
// per-key computed stores
|
|
246
|
+
getMatchStoreByRouteId,
|
|
247
|
+
|
|
248
|
+
// methods
|
|
249
|
+
setActiveMatches,
|
|
250
|
+
setPendingMatches,
|
|
251
|
+
setCachedMatches,
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// initialize the active matches
|
|
255
|
+
setActiveMatches(initialState.matches as Array<AnyRouteMatch>)
|
|
256
|
+
init?.(store)
|
|
257
|
+
|
|
258
|
+
// setters to update non-reactive utilities in sync with the reactive stores
|
|
259
|
+
function setActiveMatches(nextMatches: Array<AnyRouteMatch>) {
|
|
260
|
+
reconcileMatchPool(
|
|
261
|
+
nextMatches,
|
|
262
|
+
activeMatchStoresById,
|
|
263
|
+
matchesId,
|
|
264
|
+
createMutableStore,
|
|
265
|
+
batch,
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function setPendingMatches(nextMatches: Array<AnyRouteMatch>) {
|
|
270
|
+
reconcileMatchPool(
|
|
271
|
+
nextMatches,
|
|
272
|
+
pendingMatchStoresById,
|
|
273
|
+
pendingMatchesId,
|
|
274
|
+
createMutableStore,
|
|
275
|
+
batch,
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function setCachedMatches(nextMatches: Array<AnyRouteMatch>) {
|
|
280
|
+
reconcileMatchPool(
|
|
281
|
+
nextMatches,
|
|
282
|
+
cachedMatchStoresById,
|
|
283
|
+
cachedMatchesId,
|
|
284
|
+
createMutableStore,
|
|
285
|
+
batch,
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return store
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function readPoolMatches(
|
|
293
|
+
pool: Map<string, MatchStore>,
|
|
294
|
+
ids: Array<string>,
|
|
295
|
+
): Array<AnyRouteMatch> {
|
|
296
|
+
const matches: Array<AnyRouteMatch> = []
|
|
297
|
+
for (const id of ids) {
|
|
298
|
+
const matchStore = pool.get(id)
|
|
299
|
+
if (matchStore) {
|
|
300
|
+
matches.push(matchStore.state)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return matches
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function reconcileMatchPool(
|
|
307
|
+
nextMatches: Array<AnyRouteMatch>,
|
|
308
|
+
pool: Map<string, MatchStore>,
|
|
309
|
+
idStore: RouterWritableStore<Array<string>>,
|
|
310
|
+
createMutableStore: MutableStoreFactory,
|
|
311
|
+
batch: RouterBatchFn,
|
|
312
|
+
): void {
|
|
313
|
+
const nextIds = nextMatches.map((d) => d.id)
|
|
314
|
+
const nextIdSet = new Set(nextIds)
|
|
315
|
+
|
|
316
|
+
batch(() => {
|
|
317
|
+
for (const id of pool.keys()) {
|
|
318
|
+
if (!nextIdSet.has(id)) {
|
|
319
|
+
pool.delete(id)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
for (const nextMatch of nextMatches) {
|
|
324
|
+
const existing = pool.get(nextMatch.id)
|
|
325
|
+
if (!existing) {
|
|
326
|
+
const matchStore = createMutableStore(nextMatch) as MatchStore
|
|
327
|
+
matchStore.routeId = nextMatch.routeId
|
|
328
|
+
pool.set(nextMatch.id, matchStore)
|
|
329
|
+
continue
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
existing.routeId = nextMatch.routeId
|
|
333
|
+
if (existing.state !== nextMatch) {
|
|
334
|
+
existing.setState(() => nextMatch)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (!arraysEqual(idStore.state, nextIds)) {
|
|
339
|
+
idStore.setState(() => nextIds)
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FromPathOption,
|
|
3
|
+
NavigateOptions,
|
|
4
|
+
PathParamOptions,
|
|
5
|
+
SearchParamOptions,
|
|
6
|
+
ToPathOption,
|
|
7
|
+
} from './link'
|
|
8
|
+
import type { RedirectOptions } from './redirect'
|
|
9
|
+
import type { RouteIds } from './routeInfo'
|
|
10
|
+
import type { AnyRouter, RegisteredRouter } from './router'
|
|
11
|
+
import type { UseParamsResult } from './useParams'
|
|
12
|
+
import type { UseSearchResult } from './useSearch'
|
|
13
|
+
import type { Constrain, ConstrainLiteral } from './utils'
|
|
14
|
+
|
|
15
|
+
export type ValidateFromPath<
|
|
16
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
17
|
+
TFrom = string,
|
|
18
|
+
> = FromPathOption<TRouter, TFrom>
|
|
19
|
+
|
|
20
|
+
export type ValidateToPath<
|
|
21
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
22
|
+
TTo extends string | undefined = undefined,
|
|
23
|
+
TFrom extends string = string,
|
|
24
|
+
> = ToPathOption<TRouter, TFrom, TTo>
|
|
25
|
+
|
|
26
|
+
export type ValidateSearch<
|
|
27
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
28
|
+
TTo extends string | undefined = undefined,
|
|
29
|
+
TFrom extends string = string,
|
|
30
|
+
> = SearchParamOptions<TRouter, TFrom, TTo>
|
|
31
|
+
|
|
32
|
+
export type ValidateParams<
|
|
33
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
34
|
+
TTo extends string | undefined = undefined,
|
|
35
|
+
TFrom extends string = string,
|
|
36
|
+
> = PathParamOptions<TRouter, TFrom, TTo>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
export type InferFrom<
|
|
42
|
+
TOptions,
|
|
43
|
+
TDefaultFrom extends string = string,
|
|
44
|
+
> = TOptions extends {
|
|
45
|
+
from: infer TFrom extends string
|
|
46
|
+
}
|
|
47
|
+
? TFrom
|
|
48
|
+
: TDefaultFrom
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
export type InferTo<TOptions> = TOptions extends {
|
|
54
|
+
to: infer TTo extends string
|
|
55
|
+
}
|
|
56
|
+
? TTo
|
|
57
|
+
: undefined
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
export type InferMaskTo<TOptions> = TOptions extends {
|
|
63
|
+
mask: { to: infer TTo extends string }
|
|
64
|
+
}
|
|
65
|
+
? TTo
|
|
66
|
+
: ''
|
|
67
|
+
|
|
68
|
+
export type InferMaskFrom<TOptions> = TOptions extends {
|
|
69
|
+
mask: { from: infer TFrom extends string }
|
|
70
|
+
}
|
|
71
|
+
? TFrom
|
|
72
|
+
: string
|
|
73
|
+
|
|
74
|
+
export type ValidateNavigateOptions<
|
|
75
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
76
|
+
TOptions = unknown,
|
|
77
|
+
TDefaultFrom extends string = string,
|
|
78
|
+
> = Constrain<
|
|
79
|
+
TOptions,
|
|
80
|
+
NavigateOptions<
|
|
81
|
+
TRouter,
|
|
82
|
+
InferFrom<TOptions, TDefaultFrom>,
|
|
83
|
+
InferTo<TOptions>,
|
|
84
|
+
InferMaskFrom<TOptions>,
|
|
85
|
+
InferMaskTo<TOptions>
|
|
86
|
+
>
|
|
87
|
+
>
|
|
88
|
+
|
|
89
|
+
export type ValidateNavigateOptionsArray<
|
|
90
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
91
|
+
TOptions extends ReadonlyArray<any> = ReadonlyArray<unknown>,
|
|
92
|
+
TDefaultFrom extends string = string,
|
|
93
|
+
> = {
|
|
94
|
+
[K in keyof TOptions]: ValidateNavigateOptions<
|
|
95
|
+
TRouter,
|
|
96
|
+
TOptions[K],
|
|
97
|
+
TDefaultFrom
|
|
98
|
+
>
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type ValidateRedirectOptions<
|
|
102
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
103
|
+
TOptions = unknown,
|
|
104
|
+
TDefaultFrom extends string = string,
|
|
105
|
+
> = Constrain<
|
|
106
|
+
TOptions,
|
|
107
|
+
RedirectOptions<
|
|
108
|
+
TRouter,
|
|
109
|
+
InferFrom<TOptions, TDefaultFrom>,
|
|
110
|
+
InferTo<TOptions>,
|
|
111
|
+
InferMaskFrom<TOptions>,
|
|
112
|
+
InferMaskTo<TOptions>
|
|
113
|
+
>
|
|
114
|
+
>
|
|
115
|
+
|
|
116
|
+
export type ValidateRedirectOptionsArray<
|
|
117
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
118
|
+
TOptions extends ReadonlyArray<any> = ReadonlyArray<unknown>,
|
|
119
|
+
TDefaultFrom extends string = string,
|
|
120
|
+
> = {
|
|
121
|
+
[K in keyof TOptions]: ValidateRedirectOptions<
|
|
122
|
+
TRouter,
|
|
123
|
+
TOptions[K],
|
|
124
|
+
TDefaultFrom
|
|
125
|
+
>
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type ValidateId<
|
|
129
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
130
|
+
TId extends string = string,
|
|
131
|
+
> = ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
export type InferStrict<TOptions> = TOptions extends {
|
|
137
|
+
strict: infer TStrict extends boolean
|
|
138
|
+
}
|
|
139
|
+
? TStrict
|
|
140
|
+
: true
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
export type InferShouldThrow<TOptions> = TOptions extends {
|
|
146
|
+
shouldThrow: infer TShouldThrow extends boolean
|
|
147
|
+
}
|
|
148
|
+
? TShouldThrow
|
|
149
|
+
: true
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
export type InferSelected<TOptions> = TOptions extends {
|
|
155
|
+
select: (...args: Array<any>) => infer TSelected
|
|
156
|
+
}
|
|
157
|
+
? TSelected
|
|
158
|
+
: unknown
|
|
159
|
+
|
|
160
|
+
export type ValidateUseSearchResult<
|
|
161
|
+
TOptions,
|
|
162
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
163
|
+
> = UseSearchResult<
|
|
164
|
+
TRouter,
|
|
165
|
+
InferFrom<TOptions>,
|
|
166
|
+
InferStrict<TOptions>,
|
|
167
|
+
InferSelected<TOptions>
|
|
168
|
+
>
|
|
169
|
+
|
|
170
|
+
export type ValidateUseParamsResult<
|
|
171
|
+
TOptions,
|
|
172
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
173
|
+
> = Constrain<
|
|
174
|
+
TOptions,
|
|
175
|
+
UseParamsResult<
|
|
176
|
+
TRouter,
|
|
177
|
+
InferFrom<TOptions>,
|
|
178
|
+
InferStrict<TOptions>,
|
|
179
|
+
InferSelected<TOptions>
|
|
180
|
+
>
|
|
181
|
+
>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AllLoaderData, RouteById } from './routeInfo'
|
|
2
|
+
import type { AnyRouter } from './router'
|
|
3
|
+
import type { Expand } from './utils'
|
|
4
|
+
|
|
5
|
+
export type ResolveUseLoaderData<
|
|
6
|
+
TRouter extends AnyRouter,
|
|
7
|
+
TFrom,
|
|
8
|
+
TStrict extends boolean,
|
|
9
|
+
> = TStrict extends false
|
|
10
|
+
? AllLoaderData<TRouter['routeTree']>
|
|
11
|
+
: Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderData']>
|
|
12
|
+
|
|
13
|
+
export type UseLoaderDataResult<
|
|
14
|
+
TRouter extends AnyRouter,
|
|
15
|
+
TFrom,
|
|
16
|
+
TStrict extends boolean,
|
|
17
|
+
TSelected,
|
|
18
|
+
> = unknown extends TSelected
|
|
19
|
+
? ResolveUseLoaderData<TRouter, TFrom, TStrict>
|
|
20
|
+
: TSelected
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RouteById } from './routeInfo'
|
|
2
|
+
import type { AnyRouter } from './router'
|
|
3
|
+
import type { Expand } from './utils'
|
|
4
|
+
|
|
5
|
+
export type ResolveUseLoaderDeps<TRouter extends AnyRouter, TFrom> = Expand<
|
|
6
|
+
RouteById<TRouter['routeTree'], TFrom>['types']['loaderDeps']
|
|
7
|
+
>
|
|
8
|
+
|
|
9
|
+
export type UseLoaderDepsResult<
|
|
10
|
+
TRouter extends AnyRouter,
|
|
11
|
+
TFrom,
|
|
12
|
+
TSelected,
|
|
13
|
+
> = unknown extends TSelected ? ResolveUseLoaderDeps<TRouter, TFrom> : TSelected
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NavigateOptions } from './link'
|
|
2
|
+
import type { RegisteredRouter } from './router'
|
|
3
|
+
|
|
4
|
+
export type UseNavigateResult<TDefaultFrom extends string> = <
|
|
5
|
+
TRouter extends RegisteredRouter,
|
|
6
|
+
TTo extends string | undefined,
|
|
7
|
+
TFrom extends string = TDefaultFrom,
|
|
8
|
+
TMaskFrom extends string = TFrom,
|
|
9
|
+
TMaskTo extends string = '',
|
|
10
|
+
>({
|
|
11
|
+
from,
|
|
12
|
+
...rest
|
|
13
|
+
}: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>
|
package/src/useParams.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AllParams, RouteById } from './routeInfo'
|
|
2
|
+
import type { AnyRouter } from './router'
|
|
3
|
+
import type { Expand } from './utils'
|
|
4
|
+
|
|
5
|
+
export type ResolveUseParams<
|
|
6
|
+
TRouter extends AnyRouter,
|
|
7
|
+
TFrom,
|
|
8
|
+
TStrict extends boolean,
|
|
9
|
+
> = TStrict extends false
|
|
10
|
+
? AllParams<TRouter['routeTree']>
|
|
11
|
+
: Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allParams']>
|
|
12
|
+
|
|
13
|
+
export type UseParamsResult<
|
|
14
|
+
TRouter extends AnyRouter,
|
|
15
|
+
TFrom,
|
|
16
|
+
TStrict extends boolean,
|
|
17
|
+
TSelected,
|
|
18
|
+
> = unknown extends TSelected
|
|
19
|
+
? ResolveUseParams<TRouter, TFrom, TStrict>
|
|
20
|
+
: TSelected
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AllContext, RouteById } from './routeInfo'
|
|
2
|
+
import type { AnyRouter } from './router'
|
|
3
|
+
import type { Expand, StrictOrFrom } from './utils'
|
|
4
|
+
|
|
5
|
+
export interface UseRouteContextBaseOptions<
|
|
6
|
+
TRouter extends AnyRouter,
|
|
7
|
+
TFrom,
|
|
8
|
+
TStrict extends boolean,
|
|
9
|
+
TSelected,
|
|
10
|
+
> {
|
|
11
|
+
select?: (
|
|
12
|
+
search: ResolveUseRouteContext<TRouter, TFrom, TStrict>,
|
|
13
|
+
) => TSelected
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type UseRouteContextOptions<
|
|
17
|
+
TRouter extends AnyRouter,
|
|
18
|
+
TFrom extends string | undefined,
|
|
19
|
+
TStrict extends boolean,
|
|
20
|
+
TSelected,
|
|
21
|
+
> = StrictOrFrom<TRouter, TFrom, TStrict> &
|
|
22
|
+
UseRouteContextBaseOptions<TRouter, TFrom, TStrict, TSelected>
|
|
23
|
+
|
|
24
|
+
export type ResolveUseRouteContext<
|
|
25
|
+
TRouter extends AnyRouter,
|
|
26
|
+
TFrom,
|
|
27
|
+
TStrict extends boolean,
|
|
28
|
+
> = TStrict extends false
|
|
29
|
+
? AllContext<TRouter['routeTree']>
|
|
30
|
+
: Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allContext']>
|
|
31
|
+
|
|
32
|
+
export type UseRouteContextResult<
|
|
33
|
+
TRouter extends AnyRouter,
|
|
34
|
+
TFrom,
|
|
35
|
+
TStrict extends boolean,
|
|
36
|
+
TSelected,
|
|
37
|
+
> = unknown extends TSelected
|
|
38
|
+
? ResolveUseRouteContext<TRouter, TFrom, TStrict>
|
|
39
|
+
: TSelected
|
package/src/useSearch.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FullSearchSchema, RouteById } from './routeInfo'
|
|
2
|
+
import type { AnyRouter } from './router'
|
|
3
|
+
import type { Expand } from './utils'
|
|
4
|
+
|
|
5
|
+
export type UseSearchResult<
|
|
6
|
+
TRouter extends AnyRouter,
|
|
7
|
+
TFrom,
|
|
8
|
+
TStrict extends boolean,
|
|
9
|
+
TSelected,
|
|
10
|
+
> = unknown extends TSelected
|
|
11
|
+
? ResolveUseSearch<TRouter, TFrom, TStrict>
|
|
12
|
+
: TSelected
|
|
13
|
+
|
|
14
|
+
export type ResolveUseSearch<
|
|
15
|
+
TRouter extends AnyRouter,
|
|
16
|
+
TFrom,
|
|
17
|
+
TStrict extends boolean,
|
|
18
|
+
> = TStrict extends false
|
|
19
|
+
? FullSearchSchema<TRouter['routeTree']>
|
|
20
|
+
: Expand<RouteById<TRouter['routeTree'], TFrom>['types']['fullSearchSchema']>
|