@next-box/link-extra 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +3 -1
  2. package/dist/cjs/Link.cjs +3 -0
  3. package/dist/cjs/Link.cjs.map +1 -0
  4. package/dist/cjs/LinkProvider.cjs +3 -0
  5. package/dist/cjs/LinkProvider.cjs.map +1 -0
  6. package/dist/cjs/helpers.cjs +2 -0
  7. package/dist/cjs/helpers.cjs.map +1 -0
  8. package/dist/cjs/index.cjs +1 -1
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/useLinkExtra.cjs +2 -0
  11. package/dist/cjs/useLinkExtra.cjs.map +1 -0
  12. package/dist/esm/Link.mjs +3 -0
  13. package/dist/esm/Link.mjs.map +1 -0
  14. package/dist/esm/LinkProvider.mjs +3 -0
  15. package/dist/esm/LinkProvider.mjs.map +1 -0
  16. package/dist/esm/helpers.mjs +2 -0
  17. package/dist/esm/helpers.mjs.map +1 -0
  18. package/dist/esm/index.mjs +1 -1
  19. package/dist/esm/index.mjs.map +1 -1
  20. package/dist/esm/useLinkExtra.mjs +2 -0
  21. package/dist/esm/useLinkExtra.mjs.map +1 -0
  22. package/dist/production.analysis.txt +26 -26
  23. package/dist/types/cjs/Link.d.cts.map +1 -1
  24. package/dist/types/cjs/LinkProvider.d.cts +2 -2
  25. package/dist/types/cjs/LinkProvider.d.cts.map +1 -1
  26. package/dist/types/cjs/helpers.d.cts.map +1 -1
  27. package/dist/types/cjs/types.d.cts +3 -6
  28. package/dist/types/cjs/types.d.cts.map +1 -1
  29. package/dist/types/esm/Link.d.ts.map +1 -1
  30. package/dist/types/esm/LinkProvider.d.ts +2 -2
  31. package/dist/types/esm/LinkProvider.d.ts.map +1 -1
  32. package/dist/types/esm/helpers.d.ts.map +1 -1
  33. package/dist/types/esm/types.d.ts +3 -6
  34. package/dist/types/esm/types.d.ts.map +1 -1
  35. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  36. package/package.json +13 -13
  37. package/src/Link.tsx +2 -0
  38. package/src/LinkProvider.tsx +26 -7
  39. package/src/helpers.ts +18 -19
  40. package/src/main.test.tsx +160 -0
  41. package/src/types.ts +3 -9
package/README.md CHANGED
@@ -50,6 +50,8 @@ npm add @next-box/link-extra
50
50
  It also receives the current pathname so that it can detect when a navigation has completed.
51
51
 
52
52
  ```tsx
53
+ 'use client';
54
+
53
55
  import Link from 'next/link';
54
56
  import { usePathname } from 'next/navigation';
55
57
  import {
@@ -76,7 +78,7 @@ const LinkProviderWrapper = ({
76
78
  };
77
79
  ```
78
80
 
79
- For Next.js applications using the App Router, the provider should be placed in a client component because it uses React context and client-side navigation state.
81
+ `LinkProvider` is a Client Component. The wrapper above supplies the current pathname and the link component implementations from client code; these component functions cannot be passed as props from a Server Component.
80
82
 
81
83
  ### Render a link
82
84
 
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ "use strict";var e=require("react/jsx-runtime"),r=require("./helpers.cjs"),c=require("./useLinkExtra.cjs");exports.Link=({children:i,disableRouterCache:n=!0,href:s="#",onClick:t,prefetch:a=!1,scroll:l=!1,...h})=>{const{NextLink:u,OwnLink:o,onLinkClicked:d}=c.useLinkExtra();return n&&(s=r.addCacheBusterQueryParam(s)),e.jsx(u,{href:s,legacyBehavior:!0,passHref:!0,prefetch:a,scroll:l,children:e.jsx(o,{onClick:e=>{t&&t(e),r.shouldUrlAndLocationMatch(s)||e.defaultPrevented||d()},...h,children:i})})};
3
+ //# sourceMappingURL=Link.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Link.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ "use strict";var e=require("react/jsx-runtime"),r=require("react");const n=r.createContext({});exports.LinkContext=n,exports.LinkProvider=({LoadingComponent:t,NextLink:u,OwnLink:l,children:c,loadingTimeout:i=500,pathname:o})=>{const s=r.useRef(null),[a,x]=r.useState(!1),k=r.useCallback(()=>{null!==s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,x(!0)},i)},[i]);return r.useEffect(()=>(null!==s.current&&(clearTimeout(s.current),s.current=null),x(!1),scroll(0,0),()=>{null!==s.current&&(clearTimeout(s.current),s.current=null)}),[o]),e.jsx(n,{value:{NextLink:u,OwnLink:l,onLinkClicked:()=>{k()}},children:e.jsxs(e.Fragment,{children:[c,a?e.jsx(t,{}):void 0]})})};
3
+ //# sourceMappingURL=LinkProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkProvider.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,2 @@
1
+ "use strict";var a=require("nanoid");const r=(a,r=!1)=>{const e=new URLSearchParams(a).entries().filter(([a])=>!r||"y"!==a).toArray().toSorted(([a,r],[e,o])=>a.localeCompare(e)||r.localeCompare(o));return new URLSearchParams(e).toString()};exports.addCacheBusterQueryParam=e=>{if(!globalThis.location)return e;const o=URL.parse(e,location.origin);if(!o)return e;const t=new URLSearchParams(location.search).get("y"),{pathname:n,search:c}=o,i=new URLSearchParams(c);return n===location.pathname&&r(c,!0)===r(location.search,!0)?i.set("y",t??a.nanoid()):i.set("y",a.nanoid()),`${n}?${i.toString()}`},exports.shouldUrlAndLocationMatch=a=>{if(!globalThis.location)return!1;const e=URL.parse(a,location.origin);return!!e&&(e.pathname===location.pathname&&r(e.search,!0)===r(location.search,!0))};
2
+ //# sourceMappingURL=helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs","sources":["../../src/helpers.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\n\nconst normalizeSearchParams = (search: string, toOmitCacheBuster = false): string => {\n const entries = new URLSearchParams(search)\n .entries()\n .filter(([key]) => !toOmitCacheBuster || key !== 'y')\n .toArray()\n .toSorted(([keyA, valueA], [keyB, valueB]) => keyA.localeCompare(keyB) || valueA.localeCompare(valueB));\n\n return new URLSearchParams(entries).toString();\n};\n\nexport const shouldUrlAndLocationMatch = (url: string): boolean => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return false;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return false;\n }\n\n return (\n parsedUrl.pathname === location.pathname &&\n normalizeSearchParams(parsedUrl.search, true) === normalizeSearchParams(location.search, true)\n );\n};\n\nexport const addCacheBusterQueryParam = (url: string): string => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return url;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return url;\n }\n\n const locationSearchParams = new URLSearchParams(location.search);\n const locationCacheBusterSearchParam = locationSearchParams.get('y');\n\n const { pathname, search } = parsedUrl;\n const searchParams = new URLSearchParams(search);\n\n if (\n pathname === location.pathname &&\n normalizeSearchParams(search, true) === normalizeSearchParams(location.search, true)\n ) {\n searchParams.set('y', locationCacheBusterSearchParam ?? nanoid());\n } else {\n searchParams.set('y', nanoid());\n }\n\n return `${pathname}?${searchParams.toString()}`;\n};\n"],"names":["normalizeSearchParams","search","toOmitCacheBuster","entries","URLSearchParams","filter","key","toArray","toSorted","keyA","valueA","keyB","valueB","localeCompare","toString","url","globalThis","location","parsedUrl","URL","parse","origin","locationCacheBusterSearchParam","get","pathname","searchParams","set","nanoid"],"mappings":"qCAEA,MAAMA,EAAwB,CAACC,EAAgBC,GAAoB,KACjE,MAAMC,EAAU,IAAIC,gBAAgBH,GACjCE,UACAE,OAAO,EAAEC,MAAUJ,GAA6B,MAARI,GACxCC,UACAC,SAAS,EAAEC,EAAMC,IAAUC,EAAMC,KAAYH,EAAKI,cAAcF,IAASD,EAAOG,cAAcD,IAEjG,OAAO,IAAIR,gBAAgBD,GAASW,6CAsBGC,IAGvC,IAAKC,WAAWC,SACd,OAAOF,EAGT,MAAMG,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,IAAKH,EACH,OAAOH,EAGT,MACMO,EADuB,IAAIlB,gBAAgBa,SAAShB,QACEsB,IAAI,MAE1DC,SAAEA,EAAQvB,OAAEA,GAAWiB,EACvBO,EAAe,IAAIrB,gBAAgBH,GAWzC,OAREuB,IAAaP,SAASO,UACtBxB,EAAsBC,GAAQ,KAAUD,EAAsBiB,SAAShB,QAAQ,GAE/EwB,EAAaC,IAAI,IAAKJ,GAAkCK,EAAAA,UAExDF,EAAaC,IAAI,IAAKC,EAAAA,UAGjB,GAAGH,KAAYC,EAAaX,gDA/CKC,IAGxC,IAAKC,WAAWC,SACd,OAAO,EAGT,MAAMC,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,QAAKH,IAKHA,EAAUM,WAAaP,SAASO,UAChCxB,EAAsBkB,EAAUjB,QAAQ,KAAUD,EAAsBiB,SAAShB,QAAQ"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),r=require("react"),n=require("nanoid");const t=r.createContext({}),a=e=>{if(!globalThis.location)return!1;const r=URL.parse(e,location.origin);if(!r)return!1;const{pathname:n,search:t}=r,a=new URLSearchParams(t);a.has("y")&&a.delete("y");const o=new URLSearchParams(location.search);return o.has("y")&&o.delete("y"),`${n}?${a.toString()}`==`${location.pathname}?${o.toString()}`},o=e=>{if(!globalThis.location)return e;const r=URL.parse(e,location.origin);if(!r)return e;const t=new URLSearchParams(location.search),a=t.get("y");a&&t.delete("y");const{pathname:o,search:i}=r,c=new URLSearchParams(i);return`${o}?${i}`==`${location.pathname}?${t.toString()}`?c.set("y",a??n.nanoid()):c.set("y",n.nanoid()),`${o}?${c.toString()}`},i=()=>r.use(t);exports.Link=({children:r,disableRouterCache:n=!0,href:t="#",onClick:c,prefetch:s=!1,scroll:l=!1,...u})=>{const{NextLink:h,OwnLink:d,onLinkClicked:L}=i();return n&&(t=o(t)),e.jsx(h,{href:t,legacyBehavior:!0,passHref:!0,prefetch:s,scroll:l,children:e.jsx(d,{onClick:e=>{c&&c(e),a(t)||e.defaultPrevented||L()},...u,children:r})})},exports.LinkContext=t,exports.LinkProvider=({LoadingComponent:n,NextLink:a,OwnLink:o,children:i,loadingTimeout:c=500,pathname:s})=>{const l=r.useRef(null),[u,h]=r.useState(!1),d=r.useCallback(()=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{h(!0)},c)},[c]);return r.useEffect(()=>{l.current&&clearTimeout(l.current),h(!1),scroll(0,0)},[s]),e.jsx(t,{value:{NextLink:a,OwnLink:o,onLinkClicked:()=>{d()}},children:e.jsxs(e.Fragment,{children:[i,u?e.jsx(n,{}):void 0]})})},exports.addCacheBusterQueryParam=o,exports.shouldUrlAndLocationMatch=a,exports.useLinkExtra=i;
1
+ "use strict";var r=require("./LinkProvider.cjs"),e=require("./Link.cjs"),i=require("./helpers.cjs"),t=require("./useLinkExtra.cjs");exports.LinkContext=r.LinkContext,exports.LinkProvider=r.LinkProvider,exports.Link=e.Link,exports.addCacheBusterQueryParam=i.addCacheBusterQueryParam,exports.shouldUrlAndLocationMatch=i.shouldUrlAndLocationMatch,exports.useLinkExtra=t.useLinkExtra;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/LinkProvider.tsx","../../src/helpers.ts","../../src/useLinkExtra.ts","../../src/Link.tsx"],"sourcesContent":["import type Link from 'next/link.js';\nimport {\n type ComponentType,\n type FC,\n type ReactNode,\n createContext,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { type LinkContextData, type NextLinkComponent, type OwnLinkProps } from '#types.js';\n\n// Context requires an initial value, but this is set in the provider so casting\n// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\nexport const LinkContext = createContext<LinkContextData>({} as LinkContextData);\n\nexport type LinkProviderProps = {\n LoadingComponent: ComponentType;\n NextLink: typeof Link;\n OwnLink: ComponentType<OwnLinkProps>;\n children: ReactNode | ReactNode[];\n loadingTimeout?: number;\n pathname: string;\n};\n\nexport const LinkProvider: FC<LinkProviderProps> = ({\n LoadingComponent,\n NextLink,\n OwnLink,\n children,\n loadingTimeout = 500,\n pathname,\n}) => {\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const [showLoading, setShowLoading] = useState<boolean>(false);\n\n const onLinkClicked = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n setShowLoading(true);\n }, loadingTimeout);\n }, [loadingTimeout]);\n\n useEffect(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n // This is setting state based on pathname change\n // eslint-disable-next-line react-hooks/set-state-in-effect, @eslint-react/set-state-in-effect\n setShowLoading(false);\n scroll(0, 0);\n }, [pathname]);\n\n return (\n <LinkContext\n value={{\n // Casting due to issues marrying up prop type and context type\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n NextLink: NextLink as unknown as NextLinkComponent,\n OwnLink,\n onLinkClicked: () => {\n onLinkClicked();\n },\n }}\n >\n <>\n {children}\n {showLoading ? <LoadingComponent /> : undefined}\n </>\n </LinkContext>\n );\n};\n","import { nanoid } from 'nanoid';\n\nexport const shouldUrlAndLocationMatch = (url: string): boolean => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return false;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return false;\n }\n\n const { pathname, search } = parsedUrl;\n const urlSearchParams = new URLSearchParams(search);\n\n if (urlSearchParams.has('y')) {\n urlSearchParams.delete('y');\n }\n\n const locationSearchParams = new URLSearchParams(location.search);\n\n if (locationSearchParams.has('y')) {\n locationSearchParams.delete('y');\n }\n\n return `${pathname}?${urlSearchParams.toString()}` === `${location.pathname}?${locationSearchParams.toString()}`;\n};\n\nexport const addCacheBusterQueryParam = (url: string): string => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return url;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return url;\n }\n\n const locationSearchParams = new URLSearchParams(location.search);\n const locationCacheBusterSearchParam = locationSearchParams.get('y');\n\n if (locationCacheBusterSearchParam) {\n locationSearchParams.delete('y');\n }\n\n const { pathname, search } = parsedUrl;\n const searchParams = new URLSearchParams(search);\n\n if (`${pathname}?${search}` === `${location.pathname}?${locationSearchParams.toString()}`) {\n searchParams.set('y', locationCacheBusterSearchParam ?? nanoid());\n } else {\n searchParams.set('y', nanoid());\n }\n\n return `${pathname}?${searchParams.toString()}`;\n};\n","import { use } from 'react';\nimport { type LinkContextData } from '#types.ts';\nimport { LinkContext } from './LinkProvider.tsx';\n\nexport const useLinkExtra = (): LinkContextData => {\n return use(LinkContext);\n};\n","import { type AnchorHTMLAttributes, type JSX, type ReactNode } from 'react';\nimport { addCacheBusterQueryParam, shouldUrlAndLocationMatch } from '#helpers.ts';\nimport { useLinkExtra } from './useLinkExtra.ts';\n\nexport type LinkProps<T extends object> = {\n children: ReactNode;\n disableRouterCache?: boolean;\n href?: string;\n prefetch?: boolean;\n scroll?: boolean;\n} & AnchorHTMLAttributes<HTMLAnchorElement> &\n T;\n\nexport const Link = <T extends object>({\n children,\n disableRouterCache = true,\n href = '#',\n onClick,\n prefetch = false,\n scroll = false,\n ...otherProps\n}: LinkProps<T>): JSX.Element => {\n // This and the two other disables below are false positives\n // eslint-disable-next-line @eslint-react/static-components\n const { NextLink, OwnLink, onLinkClicked } = useLinkExtra();\n\n if (disableRouterCache) {\n href = addCacheBusterQueryParam(href);\n }\n\n return (\n // This needs to remain: https://github.com/vercel/next.js/discussions/76329\n // eslint-disable-next-line @typescript-eslint/no-deprecated, @eslint-react/static-components\n <NextLink href={href} legacyBehavior passHref prefetch={prefetch} scroll={scroll}>\n <OwnLink // eslint-disable-line @eslint-react/static-components\n onClick={event => {\n if (onClick) {\n onClick(event);\n }\n\n if (!shouldUrlAndLocationMatch(href) && !event.defaultPrevented) {\n onLinkClicked();\n }\n }}\n {...otherProps}\n >\n {children}\n </OwnLink>\n </NextLink>\n );\n};\n"],"names":["LinkContext","createContext","shouldUrlAndLocationMatch","url","globalThis","location","parsedUrl","URL","parse","origin","pathname","search","urlSearchParams","URLSearchParams","has","delete","locationSearchParams","toString","addCacheBusterQueryParam","locationCacheBusterSearchParam","get","searchParams","set","nanoid","useLinkExtra","use","children","disableRouterCache","href","onClick","prefetch","scroll","otherProps","NextLink","OwnLink","onLinkClicked","_jsx","legacyBehavior","passHref","event","defaultPrevented","LoadingComponent","loadingTimeout","timeoutRef","useRef","showLoading","setShowLoading","useState","useCallback","current","clearTimeout","setTimeout","useEffect","value","_jsxs","_Fragment","undefined"],"mappings":"uFAeO,MAAMA,EAAcC,EAAAA,cAA+B,CAAA,GCb7CC,EAA6BC,IAGxC,IAAKC,WAAWC,SACd,OAAO,EAGT,MAAMC,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,IAAKH,EACH,OAAO,EAGT,MAAMI,SAAEA,EAAQC,OAAEA,GAAWL,EACvBM,EAAkB,IAAIC,gBAAgBF,GAExCC,EAAgBE,IAAI,MACtBF,EAAgBG,OAAO,KAGzB,MAAMC,EAAuB,IAAIH,gBAAgBR,SAASM,QAM1D,OAJIK,EAAqBF,IAAI,MAC3BE,EAAqBD,OAAO,KAGvB,GAAGL,KAAYE,EAAgBK,cAAiB,GAAGZ,SAASK,YAAYM,EAAqBC,cAGzFC,EAA4Bf,IAGvC,IAAKC,WAAWC,SACd,OAAOF,EAGT,MAAMG,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,IAAKH,EACH,OAAOH,EAGT,MAAMa,EAAuB,IAAIH,gBAAgBR,SAASM,QACpDQ,EAAiCH,EAAqBI,IAAI,KAE5DD,GACFH,EAAqBD,OAAO,KAG9B,MAAML,SAAEA,EAAQC,OAAEA,GAAWL,EACvBe,EAAe,IAAIR,gBAAgBF,GAQzC,MANI,GAAGD,KAAYC,KAAa,GAAGN,SAASK,YAAYM,EAAqBC,aAC3EI,EAAaC,IAAI,IAAKH,GAAkCI,EAAAA,UAExDF,EAAaC,IAAI,IAAKC,EAAAA,UAGjB,GAAGb,KAAYW,EAAaJ,cCxDxBO,EAAe,IACnBC,EAAAA,IAAIzB,gBCQO,EAClB0B,WACAC,sBAAqB,EACrBC,OAAO,IACPC,UACAC,YAAW,EACXC,UAAS,KACNC,MAIH,MAAMC,SAAEA,EAAQC,QAAEA,EAAOC,cAAEA,GAAkBX,IAM7C,OAJIG,IACFC,EAAOV,EAAyBU,IAMhCQ,EAAAA,IAACH,EAAAA,CAASL,KAAMA,EAAMS,gBAAc,EAACC,UAAQ,EAACR,SAAUA,EAAUC,OAAQA,WACxEK,EAAAA,IAACF,GACCL,QAASU,IACHV,GACFA,EAAQU,GAGLrC,EAA0B0B,IAAUW,EAAMC,kBAC7CL,QAGAH,EAEHN,SAAAA,kDHpB0C,EACjDe,mBACAR,WACAC,UACAR,WACAgB,iBAAiB,IACjBhC,eAEA,MAAMiC,EAAaC,EAAAA,OAA6C,OACzDC,EAAaC,GAAkBC,EAAAA,UAAkB,GAElDZ,EAAgBa,EAAAA,YAAY,KAC5BL,EAAWM,SACbC,aAAaP,EAAWM,SAG1BN,EAAWM,QAAUE,WAAW,KAC9BL,GAAe,IACdJ,IACF,CAACA,IAaJ,OAXAU,EAAAA,UAAU,KACJT,EAAWM,SACbC,aAAaP,EAAWM,SAK1BH,GAAe,GACff,OAAO,EAAG,IACT,CAACrB,IAGF0B,EAAAA,IAACpC,EAAAA,CACCqD,MAAO,CAGLpB,SAAUA,EACVC,UACAC,cAAe,KACbA,eAIJmB,EAAAA,KAAAC,WAAA,WACG7B,EACAmB,EAAcT,EAAAA,IAACK,EAAAA,CAAAA,QAAsBe"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react"),r=require("./LinkProvider.cjs");exports.useLinkExtra=()=>e.use(r.LinkContext);
2
+ //# sourceMappingURL=useLinkExtra.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLinkExtra.cjs","sources":["../../src/useLinkExtra.ts"],"sourcesContent":["import { use } from 'react';\nimport { type LinkContextData } from '#types.ts';\nimport { LinkContext } from './LinkProvider.tsx';\n\nexport const useLinkExtra = (): LinkContextData => {\n return use(LinkContext);\n};\n"],"names":["use","LinkContext"],"mappings":"yFAI4B,IACnBA,EAAAA,IAAIC,EAAAA"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ import{jsx as e}from"react/jsx-runtime";import{addCacheBusterQueryParam as r,shouldUrlAndLocationMatch as i}from"./helpers.mjs";import{useLinkExtra as n}from"./useLinkExtra.mjs";const o=({children:o,disableRouterCache:t=!0,href:c="#",onClick:l,prefetch:s=!1,scroll:h=!1,...f})=>{const{NextLink:m,OwnLink:a,onLinkClicked:p}=n();return t&&(c=r(c)),e(m,{href:c,legacyBehavior:!0,passHref:!0,prefetch:s,scroll:h,children:e(a,{onClick:e=>{l&&l(e),i(c)||e.defaultPrevented||p()},...f,children:o})})};export{o as Link};
3
+ //# sourceMappingURL=Link.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Link.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ import{jsx as n,jsxs as r,Fragment as e}from"react/jsx-runtime";import{createContext as t,useRef as l,useState as u,useCallback as c,useEffect as i}from"react";const o=t({}),m=({LoadingComponent:t,NextLink:m,OwnLink:a,children:d,loadingTimeout:k=500,pathname:L})=>{const p=l(null),[s,T]=u(!1),h=c(()=>{null!==p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,T(!0)},k)},[k]);return i(()=>(null!==p.current&&(clearTimeout(p.current),p.current=null),T(!1),scroll(0,0),()=>{null!==p.current&&(clearTimeout(p.current),p.current=null)}),[L]),n(o,{value:{NextLink:m,OwnLink:a,onLinkClicked:()=>{h()}},children:r(e,{children:[d,s?n(t,{}):void 0]})})};export{o as LinkContext,m as LinkProvider};
3
+ //# sourceMappingURL=LinkProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkProvider.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,2 @@
1
+ import{nanoid as a}from"nanoid";const r=(a,r=!1)=>{const o=new URLSearchParams(a).entries().filter(([a])=>!r||"y"!==a).toArray().toSorted(([a,r],[o,t])=>a.localeCompare(o)||r.localeCompare(t));return new URLSearchParams(o).toString()},o=a=>{if(!globalThis.location)return!1;const o=URL.parse(a,location.origin);return!!o&&(o.pathname===location.pathname&&r(o.search,!0)===r(location.search,!0))},t=o=>{if(!globalThis.location)return o;const t=URL.parse(o,location.origin);if(!t)return o;const e=new URLSearchParams(location.search).get("y"),{pathname:n,search:c}=t,i=new URLSearchParams(c);return n===location.pathname&&r(c,!0)===r(location.search,!0)?i.set("y",e??a()):i.set("y",a()),`${n}?${i.toString()}`};export{t as addCacheBusterQueryParam,o as shouldUrlAndLocationMatch};
2
+ //# sourceMappingURL=helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.mjs","sources":["../../src/helpers.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\n\nconst normalizeSearchParams = (search: string, toOmitCacheBuster = false): string => {\n const entries = new URLSearchParams(search)\n .entries()\n .filter(([key]) => !toOmitCacheBuster || key !== 'y')\n .toArray()\n .toSorted(([keyA, valueA], [keyB, valueB]) => keyA.localeCompare(keyB) || valueA.localeCompare(valueB));\n\n return new URLSearchParams(entries).toString();\n};\n\nexport const shouldUrlAndLocationMatch = (url: string): boolean => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return false;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return false;\n }\n\n return (\n parsedUrl.pathname === location.pathname &&\n normalizeSearchParams(parsedUrl.search, true) === normalizeSearchParams(location.search, true)\n );\n};\n\nexport const addCacheBusterQueryParam = (url: string): string => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return url;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return url;\n }\n\n const locationSearchParams = new URLSearchParams(location.search);\n const locationCacheBusterSearchParam = locationSearchParams.get('y');\n\n const { pathname, search } = parsedUrl;\n const searchParams = new URLSearchParams(search);\n\n if (\n pathname === location.pathname &&\n normalizeSearchParams(search, true) === normalizeSearchParams(location.search, true)\n ) {\n searchParams.set('y', locationCacheBusterSearchParam ?? nanoid());\n } else {\n searchParams.set('y', nanoid());\n }\n\n return `${pathname}?${searchParams.toString()}`;\n};\n"],"names":["normalizeSearchParams","search","toOmitCacheBuster","entries","URLSearchParams","filter","key","toArray","toSorted","keyA","valueA","keyB","valueB","localeCompare","toString","shouldUrlAndLocationMatch","url","globalThis","location","parsedUrl","URL","parse","origin","pathname","addCacheBusterQueryParam","locationCacheBusterSearchParam","get","searchParams","set","nanoid"],"mappings":"gCAEA,MAAMA,EAAwB,CAACC,EAAgBC,GAAoB,KACjE,MAAMC,EAAU,IAAIC,gBAAgBH,GACjCE,UACAE,OAAO,EAAEC,MAAUJ,GAA6B,MAARI,GACxCC,UACAC,SAAS,EAAEC,EAAMC,IAAUC,EAAMC,KAAYH,EAAKI,cAAcF,IAASD,EAAOG,cAAcD,IAEjG,OAAO,IAAIR,gBAAgBD,GAASW,YAGzBC,EAA6BC,IAGxC,IAAKC,WAAWC,SACd,OAAO,EAGT,MAAMC,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,QAAKH,IAKHA,EAAUI,WAAaL,SAASK,UAChCvB,EAAsBmB,EAAUlB,QAAQ,KAAUD,EAAsBkB,SAASjB,QAAQ,KAIhFuB,EAA4BR,IAGvC,IAAKC,WAAWC,SACd,OAAOF,EAGT,MAAMG,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,IAAKH,EACH,OAAOH,EAGT,MACMS,EADuB,IAAIrB,gBAAgBc,SAASjB,QACEyB,IAAI,MAE1DH,SAAEA,EAAQtB,OAAEA,GAAWkB,EACvBQ,EAAe,IAAIvB,gBAAgBH,GAWzC,OAREsB,IAAaL,SAASK,UACtBvB,EAAsBC,GAAQ,KAAUD,EAAsBkB,SAASjB,QAAQ,GAE/E0B,EAAaC,IAAI,IAAKH,GAAkCI,KAExDF,EAAaC,IAAI,IAAKC,KAGjB,GAAGN,KAAYI,EAAab"}
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as n,Fragment as r}from"react/jsx-runtime";import{createContext as t,useRef as o,useState as a,useCallback as i,useEffect as c,use as l}from"react";import{nanoid as s}from"nanoid";const h=t({}),u=({LoadingComponent:t,NextLink:l,OwnLink:s,children:u,loadingTimeout:m=500,pathname:d})=>{const p=o(null),[L,f]=a(!1),g=i(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{f(!0)},m)},[m]);return c(()=>{p.current&&clearTimeout(p.current),f(!1),scroll(0,0)},[d]),e(h,{value:{NextLink:l,OwnLink:s,onLinkClicked:()=>{g()}},children:n(r,{children:[u,L?e(t,{}):void 0]})})},m=e=>{if(!globalThis.location)return!1;const n=URL.parse(e,location.origin);if(!n)return!1;const{pathname:r,search:t}=n,o=new URLSearchParams(t);o.has("y")&&o.delete("y");const a=new URLSearchParams(location.search);return a.has("y")&&a.delete("y"),`${r}?${o.toString()}`==`${location.pathname}?${a.toString()}`},d=e=>{if(!globalThis.location)return e;const n=URL.parse(e,location.origin);if(!n)return e;const r=new URLSearchParams(location.search),t=r.get("y");t&&r.delete("y");const{pathname:o,search:a}=n,i=new URLSearchParams(a);return`${o}?${a}`==`${location.pathname}?${r.toString()}`?i.set("y",t??s()):i.set("y",s()),`${o}?${i.toString()}`},p=()=>l(h),L=({children:n,disableRouterCache:r=!0,href:t="#",onClick:o,prefetch:a=!1,scroll:i=!1,...c})=>{const{NextLink:l,OwnLink:s,onLinkClicked:h}=p();return r&&(t=d(t)),e(l,{href:t,legacyBehavior:!0,passHref:!0,prefetch:a,scroll:i,children:e(s,{onClick:e=>{o&&o(e),m(t)||e.defaultPrevented||h()},...c,children:n})})};export{L as Link,h as LinkContext,u as LinkProvider,d as addCacheBusterQueryParam,m as shouldUrlAndLocationMatch,p as useLinkExtra};
1
+ export{LinkContext,LinkProvider}from"./LinkProvider.mjs";export{Link}from"./Link.mjs";export{addCacheBusterQueryParam,shouldUrlAndLocationMatch}from"./helpers.mjs";export{useLinkExtra}from"./useLinkExtra.mjs";
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../src/LinkProvider.tsx","../../src/helpers.ts","../../src/useLinkExtra.ts","../../src/Link.tsx"],"sourcesContent":["import type Link from 'next/link.js';\nimport {\n type ComponentType,\n type FC,\n type ReactNode,\n createContext,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { type LinkContextData, type NextLinkComponent, type OwnLinkProps } from '#types.js';\n\n// Context requires an initial value, but this is set in the provider so casting\n// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\nexport const LinkContext = createContext<LinkContextData>({} as LinkContextData);\n\nexport type LinkProviderProps = {\n LoadingComponent: ComponentType;\n NextLink: typeof Link;\n OwnLink: ComponentType<OwnLinkProps>;\n children: ReactNode | ReactNode[];\n loadingTimeout?: number;\n pathname: string;\n};\n\nexport const LinkProvider: FC<LinkProviderProps> = ({\n LoadingComponent,\n NextLink,\n OwnLink,\n children,\n loadingTimeout = 500,\n pathname,\n}) => {\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const [showLoading, setShowLoading] = useState<boolean>(false);\n\n const onLinkClicked = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n setShowLoading(true);\n }, loadingTimeout);\n }, [loadingTimeout]);\n\n useEffect(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n // This is setting state based on pathname change\n // eslint-disable-next-line react-hooks/set-state-in-effect, @eslint-react/set-state-in-effect\n setShowLoading(false);\n scroll(0, 0);\n }, [pathname]);\n\n return (\n <LinkContext\n value={{\n // Casting due to issues marrying up prop type and context type\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n NextLink: NextLink as unknown as NextLinkComponent,\n OwnLink,\n onLinkClicked: () => {\n onLinkClicked();\n },\n }}\n >\n <>\n {children}\n {showLoading ? <LoadingComponent /> : undefined}\n </>\n </LinkContext>\n );\n};\n","import { nanoid } from 'nanoid';\n\nexport const shouldUrlAndLocationMatch = (url: string): boolean => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return false;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return false;\n }\n\n const { pathname, search } = parsedUrl;\n const urlSearchParams = new URLSearchParams(search);\n\n if (urlSearchParams.has('y')) {\n urlSearchParams.delete('y');\n }\n\n const locationSearchParams = new URLSearchParams(location.search);\n\n if (locationSearchParams.has('y')) {\n locationSearchParams.delete('y');\n }\n\n return `${pathname}?${urlSearchParams.toString()}` === `${location.pathname}?${locationSearchParams.toString()}`;\n};\n\nexport const addCacheBusterQueryParam = (url: string): string => {\n // It is possible for this to be undefined\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!globalThis.location) {\n return url;\n }\n\n const parsedUrl = URL.parse(url, location.origin);\n\n if (!parsedUrl) {\n return url;\n }\n\n const locationSearchParams = new URLSearchParams(location.search);\n const locationCacheBusterSearchParam = locationSearchParams.get('y');\n\n if (locationCacheBusterSearchParam) {\n locationSearchParams.delete('y');\n }\n\n const { pathname, search } = parsedUrl;\n const searchParams = new URLSearchParams(search);\n\n if (`${pathname}?${search}` === `${location.pathname}?${locationSearchParams.toString()}`) {\n searchParams.set('y', locationCacheBusterSearchParam ?? nanoid());\n } else {\n searchParams.set('y', nanoid());\n }\n\n return `${pathname}?${searchParams.toString()}`;\n};\n","import { use } from 'react';\nimport { type LinkContextData } from '#types.ts';\nimport { LinkContext } from './LinkProvider.tsx';\n\nexport const useLinkExtra = (): LinkContextData => {\n return use(LinkContext);\n};\n","import { type AnchorHTMLAttributes, type JSX, type ReactNode } from 'react';\nimport { addCacheBusterQueryParam, shouldUrlAndLocationMatch } from '#helpers.ts';\nimport { useLinkExtra } from './useLinkExtra.ts';\n\nexport type LinkProps<T extends object> = {\n children: ReactNode;\n disableRouterCache?: boolean;\n href?: string;\n prefetch?: boolean;\n scroll?: boolean;\n} & AnchorHTMLAttributes<HTMLAnchorElement> &\n T;\n\nexport const Link = <T extends object>({\n children,\n disableRouterCache = true,\n href = '#',\n onClick,\n prefetch = false,\n scroll = false,\n ...otherProps\n}: LinkProps<T>): JSX.Element => {\n // This and the two other disables below are false positives\n // eslint-disable-next-line @eslint-react/static-components\n const { NextLink, OwnLink, onLinkClicked } = useLinkExtra();\n\n if (disableRouterCache) {\n href = addCacheBusterQueryParam(href);\n }\n\n return (\n // This needs to remain: https://github.com/vercel/next.js/discussions/76329\n // eslint-disable-next-line @typescript-eslint/no-deprecated, @eslint-react/static-components\n <NextLink href={href} legacyBehavior passHref prefetch={prefetch} scroll={scroll}>\n <OwnLink // eslint-disable-line @eslint-react/static-components\n onClick={event => {\n if (onClick) {\n onClick(event);\n }\n\n if (!shouldUrlAndLocationMatch(href) && !event.defaultPrevented) {\n onLinkClicked();\n }\n }}\n {...otherProps}\n >\n {children}\n </OwnLink>\n </NextLink>\n );\n};\n"],"names":["LinkContext","createContext","LinkProvider","LoadingComponent","NextLink","OwnLink","children","loadingTimeout","pathname","timeoutRef","useRef","showLoading","setShowLoading","useState","onLinkClicked","useCallback","current","clearTimeout","setTimeout","useEffect","scroll","_jsx","value","_jsxs","_Fragment","undefined","shouldUrlAndLocationMatch","url","globalThis","location","parsedUrl","URL","parse","origin","search","urlSearchParams","URLSearchParams","has","delete","locationSearchParams","toString","addCacheBusterQueryParam","locationCacheBusterSearchParam","get","searchParams","set","nanoid","useLinkExtra","use","Link","disableRouterCache","href","onClick","prefetch","otherProps","legacyBehavior","passHref","event","defaultPrevented"],"mappings":"yMAeO,MAAMA,EAAcC,EAA+B,CAAA,GAW7CC,EAAsC,EACjDC,mBACAC,WACAC,UACAC,WACAC,iBAAiB,IACjBC,eAEA,MAAMC,EAAaC,EAA6C,OACzDC,EAAaC,GAAkBC,GAAkB,GAElDC,EAAgBC,EAAY,KAC5BN,EAAWO,SACbC,aAAaR,EAAWO,SAG1BP,EAAWO,QAAUE,WAAW,KAC9BN,GAAe,IACdL,IACF,CAACA,IAaJ,OAXAY,EAAU,KACJV,EAAWO,SACbC,aAAaR,EAAWO,SAK1BJ,GAAe,GACfQ,OAAO,EAAG,IACT,CAACZ,IAGFa,EAACrB,EAAAA,CACCsB,MAAO,CAGLlB,SAAUA,EACVC,UACAS,cAAe,KACbA,eAIJS,EAAAC,EAAA,WACGlB,EACAK,EAAcU,EAAClB,EAAAA,CAAAA,QAAsBsB,QCtEjCC,EAA6BC,IAGxC,IAAKC,WAAWC,SACd,OAAO,EAGT,MAAMC,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,IAAKH,EACH,OAAO,EAGT,MAAMtB,SAAEA,EAAQ0B,OAAEA,GAAWJ,EACvBK,EAAkB,IAAIC,gBAAgBF,GAExCC,EAAgBE,IAAI,MACtBF,EAAgBG,OAAO,KAGzB,MAAMC,EAAuB,IAAIH,gBAAgBP,SAASK,QAM1D,OAJIK,EAAqBF,IAAI,MAC3BE,EAAqBD,OAAO,KAGvB,GAAG9B,KAAY2B,EAAgBK,cAAiB,GAAGX,SAASrB,YAAY+B,EAAqBC,cAGzFC,EAA4Bd,IAGvC,IAAKC,WAAWC,SACd,OAAOF,EAGT,MAAMG,EAAYC,IAAIC,MAAML,EAAKE,SAASI,QAE1C,IAAKH,EACH,OAAOH,EAGT,MAAMY,EAAuB,IAAIH,gBAAgBP,SAASK,QACpDQ,EAAiCH,EAAqBI,IAAI,KAE5DD,GACFH,EAAqBD,OAAO,KAG9B,MAAM9B,SAAEA,EAAQ0B,OAAEA,GAAWJ,EACvBc,EAAe,IAAIR,gBAAgBF,GAQzC,MANI,GAAG1B,KAAY0B,KAAa,GAAGL,SAASrB,YAAY+B,EAAqBC,aAC3EI,EAAaC,IAAI,IAAKH,GAAkCI,KAExDF,EAAaC,IAAI,IAAKC,KAGjB,GAAGtC,KAAYoC,EAAaJ,cCxDxBO,EAAe,IACnBC,EAAIhD,GCQAiD,EAAO,EAClB3C,WACA4C,sBAAqB,EACrBC,OAAO,IACPC,UACAC,YAAW,EACXjC,UAAS,KACNkC,MAIH,MAAMlD,SAAEA,EAAQC,QAAEA,EAAOS,cAAEA,GAAkBiC,IAM7C,OAJIG,IACFC,EAAOV,EAAyBU,IAMhC9B,EAACjB,EAAAA,CAAS+C,KAAMA,EAAMI,gBAAc,EAACC,UAAQ,EAACH,SAAUA,EAAUjC,OAAQA,WACxEC,EAAChB,GACC+C,QAASK,IACHL,GACFA,EAAQK,GAGL/B,EAA0ByB,IAAUM,EAAMC,kBAC7C5C,QAGAwC,EAEHhD,SAAAA"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import{use as r}from"react";import{LinkContext as o}from"./LinkProvider.mjs";const m=()=>r(o);export{m as useLinkExtra};
2
+ //# sourceMappingURL=useLinkExtra.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLinkExtra.mjs","sources":["../../src/useLinkExtra.ts"],"sourcesContent":["import { use } from 'react';\nimport { type LinkContextData } from '#types.ts';\nimport { LinkContext } from './LinkProvider.tsx';\n\nexport const useLinkExtra = (): LinkContextData => {\n return use(LinkContext);\n};\n"],"names":["useLinkExtra","use","LinkContext"],"mappings":"mFAIaA,EAAe,IACnBC,EAAIC"}
@@ -1,49 +1,49 @@
1
1
  -----------------------------
2
2
  Rollup File Analysis
3
3
  -----------------------------
4
- bundle size: 4.759 KB
5
- original size: 5.717 KB
6
- code reduction: 16.76 %
4
+ bundle size: 5.099 KB
5
+ original size: 6.186 KB
6
+ code reduction: 17.57 %
7
7
  module count: 5
8
8
 
9
- ██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
10
- file: /src/helpers.ts
11
- bundle space: 36.81 %
12
- rendered size: 1.752 KB
13
- original size: 1.739 KB
14
- code reduction: 0 %
9
+ ████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
10
+ file: /src/LinkProvider.tsx
11
+ bundle space: 41.38 %
12
+ rendered size: 2.11 KB
13
+ original size: 2.446 KB
14
+ code reduction: 13.74 %
15
15
  dependents: 2
16
- - /src/Link.tsx
17
16
  - /src/index.ts
17
+ - /src/useLinkExtra.ts
18
18
 
19
- █████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
20
- file: /src/LinkProvider.tsx
21
- bundle space: 35.91 %
22
- rendered size: 1.709 KB
23
- original size: 2.064 KB
24
- code reduction: 17.2 %
19
+ ████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
20
+ file: /src/helpers.ts
21
+ bundle space: 33.71 %
22
+ rendered size: 1.719 KB
23
+ original size: 1.811 KB
24
+ code reduction: 5.08 %
25
25
  dependents: 2
26
- - /src/useLinkExtra.ts
27
26
  - /src/index.ts
27
+ - /src/Link.tsx
28
28
 
29
- ████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
29
+ ███████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
30
30
  file: /src/Link.tsx
31
- bundle space: 25.93 %
32
- rendered size: 1.234 KB
33
- original size: 1.544 KB
34
- code reduction: 20.08 %
31
+ bundle space: 23.77 %
32
+ rendered size: 1.212 KB
33
+ original size: 1.559 KB
34
+ code reduction: 22.26 %
35
35
  dependents: 1
36
36
  - /src/index.ts
37
37
 
38
38
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
39
39
  file: /src/useLinkExtra.ts
40
- bundle space: 1.34 %
41
- rendered size: 64 Bytes
40
+ bundle space: 1.14 %
41
+ rendered size: 58 Bytes
42
42
  original size: 213 Bytes
43
- code reduction: 69.95 %
43
+ code reduction: 72.77 %
44
44
  dependents: 2
45
- - /src/Link.tsx
46
45
  - /src/index.ts
46
+ - /src/Link.tsx
47
47
 
48
48
  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
49
49
  file: /src/index.ts
@@ -1 +1 @@
1
- {"version":3,"file":"Link.d.cts","sourceRoot":"","sources":["../../../src/Link.ctsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5E,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,GACzC,CAAC,CAAC;AAEJ,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,kFAQpC,SAAS,CAAC,CAAC,CAAC,KAAG,GAAG,CAAC,OA6BrB,CAAC"}
1
+ {"version":3,"file":"Link.d.cts","sourceRoot":"","sources":["../../../src/Link.ctsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5E,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,GACzC,CAAC,CAAC;AAEJ,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,kFAQpC,SAAS,CAAC,CAAC,CAAC,KAAG,GAAG,CAAC,OA6BrB,CAAC"}
@@ -1,10 +1,10 @@
1
- import type Link from 'next/link.js';
1
+ import type NextLink from 'next/link.js';
2
2
  import { type ComponentType, type FC, type ReactNode } from 'react';
3
3
  import { type LinkContextData, type OwnLinkProps } from '#types.js';
4
4
  export declare const LinkContext: import("react").Context<LinkContextData>;
5
5
  export type LinkProviderProps = {
6
6
  LoadingComponent: ComponentType;
7
- NextLink: typeof Link;
7
+ NextLink: (typeof NextLink)['default'];
8
8
  OwnLink: ComponentType<OwnLinkProps>;
9
9
  children: ReactNode | ReactNode[];
10
10
  loadingTimeout?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"LinkProvider.d.cts","sourceRoot":"","sources":["../../../src/LinkProvider.ctsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EACP,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,eAAe,EAA0B,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAI5F,eAAO,MAAM,WAAW,0CAAwD,CAAC;AAEjF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gBAAgB,EAAE,aAAa,CAAC;IAChC,QAAQ,EAAE,OAAO,IAAI,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAkD9C,CAAC"}
1
+ {"version":3,"file":"LinkProvider.d.cts","sourceRoot":"","sources":["../../../src/LinkProvider.ctsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EACP,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAIpE,eAAO,MAAM,WAAW,0CAAwD,CAAC;AAEjF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gBAAgB,EAAE,aAAa,CAAC;IAChC,QAAQ,EAAE,CAAC,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAmE9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../../../src/helpers.cts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,OA2BvD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,KAAK,MAAM,KAAG,MA8BtD,CAAC"}
1
+ {"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../../../src/helpers.cts"],"names":[],"mappings":"AAYA,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,OAiBvD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,KAAK,MAAM,KAAG,MA6BtD,CAAC"}
@@ -1,11 +1,8 @@
1
- import { type LinkProps } from 'next/link.js';
2
- import { type AnchorHTMLAttributes, type ComponentType, type ReactNode } from 'react';
1
+ import type NextLink from 'next/link.js';
2
+ import { type AnchorHTMLAttributes, type ComponentType } from 'react';
3
3
  export type OwnLinkProps = Record<string, any> & AnchorHTMLAttributes<HTMLAnchorElement>;
4
- export type NextLinkComponent = ComponentType<LinkProps & {
5
- children: ReactNode;
6
- }>;
7
4
  export type LinkContextData = {
8
- NextLink: NextLinkComponent;
5
+ NextLink: (typeof NextLink)['default'];
9
6
  OwnLink: ComponentType<AnchorHTMLAttributes<HTMLAnchorElement>>;
10
7
  onLinkClicked: () => void;
11
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/types.cts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAItF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEzF,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAC3C,SAAS,GAAG;IACV,QAAQ,EAAE,SAAS,CAAC;CACrB,CACF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAChE,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC"}
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/types.cts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAItE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEzF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,CAAC,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAChE,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5E,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,GACzC,CAAC,CAAC;AAEJ,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,kFAQpC,SAAS,CAAC,CAAC,CAAC,KAAG,GAAG,CAAC,OA6BrB,CAAC"}
1
+ {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/Link.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5E,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,GACzC,CAAC,CAAC;AAEJ,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,kFAQpC,SAAS,CAAC,CAAC,CAAC,KAAG,GAAG,CAAC,OA6BrB,CAAC"}
@@ -1,10 +1,10 @@
1
- import type Link from 'next/link.js';
1
+ import type NextLink from 'next/link.js';
2
2
  import { type ComponentType, type FC, type ReactNode } from 'react';
3
3
  import { type LinkContextData, type OwnLinkProps } from '#types.js';
4
4
  export declare const LinkContext: import("react").Context<LinkContextData>;
5
5
  export type LinkProviderProps = {
6
6
  LoadingComponent: ComponentType;
7
- NextLink: typeof Link;
7
+ NextLink: (typeof NextLink)['default'];
8
8
  OwnLink: ComponentType<OwnLinkProps>;
9
9
  children: ReactNode | ReactNode[];
10
10
  loadingTimeout?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"LinkProvider.d.ts","sourceRoot":"","sources":["../../../src/LinkProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EACP,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,eAAe,EAA0B,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAI5F,eAAO,MAAM,WAAW,0CAAwD,CAAC;AAEjF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gBAAgB,EAAE,aAAa,CAAC;IAChC,QAAQ,EAAE,OAAO,IAAI,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAkD9C,CAAC"}
1
+ {"version":3,"file":"LinkProvider.d.ts","sourceRoot":"","sources":["../../../src/LinkProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EACP,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAIpE,eAAO,MAAM,WAAW,0CAAwD,CAAC;AAEjF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gBAAgB,EAAE,aAAa,CAAC;IAChC,QAAQ,EAAE,CAAC,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAmE9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,OA2BvD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,KAAK,MAAM,KAAG,MA8BtD,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/helpers.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,OAiBvD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,KAAK,MAAM,KAAG,MA6BtD,CAAC"}
@@ -1,11 +1,8 @@
1
- import { type LinkProps } from 'next/link.js';
2
- import { type AnchorHTMLAttributes, type ComponentType, type ReactNode } from 'react';
1
+ import type NextLink from 'next/link.js';
2
+ import { type AnchorHTMLAttributes, type ComponentType } from 'react';
3
3
  export type OwnLinkProps = Record<string, any> & AnchorHTMLAttributes<HTMLAnchorElement>;
4
- export type NextLinkComponent = ComponentType<LinkProps & {
5
- children: ReactNode;
6
- }>;
7
4
  export type LinkContextData = {
8
- NextLink: NextLinkComponent;
5
+ NextLink: (typeof NextLink)['default'];
9
6
  OwnLink: ComponentType<AnchorHTMLAttributes<HTMLAnchorElement>>;
10
7
  onLinkClicked: () => void;
11
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAItF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEzF,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAC3C,SAAS,GAAG;IACV,QAAQ,EAAE,SAAS,CAAC;CACrB,CACF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAChE,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAItE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEzF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,CAAC,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAChE,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC"}