@tanstack/solid-router 2.0.0-alpha.9 → 2.0.0-beta.10
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/dist/cjs/HeadContent.cjs +2 -2
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/HeadContent.d.cts +5 -1
- package/dist/cjs/HeadContent.dev.cjs +2 -2
- package/dist/cjs/HeadContent.dev.cjs.map +1 -1
- package/dist/cjs/HeadContent.dev.d.cts +2 -1
- package/dist/cjs/Match.cjs +19 -11
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +2 -4
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/ScrollRestoration.cjs +1 -11
- package/dist/cjs/ScrollRestoration.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +4 -5
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +5 -2
- package/dist/cjs/headContentUtils.cjs.map +1 -1
- package/dist/cjs/headContentUtils.d.cts +2 -2
- package/dist/cjs/not-found.cjs +9 -2
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +4 -1
- package/dist/cjs/renderRouteNotFound.cjs +4 -4
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
- package/dist/cjs/router.cjs +0 -8
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +4 -17
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +2 -2
- package/dist/cjs/useMatch.cjs +4 -3
- 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/esm/HeadContent.d.ts +5 -1
- package/dist/esm/HeadContent.dev.d.ts +2 -1
- package/dist/esm/HeadContent.dev.js +2 -2
- package/dist/esm/HeadContent.dev.js.map +1 -1
- package/dist/esm/HeadContent.js +2 -2
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Match.js +21 -11
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +2 -3
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/ScrollRestoration.js +2 -12
- package/dist/esm/ScrollRestoration.js.map +1 -1
- package/dist/esm/fileRoute.js +4 -3
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/headContentUtils.d.ts +2 -2
- package/dist/esm/headContentUtils.js +6 -3
- package/dist/esm/headContentUtils.js.map +1 -1
- package/dist/esm/not-found.d.ts +4 -1
- package/dist/esm/not-found.js +9 -3
- 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/router.js +0 -8
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.js +4 -17
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/useBlocker.d.ts +2 -2
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useMatch.js +5 -3
- 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/source/HeadContent.d.ts +5 -1
- package/dist/source/HeadContent.dev.d.ts +2 -1
- package/dist/source/HeadContent.dev.jsx +2 -2
- package/dist/source/HeadContent.dev.jsx.map +1 -1
- package/dist/source/HeadContent.jsx +2 -2
- package/dist/source/HeadContent.jsx.map +1 -1
- package/dist/source/Match.jsx +34 -15
- package/dist/source/Match.jsx.map +1 -1
- package/dist/source/Matches.jsx +2 -3
- package/dist/source/Matches.jsx.map +1 -1
- package/dist/source/ScrollRestoration.jsx +2 -18
- package/dist/source/ScrollRestoration.jsx.map +1 -1
- package/dist/source/fileRoute.js +4 -3
- package/dist/source/fileRoute.js.map +1 -1
- package/dist/source/headContentUtils.d.ts +2 -2
- package/dist/source/headContentUtils.jsx +12 -4
- package/dist/source/headContentUtils.jsx.map +1 -1
- package/dist/source/not-found.d.ts +4 -1
- package/dist/source/not-found.jsx +17 -4
- package/dist/source/not-found.jsx.map +1 -1
- package/dist/source/renderRouteNotFound.jsx +4 -3
- package/dist/source/renderRouteNotFound.jsx.map +1 -1
- package/dist/source/router.js +0 -11
- package/dist/source/router.js.map +1 -1
- package/dist/source/scroll-restoration.jsx +4 -24
- package/dist/source/scroll-restoration.jsx.map +1 -1
- package/dist/source/useBlocker.d.ts +2 -2
- package/dist/source/useMatch.jsx +7 -3
- package/dist/source/useMatch.jsx.map +1 -1
- package/dist/source/useRouter.jsx +5 -2
- package/dist/source/useRouter.jsx.map +1 -1
- package/package.json +6 -7
- package/src/HeadContent.dev.tsx +3 -2
- package/src/HeadContent.tsx +7 -2
- package/src/Match.tsx +44 -16
- package/src/Matches.tsx +3 -5
- package/src/ScrollRestoration.tsx +2 -22
- package/src/fileRoute.ts +7 -8
- package/src/headContentUtils.tsx +22 -5
- package/src/not-found.tsx +25 -5
- package/src/renderRouteNotFound.tsx +6 -6
- package/src/router.ts +0 -9
- package/src/scroll-restoration.tsx +5 -36
- package/src/useBlocker.tsx +2 -2
- package/src/useMatch.tsx +9 -6
- package/src/useRouter.tsx +7 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headContentUtils.cjs","names":["Solid","escapeHtml","useRouter","RouterManagedTag","useTags","router","nonce","options","ssr","getTagKey","tag","JSON","stringify","activeMatches","createMemo","stores","activeMatchesSnapshot","state","routeMeta","map","match","meta","filter","Boolean","Accessor","Array","resultMeta","metaByAttribute","Record","title","routeMetasArray","i","length","metas","j","m","children","json","push","attrs","type","attribute","name","property","content","reverse","links","matches","constructed","flat","link","manifest","assets","routes","routeId","asset","preloadLinks","looseRoutesById","forEach","route","id","preloads","preload","rel","href","styles","style","headScripts","script","prev","next","uniqBy","every","index","arr","T","fn","item","seen","Set","key","has","add"],"sources":["../../src/headContentUtils.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { escapeHtml } from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\n/**\n * Build the list of head/link/meta/script tags to render for active matches.\n * Used internally by `HeadContent`.\n */\nexport const useTags = () => {\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n const getTagKey = (tag: RouterManagedTag) => JSON.stringify(tag)\n const activeMatches = Solid.createMemo(\n () => router.stores.activeMatchesSnapshot.state,\n )\n const routeMeta = Solid.createMemo(() =>\n activeMatches()\n .map((match) => match.meta!)\n .filter(Boolean),\n )\n\n const meta: Solid.Accessor<Array<RouterManagedTag>> = Solid.createMemo(() => {\n const resultMeta: Array<RouterManagedTag> = []\n const metaByAttribute: Record<string, true> = {}\n let title: RouterManagedTag | undefined\n const routeMetasArray = routeMeta()\n for (let i = routeMetasArray.length - 1; i >= 0; i--) {\n const metas = routeMetasArray[i]!\n for (let j = metas.length - 1; j >= 0; j--) {\n const m = metas[j]\n if (!m) continue\n\n if (m.title) {\n if (!title) {\n title = {\n tag: 'title',\n children: m.title,\n }\n }\n } else if ('script:ld+json' in m) {\n // Handle JSON-LD structured data\n // Content is HTML-escaped to prevent XSS when injected via innerHTML\n try {\n const json = JSON.stringify(m['script:ld+json'])\n resultMeta.push({\n tag: 'script',\n attrs: {\n type: 'application/ld+json',\n },\n children: escapeHtml(json),\n })\n } catch {\n // Skip invalid JSON-LD objects\n }\n } else {\n const attribute = m.name ?? m.property\n if (attribute) {\n if (metaByAttribute[attribute]) {\n continue\n } else {\n metaByAttribute[attribute] = true\n }\n }\n\n resultMeta.push({\n tag: 'meta',\n attrs: {\n ...m,\n nonce,\n },\n })\n }\n }\n }\n\n if (title) {\n resultMeta.push(title)\n }\n\n if (router.options.ssr?.nonce) {\n resultMeta.push({\n tag: 'meta',\n attrs: {\n property: 'csp-nonce',\n content: router.options.ssr.nonce,\n },\n })\n }\n resultMeta.reverse()\n\n return resultMeta\n })\n\n const links = Solid.createMemo(() => {\n const matches = activeMatches()\n const constructed = matches\n .map((match) => match.links!)\n .filter(Boolean)\n .flat(1)\n .map((link) => ({\n tag: 'link',\n attrs: {\n ...link,\n nonce,\n },\n })) satisfies Array<RouterManagedTag>\n\n const manifest = router.ssr?.manifest\n\n const assets = matches\n .map((match) => manifest?.routes[match.routeId]?.assets ?? [])\n .filter(Boolean)\n .flat(1)\n .filter((asset) => asset.tag === 'link')\n .map(\n (asset) =>\n ({\n tag: 'link',\n attrs: { ...asset.attrs, nonce },\n }) satisfies RouterManagedTag,\n )\n\n return [...constructed, ...assets]\n })\n\n const preloadLinks = Solid.createMemo(() => {\n const matches = activeMatches()\n const preloadLinks: Array<RouterManagedTag> = []\n\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n router.ssr?.manifest?.routes[route.id]?.preloads\n ?.filter(Boolean)\n .forEach((preload) => {\n preloadLinks.push({\n tag: 'link',\n attrs: {\n rel: 'modulepreload',\n href: preload,\n nonce,\n },\n })\n }),\n )\n\n return preloadLinks\n })\n\n const styles = Solid.createMemo(() =>\n (\n activeMatches()\n .map((match) => match.styles!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...style }) => ({\n tag: 'style',\n attrs: {\n ...style,\n nonce,\n },\n children,\n })),\n )\n\n const headScripts = Solid.createMemo(() =>\n (\n activeMatches()\n .map((match) => match.headScripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n nonce,\n },\n children,\n })),\n )\n\n return Solid.createMemo((prev: Array<RouterManagedTag> | undefined) => {\n const next = uniqBy(\n [\n ...meta(),\n ...preloadLinks(),\n ...links(),\n ...styles(),\n ...headScripts(),\n ] as Array<RouterManagedTag>,\n getTagKey,\n )\n\n if (\n prev &&\n prev.length === next.length &&\n prev.every((tag, index) => getTagKey(tag) === getTagKey(next[index]!))\n ) {\n return prev\n }\n\n return next\n })\n}\n\nexport function uniqBy<T>(arr: Array<T>, fn: (item: T) => string) {\n const seen = new Set<string>()\n return arr.filter((item) => {\n const key = fn(item)\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n"],"mappings":";;;;;;;;;;AASA,IAAaI,gBAAgB;CAC3B,MAAMC,SAASH,kBAAAA,WAAW;CAC1B,MAAMI,QAAQD,OAAOE,QAAQC,KAAKF;CAClC,MAAMG,aAAaC,QAA0BC,KAAKC,UAAUF,IAAI;CAChE,MAAMG,gBAAgBb,SAAMc,iBACpBT,OAAOU,OAAOC,sBAAsBC,MAC3C;CACD,MAAMC,YAAYlB,SAAMc,iBACtBD,eAAe,CACZM,KAAKC,UAAUA,MAAMC,KAAM,CAC3BC,OAAOC,QACZ,CAAC;CAED,MAAMF,OAAgDrB,SAAMc,iBAAiB;EAC3E,MAAMY,aAAsC,EAAE;EAC9C,MAAMC,kBAAwC,EAAE;EAChD,IAAIE;EACJ,MAAMC,kBAAkBZ,WAAW;AACnC,OAAK,IAAIa,IAAID,gBAAgBE,SAAS,GAAGD,KAAK,GAAGA,KAAK;GACpD,MAAME,QAAQH,gBAAgBC;AAC9B,QAAK,IAAIG,IAAID,MAAMD,SAAS,GAAGE,KAAK,GAAGA,KAAK;IAC1C,MAAMC,IAAIF,MAAMC;AAChB,QAAI,CAACC,EAAG;AAER,QAAIA,EAAEN;SACA,CAACA,MACHA,SAAQ;MACNnB,KAAK;MACL0B,UAAUD,EAAEN;MACb;eAEM,oBAAoBM,EAG7B,KAAI;KACF,MAAME,OAAO1B,KAAKC,UAAUuB,EAAE,kBAAkB;AAChDT,gBAAWY,KAAK;MACd5B,KAAK;MACL6B,OAAO,EACLC,MAAM,uBACP;MACDJ,WAAAA,GAAAA,sBAAAA,YAAqBC,KAAI;MAC1B,CAAC;YACI;SAGH;KACL,MAAMI,YAAYN,EAAEO,QAAQP,EAAEQ;AAC9B,SAAIF,UACF,KAAId,gBAAgBc,WAClB;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id","escapeHtml","getAssetCrossOrigin","resolveManifestAssetLink","useRouter","AssetCrossOriginConfig","RouterManagedTag","useTags","assetCrossOrigin","router","nonce","options","ssr","getTagKey","tag","JSON","stringify","activeMatches","createMemo","stores","activeMatchesSnapshot","state","routeMeta","map","match","meta","filter","Boolean","Accessor","Array","resultMeta","metaByAttribute","Record","title","routeMetasArray","i","length","metas","j","m","children","json","push","attrs","type","attribute","name","property","content","reverse","links","matches","constructed","flat","link","manifest","assets","routes","routeId","asset","crossOrigin","preloadLinks","looseRoutesById","forEach","route","id","preloads","preload","preloadLink","rel","href","styles","style","headScripts","script","prev","next","uniqBy","every","index","arr","T","fn","item","seen","Set","key","has","add"],"sources":["../../src/headContentUtils.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport {\n escapeHtml,\n getAssetCrossOrigin,\n resolveManifestAssetLink,\n} from '@tanstack/router-core'\nimport { useRouter } from './useRouter'\nimport type {\n AssetCrossOriginConfig,\n RouterManagedTag,\n} from '@tanstack/router-core'\n\n/**\n * Build the list of head/link/meta/script tags to render for active matches.\n * Used internally by `HeadContent`.\n */\nexport const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n const getTagKey = (tag: RouterManagedTag) => JSON.stringify(tag)\n const activeMatches = Solid.createMemo(\n () => router.stores.activeMatchesSnapshot.state,\n )\n const routeMeta = Solid.createMemo(() =>\n activeMatches()\n .map((match) => match.meta!)\n .filter(Boolean),\n )\n\n const meta: Solid.Accessor<Array<RouterManagedTag>> = Solid.createMemo(() => {\n const resultMeta: Array<RouterManagedTag> = []\n const metaByAttribute: Record<string, true> = {}\n let title: RouterManagedTag | undefined\n const routeMetasArray = routeMeta()\n for (let i = routeMetasArray.length - 1; i >= 0; i--) {\n const metas = routeMetasArray[i]!\n for (let j = metas.length - 1; j >= 0; j--) {\n const m = metas[j]\n if (!m) continue\n\n if (m.title) {\n if (!title) {\n title = {\n tag: 'title',\n children: m.title,\n }\n }\n } else if ('script:ld+json' in m) {\n // Handle JSON-LD structured data\n // Content is HTML-escaped to prevent XSS when injected via innerHTML\n try {\n const json = JSON.stringify(m['script:ld+json'])\n resultMeta.push({\n tag: 'script',\n attrs: {\n type: 'application/ld+json',\n },\n children: escapeHtml(json),\n })\n } catch {\n // Skip invalid JSON-LD objects\n }\n } else {\n const attribute = m.name ?? m.property\n if (attribute) {\n if (metaByAttribute[attribute]) {\n continue\n } else {\n metaByAttribute[attribute] = true\n }\n }\n\n resultMeta.push({\n tag: 'meta',\n attrs: {\n ...m,\n nonce,\n },\n })\n }\n }\n }\n\n if (title) {\n resultMeta.push(title)\n }\n\n if (router.options.ssr?.nonce) {\n resultMeta.push({\n tag: 'meta',\n attrs: {\n property: 'csp-nonce',\n content: router.options.ssr.nonce,\n },\n })\n }\n resultMeta.reverse()\n\n return resultMeta\n })\n\n const links = Solid.createMemo(() => {\n const matches = activeMatches()\n const constructed = matches\n .map((match) => match.links!)\n .filter(Boolean)\n .flat(1)\n .map((link) => ({\n tag: 'link',\n attrs: {\n ...link,\n nonce,\n },\n })) satisfies Array<RouterManagedTag>\n\n const manifest = router.ssr?.manifest\n\n const assets = matches\n .map((match) => manifest?.routes[match.routeId]?.assets ?? [])\n .filter(Boolean)\n .flat(1)\n .filter((asset) => asset.tag === 'link')\n .map(\n (asset) =>\n ({\n tag: 'link',\n attrs: {\n ...asset.attrs,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'stylesheet') ??\n asset.attrs?.crossOrigin,\n nonce,\n },\n }) satisfies RouterManagedTag,\n )\n\n return [...constructed, ...assets]\n })\n\n const preloadLinks = Solid.createMemo(() => {\n const matches = activeMatches()\n const preloadLinks: Array<RouterManagedTag> = []\n\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n router.ssr?.manifest?.routes[route.id]?.preloads\n ?.filter(Boolean)\n .forEach((preload) => {\n const preloadLink = resolveManifestAssetLink(preload)\n preloadLinks.push({\n tag: 'link',\n attrs: {\n rel: 'modulepreload',\n href: preloadLink.href,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'modulepreload') ??\n preloadLink.crossOrigin,\n nonce,\n },\n })\n }),\n )\n\n return preloadLinks\n })\n\n const styles = Solid.createMemo(() =>\n (\n activeMatches()\n .map((match) => match.styles!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...style }) => ({\n tag: 'style',\n attrs: {\n ...style,\n nonce,\n },\n children,\n })),\n )\n\n const headScripts = Solid.createMemo(() =>\n (\n activeMatches()\n .map((match) => match.headScripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n nonce,\n },\n children,\n })),\n )\n\n return Solid.createMemo((prev: Array<RouterManagedTag> | undefined) => {\n const next = uniqBy(\n [\n ...meta(),\n ...preloadLinks(),\n ...links(),\n ...styles(),\n ...headScripts(),\n ] as Array<RouterManagedTag>,\n getTagKey,\n )\n\n if (\n prev &&\n prev.length === next.length &&\n prev.every((tag, index) => getTagKey(tag) === getTagKey(next[index]!))\n ) {\n return prev\n }\n\n return next\n })\n}\n\nexport function uniqBy<T>(arr: Array<T>, fn: (item: T) => string) {\n const seen = new Set<string>()\n return arr.filter((item) => {\n const key = fn(item)\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n"],"mappings":";;;;;;;;;;AAgBA,IAAaO,WAAWC,qBAA8C;CACpE,MAAMC,SAASL,kBAAAA,WAAW;CAC1B,MAAMM,QAAQD,OAAOE,QAAQC,KAAKF;CAClC,MAAMG,aAAaC,QAA0BC,KAAKC,UAAUF,IAAI;CAChE,MAAMG,gBAAgBjB,SAAMkB,iBACpBT,OAAOU,OAAOC,sBAAsBC,MAC3C;CACD,MAAMC,YAAYtB,SAAMkB,iBACtBD,eAAe,CACZM,KAAKC,UAAUA,MAAMC,KAAM,CAC3BC,OAAOC,QACZ,CAAC;CAED,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Aa;EACjC1D,KAAK;EACL6B,OAAO;GACL,GAAG6B;GACH9D;GACD;EACD8B;EACD,EACH,CAAC;CAED,MAAMiC,cAAczE,SAAMkB,iBAEtBD,eAAe,CACZM,KAAKC,UAAUA,MAAMiD,YAAa,CAClCpB,KAAK,EAAE,CACP3B,OAAOC,QAAQ,CAClBJ,KAAK,EAAEiB,UAAU,GAAGkC,cAAc;EAClC5D,KAAK;EACL6B,OAAO;GACL,GAAG+B;GACHhE;GACD;EACD8B;EACD,EACH,CAAC;AAED,QAAOxC,SAAMkB,YAAYyD,SAA8C;EACrE,MAAMC,OAAOC,OACX;GACE,GAAGpD,MAAM;GACT,GAAGoC,cAAc;GACjB,GAAGX,OAAO;GACV,GAAGqB,QAAQ;GACX,GAAGE,aAAa;GACjB,EACD5D,UACD;AAED,MACE8D,QACAA,KAAKvC,WAAWwC,KAAKxC,UACrBuC,KAAKG,OAAOhE,KAAKiE,UAAUlE,UAAUC,IAAI,KAAKD,UAAU+D,KAAKG,OAAQ,CAAC,CAEtE,QAAOJ;AAGT,SAAOC;GACP;;AAGJ,SAAgBC,OAAUG,KAAeE,IAAyB;CAChE,MAAME,uBAAO,IAAIC,KAAa;AAC9B,QAAOL,IAAItD,QAAQyD,SAAS;EAC1B,MAAMG,MAAMJ,GAAGC,KAAK;AACpB,MAAIC,KAAKG,IAAID,IAAI,CACf,QAAO;AAETF,OAAKI,IAAIF,IAAI;AACb,SAAO;GACP"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RouterManagedTag } from '@tanstack/router-core';
|
|
1
|
+
import { AssetCrossOriginConfig, RouterManagedTag } from '@tanstack/router-core';
|
|
2
2
|
import * as Solid from 'solid-js';
|
|
3
3
|
/**
|
|
4
4
|
* Build the list of head/link/meta/script tags to render for active matches.
|
|
5
5
|
* Used internally by `HeadContent`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const useTags: () => Solid.Accessor<RouterManagedTag[]>;
|
|
7
|
+
export declare const useTags: (assetCrossOrigin?: AssetCrossOriginConfig) => Solid.Accessor<RouterManagedTag[]>;
|
|
8
8
|
export declare function uniqBy<T>(arr: Array<T>, fn: (item: T) => string): T[];
|
package/dist/cjs/not-found.cjs
CHANGED
|
@@ -7,6 +7,10 @@ let solid_js = require("solid-js");
|
|
|
7
7
|
solid_js = require_runtime.__toESM(solid_js);
|
|
8
8
|
//#region src/not-found.tsx
|
|
9
9
|
var _tmpl$ = /* @__PURE__ */ (0, _solidjs_web.template)(`<p>Not Found`);
|
|
10
|
+
function getNotFound(error) {
|
|
11
|
+
if ((0, _tanstack_router_core.isNotFound)(error)) return error;
|
|
12
|
+
if ((0, _tanstack_router_core.isNotFound)(error?.cause)) return error.cause;
|
|
13
|
+
}
|
|
10
14
|
function CatchNotFound(props) {
|
|
11
15
|
const router = require_useRouter.useRouter();
|
|
12
16
|
const pathname = solid_js.createMemo(() => router.stores.location.state.pathname);
|
|
@@ -14,11 +18,13 @@ function CatchNotFound(props) {
|
|
|
14
18
|
return (0, _solidjs_web.createComponent)(require_CatchBoundary.CatchBoundary, {
|
|
15
19
|
getResetKey: () => `not-found-${pathname()}-${status()}`,
|
|
16
20
|
onCatch: (error) => {
|
|
17
|
-
|
|
21
|
+
const notFoundError = getNotFound(error);
|
|
22
|
+
if (notFoundError) props.onCatch?.(notFoundError);
|
|
18
23
|
else throw error;
|
|
19
24
|
},
|
|
20
25
|
errorComponent: ({ error }) => {
|
|
21
|
-
|
|
26
|
+
const notFoundError = getNotFound(error);
|
|
27
|
+
if (notFoundError) return props.fallback?.(notFoundError);
|
|
22
28
|
else throw error;
|
|
23
29
|
},
|
|
24
30
|
get children() {
|
|
@@ -32,5 +38,6 @@ function DefaultGlobalNotFound() {
|
|
|
32
38
|
//#endregion
|
|
33
39
|
exports.CatchNotFound = CatchNotFound;
|
|
34
40
|
exports.DefaultGlobalNotFound = DefaultGlobalNotFound;
|
|
41
|
+
exports.getNotFound = getNotFound;
|
|
35
42
|
|
|
36
43
|
//# sourceMappingURL=not-found.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not-found.cjs","names":["isNotFound","Solid","CatchBoundary","useRouter","NotFoundError","CatchNotFound","props","fallback","
|
|
1
|
+
{"version":3,"file":"not-found.cjs","names":["isNotFound","Solid","CatchBoundary","useRouter","NotFoundError","getNotFound","error","cause","undefined","CatchNotFound","props","fallback","JSX","Element","onCatch","children","router","pathname","createMemo","stores","location","state","status","_$createComponent","getResetKey","notFoundError","errorComponent","DefaultGlobalNotFound","_tmpl$"],"sources":["../../src/not-found.tsx"],"sourcesContent":["import { isNotFound } from '@tanstack/router-core'\nimport * as Solid from 'solid-js'\nimport { CatchBoundary } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport type { NotFoundError } from '@tanstack/router-core'\n\n// Solid wraps non-Error throws in an Error and stores the original thrown value\n// on `cause`, so component-thrown `notFound()` needs one extra unwrapping step.\nexport function getNotFound(\n error: unknown,\n): (NotFoundError & { isNotFound: true }) | undefined {\n if (isNotFound(error)) {\n return error as NotFoundError & { isNotFound: true }\n }\n\n if (isNotFound((error as any)?.cause)) {\n return (error as any).cause as NotFoundError & { isNotFound: true }\n }\n\n return undefined\n}\n\nexport function CatchNotFound(props: {\n fallback?: (error: NotFoundError) => Solid.JSX.Element\n onCatch?: (error: NotFoundError) => void\n children: Solid.JSX.Element\n}) {\n const router = useRouter()\n // TODO: Some way for the user to programmatically reset the not-found boundary?\n const pathname = Solid.createMemo(() => router.stores.location.state.pathname)\n const status = Solid.createMemo(() => router.stores.status.state)\n\n return (\n <CatchBoundary\n getResetKey={() => `not-found-${pathname()}-${status()}`}\n onCatch={(error) => {\n const notFoundError = getNotFound(error)\n\n if (notFoundError) {\n props.onCatch?.(notFoundError)\n } else {\n throw error\n }\n }}\n errorComponent={({ error }) => {\n const notFoundError = getNotFound(error)\n\n if (notFoundError) {\n return props.fallback?.(notFoundError)\n } else {\n throw error\n }\n }}\n >\n {props.children}\n </CatchBoundary>\n )\n}\n\nexport function DefaultGlobalNotFound() {\n return <p>Not Found</p>\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgBK,YACdC,OACoD;AACpD,MAAA,GAAA,sBAAA,YAAeA,MAAM,CACnB,QAAOA;AAGT,MAAA,GAAA,sBAAA,YAAgBA,OAAeC,MAAM,CACnC,QAAQD,MAAcC;;AAM1B,SAAgBE,cAAcC,OAI3B;CACD,MAAMM,SAASb,kBAAAA,WAAW;CAE1B,MAAMc,WAAWhB,SAAMiB,iBAAiBF,OAAOG,OAAOC,SAASC,MAAMJ,SAAS;CAC9E,MAAMK,SAASrB,SAAMiB,iBAAiBF,OAAOG,OAAOG,OAAOD,MAAM;AAEjE,SAAA,GAAA,aAAA,iBACGnB,sBAAAA,eAAa;EACZsB,mBAAmB,aAAaP,UAAU,CAAA,GAAIK,QAAQ;EACtDR,UAAUR,UAAU;GAClB,MAAMmB,gBAAgBpB,YAAYC,MAAM;AAExC,OAAImB,cACFf,OAAMI,UAAUW,cAAc;OAE9B,OAAMnB;;EAGVoB,iBAAiB,EAAEpB,YAAY;GAC7B,MAAMmB,gBAAgBpB,YAAYC,MAAM;AAExC,OAAImB,cACF,QAAOf,MAAMC,WAAWc,cAAc;OAEtC,OAAMnB;;EAET,IAAAS,WAAA;AAAA,UAEAL,MAAMK;;EAAQ,CAAA;;AAKrB,SAAgBY,wBAAwB;AACtC,QAAAC,QAAA"}
|
package/dist/cjs/not-found.d.cts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { NotFoundError } from '@tanstack/router-core';
|
|
2
2
|
import * as Solid from 'solid-js';
|
|
3
|
+
export declare function getNotFound(error: unknown): (NotFoundError & {
|
|
4
|
+
isNotFound: true;
|
|
5
|
+
}) | undefined;
|
|
3
6
|
export declare function CatchNotFound(props: {
|
|
4
7
|
fallback?: (error: NotFoundError) => Solid.JSX.Element;
|
|
5
|
-
onCatch?: (error:
|
|
8
|
+
onCatch?: (error: NotFoundError) => void;
|
|
6
9
|
children: Solid.JSX.Element;
|
|
7
10
|
}): Solid.JSX.Element;
|
|
8
11
|
export declare function DefaultGlobalNotFound(): Solid.JSX.Element;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_not_found = require("./not-found.cjs");
|
|
3
3
|
let _solidjs_web = require("@solidjs/web");
|
|
4
|
-
let tiny_warning = require("tiny-warning");
|
|
5
|
-
tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
6
4
|
//#region src/renderRouteNotFound.tsx
|
|
7
5
|
/**
|
|
8
6
|
* Renders a not found component for a route when no matching route is found.
|
|
@@ -15,7 +13,9 @@ tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
|
15
13
|
function renderRouteNotFound(router, route, data) {
|
|
16
14
|
if (!route.options.notFoundComponent) {
|
|
17
15
|
if (router.options.defaultNotFoundComponent) return (0, _solidjs_web.createComponent)(router.options.defaultNotFoundComponent, data);
|
|
18
|
-
if (process.env.NODE_ENV
|
|
16
|
+
if (process.env.NODE_ENV !== "production") {
|
|
17
|
+
if (!route.options.notFoundComponent) console.warn(`Warning: A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`);
|
|
18
|
+
}
|
|
19
19
|
return (0, _solidjs_web.createComponent)(require_not_found.DefaultGlobalNotFound, {});
|
|
20
20
|
}
|
|
21
21
|
return (0, _solidjs_web.createComponent)(route.options.notFoundComponent, data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderRouteNotFound.cjs","names":["
|
|
1
|
+
{"version":3,"file":"renderRouteNotFound.cjs","names":["DefaultGlobalNotFound","AnyRoute","AnyRouter","renderRouteNotFound","router","route","data","options","notFoundComponent","defaultNotFoundComponent","_$createComponent","process","env","NODE_ENV","console","warn","id"],"sources":["../../src/renderRouteNotFound.tsx"],"sourcesContent":["import { DefaultGlobalNotFound } from './not-found'\nimport type { AnyRoute, AnyRouter } from '@tanstack/router-core'\n\n/**\n * Renders a not found component for a route when no matching route is found.\n *\n * @param router - The router instance containing the route configuration\n * @param route - The route that triggered the not found state\n * @param data - Additional data to pass to the not found component\n * @returns The rendered not found component or a default fallback component\n */\nexport function renderRouteNotFound(\n router: AnyRouter,\n route: AnyRoute,\n data: any,\n) {\n if (!route.options.notFoundComponent) {\n if (router.options.defaultNotFoundComponent) {\n return <router.options.defaultNotFoundComponent {...data} />\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!route.options.notFoundComponent) {\n console.warn(\n `Warning: A notFoundError was encountered on the route with ID \"${route.id}\", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,\n )\n }\n }\n\n return <DefaultGlobalNotFound />\n }\n\n return <route.options.notFoundComponent {...data} />\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgBG,oBACdC,QACAC,OACAC,MACA;AACA,KAAI,CAACD,MAAME,QAAQC,mBAAmB;AACpC,MAAIJ,OAAOG,QAAQE,yBACjB,SAAA,GAAA,aAAA,iBAAQL,OAAOG,QAAQE,0BAA6BH,KAAI;AAG1D,MAAA,QAAA,IAAA,aAA6B;OACvB,CAACD,MAAME,QAAQC,kBACjBM,SAAQC,KACN,kEAAkEV,MAAMW,GAAE,oPAC3E;;AAIL,UAAA,GAAA,aAAA,iBAAQhB,kBAAAA,uBAAqB,EAAA,CAAA;;AAG/B,SAAA,GAAA,aAAA,iBAAQK,MAAME,QAAQC,mBAAsBF,KAAI"}
|
package/dist/cjs/router.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_fileRoute = require("./fileRoute.cjs");
|
|
3
2
|
const require_routerStores = require("./routerStores.cjs");
|
|
4
3
|
let _tanstack_router_core = require("@tanstack/router-core");
|
|
5
4
|
//#region src/router.ts
|
|
@@ -11,13 +10,6 @@ var Router = class extends _tanstack_router_core.RouterCore {
|
|
|
11
10
|
super(options, require_routerStores.getStoreFactory);
|
|
12
11
|
}
|
|
13
12
|
};
|
|
14
|
-
if (typeof globalThis !== "undefined") {
|
|
15
|
-
globalThis.createFileRoute = require_fileRoute.createFileRoute;
|
|
16
|
-
globalThis.createLazyFileRoute = require_fileRoute.createLazyFileRoute;
|
|
17
|
-
} else if (typeof window !== "undefined") {
|
|
18
|
-
window.createFileRoute = require_fileRoute.createFileRoute;
|
|
19
|
-
window.createLazyFileRoute = require_fileRoute.createLazyFileRoute;
|
|
20
|
-
}
|
|
21
13
|
//#endregion
|
|
22
14
|
exports.Router = Router;
|
|
23
15
|
exports.createRouter = createRouter;
|
package/dist/cjs/router.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.cjs","names":[],"sources":["../../src/router.ts"],"sourcesContent":["import { RouterCore } from '@tanstack/router-core'\nimport {
|
|
1
|
+
{"version":3,"file":"router.cjs","names":[],"sources":["../../src/router.ts"],"sourcesContent":["import { RouterCore } from '@tanstack/router-core'\nimport { getStoreFactory } from './routerStores'\nimport type { RouterHistory } from '@tanstack/history'\nimport type {\n AnyRoute,\n CreateRouterFn,\n RouterConstructorOptions,\n TrailingSlashOption,\n} from '@tanstack/router-core'\nimport type {\n ErrorRouteComponent,\n NotFoundRouteComponent,\n RouteComponent,\n} from './route'\nimport type { JSX } from 'solid-js'\n\ndeclare module '@tanstack/router-core' {\n export interface RouterOptionsExtensions {\n /**\n * The default `component` a route should use if no component is provided.\n *\n * @default Outlet\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)\n */\n defaultComponent?: RouteComponent\n /**\n * The default `errorComponent` a route should use if no error component is provided.\n *\n * @default ErrorComponent\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)\n */\n defaultErrorComponent?: ErrorRouteComponent\n /**\n * The default `pendingComponent` a route should use if no pending component is provided.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)\n */\n defaultPendingComponent?: RouteComponent\n /**\n * The default `notFoundComponent` a route should use if no notFound component is provided.\n *\n * @default NotFound\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)\n */\n defaultNotFoundComponent?: NotFoundRouteComponent\n /**\n * A component that will be used to wrap the entire router.\n *\n * This is useful for providing a context to the entire router.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#wrap-property)\n */\n Wrap?: (props: { children: any }) => JSX.Element\n /**\n * A component that will be used to wrap the inner contents of the router.\n *\n * This is useful for providing a context to the inner contents of the router where you also need access to the router context and hooks.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#innerwrap-property)\n */\n InnerWrap?: (props: { children: any }) => JSX.Element\n\n /**\n * The default `onCatch` handler for errors caught by the Router ErrorBoundary\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)\n */\n defaultOnCatch?: (error: Error) => void\n }\n}\n\nexport const createRouter: CreateRouterFn = (options) => {\n return new Router(options)\n}\n\nexport class Router<\n in out TRouteTree extends AnyRoute,\n in out TTrailingSlashOption extends TrailingSlashOption = 'never',\n in out TDefaultStructuralSharingOption extends boolean = false,\n in out TRouterHistory extends RouterHistory = RouterHistory,\n in out TDehydrated extends Record<string, any> = Record<string, any>,\n> extends RouterCore<\n TRouteTree,\n TTrailingSlashOption,\n TDefaultStructuralSharingOption,\n TRouterHistory,\n TDehydrated\n> {\n constructor(\n options: RouterConstructorOptions<\n TRouteTree,\n TTrailingSlashOption,\n TDefaultStructuralSharingOption,\n TRouterHistory,\n TDehydrated\n >,\n ) {\n super(options, getStoreFactory)\n }\n}\n"],"mappings":";;;;AA2EA,IAAa,gBAAgC,YAAY;AACvD,QAAO,IAAI,OAAO,QAAQ;;AAG5B,IAAa,SAAb,cAMU,sBAAA,WAMR;CACA,YACE,SAOA;AACA,QAAM,SAAS,qBAAA,gBAAgB"}
|
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_useRouter = require("./useRouter.cjs");
|
|
3
3
|
const require_ScriptOnce = require("./ScriptOnce.cjs");
|
|
4
|
-
let _tanstack_router_core = require("@tanstack/router-core");
|
|
5
4
|
let _solidjs_web = require("@solidjs/web");
|
|
6
|
-
let
|
|
5
|
+
let _tanstack_router_core_scroll_restoration_script = require("@tanstack/router-core/scroll-restoration-script");
|
|
7
6
|
//#region src/scroll-restoration.tsx
|
|
8
7
|
function ScrollRestoration() {
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
-
|
|
12
|
-
if (!router.options.scrollRestoration({ location: router.latestLocation })) return null;
|
|
13
|
-
}
|
|
14
|
-
const userKey = (router.options.getScrollRestorationKey || _tanstack_router_core.defaultGetScrollRestorationKey)(router.latestLocation);
|
|
15
|
-
const resolvedKey = userKey !== (0, _tanstack_router_core.defaultGetScrollRestorationKey)(router.latestLocation) ? userKey : void 0;
|
|
16
|
-
const restoreScrollOptions = {
|
|
17
|
-
storageKey: _tanstack_router_core.storageKey,
|
|
18
|
-
shouldScrollRestoration: true
|
|
19
|
-
};
|
|
20
|
-
if (resolvedKey) restoreScrollOptions.key = resolvedKey;
|
|
21
|
-
return (0, _solidjs_web.createComponent)(require_ScriptOnce.ScriptOnce, { get children() {
|
|
22
|
-
return `(${_tanstack_router_core.restoreScroll.toString()})(${(0, _tanstack_router_core.escapeHtml)(JSON.stringify(restoreScrollOptions))})`;
|
|
23
|
-
} });
|
|
8
|
+
const script = (0, _tanstack_router_core_scroll_restoration_script.getScrollRestorationScriptForRouter)(require_useRouter.useRouter());
|
|
9
|
+
if (!script) return null;
|
|
10
|
+
return (0, _solidjs_web.createComponent)(require_ScriptOnce.ScriptOnce, { children: script });
|
|
24
11
|
}
|
|
25
12
|
//#endregion
|
|
26
13
|
exports.ScrollRestoration = ScrollRestoration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-restoration.cjs","names":["
|
|
1
|
+
{"version":3,"file":"scroll-restoration.cjs","names":["getScrollRestorationScriptForRouter","useRouter","ScriptOnce","ScrollRestoration","router","script","_$createComponent","children"],"sources":["../../src/scroll-restoration.tsx"],"sourcesContent":["import { getScrollRestorationScriptForRouter } from '@tanstack/router-core/scroll-restoration-script'\nimport { useRouter } from './useRouter'\nimport { ScriptOnce } from './ScriptOnce'\n\nexport function ScrollRestoration() {\n const router = useRouter()\n const script = getScrollRestorationScriptForRouter(router)\n\n if (!script) {\n return null\n }\n\n return <ScriptOnce children={script} />\n}\n"],"mappings":";;;;;;AAIA,SAAgBG,oBAAoB;CAElC,MAAME,UAAAA,GAAAA,gDAAAA,qCADSJ,kBAAAA,WAAW,CACgC;AAE1D,KAAI,CAACI,OACH,QAAO;AAGT,SAAA,GAAA,aAAA,iBAAQH,mBAAAA,YAAU,EAACK,UAAUF,QAAM,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlocker.cjs","names":["Solid","useRouter","BlockerFnArgs","HistoryAction","HistoryLocation","SolidNode","AnyRoute","AnyRouter","ParseRoute","RegisteredRouter","ShouldBlockFnLocation","routeId","TRouteId","fullPath","TFullPath","pathname","params","TAllParams","search","TFullSearchSchema","AnyShouldBlockFnLocation","MakeShouldBlockFnLocationUnion","TRouter","TRoute","BlockerResolver","status","current","next","action","proceed","reset","ShouldBlockFnArgs","ShouldBlockFn","args","Promise","UseBlockerOpts","shouldBlockFn","enableBeforeUnload","disabled","withResolver","TWithResolver","LegacyBlockerFn","LegacyBlockerOpts","blockerFn","condition","_resolveBlockerOpts","opts","undefined","shouldBlock","Boolean","_customBlockerFn","createMemo","useBlocker","Accessor","blockerFnOrOpts","props","merge","router","resolver","setResolver","createSignal","disposeBlock","createEffect","blockerFnComposed","blockerFnArgs","getLocation","location","parsedLocation","parseLocation","matchedRoutes","getMatchedRoutes","foundRoute","routeParams","id","currentLocation","nextLocation","promise","resolve","canNavigateAsync","history","block","onSettled","_resolvePromptBlockerArgs","PromptProps","LegacyPromptProps","BlockComponent","Block","propsWithChildren","children","child","_$memo","TParams"],"sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { useRouter } from './useRouter'\nimport type {\n BlockerFnArgs,\n HistoryAction,\n HistoryLocation,\n} from '@tanstack/history'\nimport type { SolidNode } from './route'\nimport type {\n AnyRoute,\n AnyRouter,\n ParseRoute,\n RegisteredRouter,\n} from '@tanstack/router-core'\n\ninterface ShouldBlockFnLocation<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n> {\n routeId: TRouteId\n fullPath: TFullPath\n pathname: string\n params: TAllParams\n search: TFullSearchSchema\n}\n\ntype AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>\ntype MakeShouldBlockFnLocationUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? ShouldBlockFnLocation<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema']\n >\n : never\n\ntype BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =\n | {\n status: 'blocked'\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n proceed: () => void\n reset: () => void\n }\n | {\n status: 'idle'\n current: undefined\n next: undefined\n action: undefined\n proceed: undefined\n reset: undefined\n }\n\ntype ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n}\n\nexport type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (\n args: ShouldBlockFnArgs<TRouter>,\n) => boolean | Promise<boolean>\nexport type UseBlockerOpts<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n> = {\n shouldBlockFn: ShouldBlockFn<TRouter>\n enableBeforeUnload?: boolean | (() => boolean)\n disabled?: boolean\n withResolver?: TWithResolver\n}\n\ntype LegacyBlockerFn = () => Promise<any> | any\ntype LegacyBlockerOpts = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n}\n\nfunction _resolveBlockerOpts(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): UseBlockerOpts {\n if (opts === undefined) {\n return {\n shouldBlockFn: () => true,\n withResolver: false,\n }\n }\n\n if ('shouldBlockFn' in opts) {\n return opts\n }\n\n if (typeof opts === 'function') {\n const shouldBlock = Boolean(condition ?? true)\n\n const _customBlockerFn = async () => {\n if (shouldBlock) return await opts()\n return false\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: false,\n }\n }\n\n const shouldBlock = Solid.createMemo(() => Boolean(opts.condition ?? true))\n\n const _customBlockerFn = async () => {\n if (shouldBlock() && opts.blockerFn !== undefined) {\n return await opts.blockerFn()\n }\n return shouldBlock()\n }\n\n return {\n get shouldBlockFn() {\n return _customBlockerFn\n },\n get enableBeforeUnload() {\n return shouldBlock()\n },\n get withResolver() {\n return opts.blockerFn === undefined\n },\n }\n}\n\nexport function useBlocker<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = false,\n>(\n opts: UseBlockerOpts<TRouter, TWithResolver>,\n): TWithResolver extends true ? Solid.Accessor<BlockerResolver<TRouter>> : void\n\n/**\n * @deprecated Use the shouldBlockFn property instead\n */\nexport function useBlocker(\n blockerFnOrOpts?: LegacyBlockerOpts,\n): Solid.Accessor<BlockerResolver>\n\n/**\n * @deprecated Use the UseBlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: LegacyBlockerFn,\n condition?: boolean | any,\n): Solid.Accessor<BlockerResolver>\n\nexport function useBlocker(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): Solid.Accessor<BlockerResolver> | void {\n const props = Solid.merge(\n {\n enableBeforeUnload: true,\n disabled: false,\n withResolver: false,\n },\n _resolveBlockerOpts(opts, condition),\n )\n\n const router = useRouter()\n\n const [resolver, setResolver] = Solid.createSignal<BlockerResolver>({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n let disposeBlock: (() => void) | undefined\n\n Solid.createEffect(\n () => props.disabled,\n (disabled) => {\n // Dispose previous blocker registration when re-running\n disposeBlock?.()\n disposeBlock = undefined\n\n if (disabled) {\n return\n }\n\n const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {\n function getLocation(\n location: HistoryLocation,\n ): AnyShouldBlockFnLocation {\n const parsedLocation = router.parseLocation(location)\n const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)\n if (matchedRoutes.foundRoute === undefined) {\n return {\n routeId: '__notFound__',\n fullPath: parsedLocation.pathname,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: parsedLocation.search,\n }\n }\n return {\n routeId: matchedRoutes.foundRoute.id,\n fullPath: matchedRoutes.foundRoute.fullPath,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: parsedLocation.search,\n }\n }\n\n const current = getLocation(blockerFnArgs.currentLocation)\n const next = getLocation(blockerFnArgs.nextLocation)\n\n if (\n current.routeId === '__notFound__' &&\n next.routeId !== '__notFound__'\n ) {\n return false\n }\n\n const shouldBlock = await props.shouldBlockFn({\n action: blockerFnArgs.action,\n current,\n next,\n })\n if (!props.withResolver) {\n return shouldBlock\n }\n\n if (!shouldBlock) {\n return false\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n current,\n next,\n action: blockerFnArgs.action,\n proceed: () => resolve(false),\n reset: () => resolve(true),\n })\n })\n\n const canNavigateAsync = await promise\n setResolver({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n return canNavigateAsync\n }\n\n disposeBlock = router.history.block({\n blockerFn: blockerFnComposed,\n enableBeforeUnload: props.enableBeforeUnload,\n })\n },\n )\n\n // Clean up on unmount\n Solid.onSettled(() => {\n return () => {\n disposeBlock?.()\n disposeBlock = undefined\n }\n })\n\n return resolver\n}\n\nconst _resolvePromptBlockerArgs = (\n props: PromptProps | LegacyPromptProps,\n): UseBlockerOpts => {\n if ('shouldBlockFn' in props) {\n return props\n }\n\n const shouldBlock = Solid.createMemo(() => Boolean(props.condition ?? true))\n\n const _customBlockerFn = async () => {\n if (shouldBlock() && props.blockerFn !== undefined) {\n return await props.blockerFn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n get enableBeforeUnload() {\n return shouldBlock()\n },\n get withResolver() {\n return props.blockerFn === undefined\n },\n }\n}\n\ninterface BlockComponent {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n >(\n opts: PromptProps<TRouter, TWithResolver>,\n ): SolidNode\n /**\n * @deprecated Use the UseBlockerOpts property instead\n */\n (opts: LegacyPromptProps): SolidNode\n}\n\nexport const Block: BlockComponent = function Block(\n opts: PromptProps | LegacyPromptProps,\n): SolidNode {\n const propsWithChildren = {\n get children() {\n return opts.children\n },\n }\n const args = _resolvePromptBlockerArgs(opts)\n\n const resolver = useBlocker(args)\n const children = Solid.createMemo(() => {\n const child = propsWithChildren.children\n if (resolver && typeof child === 'function') return child(resolver())\n return child\n })\n\n return <>{children()}</>\n}\n\ntype LegacyPromptProps = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n children?: SolidNode | ((params: BlockerResolver) => SolidNode)\n}\n\ntype PromptProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,\n> = UseBlockerOpts<TRouter, TWithResolver> & {\n children?: SolidNode | ((params: TParams) => SolidNode)\n}\n"],"mappings":";;;;;;AAoFA,SAAS6C,oBACPC,MACAF,WACgB;AAChB,KAAIE,SAASC,KAAAA,EACX,QAAO;EACLX,qBAAqB;EACrBG,cAAc;EACf;AAGH,KAAI,mBAAmBO,KACrB,QAAOA;AAGT,KAAI,OAAOA,SAAS,YAAY;EAC9B,MAAME,cAAcC,QAAQL,aAAa,KAAK;EAE9C,MAAMM,mBAAmB,YAAY;AACnC,OAAIF,YAAa,QAAO,MAAMF,MAAM;AACpC,UAAO;;AAGT,SAAO;GACLV,eAAec;GACfb,oBAAoBW;GACpBT,cAAc;GACf;;CAGH,MAAMS,cAAchD,SAAMmD,iBAAiBF,QAAQH,KAAKF,aAAa,KAAK,CAAC;CAE3E,MAAMM,mBAAmB,YAAY;AACnC,MAAIF,aAAa,IAAIF,KAAKH,cAAcI,KAAAA,EACtC,QAAO,MAAMD,KAAKH,WAAW;AAE/B,SAAOK,aAAa;;AAGtB,QAAO;EACL,IAAIZ,gBAAgB;AAClB,UAAOc;;EAET,IAAIb,qBAAqB;AACvB,UAAOW,aAAa;;EAEtB,IAAIT,eAAe;AACjB,UAAOO,KAAKH,cAAcI,KAAAA;;EAE7B;;AAyBH,SAAgBK,WACdN,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ChC,MAAI9B,YAAY,OAAO+B,UAAU,WAAY,QAAOA,MAAM/B,UAAU,CAAC;AACrE,SAAO+B;GACP,CAEgB"}
|
|
1
|
+
{"version":3,"file":"useBlocker.cjs","names":["Solid","useRouter","BlockerFnArgs","HistoryAction","HistoryLocation","SolidNode","AnyRoute","AnyRouter","ParseRoute","RegisteredRouter","ShouldBlockFnLocation","routeId","TRouteId","fullPath","TFullPath","pathname","params","TAllParams","search","TFullSearchSchema","AnyShouldBlockFnLocation","MakeShouldBlockFnLocationUnion","TRouter","TRoute","BlockerResolver","status","current","next","action","proceed","reset","ShouldBlockFnArgs","ShouldBlockFn","args","Promise","UseBlockerOpts","shouldBlockFn","enableBeforeUnload","disabled","withResolver","TWithResolver","LegacyBlockerFn","LegacyBlockerOpts","blockerFn","condition","_resolveBlockerOpts","opts","undefined","shouldBlock","Boolean","_customBlockerFn","createMemo","useBlocker","Accessor","blockerFnOrOpts","props","merge","router","resolver","setResolver","createSignal","disposeBlock","createEffect","blockerFnComposed","blockerFnArgs","getLocation","location","parsedLocation","parseLocation","matchedRoutes","getMatchedRoutes","foundRoute","routeParams","id","currentLocation","nextLocation","promise","resolve","canNavigateAsync","history","block","onSettled","_resolvePromptBlockerArgs","PromptProps","LegacyPromptProps","BlockComponent","Block","propsWithChildren","children","child","_$memo","TParams"],"sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { useRouter } from './useRouter'\nimport type {\n BlockerFnArgs,\n HistoryAction,\n HistoryLocation,\n} from '@tanstack/history'\nimport type { SolidNode } from './route'\nimport type {\n AnyRoute,\n AnyRouter,\n ParseRoute,\n RegisteredRouter,\n} from '@tanstack/router-core'\n\ntype ShouldBlockFnLocation<\n out TRouteId,\n out TFullPath,\n out TAllParams,\n out TFullSearchSchema,\n> = {\n routeId: TRouteId\n fullPath: TFullPath\n pathname: string\n params: TAllParams\n search: TFullSearchSchema\n}\n\ntype AnyShouldBlockFnLocation = ShouldBlockFnLocation<any, any, any, any>\ntype MakeShouldBlockFnLocationUnion<\n TRouter extends AnyRouter = RegisteredRouter,\n TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,\n> = TRoute extends any\n ? ShouldBlockFnLocation<\n TRoute['id'],\n TRoute['fullPath'],\n TRoute['types']['allParams'],\n TRoute['types']['fullSearchSchema']\n >\n : never\n\ntype BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> =\n | {\n status: 'blocked'\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n proceed: () => void\n reset: () => void\n }\n | {\n status: 'idle'\n current: undefined\n next: undefined\n action: undefined\n proceed: undefined\n reset: undefined\n }\n\ntype ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {\n current: MakeShouldBlockFnLocationUnion<TRouter>\n next: MakeShouldBlockFnLocationUnion<TRouter>\n action: HistoryAction\n}\n\nexport type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (\n args: ShouldBlockFnArgs<TRouter>,\n) => boolean | Promise<boolean>\nexport type UseBlockerOpts<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n> = {\n shouldBlockFn: ShouldBlockFn<TRouter>\n enableBeforeUnload?: boolean | (() => boolean)\n disabled?: boolean\n withResolver?: TWithResolver\n}\n\ntype LegacyBlockerFn = () => Promise<any> | any\ntype LegacyBlockerOpts = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n}\n\nfunction _resolveBlockerOpts(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): UseBlockerOpts {\n if (opts === undefined) {\n return {\n shouldBlockFn: () => true,\n withResolver: false,\n }\n }\n\n if ('shouldBlockFn' in opts) {\n return opts\n }\n\n if (typeof opts === 'function') {\n const shouldBlock = Boolean(condition ?? true)\n\n const _customBlockerFn = async () => {\n if (shouldBlock) return await opts()\n return false\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n enableBeforeUnload: shouldBlock,\n withResolver: false,\n }\n }\n\n const shouldBlock = Solid.createMemo(() => Boolean(opts.condition ?? true))\n\n const _customBlockerFn = async () => {\n if (shouldBlock() && opts.blockerFn !== undefined) {\n return await opts.blockerFn()\n }\n return shouldBlock()\n }\n\n return {\n get shouldBlockFn() {\n return _customBlockerFn\n },\n get enableBeforeUnload() {\n return shouldBlock()\n },\n get withResolver() {\n return opts.blockerFn === undefined\n },\n }\n}\n\nexport function useBlocker<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = false,\n>(\n opts: UseBlockerOpts<TRouter, TWithResolver>,\n): TWithResolver extends true ? Solid.Accessor<BlockerResolver<TRouter>> : void\n\n/**\n * @deprecated Use the shouldBlockFn property instead\n */\nexport function useBlocker(\n blockerFnOrOpts?: LegacyBlockerOpts,\n): Solid.Accessor<BlockerResolver>\n\n/**\n * @deprecated Use the UseBlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: LegacyBlockerFn,\n condition?: boolean | any,\n): Solid.Accessor<BlockerResolver>\n\nexport function useBlocker(\n opts?: UseBlockerOpts | LegacyBlockerOpts | LegacyBlockerFn,\n condition?: boolean | any,\n): Solid.Accessor<BlockerResolver> | void {\n const props = Solid.merge(\n {\n enableBeforeUnload: true,\n disabled: false,\n withResolver: false,\n },\n _resolveBlockerOpts(opts, condition),\n )\n\n const router = useRouter()\n\n const [resolver, setResolver] = Solid.createSignal<BlockerResolver>({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n let disposeBlock: (() => void) | undefined\n\n Solid.createEffect(\n () => props.disabled,\n (disabled) => {\n // Dispose previous blocker registration when re-running\n disposeBlock?.()\n disposeBlock = undefined\n\n if (disabled) {\n return\n }\n\n const blockerFnComposed = async (blockerFnArgs: BlockerFnArgs) => {\n function getLocation(\n location: HistoryLocation,\n ): AnyShouldBlockFnLocation {\n const parsedLocation = router.parseLocation(location)\n const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)\n if (matchedRoutes.foundRoute === undefined) {\n return {\n routeId: '__notFound__',\n fullPath: parsedLocation.pathname,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: parsedLocation.search,\n }\n }\n return {\n routeId: matchedRoutes.foundRoute.id,\n fullPath: matchedRoutes.foundRoute.fullPath,\n pathname: parsedLocation.pathname,\n params: matchedRoutes.routeParams,\n search: parsedLocation.search,\n }\n }\n\n const current = getLocation(blockerFnArgs.currentLocation)\n const next = getLocation(blockerFnArgs.nextLocation)\n\n if (\n current.routeId === '__notFound__' &&\n next.routeId !== '__notFound__'\n ) {\n return false\n }\n\n const shouldBlock = await props.shouldBlockFn({\n action: blockerFnArgs.action,\n current,\n next,\n })\n if (!props.withResolver) {\n return shouldBlock\n }\n\n if (!shouldBlock) {\n return false\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n current,\n next,\n action: blockerFnArgs.action,\n proceed: () => resolve(false),\n reset: () => resolve(true),\n })\n })\n\n const canNavigateAsync = await promise\n setResolver({\n status: 'idle',\n current: undefined,\n next: undefined,\n action: undefined,\n proceed: undefined,\n reset: undefined,\n })\n\n return canNavigateAsync\n }\n\n disposeBlock = router.history.block({\n blockerFn: blockerFnComposed,\n enableBeforeUnload: props.enableBeforeUnload,\n })\n },\n )\n\n // Clean up on unmount\n Solid.onSettled(() => {\n return () => {\n disposeBlock?.()\n disposeBlock = undefined\n }\n })\n\n return resolver\n}\n\nconst _resolvePromptBlockerArgs = (\n props: PromptProps | LegacyPromptProps,\n): UseBlockerOpts => {\n if ('shouldBlockFn' in props) {\n return props\n }\n\n const shouldBlock = Solid.createMemo(() => Boolean(props.condition ?? true))\n\n const _customBlockerFn = async () => {\n if (shouldBlock() && props.blockerFn !== undefined) {\n return await props.blockerFn()\n }\n return shouldBlock\n }\n\n return {\n shouldBlockFn: _customBlockerFn,\n get enableBeforeUnload() {\n return shouldBlock()\n },\n get withResolver() {\n return props.blockerFn === undefined\n },\n }\n}\n\ninterface BlockComponent {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n >(\n opts: PromptProps<TRouter, TWithResolver>,\n ): SolidNode\n /**\n * @deprecated Use the UseBlockerOpts property instead\n */\n (opts: LegacyPromptProps): SolidNode\n}\n\nexport const Block: BlockComponent = function Block(\n opts: PromptProps | LegacyPromptProps,\n): SolidNode {\n const propsWithChildren = {\n get children() {\n return opts.children\n },\n }\n const args = _resolvePromptBlockerArgs(opts)\n\n const resolver = useBlocker(args)\n const children = Solid.createMemo(() => {\n const child = propsWithChildren.children\n if (resolver && typeof child === 'function') return child(resolver())\n return child\n })\n\n return <>{children()}</>\n}\n\ntype LegacyPromptProps = {\n blockerFn?: LegacyBlockerFn\n condition?: boolean | any\n children?: SolidNode | ((params: BlockerResolver) => SolidNode)\n}\n\ntype PromptProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TWithResolver extends boolean = boolean,\n TParams = TWithResolver extends true ? BlockerResolver<TRouter> : void,\n> = UseBlockerOpts<TRouter, TWithResolver> & {\n children?: SolidNode | ((params: TParams) => SolidNode)\n}\n"],"mappings":";;;;;;AAoFA,SAAS6C,oBACPC,MACAF,WACgB;AAChB,KAAIE,SAASC,KAAAA,EACX,QAAO;EACLX,qBAAqB;EACrBG,cAAc;EACf;AAGH,KAAI,mBAAmBO,KACrB,QAAOA;AAGT,KAAI,OAAOA,SAAS,YAAY;EAC9B,MAAME,cAAcC,QAAQL,aAAa,KAAK;EAE9C,MAAMM,mBAAmB,YAAY;AACnC,OAAIF,YAAa,QAAO,MAAMF,MAAM;AACpC,UAAO;;AAGT,SAAO;GACLV,eAAec;GACfb,oBAAoBW;GACpBT,cAAc;GACf;;CAGH,MAAMS,cAAchD,SAAMmD,iBAAiBF,QAAQH,KAAKF,aAAa,KAAK,CAAC;CAE3E,MAAMM,mBAAmB,YAAY;AACnC,MAAIF,aAAa,IAAIF,KAAKH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gBH,IAAauC,QAAwB,SAASA,MAC5CxC,MACW;CACX,MAAMyC,oBAAoB,EACxB,IAAIC,WAAW;AACb,SAAO1C,KAAK0C;IAEf;CAGD,MAAM9B,WAAWN,WAFJ8B,0BAA0BpC,KAAK,CAEX;AAOjC,SAAA,GAAA,aAAA,MANiB9C,SAAMmD,iBAAiB;EACtC,MAAMsC,QAAQF,kBAAkBC;AAChC,MAAI9B,YAAY,OAAO+B,UAAU,WAAY,QAAOA,MAAM/B,UAAU,CAAC;AACrE,SAAO+B;GACP,CAEgB"}
|
|
@@ -2,13 +2,13 @@ import { HistoryAction } from '@tanstack/history';
|
|
|
2
2
|
import { SolidNode } from './route.cjs';
|
|
3
3
|
import { AnyRoute, AnyRouter, ParseRoute, RegisteredRouter } from '@tanstack/router-core';
|
|
4
4
|
import * as Solid from 'solid-js';
|
|
5
|
-
|
|
5
|
+
type ShouldBlockFnLocation<out TRouteId, out TFullPath, out TAllParams, out TFullSearchSchema> = {
|
|
6
6
|
routeId: TRouteId;
|
|
7
7
|
fullPath: TFullPath;
|
|
8
8
|
pathname: string;
|
|
9
9
|
params: TAllParams;
|
|
10
10
|
search: TFullSearchSchema;
|
|
11
|
-
}
|
|
11
|
+
};
|
|
12
12
|
type MakeShouldBlockFnLocationUnion<TRouter extends AnyRouter = RegisteredRouter, TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>> = TRoute extends any ? ShouldBlockFnLocation<TRoute['id'], TRoute['fullPath'], TRoute['types']['allParams'], TRoute['types']['fullSearchSchema']> : never;
|
|
13
13
|
type BlockerResolver<TRouter extends AnyRouter = RegisteredRouter> = {
|
|
14
14
|
status: 'blocked';
|
package/dist/cjs/useMatch.cjs
CHANGED
|
@@ -4,8 +4,6 @@ const require_matchContext = require("./matchContext.cjs");
|
|
|
4
4
|
let _tanstack_router_core = require("@tanstack/router-core");
|
|
5
5
|
let solid_js = require("solid-js");
|
|
6
6
|
solid_js = require_runtime.__toESM(solid_js);
|
|
7
|
-
let tiny_invariant = require("tiny-invariant");
|
|
8
|
-
tiny_invariant = require_runtime.__toESM(tiny_invariant);
|
|
9
7
|
//#region src/useMatch.tsx
|
|
10
8
|
function useMatch(opts) {
|
|
11
9
|
const router = require_useRouter.useRouter();
|
|
@@ -26,7 +24,10 @@ function useMatch(opts) {
|
|
|
26
24
|
if (selectedMatch === void 0) {
|
|
27
25
|
const hasPendingMatch = opts.from ? Boolean(router.stores.pendingRouteIds.state[opts.from]) : nearestMatch?.hasPending() ?? false;
|
|
28
26
|
const isTransitioning = router.stores.isTransitioning.state;
|
|
29
|
-
|
|
27
|
+
if (!hasPendingMatch && !isTransitioning && (opts.shouldThrow ?? true)) {
|
|
28
|
+
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!"}`);
|
|
29
|
+
(0, _tanstack_router_core.invariant)();
|
|
30
|
+
}
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
const res = opts.select ? opts.select(selectedMatch) : selectedMatch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.cjs","names":["Solid","invariant","replaceEqualDeep","nearestMatchContext","useRouter","AnyRouter","MakeRouteMatch","MakeRouteMatchUnion","RegisteredRouter","StrictOrFrom","ThrowConstraint","ThrowOrOptional","UseMatchBaseOptions","select","match","TRouter","TFrom","TStrict","TSelected","shouldThrow","TThrow","UseMatchRoute","opts","Accessor","UseMatchResult","UseMatchOptions","useMatch","router","nearestMatch","from","undefined","useContext","ids","stores","matchesId","state","id","matchStore","activeMatchStoresById","get","routeId","createMemo","prev","selectedMatch","hasPendingMatch","Boolean","pendingRouteIds","hasPending","isTransitioning","res"],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport
|
|
1
|
+
{"version":3,"file":"useMatch.cjs","names":["Solid","invariant","replaceEqualDeep","nearestMatchContext","useRouter","AnyRouter","MakeRouteMatch","MakeRouteMatchUnion","RegisteredRouter","StrictOrFrom","ThrowConstraint","ThrowOrOptional","UseMatchBaseOptions","select","match","TRouter","TFrom","TStrict","TSelected","shouldThrow","TThrow","UseMatchRoute","opts","Accessor","UseMatchResult","UseMatchOptions","useMatch","router","nearestMatch","from","undefined","useContext","ids","stores","matchesId","state","id","matchStore","activeMatchStoresById","get","routeId","createMemo","prev","selectedMatch","hasPendingMatch","Boolean","pendingRouteIds","hasPending","isTransitioning","process","env","NODE_ENV","Error","res"],"sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { invariant, replaceEqualDeep } from '@tanstack/router-core'\nimport { nearestMatchContext } from './matchContext'\nimport { useRouter } from './useRouter'\nimport type {\n AnyRouter,\n MakeRouteMatch,\n MakeRouteMatchUnion,\n RegisteredRouter,\n StrictOrFrom,\n ThrowConstraint,\n ThrowOrOptional,\n} from '@tanstack/router-core'\n\nexport interface UseMatchBaseOptions<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean,\n TThrow extends boolean,\n TSelected,\n> {\n select?: (\n match: MakeRouteMatch<TRouter['routeTree'], TFrom, TStrict>,\n ) => TSelected\n shouldThrow?: TThrow\n}\n\nexport type UseMatchRoute<out TFrom> = <\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n>(\n opts?: UseMatchBaseOptions<TRouter, TFrom, true, true, TSelected>,\n) => Solid.Accessor<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> = StrictOrFrom<TRouter, TFrom, TStrict> &\n UseMatchBaseOptions<TRouter, TFrom, TStrict, TThrow, TSelected>\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\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>(\n opts: UseMatchOptions<\n TRouter,\n TFrom,\n TStrict,\n ThrowConstraint<TStrict, TThrow>,\n TSelected\n >,\n): Solid.Accessor<\n ThrowOrOptional<UseMatchResult<TRouter, TFrom, TStrict, TSelected>, TThrow>\n> {\n const router = useRouter<TRouter>()\n const nearestMatch = opts.from\n ? undefined\n : Solid.useContext(nearestMatchContext)\n\n const match = () => {\n if (opts.from) {\n const ids = router.stores.matchesId.state\n for (const id of ids) {\n const matchStore = router.stores.activeMatchStoresById.get(id)\n if (matchStore?.routeId === opts.from) {\n return matchStore.state\n }\n }\n\n return undefined\n }\n\n return nearestMatch?.match()\n }\n\n return Solid.createMemo((prev: TSelected | undefined) => {\n const selectedMatch = match()\n\n if (selectedMatch === undefined) {\n const hasPendingMatch = opts.from\n ? Boolean(router.stores.pendingRouteIds.state[opts.from!])\n : (nearestMatch?.hasPending() ?? false)\n const isTransitioning = router.stores.isTransitioning.state\n\n if (!hasPendingMatch && !isTransitioning && (opts.shouldThrow ?? true)) {\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 invariant()\n }\n return undefined\n }\n\n const res = opts.select ? opts.select(selectedMatch as any) : selectedMatch\n if (prev === undefined) return res as TSelected\n return replaceEqualDeep(prev, res) as TSelected\n }) as any\n}\n"],"mappings":";;;;;;;AAsDA,SAAgB0B,SAOdJ,MASA;CACA,MAAMK,SAASvB,kBAAAA,WAAoB;CACnC,MAAMwB,eAAeN,KAAKO,OACtBC,KAAAA,IACA9B,SAAM+B,WAAW5B,qBAAAA,oBAAoB;CAEzC,MAAMW,cAAc;AAClB,MAAIQ,KAAKO,MAAM;GACb,MAAMG,MAAML,OAAOM,OAAOC,UAAUC;AACpC,QAAK,MAAMC,MAAMJ,KAAK;IACpB,MAAMK,aAAaV,OAAOM,OAAOK,sBAAsBC,IAAIH,GAAG;AAC9D,QAAIC,YAAYG,YAAYlB,KAAKO,KAC/B,QAAOQ,WAAWF;;AAItB;;AAGF,SAAOP,cAAcd,OAAO;;AAG9B,QAAOd,SAAMyC,YAAYC,SAAgC;EACvD,MAAMC,gBAAgB7B,OAAO;AAE7B,MAAI6B,kBAAkBb,KAAAA,GAAW;GAC/B,MAAMc,kBAAkBtB,KAAKO,OACzBgB,QAAQlB,OAAOM,OAAOa,gBAAgBX,MAAMb,KAAKO,MAAO,GACvDD,cAAcmB,YAAY,IAAI;GACnC,MAAMC,kBAAkBrB,OAAOM,OAAOe,gBAAgBb;AAEtD,OAAI,CAACS,mBAAmB,CAACI,oBAAoB1B,KAAKH,eAAe,OAAO;AACtE,QAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAIiC,MACR,oCAAoC9B,KAAKO,OAAO,yBAAyBP,KAAKO,KAAI,KAAM,qBACzF;AAEH5B,KAAAA,GAAAA,sBAAAA,YAAW;;AAEb;;EAGF,MAAMoD,MAAM/B,KAAKT,SAASS,KAAKT,OAAO8B,cAAqB,GAAGA;AAC9D,MAAID,SAASZ,KAAAA,EAAW,QAAOuB;AAC/B,UAAA,GAAA,sBAAA,kBAAwBX,MAAMW,IAAI;GAClC"}
|
package/dist/cjs/useRouter.cjs
CHANGED
|
@@ -2,12 +2,12 @@ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
|
2
2
|
const require_routerContext = require("./routerContext.cjs");
|
|
3
3
|
let solid_js = require("solid-js");
|
|
4
4
|
solid_js = require_runtime.__toESM(solid_js);
|
|
5
|
-
let tiny_warning = require("tiny-warning");
|
|
6
|
-
tiny_warning = require_runtime.__toESM(tiny_warning);
|
|
7
5
|
//#region src/useRouter.tsx
|
|
8
6
|
function useRouter(opts) {
|
|
9
7
|
const value = solid_js.useContext(require_routerContext.routerContext);
|
|
10
|
-
(
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
if ((opts?.warn ?? true) && !value) console.warn("Warning: useRouter must be used inside a <RouterProvider> component!");
|
|
10
|
+
}
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.cjs","names":["Solid","
|
|
1
|
+
{"version":3,"file":"useRouter.cjs","names":["Solid","routerContext","AnyRouter","RegisteredRouter","useRouter","opts","warn","TRouter","value","useContext","process","env","NODE_ENV","console"],"sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = Solid.useContext(routerContext as any)\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":";;;;;AAIA,SAAgBI,UAAwDC,MAE5D;CACV,MAAMG,QAAQR,SAAMS,WAAWR,sBAAAA,cAAqB;AACpD,KAAA,QAAA,IAAA,aAA6B;OACtBI,MAAMC,QAAQ,SAAS,CAACE,MAC3BK,SAAQP,KACN,uEACD;;AAGL,QAAOE"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { AssetCrossOriginConfig } from '@tanstack/router-core';
|
|
2
|
+
export interface HeadContentProps {
|
|
3
|
+
assetCrossOrigin?: AssetCrossOriginConfig;
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
|
|
3
7
|
* When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`
|
|
4
8
|
* to ensure it's part of the reactive tree and updates correctly during client-side navigation.
|
|
5
9
|
* The component uses portals internally to render content into the `<head>` element.
|
|
6
10
|
*/
|
|
7
|
-
export declare function HeadContent(): import("solid-js").JSX.Element;
|
|
11
|
+
export declare function HeadContent(props: HeadContentProps): import("solid-js").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HeadContentProps } from './HeadContent.js';
|
|
1
2
|
/**
|
|
2
3
|
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
|
|
3
4
|
* When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`
|
|
@@ -7,4 +8,4 @@
|
|
|
7
8
|
* Development version: filters out dev styles link after hydration and
|
|
8
9
|
* includes a fallback cleanup effect for hydration mismatch cases.
|
|
9
10
|
*/
|
|
10
|
-
export declare function HeadContent(): import("solid-js").JSX.Element;
|
|
11
|
+
export declare function HeadContent(props: HeadContentProps): import("solid-js").JSX.Element;
|
|
@@ -15,8 +15,8 @@ var DEV_STYLES_ATTR = "data-tanstack-router-dev-styles";
|
|
|
15
15
|
* Development version: filters out dev styles link after hydration and
|
|
16
16
|
* includes a fallback cleanup effect for hydration mismatch cases.
|
|
17
17
|
*/
|
|
18
|
-
function HeadContent() {
|
|
19
|
-
const tags = useTags();
|
|
18
|
+
function HeadContent(props) {
|
|
19
|
+
const tags = useTags(props.assetCrossOrigin);
|
|
20
20
|
const hydrated = useHydrated();
|
|
21
21
|
const router = useRouter();
|
|
22
22
|
createEffect(() => [hydrated()], ([hydrated]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeadContent.dev.js","names":["For","createEffect","createMemo","Portal","isServer","Asset","useHydrated","useRouter","useTags","DEV_STYLES_ATTR","HeadContent","tags","hydrated","router","const","document","querySelectorAll","forEach","el","remove","filteredTags","filter","tag","attrs","content","_$createComponent","each","children","t","mount","head"],"sources":["../../src/HeadContent.dev.tsx"],"sourcesContent":["import { For, createEffect, createMemo } from 'solid-js'\nimport { Portal, isServer } from '@solidjs/web'\nimport { Asset } from './Asset'\nimport { useHydrated } from './ClientOnly'\nimport { useRouter } from './useRouter'\nimport { useTags } from './headContentUtils'\n\nconst DEV_STYLES_ATTR = 'data-tanstack-router-dev-styles'\n\n/**\n * @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.\n * When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`\n * to ensure it's part of the reactive tree and updates correctly during client-side navigation.\n * The component uses portals internally to render content into the `<head>` element.\n *\n * Development version: filters out dev styles link after hydration and\n * includes a fallback cleanup effect for hydration mismatch cases.\n */\nexport function HeadContent() {\n const tags = useTags()\n const hydrated = useHydrated()\n const router = useRouter()\n\n // Fallback cleanup for hydration mismatch cases\n // Runs when hydration completes to remove any orphaned dev styles links from DOM\n createEffect(\n () => [hydrated()] as const,\n ([hydrated]) => {\n if (hydrated) {\n document\n .querySelectorAll(`link[${DEV_STYLES_ATTR}]`)\n .forEach((el) => el.remove())\n }\n },\n )\n\n // Filter out dev styles after hydration\n const filteredTags = createMemo(() => {\n if (hydrated()) {\n return tags().filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR])\n }\n return tags()\n })\n\n const content = () => (\n <For each={filteredTags()}>\n {(tag) => {\n const t = tag() as any\n return <Asset tag={t.tag} attrs={t.attrs} children={t.children} />\n }}\n </For>\n )\n\n return (isServer ?? router.isServer) ? (\n content()\n ) : (\n <Portal mount={document.head}>{content()}</Portal>\n )\n}\n"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"HeadContent.dev.js","names":["For","createEffect","createMemo","Portal","isServer","Asset","useHydrated","useRouter","useTags","HeadContentProps","DEV_STYLES_ATTR","HeadContent","props","tags","assetCrossOrigin","hydrated","router","const","document","querySelectorAll","forEach","el","remove","filteredTags","filter","tag","attrs","content","_$createComponent","each","children","t","mount","head"],"sources":["../../src/HeadContent.dev.tsx"],"sourcesContent":["import { For, createEffect, createMemo } from 'solid-js'\nimport { Portal, isServer } from '@solidjs/web'\nimport { Asset } from './Asset'\nimport { useHydrated } from './ClientOnly'\nimport { useRouter } from './useRouter'\nimport { useTags } from './headContentUtils'\nimport type { HeadContentProps } from './HeadContent'\n\nconst DEV_STYLES_ATTR = 'data-tanstack-router-dev-styles'\n\n/**\n * @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.\n * When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`\n * to ensure it's part of the reactive tree and updates correctly during client-side navigation.\n * The component uses portals internally to render content into the `<head>` element.\n *\n * Development version: filters out dev styles link after hydration and\n * includes a fallback cleanup effect for hydration mismatch cases.\n */\nexport function HeadContent(props: HeadContentProps) {\n const tags = useTags(props.assetCrossOrigin)\n const hydrated = useHydrated()\n const router = useRouter()\n\n // Fallback cleanup for hydration mismatch cases\n // Runs when hydration completes to remove any orphaned dev styles links from DOM\n createEffect(\n () => [hydrated()] as const,\n ([hydrated]) => {\n if (hydrated) {\n document\n .querySelectorAll(`link[${DEV_STYLES_ATTR}]`)\n .forEach((el) => el.remove())\n }\n },\n )\n\n // Filter out dev styles after hydration\n const filteredTags = createMemo(() => {\n if (hydrated()) {\n return tags().filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR])\n }\n return tags()\n })\n\n const content = () => (\n <For each={filteredTags()}>\n {(tag) => {\n const t = tag() as any\n return <Asset tag={t.tag} attrs={t.attrs} children={t.children} />\n }}\n </For>\n )\n\n return (isServer ?? router.isServer) ? (\n content()\n ) : (\n <Portal mount={document.head}>{content()}</Portal>\n )\n}\n"],"mappings":";;;;;;;AAQA,IAAMU,kBAAkB;;;;;;;;;;AAWxB,SAAgBC,YAAYC,OAAyB;CACnD,MAAMC,OAAOL,QAAQI,MAAME,iBAAiB;CAC5C,MAAMC,WAAWT,aAAa;CAC9B,MAAMU,SAAST,WAAW;AAI1BN,oBACQ,CAACc,UAAU,CAAC,GACjB,CAACA,cAAc;AACd,MAAIA,SACFG,UACGC,iBAAiB,QAAQT,gBAAe,GAAI,CAC5CU,SAASC,OAAOA,GAAGC,QAAQ,CAAC;GAGpC;CAGD,MAAMC,eAAerB,iBAAiB;AACpC,MAAIa,UAAU,CACZ,QAAOF,MAAM,CAACW,QAAQC,QAAQ,CAACA,IAAIC,QAAQhB,iBAAiB;AAE9D,SAAOG,MAAM;GACb;CAEF,MAAMc,gBAAUC,gBACb5B,KAAG;EAAA,IAAC6B,OAAI;AAAA,UAAEN,cAAc;;EAAAO,WACrBL,QAAQ;GACR,MAAMM,IAAIN,KAAK;AACf,UAAAG,gBAAQvB,OAAK;IAAA,IAACoB,MAAG;AAAA,YAAEM,EAAEN;;IAAG,IAAEC,QAAK;AAAA,YAAEK,EAAEL;;IAAK,IAAEI,WAAQ;AAAA,YAAEC,EAAED;;IAAQ,CAAA;;EAC/D,CAEJ;AAED,QAAQ1B,YAAYY,OAAOZ,WACzBuB,SAAS,GAAAC,gBAERzB,QAAM;EAAA,IAAC6B,QAAK;AAAA,UAAEd,SAASe;;EAAI,IAAAH,WAAA;AAAA,UAAGH,SAAS;;EAAA,CACzC"}
|
package/dist/esm/HeadContent.js
CHANGED
|
@@ -10,8 +10,8 @@ import { For } from "solid-js";
|
|
|
10
10
|
* to ensure it's part of the reactive tree and updates correctly during client-side navigation.
|
|
11
11
|
* The component uses portals internally to render content into the `<head>` element.
|
|
12
12
|
*/
|
|
13
|
-
function HeadContent() {
|
|
14
|
-
const tags = useTags();
|
|
13
|
+
function HeadContent(props) {
|
|
14
|
+
const tags = useTags(props.assetCrossOrigin);
|
|
15
15
|
const router = useRouter();
|
|
16
16
|
const content = () => createComponent(For, {
|
|
17
17
|
get each() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeadContent.js","names":["For","Portal","isServer","Asset","useRouter","useTags","HeadContent","tags","router","content","_$createComponent","each","children","tag","t","attrs","mount","document","head"],"sources":["../../src/HeadContent.tsx"],"sourcesContent":["import { For } from 'solid-js'\nimport { Portal, isServer } from '@solidjs/web'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport { useTags } from './headContentUtils'\n\n/**\n * @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.\n * When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`\n * to ensure it's part of the reactive tree and updates correctly during client-side navigation.\n * The component uses portals internally to render content into the `<head>` element.\n */\nexport function HeadContent() {\n const tags = useTags()\n const router = useRouter()\n\n const content = () => (\n <For each={tags()}>\n {(tag) => {\n const t = tag() as any\n return <Asset tag={t.tag} attrs={t.attrs} children={t.children} />\n }}\n </For>\n )\n\n return (isServer ?? router.isServer) ? (\n content()\n ) : (\n <Portal mount={document.head}>{content()}</Portal>\n )\n}\n"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"HeadContent.js","names":["For","Portal","isServer","Asset","useRouter","useTags","AssetCrossOriginConfig","HeadContentProps","assetCrossOrigin","HeadContent","props","tags","router","content","_$createComponent","each","children","tag","t","attrs","mount","document","head"],"sources":["../../src/HeadContent.tsx"],"sourcesContent":["import { For } from 'solid-js'\nimport { Portal, isServer } from '@solidjs/web'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport { useTags } from './headContentUtils'\nimport type { AssetCrossOriginConfig } from '@tanstack/router-core'\n\nexport interface HeadContentProps {\n assetCrossOrigin?: AssetCrossOriginConfig\n}\n\n/**\n * @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.\n * When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`\n * to ensure it's part of the reactive tree and updates correctly during client-side navigation.\n * The component uses portals internally to render content into the `<head>` element.\n */\nexport function HeadContent(props: HeadContentProps) {\n const tags = useTags(props.assetCrossOrigin)\n const router = useRouter()\n\n const content = () => (\n <For each={tags()}>\n {(tag) => {\n const t = tag() as any\n return <Asset tag={t.tag} attrs={t.attrs} children={t.children} />\n }}\n </For>\n )\n\n return (isServer ?? router.isServer) ? (\n content()\n ) : (\n <Portal mount={document.head}>{content()}</Portal>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAgBS,YAAYC,OAAyB;CACnD,MAAMC,OAAON,QAAQK,MAAMF,iBAAiB;CAC5C,MAAMI,SAASR,WAAW;CAE1B,MAAMS,gBAAUC,gBACbd,KAAG;EAAA,IAACe,OAAI;AAAA,UAAEJ,MAAM;;EAAAK,WACbC,QAAQ;GACR,MAAMC,IAAID,KAAK;AACf,UAAAH,gBAAQX,OAAK;IAAA,IAACc,MAAG;AAAA,YAAEC,EAAED;;IAAG,IAAEE,QAAK;AAAA,YAAED,EAAEC;;IAAK,IAAEH,WAAQ;AAAA,YAAEE,EAAEF;;IAAQ,CAAA;;EAC/D,CAEJ;AAED,QAAQd,YAAYU,OAAOV,WACzBW,SAAS,GAAAC,gBAERb,QAAM;EAAA,IAACmB,QAAK;AAAA,UAAEC,SAASC;;EAAI,IAAAN,WAAA;AAAA,UAAGH,SAAS;;EAAA,CACzC"}
|