@depup/tanstack__react-router 1.167.5-depup.0 → 1.168.2-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.
- package/README.md +3 -4
- package/changes.json +2 -6
- package/dist/cjs/Match.cjs +147 -58
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +22 -24
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +36 -32
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/Transitioner.cjs +10 -16
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +4 -6
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +147 -59
- package/dist/cjs/headContentUtils.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.dev.cjs +1 -1
- package/dist/cjs/link.cjs +34 -29
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +20 -2
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/renderRouteNotFound.cjs +3 -3
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
- package/dist/cjs/route.cjs +0 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +2 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/routerStores.cjs +21 -0
- package/dist/cjs/routerStores.cjs.map +1 -0
- package/dist/cjs/routerStores.d.cts +7 -0
- package/dist/cjs/ssr/RouterClient.cjs +1 -1
- package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToStream.cjs +2 -2
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/cjs/useCanGoBack.cjs +7 -2
- package/dist/cjs/useCanGoBack.cjs.map +1 -1
- package/dist/cjs/useLocation.cjs +21 -2
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +35 -11
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useRouter.cjs +3 -3
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouterState.cjs +2 -2
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/esm/Match.js +148 -57
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +23 -24
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/Scripts.js +36 -32
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/Transitioner.js +10 -16
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/fileRoute.js +4 -4
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/headContentUtils.js +148 -60
- package/dist/esm/headContentUtils.js.map +1 -1
- package/dist/esm/index.dev.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/link.js +34 -29
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/not-found.js +20 -2
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/renderRouteNotFound.js +3 -2
- package/dist/esm/renderRouteNotFound.js.map +1 -1
- package/dist/esm/route.js +0 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.js +2 -1
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerStores.d.ts +7 -0
- package/dist/esm/routerStores.js +20 -0
- package/dist/esm/routerStores.js.map +1 -0
- package/dist/esm/ssr/RouterClient.js +1 -1
- package/dist/esm/ssr/RouterClient.js.map +1 -1
- package/dist/esm/ssr/renderRouterToStream.js +2 -2
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +1 -1
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/useCanGoBack.js +6 -2
- package/dist/esm/useCanGoBack.js.map +1 -1
- package/dist/esm/useLocation.js +20 -2
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.js +35 -10
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useRouter.js +3 -2
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.js +2 -2
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/llms/rules/api.d.ts +1 -1
- package/dist/llms/rules/api.js +13 -19
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +27 -6
- package/package.json +5 -11
- package/src/Match.tsx +274 -81
- package/src/Matches.tsx +48 -30
- package/src/Scripts.tsx +72 -44
- package/src/Transitioner.tsx +24 -16
- package/src/fileRoute.ts +7 -9
- package/src/headContentUtils.tsx +210 -27
- package/src/link.tsx +66 -71
- package/src/not-found.tsx +41 -4
- package/src/renderRouteNotFound.tsx +6 -6
- package/src/route.tsx +0 -2
- package/src/router.ts +2 -1
- package/src/routerStores.ts +26 -0
- package/src/ssr/RouterClient.tsx +1 -1
- package/src/ssr/renderRouterToStream.tsx +2 -2
- package/src/ssr/renderRouterToString.tsx +1 -1
- package/src/useCanGoBack.ts +14 -2
- package/src/useLocation.tsx +32 -5
- package/src/useMatch.tsx +68 -19
- package/src/useRouter.tsx +7 -5
- package/src/useRouterState.tsx +4 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _tanstack_router_core = require("@tanstack/router-core");
|
|
3
|
+
let _tanstack_react_store = require("@tanstack/react-store");
|
|
4
|
+
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
5
|
+
//#region src/routerStores.ts
|
|
6
|
+
var getStoreFactory = (opts) => {
|
|
7
|
+
if (_tanstack_router_core_isServer.isServer ?? opts.isServer) return {
|
|
8
|
+
createMutableStore: _tanstack_router_core.createNonReactiveMutableStore,
|
|
9
|
+
createReadonlyStore: _tanstack_router_core.createNonReactiveReadonlyStore,
|
|
10
|
+
batch: (fn) => fn()
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
createMutableStore: _tanstack_react_store.createStore,
|
|
14
|
+
createReadonlyStore: _tanstack_react_store.createStore,
|
|
15
|
+
batch: _tanstack_react_store.batch
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.getStoreFactory = getStoreFactory;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=routerStores.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routerStores.cjs","names":[],"sources":["../../src/routerStores.ts"],"sourcesContent":["import { batch, createStore } from '@tanstack/react-store'\nimport {\n createNonReactiveMutableStore,\n createNonReactiveReadonlyStore,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport type { Readable } from '@tanstack/react-store'\nimport type { GetStoreConfig } from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouterReadableStore<TValue> extends Readable<TValue> {}\n}\nexport const getStoreFactory: GetStoreConfig = (opts) => {\n if (isServer ?? opts.isServer) {\n return {\n createMutableStore: createNonReactiveMutableStore,\n createReadonlyStore: createNonReactiveReadonlyStore,\n batch: (fn) => fn(),\n }\n }\n return {\n createMutableStore: createStore,\n createReadonlyStore: createStore,\n batch: batch,\n }\n}\n"],"mappings":";;;;;AAYA,IAAa,mBAAmC,SAAS;AACvD,KAAI,+BAAA,YAAY,KAAK,SACnB,QAAO;EACL,oBAAoB,sBAAA;EACpB,qBAAqB,sBAAA;EACrB,QAAQ,OAAO,IAAI;EACpB;AAEH,QAAO;EACL,oBAAoB,sBAAA;EACpB,qBAAqB,sBAAA;EACd,OAAA,sBAAA;EACR"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Readable } from '@tanstack/react-store';
|
|
2
|
+
import { GetStoreConfig } from '@tanstack/router-core';
|
|
3
|
+
declare module '@tanstack/router-core' {
|
|
4
|
+
interface RouterReadableStore<TValue> extends Readable<TValue> {
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare const getStoreFactory: GetStoreConfig;
|
|
@@ -6,7 +6,7 @@ let _tanstack_router_core_ssr_client = require("@tanstack/router-core/ssr/client
|
|
|
6
6
|
//#region src/ssr/RouterClient.tsx
|
|
7
7
|
var hydrationPromise;
|
|
8
8
|
function RouterClient(props) {
|
|
9
|
-
if (!hydrationPromise) if (!props.router.state.
|
|
9
|
+
if (!hydrationPromise) if (!props.router.stores.matchesId.state.length) hydrationPromise = (0, _tanstack_router_core_ssr_client.hydrate)(props.router);
|
|
10
10
|
else hydrationPromise = Promise.resolve();
|
|
11
11
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_awaited.Await, {
|
|
12
12
|
promise: hydrationPromise,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterClient.cjs","names":[],"sources":["../../../src/ssr/RouterClient.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/router-core/ssr/client'\nimport { Await } from '../awaited'\nimport { RouterProvider } from '../RouterProvider'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nlet hydrationPromise: Promise<void | Array<Array<void>>> | undefined\n\nexport function RouterClient(props: { router: AnyRouter }) {\n if (!hydrationPromise) {\n if (!props.router.state.
|
|
1
|
+
{"version":3,"file":"RouterClient.cjs","names":[],"sources":["../../../src/ssr/RouterClient.tsx"],"sourcesContent":["import { hydrate } from '@tanstack/router-core/ssr/client'\nimport { Await } from '../awaited'\nimport { RouterProvider } from '../RouterProvider'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nlet hydrationPromise: Promise<void | Array<Array<void>>> | undefined\n\nexport function RouterClient(props: { router: AnyRouter }) {\n if (!hydrationPromise) {\n if (!props.router.stores.matchesId.state.length) {\n hydrationPromise = hydrate(props.router)\n } else {\n hydrationPromise = Promise.resolve()\n }\n }\n return (\n <Await\n promise={hydrationPromise}\n children={() => <RouterProvider router={props.router} />}\n />\n )\n}\n"],"mappings":";;;;;;AAKA,IAAI;AAEJ,SAAgB,aAAa,OAA8B;AACzD,KAAI,CAAC,iBACH,KAAI,CAAC,MAAM,OAAO,OAAO,UAAU,MAAM,OACvC,qBAAA,GAAA,iCAAA,SAA2B,MAAM,OAAO;KAExC,oBAAmB,QAAQ,SAAS;AAGxC,QACE,iBAAA,GAAA,kBAAA,KAAC,gBAAA,OAAD;EACE,SAAS;EACT,gBAAgB,iBAAA,GAAA,kBAAA,KAAC,uBAAA,gBAAD,EAAgB,QAAQ,MAAM,QAAU,CAAA;EACxD,CAAA"}
|
|
@@ -15,7 +15,7 @@ var renderRouterToStream = async ({ request, router, responseHeaders, children }
|
|
|
15
15
|
if ((0, isbot.isbot)(request.headers.get("User-Agent"))) await stream.allReady;
|
|
16
16
|
const responseStream = (0, _tanstack_router_core_ssr_server.transformReadableStreamWithRouter)(router, stream);
|
|
17
17
|
return new Response(responseStream, {
|
|
18
|
-
status: router.
|
|
18
|
+
status: router.stores.statusCode.state,
|
|
19
19
|
headers: responseHeaders
|
|
20
20
|
});
|
|
21
21
|
}
|
|
@@ -41,7 +41,7 @@ var renderRouterToStream = async ({ request, router, responseHeaders, children }
|
|
|
41
41
|
}
|
|
42
42
|
const responseStream = (0, _tanstack_router_core_ssr_server.transformPipeableStreamWithRouter)(router, reactAppPassthrough);
|
|
43
43
|
return new Response(responseStream, {
|
|
44
|
-
status: router.
|
|
44
|
+
status: router.stores.statusCode.state,
|
|
45
45
|
headers: responseHeaders
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouterToStream.cjs","names":[],"sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.
|
|
1
|
+
{"version":3,"file":"renderRouterToStream.cjs","names":[],"sources":["../../../src/ssr/renderRouterToStream.tsx"],"sourcesContent":["import { PassThrough } from 'node:stream'\nimport ReactDOMServer from 'react-dom/server'\nimport { isbot } from 'isbot'\nimport {\n transformPipeableStreamWithRouter,\n transformReadableStreamWithRouter,\n} from '@tanstack/router-core/ssr/server'\nimport type { AnyRouter } from '@tanstack/router-core'\nimport type { ReadableStream } from 'node:stream/web'\nimport type { ReactNode } from 'react'\n\nexport const renderRouterToStream = async ({\n request,\n router,\n responseHeaders,\n children,\n}: {\n request: Request\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n if (typeof ReactDOMServer.renderToReadableStream === 'function') {\n const stream = await ReactDOMServer.renderToReadableStream(children, {\n signal: request.signal,\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n })\n\n if (isbot(request.headers.get('User-Agent'))) {\n await stream.allReady\n }\n\n const responseStream = transformReadableStreamWithRouter(\n router,\n stream as unknown as ReadableStream,\n )\n return new Response(responseStream as any, {\n status: router.stores.statusCode.state,\n headers: responseHeaders,\n })\n }\n\n if (typeof ReactDOMServer.renderToPipeableStream === 'function') {\n const reactAppPassthrough = new PassThrough()\n\n try {\n const pipeable = ReactDOMServer.renderToPipeableStream(children, {\n nonce: router.options.ssr?.nonce,\n progressiveChunkSize: Number.POSITIVE_INFINITY,\n ...(isbot(request.headers.get('User-Agent'))\n ? {\n onAllReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }\n : {\n onShellReady() {\n pipeable.pipe(reactAppPassthrough)\n },\n }),\n onError: (error, info) => {\n console.error('Error in renderToPipeableStream:', error, info)\n // Destroy the passthrough stream on error\n if (!reactAppPassthrough.destroyed) {\n reactAppPassthrough.destroy(\n error instanceof Error ? error : new Error(String(error)),\n )\n }\n },\n })\n } catch (e) {\n console.error('Error in renderToPipeableStream:', e)\n reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)))\n }\n\n const responseStream = transformPipeableStreamWithRouter(\n router,\n reactAppPassthrough,\n )\n return new Response(responseStream as any, {\n status: router.stores.statusCode.state,\n headers: responseHeaders,\n })\n }\n\n throw new Error(\n 'No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.',\n )\n}\n"],"mappings":";;;;;;;AAWA,IAAa,uBAAuB,OAAO,EACzC,SACA,QACA,iBACA,eAMI;AACJ,KAAI,OAAO,iBAAA,QAAe,2BAA2B,YAAY;EAC/D,MAAM,SAAS,MAAM,iBAAA,QAAe,uBAAuB,UAAU;GACnE,QAAQ,QAAQ;GAChB,OAAO,OAAO,QAAQ,KAAK;GAC3B,sBAAsB,OAAO;GAC9B,CAAC;AAEF,OAAA,GAAA,MAAA,OAAU,QAAQ,QAAQ,IAAI,aAAa,CAAC,CAC1C,OAAM,OAAO;EAGf,MAAM,kBAAA,GAAA,iCAAA,mCACJ,QACA,OACD;AACD,SAAO,IAAI,SAAS,gBAAuB;GACzC,QAAQ,OAAO,OAAO,WAAW;GACjC,SAAS;GACV,CAAC;;AAGJ,KAAI,OAAO,iBAAA,QAAe,2BAA2B,YAAY;EAC/D,MAAM,sBAAsB,IAAI,YAAA,aAAa;AAE7C,MAAI;GACF,MAAM,WAAW,iBAAA,QAAe,uBAAuB,UAAU;IAC/D,OAAO,OAAO,QAAQ,KAAK;IAC3B,sBAAsB,OAAO;IAC7B,IAAA,GAAA,MAAA,OAAU,QAAQ,QAAQ,IAAI,aAAa,CAAC,GACxC,EACE,aAAa;AACX,cAAS,KAAK,oBAAoB;OAErC,GACD,EACE,eAAe;AACb,cAAS,KAAK,oBAAoB;OAErC;IACL,UAAU,OAAO,SAAS;AACxB,aAAQ,MAAM,oCAAoC,OAAO,KAAK;AAE9D,SAAI,CAAC,oBAAoB,UACvB,qBAAoB,QAClB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAC1D;;IAGN,CAAC;WACK,GAAG;AACV,WAAQ,MAAM,oCAAoC,EAAE;AACpD,uBAAoB,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC;;EAG5E,MAAM,kBAAA,GAAA,iCAAA,mCACJ,QACA,oBACD;AACD,SAAO,IAAI,SAAS,gBAAuB;GACzC,QAAQ,OAAO,OAAO,WAAW;GACjC,SAAS;GACV,CAAC;;AAGJ,OAAM,IAAI,MACR,sJACD"}
|
|
@@ -9,7 +9,7 @@ var renderRouterToString = async ({ router, responseHeaders, children }) => {
|
|
|
9
9
|
const injectedHtml = router.serverSsr.takeBufferedHtml();
|
|
10
10
|
if (injectedHtml) html = html.replace(`</body>`, () => `${injectedHtml}</body>`);
|
|
11
11
|
return new Response(`<!DOCTYPE html>${html}`, {
|
|
12
|
-
status: router.
|
|
12
|
+
status: router.stores.statusCode.state,
|
|
13
13
|
headers: responseHeaders
|
|
14
14
|
});
|
|
15
15
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouterToString.cjs","names":[],"sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n\n const injectedHtml = router.serverSsr!.takeBufferedHtml()\n if (injectedHtml) {\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n }\n\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.
|
|
1
|
+
{"version":3,"file":"renderRouterToString.cjs","names":[],"sources":["../../../src/ssr/renderRouterToString.tsx"],"sourcesContent":["import ReactDOMServer from 'react-dom/server'\nimport type { ReactNode } from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const renderRouterToString = async ({\n router,\n responseHeaders,\n children,\n}: {\n router: AnyRouter\n responseHeaders: Headers\n children: ReactNode\n}) => {\n try {\n let html = ReactDOMServer.renderToString(children)\n router.serverSsr!.setRenderFinished()\n\n const injectedHtml = router.serverSsr!.takeBufferedHtml()\n if (injectedHtml) {\n html = html.replace(`</body>`, () => `${injectedHtml}</body>`)\n }\n\n return new Response(`<!DOCTYPE html>${html}`, {\n status: router.stores.statusCode.state,\n headers: responseHeaders,\n })\n } catch (error) {\n console.error('Render to string error:', error)\n return new Response('Internal Server Error', {\n status: 500,\n headers: responseHeaders,\n })\n } finally {\n router.serverSsr?.cleanup()\n }\n}\n"],"mappings":";;;;AAIA,IAAa,uBAAuB,OAAO,EACzC,QACA,iBACA,eAKI;AACJ,KAAI;EACF,IAAI,OAAO,iBAAA,QAAe,eAAe,SAAS;AAClD,SAAO,UAAW,mBAAmB;EAErC,MAAM,eAAe,OAAO,UAAW,kBAAkB;AACzD,MAAI,aACF,QAAO,KAAK,QAAQ,iBAAiB,GAAG,aAAa,SAAS;AAGhE,SAAO,IAAI,SAAS,kBAAkB,QAAQ;GAC5C,QAAQ,OAAO,OAAO,WAAW;GACjC,SAAS;GACV,CAAC;UACK,OAAO;AACd,UAAQ,MAAM,2BAA2B,MAAM;AAC/C,SAAO,IAAI,SAAS,yBAAyB;GAC3C,QAAQ;GACR,SAAS;GACV,CAAC;WACM;AACR,SAAO,WAAW,SAAS"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_useRouter = require("./useRouter.cjs");
|
|
3
|
+
let _tanstack_react_store = require("@tanstack/react-store");
|
|
4
|
+
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
2
5
|
//#region src/useCanGoBack.ts
|
|
3
6
|
function useCanGoBack() {
|
|
4
|
-
|
|
7
|
+
const router = require_useRouter.useRouter();
|
|
8
|
+
if (_tanstack_router_core_isServer.isServer ?? router.isServer) return router.stores.location.state.state.__TSR_index !== 0;
|
|
9
|
+
return (0, _tanstack_react_store.useStore)(router.stores.location, (location) => location.state.__TSR_index !== 0);
|
|
5
10
|
}
|
|
6
11
|
//#endregion
|
|
7
12
|
exports.useCanGoBack = useCanGoBack;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCanGoBack.cjs","names":[],"sources":["../../src/useCanGoBack.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useCanGoBack.cjs","names":[],"sources":["../../src/useCanGoBack.ts"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\n\nexport function useCanGoBack() {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n return router.stores.location.state.state.__TSR_index !== 0\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(\n router.stores.location,\n (location) => location.state.__TSR_index !== 0,\n )\n}\n"],"mappings":";;;;;AAIA,SAAgB,eAAe;CAC7B,MAAM,SAAS,kBAAA,WAAW;AAE1B,KAAI,+BAAA,YAAY,OAAO,SACrB,QAAO,OAAO,OAAO,SAAS,MAAM,MAAM,gBAAgB;AAI5D,SAAA,GAAA,sBAAA,UACE,OAAO,OAAO,WACb,aAAa,SAAS,MAAM,gBAAgB,EAC9C"}
|
package/dist/cjs/useLocation.cjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_useRouter = require("./useRouter.cjs");
|
|
3
|
+
let _tanstack_router_core = require("@tanstack/router-core");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let _tanstack_react_store = require("@tanstack/react-store");
|
|
6
|
+
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
2
7
|
//#region src/useLocation.tsx
|
|
3
8
|
/**
|
|
4
9
|
* Read the current location from the router state with optional selection.
|
|
@@ -12,7 +17,21 @@ const require_useRouterState = require("./useRouterState.cjs");
|
|
|
12
17
|
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook
|
|
13
18
|
*/
|
|
14
19
|
function useLocation(opts) {
|
|
15
|
-
|
|
20
|
+
const router = require_useRouter.useRouter();
|
|
21
|
+
if (_tanstack_router_core_isServer.isServer ?? router.isServer) {
|
|
22
|
+
const location = router.stores.location.state;
|
|
23
|
+
return opts?.select ? opts.select(location) : location;
|
|
24
|
+
}
|
|
25
|
+
const previousResult = (0, react.useRef)(void 0);
|
|
26
|
+
return (0, _tanstack_react_store.useStore)(router.stores.location, (location) => {
|
|
27
|
+
const selected = opts?.select ? opts.select(location) : location;
|
|
28
|
+
if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {
|
|
29
|
+
const shared = (0, _tanstack_router_core.replaceEqualDeep)(previousResult.current, selected);
|
|
30
|
+
previousResult.current = shared;
|
|
31
|
+
return shared;
|
|
32
|
+
}
|
|
33
|
+
return selected;
|
|
34
|
+
});
|
|
16
35
|
}
|
|
17
36
|
//#endregion
|
|
18
37
|
exports.useLocation = useLocation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocation.cjs","names":[],"sources":["../../src/useLocation.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useLocation.cjs","names":[],"sources":["../../src/useLocation.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 StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterState,\n} from '@tanstack/router-core'\n\nexport interface UseLocationBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing extends boolean = boolean,\n> {\n select?: (\n state: RouterState<TRouter['routeTree']>['location'],\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseLocationResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected\n ? RouterState<TRouter['routeTree']>['location']\n : TSelected\n\n/**\n * Read the current location from the router state with optional selection.\n * Useful for subscribing to just the pieces of location you care about.\n *\n * Options:\n * - `select`: Project the `location` object to a derived value\n * - `structuralSharing`: Enable structural sharing for stable references\n *\n * @returns The current location (or selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook\n */\nexport function useLocation<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseLocationBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseLocationResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n\n if (isServer ?? router.isServer) {\n const location = router.stores.location.state\n return (\n opts?.select ? opts.select(location as any) : location\n ) as UseLocationResult<TRouter, TSelected>\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(router.stores.location, (location) => {\n const selected = (\n opts?.select ? opts.select(location as any) : location\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseLocationResult<TRouter, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2CA,SAAgB,YAKd,MAEuC;CACvC,MAAM,SAAS,kBAAA,WAAoB;AAEnC,KAAI,+BAAA,YAAY,OAAO,UAAU;EAC/B,MAAM,WAAW,OAAO,OAAO,SAAS;AACxC,SACE,MAAM,SAAS,KAAK,OAAO,SAAgB,GAAG;;CAIlD,MAAM,kBAAA,GAAA,MAAA,QAE6D,KAAA,EAAU;AAG7E,SAAA,GAAA,sBAAA,UAAgB,OAAO,OAAO,WAAW,aAAa;EACpD,MAAM,WACJ,MAAM,SAAS,KAAK,OAAO,SAAgB,GAAG;AAGhD,MAAI,MAAM,qBAAqB,OAAO,QAAQ,0BAA0B;GACtE,MAAM,UAAA,GAAA,sBAAA,kBAA0B,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
|
package/dist/cjs/useMatch.cjs
CHANGED
|
@@ -1,25 +1,49 @@
|
|
|
1
1
|
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_useRouterState = require("./useRouterState.cjs");
|
|
3
2
|
const require_matchContext = require("./matchContext.cjs");
|
|
3
|
+
const require_useRouter = require("./useRouter.cjs");
|
|
4
|
+
let _tanstack_router_core = require("@tanstack/router-core");
|
|
4
5
|
let react = require("react");
|
|
5
6
|
react = require_runtime.__toESM(react);
|
|
6
|
-
let
|
|
7
|
-
|
|
7
|
+
let _tanstack_react_store = require("@tanstack/react-store");
|
|
8
|
+
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
8
9
|
//#region src/useMatch.tsx
|
|
10
|
+
var dummyStore = {
|
|
11
|
+
state: void 0,
|
|
12
|
+
get: () => void 0,
|
|
13
|
+
subscribe: () => () => {}
|
|
14
|
+
};
|
|
9
15
|
/**
|
|
10
16
|
* Read and select the nearest or targeted route match.
|
|
11
17
|
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook
|
|
12
18
|
*/
|
|
13
19
|
function useMatch(opts) {
|
|
20
|
+
const router = require_useRouter.useRouter();
|
|
14
21
|
const nearestMatchId = react.useContext(opts.from ? require_matchContext.dummyMatchContext : require_matchContext.matchContext);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const key = opts.from ?? nearestMatchId;
|
|
23
|
+
const matchStore = key ? opts.from ? router.stores.getMatchStoreByRouteId(key) : router.stores.activeMatchStoresById.get(key) : void 0;
|
|
24
|
+
if (_tanstack_router_core_isServer.isServer ?? router.isServer) {
|
|
25
|
+
const match = matchStore?.state;
|
|
26
|
+
if ((opts.shouldThrow ?? true) && !match) {
|
|
27
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
|
|
28
|
+
(0, _tanstack_router_core.invariant)();
|
|
29
|
+
}
|
|
30
|
+
if (match === void 0) return;
|
|
31
|
+
return opts.select ? opts.select(match) : match;
|
|
32
|
+
}
|
|
33
|
+
const previousResult = react.useRef(void 0);
|
|
34
|
+
return (0, _tanstack_react_store.useStore)(matchStore ?? dummyStore, (match) => {
|
|
35
|
+
if ((opts.shouldThrow ?? true) && !match) {
|
|
36
|
+
if (process.env.NODE_ENV !== "production") throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
|
|
37
|
+
(0, _tanstack_router_core.invariant)();
|
|
38
|
+
}
|
|
39
|
+
if (match === void 0) return;
|
|
40
|
+
const selected = opts.select ? opts.select(match) : match;
|
|
41
|
+
if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {
|
|
42
|
+
const shared = (0, _tanstack_router_core.replaceEqualDeep)(previousResult.current, selected);
|
|
43
|
+
previousResult.current = shared;
|
|
44
|
+
return shared;
|
|
45
|
+
}
|
|
46
|
+
return selected;
|
|
23
47
|
});
|
|
24
48
|
}
|
|
25
49
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.cjs","names":[],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport
|
|
1
|
+
{"version":3,"file":"useMatch.cjs","names":[],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { invariant, replaceEqualDeep } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { dummyMatchContext, matchContext } from './matchContext'\nimport { useRouter } from './useRouter'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRouter,\n MakeRouteMatch,\n MakeRouteMatchUnion,\n RegisteredRouter,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n} from '@tanstack/router-core'\n\nconst dummyStore = {\n state: undefined,\n get: () => undefined,\n subscribe: () => () => {},\n} as any\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchBaseOptions<\n TRouter,\n TFrom,\n true,\n true,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n) => UseMatchResult<TRouter, TFrom, true, TSelected>\n\nexport type UseMatchOptions<\n TRouter extends AnyRouter,\n TFrom extends string | undefined,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n TStructuralSharing extends boolean,\n> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<\n TRouter,\n TFrom,\n TStrict,\n TThrow,\n TSelected,\n TStructuralSharing\n > &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>\n\nexport type UseMatchResult<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TSelected,\n> = unknown extends TSelected\n ? TStrict extends true\n ? MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>\n : MakeRouteMatchUnion<TRouter>\n : TSelected\n\n/**\n * Read and select the nearest or targeted route match.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook\n */\nexport function useMatch<\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: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected,\n TStructuralSharing\n >,\n): ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow> {\n const router = useRouter<TRouter>()\n const nearestMatchId = React.useContext(\n opts.from ? dummyMatchContext : matchContext,\n )\n\n const key = opts.from ?? nearestMatchId\n const matchStore = key\n ? opts.from\n ? router.stores.getMatchStoreByRouteId(key)\n : router.stores.activeMatchStoresById.get(key)\n : undefined\n\n if (isServer ?? router.isServer) {\n const match = matchStore?.state\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined as any\n }\n\n return (opts.select ? opts.select(match as any) : match) as any\n }\n\n const previousResult =\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n return useStore(matchStore ?? dummyStore, (match) => {\n if ((opts.shouldThrow ?? true) && !match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n }\n\n invariant()\n }\n\n if (match === undefined) {\n return undefined\n }\n\n const selected = (\n opts.select ? opts.select(match as any) : match\n ) as ValidateSelected<TRouter, TSelected, TStructuralSharing>\n\n if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as any\n}\n"],"mappings":";;;;;;;;;AAoBA,IAAM,aAAa;CACjB,OAAO,KAAA;CACP,WAAW,KAAA;CACX,uBAAuB;CACxB;;;;;AAiED,SAAgB,SAQd,MAQ6E;CAC7E,MAAM,SAAS,kBAAA,WAAoB;CACnC,MAAM,iBAAiB,MAAM,WAC3B,KAAK,OAAO,qBAAA,oBAAoB,qBAAA,aACjC;CAED,MAAM,MAAM,KAAK,QAAQ;CACzB,MAAM,aAAa,MACf,KAAK,OACH,OAAO,OAAO,uBAAuB,IAAI,GACzC,OAAO,OAAO,sBAAsB,IAAI,IAAI,GAC9C,KAAA;AAEJ,KAAI,+BAAA,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,YAAY;AAC1B,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,IAAA,GAAA,sBAAA,YAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;AAGF,SAAQ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;;CAGpD,MAAM,iBAEJ,MAAM,OACJ,KAAA,EACD;AAGH,SAAA,GAAA,sBAAA,UAAgB,cAAc,aAAa,UAAU;AACnD,OAAK,KAAK,eAAe,SAAS,CAAC,OAAO;AACxC,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,oCAAoC,KAAK,OAAO,yBAAyB,KAAK,KAAK,KAAK,qBACzF;AAGH,IAAA,GAAA,sBAAA,YAAW;;AAGb,MAAI,UAAU,KAAA,EACZ;EAGF,MAAM,WACJ,KAAK,SAAS,KAAK,OAAO,MAAa,GAAG;AAG5C,MAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;GACrE,MAAM,UAAA,GAAA,sBAAA,kBAA0B,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP"}
|
package/dist/cjs/useRouter.cjs
CHANGED
|
@@ -2,8 +2,6 @@ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
|
2
2
|
const require_routerContext = require("./routerContext.cjs");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
react = require_runtime.__toESM(react);
|
|
5
|
-
let tiny_warning = require("tiny-warning");
|
|
6
|
-
tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
7
5
|
//#region src/useRouter.tsx
|
|
8
6
|
/**
|
|
9
7
|
* Access the current TanStack Router instance from React context.
|
|
@@ -17,7 +15,9 @@ tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
|
17
15
|
*/
|
|
18
16
|
function useRouter(opts) {
|
|
19
17
|
const value = react.useContext(require_routerContext.routerContext);
|
|
20
|
-
(
|
|
18
|
+
if (process.env.NODE_ENV !== "production") {
|
|
19
|
+
if ((opts?.warn ?? true) && !value) console.warn("Warning: useRouter must be used inside a <RouterProvider> component!");
|
|
20
|
+
}
|
|
21
21
|
return value;
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.cjs","names":[],"sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport
|
|
1
|
+
{"version":3,"file":"useRouter.cjs","names":[],"sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\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 if (process.env.NODE_ENV !== 'production') {\n if ((opts?.warn ?? true) && !value) {\n console.warn(\n 'Warning: useRouter must be used inside a <RouterProvider> component!',\n )\n }\n }\n return value as any\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,UAAwD,MAE5D;CACV,MAAM,QAAQ,MAAM,WAAW,sBAAA,cAAc;AAC7C,KAAA,QAAA,IAAA,aAA6B;OACtB,MAAM,QAAQ,SAAS,CAAC,MAC3B,SAAQ,KACN,uEACD;;AAGL,QAAO"}
|
|
@@ -21,11 +21,11 @@ function useRouterState(opts) {
|
|
|
21
21
|
const contextRouter = require_useRouter.useRouter({ warn: opts?.router === void 0 });
|
|
22
22
|
const router = opts?.router || contextRouter;
|
|
23
23
|
if (_tanstack_router_core_isServer.isServer ?? router.isServer) {
|
|
24
|
-
const state = router.state;
|
|
24
|
+
const state = router.stores.__store.state;
|
|
25
25
|
return opts?.select ? opts.select(state) : state;
|
|
26
26
|
}
|
|
27
27
|
const previousResult = (0, react.useRef)(void 0);
|
|
28
|
-
return (0, _tanstack_react_store.useStore)(router.__store, (state) => {
|
|
28
|
+
return (0, _tanstack_react_store.useStore)(router.stores.__store, (state) => {
|
|
29
29
|
if (opts?.select) {
|
|
30
30
|
if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {
|
|
31
31
|
const newSlice = (0, _tanstack_router_core.replaceEqualDeep)(previousResult.current, opts.select(state));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouterState.cjs","names":[],"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
|
|
1
|
+
{"version":3,"file":"useRouterState.cjs","names":[],"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.stores.__store.state as RouterState<\n TRouter['routeTree']\n >\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.stores.__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"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,eAKd,MAC0C;CAC1C,MAAM,gBAAgB,kBAAA,UAAmB,EACvC,MAAM,MAAM,WAAW,KAAA,GACxB,CAAC;CACF,MAAM,SAAS,MAAM,UAAU;AAK/B,KADkB,+BAAA,YAAY,OAAO,UACtB;EACb,MAAM,QAAQ,OAAO,OAAO,QAAQ;AAGpC,SAAQ,MAAM,SAAS,KAAK,OAAO,MAAM,GAAG;;CAM9C,MAAM,kBAAA,GAAA,MAAA,QAE6D,KAAA,EAAU;AAG7E,SAAA,GAAA,sBAAA,UAAgB,OAAO,OAAO,UAAU,UAAU;AAChD,MAAI,MAAM,QAAQ;AAChB,OAAI,KAAK,qBAAqB,OAAO,QAAQ,0BAA0B;IACrE,MAAM,YAAA,GAAA,sBAAA,kBACJ,eAAe,SACf,KAAK,OAAO,MAAM,CACnB;AACD,mBAAe,UAAU;AACzB,WAAO;;AAET,UAAO,KAAK,OAAO,MAAM;;AAE3B,SAAO;GACP"}
|