react-scroll-to-top-route
Version:
A reactJS component which scrolls user back to top when navigating between routes
14 lines • 18.7 kB
JavaScript
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t,r){e.exports=r(7)()},function(e,t,r){"use strict";e.exports=r(5)},function(e,t,r){"use strict";var n=function(){};e.exports=n},function(e,t,r){"use strict";e.exports=function(e,t,r,n,o,i,u,c){if(!e){var a;if(void 0===t)a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[r,n,o,i,u,c],f=0;(a=new Error(t.replace(/%s/g,function(){return l[f++]}))).name="Invariant Violation"}throw a.framesToPop=1,a}}},function(e,t,r){var n=r(9);e.exports=y,e.exports.parse=i,e.exports.compile=function(e,t){return c(i(e,t))},e.exports.tokensToFunction=c,e.exports.tokensToRegExp=s;var o=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function i(e,t){for(var r,n=[],i=0,u=0,c="",f=t&&t.delimiter||"/";null!=(r=o.exec(e));){var p=r[0],s=r[1],y=r.index;if(c+=e.slice(u,y),u=y+p.length,s)c+=s[1];else{var d=e[u],h=r[2],v=r[3],m=r[4],b=r[5],g=r[6],x=r[7];c&&(n.push(c),c="");var O=null!=h&&null!=d&&d!==h,w="+"===g||"*"===g,j="?"===g||"*"===g,_=r[2]||f,S=m||b;n.push({name:v||i++,prefix:h||"",delimiter:_,optional:j,repeat:w,partial:O,asterisk:!!x,pattern:S?l(S):x?".*":"[^"+a(_)+"]+?"})}}return u<e.length&&(c+=e.substr(u)),c&&n.push(c),n}function u(e){return encodeURI(e).replace(/[\/?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function c(e){for(var t=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(t[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,o){for(var i="",c=r||{},a=(o||{}).pretty?u:encodeURIComponent,l=0;l<e.length;l++){var f=e[l];if("string"!=typeof f){var p,s=c[f.name];if(null==s){if(f.optional){f.partial&&(i+=f.prefix);continue}throw new TypeError('Expected "'+f.name+'" to be defined')}if(n(s)){if(!f.repeat)throw new TypeError('Expected "'+f.name+'" to not repeat, but received `'+JSON.stringify(s)+"`");if(0===s.length){if(f.optional)continue;throw new TypeError('Expected "'+f.name+'" to not be empty')}for(var y=0;y<s.length;y++){if(p=a(s[y]),!t[l].test(p))throw new TypeError('Expected all "'+f.name+'" to match "'+f.pattern+'", but received `'+JSON.stringify(p)+"`");i+=(0===y?f.prefix:f.delimiter)+p}}else{if(p=f.asterisk?encodeURI(s).replace(/[?#]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()}):a(s),!t[l].test(p))throw new TypeError('Expected "'+f.name+'" to match "'+f.pattern+'", but received "'+p+'"');i+=f.prefix+p}}else i+=f}return i}}function a(e){return e.replace(/([.+*?=^!:${}()[\]|\/\\])/g,"\\$1")}function l(e){return e.replace(/([=!:$\/()])/g,"\\$1")}function f(e,t){return e.keys=t,e}function p(e){return e.sensitive?"":"i"}function s(e,t,r){n(t)||(r=t||r,t=[]);for(var o=(r=r||{}).strict,i=!1!==r.end,u="",c=0;c<e.length;c++){var l=e[c];if("string"==typeof l)u+=a(l);else{var s=a(l.prefix),y="(?:"+l.pattern+")";t.push(l),l.repeat&&(y+="(?:"+s+y+")*"),u+=y=l.optional?l.partial?s+"("+y+")?":"(?:"+s+"("+y+"))?":s+"("+y+")"}}var d=a(r.delimiter||"/"),h=u.slice(-d.length)===d;return o||(u=(h?u.slice(0,-d.length):u)+"(?:"+d+"(?=$))?"),u+=i?"$":o&&h?"":"(?="+d+"|$)",f(new RegExp("^"+u,p(r)),t)}function y(e,t,r){return n(t)||(r=t||r,t=[]),r=r||{},e instanceof RegExp?function(e,t){var r=e.source.match(/\((?!\?)/g);if(r)for(var n=0;n<r.length;n++)t.push({name:n,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,asterisk:!1,pattern:null});return f(e,t)}(e,t):n(e)?function(e,t,r){for(var n=[],o=0;o<e.length;o++)n.push(y(e[o],t,r).source);return f(new RegExp("(?:"+n.join("|")+")",p(r)),t)}(e,t,r):function(e,t,r){return s(i(e,r),t,r)}(e,t,r)}},function(e,t,r){"use strict";
/** @license React v16.7.0
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var n=r(6),o="function"==typeof Symbol&&Symbol.for,i=o?Symbol.for("react.element"):60103,u=o?Symbol.for("react.portal"):60106,c=o?Symbol.for("react.fragment"):60107,a=o?Symbol.for("react.strict_mode"):60108,l=o?Symbol.for("react.profiler"):60114,f=o?Symbol.for("react.provider"):60109,p=o?Symbol.for("react.context"):60110,s=o?Symbol.for("react.concurrent_mode"):60111,y=o?Symbol.for("react.forward_ref"):60112,d=o?Symbol.for("react.suspense"):60113,h=o?Symbol.for("react.memo"):60115,v=o?Symbol.for("react.lazy"):60116,m="function"==typeof Symbol&&Symbol.iterator;function b(e){for(var t=arguments.length-1,r="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=0;n<t;n++)r+="&args[]="+encodeURIComponent(arguments[n+1]);!function(e,t,r,n,o,i,u,c){if(!e){if(e=void 0,void 0===t)e=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var a=[r,n,o,i,u,c],l=0;(e=Error(t.replace(/%s/g,function(){return a[l++]}))).name="Invariant Violation"}throw e.framesToPop=1,e}}(!1,"Minified React error #"+e+"; visit %s for the full message or use the non-minified dev environment for full errors and additional helpful warnings. ",r)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},x={};function O(e,t,r){this.props=e,this.context=t,this.refs=x,this.updater=r||g}function w(){}function j(e,t,r){this.props=e,this.context=t,this.refs=x,this.updater=r||g}O.prototype.isReactComponent={},O.prototype.setState=function(e,t){"object"!=typeof e&&"function"!=typeof e&&null!=e&&b("85"),this.updater.enqueueSetState(this,e,t,"setState")},O.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},w.prototype=O.prototype;var _=j.prototype=new w;_.constructor=j,n(_,O.prototype),_.isPureReactComponent=!0;var S={current:null,currentDispatcher:null},E=Object.prototype.hasOwnProperty,R={key:!0,ref:!0,__self:!0,__source:!0};function P(e,t,r){var n=void 0,o={},u=null,c=null;if(null!=t)for(n in void 0!==t.ref&&(c=t.ref),void 0!==t.key&&(u=""+t.key),t)E.call(t,n)&&!R.hasOwnProperty(n)&&(o[n]=t[n]);var a=arguments.length-2;if(1===a)o.children=r;else if(1<a){for(var l=Array(a),f=0;f<a;f++)l[f]=arguments[f+2];o.children=l}if(e&&e.defaultProps)for(n in a=e.defaultProps)void 0===o[n]&&(o[n]=a[n]);return{$$typeof:i,type:e,key:u,ref:c,props:o,_owner:S.current}}function k(e){return"object"==typeof e&&null!==e&&e.$$typeof===i}var C=/\/+/g,T=[];function $(e,t,r,n){if(T.length){var o=T.pop();return o.result=e,o.keyPrefix=t,o.func=r,o.context=n,o.count=0,o}return{result:e,keyPrefix:t,func:r,context:n,count:0}}function A(e){e.result=null,e.keyPrefix=null,e.func=null,e.context=null,e.count=0,10>T.length&&T.push(e)}function M(e,t,r){return null==e?0:function e(t,r,n,o){var c=typeof t;"undefined"!==c&&"boolean"!==c||(t=null);var a=!1;if(null===t)a=!0;else switch(c){case"string":case"number":a=!0;break;case"object":switch(t.$$typeof){case i:case u:a=!0}}if(a)return n(o,t,""===r?"."+I(t,0):r),1;if(a=0,r=""===r?".":r+":",Array.isArray(t))for(var l=0;l<t.length;l++){var f=r+I(c=t[l],l);a+=e(c,f,n,o)}else if(f=null===t||"object"!=typeof t?null:"function"==typeof(f=m&&t[m]||t["@@iterator"])?f:null,"function"==typeof f)for(t=f.call(t),l=0;!(c=t.next()).done;)a+=e(c=c.value,f=r+I(c,l++),n,o);else"object"===c&&b("31","[object Object]"==(n=""+t)?"object with keys {"+Object.keys(t).join(", ")+"}":n,"");return a}(e,"",t,r)}function I(e,t){return"object"==typeof e&&null!==e&&null!=e.key?function(e){var t={"=":"=0",":":"=2"};return"$"+(""+e).replace(/[=:]/g,function(e){return t[e]})}(e.key):t.toString(36)}function U(e,t){e.func.call(e.context,t,e.count++)}function q(e,t,r){var n=e.result,o=e.keyPrefix;e=e.func.call(e.context,t,e.count++),Array.isArray(e)?N(e,n,r,function(e){return e}):null!=e&&(k(e)&&(e=function(e,t){return{$$typeof:i,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}(e,o+(!e.key||t&&t.key===e.key?"":(""+e.key).replace(C,"$&/")+"/")+r)),n.push(e))}function N(e,t,r,n,o){var i="";null!=r&&(i=(""+r).replace(C,"$&/")+"/"),M(e,q,t=$(t,i,n,o)),A(t)}var Y={Children:{map:function(e,t,r){if(null==e)return e;var n=[];return N(e,n,null,t,r),n},forEach:function(e,t,r){if(null==e)return e;M(e,U,t=$(null,null,t,r)),A(t)},count:function(e){return M(e,function(){return null},null)},toArray:function(e){var t=[];return N(e,t,null,function(e){return e}),t},only:function(e){return k(e)||b("143"),e}},createRef:function(){return{current:null}},Component:O,PureComponent:j,createContext:function(e,t){return void 0===t&&(t=null),(e={$$typeof:p,_calculateChangedBits:t,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null}).Provider={$$typeof:f,_context:e},e.Consumer=e},forwardRef:function(e){return{$$typeof:y,render:e}},lazy:function(e){return{$$typeof:v,_ctor:e,_status:-1,_result:null}},memo:function(e,t){return{$$typeof:h,type:e,compare:void 0===t?null:t}},Fragment:c,StrictMode:a,Suspense:d,createElement:P,cloneElement:function(e,t,r){null==e&&b("267",e);var o=void 0,u=n({},e.props),c=e.key,a=e.ref,l=e._owner;if(null!=t){void 0!==t.ref&&(a=t.ref,l=S.current),void 0!==t.key&&(c=""+t.key);var f=void 0;for(o in e.type&&e.type.defaultProps&&(f=e.type.defaultProps),t)E.call(t,o)&&!R.hasOwnProperty(o)&&(u[o]=void 0===t[o]&&void 0!==f?f[o]:t[o])}if(1===(o=arguments.length-2))u.children=r;else if(1<o){f=Array(o);for(var p=0;p<o;p++)f[p]=arguments[p+2];u.children=f}return{$$typeof:i,type:e.type,key:c,ref:a,props:u,_owner:l}},createFactory:function(e){var t=P.bind(null,e);return t.type=e,t},isValidElement:k,version:"16.7.0",unstable_ConcurrentMode:s,unstable_Profiler:l,__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED:{ReactCurrentOwner:S,assign:n}},F={default:Y},D=F&&Y||F;e.exports=D.default||D},function(e,t,r){"use strict";
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/var n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var r,u,c=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),a=1;a<arguments.length;a++){for(var l in r=Object(arguments[a]))o.call(r,l)&&(c[l]=r[l]);if(n){u=n(r);for(var f=0;f<u.length;f++)i.call(r,u[f])&&(c[u[f]]=r[u[f]])}}return c}},function(e,t,r){"use strict";var n=r(8);function o(){}e.exports=function(){function e(e,t,r,o,i,u){if(u!==n){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=o,r.PropTypes=r,r}},function(e,t,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t){e.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},function(e,t,r){"use strict";r.r(t);var n=r(1),o=r.n(n),i=r(2),u=r.n(i),c=r(3),a=r.n(c),l=r(0),f=r.n(l),p=r(4),s=r.n(p),y={},d=0,h=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];"string"==typeof t&&(t={path:t});var n=t,o=n.path,i=n.exact,u=void 0!==i&&i,c=n.strict,a=void 0!==c&&c,l=n.sensitive;if(null==o)return r;var f=function(e,t){var r=""+t.end+t.strict+t.sensitive,n=y[r]||(y[r]={});if(n[e])return n[e];var o=[],i={re:s()(e,o,t),keys:o};return d<1e4&&(n[e]=i,d++),i}(o,{end:u,strict:a,sensitive:void 0!==l&&l}),p=f.re,h=f.keys,v=p.exec(e);if(!v)return null;var m=v[0],b=v.slice(1),g=e===m;return u&&!g?null:{path:o,url:"/"===o&&""===m?"/":m,isExact:g,params:h.reduce(function(e,t,r){return e[t.name]=b[r],e},{})}},v=Object.assign||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};function m(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var b=function(e){return 0===o.a.Children.count(e)},g=function(e){function t(){var r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var o=arguments.length,i=Array(o),u=0;u<o;u++)i[u]=arguments[u];return r=n=m(this,e.call.apply(e,[this].concat(i))),n.state={match:n.computeMatch(n.props,n.context.router)},m(n,r)}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.getChildContext=function(){return{router:v({},this.context.router,{route:{location:this.props.location||this.context.router.route.location,match:this.state.match}})}},t.prototype.computeMatch=function(e,t){var r=e.computedMatch,n=e.location,o=e.path,i=e.strict,u=e.exact,c=e.sensitive;if(r)return r;a()(t,"You should not use <Route> or withRouter() outside a <Router>");var l=t.route,f=(n||l.location).pathname;return h(f,{path:o,strict:i,exact:u,sensitive:c},l.match)},t.prototype.componentWillMount=function(){u()(!(this.props.component&&this.props.render),"You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored"),u()(!(this.props.component&&this.props.children&&!b(this.props.children)),"You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored"),u()(!(this.props.render&&this.props.children&&!b(this.props.children)),"You should not use <Route render> and <Route children> in the same route; <Route children> will be ignored")},t.prototype.componentWillReceiveProps=function(e,t){u()(!(e.location&&!this.props.location),'<Route> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.'),u()(!(!e.location&&this.props.location),'<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.'),this.setState({match:this.computeMatch(e,t.router)})},t.prototype.render=function(){var e=this.state.match,t=this.props,r=t.children,n=t.component,i=t.render,u=this.context.router,c=u.history,a=u.route,l=u.staticContext,f={match:e,location:this.props.location||a.location,history:c,staticContext:l};return n?e?o.a.createElement(n,f):null:i?e?i(f):null:"function"==typeof r?r(f):r&&!b(r)?o.a.Children.only(r):null},t}(o.a.Component);g.propTypes={computedMatch:f.a.object,path:f.a.string,exact:f.a.bool,strict:f.a.bool,sensitive:f.a.bool,component:f.a.func,render:f.a.func,children:f.a.oneOfType([f.a.func,f.a.node]),location:f.a.object},g.contextTypes={router:f.a.shape({history:f.a.object.isRequired,route:f.a.object.isRequired,staticContext:f.a.object})},g.childContextTypes={router:f.a.object.isRequired};var x=g;function O(e){return(O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function w(){return(w=Object.assign||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}).apply(this,arguments)}function j(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function _(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function S(e,t){return!t||"object"!==O(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function E(e){return(E=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function R(e,t){return(R=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var P=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),S(this,E(t).apply(this,arguments))}var r,i,u;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&R(e,t)}(t,n["Component"]),r=t,(i=[{key:"componentDidUpdate",value:function(){window.scrollTo(0,0)}},{key:"render",value:function(){var e=this.props,t=e.component,r=j(e,["component"]);return o.a.createElement(x,w({},r,{render:function(e){return o.a.createElement(t,e)}}))}}])&&_(r.prototype,i),u&&_(r,u),t}();t.default=P}]);