gatsby-link 4.22.0 → 4.23.0-next.1

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 CHANGED
@@ -1,2 +1,3 @@
1
+ "client export"
1
2
  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?Object.assign.bind():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?Object.setPrototypeOf.bind():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 m(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 w=i.default.forwardRef(function(e,t){/*#__PURE__*/return i.default.createElement(m,s({innerRef:t},e))}),O={__proto__:null,parsePath:c,withPrefix:h,withAssetPrefix:function(e){return h(e,f())},default:w,navigate:function(e,t){window.___navigate(v(e,window.location.pathname),t)}};module.exports=w,Object.getOwnPropertyNames(O).forEach(function(e){Object.defineProperty(module.exports,e,{value:O[e],enumerable:!0})});
2
3
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,3 @@
1
+ "client export"
1
2
  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?Object.assign.bind():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
3
  //# sourceMappingURL=index.modern.mjs.map
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.22.0",
4
+ "version": "4.23.0-next.1",
5
5
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/gatsbyjs/gatsby/issues"
@@ -16,6 +16,7 @@
16
16
  "sideEffects": false,
17
17
  "scripts": {
18
18
  "build": "npm-run-all --npm-path npm -s build:cjs build:esm",
19
+ "postbuild": "prepend-directive --files=dist/index.js,dist/index.modern.mjs --directive=\"client export\"",
19
20
  "build:cjs": "microbundle -f cjs --jsx React.createElement --generateTypes false -i src/index-cjs.js -o dist/index.js",
20
21
  "build:esm": "microbundle -f modern --jsx React.createElement --generateTypes false -o dist/index.mjs",
21
22
  "watch": "npm-run-all --npm-path npm -p watch:cjs watch:esm",
@@ -26,7 +27,7 @@
26
27
  },
27
28
  "dependencies": {
28
29
  "@types/reach__router": "^1.3.10",
29
- "gatsby-page-utils": "^2.22.0",
30
+ "gatsby-page-utils": "^2.23.0-next.0",
30
31
  "prop-types": "^15.8.1"
31
32
  },
32
33
  "devDependencies": {
@@ -34,7 +35,8 @@
34
35
  "cross-env": "^7.0.3",
35
36
  "del-cli": "^5.0.0",
36
37
  "microbundle": "^0.15.0",
37
- "npm-run-all": "^4.1.5"
38
+ "npm-run-all": "^4.1.5",
39
+ "prepend-directive": "^1.0.3"
38
40
  },
39
41
  "peerDependencies": {
40
42
  "@gatsbyjs/reach-router": "^1.3.5",
@@ -54,5 +56,5 @@
54
56
  "engines": {
55
57
  "node": ">=14.15.0"
56
58
  },
57
- "gitHead": "78f8c7a599748feed4865cdc832a07537d44ded8"
59
+ "gitHead": "232d3b6de2281caa579a619888bcb6771733f548"
58
60
  }