Socket
Socket
Sign inDemoInstall

@gatsbyjs/reach-router

Package Overview
Dependencies
Maintainers
21
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gatsbyjs/reach-router - npm Package Compare versions

Comparing version 2.0.0-v2.0.2 to 2.0.0-v2.0.3

2

dist/index.js

@@ -1,2 +0,2 @@

var e=require("react"),t=require("prop-types"),r=require("invariant");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var a=/*#__PURE__*/n(e),i=/*#__PURE__*/o(e),u=/*#__PURE__*/n(t),c=/*#__PURE__*/n(r);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}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 p(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(o[r]=e[r]);return o}var f=function(e){var t=e.location,r=t.search,n=t.hash,o=t.href,a=t.origin,i=t.protocol,u=t.host,c=t.hostname,s=t.port,l=e.location.pathname;return!l&&o&&v&&(l=new URL(o).pathname),{pathname:encodeURI(decodeURI(l)),search:r,hash:n,href:o,origin:a,protocol:i,host:u,hostname:c,port:s,state:e.history.state,key:e.history.state&&e.history.state.key||"initial"}},h=function(e,t){var r=[],n=f(e),o=!1,a=function(){};return{get location(){return n},get transitioning(){return o},_onTransitionComplete:function(){o=!1,a()},listen:function(t){r.push(t);var o=function(){n=f(e),t({location:n,action:"POP"})};return e.addEventListener("popstate",o),function(){e.removeEventListener("popstate",o),r=r.filter(function(e){return e!==t})}},navigate:function(t,i){var u=void 0===i?{}:i,c=u.state,l=u.replace,p=void 0!==l&&l;if("number"==typeof t)e.history.go(t);else{c=s({},c,{key:Date.now()+""});try{o||p?e.history.replaceState(c,null,t):e.history.pushState(c,null,t)}catch(r){e.location[p?"replace":"assign"](t)}}n=f(e),o=!0;var h=new Promise(function(e){return a=e});return r.forEach(function(e){return e({location:n,action:"PUSH"})}),h}}},d=function(e){void 0===e&&(e="/");var t=e.indexOf("?"),r={pathname:t>-1?e.substr(0,t):e,search:t>-1?e.substr(t):""},n=0,o=[r],a=[null];return{get location(){return o[n]},addEventListener:function(e,t){},removeEventListener:function(e,t){},history:{get entries(){return o},get index(){return n},get state(){return a[n]},pushState:function(e,t,r){var i=r.split("?"),u=i[1],c=void 0===u?"":u;n++,o.push({pathname:i[0],search:c.length?"?"+c:c}),a.push(e)},replaceState:function(e,t,r){var i=r.split("?"),u=i[1];o[n]={pathname:i[0],search:void 0===u?"":u},a[n]=e},go:function(e){var t=n+e;t<0||t>a.length-1||(n=t)}}}},v=!("undefined"==typeof window||!window.document||!window.document.createElement),m=h(v?window:d()),y=m.navigate;function g(e,t){return a.default.createServerContext?function(e,t){return void 0===t&&(t=null),globalThis.__SERVER_CONTEXT||(globalThis.__SERVER_CONTEXT={}),globalThis.__SERVER_CONTEXT[e]||(globalThis.__SERVER_CONTEXT[e]=a.default.createServerContext(e,t)),globalThis.__SERVER_CONTEXT[e]}(e,t):a.default.createContext(t)}var x=g("Base",{baseuri:"/",basepath:"/"}),E=g("Focus"),b=g("Location"),C=function(){return i.useContext(x)},R=function(){return i.useContext(E)},w=function(){return i.useContext(b)};function O(e){this.uri=e}var P=function(e){return e instanceof O},k=function(e){throw new O(e)};function _(e){var t=e.to,r=e.replace,n=void 0===r||r,o=e.state,a=e.noThrow,u=e.baseuri;i.useEffect(function(){Promise.resolve().then(function(){var r=N(t,u);y(q(r,e),{replace:n,state:o})})},[]);var c=N(t,u);return a||k(q(c,e)),null}var j=function(e){var t=w(),r=C();/*#__PURE__*/return i.createElement(_,s({},t,{baseuri:r.baseuri},e))};j.propTypes={from:u.default.string,to:u.default.string.isRequired};var T=function(e,t){return e.substr(0,t.length)===t},L=function(e,t){for(var r,n,o=t.split("?"),a=V(o[0]),i=""===a[0],u=I(e),s=0,l=u.length;s<l;s++){var p=!1,f=u[s].route;if(f.default)n={route:f,params:{},uri:t};else{for(var h=V(f.path),d={},v=Math.max(a.length,h.length),m=0;m<v;m++){var y=h[m],g=a[m];if(F(y)){d[y.slice(1)||"*"]=a.slice(m).map(decodeURIComponent).join("/");break}if(void 0===g){p=!0;break}var x=U.exec(y);if(x&&!i){var E=-1===K.indexOf(x[1]);c.default(E,'<Router> dynamic segment "'+x[1]+'" is a reserved name. Please use a different name in path "'+f.path+'".');var b=decodeURIComponent(g);d[x[1]]=b}else if(y!==g){p=!0;break}}if(!p){r={route:f,params:d,uri:"/"+a.slice(0,m).join("/")};break}}}return r||n||null},S=function(e,t){return L([{path:e}],t)},N=function(e,t){if(T(e,"/"))return e;var r=e.split("?"),n=r[0],o=r[1],a=t.split("?")[0],i=V(n),u=V(a);if(""===i[0])return X(a,o);if(!T(i[0],".")){var c=u.concat(i).join("/");return X(("/"===a?"":"/")+c,o)}for(var s=u.concat(i),l=[],p=0,f=s.length;p<f;p++){var h=s[p];".."===h?l.pop():"."!==h&&l.push(h)}return X("/"+l.join("/"),o)},q=function(e,t){var r=e.split("?"),n=r[1],o=void 0===n?"":n,a="/"+V(r[0]).map(function(e){var r=U.exec(e);return r?t[r[1]]:e}).join("/"),i=t.location,u=(i=void 0===i?{}:i).search,c=(void 0===u?"":u).split("?")[1]||"";return X(a,o,c)},M=function(e,t){var r=function(e){return D(e)};return V(e).filter(r).sort().join("/")===V(t).filter(r).sort().join("/")},U=/^:(.+)/,D=function(e){return U.test(e)},F=function(e){return e&&"*"===e[0]},B=function(e,t){return{route:e,score:e.default?0:V(e.path).reduce(function(e,t){return e+=4,function(e){return""===e}(t)?e+=1:D(t)?e+=2:F(t)?e-=5:e+=3,e},0),index:t}},I=function(e){return e.map(B).sort(function(e,t){return e.score<t.score?1:e.score>t.score?-1:e.index-t.index})},V=function(e){return e.replace(/(^\/+|\/+$)/g,"").split("/")},X=function(e){var t=[].slice.call(arguments,1);return e+((t=t.filter(function(e){return e&&e.length>0}))&&t.length>0?"?"+t.join("&"):"")},K=["uri","path"],A=function(e,t){var r=Object.keys(e);return r.length===Object.keys(t).length&&r.every(function(r){return t.hasOwnProperty(r)&&e[r]===t[r]})},H=function(e){return e.replace(/(^\/+|\/+$)/g,"")},W=function e(t){return function(r){if(!r)return null;if(r.type===i.Fragment&&r.props.children)return i.Children.map(r.props.children,e(t));if(c.default(r.props.path||r.props.default||r.type===j,"<Router>: Children of <Router> must have a `path` or `default` prop, or be a `<Redirect>`. None found on element type `"+r.type+"`"),c.default(!!(r.type!==j||r.props.from&&r.props.to),'<Redirect from="'+r.props.from+'" to="'+r.props.to+'"/> requires both "from" and "to" props when inside a <Router>.'),c.default(!(r.type===j&&!M(r.props.from,r.props.to)),'<Redirect from="'+r.props.from+' to="'+r.props.to+'"/> has mismatched dynamic segments, ensure both paths have the exact same dynamic segments.'),r.props.default)return{value:r,default:!0};var n=r.type===j?r.props.from:r.props.path,o="/"===n?t:H(t)+"/"+H(n);return{value:r,default:r.props.default,path:r.props.children?H(o)+"/*":o}}},$=["innerRef"],z=["to","state","replace","getProps"],G=["key"],J=i.forwardRef;void 0===J&&(J=function(e){return e});var Q=function(){},Y=J(function(e,t){var r=e.innerRef,n=p(e,$),o=C().baseuri,a=w().location,u=n.to,c=n.state,l=n.replace,f=n.getProps,h=void 0===f?Q:f,d=p(n,z),v=N(u,o),m=encodeURI(v),g=a.pathname===m,x=T(a.pathname,m);/*#__PURE__*/return i.createElement("a",s({ref:t||r,"aria-current":g?"page":void 0},d,h({isCurrent:g,isPartiallyCurrent:x,href:v,location:a}),{href:v,onClick:function(e){if(d.onClick&&d.onClick(e),function(e){return!e.defaultPrevented&&0===e.button&&!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(e)){e.preventDefault();var t=l;if("boolean"!=typeof l&&g){var r=p(s({},a.state),G);t=A(s({},c),r)}y(v,{state:c,replace:t})}}}))});Y.displayName="Link",Y.propTypes={to:u.default.string.isRequired};var Z=/*#__PURE__*/function(e){var t,r;function n(){for(var t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return(t=e.call.apply(e,[this].concat(n))||this).displayName="ReactUseErrorBoundary",t}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,l(t,r);var o=n.prototype;return o.componentDidCatch=function(){var e;this.setState({}),(e=this.props).onError.apply(e,[].slice.call(arguments))},o.render=function(){return this.props.children},n}(i.Component),ee=i.createContext({componentDidCatch:{current:void 0},error:void 0,setError:function(){return!1}});function te(e){var t=e.children,r=i.useState(),n=r[0],o=r[1],a=i.useRef(),u=i.useMemo(function(){return{componentDidCatch:a,error:n,setError:o}},[n]);/*#__PURE__*/return i.createElement(ee.Provider,{value:u},/*#__PURE__*/i.createElement(Z,{error:n,onError:function(e,t){o(e),null==a.current||a.current(e,t)}},t))}te.displayName="ReactUseErrorBoundaryContext";var re=function(e){var t,r;function n(t){/*#__PURE__*/return i.createElement(te,null,/*#__PURE__*/i.createElement(e,s({key:"WrappedComponent"},t)))}return n.displayName="WithErrorBoundary("+(null!=(t=null!=(r=e.displayName)?r:e.name)?t:"Component")+")",n}(function(e){var t=e.history,r=void 0===t?m:t,n=e.children,o=i.useState({location:r.location}),a=o[0],u=o[1],c=function(e){var t=i.useContext(ee);t.componentDidCatch.current=void 0;var r=i.useCallback(function(){t.setError(void 0)},[]);return[t.error,r]}()[0];if(i.useEffect(function(){r._onTransitionComplete()},[a.location]),i.useEffect(function(){var e=!1,t=r.listen(function(t){var r=t.location;Promise.resolve().then(function(){requestAnimationFrame(function(){e||u({location:r})})})});return function(){e=!0,t()}},[]),c){if(!P(c))throw c;y(c.uri,{replace:!0})}/*#__PURE__*/return i.createElement(b.Provider,{value:a},"function"==typeof n?n(a):n||null)}),ne=["uri","location","component"],oe=["children","style","requestFocus","component","uri","location"],ae=function(e){var t=e.uri,r=e.location,n=e.component,o=p(e,ne),a=R();/*#__PURE__*/return i.createElement(ue,s({},o,{component:n,requestFocus:a,uri:t,location:r}))},ie=0,ue=function(e){var t=e.children,r=e.style,n=e.requestFocus,o=e.component,a=void 0===o?"div":o,u=e.uri,c=e.location,l=p(e,oe),f=i.useRef(),h=i.useRef(!0),d=i.useRef(u),v=i.useRef(c.pathname),m=i.useRef(!0);i.useEffect(function(){return ie++,y(),function(){0==--ie&&(h.current=!0)}},[]),i.useEffect(function(){var e=!1,t=!1;u!==d.current&&(d.current=u,e=!0),c.pathname!==v.current&&(v.current=c.pathname,t=!0),m.current=e||t&&c.pathname===u,m.current&&y()},[u,c]);var y=i.useCallback(function(){"test"!==process.env.NODE_ENV&&(n?n(f.current):h.current?h.current=!1:f&&(f.current.contains(document.activeElement)||f.current.focus()))},[]);/*#__PURE__*/return i.createElement(a,s({style:s({outline:"none"},r),tabIndex:"-1",ref:function(e){return f=e}},l),/*#__PURE__*/i.createElement(E.Provider,{value:function(e){!m.current&&e&&e.current.focus()}},t))},ce=["location","primary","children","basepath","baseuri","component"],se=function(e){var t=C(),r=w();/*#__PURE__*/return i.createElement(le,s({},t,r,e))};function le(e){var t=e.location,r=e.primary,n=void 0===r||r,o=e.children,a=e.basepath,u=e.component,c=void 0===u?"div":u,l=p(e,ce),f=i.Children.toArray(o).reduce(function(e,t){var r=W(a)(t);return e.concat(r)},[]),h=L(f,t.pathname);if(h){var d=h.params,v=h.uri,m=h.route,y=h.route.value,g=m.default?a:m.path.replace(/\*$/,""),E=s({},d,{uri:v,location:t}),b=i.cloneElement(y,E,y.props.children?/*#__PURE__*/i.createElement(se,{location:t,primary:n},y.props.children):void 0),C=n?ae:c,R=n?s({uri:v,location:t,component:c},l):l;/*#__PURE__*/return i.createElement(x.Provider,{value:{baseuri:v,basepath:g}},/*#__PURE__*/i.createElement(C,R,b))}return null}var pe=function(){var e=w();if(!e)throw new Error("useLocation hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");return e.location};exports.BaseContext=x,exports.FocusContext=E,exports.Link=Y,exports.Location=function(e){var t=e.children,r=w();return r?t(r):/*#__PURE__*/i.createElement(re,null,t)},exports.LocationContext=b,exports.LocationProvider=re,exports.Match=function(e){var t=e.path,r=e.children,n=C().baseuri,o=w().location,a=N(t,n),i=S(a,o.pathname);return r({location:o,match:i?s({},i.params,{uri:i.uri,path:t}):null})},exports.Redirect=j,exports.Router=se,exports.ServerLocation=function(e){var t,r=e.url,n=e.children,o=r.indexOf("?"),a="";return o>-1?(t=r.substring(0,o),a=r.substring(o)):t=r,/*#__PURE__*/i.createElement(b.Provider,{value:{location:{pathname:t,search:a,hash:""}}},n)},exports.createHistory=h,exports.createMemorySource=d,exports.globalHistory=m,exports.insertParams=q,exports.isRedirect=P,exports.match=S,exports.navigate=y,exports.pick=L,exports.redirectTo=k,exports.resolve=N,exports.shallowCompare=A,exports.startsWith=T,exports.useBaseContext=C,exports.useFocusContext=R,exports.useLocation=pe,exports.useLocationContext=w,exports.useMatch=function(e){if(!e)throw new Error("useMatch(path: string) requires an argument of a string to match against");var t=C();if(!t)throw new Error("useMatch hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");var r=pe(),n=N(e,t.baseuri),o=S(n,r.pathname);return o?s({},o.params,{uri:o.uri,path:e}):null},exports.useNavigate=function(){throw new Error("useNavigate is removed. Use import { navigate } from 'gatsby' instead")},exports.useParams=function(){var e=C();if(!e)throw new Error("useParams hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");var t=pe(),r=S(e.basepath,t.pathname);return r?r.params:null},exports.validateRedirect=M;
var e=require("react"),t=require("prop-types"),r=require("invariant");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var a=/*#__PURE__*/n(e),i=/*#__PURE__*/o(e),u=/*#__PURE__*/n(t),c=/*#__PURE__*/n(r);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}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 p(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(o[r]=e[r]);return o}var f=function(e){var t=e.location,r=t.search,n=t.hash,o=t.href,a=t.origin,i=t.protocol,u=t.host,c=t.hostname,s=t.port,l=e.location.pathname;return!l&&o&&v&&(l=new URL(o).pathname),{pathname:encodeURI(decodeURI(l)),search:r,hash:n,href:o,origin:a,protocol:i,host:u,hostname:c,port:s,state:e.history.state,key:e.history.state&&e.history.state.key||"initial"}},h=function(e,t){var r=[],n=f(e),o=!1,a=function(){};return{get location(){return n},get transitioning(){return o},_onTransitionComplete:function(){o=!1,a()},listen:function(t){r.push(t);var o=function(){n=f(e),t({location:n,action:"POP"})};return e.addEventListener("popstate",o),function(){e.removeEventListener("popstate",o),r=r.filter(function(e){return e!==t})}},navigate:function(t,i){var u=void 0===i?{}:i,c=u.state,l=u.replace,p=void 0!==l&&l;if("number"==typeof t)e.history.go(t);else{c=s({},c,{key:Date.now()+""});try{o||p?e.history.replaceState(c,null,t):e.history.pushState(c,null,t)}catch(r){e.location[p?"replace":"assign"](t)}}n=f(e),o=!0;var h=new Promise(function(e){return a=e});return r.forEach(function(e){return e({location:n,action:"PUSH"})}),h}}},d=function(e){void 0===e&&(e="/");var t=e.indexOf("?"),r={pathname:t>-1?e.substr(0,t):e,search:t>-1?e.substr(t):""},n=0,o=[r],a=[null];return{get location(){return o[n]},addEventListener:function(e,t){},removeEventListener:function(e,t){},history:{get entries(){return o},get index(){return n},get state(){return a[n]},pushState:function(e,t,r){var i=r.split("?"),u=i[1],c=void 0===u?"":u;n++,o.push({pathname:i[0],search:c.length?"?"+c:c}),a.push(e)},replaceState:function(e,t,r){var i=r.split("?"),u=i[1];o[n]={pathname:i[0],search:void 0===u?"":u},a[n]=e},go:function(e){var t=n+e;t<0||t>a.length-1||(n=t)}}}},v=!("undefined"==typeof window||!window.document||!window.document.createElement),m=h(v?window:d()),y=m.navigate;function g(e,t){return a.default.createServerContext?function(e,t){return void 0===t&&(t=null),globalThis.__SERVER_CONTEXT||(globalThis.__SERVER_CONTEXT={}),globalThis.__SERVER_CONTEXT[e]||(globalThis.__SERVER_CONTEXT[e]=a.default.createServerContext(e,t)),globalThis.__SERVER_CONTEXT[e]}(e,t):a.default.createContext(t)}var b=g("Base",{baseuri:"/",basepath:"/"}),E=g("Location"),x=function(){return i.useContext(b)},R=function(){return i.useContext(E)};function C(e){this.uri=e}var w=function(e){return e instanceof C},O=function(e){throw new C(e)};function P(e){var t=e.to,r=e.replace,n=void 0===r||r,o=e.state,a=e.noThrow,u=e.baseuri;i.useEffect(function(){Promise.resolve().then(function(){var r=L(t,u);y(S(r,e),{replace:n,state:o})})},[]);var c=L(t,u);return a||O(S(c,e)),null}var k=function(e){var t=R(),r=x();/*#__PURE__*/return i.createElement(P,s({},t,{baseuri:r.baseuri},e))};k.propTypes={from:u.default.string,to:u.default.string.isRequired};var _=function(e,t){return e.substr(0,t.length)===t},j=function(e,t){for(var r,n,o=t.split("?"),a=I(o[0]),i=""===a[0],u=B(e),s=0,l=u.length;s<l;s++){var p=!1,f=u[s].route;if(f.default)n={route:f,params:{},uri:t};else{for(var h=I(f.path),d={},v=Math.max(a.length,h.length),m=0;m<v;m++){var y=h[m],g=a[m];if(q(y)){d[y.slice(1)||"*"]=a.slice(m).map(decodeURIComponent).join("/");break}if(void 0===g){p=!0;break}var b=M.exec(y);if(b&&!i){var E=-1===X.indexOf(b[1]);c.default(E,'<Router> dynamic segment "'+b[1]+'" is a reserved name. Please use a different name in path "'+f.path+'".');var x=decodeURIComponent(g);d[b[1]]=x}else if(y!==g){p=!0;break}}if(!p){r={route:f,params:d,uri:"/"+a.slice(0,m).join("/")};break}}}return r||n||null},T=function(e,t){return j([{path:e}],t)},L=function(e,t){if(_(e,"/"))return e;var r=e.split("?"),n=r[0],o=r[1],a=t.split("?")[0],i=I(n),u=I(a);if(""===i[0])return V(a,o);if(!_(i[0],".")){var c=u.concat(i).join("/");return V(("/"===a?"":"/")+c,o)}for(var s=u.concat(i),l=[],p=0,f=s.length;p<f;p++){var h=s[p];".."===h?l.pop():"."!==h&&l.push(h)}return V("/"+l.join("/"),o)},S=function(e,t){var r=e.split("?"),n=r[1],o=void 0===n?"":n,a="/"+I(r[0]).map(function(e){var r=M.exec(e);return r?t[r[1]]:e}).join("/"),i=t.location,u=(i=void 0===i?{}:i).search,c=(void 0===u?"":u).split("?")[1]||"";return V(a,o,c)},N=function(e,t){var r=function(e){return U(e)};return I(e).filter(r).sort().join("/")===I(t).filter(r).sort().join("/")},M=/^:(.+)/,U=function(e){return M.test(e)},q=function(e){return e&&"*"===e[0]},D=function(e,t){return{route:e,score:e.default?0:I(e.path).reduce(function(e,t){return e+=4,function(e){return""===e}(t)?e+=1:U(t)?e+=2:q(t)?e-=5:e+=3,e},0),index:t}},B=function(e){return e.map(D).sort(function(e,t){return e.score<t.score?1:e.score>t.score?-1:e.index-t.index})},I=function(e){return e.replace(/(^\/+|\/+$)/g,"").split("/")},V=function(e){var t=[].slice.call(arguments,1);return e+((t=t.filter(function(e){return e&&e.length>0}))&&t.length>0?"?"+t.join("&"):"")},X=["uri","path"],K=function(e,t){var r=Object.keys(e);return r.length===Object.keys(t).length&&r.every(function(r){return t.hasOwnProperty(r)&&e[r]===t[r]})},A=function(e){return e.replace(/(^\/+|\/+$)/g,"")},H=function e(t){return function(r){if(!r)return null;if(r.type===i.Fragment&&r.props.children)return i.Children.map(r.props.children,e(t));if(c.default(r.props.path||r.props.default||r.type===k,"<Router>: Children of <Router> must have a `path` or `default` prop, or be a `<Redirect>`. None found on element type `"+r.type+"`"),c.default(!!(r.type!==k||r.props.from&&r.props.to),'<Redirect from="'+r.props.from+'" to="'+r.props.to+'"/> requires both "from" and "to" props when inside a <Router>.'),c.default(!(r.type===k&&!N(r.props.from,r.props.to)),'<Redirect from="'+r.props.from+' to="'+r.props.to+'"/> has mismatched dynamic segments, ensure both paths have the exact same dynamic segments.'),r.props.default)return{value:r,default:!0};var n=r.type===k?r.props.from:r.props.path,o="/"===n?t:A(t)+"/"+A(n);return{value:r,default:r.props.default,path:r.props.children?A(o)+"/*":o}}},W=["innerRef"],$=["to","state","replace","getProps"],F=["key"],z=i.forwardRef;void 0===z&&(z=function(e){return e});var G=function(){},J=z(function(e,t){var r=e.innerRef,n=p(e,W),o=x().baseuri,a=R().location,u=n.to,c=n.state,l=n.replace,f=n.getProps,h=void 0===f?G:f,d=p(n,$),v=L(u,o),m=encodeURI(v),g=a.pathname===m,b=_(a.pathname,m);/*#__PURE__*/return i.createElement("a",s({ref:t||r,"aria-current":g?"page":void 0},d,h({isCurrent:g,isPartiallyCurrent:b,href:v,location:a}),{href:v,onClick:function(e){if(d.onClick&&d.onClick(e),function(e){return!e.defaultPrevented&&0===e.button&&!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(e)){e.preventDefault();var t=l;if("boolean"!=typeof l&&g){var r=p(s({},a.state),F);t=K(s({},c),r)}y(v,{state:c,replace:t})}}}))});J.displayName="Link",J.propTypes={to:u.default.string.isRequired};var Q=/*#__PURE__*/function(e){var t,r;function n(){for(var t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return(t=e.call.apply(e,[this].concat(n))||this).displayName="ReactUseErrorBoundary",t}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,l(t,r);var o=n.prototype;return o.componentDidCatch=function(){var e;this.setState({}),(e=this.props).onError.apply(e,[].slice.call(arguments))},o.render=function(){return this.props.children},n}(i.Component),Y=i.createContext({componentDidCatch:{current:void 0},error:void 0,setError:function(){return!1}});function Z(e){var t=e.children,r=i.useState(),n=r[0],o=r[1],a=i.useRef(),u=i.useMemo(function(){return{componentDidCatch:a,error:n,setError:o}},[n]);/*#__PURE__*/return i.createElement(Y.Provider,{value:u},/*#__PURE__*/i.createElement(Q,{error:n,onError:function(e,t){o(e),null==a.current||a.current(e,t)}},t))}Z.displayName="ReactUseErrorBoundaryContext";var ee=function(e){var t,r;function n(t){/*#__PURE__*/return i.createElement(Z,null,/*#__PURE__*/i.createElement(e,s({key:"WrappedComponent"},t)))}return n.displayName="WithErrorBoundary("+(null!=(t=null!=(r=e.displayName)?r:e.name)?t:"Component")+")",n}(function(e){var t=e.history,r=void 0===t?m:t,n=e.children,o=i.useState({location:r.location}),a=o[0],u=o[1],c=function(e){var t=i.useContext(Y);t.componentDidCatch.current=void 0;var r=i.useCallback(function(){t.setError(void 0)},[]);return[t.error,r]}()[0];if(i.useEffect(function(){r._onTransitionComplete()},[a.location]),i.useEffect(function(){var e=!1,t=r.listen(function(t){var r=t.location;Promise.resolve().then(function(){requestAnimationFrame(function(){e||u({location:r})})})});return function(){e=!0,t()}},[]),c){if(!w(c))throw c;y(c.uri,{replace:!0})}/*#__PURE__*/return i.createElement(E.Provider,{value:a},"function"==typeof n?n(a):n||null)}),te=["uri","location","component"],re=["children","style","component","uri","location"],ne=function(e){var t=e.uri,r=e.location,n=e.component,o=p(e,te);/*#__PURE__*/return i.createElement(ae,s({},o,{component:n,uri:t,location:r}))},oe=0,ae=function(e){var t=e.children,r=e.style,n=e.component,o=void 0===n?"div":n,a=e.uri,u=e.location,c=p(e,re),l=i.useRef(),f=i.useRef(!0),h=i.useRef(a),d=i.useRef(u.pathname),v=i.useRef(!1);i.useEffect(function(){return oe++,m(),function(){0==--oe&&(f.current=!0)}},[]),i.useEffect(function(){var e=!1,t=!1;a!==h.current&&(h.current=a,e=!0),u.pathname!==d.current&&(d.current=u.pathname,t=!0),v.current=e||t&&u.pathname===a,v.current&&m()},[a,u]);var m=i.useCallback(function(){var e;"test"!==process.env.NODE_ENV&&(f.current?f.current=!1:(e=l.current,v.current&&e&&e.focus()))},[]);/*#__PURE__*/return i.createElement(o,s({style:s({outline:"none"},r),tabIndex:"-1",ref:l},c),t)},ie=["location","primary","children","basepath","baseuri","component"],ue=function(e){var t=x(),r=R();/*#__PURE__*/return i.createElement(ce,s({},t,r,e))};function ce(e){var t=e.location,r=e.primary,n=void 0===r||r,o=e.children,a=e.basepath,u=e.component,c=void 0===u?"div":u,l=p(e,ie),f=i.Children.toArray(o).reduce(function(e,t){var r=H(a)(t);return e.concat(r)},[]),h=j(f,t.pathname);if(h){var d=h.params,v=h.uri,m=h.route,y=h.route.value,g=m.default?a:m.path.replace(/\*$/,""),E=s({},d,{uri:v,location:t}),x=i.cloneElement(y,E,y.props.children?/*#__PURE__*/i.createElement(ue,{location:t,primary:n},y.props.children):void 0),R=n?ne:c,C=n?s({uri:v,location:t,component:c},l):l;/*#__PURE__*/return i.createElement(b.Provider,{value:{baseuri:v,basepath:g}},/*#__PURE__*/i.createElement(R,C,x))}return null}var se=function(){var e=R();if(!e)throw new Error("useLocation hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");return e.location};exports.BaseContext=b,exports.Link=J,exports.Location=function(e){var t=e.children,r=R();return r?t(r):/*#__PURE__*/i.createElement(ee,null,t)},exports.LocationContext=E,exports.LocationProvider=ee,exports.Match=function(e){var t=e.path,r=e.children,n=x().baseuri,o=R().location,a=L(t,n),i=T(a,o.pathname);return r({location:o,match:i?s({},i.params,{uri:i.uri,path:t}):null})},exports.Redirect=k,exports.Router=ue,exports.ServerLocation=function(e){var t,r=e.url,n=e.children,o=r.indexOf("?"),a="";return o>-1?(t=r.substring(0,o),a=r.substring(o)):t=r,/*#__PURE__*/i.createElement(E.Provider,{value:{location:{pathname:t,search:a,hash:""}}},n)},exports.createHistory=h,exports.createMemorySource=d,exports.globalHistory=m,exports.insertParams=S,exports.isRedirect=w,exports.match=T,exports.navigate=y,exports.pick=j,exports.redirectTo=O,exports.resolve=L,exports.shallowCompare=K,exports.startsWith=_,exports.useBaseContext=x,exports.useLocation=se,exports.useLocationContext=R,exports.useMatch=function(e){if(!e)throw new Error("useMatch(path: string) requires an argument of a string to match against");var t=x();if(!t)throw new Error("useMatch hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");var r=se(),n=L(e,t.baseuri),o=T(n,r.pathname);return o?s({},o.params,{uri:o.uri,path:e}):null},exports.useNavigate=function(){throw new Error("useNavigate is removed. Use import { navigate } from 'gatsby' instead")},exports.useParams=function(){var e=x();if(!e)throw new Error("useParams hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");var t=se(),r=T(e.basepath,t.pathname);return r?r.params:null},exports.validateRedirect=N;
//# sourceMappingURL=index.js.map
{
"name": "@gatsbyjs/reach-router",
"version": "2.0.0-v2.0.2",
"version": "2.0.0-v2.0.3",
"description": "Gatsby's fork to modernize reach-router",

@@ -5,0 +5,0 @@ "source": "src/index.js",

@@ -5,3 +5,3 @@ # @gatsbyjs/reach-router

- Support for React 17 & 18
- Support for React 18 **only**
- Support for React Server Components

@@ -8,0 +8,0 @@ - Publish as CJS and ESM

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc