@tanstack/solid-router 1.167.4 → 1.168.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/dist/cjs/Match.cjs +244 -223
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Match.d.cts +1 -3
- package/dist/cjs/Matches.cjs +32 -31
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +10 -8
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/Scripts.d.cts +2 -1
- package/dist/cjs/Transitioner.cjs +26 -26
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +15 -15
- 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 +119 -84
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/matchContext.cjs +7 -5
- package/dist/cjs/matchContext.cjs.map +1 -1
- package/dist/cjs/matchContext.d.cts +8 -2
- package/dist/cjs/not-found.cjs +8 -4
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +1 -1
- package/dist/cjs/router.cjs +2 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/routerStores.cjs +67 -0
- package/dist/cjs/routerStores.cjs.map +1 -0
- package/dist/cjs/routerStores.d.cts +10 -0
- package/dist/cjs/ssr/RouterClient.cjs +1 -1
- package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToStream.cjs +1 -1
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs +2 -2
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.d.cts +1 -1
- package/dist/cjs/useCanGoBack.cjs +6 -2
- package/dist/cjs/useCanGoBack.cjs.map +1 -1
- package/dist/cjs/useCanGoBack.d.cts +2 -1
- package/dist/cjs/useLoaderDeps.cjs +2 -3
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLocation.cjs +13 -2
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +17 -15
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useParams.cjs +1 -1
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useRouterState.cjs +12 -19
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useSearch.cjs +2 -1
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/utils.cjs +0 -14
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -4
- package/dist/esm/Match.d.ts +1 -3
- package/dist/esm/Match.js +245 -224
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +34 -33
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/Scripts.d.ts +2 -1
- package/dist/esm/Scripts.js +8 -7
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/Transitioner.js +26 -26
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/headContentUtils.js +15 -15
- 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 +120 -85
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/matchContext.d.ts +8 -2
- package/dist/esm/matchContext.js +7 -4
- package/dist/esm/matchContext.js.map +1 -1
- package/dist/esm/not-found.d.ts +1 -1
- package/dist/esm/not-found.js +6 -3
- package/dist/esm/not-found.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 +10 -0
- package/dist/esm/routerStores.js +65 -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 +1 -1
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.d.ts +1 -1
- package/dist/esm/ssr/renderRouterToString.js +2 -2
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/useCanGoBack.d.ts +2 -1
- package/dist/esm/useCanGoBack.js +4 -2
- package/dist/esm/useCanGoBack.js.map +1 -1
- package/dist/esm/useLoaderDeps.js +2 -3
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useLocation.js +11 -2
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.js +18 -16
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useParams.js +1 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouterState.js +10 -18
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.js +2 -1
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +0 -4
- package/dist/esm/utils.js +1 -14
- package/dist/esm/utils.js.map +1 -1
- package/dist/source/Match.d.ts +1 -3
- package/dist/source/Match.jsx +246 -237
- package/dist/source/Match.jsx.map +1 -1
- package/dist/source/Matches.jsx +42 -44
- package/dist/source/Matches.jsx.map +1 -1
- package/dist/source/Scripts.d.ts +2 -1
- package/dist/source/Scripts.jsx +31 -36
- package/dist/source/Scripts.jsx.map +1 -1
- package/dist/source/Transitioner.jsx +26 -31
- package/dist/source/Transitioner.jsx.map +1 -1
- package/dist/source/headContentUtils.jsx +64 -72
- package/dist/source/headContentUtils.jsx.map +1 -1
- package/dist/source/link.jsx +136 -107
- package/dist/source/link.jsx.map +1 -1
- package/dist/source/matchContext.d.ts +8 -2
- package/dist/source/matchContext.jsx +7 -3
- package/dist/source/matchContext.jsx.map +1 -1
- package/dist/source/not-found.d.ts +1 -1
- package/dist/source/not-found.jsx +6 -5
- package/dist/source/not-found.jsx.map +1 -1
- package/dist/source/router.js +2 -1
- package/dist/source/router.js.map +1 -1
- package/dist/source/routerStores.d.ts +10 -0
- package/dist/source/routerStores.js +71 -0
- package/dist/source/routerStores.js.map +1 -0
- package/dist/source/ssr/RouterClient.jsx +1 -1
- package/dist/source/ssr/RouterClient.jsx.map +1 -1
- package/dist/source/ssr/renderRouterToStream.jsx +1 -1
- package/dist/source/ssr/renderRouterToStream.jsx.map +1 -1
- package/dist/source/ssr/renderRouterToString.d.ts +1 -1
- package/dist/source/ssr/renderRouterToString.jsx +2 -2
- package/dist/source/ssr/renderRouterToString.jsx.map +1 -1
- package/dist/source/useCanGoBack.d.ts +2 -1
- package/dist/source/useCanGoBack.js +4 -2
- package/dist/source/useCanGoBack.js.map +1 -1
- package/dist/source/useLoaderDeps.jsx +2 -3
- package/dist/source/useLoaderDeps.jsx.map +1 -1
- package/dist/source/useLocation.jsx +13 -3
- package/dist/source/useLocation.jsx.map +1 -1
- package/dist/source/useMatch.jsx +30 -27
- package/dist/source/useMatch.jsx.map +1 -1
- package/dist/source/useParams.jsx +1 -1
- package/dist/source/useParams.jsx.map +1 -1
- package/dist/source/useRouterState.jsx +12 -33
- package/dist/source/useRouterState.jsx.map +1 -1
- package/dist/source/useSearch.jsx +2 -1
- package/dist/source/useSearch.jsx.map +1 -1
- package/dist/source/utils.d.ts +0 -4
- package/dist/source/utils.js +0 -13
- package/dist/source/utils.js.map +1 -1
- package/package.json +2 -3
- package/skills/solid-router/SKILL.md +2 -0
- package/src/Match.tsx +351 -304
- package/src/Matches.tsx +49 -52
- package/src/Scripts.tsx +40 -41
- package/src/Transitioner.tsx +67 -66
- package/src/headContentUtils.tsx +89 -91
- package/src/link.tsx +179 -141
- package/src/matchContext.tsx +16 -7
- package/src/not-found.tsx +6 -6
- package/src/router.ts +2 -1
- package/src/routerStores.ts +107 -0
- package/src/ssr/RouterClient.tsx +1 -1
- package/src/ssr/renderRouterToStream.tsx +1 -1
- package/src/ssr/renderRouterToString.tsx +2 -2
- package/src/useCanGoBack.ts +6 -2
- package/src/useLoaderDeps.tsx +2 -3
- package/src/useLocation.tsx +18 -5
- package/src/useMatch.tsx +36 -43
- package/src/useParams.tsx +2 -3
- package/src/useRouterState.tsx +17 -41
- package/src/useSearch.tsx +2 -1
- package/src/utils.ts +0 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headContentUtils.js","names":["Solid","escapeHtml","useRouter","
|
|
1
|
+
{"version":3,"file":"headContentUtils.js","names":["Solid","escapeHtml","useRouter","RouterManagedTag","useTags","router","nonce","options","ssr","activeMatches","createMemo","stores","activeMatchesSnapshot","state","routeMeta","map","match","meta","filter","Boolean","Accessor","Array","resultMeta","metaByAttribute","Record","title","routeMetasArray","i","length","metas","j","m","tag","children","json","JSON","stringify","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","uniqBy","d","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 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 () =>\n uniqBy(\n [\n ...meta(),\n ...preloadLinks(),\n ...links(),\n ...styles(),\n ...headScripts(),\n ] as Array<RouterManagedTag>,\n (d) => {\n return JSON.stringify(d)\n },\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,WAAW;CAC1B,MAAMI,QAAQD,OAAOE,QAAQC,KAAKF;CAClC,MAAMG,gBAAgBT,MAAMU,iBACpBL,OAAOM,OAAOC,sBAAsBC,MAC3C;CACD,MAAMC,YAAYd,MAAMU,iBACtBD,eAAe,CACZM,KAAKC,UAAUA,MAAMC,KAAM,CAC3BC,OAAOC,QACZ,CAAC;CAED,MAAMF,OAAgDjB,MAAMU,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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,MAAME,uBAAO,IAAIC,KAAa;AAC9B,QAAOL,IAAIpD,QAAQuD,SAAS;EAC1B,MAAMG,MAAMJ,GAAGC,KAAK;AACpB,MAAIC,KAAKG,IAAID,IAAI,CACf,QAAO;AAETF,OAAKI,IAAIF,IAAI;AACb,SAAO;GACP"}
|
package/dist/esm/index.dev.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Await, useAwaited } from "./awaited.js";
|
|
|
2
2
|
import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
|
|
3
3
|
import { ClientOnly, useHydrated } from "./ClientOnly.js";
|
|
4
4
|
import { useRouter } from "./useRouter.js";
|
|
5
|
-
import { useRouterState } from "./useRouterState.js";
|
|
6
5
|
import { Link, createLink, linkOptions, useLinkProps } from "./link.js";
|
|
7
6
|
import { useMatch } from "./useMatch.js";
|
|
8
7
|
import { useLoaderData } from "./useLoaderData.js";
|
|
@@ -22,6 +21,7 @@ import { Router, createRouter } from "./router.js";
|
|
|
22
21
|
import { RouterContextProvider, RouterProvider } from "./RouterProvider.js";
|
|
23
22
|
import { ScrollRestoration, useElementScrollRestoration } from "./ScrollRestoration.js";
|
|
24
23
|
import { Block, useBlocker } from "./useBlocker.js";
|
|
24
|
+
import { useRouterState } from "./useRouterState.js";
|
|
25
25
|
import { useLocation } from "./useLocation.js";
|
|
26
26
|
import { useCanGoBack } from "./useCanGoBack.js";
|
|
27
27
|
import { Asset } from "./Asset.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Await, useAwaited } from "./awaited.js";
|
|
|
2
2
|
import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
|
|
3
3
|
import { ClientOnly, useHydrated } from "./ClientOnly.js";
|
|
4
4
|
import { useRouter } from "./useRouter.js";
|
|
5
|
-
import { useRouterState } from "./useRouterState.js";
|
|
6
5
|
import { Link, createLink, linkOptions, useLinkProps } from "./link.js";
|
|
7
6
|
import { useMatch } from "./useMatch.js";
|
|
8
7
|
import { useLoaderData } from "./useLoaderData.js";
|
|
@@ -22,6 +21,7 @@ import { Router, createRouter } from "./router.js";
|
|
|
22
21
|
import { RouterContextProvider, RouterProvider } from "./RouterProvider.js";
|
|
23
22
|
import { ScrollRestoration, useElementScrollRestoration } from "./ScrollRestoration.js";
|
|
24
23
|
import { Block, useBlocker } from "./useBlocker.js";
|
|
24
|
+
import { useRouterState } from "./useRouterState.js";
|
|
25
25
|
import { useLocation } from "./useLocation.js";
|
|
26
26
|
import { useCanGoBack } from "./useCanGoBack.js";
|
|
27
27
|
import { Asset } from "./Asset.js";
|
package/dist/esm/link.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { useHydrated } from "./ClientOnly.js";
|
|
2
2
|
import { useRouter } from "./useRouter.js";
|
|
3
|
-
import { useRouterState } from "./useRouterState.js";
|
|
4
3
|
import { useIntersectionObserver } from "./utils.js";
|
|
5
4
|
import { deepEqual, exactPathTest, functionalUpdate, isDangerousProtocol, preloadWarning, removeTrailingSlash } from "@tanstack/router-core";
|
|
6
|
-
import { Dynamic, createComponent, insert,
|
|
5
|
+
import { Dynamic, createComponent, insert, mergeProps, spread, template } from "solid-js/web";
|
|
7
6
|
import * as Solid from "solid-js";
|
|
8
7
|
import { mergeRefs } from "@solid-primitives/refs";
|
|
9
8
|
import { isServer } from "@tanstack/router-core/isServer";
|
|
10
9
|
//#region src/link.tsx
|
|
11
|
-
var _tmpl$ = /* @__PURE__ */ template(`<svg><a>`);
|
|
10
|
+
var _tmpl$ = /* @__PURE__ */ template(`<svg><a>`), _tmpl$2 = /* @__PURE__ */ template(`<a>`);
|
|
12
11
|
var timeoutMap = /* @__PURE__ */ new WeakMap();
|
|
13
12
|
function useLinkProps(options) {
|
|
14
13
|
const router = useRouter();
|
|
@@ -17,8 +16,8 @@ function useLinkProps(options) {
|
|
|
17
16
|
const hasHydrated = useHydrated();
|
|
18
17
|
let hasRenderFetched = false;
|
|
19
18
|
const [local, rest] = Solid.splitProps(Solid.mergeProps({
|
|
20
|
-
activeProps:
|
|
21
|
-
inactiveProps:
|
|
19
|
+
activeProps: STATIC_ACTIVE_PROPS_GET,
|
|
20
|
+
inactiveProps: STATIC_INACTIVE_PROPS_GET
|
|
22
21
|
}, options), [
|
|
23
22
|
"activeProps",
|
|
24
23
|
"inactiveProps",
|
|
@@ -54,25 +53,14 @@ function useLinkProps(options) {
|
|
|
54
53
|
"reloadDocument",
|
|
55
54
|
"unsafeRelative"
|
|
56
55
|
]);
|
|
57
|
-
const currentLocation =
|
|
58
|
-
const
|
|
59
|
-
const leaf = s.matches[s.matches.length - 1];
|
|
60
|
-
return {
|
|
61
|
-
search: leaf?.search,
|
|
62
|
-
hash: s.location.hash,
|
|
63
|
-
path: leaf?.pathname
|
|
64
|
-
};
|
|
65
|
-
} });
|
|
66
|
-
const from = options.from;
|
|
67
|
-
const _options = () => {
|
|
68
|
-
return {
|
|
69
|
-
...options,
|
|
70
|
-
from
|
|
71
|
-
};
|
|
72
|
-
};
|
|
56
|
+
const currentLocation = Solid.createMemo(() => router.stores.location.state, void 0, { equals: (prev, next) => prev.href === next.href });
|
|
57
|
+
const _options = () => options;
|
|
73
58
|
const next = Solid.createMemo(() => {
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
const options = {
|
|
60
|
+
_fromLocation: currentLocation(),
|
|
61
|
+
..._options()
|
|
62
|
+
};
|
|
63
|
+
return Solid.untrack(() => router.buildLocation(options));
|
|
76
64
|
});
|
|
77
65
|
const hrefOption = Solid.createMemo(() => {
|
|
78
66
|
if (_options().disabled) return void 0;
|
|
@@ -97,7 +85,8 @@ function useLinkProps(options) {
|
|
|
97
85
|
return _href.href;
|
|
98
86
|
}
|
|
99
87
|
const to = _options().to;
|
|
100
|
-
if (
|
|
88
|
+
if (isSafeInternal(to)) return void 0;
|
|
89
|
+
if (typeof to !== "string" || to.indexOf(":") === -1) return void 0;
|
|
101
90
|
try {
|
|
102
91
|
new URL(to);
|
|
103
92
|
if (isDangerousProtocol(to, router.protocolAllowlist)) {
|
|
@@ -114,22 +103,29 @@ function useLinkProps(options) {
|
|
|
114
103
|
const preloadDelay = () => local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0;
|
|
115
104
|
const isActive = Solid.createMemo(() => {
|
|
116
105
|
if (externalLink()) return false;
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
const activeOptions = local.activeOptions;
|
|
107
|
+
const current = currentLocation();
|
|
108
|
+
const nextLocation = next();
|
|
109
|
+
if (activeOptions?.exact) {
|
|
110
|
+
if (!exactPathTest(current.pathname, nextLocation.pathname, router.basepath)) return false;
|
|
119
111
|
} else {
|
|
120
|
-
const
|
|
121
|
-
|
|
112
|
+
const currentPath = removeTrailingSlash(current.pathname, router.basepath);
|
|
113
|
+
const nextPath = removeTrailingSlash(nextLocation.pathname, router.basepath);
|
|
114
|
+
if (!(currentPath.startsWith(nextPath) && (currentPath.length === nextPath.length || currentPath[nextPath.length] === "/"))) return false;
|
|
122
115
|
}
|
|
123
|
-
if (
|
|
124
|
-
if (!deepEqual(
|
|
125
|
-
partial: !
|
|
126
|
-
ignoreUndefined: !
|
|
116
|
+
if (activeOptions?.includeSearch ?? true) {
|
|
117
|
+
if (!deepEqual(current.search, nextLocation.search, {
|
|
118
|
+
partial: !activeOptions?.exact,
|
|
119
|
+
ignoreUndefined: !activeOptions?.explicitUndefined
|
|
127
120
|
})) return false;
|
|
128
121
|
}
|
|
129
|
-
if (
|
|
122
|
+
if (activeOptions?.includeHash) return (shouldHydrateHash && !hasHydrated() ? "" : current.hash) === nextLocation.hash;
|
|
130
123
|
return true;
|
|
131
124
|
});
|
|
132
|
-
const doPreload = () => router.preloadRoute(
|
|
125
|
+
const doPreload = () => router.preloadRoute({
|
|
126
|
+
..._options(),
|
|
127
|
+
_builtLocation: next()
|
|
128
|
+
}).catch((err) => {
|
|
133
129
|
console.warn(err);
|
|
134
130
|
console.warn(preloadWarning);
|
|
135
131
|
});
|
|
@@ -209,62 +205,89 @@ function useLinkProps(options) {
|
|
|
209
205
|
timeoutMap.delete(eventTarget);
|
|
210
206
|
}
|
|
211
207
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const resolvedInactiveProps = () => isActive() ? {} : functionalUpdate(local.inactiveProps, {});
|
|
225
|
-
const resolvedClassName = () => [
|
|
226
|
-
local.class,
|
|
227
|
-
resolvedActiveProps().class,
|
|
228
|
-
resolvedInactiveProps().class
|
|
229
|
-
].filter(Boolean).join(" ");
|
|
230
|
-
const resolvedStyle = () => ({
|
|
231
|
-
...local.style,
|
|
232
|
-
...resolvedActiveProps().style,
|
|
233
|
-
...resolvedInactiveProps().style
|
|
234
|
-
});
|
|
235
|
-
return Solid.mergeProps(propsSafeToSpread, resolvedActiveProps, resolvedInactiveProps, () => {
|
|
236
|
-
return {
|
|
208
|
+
const simpleStyling = Solid.createMemo(() => local.activeProps === STATIC_ACTIVE_PROPS_GET && local.inactiveProps === STATIC_INACTIVE_PROPS_GET && local.class === void 0 && local.style === void 0);
|
|
209
|
+
const onClick = createComposedHandler(() => local.onClick, handleClick);
|
|
210
|
+
const onBlur = createComposedHandler(() => local.onBlur, handleLeave);
|
|
211
|
+
const onFocus = createComposedHandler(() => local.onFocus, enqueueIntentPreload);
|
|
212
|
+
const onMouseEnter = createComposedHandler(() => local.onMouseEnter, enqueueIntentPreload);
|
|
213
|
+
const onMouseOver = createComposedHandler(() => local.onMouseOver, enqueueIntentPreload);
|
|
214
|
+
const onMouseLeave = createComposedHandler(() => local.onMouseLeave, handleLeave);
|
|
215
|
+
const onMouseOut = createComposedHandler(() => local.onMouseOut, handleLeave);
|
|
216
|
+
const onTouchStart = createComposedHandler(() => local.onTouchStart, handleTouchStart);
|
|
217
|
+
const resolvedProps = Solid.createMemo(() => {
|
|
218
|
+
const active = isActive();
|
|
219
|
+
const base = {
|
|
237
220
|
href: hrefOption()?.href,
|
|
238
221
|
ref: mergeRefs(setRef, _options().ref),
|
|
239
|
-
onClick
|
|
240
|
-
onBlur
|
|
241
|
-
onFocus
|
|
242
|
-
onMouseEnter
|
|
243
|
-
onMouseOver
|
|
244
|
-
onMouseLeave
|
|
245
|
-
onMouseOut
|
|
246
|
-
onTouchStart
|
|
222
|
+
onClick,
|
|
223
|
+
onBlur,
|
|
224
|
+
onFocus,
|
|
225
|
+
onMouseEnter,
|
|
226
|
+
onMouseOver,
|
|
227
|
+
onMouseLeave,
|
|
228
|
+
onMouseOut,
|
|
229
|
+
onTouchStart,
|
|
247
230
|
disabled: !!local.disabled,
|
|
248
231
|
target: local.target,
|
|
249
|
-
...
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
...
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
...
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
232
|
+
...local.disabled && STATIC_DISABLED_PROPS,
|
|
233
|
+
...isTransitioning() && STATIC_TRANSITIONING_ATTRIBUTES
|
|
234
|
+
};
|
|
235
|
+
if (simpleStyling()) return {
|
|
236
|
+
...base,
|
|
237
|
+
...active && STATIC_DEFAULT_ACTIVE_ATTRIBUTES
|
|
238
|
+
};
|
|
239
|
+
const activeProps = active ? functionalUpdate(local.activeProps, {}) ?? EMPTY_OBJECT : EMPTY_OBJECT;
|
|
240
|
+
const inactiveProps = active ? EMPTY_OBJECT : functionalUpdate(local.inactiveProps, {});
|
|
241
|
+
const style = {
|
|
242
|
+
...local.style,
|
|
243
|
+
...activeProps.style,
|
|
244
|
+
...inactiveProps.style
|
|
245
|
+
};
|
|
246
|
+
const className = [
|
|
247
|
+
local.class,
|
|
248
|
+
activeProps.class,
|
|
249
|
+
inactiveProps.class
|
|
250
|
+
].filter(Boolean).join(" ");
|
|
251
|
+
return {
|
|
252
|
+
...activeProps,
|
|
253
|
+
...inactiveProps,
|
|
254
|
+
...base,
|
|
255
|
+
...Object.keys(style).length ? { style } : void 0,
|
|
256
|
+
...className ? { class: className } : void 0,
|
|
257
|
+
...active && STATIC_ACTIVE_ATTRIBUTES
|
|
266
258
|
};
|
|
267
259
|
});
|
|
260
|
+
return Solid.mergeProps(propsSafeToSpread, resolvedProps);
|
|
261
|
+
}
|
|
262
|
+
var STATIC_ACTIVE_PROPS = { class: "active" };
|
|
263
|
+
var STATIC_ACTIVE_PROPS_GET = () => STATIC_ACTIVE_PROPS;
|
|
264
|
+
var EMPTY_OBJECT = {};
|
|
265
|
+
var STATIC_INACTIVE_PROPS_GET = () => EMPTY_OBJECT;
|
|
266
|
+
var STATIC_DEFAULT_ACTIVE_ATTRIBUTES = {
|
|
267
|
+
class: "active",
|
|
268
|
+
"data-status": "active",
|
|
269
|
+
"aria-current": "page"
|
|
270
|
+
};
|
|
271
|
+
var STATIC_DISABLED_PROPS = {
|
|
272
|
+
role: "link",
|
|
273
|
+
"aria-disabled": true
|
|
274
|
+
};
|
|
275
|
+
var STATIC_ACTIVE_ATTRIBUTES = {
|
|
276
|
+
"data-status": "active",
|
|
277
|
+
"aria-current": "page"
|
|
278
|
+
};
|
|
279
|
+
var STATIC_TRANSITIONING_ATTRIBUTES = { "data-transitioning": "transitioning" };
|
|
280
|
+
/** Call a JSX.EventHandlerUnion with the event. */
|
|
281
|
+
function callHandler(event, handler) {
|
|
282
|
+
if (typeof handler === "function") handler(event);
|
|
283
|
+
else handler[0](handler[1], event);
|
|
284
|
+
return event.defaultPrevented;
|
|
285
|
+
}
|
|
286
|
+
function createComposedHandler(getHandler, fallback) {
|
|
287
|
+
return (event) => {
|
|
288
|
+
const handler = getHandler();
|
|
289
|
+
if (!handler || !callHandler(event, handler)) fallback(event);
|
|
290
|
+
};
|
|
268
291
|
}
|
|
269
292
|
function createLink(Comp) {
|
|
270
293
|
return (props) => createComponent(Link, mergeProps(props, { _asChild: Comp }));
|
|
@@ -293,8 +316,14 @@ var Link = (props) => {
|
|
|
293
316
|
return _el$;
|
|
294
317
|
})();
|
|
295
318
|
}
|
|
319
|
+
if (!local._asChild) return (() => {
|
|
320
|
+
var _el$3 = _tmpl$2();
|
|
321
|
+
spread(_el$3, linkProps, false, true);
|
|
322
|
+
insert(_el$3, children);
|
|
323
|
+
return _el$3;
|
|
324
|
+
})();
|
|
296
325
|
return createComponent(Dynamic, mergeProps({ get component() {
|
|
297
|
-
return
|
|
326
|
+
return local._asChild;
|
|
298
327
|
} }, linkProps, { get children() {
|
|
299
328
|
return children();
|
|
300
329
|
} }));
|
|
@@ -302,6 +331,12 @@ var Link = (props) => {
|
|
|
302
331
|
function isCtrlEvent(e) {
|
|
303
332
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
304
333
|
}
|
|
334
|
+
function isSafeInternal(to) {
|
|
335
|
+
if (typeof to !== "string") return false;
|
|
336
|
+
const zero = to.charCodeAt(0);
|
|
337
|
+
if (zero === 47) return to.charCodeAt(1) !== 47;
|
|
338
|
+
return zero === 46;
|
|
339
|
+
}
|
|
305
340
|
var linkOptions = (options) => {
|
|
306
341
|
return options;
|
|
307
342
|
};
|
package/dist/esm/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","names":["Solid","mergeRefs","deepEqual","exactPathTest","functionalUpdate","isDangerousProtocol","preloadWarning","removeTrailingSlash","isServer","Dynamic","useRouterState","useRouter","useIntersectionObserver","useHydrated","AnyRouter","Constrain","LinkOptions","RegisteredRouter","RoutePaths","ValidateLinkOptions","ValidateLinkOptionsArray","timeoutMap","WeakMap","EventTarget","ReturnType","setTimeout","useLinkProps","TRouter","TFrom","options","UseLinkPropsOptions","TTo","TMaskFrom","TMaskTo","ComponentProps","router","isTransitioning","setIsTransitioning","createSignal","shouldHydrateHash","ssr","hasHydrated","hasRenderFetched","local","rest","splitProps","mergeProps","activeProps","class","inactiveProps","_","propsSafeToSpread","currentLocation","select","s","location","buildLocationKey","leaf","matches","length","search","hash","path","pathname","from","_options","next","createMemo","buildLocation","hrefOption","disabled","undefined","maskedLocation","publicHref","external","href","history","createHref","externalLink","_href","protocolAllowlist","process","env","NODE_ENV","console","warn","to","isSafeInternal","charCodeAt","URL","preload","reloadDocument","defaultPreload","preloadDelay","defaultPreloadDelay","isActive","activeOptions","exact","testExact","basepath","currentPathSplit","split","nextPathSplit","pathIsFuzzyEqual","every","d","i","includeSearch","searchTest","partial","ignoreUndefined","explicitUndefined","includeHash","currentHash","doPreload","preloadRoute","catch","err","preloadViewportIoCallback","entry","IntersectionObserverEntry","isIntersecting","ref","setRef","Element","rootMargin","createEffect","handleClick","e","MouseEvent","elementTarget","currentTarget","HTMLAnchorElement","SVGAElement","getAttribute","effectiveTarget","target","isCtrlEvent","defaultPrevented","button","preventDefault","unsub","subscribe","navigate","replace","resetScroll","hashScrollIntoView","startTransition","viewTransition","ignoreBlocker","enqueueIntentPreload","FocusEvent","eventTarget","has","set","delete","handleTouchStart","TouchEvent","handleLeave","id","get","clearTimeout","callHandler","Event","event","TEvent","T","handler","JSX","EventHandlerUnion","composeEventHandlers","handlers","Array","resolvedActiveProps","Omit","style","CSSProperties","resolvedInactiveProps","resolvedClassName","filter","Boolean","join","resolvedStyle","onClick","onBlur","onFocus","onMouseEnter","onMouseOver","onMouseLeave","onMouseOut","onTouchStart","Object","keys","c","role","ActiveLinkOptions","ActiveLinkOptionProps","TComp","ActiveLinkProps","Partial","LinkComponentSolidProps","key","LinkProps","LinkPropsChildren","children","state","ValidComponent","CreateLinkProps","LinkComponentProps","LinkComponent","TDefaultFrom","props","LinkComponentRoute","defaultFrom","createLink","Comp","_$createComponent","Link","_$mergeProps","_asChild","linkProps","ch","svgLinkProps","_el$","_tmpl$","_el$2","firstChild","_$spread","_$insert","component","_$memo","metaKey","altKey","ctrlKey","shiftKey","LinkOptionsFnOptions","TOptions","ReadonlyArray","LinkOptionsFn","linkOptions"],"sources":["../../src/link.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\n\nimport { mergeRefs } from '@solid-primitives/refs'\n\nimport {\n deepEqual,\n exactPathTest,\n functionalUpdate,\n isDangerousProtocol,\n preloadWarning,\n removeTrailingSlash,\n} from '@tanstack/router-core'\n\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { Dynamic } from 'solid-js/web'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\n\nimport { useIntersectionObserver } from './utils'\n\nimport { useHydrated } from './ClientOnly'\nimport type {\n AnyRouter,\n Constrain,\n LinkOptions,\n RegisteredRouter,\n RoutePaths,\n} from '@tanstack/router-core'\nimport type {\n ValidateLinkOptions,\n ValidateLinkOptionsArray,\n} from './typePrimitives'\n\nconst timeoutMap = new WeakMap<EventTarget, ReturnType<typeof setTimeout>>()\n\nexport function useLinkProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Solid.ComponentProps<'a'> {\n const router = useRouter()\n const [isTransitioning, setIsTransitioning] = Solid.createSignal(false)\n const shouldHydrateHash = !isServer && !!router.options.ssr\n const hasHydrated = useHydrated()\n\n let hasRenderFetched = false\n\n const [local, rest] = Solid.splitProps(\n Solid.mergeProps(\n {\n activeProps: () => ({ class: 'active' }),\n inactiveProps: () => ({}),\n },\n options,\n ),\n [\n 'activeProps',\n 'inactiveProps',\n 'activeOptions',\n 'to',\n 'preload',\n 'preloadDelay',\n 'hashScrollIntoView',\n 'replace',\n 'startTransition',\n 'resetScroll',\n 'viewTransition',\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onBlur',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOver',\n 'onMouseOut',\n 'onTouchStart',\n 'ignoreBlocker',\n ],\n )\n\n // const {\n // // custom props\n // activeProps = () => ({ class: 'active' }),\n // inactiveProps = () => ({}),\n // activeOptions,\n // to,\n // preload: userPreload,\n // preloadDelay: userPreloadDelay,\n // hashScrollIntoView,\n // replace,\n // startTransition,\n // resetScroll,\n // viewTransition,\n // // element props\n // children,\n // target,\n // disabled,\n // style,\n // class,\n // onClick,\n // onFocus,\n // onMouseEnter,\n // onMouseLeave,\n // onTouchStart,\n // ignoreBlocker,\n // ...rest\n // } = options\n\n const [_, propsSafeToSpread] = Solid.splitProps(rest, [\n 'params',\n 'search',\n 'hash',\n 'state',\n 'mask',\n 'reloadDocument',\n 'unsafeRelative',\n ])\n\n const currentLocation = useRouterState({\n select: (s) => s.location,\n })\n\n const buildLocationKey = useRouterState({\n select: (s) => {\n const leaf = s.matches[s.matches.length - 1]\n return {\n search: leaf?.search,\n hash: s.location.hash,\n path: leaf?.pathname, // path + params\n }\n },\n })\n\n const from = options.from\n\n const _options = () => {\n return {\n ...options,\n from,\n }\n }\n\n const next = Solid.createMemo(() => {\n buildLocationKey()\n return router.buildLocation(_options() as any)\n })\n\n const hrefOption = Solid.createMemo(() => {\n if (_options().disabled) return undefined\n // Use publicHref - it contains the correct href for display\n // When a rewrite changes the origin, publicHref is the full URL\n // Otherwise it's the origin-stripped path\n // This avoids constructing URL objects in the hot path\n const location = next().maskedLocation ?? next()\n const publicHref = location.publicHref\n const external = location.external\n\n if (external) {\n return { href: publicHref, external: true }\n }\n\n return {\n href: router.history.createHref(publicHref) || '/',\n external: false,\n }\n })\n\n const externalLink = Solid.createMemo(() => {\n const _href = hrefOption()\n if (_href?.external) {\n // Block dangerous protocols for external links\n if (isDangerousProtocol(_href.href, router.protocolAllowlist)) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Blocked Link with dangerous protocol: ${_href.href}`)\n }\n return undefined\n }\n return _href.href\n }\n const to = _options().to\n const isSafeInternal =\n typeof to === 'string' &&\n to.charCodeAt(0) === 47 && // '/'\n to.charCodeAt(1) !== 47 // but not '//'\n if (isSafeInternal) return undefined\n try {\n new URL(to as any)\n // Block dangerous protocols like javascript:, blob:, data:\n if (isDangerousProtocol(to as string, router.protocolAllowlist)) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Blocked Link with dangerous protocol: ${to}`)\n }\n return undefined\n }\n return to\n } catch {}\n return undefined\n })\n\n const preload = Solid.createMemo(() => {\n if (_options().reloadDocument || externalLink()) {\n return false\n }\n return local.preload ?? router.options.defaultPreload\n })\n const preloadDelay = () =>\n local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = Solid.createMemo(() => {\n if (externalLink()) return false\n if (local.activeOptions?.exact) {\n const testExact = exactPathTest(\n currentLocation().pathname,\n next().pathname,\n router.basepath,\n )\n if (!testExact) {\n return false\n }\n } else {\n const currentPathSplit = removeTrailingSlash(\n currentLocation().pathname,\n router.basepath,\n ).split('/')\n const nextPathSplit = removeTrailingSlash(\n next()?.pathname,\n router.basepath,\n )?.split('/')\n\n const pathIsFuzzyEqual = nextPathSplit?.every(\n (d, i) => d === currentPathSplit[i],\n )\n if (!pathIsFuzzyEqual) {\n return false\n }\n }\n\n if (local.activeOptions?.includeSearch ?? true) {\n const searchTest = deepEqual(currentLocation().search, next().search, {\n partial: !local.activeOptions?.exact,\n ignoreUndefined: !local.activeOptions?.explicitUndefined,\n })\n if (!searchTest) {\n return false\n }\n }\n\n if (local.activeOptions?.includeHash) {\n const currentHash =\n shouldHydrateHash && !hasHydrated() ? '' : currentLocation().hash\n return currentHash === next().hash\n }\n return true\n })\n\n const doPreload = () =>\n router.preloadRoute(_options() as any).catch((err: any) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n\n const preloadViewportIoCallback = (\n entry: IntersectionObserverEntry | undefined,\n ) => {\n if (entry?.isIntersecting) {\n doPreload()\n }\n }\n\n const [ref, setRef] = Solid.createSignal<Element | null>(null)\n\n useIntersectionObserver(\n ref,\n preloadViewportIoCallback,\n { rootMargin: '100px' },\n { disabled: !!local.disabled || !(preload() === 'viewport') },\n )\n\n Solid.createEffect(() => {\n if (hasRenderFetched) {\n return\n }\n if (!local.disabled && preload() === 'render') {\n doPreload()\n hasRenderFetched = true\n }\n })\n\n if (externalLink()) {\n return Solid.mergeProps(\n propsSafeToSpread,\n {\n ref: mergeRefs(setRef, _options().ref),\n href: externalLink(),\n },\n Solid.splitProps(local, [\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onBlur',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOut',\n 'onMouseOver',\n 'onTouchStart',\n ])[0],\n ) as any\n }\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n // Check actual element's target attribute as fallback\n const elementTarget = (\n e.currentTarget as HTMLAnchorElement | SVGAElement\n ).getAttribute('target')\n const effectiveTarget =\n local.target !== undefined ? local.target : elementTarget\n\n if (\n !local.disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!effectiveTarget || effectiveTarget === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n setIsTransitioning(true)\n\n const unsub = router.subscribe('onResolved', () => {\n unsub()\n setIsTransitioning(false)\n })\n\n // All is well? Navigate!\n // N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing\n router.navigate({\n ..._options(),\n replace: local.replace,\n resetScroll: local.resetScroll,\n hashScrollIntoView: local.hashScrollIntoView,\n startTransition: local.startTransition,\n viewTransition: local.viewTransition,\n ignoreBlocker: local.ignoreBlocker,\n })\n }\n }\n\n const enqueueIntentPreload = (e: MouseEvent | FocusEvent) => {\n if (local.disabled || preload() !== 'intent') return\n\n if (!preloadDelay()) {\n doPreload()\n return\n }\n\n const eventTarget = e.currentTarget || e.target\n\n if (!eventTarget || timeoutMap.has(eventTarget)) return\n\n timeoutMap.set(\n eventTarget,\n setTimeout(() => {\n timeoutMap.delete(eventTarget)\n doPreload()\n }, preloadDelay()),\n )\n }\n\n const handleTouchStart = (_: TouchEvent) => {\n if (local.disabled || preload() !== 'intent') return\n doPreload()\n }\n\n const handleLeave = (e: MouseEvent | FocusEvent) => {\n if (local.disabled) return\n const eventTarget = e.currentTarget || e.target\n\n if (eventTarget) {\n const id = timeoutMap.get(eventTarget)\n clearTimeout(id)\n timeoutMap.delete(eventTarget)\n }\n }\n\n /** Call a JSX.EventHandlerUnion with the event. */\n function callHandler<T, TEvent extends Event>(\n event: TEvent & { currentTarget: T; target: Element },\n handler: Solid.JSX.EventHandlerUnion<T, TEvent> | undefined,\n ) {\n if (handler) {\n if (typeof handler === 'function') {\n handler(event)\n } else {\n handler[0](handler[1], event)\n }\n }\n\n return event.defaultPrevented\n }\n\n function composeEventHandlers<T>(\n handlers: Array<Solid.JSX.EventHandlerUnion<T, any> | undefined>,\n ) {\n return (event: any) => {\n for (const handler of handlers) {\n callHandler(event, handler)\n }\n }\n }\n\n // Get the active props\n const resolvedActiveProps: () => Omit<Solid.ComponentProps<'a'>, 'style'> & {\n style?: Solid.JSX.CSSProperties\n } = () =>\n isActive() ? (functionalUpdate(local.activeProps as any, {}) ?? {}) : {}\n\n // Get the inactive props\n const resolvedInactiveProps: () => Omit<\n Solid.ComponentProps<'a'>,\n 'style'\n > & { style?: Solid.JSX.CSSProperties } = () =>\n isActive() ? {} : functionalUpdate(local.inactiveProps, {})\n\n const resolvedClassName = () =>\n [local.class, resolvedActiveProps().class, resolvedInactiveProps().class]\n .filter(Boolean)\n .join(' ')\n\n const resolvedStyle = () => ({\n ...local.style,\n ...resolvedActiveProps().style,\n ...resolvedInactiveProps().style,\n })\n\n return Solid.mergeProps(\n propsSafeToSpread,\n resolvedActiveProps,\n resolvedInactiveProps,\n () => {\n return {\n href: hrefOption()?.href,\n ref: mergeRefs(setRef, _options().ref),\n onClick: composeEventHandlers([local.onClick, handleClick]),\n onBlur: composeEventHandlers([local.onBlur, handleLeave]),\n onFocus: composeEventHandlers([local.onFocus, enqueueIntentPreload]),\n onMouseEnter: composeEventHandlers([\n local.onMouseEnter,\n enqueueIntentPreload,\n ]),\n onMouseOver: composeEventHandlers([\n local.onMouseOver,\n enqueueIntentPreload,\n ]),\n onMouseLeave: composeEventHandlers([local.onMouseLeave, handleLeave]),\n onMouseOut: composeEventHandlers([local.onMouseOut, handleLeave]),\n onTouchStart: composeEventHandlers([\n local.onTouchStart,\n handleTouchStart,\n ]),\n disabled: !!local.disabled,\n target: local.target,\n ...(() => {\n const s = resolvedStyle()\n return Object.keys(s).length ? { style: s } : {}\n })(),\n ...(() => {\n const c = resolvedClassName()\n return c ? { class: c } : {}\n })(),\n ...(local.disabled && {\n role: 'link',\n 'aria-disabled': true,\n }),\n ...(isActive() && { 'data-status': 'active', 'aria-current': 'page' }),\n ...(isTransitioning() && { 'data-transitioning': 'transitioning' }),\n }\n },\n ) as any\n}\n\nexport type UseLinkPropsOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n Omit<Solid.ComponentProps<'a'>, 'style'> & { style?: Solid.JSX.CSSProperties }\n\nexport type ActiveLinkOptions<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n ActiveLinkOptionProps<TComp>\n\ntype ActiveLinkProps<TComp> = Partial<\n LinkComponentSolidProps<TComp> & {\n [key: `data-${string}`]: unknown\n }\n>\n\nexport interface ActiveLinkOptionProps<TComp = 'a'> {\n /**\n * A function that returns additional props for the `active` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n activeProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n /**\n * A function that returns additional props for the `inactive` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n inactiveProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n}\n\nexport type LinkProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n LinkPropsChildren\n\nexport interface LinkPropsChildren {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | Solid.JSX.Element\n | ((state: {\n isActive: boolean\n isTransitioning: boolean\n }) => Solid.JSX.Element)\n}\n\ntype LinkComponentSolidProps<TComp> = TComp extends Solid.ValidComponent\n ? Omit<Solid.ComponentProps<TComp>, keyof CreateLinkProps>\n : never\n\nexport type LinkComponentProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkComponentSolidProps<TComp> &\n LinkProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type CreateLinkProps = LinkProps<\n any,\n any,\n string,\n string,\n string,\n string\n>\n\nexport type LinkComponent<\n in out TComp,\n in out TDefaultFrom extends string = string,\n> = <\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = TDefaultFrom,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Solid.JSX.Element\n\nexport interface LinkComponentRoute<\n in out TDefaultFrom extends string = string,\n> {\n defaultFrom: TDefaultFrom;\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n props: LinkComponentProps<\n 'a',\n TRouter,\n this['defaultFrom'],\n TTo,\n this['defaultFrom'],\n TMaskTo\n >,\n ): Solid.JSX.Element\n}\n\nexport function createLink<const TComp>(\n Comp: Constrain<TComp, any, (props: CreateLinkProps) => Solid.JSX.Element>,\n): LinkComponent<TComp> {\n return (props) => <Link {...props} _asChild={Comp} />\n}\n\nexport const Link: LinkComponent<'a'> = (props) => {\n const [local, rest] = Solid.splitProps(\n props as typeof props & { _asChild: any },\n ['_asChild', 'children'],\n )\n\n const [_, linkProps] = Solid.splitProps(\n useLinkProps(rest as unknown as any),\n ['type'],\n )\n\n const children = Solid.createMemo(() => {\n const ch = local.children\n if (typeof ch === 'function') {\n return ch({\n get isActive() {\n return (linkProps as any)['data-status'] === 'active'\n },\n get isTransitioning() {\n return (linkProps as any)['data-transitioning'] === 'transitioning'\n },\n })\n }\n\n return ch satisfies Solid.JSX.Element\n })\n\n if (local._asChild === 'svg') {\n const [_, svgLinkProps] = Solid.splitProps(linkProps, ['class'])\n return (\n <svg>\n <a {...svgLinkProps}>{children()}</a>\n </svg>\n )\n }\n\n return (\n <Dynamic component={local._asChild ? local._asChild : 'a'} {...linkProps}>\n {children()}\n </Dynamic>\n )\n}\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n\nexport type LinkOptionsFnOptions<\n TOptions,\n TComp,\n TRouter extends AnyRouter = RegisteredRouter,\n> =\n TOptions extends ReadonlyArray<any>\n ? ValidateLinkOptionsArray<TRouter, TOptions, string, TComp>\n : ValidateLinkOptions<TRouter, TOptions, string, TComp>\n\nexport type LinkOptionsFn<TComp> = <\n const TOptions,\n TRouter extends AnyRouter = RegisteredRouter,\n>(\n options: LinkOptionsFnOptions<TOptions, TComp, TRouter>,\n) => TOptions\n\nexport const linkOptions: LinkOptionsFn<'a'> = (options) => {\n return options as any\n}\n"],"mappings":";;;;;;;;;;;AAiCA,IAAMqB,6BAAa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AA0B;;GAEvD,CAAC;AAGJ,SAAOC;GACP;AAEF,KAAIlL,MAAMgL,aAAa,OAAO;EAC5B,MAAM,CAACzK,GAAG4K,gBAAgB9N,MAAM6C,WAAW+K,WAAW,CAAC,QAAQ,CAAC;AAChE,gBAAA;GAAA,IAAAG,OAAAC,QAAA,EAAAC,QAAAF,KAAAG;AAAAC,UAAAF,OAEWH,cAAY,OAAA,KAAA;AAAAM,UAAAH,OAAGrB,SAAQ;AAAA,UAAAmB;MAAA;;AAKpC,QAAAP,gBACG/M,SAAOiN,WAAA,EAAA,IAACW,YAAS;AAAA,SAAEC,WAAA,CAAA,CAAA3L,MAAMgL,SAAQ,EAAA,GAAGhL,MAAMgL,WAAW;IAAG,EAAMC,WAAS,EAAA,IAAAhB,WAAA;AAAA,SACrEA,UAAU;IAAA,CAAA,CAAA;;AAKjB,SAASnE,YAAYT,GAAe;AAClC,QAAO,CAAC,EAAEA,EAAEuG,WAAWvG,EAAEwG,UAAUxG,EAAEyG,WAAWzG,EAAE0G;;AAmBpD,IAAaK,eAAmClN,YAAY;AAC1D,QAAOA"}
|
|
1
|
+
{"version":3,"file":"link.js","names":["Solid","mergeRefs","deepEqual","exactPathTest","functionalUpdate","isDangerousProtocol","preloadWarning","removeTrailingSlash","isServer","Dynamic","useRouter","useIntersectionObserver","useHydrated","AnyRouter","Constrain","LinkOptions","RegisteredRouter","RoutePaths","ValidateLinkOptions","ValidateLinkOptionsArray","timeoutMap","WeakMap","EventTarget","ReturnType","setTimeout","useLinkProps","TRouter","TFrom","options","UseLinkPropsOptions","TTo","TMaskFrom","TMaskTo","ComponentProps","router","isTransitioning","setIsTransitioning","createSignal","shouldHydrateHash","ssr","hasHydrated","hasRenderFetched","local","rest","splitProps","mergeProps","activeProps","STATIC_ACTIVE_PROPS_GET","inactiveProps","STATIC_INACTIVE_PROPS_GET","_","propsSafeToSpread","currentLocation","createMemo","stores","location","state","undefined","equals","prev","next","href","_options","_fromLocation","untrack","buildLocation","hrefOption","disabled","maskedLocation","publicHref","external","history","createHref","externalLink","_href","protocolAllowlist","process","env","NODE_ENV","console","warn","to","safeInternal","isSafeInternal","indexOf","URL","preload","reloadDocument","defaultPreload","preloadDelay","defaultPreloadDelay","isActive","activeOptions","current","nextLocation","exact","testExact","pathname","basepath","currentPath","nextPath","pathIsFuzzyEqual","startsWith","length","includeSearch","searchTest","search","partial","ignoreUndefined","explicitUndefined","includeHash","currentHash","hash","doPreload","preloadRoute","_builtLocation","catch","err","preloadViewportIoCallback","entry","IntersectionObserverEntry","isIntersecting","ref","setRef","Element","rootMargin","createEffect","handleClick","e","MouseEvent","elementTarget","currentTarget","HTMLAnchorElement","SVGAElement","getAttribute","effectiveTarget","target","isCtrlEvent","defaultPrevented","button","preventDefault","unsub","subscribe","navigate","replace","resetScroll","hashScrollIntoView","startTransition","viewTransition","ignoreBlocker","enqueueIntentPreload","FocusEvent","eventTarget","has","set","delete","handleTouchStart","TouchEvent","handleLeave","id","get","clearTimeout","simpleStyling","class","style","onClick","createComposedHandler","onBlur","onFocus","onMouseEnter","onMouseOver","onMouseLeave","onMouseOut","onTouchStart","ResolvedLinkStateProps","Omit","JSX","CSSProperties","resolvedProps","active","base","STATIC_DISABLED_PROPS","STATIC_TRANSITIONING_ATTRIBUTES","STATIC_DEFAULT_ACTIVE_ATTRIBUTES","EMPTY_OBJECT","className","filter","Boolean","join","Object","keys","STATIC_ACTIVE_ATTRIBUTES","STATIC_ACTIVE_PROPS","role","callHandler","Event","event","TEvent","T","handler","EventHandlerUnion","getHandler","fallback","ActiveLinkOptions","ActiveLinkOptionProps","TComp","ActiveLinkProps","Partial","LinkComponentSolidProps","key","LinkProps","LinkPropsChildren","children","ValidComponent","CreateLinkProps","LinkComponentProps","LinkComponent","TDefaultFrom","props","LinkComponentRoute","defaultFrom","createLink","Comp","_$createComponent","Link","_$mergeProps","_asChild","linkProps","ch","svgLinkProps","_el$","_tmpl$","_el$2","firstChild","_$spread","_$insert","_el$3","_tmpl$2","component","metaKey","altKey","ctrlKey","shiftKey","zero","charCodeAt","LinkOptionsFnOptions","TOptions","ReadonlyArray","LinkOptionsFn","linkOptions"],"sources":["../../src/link.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\n\nimport { mergeRefs } from '@solid-primitives/refs'\n\nimport {\n deepEqual,\n exactPathTest,\n functionalUpdate,\n isDangerousProtocol,\n preloadWarning,\n removeTrailingSlash,\n} from '@tanstack/router-core'\n\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { Dynamic } from 'solid-js/web'\nimport { useRouter } from './useRouter'\n\nimport { useIntersectionObserver } from './utils'\n\nimport { useHydrated } from './ClientOnly'\nimport type {\n AnyRouter,\n Constrain,\n LinkOptions,\n RegisteredRouter,\n RoutePaths,\n} from '@tanstack/router-core'\nimport type {\n ValidateLinkOptions,\n ValidateLinkOptionsArray,\n} from './typePrimitives'\n\nconst timeoutMap = new WeakMap<EventTarget, ReturnType<typeof setTimeout>>()\n\nexport function useLinkProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(\n options: UseLinkPropsOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Solid.ComponentProps<'a'> {\n const router = useRouter()\n const [isTransitioning, setIsTransitioning] = Solid.createSignal(false)\n const shouldHydrateHash = !isServer && !!router.options.ssr\n const hasHydrated = useHydrated()\n\n let hasRenderFetched = false\n\n const [local, rest] = Solid.splitProps(\n Solid.mergeProps(\n {\n activeProps: STATIC_ACTIVE_PROPS_GET,\n inactiveProps: STATIC_INACTIVE_PROPS_GET,\n },\n options,\n ),\n [\n 'activeProps',\n 'inactiveProps',\n 'activeOptions',\n 'to',\n 'preload',\n 'preloadDelay',\n 'hashScrollIntoView',\n 'replace',\n 'startTransition',\n 'resetScroll',\n 'viewTransition',\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onBlur',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOver',\n 'onMouseOut',\n 'onTouchStart',\n 'ignoreBlocker',\n ],\n )\n\n // const {\n // // custom props\n // activeProps = () => ({ class: 'active' }),\n // inactiveProps = () => ({}),\n // activeOptions,\n // to,\n // preload: userPreload,\n // preloadDelay: userPreloadDelay,\n // hashScrollIntoView,\n // replace,\n // startTransition,\n // resetScroll,\n // viewTransition,\n // // element props\n // children,\n // target,\n // disabled,\n // style,\n // class,\n // onClick,\n // onFocus,\n // onMouseEnter,\n // onMouseLeave,\n // onTouchStart,\n // ignoreBlocker,\n // ...rest\n // } = options\n\n const [_, propsSafeToSpread] = Solid.splitProps(rest, [\n 'params',\n 'search',\n 'hash',\n 'state',\n 'mask',\n 'reloadDocument',\n 'unsafeRelative',\n ])\n\n const currentLocation = Solid.createMemo(\n () => router.stores.location.state,\n undefined,\n { equals: (prev, next) => prev.href === next.href },\n )\n\n const _options = () => options\n\n const next = Solid.createMemo(() => {\n // Rebuild when inherited search/hash or the current route context changes.\n const _fromLocation = currentLocation()\n const options = { _fromLocation, ..._options() } as any\n // untrack because router-core will also access stores, which are signals in solid\n return Solid.untrack(() => router.buildLocation(options))\n })\n\n const hrefOption = Solid.createMemo(() => {\n if (_options().disabled) return undefined\n // Use publicHref - it contains the correct href for display\n // When a rewrite changes the origin, publicHref is the full URL\n // Otherwise it's the origin-stripped path\n // This avoids constructing URL objects in the hot path\n const location = next().maskedLocation ?? next()\n const publicHref = location.publicHref\n const external = location.external\n\n if (external) {\n return { href: publicHref, external: true }\n }\n\n return {\n href: router.history.createHref(publicHref) || '/',\n external: false,\n }\n })\n\n const externalLink = Solid.createMemo(() => {\n const _href = hrefOption()\n if (_href?.external) {\n // Block dangerous protocols for external links\n if (isDangerousProtocol(_href.href, router.protocolAllowlist)) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Blocked Link with dangerous protocol: ${_href.href}`)\n }\n return undefined\n }\n return _href.href\n }\n const to = _options().to\n const safeInternal = isSafeInternal(to)\n if (safeInternal) return undefined\n if (typeof to !== 'string' || to.indexOf(':') === -1) return undefined\n try {\n new URL(to as any)\n // Block dangerous protocols like javascript:, blob:, data:\n if (isDangerousProtocol(to, router.protocolAllowlist)) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Blocked Link with dangerous protocol: ${to}`)\n }\n return undefined\n }\n return to\n } catch {}\n return undefined\n })\n\n const preload = Solid.createMemo(() => {\n if (_options().reloadDocument || externalLink()) {\n return false\n }\n return local.preload ?? router.options.defaultPreload\n })\n const preloadDelay = () =>\n local.preloadDelay ?? router.options.defaultPreloadDelay ?? 0\n\n const isActive = Solid.createMemo(() => {\n if (externalLink()) return false\n const activeOptions = local.activeOptions\n const current = currentLocation()\n const nextLocation = next()\n\n if (activeOptions?.exact) {\n const testExact = exactPathTest(\n current.pathname,\n nextLocation.pathname,\n router.basepath,\n )\n if (!testExact) {\n return false\n }\n } else {\n const currentPath = removeTrailingSlash(current.pathname, router.basepath)\n const nextPath = removeTrailingSlash(\n nextLocation.pathname,\n router.basepath,\n )\n\n const pathIsFuzzyEqual =\n currentPath.startsWith(nextPath) &&\n (currentPath.length === nextPath.length ||\n currentPath[nextPath.length] === '/')\n if (!pathIsFuzzyEqual) {\n return false\n }\n }\n\n if (activeOptions?.includeSearch ?? true) {\n const searchTest = deepEqual(current.search, nextLocation.search, {\n partial: !activeOptions?.exact,\n ignoreUndefined: !activeOptions?.explicitUndefined,\n })\n if (!searchTest) {\n return false\n }\n }\n\n if (activeOptions?.includeHash) {\n const currentHash =\n shouldHydrateHash && !hasHydrated() ? '' : current.hash\n return currentHash === nextLocation.hash\n }\n return true\n })\n\n const doPreload = () =>\n router\n .preloadRoute({ ..._options(), _builtLocation: next() } as any)\n .catch((err: any) => {\n console.warn(err)\n console.warn(preloadWarning)\n })\n\n const preloadViewportIoCallback = (\n entry: IntersectionObserverEntry | undefined,\n ) => {\n if (entry?.isIntersecting) {\n doPreload()\n }\n }\n\n const [ref, setRef] = Solid.createSignal<Element | null>(null)\n\n useIntersectionObserver(\n ref,\n preloadViewportIoCallback,\n { rootMargin: '100px' },\n { disabled: !!local.disabled || !(preload() === 'viewport') },\n )\n\n Solid.createEffect(() => {\n if (hasRenderFetched) {\n return\n }\n if (!local.disabled && preload() === 'render') {\n doPreload()\n hasRenderFetched = true\n }\n })\n\n if (externalLink()) {\n return Solid.mergeProps(\n propsSafeToSpread,\n {\n ref: mergeRefs(setRef, _options().ref),\n href: externalLink(),\n },\n Solid.splitProps(local, [\n 'target',\n 'disabled',\n 'style',\n 'class',\n 'onClick',\n 'onBlur',\n 'onFocus',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseOut',\n 'onMouseOver',\n 'onTouchStart',\n ])[0],\n ) as any\n }\n\n // The click handler\n const handleClick = (e: MouseEvent) => {\n // Check actual element's target attribute as fallback\n const elementTarget = (\n e.currentTarget as HTMLAnchorElement | SVGAElement\n ).getAttribute('target')\n const effectiveTarget =\n local.target !== undefined ? local.target : elementTarget\n\n if (\n !local.disabled &&\n !isCtrlEvent(e) &&\n !e.defaultPrevented &&\n (!effectiveTarget || effectiveTarget === '_self') &&\n e.button === 0\n ) {\n e.preventDefault()\n\n setIsTransitioning(true)\n\n const unsub = router.subscribe('onResolved', () => {\n unsub()\n setIsTransitioning(false)\n })\n\n // All is well? Navigate!\n // N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing\n router.navigate({\n ..._options(),\n replace: local.replace,\n resetScroll: local.resetScroll,\n hashScrollIntoView: local.hashScrollIntoView,\n startTransition: local.startTransition,\n viewTransition: local.viewTransition,\n ignoreBlocker: local.ignoreBlocker,\n })\n }\n }\n\n const enqueueIntentPreload = (e: MouseEvent | FocusEvent) => {\n if (local.disabled || preload() !== 'intent') return\n\n if (!preloadDelay()) {\n doPreload()\n return\n }\n\n const eventTarget = e.currentTarget || e.target\n\n if (!eventTarget || timeoutMap.has(eventTarget)) return\n\n timeoutMap.set(\n eventTarget,\n setTimeout(() => {\n timeoutMap.delete(eventTarget)\n doPreload()\n }, preloadDelay()),\n )\n }\n\n const handleTouchStart = (_: TouchEvent) => {\n if (local.disabled || preload() !== 'intent') return\n doPreload()\n }\n\n const handleLeave = (e: MouseEvent | FocusEvent) => {\n if (local.disabled) return\n const eventTarget = e.currentTarget || e.target\n\n if (eventTarget) {\n const id = timeoutMap.get(eventTarget)\n clearTimeout(id)\n timeoutMap.delete(eventTarget)\n }\n }\n\n const simpleStyling = Solid.createMemo(\n () =>\n local.activeProps === STATIC_ACTIVE_PROPS_GET &&\n local.inactiveProps === STATIC_INACTIVE_PROPS_GET &&\n local.class === undefined &&\n local.style === undefined,\n )\n\n const onClick = createComposedHandler(() => local.onClick, handleClick)\n const onBlur = createComposedHandler(() => local.onBlur, handleLeave)\n const onFocus = createComposedHandler(\n () => local.onFocus,\n enqueueIntentPreload,\n )\n const onMouseEnter = createComposedHandler(\n () => local.onMouseEnter,\n enqueueIntentPreload,\n )\n const onMouseOver = createComposedHandler(\n () => local.onMouseOver,\n enqueueIntentPreload,\n )\n const onMouseLeave = createComposedHandler(\n () => local.onMouseLeave,\n handleLeave,\n )\n const onMouseOut = createComposedHandler(() => local.onMouseOut, handleLeave)\n const onTouchStart = createComposedHandler(\n () => local.onTouchStart,\n handleTouchStart,\n )\n\n type ResolvedLinkStateProps = Omit<Solid.ComponentProps<'a'>, 'style'> & {\n style?: Solid.JSX.CSSProperties\n }\n\n const resolvedProps = Solid.createMemo(() => {\n const active = isActive()\n\n const base = {\n href: hrefOption()?.href,\n ref: mergeRefs(setRef, _options().ref),\n onClick,\n onBlur,\n onFocus,\n onMouseEnter,\n onMouseOver,\n onMouseLeave,\n onMouseOut,\n onTouchStart,\n disabled: !!local.disabled,\n target: local.target,\n ...(local.disabled && STATIC_DISABLED_PROPS),\n ...(isTransitioning() && STATIC_TRANSITIONING_ATTRIBUTES),\n }\n\n if (simpleStyling()) {\n return {\n ...base,\n ...(active && STATIC_DEFAULT_ACTIVE_ATTRIBUTES),\n }\n }\n\n const activeProps: ResolvedLinkStateProps = active\n ? (functionalUpdate(local.activeProps as any, {}) ?? EMPTY_OBJECT)\n : EMPTY_OBJECT\n const inactiveProps: ResolvedLinkStateProps = active\n ? EMPTY_OBJECT\n : functionalUpdate(local.inactiveProps, {})\n const style = {\n ...local.style,\n ...activeProps.style,\n ...inactiveProps.style,\n }\n const className = [local.class, activeProps.class, inactiveProps.class]\n .filter(Boolean)\n .join(' ')\n\n return {\n ...activeProps,\n ...inactiveProps,\n ...base,\n ...(Object.keys(style).length ? { style } : undefined),\n ...(className ? { class: className } : undefined),\n ...(active && STATIC_ACTIVE_ATTRIBUTES),\n } as ResolvedLinkStateProps\n })\n\n return Solid.mergeProps(propsSafeToSpread, resolvedProps) as any\n}\n\nconst STATIC_ACTIVE_PROPS = { class: 'active' }\nconst STATIC_ACTIVE_PROPS_GET = () => STATIC_ACTIVE_PROPS\nconst EMPTY_OBJECT = {}\nconst STATIC_INACTIVE_PROPS_GET = () => EMPTY_OBJECT\nconst STATIC_DEFAULT_ACTIVE_ATTRIBUTES = {\n class: 'active',\n 'data-status': 'active',\n 'aria-current': 'page',\n}\nconst STATIC_DISABLED_PROPS = {\n role: 'link',\n 'aria-disabled': true,\n}\nconst STATIC_ACTIVE_ATTRIBUTES = {\n 'data-status': 'active',\n 'aria-current': 'page',\n}\nconst STATIC_TRANSITIONING_ATTRIBUTES = {\n 'data-transitioning': 'transitioning',\n}\n\n/** Call a JSX.EventHandlerUnion with the event. */\nfunction callHandler<T, TEvent extends Event>(\n event: TEvent & { currentTarget: T; target: Element },\n handler: Solid.JSX.EventHandlerUnion<T, TEvent>,\n) {\n if (typeof handler === 'function') {\n handler(event)\n } else {\n handler[0](handler[1], event)\n }\n return event.defaultPrevented\n}\n\nfunction createComposedHandler<T, TEvent extends Event>(\n getHandler: () => Solid.JSX.EventHandlerUnion<T, TEvent> | undefined,\n fallback: (event: TEvent) => void,\n) {\n return (event: TEvent & { currentTarget: T; target: Element }) => {\n const handler = getHandler()\n if (!handler || !callHandler(event, handler)) fallback(event)\n }\n}\n\nexport type UseLinkPropsOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n Omit<Solid.ComponentProps<'a'>, 'style'> & { style?: Solid.JSX.CSSProperties }\n\nexport type ActiveLinkOptions<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n ActiveLinkOptionProps<TComp>\n\ntype ActiveLinkProps<TComp> = Partial<\n LinkComponentSolidProps<TComp> & {\n [key: `data-${string}`]: unknown\n }\n>\n\nexport interface ActiveLinkOptionProps<TComp = 'a'> {\n /**\n * A function that returns additional props for the `active` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n activeProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n /**\n * A function that returns additional props for the `inactive` state of this link.\n * These props override other props passed to the link (`style`'s are merged, `class`'s are concatenated)\n */\n inactiveProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)\n}\n\nexport type LinkProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ActiveLinkOptions<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &\n LinkPropsChildren\n\nexport interface LinkPropsChildren {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | Solid.JSX.Element\n | ((state: {\n isActive: boolean\n isTransitioning: boolean\n }) => Solid.JSX.Element)\n}\n\ntype LinkComponentSolidProps<TComp> = TComp extends Solid.ValidComponent\n ? Omit<Solid.ComponentProps<TComp>, keyof CreateLinkProps>\n : never\n\nexport type LinkComponentProps<\n TComp = 'a',\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = LinkComponentSolidProps<TComp> &\n LinkProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type CreateLinkProps = LinkProps<\n any,\n any,\n string,\n string,\n string,\n string\n>\n\nexport type LinkComponent<\n in out TComp,\n in out TDefaultFrom extends string = string,\n> = <\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = TDefaultFrom,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Solid.JSX.Element\n\nexport interface LinkComponentRoute<\n in out TDefaultFrom extends string = string,\n> {\n defaultFrom: TDefaultFrom;\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n props: LinkComponentProps<\n 'a',\n TRouter,\n this['defaultFrom'],\n TTo,\n this['defaultFrom'],\n TMaskTo\n >,\n ): Solid.JSX.Element\n}\n\nexport function createLink<const TComp>(\n Comp: Constrain<TComp, any, (props: CreateLinkProps) => Solid.JSX.Element>,\n): LinkComponent<TComp> {\n return (props) => <Link {...props} _asChild={Comp} />\n}\n\nexport const Link: LinkComponent<'a'> = (props) => {\n const [local, rest] = Solid.splitProps(\n props as typeof props & { _asChild: any },\n ['_asChild', 'children'],\n )\n\n const [_, linkProps] = Solid.splitProps(\n useLinkProps(rest as unknown as any),\n ['type'],\n )\n\n const children = Solid.createMemo(() => {\n const ch = local.children\n if (typeof ch === 'function') {\n return ch({\n get isActive() {\n return (linkProps as any)['data-status'] === 'active'\n },\n get isTransitioning() {\n return (linkProps as any)['data-transitioning'] === 'transitioning'\n },\n })\n }\n\n return ch satisfies Solid.JSX.Element\n })\n\n if (local._asChild === 'svg') {\n const [_, svgLinkProps] = Solid.splitProps(linkProps, ['class'])\n return (\n <svg>\n <a {...svgLinkProps}>{children()}</a>\n </svg>\n )\n }\n\n if (!local._asChild) {\n return <a {...linkProps}>{children()}</a>\n }\n\n return (\n <Dynamic component={local._asChild as Solid.ValidComponent} {...linkProps}>\n {children()}\n </Dynamic>\n )\n}\n\nfunction isCtrlEvent(e: MouseEvent) {\n return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)\n}\n\nfunction isSafeInternal(to: unknown) {\n if (typeof to !== 'string') return false\n const zero = to.charCodeAt(0)\n if (zero === 47) return to.charCodeAt(1) !== 47 // '/' but not '//'\n return zero === 46 // '.', '..', './', '../'\n}\n\nexport type LinkOptionsFnOptions<\n TOptions,\n TComp,\n TRouter extends AnyRouter = RegisteredRouter,\n> =\n TOptions extends ReadonlyArray<any>\n ? ValidateLinkOptionsArray<TRouter, TOptions, string, TComp>\n : ValidateLinkOptions<TRouter, TOptions, string, TComp>\n\nexport type LinkOptionsFn<TComp> = <\n const TOptions,\n TRouter extends AnyRouter = RegisteredRouter,\n>(\n options: LinkOptionsFnOptions<TOptions, TComp, TRouter>,\n) => TOptions\n\nexport const linkOptions: LinkOptionsFn<'a'> = (options) => {\n return options as any\n}\n"],"mappings":";;;;;;;;;;AAgCA,IAAMoB,6BAAa,IAAIC,SAAqD;AAE5E,SAAgBI,aAOdG,SAC2B;CAC3B,MAAMM,SAASxB,WAAW;CAC1B,MAAM,CAACyB,iBAAiBC,sBAAsBpC,MAAMqC,aAAa,MAAM;CACvE,MAAMC,oBAAoB,CAAC9B,YAAY,CAAC,CAAC0B,OAAON,QAAQW;CACxD,MAAMC,cAAc5B,aAAa;CAEjC,IAAI6B,mBAAm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
|
3
|
+
export type NearestMatchContextValue = {
|
|
4
|
+
matchId: Solid.Accessor<string | undefined>;
|
|
5
|
+
routeId: Solid.Accessor<string | undefined>;
|
|
6
|
+
match: Solid.Accessor<AnyRouteMatch | undefined>;
|
|
7
|
+
hasPending: Solid.Accessor<boolean>;
|
|
8
|
+
};
|
|
9
|
+
export declare const nearestMatchContext: Solid.Context<NearestMatchContextValue>;
|
package/dist/esm/matchContext.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as Solid from "solid-js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var nearestMatchContext = Solid.createContext({
|
|
3
|
+
matchId: () => void 0,
|
|
4
|
+
routeId: () => void 0,
|
|
5
|
+
match: () => void 0,
|
|
6
|
+
hasPending: () => false
|
|
7
|
+
});
|
|
5
8
|
//#endregion
|
|
6
|
-
export {
|
|
9
|
+
export { nearestMatchContext };
|
|
7
10
|
|
|
8
11
|
//# sourceMappingURL=matchContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchContext.js","names":["Solid","
|
|
1
|
+
{"version":3,"file":"matchContext.js","names":["Solid","AnyRouteMatch","NearestMatchContextValue","matchId","Accessor","routeId","match","hasPending","defaultNearestMatchContext","undefined","nearestMatchContext","createContext"],"sources":["../../src/matchContext.tsx"],"sourcesContent":["import * as Solid from 'solid-js'\nimport type { AnyRouteMatch } from '@tanstack/router-core'\n\nexport type NearestMatchContextValue = {\n matchId: Solid.Accessor<string | undefined>\n routeId: Solid.Accessor<string | undefined>\n match: Solid.Accessor<AnyRouteMatch | undefined>\n hasPending: Solid.Accessor<boolean>\n}\n\nconst defaultNearestMatchContext: NearestMatchContextValue = {\n matchId: () => undefined,\n routeId: () => undefined,\n match: () => undefined,\n hasPending: () => false,\n}\n\nexport const nearestMatchContext =\n Solid.createContext<NearestMatchContextValue>(defaultNearestMatchContext)\n"],"mappings":";AAiBA,IAAaU,sBACXV,MAAMW,cARqD;CAC3DR,eAAeM,KAAAA;CACfJ,eAAeI,KAAAA;CACfH,aAAaG,KAAAA;CACbF,kBAAkB;CACnB,CAG0E"}
|
package/dist/esm/not-found.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NotFoundError } from '@tanstack/router-core';
|
|
2
|
-
import
|
|
2
|
+
import * as Solid from 'solid-js';
|
|
3
3
|
export declare function CatchNotFound(props: {
|
|
4
4
|
fallback?: (error: NotFoundError) => Solid.JSX.Element;
|
|
5
5
|
onCatch?: (error: Error) => void;
|
package/dist/esm/not-found.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { CatchBoundary } from "./CatchBoundary.js";
|
|
2
|
-
import {
|
|
2
|
+
import { useRouter } from "./useRouter.js";
|
|
3
3
|
import { isNotFound } from "@tanstack/router-core";
|
|
4
4
|
import { createComponent, template } from "solid-js/web";
|
|
5
|
+
import * as Solid from "solid-js";
|
|
5
6
|
//#region src/not-found.tsx
|
|
6
7
|
var _tmpl$ = /* @__PURE__ */ template(`<p>Not Found`);
|
|
7
8
|
function CatchNotFound(props) {
|
|
8
|
-
const
|
|
9
|
+
const router = useRouter();
|
|
10
|
+
const pathname = Solid.createMemo(() => router.stores.location.state.pathname);
|
|
11
|
+
const status = Solid.createMemo(() => router.stores.status.state);
|
|
9
12
|
return createComponent(CatchBoundary, {
|
|
10
|
-
getResetKey: () =>
|
|
13
|
+
getResetKey: () => `not-found-${pathname()}-${status()}`,
|
|
11
14
|
onCatch: (error) => {
|
|
12
15
|
if (isNotFound(error)) props.onCatch?.(error);
|
|
13
16
|
else throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not-found.js","names":["isNotFound","
|
|
1
|
+
{"version":3,"file":"not-found.js","names":["isNotFound","Solid","CatchBoundary","useRouter","NotFoundError","CatchNotFound","props","fallback","error","JSX","Element","onCatch","Error","children","router","pathname","createMemo","stores","location","state","status","_$createComponent","getResetKey","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\nexport function CatchNotFound(props: {\n fallback?: (error: NotFoundError) => Solid.JSX.Element\n onCatch?: (error: Error) => 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 if (isNotFound(error)) {\n props.onCatch?.(error)\n } else {\n throw error\n }\n }}\n errorComponent={({ error }) => {\n if (isNotFound(error)) {\n return props.fallback?.(error)\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":";;;;;;;AAMA,SAAgBK,cAAcC,OAI3B;CACD,MAAMQ,SAASX,WAAW;CAE1B,MAAMY,WAAWd,MAAMe,iBAAiBF,OAAOG,OAAOC,SAASC,MAAMJ,SAAS;CAC9E,MAAMK,SAASnB,MAAMe,iBAAiBF,OAAOG,OAAOG,OAAOD,MAAM;AAEjE,QAAAE,gBACGnB,eAAa;EACZoB,mBAAmB,aAAaP,UAAU,CAAA,GAAIK,QAAQ;EACtDT,UAAUH,UAAU;AAClB,OAAIR,WAAWQ,MAAM,CACnBF,OAAMK,UAAUH,MAAM;OAEtB,OAAMA;;EAGVe,iBAAiB,EAAEf,YAAY;AAC7B,OAAIR,WAAWQ,MAAM,CACnB,QAAOF,MAAMC,WAAWC,MAAM;OAE9B,OAAMA;;EAET,IAAAK,WAAA;AAAA,UAEAP,MAAMO;;EAAQ,CAAA;;AAKrB,SAAgBW,wBAAwB;AACtC,QAAAC,QAAA"}
|