2 lines
18 KiB
JavaScript
2 lines
18 KiB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t.ReachRouter={},t.React)}(this,function(t,e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function r(t,e){return t(e={exports:{}},e.exports),e.exports}function i(t){return function(){return t}}var a=function(){};a.thatReturns=i,a.thatReturnsFalse=i(!1),a.thatReturnsTrue=i(!0),a.thatReturnsNull=i(null),a.thatReturnsThis=function(){return this},a.thatReturnsArgument=function(t){return t};var u=a;var c=function(t,e,n,o,r,i,a,u){if(!t){var c;if(void 0===e)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,o,r,i,a,u],p=0;(c=new Error(e.replace(/%s/g,function(){return s[p++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},s=u,p=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;(function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(t){o[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(t){return!1}})()&&Object.assign;var h="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",d=r(function(t){t.exports=function(){function t(t,e,n,o,r,i){i!==h&&c(!1,"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")}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return n.checkPropTypes=u,n.PropTypes=n,n}()}),v=function(t,e,n,o,r,i,a,u){if(!t){var c;if(void 0===e)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,o,r,i,a,u],p=0;(c=new Error(e.replace(/%s/g,function(){return s[p++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},m="__global_unique_id__",y=function(){return n[m]=(n[m]||0)+1},g=r(function(t,n){n.__esModule=!0;var o=a(e),r=a(d),i=a(y);a(s);function a(t){return t&&t.__esModule?t:{default:t}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var l=1073741823;n.default=o.default.createContext||function(t,n){var o,a,s="__create-react-context-"+(0,i.default)()+"__",f=function(t){function e(){var n,o,r,i;u(this,e);for(var a=arguments.length,s=Array(a),p=0;p<a;p++)s[p]=arguments[p];return n=o=c(this,t.call.apply(t,[this].concat(s))),o.emitter=(r=o.props.value,i=[],{on:function(t){i.push(t)},off:function(t){i=i.filter(function(e){return e!==t})},get:function(){return r},set:function(t,e){r=t,i.forEach(function(t){return t(r,e)})}}),c(o,n)}return p(e,t),e.prototype.getChildContext=function(){var t;return(t={})[s]=this.emitter,t},e.prototype.componentWillReceiveProps=function(t){if(this.props.value!==t.value){var e=this.props.value,o=t.value,r=void 0;((i=e)===(a=o)?0!==i||1/i==1/a:i!=i&&a!=a)?r=0:(r="function"==typeof n?n(e,o):l,0!=(r|=0)&&this.emitter.set(t.value,r))}var i,a},e.prototype.render=function(){return this.props.children},e}(e.Component);f.childContextTypes=((o={})[s]=r.default.object.isRequired,o);var h=function(e){function n(){var t,o;u(this,n);for(var r=arguments.length,i=Array(r),a=0;a<r;a++)i[a]=arguments[a];return t=o=c(this,e.call.apply(e,[this].concat(i))),o.state={value:o.getValue()},o.onUpdate=function(t,e){0!=((0|o.observedBits)&e)&&o.setState({value:o.getValue()})},c(o,t)}return p(n,e),n.prototype.componentWillReceiveProps=function(t){var e=t.observedBits;this.observedBits=void 0===e||null===e?l:e},n.prototype.componentDidMount=function(){this.context[s]&&this.context[s].on(this.onUpdate);var t=this.props.observedBits;this.observedBits=void 0===t||null===t?l:t},n.prototype.componentWillUnmount=function(){this.context[s]&&this.context[s].off(this.onUpdate)},n.prototype.getValue=function(){return this.context[s]?this.context[s].get():t},n.prototype.render=function(){return(t=this.props.children,Array.isArray(t)?t[0]:t)(this.state.value);var t},n}(e.Component);return h.contextTypes=((a={})[s]=r.default.object,a),{Provider:f,Consumer:h}},t.exports=n.default});o(g);var b=o(r(function(t,n){n.__esModule=!0;var o=i(e),r=i(g);function i(t){return t&&t.__esModule?t:{default:t}}n.default=o.default.createContext||r.default,t.exports=n.default}));function w(){var t=this.constructor.getDerivedStateFromProps(this.props,this.state);null!==t&&void 0!==t&&this.setState(t)}function _(t){this.setState(function(e){var n=this.constructor.getDerivedStateFromProps(t,e);return null!==n&&void 0!==n?n:null}.bind(this))}function P(t,e){try{var n=this.props,o=this.state;this.props=t,this.state=e,this.__reactInternalSnapshotFlag=!0,this.__reactInternalSnapshot=this.getSnapshotBeforeUpdate(n,o)}finally{this.props=n,this.state=o}}w.__suppressDeprecationWarning=!0,_.__suppressDeprecationWarning=!0,P.__suppressDeprecationWarning=!0;var E=function(t,e){return t.substr(0,e.length)===e},x=function(t,e){for(var n=void 0,o=void 0,r=e.split("?")[0],i=F(r),a=""===i[0],u=R(t),c=0,s=u.length;c<s;c++){var p=!1,l=u[c].route;if(l.default)o={route:l,params:{},uri:e};else{for(var f=F(l.path),h={},d=Math.max(i.length,f.length),m=0;m<d;m++){var y=f[m],g=i[m];if("*"===y){h["*"]=i.slice(m).map(decodeURIComponent).join("/");break}if(void 0===g){p=!0;break}var b=S.exec(y);if(b&&!a){-1===D.indexOf(b[1])||v(!1);var w=decodeURIComponent(g);h[b[1]]=w}else if(y!==g){p=!0;break}}if(!p){n={route:l,params:h,uri:"/"+i.slice(0,m).join("/")};break}}}return n||o||null},O=function(t,e){if(E(t,"/"))return t;var n=t.split("?"),o=n[0],r=n[1],i=e.split("?")[0],a=F(o),u=F(i);if(""===a[0])return T(i,r);if(!E(a[0],".")){var c=u.concat(a).join("/");return T(("/"===i?"":"/")+c,r)}for(var s=u.concat(a),p=[],l=0,f=s.length;l<f;l++){var h=s[l];".."===h?p.pop():"."!==h&&p.push(h)}return T("/"+p.join("/"),r)},C=function(t,e){return"/"+F(t).map(function(t){var n=S.exec(t);return n?e[n[1]]:t}).join("/")},S=/^:(.+)/,j=function(t){return S.test(t)},U=function(t,e){return{route:t,score:t.default?0:F(t.path).reduce(function(t,e){return t+=4,!function(t){return""===t}(e)?j(e)?t+=2:!function(t){return"*"===t}(e)?t+=3:t-=5:t+=1,t},0),index:e}},R=function(t){return t.map(U).sort(function(t,e){return t.score<e.score?1:t.score>e.score?-1:t.index-e.index})},F=function(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")},T=function(t,e){return t+(e?"?"+e:"")},D=["uri","path"],W=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},M=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},k=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},A=function(t,e){var n={};for(var o in t)e.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},I=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},q=function(t){return M({},t.location,{state:t.history.state,key:t.history.state&&t.history.state.key||"initial"})},N=function(t,e){var n=[],o=q(t),r=!1,i=function(){};return{get location(){return o},get transitioning(){return r},_onTransitionComplete:function(){r=!1,i()},listen:function(e){n.push(e);var r=function(){o=q(t),e({location:o,action:"POP"})};return t.addEventListener("popstate",r),function(){t.removeEventListener("popstate",r),n=n.filter(function(t){return t!==e})}},navigate:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=a.state,c=a.replace,s=void 0!==c&&c;u=M({},u,{key:Date.now()+""});try{r||s?t.history.replaceState(u,null,e):t.history.pushState(u,null,e)}catch(n){t.location[s?"replace":"assign"](e)}o=q(t),r=!0;var p=new Promise(function(t){return i=t});return n.forEach(function(t){return t({location:o,action:"PUSH"})}),p}}},B=function(){var t=0,e=[{pathname:arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",search:""}],n=[];return{get location(){return e[t]},addEventListener:function(t,e){},removeEventListener:function(t,e){},history:{get entries(){return e},get index(){return t},get state(){return n[t]},pushState:function(o,r,i){var a=i.split("?"),u=a[0],c=a[1],s=void 0===c?"":c;t++,e.push({pathname:u,search:s}),n.push(o)},replaceState:function(o,r,i){var a=i.split("?"),u=a[0],c=a[1],s=void 0===c?"":c;e[t]={pathname:u,search:s},n[t]=o}}}},L=N(!("undefined"==typeof window||!window.document||!window.document.createElement)?window:B()),V=L.navigate,H=function(t,e){var n=b(e);return n.Consumer.displayName=t+".Consumer",n.Provider.displayName=t+".Provider",n},K=H("Location"),$=function(t){var n=t.children;return e.createElement(K.Consumer,null,function(t){return t?n(t):e.createElement(Y,null,n)})},Y=function(t){function n(){var e,o;W(this,n);for(var r=arguments.length,i=Array(r),a=0;a<r;a++)i[a]=arguments[a];return e=o=I(this,t.call.apply(t,[this].concat(i))),o.state={context:o.getContext(),refs:{unlisten:null}},I(o,e)}return k(n,t),n.prototype.getContext=function(){var t=this.props.history;return{navigate:t.navigate,location:t.location}},n.prototype.componentDidCatch=function(t,e){if(!at(t))throw t;(0,this.props.history.navigate)(t.uri,{replace:!0})},n.prototype.componentDidUpdate=function(t,e){e.context.location!==this.state.context.location&&this.props.history._onTransitionComplete()},n.prototype.componentDidMount=function(){var t=this,e=this.state.refs,n=this.props.history;e.unlisten=n.listen(function(){Promise.resolve().then(function(){requestAnimationFrame(function(){t.unmounted||t.setState(function(){return{context:t.getContext()}})})})})},n.prototype.componentWillUnmount=function(){var t=this.state.refs;this.unmounted=!0,t.unlisten()},n.prototype.render=function(){var t=this.state.context,n=this.props.children;return e.createElement(K.Provider,{value:t},"function"==typeof n?n(t):n||null)},n}(e.Component);Y.defaultProps={history:L};var z=H("Base",{baseuri:"/",basepath:"/"}),G=function(t){return e.createElement(z.Consumer,null,function(n){return e.createElement($,null,function(o){return e.createElement(J,M({},n,o,t))})})},J=function(t){function n(){return W(this,n),I(this,t.apply(this,arguments))}return k(n,t),n.prototype.render=function(){var t=this.props,n=t.location,o=t.navigate,r=t.basepath,i=t.primary,a=t.children,u=(t.baseuri,t.component),c=void 0===u?"div":u,s=A(t,["location","navigate","basepath","primary","children","baseuri","component"]),p=e.Children.map(a,lt(r)),l=n.pathname,f=x(p,l);if(f){var h=f.params,d=f.uri,v=f.route,m=f.route.value;r=v.default?r:v.path.replace(/\*$/,"");var y=M({},h,{uri:d,location:n,navigate:function(t,e){return o(O(t,d),e)}}),g=e.cloneElement(m,y,m.props.children?e.createElement(G,{primary:i},m.props.children):void 0),b=i?X:c,w=i?M({uri:d,location:n,component:c},s):s;return e.createElement(z.Provider,{value:{baseuri:d,basepath:r}},e.createElement(b,w,g))}return null},n}(e.PureComponent);J.defaultProps={primary:!0};var Q=H("Focus"),X=function(t){var n=t.uri,o=t.location,r=t.component,i=A(t,["uri","location","component"]);return e.createElement(Q.Consumer,null,function(t){return e.createElement(et,M({},i,{component:r,requestFocus:t,uri:n,location:o}))})},Z=!0,tt=0,et=function(t){function n(){var e,o;W(this,n);for(var r=arguments.length,i=Array(r),a=0;a<r;a++)i[a]=arguments[a];return e=o=I(this,t.call.apply(t,[this].concat(i))),o.state={},o.requestFocus=function(t){o.state.shouldFocus||t.focus()},I(o,e)}return k(n,t),n.getDerivedStateFromProps=function(t,e){if(null==e.uri)return M({shouldFocus:!0},t);var n=t.uri!==e.uri,o=e.location.pathname!==t.location.pathname&&t.location.pathname===t.uri;return M({shouldFocus:n||o},t)},n.prototype.componentDidMount=function(){tt++,this.focus()},n.prototype.componentWillUnmount=function(){0===--tt&&(Z=!0)},n.prototype.componentDidUpdate=function(t,e){t.location!==this.props.location&&this.state.shouldFocus&&this.focus()},n.prototype.focus=function(){var t=this.props.requestFocus;t?t(this.node):Z?Z=!1:this.node.contains(document.activeElement)||this.node.focus()},n.prototype.render=function(){var t=this,n=this.props,o=(n.children,n.style),r=(n.requestFocus,n.role),i=void 0===r?"group":r,a=n.component,u=void 0===a?"div":a,c=(n.uri,n.location,A(n,["children","style","requestFocus","role","component","uri","location"]));return e.createElement(u,M({style:M({outline:"none"},o),tabIndex:"-1",role:i,ref:function(e){return t.node=e}},c),e.createElement(Q.Provider,{value:this.requestFocus},this.props.children))},n}(e.Component);!function(t){var e=t.prototype;if(!e||!e.isReactComponent)throw new Error("Can only polyfill class components");if("function"!=typeof t.getDerivedStateFromProps&&"function"!=typeof e.getSnapshotBeforeUpdate)return t;var n=null,o=null,r=null;if("function"==typeof e.componentWillMount?n="componentWillMount":"function"==typeof e.UNSAFE_componentWillMount&&(n="UNSAFE_componentWillMount"),"function"==typeof e.componentWillReceiveProps?o="componentWillReceiveProps":"function"==typeof e.UNSAFE_componentWillReceiveProps&&(o="UNSAFE_componentWillReceiveProps"),"function"==typeof e.componentWillUpdate?r="componentWillUpdate":"function"==typeof e.UNSAFE_componentWillUpdate&&(r="UNSAFE_componentWillUpdate"),null!==n||null!==o||null!==r){var i=t.displayName||t.name,a="function"==typeof t.getDerivedStateFromProps?"getDerivedStateFromProps()":"getSnapshotBeforeUpdate()";throw Error("Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n"+i+" uses "+a+" but also contains the following legacy lifecycles:"+(null!==n?"\n "+n:"")+(null!==o?"\n "+o:"")+(null!==r?"\n "+r:"")+"\n\nThe above lifecycles should be removed. Learn more about this warning here:\nhttps://fb.me/react-async-component-lifecycle-hooks")}if("function"==typeof t.getDerivedStateFromProps&&(e.componentWillMount=w,e.componentWillReceiveProps=_),"function"==typeof e.getSnapshotBeforeUpdate){if("function"!=typeof e.componentDidUpdate)throw new Error("Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype");e.componentWillUpdate=P;var u=e.componentDidUpdate;e.componentDidUpdate=function(t,e,n){var o=this.__reactInternalSnapshotFlag?this.__reactInternalSnapshot:n;u.call(this,t,e,o)}}}(et);var nt=function(){},ot=e.forwardRef;void 0===ot&&(ot=function(t){return t});var rt=ot(function(t,n){var o=t.innerRef,r=A(t,["innerRef"]);return e.createElement(z.Consumer,null,function(t){t.basepath;var i=t.baseuri;return e.createElement($,null,function(t){var a=t.location,u=t.navigate,c=r.to,s=r.state,p=r.replace,l=r.getProps,f=void 0===l?nt:l,h=A(r,["to","state","replace","getProps"]),d=O(c,i),v=a.pathname===d,m=E(a.pathname,d);return e.createElement("a",M({ref:n||o,"aria-current":v?"page":void 0},h,f({isCurrent:v,isPartiallyCurrent:m,href:d,location:a}),{href:d,onClick:function(t){h.onClick&&h.onClick(t),ft(t)&&(t.preventDefault(),u(d,{state:s,replace:p}))}}))})})});function it(t){this.uri=t}var at=function(t){return t instanceof it},ut=function(t){throw new it(t)},ct=function(t){function e(){return W(this,e),I(this,t.apply(this,arguments))}return k(e,t),e.prototype.componentDidMount=function(){var t=this.props,e=t.navigate,n=t.to,o=(t.from,t.replace),r=void 0===o||o,i=t.state,a=(t.noThrow,A(t,["navigate","to","from","replace","state","noThrow"]));Promise.resolve().then(function(){e(C(n,a),{replace:r,state:i})})},e.prototype.render=function(){var t=this.props,e=(t.navigate,t.to),n=(t.from,t.replace,t.state,t.noThrow),o=A(t,["navigate","to","from","replace","state","noThrow"]);return n||ut(C(e,o)),null},e}(e.Component),st=function(t){return e.createElement($,null,function(n){return e.createElement(ct,M({},n,t))})},pt=function(t){return t.replace(/(^\/+|\/+$)/g,"")},lt=function(t){return function(e){if(!e)return null;var n,o,r;if(e.props.path||e.props.default||e.type===st||v(!1),e.type!==st||e.props.from&&e.props.to||v(!1),e.type===st&&(n=e.props.from,o=e.props.to,r=function(t){return j(t)},F(n).filter(r).sort().join("/")!==F(o).filter(r).sort().join("/"))&&v(!1),e.props.default)return{value:e,default:!0};var i=e.type===st?e.props.from:e.props.path,a="/"===i?t:pt(t)+"/"+pt(i);return{value:e,default:e.props.default,path:e.props.children?pt(a)+"/*":a}}},ft=function(t){return!t.defaultPrevented&&0===t.button&&!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)};t.Link=rt,t.Location=$,t.LocationProvider=Y,t.Match=function(t){var n=t.path,o=t.children;return e.createElement(z.Consumer,null,function(t){var r=t.baseuri;return e.createElement($,null,function(t){var e=t.navigate,i=t.location,a=function(t,e){return x([{path:t}],e)}(O(n,r),i.pathname);return o({navigate:e,location:i,match:a?M({},a.params,{uri:a.uri,path:n}):null})})})},t.Redirect=st,t.Router=G,t.ServerLocation=function(t){var n=t.url,o=t.children;return e.createElement(K.Provider,{value:{location:{pathname:n,search:"",hash:""},navigate:function(){throw new Error("You can't call navigate on the server.")}}},o)},t.createHistory=N,t.createMemorySource=B,t.isRedirect=at,t.navigate=V,t.redirectTo=ut,t.globalHistory=L,Object.defineProperty(t,"__esModule",{value:!0})});
|