gatsby-link 4.20.0-next.0 → 4.20.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/CHANGELOG.md +32 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/index.d.ts +44 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
### [4.19.1](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.19.1/packages/gatsby-link) (2022-07-21)
|
|
7
|
+
|
|
8
|
+
#### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Publish types [#36199](https://github.com/gatsbyjs/gatsby/issues/36199) [#36200](https://github.com/gatsbyjs/gatsby/issues/36200) ([c4adb3e](https://github.com/gatsbyjs/gatsby/commit/c4adb3e7da572dca2296268db80e40d94c466b88))
|
|
11
|
+
|
|
12
|
+
## [4.19.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.19.0/packages/gatsby-link) (2022-07-19)
|
|
13
|
+
|
|
14
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.19)
|
|
15
|
+
|
|
16
|
+
#### Features
|
|
17
|
+
|
|
18
|
+
- Publish some packages as ESM & CJS [#36012](https://github.com/gatsbyjs/gatsby/issues/36012) ([5bd3063](https://github.com/gatsbyjs/gatsby/commit/5bd3063a1e72c6f98447bfac2bf767cca781330b))
|
|
19
|
+
|
|
20
|
+
### [4.18.1](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.18.1/packages/gatsby-link) (2022-07-12)
|
|
21
|
+
|
|
22
|
+
**Note:** Version bump only for package gatsby-link
|
|
23
|
+
|
|
24
|
+
## [4.18.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.18.0/packages/gatsby-link) (2022-07-05)
|
|
25
|
+
|
|
26
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.18)
|
|
27
|
+
|
|
28
|
+
#### Bug Fixes
|
|
29
|
+
|
|
30
|
+
- use proper babelrc configs for compiling packages [#35948](https://github.com/gatsbyjs/gatsby/issues/35948) ([384e801](https://github.com/gatsbyjs/gatsby/commit/384e8019152ad9bfa221e3e8b6da54675c93f293))
|
|
31
|
+
|
|
32
|
+
## [4.17.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.17.0/packages/gatsby-link) (2022-06-21)
|
|
33
|
+
|
|
34
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.17)
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package gatsby-link
|
|
37
|
+
|
|
6
38
|
## [4.16.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-link@4.16.0/packages/gatsby-link) (2022-06-07)
|
|
7
39
|
|
|
8
40
|
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.16)
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("prop-types"),t=require("react"),n=require("@gatsbyjs/reach-router"),r=require("
|
|
1
|
+
var e=require("prop-types"),t=require("react"),n=require("@gatsbyjs/reach-router"),r=require("gatsby-page-utils/apply-trailing-slash-option");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/o(e),i=/*#__PURE__*/o(t);function s(){return s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(this,arguments)}function l(e,t){return l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},l(e,t)}function c(e){var t=e||"/",n="",r="",o=t.indexOf("#");-1!==o&&(r=t.slice(o),t=t.slice(0,o));var a=t.indexOf("?");return-1!==a&&(n=t.slice(a),t=t.slice(0,a)),{pathname:t,search:"?"===n?"":n,hash:"#"===r?"":r}}var u=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,p=function(e){if("string"==typeof e)return!function(e){return u.test(e)}(e)},f=function(){return"production"!==process.env.NODE_ENV?"undefined"!=typeof __PATH_PREFIX__?__PATH_PREFIX__:void 0:__PATH_PREFIX__};function h(e,t){var n,r;if(void 0===t&&(t="production"!==process.env.NODE_ENV?"undefined"!=typeof __BASE_PATH__?__BASE_PATH__:void 0:__BASE_PATH__),!p(e))return e;if(e.startsWith("./")||e.startsWith("../"))return e;var o=null!=(n=null!=(r=t)?r:f())?n:"/";return""+(null!=o&&o.endsWith("/")?o.slice(0,-1):o)+(e.startsWith("/")?e:"/"+e)}var d=function(e){return null==e?void 0:e.startsWith("/")},_=function(){return"undefined"!=typeof __TRAILING_SLASH__?__TRAILING_SLASH__:void 0},v=function(e,t){if("number"==typeof e)return e;if(!p(e))return e;var o=c(e),a=o.pathname,i=o.search,s=o.hash,l=_(),u=e;return"always"!==l&&"never"!==l||(u=""+r.applyTrailingSlashOption(a,l)+i+s),d(u)?h(u):function(e,t){if(d(e))return e;var o=_(),a=n.resolve(e,t);return"always"===o||"never"===o?r.applyTrailingSlashOption(a,o):a}(u,t)},y=["to","getProps","onClick","onMouseEnter","activeClassName","activeStyle","innerRef","partiallyActive","state","replace","_location"],b={activeClassName:a.default.string,activeStyle:a.default.object,partiallyActive:a.default.bool};function w(e){/*#__PURE__*/return i.default.createElement(n.Location,null,function(t){/*#__PURE__*/return i.default.createElement(P,s({},e,{_location:t.location}))})}var P=/*#__PURE__*/function(e){var t,r;function o(t){var n;(n=e.call(this,t)||this).defaultGetProps=function(e){return(n.props.partiallyActive?e.isPartiallyCurrent:e.isCurrent)?{className:[n.props.className,n.props.activeClassName].filter(Boolean).join(" "),style:s({},n.props.style,n.props.activeStyle)}:null};var r=!1;return"undefined"!=typeof window&&window.IntersectionObserver&&(r=!0),n.state={IOSupported:r},n.abortPrefetch=null,n.handleRef=n.handleRef.bind(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(n)),n}r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,l(t,r);var a=o.prototype;return a._prefetch=function(){var e=window.location.pathname+window.location.search;this.props._location&&this.props._location.pathname&&(e=this.props._location.pathname+this.props._location.search);var t=c(v(this.props.to,e)),n=t.pathname+t.search;if(e!==n)return ___loader.enqueue(n)},a.componentWillUnmount=function(){if(this.io){var e=this.io,t=e.instance,n=e.el;this.abortPrefetch&&this.abortPrefetch.abort(),t.unobserve(n),t.disconnect()}},a.handleRef=function(e){var t,n,r,o=this;this.props.innerRef&&Object.prototype.hasOwnProperty.call(this.props.innerRef,"current")?this.props.innerRef.current=e:this.props.innerRef&&this.props.innerRef(e),this.state.IOSupported&&e&&(this.io=(t=e,n=function(e){e?o.abortPrefetch=o._prefetch():o.abortPrefetch&&o.abortPrefetch.abort()},(r=new window.IntersectionObserver(function(e){e.forEach(function(e){t===e.target&&n(e.isIntersecting||e.intersectionRatio>0)})})).observe(t),{instance:r,el:t}))},a.render=function(){var e=this,t=this.props,r=t.to,o=t.getProps,a=void 0===o?this.defaultGetProps:o,l=t.onClick,u=t.onMouseEnter,f=t.state,h=t.replace,d=t._location,_=function(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}(t,y);"production"===process.env.NODE_ENV||p(r)||console.warn("External link "+r+" was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links");var b=v(r,d.pathname);return p(b)?/*#__PURE__*/i.default.createElement(n.Link,s({to:b,state:f,getProps:a,innerRef:this.handleRef,onMouseEnter:function(e){u&&u(e);var t=c(b);___loader.hovering(t.pathname+t.search)},onClick:function(t){if(l&&l(t),!(0!==t.button||e.props.target||t.defaultPrevented||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)){t.preventDefault();var n=h,r=encodeURI(b)===d.pathname;"boolean"!=typeof h&&r&&(n=!0),window.___navigate(b,{state:f,replace:n})}return!0}},_)):/*#__PURE__*/i.default.createElement("a",s({href:b},_))},o}(i.default.Component);P.propTypes=s({},b,{onClick:a.default.func,to:a.default.string.isRequired,replace:a.default.bool,state:a.default.object});var m=i.default.forwardRef(function(e,t){/*#__PURE__*/return i.default.createElement(w,s({innerRef:t},e))});exports.default=m,exports.navigate=function(e,t){window.___navigate(v(e,window.location.pathname),t)},exports.parsePath=c,exports.withAssetPrefix=function(e){return h(e,f())},exports.withPrefix=h;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/parse-path.js","../src/is-local-link.js","../src/prefix-helpers.js","../src/rewrite-link-path.js","../src/index.js"],"sourcesContent":["export function parsePath(path) {\n let pathname = path || `/`\n let search = ``\n let hash = ``\n\n const hashIndex = pathname.indexOf(`#`)\n if (hashIndex !== -1) {\n hash = pathname.slice(hashIndex)\n pathname = pathname.slice(0, hashIndex)\n }\n\n const searchIndex = pathname.indexOf(`?`)\n if (searchIndex !== -1) {\n search = pathname.slice(searchIndex)\n pathname = pathname.slice(0, searchIndex)\n }\n\n return {\n pathname: pathname,\n search: search === `?` ? `` : search,\n hash: hash === `#` ? `` : hash,\n }\n}\n","// Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js\nconst ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\\d+\\-.]*?:/\nconst isAbsolute = path => ABSOLUTE_URL_REGEX.test(path)\n\nexport const isLocalLink = path => {\n if (typeof path !== `string`) {\n return undefined\n // TODO(v5): Re-Add TypeError\n // throw new TypeError(`Expected a \\`string\\`, got \\`${typeof path}\\``)\n }\n\n return !isAbsolute(path)\n}\n","import { isLocalLink } from \"./is-local-link\"\n\nexport const getGlobalBasePrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __BASE_PATH__ !== `undefined`\n ? __BASE_PATH__\n : undefined\n : __BASE_PATH__\n\n// These global values are wrapped in typeof clauses to ensure the values exist.\n// This is especially problematic in unit testing of this component.\nexport const getGlobalPathPrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __PATH_PREFIX__ !== `undefined`\n ? __PATH_PREFIX__\n : undefined\n : __PATH_PREFIX__\n\nexport function withPrefix(path, prefix = getGlobalBasePrefix()) {\n if (!isLocalLink(path)) {\n return path\n }\n\n if (path.startsWith(`./`) || path.startsWith(`../`)) {\n return path\n }\n const base = prefix ?? getGlobalPathPrefix() ?? `/`\n\n return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${\n path.startsWith(`/`) ? path : `/${path}`\n }`\n}\n","import { resolve } from \"@gatsbyjs/reach-router/lib/utils\"\n// Specific import to treeshake Node.js stuff\nimport { applyTrailingSlashOption } from \"gatsby-page-utils/apply-trailing-slash-option\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { withPrefix } from \"./prefix-helpers\"\n\nconst isAbsolutePath = path => path?.startsWith(`/`)\n\nconst getGlobalTrailingSlash = () =>\n typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined\n\nfunction absolutify(path, current) {\n // If it's already absolute, return as-is\n if (isAbsolutePath(path)) {\n return path\n }\n\n const option = getGlobalTrailingSlash()\n const absolutePath = resolve(path, current)\n\n if (option === `always` || option === `never`) {\n return applyTrailingSlashOption(absolutePath, option)\n }\n\n return absolutePath\n}\n\nexport const rewriteLinkPath = (path, relativeTo) => {\n if (typeof path === `number`) {\n return path\n }\n if (!isLocalLink(path)) {\n return path\n }\n\n const { pathname, search, hash } = parsePath(path)\n const option = getGlobalTrailingSlash()\n let adjustedPath = path\n\n if (option === `always` || option === `never`) {\n const output = applyTrailingSlashOption(pathname, option)\n adjustedPath = `${output}${search}${hash}`\n }\n\n return isAbsolutePath(adjustedPath)\n ? withPrefix(adjustedPath)\n : absolutify(adjustedPath, relativeTo)\n}\n","import PropTypes from \"prop-types\"\nimport React from \"react\"\nimport { Link, Location } from \"@gatsbyjs/reach-router\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { rewriteLinkPath } from \"./rewrite-link-path\"\nimport { withPrefix, getGlobalPathPrefix } from \"./prefix-helpers\"\n\nexport { parsePath, withPrefix }\n\nexport function withAssetPrefix(path) {\n return withPrefix(path, getGlobalPathPrefix())\n}\n\nconst NavLinkPropTypes = {\n activeClassName: PropTypes.string,\n activeStyle: PropTypes.object,\n partiallyActive: PropTypes.bool,\n}\n\n// Set up IntersectionObserver\nconst createIntersectionObserver = (el, cb) => {\n const io = new window.IntersectionObserver(entries => {\n entries.forEach(entry => {\n if (el === entry.target) {\n // Check if element is within viewport, remove listener, destroy observer, and run link callback.\n // MSEdge doesn't currently support isIntersecting, so also test for an intersectionRatio > 0\n cb(entry.isIntersecting || entry.intersectionRatio > 0)\n }\n })\n })\n\n // Add element to the observer\n io.observe(el)\n\n return { instance: io, el }\n}\n\nfunction GatsbyLinkLocationWrapper(props) {\n return (\n <Location>\n {({ location }) => <GatsbyLink {...props} _location={location} />}\n </Location>\n )\n}\n\nclass GatsbyLink extends React.Component {\n constructor(props) {\n super(props)\n // Default to no support for IntersectionObserver\n let IOSupported = false\n if (typeof window !== `undefined` && window.IntersectionObserver) {\n IOSupported = true\n }\n\n this.state = {\n IOSupported,\n }\n this.abortPrefetch = null\n this.handleRef = this.handleRef.bind(this)\n }\n\n _prefetch() {\n let currentPath = window.location.pathname + window.location.search\n\n // reach router should have the correct state\n if (this.props._location && this.props._location.pathname) {\n currentPath = this.props._location.pathname + this.props._location.search\n }\n\n const rewrittenPath = rewriteLinkPath(this.props.to, currentPath)\n const parsed = parsePath(rewrittenPath)\n\n const newPathName = parsed.pathname + parsed.search\n\n // Prefetch is used to speed up next navigations. When you use it on the current navigation,\n // there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete\n if (currentPath !== newPathName) {\n return ___loader.enqueue(newPathName)\n }\n\n return undefined\n }\n\n componentWillUnmount() {\n if (!this.io) {\n return\n }\n const { instance, el } = this.io\n\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n\n instance.unobserve(el)\n instance.disconnect()\n }\n\n handleRef(ref) {\n if (\n this.props.innerRef &&\n Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)\n ) {\n this.props.innerRef.current = ref\n } else if (this.props.innerRef) {\n this.props.innerRef(ref)\n }\n\n if (this.state.IOSupported && ref) {\n // If IO supported and element reference found, setup Observer functionality\n this.io = createIntersectionObserver(ref, inViewPort => {\n if (inViewPort) {\n this.abortPrefetch = this._prefetch()\n } else {\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n }\n })\n }\n }\n\n defaultGetProps = ({ isPartiallyCurrent, isCurrent }) => {\n if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {\n return {\n className: [this.props.className, this.props.activeClassName]\n .filter(Boolean)\n .join(` `),\n style: { ...this.props.style, ...this.props.activeStyle },\n }\n }\n return null\n }\n\n render() {\n const {\n to,\n getProps = this.defaultGetProps,\n onClick,\n onMouseEnter,\n /* eslint-disable no-unused-vars */\n activeClassName: $activeClassName,\n activeStyle: $activeStyle,\n innerRef: $innerRef,\n partiallyActive,\n state,\n replace,\n _location,\n /* eslint-enable no-unused-vars */\n ...rest\n } = this.props\n\n if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {\n console.warn(\n `External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`\n )\n }\n\n const prefixedTo = rewriteLinkPath(to, _location.pathname)\n if (!isLocalLink(prefixedTo)) {\n return <a href={prefixedTo} {...rest} />\n }\n\n return (\n <Link\n to={prefixedTo}\n state={state}\n getProps={getProps}\n innerRef={this.handleRef}\n onMouseEnter={e => {\n if (onMouseEnter) {\n onMouseEnter(e)\n }\n const parsed = parsePath(prefixedTo)\n ___loader.hovering(parsed.pathname + parsed.search)\n }}\n onClick={e => {\n if (onClick) {\n onClick(e)\n }\n\n if (\n e.button === 0 && // ignore right clicks\n !this.props.target && // let browser handle \"target=_blank\"\n !e.defaultPrevented && // onClick prevented default\n !e.metaKey && // ignore clicks with modifier keys...\n !e.altKey &&\n !e.ctrlKey &&\n !e.shiftKey\n ) {\n e.preventDefault()\n\n let shouldReplace = replace\n const isCurrent = encodeURI(prefixedTo) === _location.pathname\n\n if (typeof replace !== `boolean` && isCurrent) {\n shouldReplace = true\n }\n // Make sure the necessary scripts and data are\n // loaded before continuing.\n window.___navigate(prefixedTo, {\n state,\n replace: shouldReplace,\n })\n }\n\n return true\n }}\n {...rest}\n />\n )\n }\n}\n\nGatsbyLink.propTypes = {\n ...NavLinkPropTypes,\n onClick: PropTypes.func,\n to: PropTypes.string.isRequired,\n replace: PropTypes.bool,\n state: PropTypes.object,\n}\n\nexport default React.forwardRef((props, ref) => (\n <GatsbyLinkLocationWrapper innerRef={ref} {...props} />\n))\n\nexport const navigate = (to, options) => {\n window.___navigate(rewriteLinkPath(to, window.location.pathname), options)\n}\n"],"names":["path","pathname","indexOf","hashIndex","hash","slice","searchIndex","search","test","isAbsolute","env","NODE_ENV","__PATH_PREFIX__","undefined","prefix","__BASE_PATH__","isLocalLink","startsWith","getGlobalPathPrefix","base","endsWith","__TRAILING_SLASH__","relativeTo","parsePath","getGlobalTrailingSlash","option","adjustedPath","applyTrailingSlashOption","withPrefix","current","isAbsolutePath","resolve","absolutePath","absolutify","activeClassName","PropTypes","string","activeStyle","object","partiallyActive","bool","props","React","Location","GatsbyLink","_location","location","_this","defaultGetProps","isPartiallyCurrent","isCurrent","className","filter","Boolean","join","style","window","IntersectionObserver","IOSupported","state","abortPrefetch","handleRef","bind","_prefetch","this","currentPath","rewriteLinkPath","to","parsed","newPathName","enqueue","componentWillUnmount","io","instance","el","abort","unobserve","disconnect","ref","cb","innerRef","Object","prototype","hasOwnProperty","call","inViewPort","_this2","entries","forEach","entry","target","isIntersecting","intersectionRatio","observe","render","getProps","onClick","onMouseEnter","replace","rest","process","console","warn","prefixedTo","Link","e","___loader","hovering","button","_this3","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","preventDefault","encodeURI","shouldReplace","___navigate","href","Component","propTypes","NavLinkPropTypes","func","isRequired","forwardRef","GatsbyLinkLocationWrapper","options"],"mappings":"wmBAA0BA,GACxB,MAAeA,mBAIGC,EAASC,cACR,IAAfC,IACFC,EAAOH,EAASI,MAAMF,GACtBF,EAAWA,EAASI,MAAM,EAAGF,IAG/B,MAAoBF,EAASC,aAM7B,OALqB,IAAjBI,IACFC,EAASN,EAASI,MAAMC,GACxBL,EAAWA,EAASI,MAAM,EAAGC,IAGxB,CACLL,SAAUA,EACVM,aAAQA,KAAsBA,EAC9BH,WAAMA,KAAoBA,GCnB9B,MAA2B,+BAGA,SAAAJ,GACzB,sBAMA,OATiB,SAAAA,YAA2BQ,KAAKR,GASzCS,CAAWT,MCAc,wCACzBU,IAAIC,6CAENC,qBACAC,EACFD,4BAEqBZ,EAAMc,WAC/B,YAD+BA,IAAAA,yBAfvBJ,IAAIC,2CAENI,mBACAF,EACFE,gBAYCC,EAAYhB,GACf,SAGF,GAAIA,EAAKiB,kBAAoBjB,EAAKiB,kBAChC,SAEF,wBAAaH,KAAUI,WAEvB,gBAAUC,GAAAA,EAAMC,cAAgBD,EAAKd,MAAM,GAAI,GAAKc,IAClDnB,EAAKiB,gBAAkBjB,MAAWA,GCtBtC,MAAuB,SAAAA,yBAAQA,EAAMiB,mBAEN,wDACeI,wBAAqBR,KAkBpC,SAACb,EAAMsB,GACpC,sBACE,SAEF,IAAKN,EAAYhB,GACf,SAGF,MAAmCuB,EAAUvB,GAArCC,IAAAA,SAAUM,IAAAA,OAAQH,IAAAA,OACXoB,MACIxB,EAOnB,iBALIyB,aAAuBA,IAEzBC,KADeC,2BAAyB1B,EAAUwB,GACvBlB,EAASH,KAGhBsB,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B,IACFkB,UAAUb,KAAgB1D,EAAU5C,8BAElBiD,IAClCmE,GAAgB,GAIlB7D,OAAO8D,YAAYf,EAAY,CAC7B5C,MAAAA,EACAuC,QAASmB,IAIb,WAEElB,iBAhDCzD,+BAAG6E,KAAMhB,GAAgBJ,QAlHbzD,UAAM8E,WAwK/B5E,EAAW6E,eACNC,GACH1B,QAAS7D,UAAUwF,KACnBxD,GAAIhC,UAAUC,OAAOwF,WACrB1B,QAAS/D,UAAUK,KACnBmB,MAAOxB,UAAUG,SAGnB,gBAAqBuF,WAAW,SAACpF,EAAOqC,uBACtCpC,wBAACoF,KAA0B9C,SAAUF,GAASrC,yCAGxB,SAAC0B,EAAI4D,GAC3BvE,OAAO8D,YAAYpD,EAAgBC,EAAIX,OAAOV,SAAS7C,UAAW8H,yDAzNpC/H,GAC9B,SAAkBA,EAAMkB"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/parse-path.js","../src/is-local-link.js","../src/prefix-helpers.js","../src/rewrite-link-path.js","../src/index.js"],"sourcesContent":["export function parsePath(path) {\n let pathname = path || `/`\n let search = ``\n let hash = ``\n\n const hashIndex = pathname.indexOf(`#`)\n if (hashIndex !== -1) {\n hash = pathname.slice(hashIndex)\n pathname = pathname.slice(0, hashIndex)\n }\n\n const searchIndex = pathname.indexOf(`?`)\n if (searchIndex !== -1) {\n search = pathname.slice(searchIndex)\n pathname = pathname.slice(0, searchIndex)\n }\n\n return {\n pathname: pathname,\n search: search === `?` ? `` : search,\n hash: hash === `#` ? `` : hash,\n }\n}\n","// Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js\nconst ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\\d+\\-.]*?:/\nconst isAbsolute = path => ABSOLUTE_URL_REGEX.test(path)\n\nexport const isLocalLink = path => {\n if (typeof path !== `string`) {\n return undefined\n // TODO(v5): Re-Add TypeError\n // throw new TypeError(`Expected a \\`string\\`, got \\`${typeof path}\\``)\n }\n\n return !isAbsolute(path)\n}\n","import { isLocalLink } from \"./is-local-link\"\n\nexport const getGlobalBasePrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __BASE_PATH__ !== `undefined`\n ? __BASE_PATH__\n : undefined\n : __BASE_PATH__\n\n// These global values are wrapped in typeof clauses to ensure the values exist.\n// This is especially problematic in unit testing of this component.\nexport const getGlobalPathPrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __PATH_PREFIX__ !== `undefined`\n ? __PATH_PREFIX__\n : undefined\n : __PATH_PREFIX__\n\nexport function withPrefix(path, prefix = getGlobalBasePrefix()) {\n if (!isLocalLink(path)) {\n return path\n }\n\n if (path.startsWith(`./`) || path.startsWith(`../`)) {\n return path\n }\n const base = prefix ?? getGlobalPathPrefix() ?? `/`\n\n return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${\n path.startsWith(`/`) ? path : `/${path}`\n }`\n}\n","import { resolve } from \"@gatsbyjs/reach-router\"\n// Specific import to treeshake Node.js stuff\nimport { applyTrailingSlashOption } from \"gatsby-page-utils/apply-trailing-slash-option\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { withPrefix } from \"./prefix-helpers\"\n\nconst isAbsolutePath = path => path?.startsWith(`/`)\n\nconst getGlobalTrailingSlash = () =>\n typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined\n\nfunction absolutify(path, current) {\n // If it's already absolute, return as-is\n if (isAbsolutePath(path)) {\n return path\n }\n\n const option = getGlobalTrailingSlash()\n const absolutePath = resolve(path, current)\n\n if (option === `always` || option === `never`) {\n return applyTrailingSlashOption(absolutePath, option)\n }\n\n return absolutePath\n}\n\nexport const rewriteLinkPath = (path, relativeTo) => {\n if (typeof path === `number`) {\n return path\n }\n if (!isLocalLink(path)) {\n return path\n }\n\n const { pathname, search, hash } = parsePath(path)\n const option = getGlobalTrailingSlash()\n let adjustedPath = path\n\n if (option === `always` || option === `never`) {\n const output = applyTrailingSlashOption(pathname, option)\n adjustedPath = `${output}${search}${hash}`\n }\n\n return isAbsolutePath(adjustedPath)\n ? withPrefix(adjustedPath)\n : absolutify(adjustedPath, relativeTo)\n}\n","import PropTypes from \"prop-types\"\nimport React from \"react\"\nimport { Link, Location } from \"@gatsbyjs/reach-router\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { rewriteLinkPath } from \"./rewrite-link-path\"\nimport { withPrefix, getGlobalPathPrefix } from \"./prefix-helpers\"\n\nexport { parsePath, withPrefix }\n\nexport function withAssetPrefix(path) {\n return withPrefix(path, getGlobalPathPrefix())\n}\n\nconst NavLinkPropTypes = {\n activeClassName: PropTypes.string,\n activeStyle: PropTypes.object,\n partiallyActive: PropTypes.bool,\n}\n\n// Set up IntersectionObserver\nconst createIntersectionObserver = (el, cb) => {\n const io = new window.IntersectionObserver(entries => {\n entries.forEach(entry => {\n if (el === entry.target) {\n // Check if element is within viewport, remove listener, destroy observer, and run link callback.\n // MSEdge doesn't currently support isIntersecting, so also test for an intersectionRatio > 0\n cb(entry.isIntersecting || entry.intersectionRatio > 0)\n }\n })\n })\n\n // Add element to the observer\n io.observe(el)\n\n return { instance: io, el }\n}\n\nfunction GatsbyLinkLocationWrapper(props) {\n return (\n <Location>\n {({ location }) => <GatsbyLink {...props} _location={location} />}\n </Location>\n )\n}\n\nclass GatsbyLink extends React.Component {\n constructor(props) {\n super(props)\n // Default to no support for IntersectionObserver\n let IOSupported = false\n if (typeof window !== `undefined` && window.IntersectionObserver) {\n IOSupported = true\n }\n\n this.state = {\n IOSupported,\n }\n this.abortPrefetch = null\n this.handleRef = this.handleRef.bind(this)\n }\n\n _prefetch() {\n let currentPath = window.location.pathname + window.location.search\n\n // reach router should have the correct state\n if (this.props._location && this.props._location.pathname) {\n currentPath = this.props._location.pathname + this.props._location.search\n }\n\n const rewrittenPath = rewriteLinkPath(this.props.to, currentPath)\n const parsed = parsePath(rewrittenPath)\n\n const newPathName = parsed.pathname + parsed.search\n\n // Prefetch is used to speed up next navigations. When you use it on the current navigation,\n // there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete\n if (currentPath !== newPathName) {\n return ___loader.enqueue(newPathName)\n }\n\n return undefined\n }\n\n componentWillUnmount() {\n if (!this.io) {\n return\n }\n const { instance, el } = this.io\n\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n\n instance.unobserve(el)\n instance.disconnect()\n }\n\n handleRef(ref) {\n if (\n this.props.innerRef &&\n Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)\n ) {\n this.props.innerRef.current = ref\n } else if (this.props.innerRef) {\n this.props.innerRef(ref)\n }\n\n if (this.state.IOSupported && ref) {\n // If IO supported and element reference found, setup Observer functionality\n this.io = createIntersectionObserver(ref, inViewPort => {\n if (inViewPort) {\n this.abortPrefetch = this._prefetch()\n } else {\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n }\n })\n }\n }\n\n defaultGetProps = ({ isPartiallyCurrent, isCurrent }) => {\n if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {\n return {\n className: [this.props.className, this.props.activeClassName]\n .filter(Boolean)\n .join(` `),\n style: { ...this.props.style, ...this.props.activeStyle },\n }\n }\n return null\n }\n\n render() {\n const {\n to,\n getProps = this.defaultGetProps,\n onClick,\n onMouseEnter,\n /* eslint-disable no-unused-vars */\n activeClassName: $activeClassName,\n activeStyle: $activeStyle,\n innerRef: $innerRef,\n partiallyActive,\n state,\n replace,\n _location,\n /* eslint-enable no-unused-vars */\n ...rest\n } = this.props\n\n if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {\n console.warn(\n `External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`\n )\n }\n\n const prefixedTo = rewriteLinkPath(to, _location.pathname)\n if (!isLocalLink(prefixedTo)) {\n return <a href={prefixedTo} {...rest} />\n }\n\n return (\n <Link\n to={prefixedTo}\n state={state}\n getProps={getProps}\n innerRef={this.handleRef}\n onMouseEnter={e => {\n if (onMouseEnter) {\n onMouseEnter(e)\n }\n const parsed = parsePath(prefixedTo)\n ___loader.hovering(parsed.pathname + parsed.search)\n }}\n onClick={e => {\n if (onClick) {\n onClick(e)\n }\n\n if (\n e.button === 0 && // ignore right clicks\n !this.props.target && // let browser handle \"target=_blank\"\n !e.defaultPrevented && // onClick prevented default\n !e.metaKey && // ignore clicks with modifier keys...\n !e.altKey &&\n !e.ctrlKey &&\n !e.shiftKey\n ) {\n e.preventDefault()\n\n let shouldReplace = replace\n const isCurrent = encodeURI(prefixedTo) === _location.pathname\n\n if (typeof replace !== `boolean` && isCurrent) {\n shouldReplace = true\n }\n // Make sure the necessary scripts and data are\n // loaded before continuing.\n window.___navigate(prefixedTo, {\n state,\n replace: shouldReplace,\n })\n }\n\n return true\n }}\n {...rest}\n />\n )\n }\n}\n\nGatsbyLink.propTypes = {\n ...NavLinkPropTypes,\n onClick: PropTypes.func,\n to: PropTypes.string.isRequired,\n replace: PropTypes.bool,\n state: PropTypes.object,\n}\n\nexport default React.forwardRef((props, ref) => (\n <GatsbyLinkLocationWrapper innerRef={ref} {...props} />\n))\n\nexport const navigate = (to, options) => {\n window.___navigate(rewriteLinkPath(to, window.location.pathname), options)\n}\n"],"names":["path","pathname","indexOf","hashIndex","hash","slice","searchIndex","search","test","isAbsolute","env","NODE_ENV","__PATH_PREFIX__","undefined","prefix","__BASE_PATH__","isLocalLink","startsWith","getGlobalPathPrefix","base","endsWith","__TRAILING_SLASH__","relativeTo","parsePath","getGlobalTrailingSlash","option","adjustedPath","applyTrailingSlashOption","withPrefix","current","isAbsolutePath","resolve","absolutePath","absolutify","activeClassName","PropTypes","string","activeStyle","object","partiallyActive","bool","props","React","Location","GatsbyLink","_location","location","_this","defaultGetProps","isPartiallyCurrent","isCurrent","className","filter","Boolean","join","style","window","IntersectionObserver","IOSupported","state","abortPrefetch","handleRef","bind","_prefetch","this","currentPath","rewriteLinkPath","to","parsed","newPathName","enqueue","componentWillUnmount","io","instance","el","abort","unobserve","disconnect","ref","cb","innerRef","Object","prototype","hasOwnProperty","call","inViewPort","_this2","entries","forEach","entry","target","isIntersecting","intersectionRatio","observe","render","getProps","onClick","onMouseEnter","replace","rest","process","console","warn","prefixedTo","Link","e","___loader","hovering","button","_this3","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","preventDefault","encodeURI","shouldReplace","___navigate","href","Component","propTypes","NavLinkPropTypes","func","isRequired","forwardRef","GatsbyLinkLocationWrapper","options"],"mappings":"0jBAA0BA,GACxB,MAAeA,mBAIGC,EAASC,cACR,IAAfC,IACFC,EAAOH,EAASI,MAAMF,GACtBF,EAAWA,EAASI,MAAM,EAAGF,IAG/B,MAAoBF,EAASC,aAM7B,OALqB,IAAjBI,IACFC,EAASN,EAASI,MAAMC,GACxBL,EAAWA,EAASI,MAAM,EAAGC,IAGxB,CACLL,SAAUA,EACVM,aAAQA,KAAsBA,EAC9BH,WAAMA,KAAoBA,GCnB9B,MAA2B,+BAGA,SAAAJ,GACzB,sBAMA,OATiB,SAAAA,YAA2BQ,KAAKR,GASzCS,CAAWT,MCAc,wCACzBU,IAAIC,6CAENC,qBACAC,EACFD,4BAEqBZ,EAAMc,WAC/B,YAD+BA,IAAAA,yBAfvBJ,IAAIC,2CAENI,mBACAF,EACFE,gBAYCC,EAAYhB,GACf,SAGF,GAAIA,EAAKiB,kBAAoBjB,EAAKiB,kBAChC,SAEF,wBAAaH,KAAUI,WAEvB,gBAAUC,GAAAA,EAAMC,cAAgBD,EAAKd,MAAM,GAAI,GAAKc,IAClDnB,EAAKiB,gBAAkBjB,MAAWA,GCtBtC,MAAuB,SAAAA,yBAAQA,EAAMiB,mBAEN,wDACeI,wBAAqBR,KAkBpC,SAACb,EAAMsB,GACpC,sBACE,SAEF,IAAKN,EAAYhB,GACf,SAGF,MAAmCuB,EAAUvB,GAArCC,IAAAA,SAAUM,IAAAA,OAAQH,IAAAA,OACXoB,MACIxB,EAOnB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EM,SACFN,EAAEO,QACFP,EAAEQ,SACFR,EAAES,UACH,CACAT,EAAEU,iBAEF,MAAoBjB,IACFkB,UAAUb,KAAgB1D,EAAU5C,8BAElBiD,IAClCmE,GAAgB,GAIlB7D,OAAO8D,YAAYf,EAAY,CAC7B5C,MAAAA,EACAuC,QAASmB,IAIb,WAEElB,iBAhDCzD,+BAAG6E,KAAMhB,GAAgBJ,QAlHbzD,UAAM8E,WAwK/B5E,EAAW6E,eACNC,GACH1B,QAAS7D,UAAUwF,KACnBxD,GAAIhC,UAAUC,OAAOwF,WACrB1B,QAAS/D,UAAUK,KACnBmB,MAAOxB,UAAUG,SAGnB,gBAAqBuF,WAAW,SAACpF,EAAOqC,uBACtCpC,wBAACoF,KAA0B9C,SAAUF,GAASrC,yCAGxB,SAAC0B,EAAI4D,GAC3BvE,OAAO8D,YAAYpD,EAAgBC,EAAIX,OAAOV,SAAS7C,UAAW8H,yDAzNpC/H,GAC9B,SAAkBA,EAAMkB"}
|
package/dist/index.modern.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"prop-types";import e from"react";import{
|
|
1
|
+
import t from"prop-types";import e from"react";import{resolve as n,Location as r,Link as o}from"@gatsbyjs/reach-router";import{applyTrailingSlashOption as s}from"gatsby-page-utils/apply-trailing-slash-option";function i(){return i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function a(t){let e=t||"/",n="",r="";const o=e.indexOf("#");-1!==o&&(r=e.slice(o),e=e.slice(0,o));const s=e.indexOf("?");return-1!==s&&(n=e.slice(s),e=e.slice(0,s)),{pathname:e,search:"?"===n?"":n,hash:"#"===r?"":r}}const c=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,l=t=>{if("string"==typeof t)return!(t=>c.test(t))(t)},p=()=>"production"!==process.env.NODE_ENV?"undefined"!=typeof __PATH_PREFIX__?__PATH_PREFIX__:void 0:__PATH_PREFIX__;function h(t,e=(()=>"production"!==process.env.NODE_ENV?"undefined"!=typeof __BASE_PATH__?__BASE_PATH__:void 0:__BASE_PATH__)()){var n;if(!l(t))return t;if(t.startsWith("./")||t.startsWith("../"))return t;const r=null!=(n=null!=e?e:p())?n:"/";return`${null!=r&&r.endsWith("/")?r.slice(0,-1):r}${t.startsWith("/")?t:`/${t}`}`}const f=t=>null==t?void 0:t.startsWith("/"),u=()=>"undefined"!=typeof __TRAILING_SLASH__?__TRAILING_SLASH__:void 0,_=(t,e)=>{if("number"==typeof t)return t;if(!l(t))return t;const{pathname:r,search:o,hash:i}=a(t),c=u();let p=t;return"always"!==c&&"never"!==c||(p=`${s(r,c)}${o}${i}`),f(p)?h(p):function(t,e){if(f(t))return t;const r=u(),o=n(t,e);return"always"===r||"never"===r?s(o,r):o}(p,e)},d=["to","getProps","onClick","onMouseEnter","activeClassName","activeStyle","innerRef","partiallyActive","state","replace","_location"];function m(t){return h(t,p())}const y={activeClassName:t.string,activeStyle:t.object,partiallyActive:t.bool};function v(t){/*#__PURE__*/return e.createElement(r,null,({location:n})=>/*#__PURE__*/e.createElement(b,i({},t,{_location:n})))}class b extends e.Component{constructor(t){super(t),this.defaultGetProps=({isPartiallyCurrent:t,isCurrent:e})=>(this.props.partiallyActive?t:e)?{className:[this.props.className,this.props.activeClassName].filter(Boolean).join(" "),style:i({},this.props.style,this.props.activeStyle)}:null;let e=!1;"undefined"!=typeof window&&window.IntersectionObserver&&(e=!0),this.state={IOSupported:e},this.abortPrefetch=null,this.handleRef=this.handleRef.bind(this)}_prefetch(){let t=window.location.pathname+window.location.search;this.props._location&&this.props._location.pathname&&(t=this.props._location.pathname+this.props._location.search);const e=a(_(this.props.to,t)),n=e.pathname+e.search;if(t!==n)return ___loader.enqueue(n)}componentWillUnmount(){if(!this.io)return;const{instance:t,el:e}=this.io;this.abortPrefetch&&this.abortPrefetch.abort(),t.unobserve(e),t.disconnect()}handleRef(t){this.props.innerRef&&Object.prototype.hasOwnProperty.call(this.props.innerRef,"current")?this.props.innerRef.current=t:this.props.innerRef&&this.props.innerRef(t),this.state.IOSupported&&t&&(this.io=((t,e)=>{const n=new window.IntersectionObserver(n=>{n.forEach(n=>{t===n.target&&e(n.isIntersecting||n.intersectionRatio>0)})});return n.observe(t),{instance:n,el:t}})(t,t=>{t?this.abortPrefetch=this._prefetch():this.abortPrefetch&&this.abortPrefetch.abort()}))}render(){const t=this.props,{to:n,getProps:r=this.defaultGetProps,onClick:s,onMouseEnter:c,state:p,replace:h,_location:f}=t,u=function(t,e){if(null==t)return{};var n,r,o={},s=Object.keys(t);for(r=0;r<s.length;r++)e.indexOf(n=s[r])>=0||(o[n]=t[n]);return o}(t,d);"production"===process.env.NODE_ENV||l(n)||console.warn(`External link ${n} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`);const m=_(n,f.pathname);return l(m)?/*#__PURE__*/e.createElement(o,i({to:m,state:p,getProps:r,innerRef:this.handleRef,onMouseEnter:t=>{c&&c(t);const e=a(m);___loader.hovering(e.pathname+e.search)},onClick:t=>{if(s&&s(t),!(0!==t.button||this.props.target||t.defaultPrevented||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)){t.preventDefault();let e=h;const n=encodeURI(m)===f.pathname;"boolean"!=typeof h&&n&&(e=!0),window.___navigate(m,{state:p,replace:e})}return!0}},u)):/*#__PURE__*/e.createElement("a",i({href:m},u))}}b.propTypes=i({},y,{onClick:t.func,to:t.string.isRequired,replace:t.bool,state:t.object});var w=e.forwardRef((t,n)=>/*#__PURE__*/e.createElement(v,i({innerRef:n},t)));const P=(t,e)=>{window.___navigate(_(t,window.location.pathname),e)};export{w as default,P as navigate,a as parsePath,m as withAssetPrefix,h as withPrefix};
|
|
2
2
|
//# sourceMappingURL=index.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.mjs","sources":["../src/parse-path.js","../src/is-local-link.js","../src/prefix-helpers.js","../src/rewrite-link-path.js","../src/index.js"],"sourcesContent":["export function parsePath(path) {\n let pathname = path || `/`\n let search = ``\n let hash = ``\n\n const hashIndex = pathname.indexOf(`#`)\n if (hashIndex !== -1) {\n hash = pathname.slice(hashIndex)\n pathname = pathname.slice(0, hashIndex)\n }\n\n const searchIndex = pathname.indexOf(`?`)\n if (searchIndex !== -1) {\n search = pathname.slice(searchIndex)\n pathname = pathname.slice(0, searchIndex)\n }\n\n return {\n pathname: pathname,\n search: search === `?` ? `` : search,\n hash: hash === `#` ? `` : hash,\n }\n}\n","// Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js\nconst ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\\d+\\-.]*?:/\nconst isAbsolute = path => ABSOLUTE_URL_REGEX.test(path)\n\nexport const isLocalLink = path => {\n if (typeof path !== `string`) {\n return undefined\n // TODO(v5): Re-Add TypeError\n // throw new TypeError(`Expected a \\`string\\`, got \\`${typeof path}\\``)\n }\n\n return !isAbsolute(path)\n}\n","import { isLocalLink } from \"./is-local-link\"\n\nexport const getGlobalBasePrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __BASE_PATH__ !== `undefined`\n ? __BASE_PATH__\n : undefined\n : __BASE_PATH__\n\n// These global values are wrapped in typeof clauses to ensure the values exist.\n// This is especially problematic in unit testing of this component.\nexport const getGlobalPathPrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __PATH_PREFIX__ !== `undefined`\n ? __PATH_PREFIX__\n : undefined\n : __PATH_PREFIX__\n\nexport function withPrefix(path, prefix = getGlobalBasePrefix()) {\n if (!isLocalLink(path)) {\n return path\n }\n\n if (path.startsWith(`./`) || path.startsWith(`../`)) {\n return path\n }\n const base = prefix ?? getGlobalPathPrefix() ?? `/`\n\n return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${\n path.startsWith(`/`) ? path : `/${path}`\n }`\n}\n","import { resolve } from \"@gatsbyjs/reach-router/lib/utils\"\n// Specific import to treeshake Node.js stuff\nimport { applyTrailingSlashOption } from \"gatsby-page-utils/apply-trailing-slash-option\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { withPrefix } from \"./prefix-helpers\"\n\nconst isAbsolutePath = path => path?.startsWith(`/`)\n\nconst getGlobalTrailingSlash = () =>\n typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined\n\nfunction absolutify(path, current) {\n // If it's already absolute, return as-is\n if (isAbsolutePath(path)) {\n return path\n }\n\n const option = getGlobalTrailingSlash()\n const absolutePath = resolve(path, current)\n\n if (option === `always` || option === `never`) {\n return applyTrailingSlashOption(absolutePath, option)\n }\n\n return absolutePath\n}\n\nexport const rewriteLinkPath = (path, relativeTo) => {\n if (typeof path === `number`) {\n return path\n }\n if (!isLocalLink(path)) {\n return path\n }\n\n const { pathname, search, hash } = parsePath(path)\n const option = getGlobalTrailingSlash()\n let adjustedPath = path\n\n if (option === `always` || option === `never`) {\n const output = applyTrailingSlashOption(pathname, option)\n adjustedPath = `${output}${search}${hash}`\n }\n\n return isAbsolutePath(adjustedPath)\n ? withPrefix(adjustedPath)\n : absolutify(adjustedPath, relativeTo)\n}\n","import PropTypes from \"prop-types\"\nimport React from \"react\"\nimport { Link, Location } from \"@gatsbyjs/reach-router\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { rewriteLinkPath } from \"./rewrite-link-path\"\nimport { withPrefix, getGlobalPathPrefix } from \"./prefix-helpers\"\n\nexport { parsePath, withPrefix }\n\nexport function withAssetPrefix(path) {\n return withPrefix(path, getGlobalPathPrefix())\n}\n\nconst NavLinkPropTypes = {\n activeClassName: PropTypes.string,\n activeStyle: PropTypes.object,\n partiallyActive: PropTypes.bool,\n}\n\n// Set up IntersectionObserver\nconst createIntersectionObserver = (el, cb) => {\n const io = new window.IntersectionObserver(entries => {\n entries.forEach(entry => {\n if (el === entry.target) {\n // Check if element is within viewport, remove listener, destroy observer, and run link callback.\n // MSEdge doesn't currently support isIntersecting, so also test for an intersectionRatio > 0\n cb(entry.isIntersecting || entry.intersectionRatio > 0)\n }\n })\n })\n\n // Add element to the observer\n io.observe(el)\n\n return { instance: io, el }\n}\n\nfunction GatsbyLinkLocationWrapper(props) {\n return (\n <Location>\n {({ location }) => <GatsbyLink {...props} _location={location} />}\n </Location>\n )\n}\n\nclass GatsbyLink extends React.Component {\n constructor(props) {\n super(props)\n // Default to no support for IntersectionObserver\n let IOSupported = false\n if (typeof window !== `undefined` && window.IntersectionObserver) {\n IOSupported = true\n }\n\n this.state = {\n IOSupported,\n }\n this.abortPrefetch = null\n this.handleRef = this.handleRef.bind(this)\n }\n\n _prefetch() {\n let currentPath = window.location.pathname + window.location.search\n\n // reach router should have the correct state\n if (this.props._location && this.props._location.pathname) {\n currentPath = this.props._location.pathname + this.props._location.search\n }\n\n const rewrittenPath = rewriteLinkPath(this.props.to, currentPath)\n const parsed = parsePath(rewrittenPath)\n\n const newPathName = parsed.pathname + parsed.search\n\n // Prefetch is used to speed up next navigations. When you use it on the current navigation,\n // there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete\n if (currentPath !== newPathName) {\n return ___loader.enqueue(newPathName)\n }\n\n return undefined\n }\n\n componentWillUnmount() {\n if (!this.io) {\n return\n }\n const { instance, el } = this.io\n\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n\n instance.unobserve(el)\n instance.disconnect()\n }\n\n handleRef(ref) {\n if (\n this.props.innerRef &&\n Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)\n ) {\n this.props.innerRef.current = ref\n } else if (this.props.innerRef) {\n this.props.innerRef(ref)\n }\n\n if (this.state.IOSupported && ref) {\n // If IO supported and element reference found, setup Observer functionality\n this.io = createIntersectionObserver(ref, inViewPort => {\n if (inViewPort) {\n this.abortPrefetch = this._prefetch()\n } else {\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n }\n })\n }\n }\n\n defaultGetProps = ({ isPartiallyCurrent, isCurrent }) => {\n if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {\n return {\n className: [this.props.className, this.props.activeClassName]\n .filter(Boolean)\n .join(` `),\n style: { ...this.props.style, ...this.props.activeStyle },\n }\n }\n return null\n }\n\n render() {\n const {\n to,\n getProps = this.defaultGetProps,\n onClick,\n onMouseEnter,\n /* eslint-disable no-unused-vars */\n activeClassName: $activeClassName,\n activeStyle: $activeStyle,\n innerRef: $innerRef,\n partiallyActive,\n state,\n replace,\n _location,\n /* eslint-enable no-unused-vars */\n ...rest\n } = this.props\n\n if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {\n console.warn(\n `External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`\n )\n }\n\n const prefixedTo = rewriteLinkPath(to, _location.pathname)\n if (!isLocalLink(prefixedTo)) {\n return <a href={prefixedTo} {...rest} />\n }\n\n return (\n <Link\n to={prefixedTo}\n state={state}\n getProps={getProps}\n innerRef={this.handleRef}\n onMouseEnter={e => {\n if (onMouseEnter) {\n onMouseEnter(e)\n }\n const parsed = parsePath(prefixedTo)\n ___loader.hovering(parsed.pathname + parsed.search)\n }}\n onClick={e => {\n if (onClick) {\n onClick(e)\n }\n\n if (\n e.button === 0 && // ignore right clicks\n !this.props.target && // let browser handle \"target=_blank\"\n !e.defaultPrevented && // onClick prevented default\n !e.metaKey && // ignore clicks with modifier keys...\n !e.altKey &&\n !e.ctrlKey &&\n !e.shiftKey\n ) {\n e.preventDefault()\n\n let shouldReplace = replace\n const isCurrent = encodeURI(prefixedTo) === _location.pathname\n\n if (typeof replace !== `boolean` && isCurrent) {\n shouldReplace = true\n }\n // Make sure the necessary scripts and data are\n // loaded before continuing.\n window.___navigate(prefixedTo, {\n state,\n replace: shouldReplace,\n })\n }\n\n return true\n }}\n {...rest}\n />\n )\n }\n}\n\nGatsbyLink.propTypes = {\n ...NavLinkPropTypes,\n onClick: PropTypes.func,\n to: PropTypes.string.isRequired,\n replace: PropTypes.bool,\n state: PropTypes.object,\n}\n\nexport default React.forwardRef((props, ref) => (\n <GatsbyLinkLocationWrapper innerRef={ref} {...props} />\n))\n\nexport const navigate = (to, options) => {\n window.___navigate(rewriteLinkPath(to, window.location.pathname), options)\n}\n"],"names":["path","pathname","indexOf","hashIndex","hash","slice","searchIndex","search","ABSOLUTE_URL_REGEX","test","isAbsolute","process","env","NODE_ENV","__PATH_PREFIX__","undefined","prefix","__BASE_PATH__","getGlobalBasePrefix","isLocalLink","startsWith","getGlobalPathPrefix","base","endsWith","__TRAILING_SLASH__","relativeTo","parsePath","getGlobalTrailingSlash","option","adjustedPath","applyTrailingSlashOption","withPrefix","current","isAbsolutePath","resolve","absolutePath","absolutify","activeClassName","PropTypes","string","activeStyle","object","partiallyActive","bool","props","React","Location","location","GatsbyLink","_location","Component","constructor","super","this","defaultGetProps","isPartiallyCurrent","isCurrent","className","filter","Boolean","join","style","window","IntersectionObserver","IOSupported","state","abortPrefetch","handleRef","bind","_prefetch","currentPath","rewriteLinkPath","to","parsed","newPathName","enqueue","componentWillUnmount","io","instance","el","abort","unobserve","disconnect","ref","innerRef","Object","prototype","hasOwnProperty","call","cb","entries","forEach","entry","target","isIntersecting","intersectionRatio","observe","createIntersectionObserver","inViewPort","render","getProps","onClick","onMouseEnter","replace","rest","console","warn","prefixedTo","Link","e","___loader","hovering","button","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","preventDefault","encodeURI","shouldReplace","___navigate","href","propTypes","NavLinkPropTypes","func","isRequired","forwardRef","GatsbyLinkLocationWrapper","navigate","options"],"mappings":"0dAA0BA,GACxB,MAAeA,GAAS,MACV,KACF,GAEZ,QAAkBC,EAASC,QAAS,MACjB,IAAfC,IACFC,EAAOH,EAASI,MAAMF,GACtBF,EAAWA,EAASI,MAAM,EAAGF,IAG/B,QAAoBF,EAASC,QAAS,KAMtC,OALqB,IAAjBI,IACFC,EAASN,EAASI,MAAMC,GAC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AMf,GAAgBH,KAsDtCxD,EAAW2E,eACNC,GACHvB,QAAS/D,EAAUuF,KACnBrD,GAAIlC,EAAUC,OAAOuF,WACrBvB,QAASjE,EAAUK,KACnBsB,MAAO3B,EAAUG,SAGnB,QAAqBsF,WAAW,CAACnF,EAAOuC,iBACtCtC,gBAACmF,KAA0B5C,SAAUD,GAASvC,KAGnCqF,QAAW,CAACzD,EAAI0D,KAC3BpE,OAAO2D,YAAYlD,EAAgBC,EAAIV,OAAOf,SAAS9C,UAAWiI"}
|
|
1
|
+
{"version":3,"file":"index.modern.mjs","sources":["../src/parse-path.js","../src/is-local-link.js","../src/prefix-helpers.js","../src/rewrite-link-path.js","../src/index.js"],"sourcesContent":["export function parsePath(path) {\n let pathname = path || `/`\n let search = ``\n let hash = ``\n\n const hashIndex = pathname.indexOf(`#`)\n if (hashIndex !== -1) {\n hash = pathname.slice(hashIndex)\n pathname = pathname.slice(0, hashIndex)\n }\n\n const searchIndex = pathname.indexOf(`?`)\n if (searchIndex !== -1) {\n search = pathname.slice(searchIndex)\n pathname = pathname.slice(0, searchIndex)\n }\n\n return {\n pathname: pathname,\n search: search === `?` ? `` : search,\n hash: hash === `#` ? `` : hash,\n }\n}\n","// Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js\nconst ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\\d+\\-.]*?:/\nconst isAbsolute = path => ABSOLUTE_URL_REGEX.test(path)\n\nexport const isLocalLink = path => {\n if (typeof path !== `string`) {\n return undefined\n // TODO(v5): Re-Add TypeError\n // throw new TypeError(`Expected a \\`string\\`, got \\`${typeof path}\\``)\n }\n\n return !isAbsolute(path)\n}\n","import { isLocalLink } from \"./is-local-link\"\n\nexport const getGlobalBasePrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __BASE_PATH__ !== `undefined`\n ? __BASE_PATH__\n : undefined\n : __BASE_PATH__\n\n// These global values are wrapped in typeof clauses to ensure the values exist.\n// This is especially problematic in unit testing of this component.\nexport const getGlobalPathPrefix = () =>\n process.env.NODE_ENV !== `production`\n ? typeof __PATH_PREFIX__ !== `undefined`\n ? __PATH_PREFIX__\n : undefined\n : __PATH_PREFIX__\n\nexport function withPrefix(path, prefix = getGlobalBasePrefix()) {\n if (!isLocalLink(path)) {\n return path\n }\n\n if (path.startsWith(`./`) || path.startsWith(`../`)) {\n return path\n }\n const base = prefix ?? getGlobalPathPrefix() ?? `/`\n\n return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${\n path.startsWith(`/`) ? path : `/${path}`\n }`\n}\n","import { resolve } from \"@gatsbyjs/reach-router\"\n// Specific import to treeshake Node.js stuff\nimport { applyTrailingSlashOption } from \"gatsby-page-utils/apply-trailing-slash-option\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { withPrefix } from \"./prefix-helpers\"\n\nconst isAbsolutePath = path => path?.startsWith(`/`)\n\nconst getGlobalTrailingSlash = () =>\n typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined\n\nfunction absolutify(path, current) {\n // If it's already absolute, return as-is\n if (isAbsolutePath(path)) {\n return path\n }\n\n const option = getGlobalTrailingSlash()\n const absolutePath = resolve(path, current)\n\n if (option === `always` || option === `never`) {\n return applyTrailingSlashOption(absolutePath, option)\n }\n\n return absolutePath\n}\n\nexport const rewriteLinkPath = (path, relativeTo) => {\n if (typeof path === `number`) {\n return path\n }\n if (!isLocalLink(path)) {\n return path\n }\n\n const { pathname, search, hash } = parsePath(path)\n const option = getGlobalTrailingSlash()\n let adjustedPath = path\n\n if (option === `always` || option === `never`) {\n const output = applyTrailingSlashOption(pathname, option)\n adjustedPath = `${output}${search}${hash}`\n }\n\n return isAbsolutePath(adjustedPath)\n ? withPrefix(adjustedPath)\n : absolutify(adjustedPath, relativeTo)\n}\n","import PropTypes from \"prop-types\"\nimport React from \"react\"\nimport { Link, Location } from \"@gatsbyjs/reach-router\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { rewriteLinkPath } from \"./rewrite-link-path\"\nimport { withPrefix, getGlobalPathPrefix } from \"./prefix-helpers\"\n\nexport { parsePath, withPrefix }\n\nexport function withAssetPrefix(path) {\n return withPrefix(path, getGlobalPathPrefix())\n}\n\nconst NavLinkPropTypes = {\n activeClassName: PropTypes.string,\n activeStyle: PropTypes.object,\n partiallyActive: PropTypes.bool,\n}\n\n// Set up IntersectionObserver\nconst createIntersectionObserver = (el, cb) => {\n const io = new window.IntersectionObserver(entries => {\n entries.forEach(entry => {\n if (el === entry.target) {\n // Check if element is within viewport, remove listener, destroy observer, and run link callback.\n // MSEdge doesn't currently support isIntersecting, so also test for an intersectionRatio > 0\n cb(entry.isIntersecting || entry.intersectionRatio > 0)\n }\n })\n })\n\n // Add element to the observer\n io.observe(el)\n\n return { instance: io, el }\n}\n\nfunction GatsbyLinkLocationWrapper(props) {\n return (\n <Location>\n {({ location }) => <GatsbyLink {...props} _location={location} />}\n </Location>\n )\n}\n\nclass GatsbyLink extends React.Component {\n constructor(props) {\n super(props)\n // Default to no support for IntersectionObserver\n let IOSupported = false\n if (typeof window !== `undefined` && window.IntersectionObserver) {\n IOSupported = true\n }\n\n this.state = {\n IOSupported,\n }\n this.abortPrefetch = null\n this.handleRef = this.handleRef.bind(this)\n }\n\n _prefetch() {\n let currentPath = window.location.pathname + window.location.search\n\n // reach router should have the correct state\n if (this.props._location && this.props._location.pathname) {\n currentPath = this.props._location.pathname + this.props._location.search\n }\n\n const rewrittenPath = rewriteLinkPath(this.props.to, currentPath)\n const parsed = parsePath(rewrittenPath)\n\n const newPathName = parsed.pathname + parsed.search\n\n // Prefetch is used to speed up next navigations. When you use it on the current navigation,\n // there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete\n if (currentPath !== newPathName) {\n return ___loader.enqueue(newPathName)\n }\n\n return undefined\n }\n\n componentWillUnmount() {\n if (!this.io) {\n return\n }\n const { instance, el } = this.io\n\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n\n instance.unobserve(el)\n instance.disconnect()\n }\n\n handleRef(ref) {\n if (\n this.props.innerRef &&\n Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)\n ) {\n this.props.innerRef.current = ref\n } else if (this.props.innerRef) {\n this.props.innerRef(ref)\n }\n\n if (this.state.IOSupported && ref) {\n // If IO supported and element reference found, setup Observer functionality\n this.io = createIntersectionObserver(ref, inViewPort => {\n if (inViewPort) {\n this.abortPrefetch = this._prefetch()\n } else {\n if (this.abortPrefetch) {\n this.abortPrefetch.abort()\n }\n }\n })\n }\n }\n\n defaultGetProps = ({ isPartiallyCurrent, isCurrent }) => {\n if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {\n return {\n className: [this.props.className, this.props.activeClassName]\n .filter(Boolean)\n .join(` `),\n style: { ...this.props.style, ...this.props.activeStyle },\n }\n }\n return null\n }\n\n render() {\n const {\n to,\n getProps = this.defaultGetProps,\n onClick,\n onMouseEnter,\n /* eslint-disable no-unused-vars */\n activeClassName: $activeClassName,\n activeStyle: $activeStyle,\n innerRef: $innerRef,\n partiallyActive,\n state,\n replace,\n _location,\n /* eslint-enable no-unused-vars */\n ...rest\n } = this.props\n\n if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {\n console.warn(\n `External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`\n )\n }\n\n const prefixedTo = rewriteLinkPath(to, _location.pathname)\n if (!isLocalLink(prefixedTo)) {\n return <a href={prefixedTo} {...rest} />\n }\n\n return (\n <Link\n to={prefixedTo}\n state={state}\n getProps={getProps}\n innerRef={this.handleRef}\n onMouseEnter={e => {\n if (onMouseEnter) {\n onMouseEnter(e)\n }\n const parsed = parsePath(prefixedTo)\n ___loader.hovering(parsed.pathname + parsed.search)\n }}\n onClick={e => {\n if (onClick) {\n onClick(e)\n }\n\n if (\n e.button === 0 && // ignore right clicks\n !this.props.target && // let browser handle \"target=_blank\"\n !e.defaultPrevented && // onClick prevented default\n !e.metaKey && // ignore clicks with modifier keys...\n !e.altKey &&\n !e.ctrlKey &&\n !e.shiftKey\n ) {\n e.preventDefault()\n\n let shouldReplace = replace\n const isCurrent = encodeURI(prefixedTo) === _location.pathname\n\n if (typeof replace !== `boolean` && isCurrent) {\n shouldReplace = true\n }\n // Make sure the necessary scripts and data are\n // loaded before continuing.\n window.___navigate(prefixedTo, {\n state,\n replace: shouldReplace,\n })\n }\n\n return true\n }}\n {...rest}\n />\n )\n }\n}\n\nGatsbyLink.propTypes = {\n ...NavLinkPropTypes,\n onClick: PropTypes.func,\n to: PropTypes.string.isRequired,\n replace: PropTypes.bool,\n state: PropTypes.object,\n}\n\nexport default React.forwardRef((props, ref) => (\n <GatsbyLinkLocationWrapper innerRef={ref} {...props} />\n))\n\nexport const navigate = (to, options) => {\n window.___navigate(rewriteLinkPath(to, window.location.pathname), options)\n}\n"],"names":["path","pathname","indexOf","hashIndex","hash","slice","searchIndex","search","ABSOLUTE_URL_REGEX","test","isAbsolute","process","env","NODE_ENV","__PATH_PREFIX__","undefined","prefix","__BASE_PATH__","getGlobalBasePrefix","isLocalLink","startsWith","getGlobalPathPrefix","base","endsWith","__TRAILING_SLASH__","relativeTo","parsePath","getGlobalTrailingSlash","option","adjustedPath","applyTrailingSlashOption","withPrefix","current","isAbsolutePath","resolve","absolutePath","absolutify","activeClassName","PropTypes","string","activeStyle","object","partiallyActive","bool","props","React","Location","location","GatsbyLink","_location","Component","constructor","super","this","defaultGetProps","isPartiallyCurrent","isCurrent","className","filter","Boolean","join","style","window","IntersectionObserver","IOSupported","state","abortPrefetch","handleRef","bind","_prefetch","currentPath","rewriteLinkPath","to","parsed","newPathName","enqueue","componentWillUnmount","io","instance","el","abort","unobserve","disconnect","ref","innerRef","Object","prototype","hasOwnProperty","call","cb","entries","forEach","entry","target","isIntersecting","intersectionRatio","observe","createIntersectionObserver","inViewPort","render","getProps","onClick","onMouseEnter","replace","rest","console","warn","prefixedTo","Link","e","___loader","hovering","button","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","preventDefault","encodeURI","shouldReplace","___navigate","href","propTypes","NavLinkPropTypes","func","isRequired","forwardRef","GatsbyLinkLocationWrapper","navigate","options"],"mappings":"4aAA0BA,GACxB,MAAeA,GAAS,MACV,KACF,GAEZ,QAAkBC,EAASC,QAAS,MACjB,IAAfC,IACFC,EAAOH,EAASI,MAAMF,GACtBF,EAAWA,EAASI,MAAM,EAAGF,IAG/B,QAAoBF,EAASC,QAAS,KAMtC,OALqB,IAAjBI,IACFC,EAASN,EAASI,MAAMC,GACxBL,EAAWA,EAASI,MAAM,EAAGC,IAGxB,CACLL,SAAUA,EACVM,OAAoB,MAAZA,EAAkB,GAAIA,EAC9BH,KAAgB,MAAVA,EAAgB,GAAIA,GCnB9B,QAA2B,+BAGAJ,IACzB,GAAqB,mBAMrB,OATiBA,CAAAA,GAAQQ,EAAmBC,KAAKT,GASzCU,CAAWV,MCAc,IACP,eAA1BW,QAAQC,IAAIC,SACoB,oCAC1BC,qBACAC,EACFD,2BAEqBd,EAAMgB,EAhBE,KACP,eAA1BL,QAAQC,IAAIC,SACkB,kCACxBI,mBACAF,EACFE,cAWoCC,UACxC,IAAKC,EAAYnB,GACf,SAGF,GAAIA,EAAKoB,WAAY,OAAQpB,EAAKoB,WAAY,OAC5C,SAEF,uBAAaJ,EAAAA,EAAUK,OAA0B,IAEjD,MAAQ,SAAEC,GAAAA,EAAMC,SAAU,KAAMD,EAAKjB,MAAM,GAAI,GAAKiB,IAClDtB,EAAKoB,WAAY,KAAMpB,EAAQ,IAAGA,MCtBtC,QAAuBA,SAAQA,SAAAA,EAAMoB,WAAY,OAElB,IACE,uCAAaI,wBAAqBT,IAkBpC,CAACf,EAAMyB,KACpC,GAAqB,mBACnB,SAEF,IAAKN,EAAYnB,GACf,SAGF,MAAMC,SAAEA,EAAFM,OAAYA,EAAZH,KAAoBA,GAASsB,EAAU1B,KAC9B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StC,EAAOxE,SAAWwE,EAAOlE,SAE9C8F,QAASQ,IAKP,GAJIR,GACFA,EAAQQ,KAIK,IAAbA,EAAEG,QACD3D,KAAKT,MAAMiD,QACXgB,EAAEI,kBACFJ,EAAEK,SACFL,EAAEM,QACFN,EAAEO,SACFP,EAAEQ,UACH,CACAR,EAAES,iBAEF,MAAoBf,EACpB,QAAkBgB,UAAUZ,KAAgB1D,EAAUhD,SAE9B,qBAAYuD,IAClCgE,GAAgB,GAIlB1D,OAAO2D,YAAYd,EAAY,CAC7B1C,MAAAA,EACAsC,QAASiB,IAIb,WAEEhB,iBAhDC3D,uBAAG6E,KAAMf,GAAgBH,KAsDtCxD,EAAW2E,eACNC,GACHvB,QAAS/D,EAAUuF,KACnBrD,GAAIlC,EAAUC,OAAOuF,WACrBvB,QAASjE,EAAUK,KACnBsB,MAAO3B,EAAUG,SAGnB,QAAqBsF,WAAW,CAACnF,EAAOuC,iBACtCtC,gBAACmF,KAA0B5C,SAAUD,GAASvC,KAGnCqF,QAAW,CAACzD,EAAI0D,KAC3BpE,OAAO2D,YAAYlD,EAAgBC,EAAIV,OAAOf,SAAS9C,UAAWiI"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { NavigateFn, LinkProps } from "@reach/router"
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
+
export interface GatsbyLinkProps<TState> extends LinkProps<TState> {
|
|
6
|
+
/** A class to apply when this Link is active */
|
|
7
|
+
activeClassName?: string
|
|
8
|
+
/** Inline styles for when this Link is active */
|
|
9
|
+
activeStyle?: object
|
|
10
|
+
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void
|
|
11
|
+
/** Class the link as highlighted if there is a partial match via a the `to` being prefixed to the current url */
|
|
12
|
+
partiallyActive?: boolean
|
|
13
|
+
/** Used to declare that this link replaces the current URL in history with the target */
|
|
14
|
+
replace?: boolean
|
|
15
|
+
/** Used to pass state data to the linked page.
|
|
16
|
+
* The linked page will have a `location` prop containing a nested `state` object structure containing the passed data.
|
|
17
|
+
*/
|
|
18
|
+
state?: TState
|
|
19
|
+
/** The URL you want to link to */
|
|
20
|
+
to: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This component is intended _only_ for links to pages handled by Gatsby. For links to pages on other
|
|
25
|
+
* domains or pages on the same domain not handled by the current Gatsby site, use the normal `<a>` element.
|
|
26
|
+
*/
|
|
27
|
+
export default class GatsbyLink<TState> extends React.Component<
|
|
28
|
+
GatsbyLinkProps<TState>,
|
|
29
|
+
any
|
|
30
|
+
> {}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Sometimes you need to navigate to pages programmatically, such as during form submissions. In these
|
|
34
|
+
* cases, `Link` won’t work.
|
|
35
|
+
*/
|
|
36
|
+
export const navigate: NavigateFn
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* It is common to host sites in a sub-directory of a site. Gatsby lets you set the path prefix for your site.
|
|
40
|
+
* After doing so, Gatsby's `<Link>` component will automatically handle constructing the correct URL in
|
|
41
|
+
* development and production
|
|
42
|
+
*/
|
|
43
|
+
export const withPrefix: (path: string) => string
|
|
44
|
+
export const withAssetPrefix: (path: string) => string
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-link",
|
|
3
3
|
"description": "An enhanced Link component for Gatsby sites with support for resource prefetching",
|
|
4
|
-
"version": "4.20.0
|
|
4
|
+
"version": "4.20.0",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"module": "dist/index.modern.mjs",
|
|
12
12
|
"types": "index.d.ts",
|
|
13
13
|
"files": [
|
|
14
|
-
"dist/*"
|
|
14
|
+
"dist/*",
|
|
15
|
+
"index.d.ts"
|
|
15
16
|
],
|
|
16
17
|
"sideEffects": false,
|
|
17
18
|
"scripts": {
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@types/reach__router": "^1.3.10",
|
|
25
|
-
"gatsby-page-utils": "^2.20.0
|
|
26
|
+
"gatsby-page-utils": "^2.20.0",
|
|
26
27
|
"prop-types": "^15.8.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
@@ -49,5 +50,5 @@
|
|
|
49
50
|
"engines": {
|
|
50
51
|
"node": ">=14.15.0"
|
|
51
52
|
},
|
|
52
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "3ec74acade17fe80c6281c7d0caf52a78a018810"
|
|
53
54
|
}
|