gatsby-link 4.19.0-next.0 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var e=require("prop-types"),t=require("react"),n=require("@gatsbyjs/reach-router"),r=require("@gatsbyjs/reach-router/lib/utils"),o=require("gatsby-page-utils/apply-trailing-slash-option");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/a(e),s=/*#__PURE__*/a(t);function l(){return l=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},l.apply(this,arguments)}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function u(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 p=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,f=function(e){if("string"==typeof e)return!function(e){return p.test(e)}(e)},h=function(){return"production"!==process.env.NODE_ENV?"undefined"!=typeof __PATH_PREFIX__?__PATH_PREFIX__:void 0:__PATH_PREFIX__};function d(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__),!f(e))return e;if(e.startsWith("./")||e.startsWith("../"))return e;var o=null!=(n=null!=(r=t)?r:h())?n:"/";return""+(null!=o&&o.endsWith("/")?o.slice(0,-1):o)+(e.startsWith("/")?e:"/"+e)}var _=function(e){return null==e?void 0:e.startsWith("/")},v=function(){return"undefined"!=typeof __TRAILING_SLASH__?__TRAILING_SLASH__:void 0},y=function(e,t){if("number"==typeof e)return e;if(!f(e))return e;var n=u(e),a=n.pathname,i=n.search,s=n.hash,l=v(),c=e;return"always"!==l&&"never"!==l||(c=""+o.applyTrailingSlashOption(a,l)+i+s),_(c)?d(c):function(e,t){if(_(e))return e;var n=v(),a=r.resolve(e,t);return"always"===n||"never"===n?o.applyTrailingSlashOption(a,n):a}(c,t)},b=["to","getProps","onClick","onMouseEnter","activeClassName","activeStyle","innerRef","partiallyActive","state","replace","_location"],w={activeClassName:i.default.string,activeStyle:i.default.object,partiallyActive:i.default.bool};function P(e){/*#__PURE__*/return s.default.createElement(n.Location,null,function(t){/*#__PURE__*/return s.default.createElement(m,l({},e,{_location:t.location}))})}var m=/*#__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:l({},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,c(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=u(y(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,i=t.onClick,c=t.onMouseEnter,p=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,b);"production"===process.env.NODE_ENV||f(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 v=y(r,d.pathname);return f(v)?/*#__PURE__*/s.default.createElement(n.Link,l({to:v,state:p,getProps:a,innerRef:this.handleRef,onMouseEnter:function(e){c&&c(e);var t=u(v);___loader.hovering(t.pathname+t.search)},onClick:function(t){if(i&&i(t),!(0!==t.button||e.props.target||t.defaultPrevented||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)){t.preventDefault();var n=h,r=encodeURI(v)===d.pathname;"boolean"!=typeof h&&r&&(n=!0),window.___navigate(v,{state:p,replace:n})}return!0}},_)):/*#__PURE__*/s.default.createElement("a",l({href:v},_))},o}(s.default.Component);m.propTypes=l({},w,{onClick:i.default.func,to:i.default.string.isRequired,replace:i.default.bool,state:i.default.object});var g=s.default.forwardRef(function(e,t){/*#__PURE__*/return s.default.createElement(P,l({innerRef:t},e))});exports.default=g,exports.navigate=function(e,t){window.___navigate(y(e,window.location.pathname),t)},exports.parsePath=u,exports.withAssetPrefix=function(e){return d(e,h())},exports.withPrefix=d;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,4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AA,MACAuC,IAAAA,QACArD,IAAAA,UAEGsD,yJAGDC,QAAQ1F,IAAIC,UAA8BK,EAAYmD,IACxDkC,QAAQC,sBACWnC,+HAIrB,MAAmBD,EAAgBC,EAAItB,EAAU5C,UACjD,OAAKe,EAAYuF,gBAKf7D,wBAAC8D,UACCrC,GAAIoC,EACJ5C,MAAOA,EACPoC,SAAUA,EACVf,SAAUhB,KAAKH,UACfoC,aAAc,SAAAQ,GACRR,GACFA,EAAaQ,GAEf,MAAelF,EAAUgF,GACzBG,UAAUC,SAASvC,EAAOnE,SAAWmE,EAAO7D,SAE9CyF,QAAS,SAAAS,GAKP,GAJIT,GACFA,EAAQS,KAIK,IAAbA,EAAEG,QACDC,EAAKpE,MAAMiD,QACXe,EAAEK,kBACFL,EAAEM,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"}
@@ -0,0 +1,2 @@
1
+ import t from"prop-types";import e from"react";import{Location as n,Link as r}from"@gatsbyjs/reach-router";import{resolve as o}from"@gatsbyjs/reach-router/lib/utils";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:n,search:r,hash:i}=a(t),c=u();let p=t;return"always"!==c&&"never"!==c||(p=`${s(n,c)}${r}${i}`),f(p)?h(p):function(t,e){if(f(t))return t;const n=u(),r=o(t,e);return"always"===n||"never"===n?s(r,n):r}(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(n,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:o=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(r,i({to:m,state:p,getProps:o,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
+ //# sourceMappingURL=index.modern.mjs.map
@@ -0,0 +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,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,KAAo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AAUiF,GACzBG,UAAUC,SAAStC,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/package.json CHANGED
@@ -1,23 +1,35 @@
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.19.0-next.0",
4
+ "version": "4.19.0",
5
5
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/gatsbyjs/gatsby/issues"
8
8
  },
9
+ "source": "src/index.js",
10
+ "main": "dist/index.js",
11
+ "module": "dist/index.modern.mjs",
12
+ "types": "index.d.ts",
13
+ "files": [
14
+ "dist/*"
15
+ ],
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "microbundle -f cjs,modern --jsx React.createElement --generateTypes false",
19
+ "watch": "npm run build watch --no-compress",
20
+ "prepare": "cross-env NODE_ENV=production npm run clean && npm run build",
21
+ "clean": "del-cli dist/*"
22
+ },
9
23
  "dependencies": {
10
- "@babel/runtime": "^7.15.4",
11
24
  "@types/reach__router": "^1.3.10",
12
- "gatsby-page-utils": "^2.19.0-next.0",
25
+ "gatsby-page-utils": "^2.19.0",
13
26
  "prop-types": "^15.8.1"
14
27
  },
15
28
  "devDependencies": {
16
- "@babel/cli": "^7.15.4",
17
- "@babel/core": "^7.15.5",
18
29
  "@testing-library/react": "^11.2.7",
19
- "babel-preset-gatsby-package": "^2.19.0-next.0",
20
- "cross-env": "^7.0.3"
30
+ "cross-env": "^7.0.3",
31
+ "del-cli": "^3.0.1",
32
+ "microbundle": "^0.15.0"
21
33
  },
22
34
  "peerDependencies": {
23
35
  "@gatsbyjs/reach-router": "^1.3.5",
@@ -29,20 +41,13 @@
29
41
  "gatsby"
30
42
  ],
31
43
  "license": "MIT",
32
- "main": "index.js",
33
44
  "repository": {
34
45
  "type": "git",
35
46
  "url": "https://github.com/gatsbyjs/gatsby.git",
36
47
  "directory": "packages/gatsby-link"
37
48
  },
38
- "scripts": {
39
- "build": "babel src --out-dir . --ignore \"**/__tests__\"",
40
- "prepare": "cross-env NODE_ENV=production npm run build",
41
- "watch": "babel -w src --out-dir . --ignore \"**/__tests__\""
42
- },
43
- "types": "index.d.ts",
44
49
  "engines": {
45
50
  "node": ">=14.15.0"
46
51
  },
47
- "gitHead": "b535098fba656d6bc5fea22861c3d35e63ff71d9"
52
+ "gitHead": "53bedf19e998aee23db6a7b85205470ee6e3cc0a"
48
53
  }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": [["babel-preset-gatsby-package", { "browser": true, "esm": true }]]
3
- }
package/.eslintrc.yaml DELETED
@@ -1,4 +0,0 @@
1
- env:
2
- browser: true
3
- globals:
4
- ___loader: false
package/index.d.ts DELETED
@@ -1,44 +0,0 @@
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/index.js DELETED
@@ -1,239 +0,0 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
2
- import _extends from "@babel/runtime/helpers/extends";
3
- const _excluded = ["to", "getProps", "onClick", "onMouseEnter", "activeClassName", "activeStyle", "innerRef", "partiallyActive", "state", "replace", "_location"];
4
- import PropTypes from "prop-types";
5
- import React from "react";
6
- import { Link, Location } from "@gatsbyjs/reach-router";
7
- import { parsePath } from "./parse-path";
8
- import { isLocalLink } from "./is-local-link";
9
- import { rewriteLinkPath } from "./rewrite-link-path";
10
- export { parsePath };
11
- export function withPrefix(path, prefix = getGlobalBasePrefix()) {
12
- var _ref;
13
-
14
- if (!isLocalLink(path)) {
15
- return path;
16
- }
17
-
18
- if (path.startsWith(`./`) || path.startsWith(`../`)) {
19
- return path;
20
- }
21
-
22
- const base = (_ref = prefix !== null && prefix !== void 0 ? prefix : getGlobalPathPrefix()) !== null && _ref !== void 0 ? _ref : `/`;
23
- return `${base !== null && base !== void 0 && base.endsWith(`/`) ? base.slice(0, -1) : base}${path.startsWith(`/`) ? path : `/${path}`}`;
24
- } // These global values are wrapped in typeof clauses to ensure the values exist.
25
- // This is especially problematic in unit testing of this component.
26
-
27
- const getGlobalPathPrefix = () => process.env.NODE_ENV !== `production` ? typeof __PATH_PREFIX__ !== `undefined` ? __PATH_PREFIX__ : undefined : __PATH_PREFIX__;
28
-
29
- const getGlobalBasePrefix = () => process.env.NODE_ENV !== `production` ? typeof __BASE_PATH__ !== `undefined` ? __BASE_PATH__ : undefined : __BASE_PATH__;
30
-
31
- export function withAssetPrefix(path) {
32
- return withPrefix(path, getGlobalPathPrefix());
33
- }
34
- const NavLinkPropTypes = {
35
- activeClassName: PropTypes.string,
36
- activeStyle: PropTypes.object,
37
- partiallyActive: PropTypes.bool
38
- }; // Set up IntersectionObserver
39
-
40
- const createIntersectionObserver = (el, cb) => {
41
- const io = new window.IntersectionObserver(entries => {
42
- entries.forEach(entry => {
43
- if (el === entry.target) {
44
- // Check if element is within viewport, remove listener, destroy observer, and run link callback.
45
- // MSEdge doesn't currently support isIntersecting, so also test for an intersectionRatio > 0
46
- cb(entry.isIntersecting || entry.intersectionRatio > 0);
47
- }
48
- });
49
- }); // Add element to the observer
50
-
51
- io.observe(el);
52
- return {
53
- instance: io,
54
- el
55
- };
56
- };
57
-
58
- function GatsbyLinkLocationWrapper(props) {
59
- return /*#__PURE__*/React.createElement(Location, null, ({
60
- location
61
- }) => /*#__PURE__*/React.createElement(GatsbyLink, _extends({}, props, {
62
- _location: location
63
- })));
64
- }
65
-
66
- class GatsbyLink extends React.Component {
67
- constructor(props) {
68
- super(props); // Default to no support for IntersectionObserver
69
-
70
- this.defaultGetProps = ({
71
- isPartiallyCurrent,
72
- isCurrent
73
- }) => {
74
- if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {
75
- return {
76
- className: [this.props.className, this.props.activeClassName].filter(Boolean).join(` `),
77
- style: _extends({}, this.props.style, this.props.activeStyle)
78
- };
79
- }
80
-
81
- return null;
82
- };
83
-
84
- let IOSupported = false;
85
-
86
- if (typeof window !== `undefined` && window.IntersectionObserver) {
87
- IOSupported = true;
88
- }
89
-
90
- this.state = {
91
- IOSupported
92
- };
93
- this.abortPrefetch = null;
94
- this.handleRef = this.handleRef.bind(this);
95
- }
96
-
97
- _prefetch() {
98
- let currentPath = window.location.pathname + window.location.search; // reach router should have the correct state
99
-
100
- if (this.props._location && this.props._location.pathname) {
101
- currentPath = this.props._location.pathname + this.props._location.search;
102
- }
103
-
104
- const rewrittenPath = rewriteLinkPath(this.props.to, currentPath);
105
- const parsed = parsePath(rewrittenPath);
106
- const newPathName = parsed.pathname + parsed.search; // Prefetch is used to speed up next navigations. When you use it on the current navigation,
107
- // there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete
108
-
109
- if (currentPath !== newPathName) {
110
- return ___loader.enqueue(newPathName);
111
- }
112
-
113
- return undefined;
114
- }
115
-
116
- componentWillUnmount() {
117
- if (!this.io) {
118
- return;
119
- }
120
-
121
- const {
122
- instance,
123
- el
124
- } = this.io;
125
-
126
- if (this.abortPrefetch) {
127
- this.abortPrefetch.abort();
128
- }
129
-
130
- instance.unobserve(el);
131
- instance.disconnect();
132
- }
133
-
134
- handleRef(ref) {
135
- if (this.props.innerRef && Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)) {
136
- this.props.innerRef.current = ref;
137
- } else if (this.props.innerRef) {
138
- this.props.innerRef(ref);
139
- }
140
-
141
- if (this.state.IOSupported && ref) {
142
- // If IO supported and element reference found, setup Observer functionality
143
- this.io = createIntersectionObserver(ref, inViewPort => {
144
- if (inViewPort) {
145
- this.abortPrefetch = this._prefetch();
146
- } else {
147
- if (this.abortPrefetch) {
148
- this.abortPrefetch.abort();
149
- }
150
- }
151
- });
152
- }
153
- }
154
-
155
- render() {
156
- const _this$props = this.props,
157
- {
158
- to,
159
- getProps = this.defaultGetProps,
160
- onClick,
161
- onMouseEnter,
162
- state,
163
- replace,
164
- _location
165
- } = _this$props,
166
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
167
-
168
- if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {
169
- console.warn(`External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`);
170
- }
171
-
172
- const prefixedTo = rewriteLinkPath(to, _location.pathname);
173
-
174
- if (!isLocalLink(prefixedTo)) {
175
- return /*#__PURE__*/React.createElement("a", _extends({
176
- href: prefixedTo
177
- }, rest));
178
- }
179
-
180
- return /*#__PURE__*/React.createElement(Link, _extends({
181
- to: prefixedTo,
182
- state: state,
183
- getProps: getProps,
184
- innerRef: this.handleRef,
185
- onMouseEnter: e => {
186
- if (onMouseEnter) {
187
- onMouseEnter(e);
188
- }
189
-
190
- const parsed = parsePath(prefixedTo);
191
-
192
- ___loader.hovering(parsed.pathname + parsed.search);
193
- },
194
- onClick: e => {
195
- if (onClick) {
196
- onClick(e);
197
- }
198
-
199
- if (e.button === 0 && // ignore right clicks
200
- !this.props.target && // let browser handle "target=_blank"
201
- !e.defaultPrevented && // onClick prevented default
202
- !e.metaKey && // ignore clicks with modifier keys...
203
- !e.altKey && !e.ctrlKey && !e.shiftKey) {
204
- e.preventDefault();
205
- let shouldReplace = replace;
206
-
207
- const isCurrent = encodeURI(prefixedTo) === _location.pathname;
208
-
209
- if (typeof replace !== `boolean` && isCurrent) {
210
- shouldReplace = true;
211
- } // Make sure the necessary scripts and data are
212
- // loaded before continuing.
213
-
214
-
215
- window.___navigate(prefixedTo, {
216
- state,
217
- replace: shouldReplace
218
- });
219
- }
220
-
221
- return true;
222
- }
223
- }, rest));
224
- }
225
-
226
- }
227
-
228
- GatsbyLink.propTypes = _extends({}, NavLinkPropTypes, {
229
- onClick: PropTypes.func,
230
- to: PropTypes.string.isRequired,
231
- replace: PropTypes.bool,
232
- state: PropTypes.object
233
- });
234
- export default /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(GatsbyLinkLocationWrapper, _extends({
235
- innerRef: ref
236
- }, props)));
237
- export const navigate = (to, options) => {
238
- window.___navigate(rewriteLinkPath(to, window.location.pathname), options);
239
- };
package/is-local-link.js DELETED
@@ -1,13 +0,0 @@
1
- // Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js
2
- const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
3
-
4
- const isAbsolute = path => ABSOLUTE_URL_REGEX.test(path);
5
-
6
- export const isLocalLink = path => {
7
- if (typeof path !== `string`) {
8
- return undefined; // TODO(v5): Re-Add TypeError
9
- // throw new TypeError(`Expected a \`string\`, got \`${typeof path}\``)
10
- }
11
-
12
- return !isAbsolute(path);
13
- };
package/parse-path.js DELETED
@@ -1,24 +0,0 @@
1
- export function parsePath(path) {
2
- let pathname = path || `/`;
3
- let search = ``;
4
- let hash = ``;
5
- const hashIndex = pathname.indexOf(`#`);
6
-
7
- if (hashIndex !== -1) {
8
- hash = pathname.slice(hashIndex);
9
- pathname = pathname.slice(0, hashIndex);
10
- }
11
-
12
- const searchIndex = pathname.indexOf(`?`);
13
-
14
- if (searchIndex !== -1) {
15
- search = pathname.slice(searchIndex);
16
- pathname = pathname.slice(0, searchIndex);
17
- }
18
-
19
- return {
20
- pathname: pathname,
21
- search: search === `?` ? `` : search,
22
- hash: hash === `#` ? `` : hash
23
- };
24
- }
@@ -1,51 +0,0 @@
1
- import { resolve } from "@gatsbyjs/reach-router/lib/utils"; // Specific import to treeshake Node.js stuff
2
-
3
- import { applyTrailingSlashOption } from "gatsby-page-utils/apply-trailing-slash-option";
4
- import { parsePath } from "./parse-path";
5
- import { isLocalLink } from "./is-local-link";
6
- import { withPrefix } from ".";
7
-
8
- const isAbsolutePath = path => path === null || path === void 0 ? void 0 : path.startsWith(`/`);
9
-
10
- const getGlobalTrailingSlash = () => typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined;
11
-
12
- function absolutify(path, current) {
13
- // If it's already absolute, return as-is
14
- if (isAbsolutePath(path)) {
15
- return path;
16
- }
17
-
18
- const option = getGlobalTrailingSlash();
19
- const absolutePath = resolve(path, current);
20
-
21
- if (option === `always` || option === `never`) {
22
- return applyTrailingSlashOption(absolutePath, option);
23
- }
24
-
25
- return absolutePath;
26
- }
27
-
28
- export const rewriteLinkPath = (path, relativeTo) => {
29
- if (typeof path === `number`) {
30
- return path;
31
- }
32
-
33
- if (!isLocalLink(path)) {
34
- return path;
35
- }
36
-
37
- const {
38
- pathname,
39
- search,
40
- hash
41
- } = parsePath(path);
42
- const option = getGlobalTrailingSlash();
43
- let adjustedPath = path;
44
-
45
- if (option === `always` || option === `never`) {
46
- const output = applyTrailingSlashOption(pathname, option);
47
- adjustedPath = `${output}${search}${hash}`;
48
- }
49
-
50
- return isAbsolutePath(adjustedPath) ? withPrefix(adjustedPath) : absolutify(adjustedPath, relativeTo);
51
- };
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json"
3
- }