Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

2744 строки
87 KiB

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  4. (factory((global.ReactRouter = {}),global.React));
  5. }(this, (function (exports,React) { 'use strict';
  6. React = React && React.hasOwnProperty('default') ? React['default'] : React;
  7. /**
  8. * Copyright (c) 2014-present, Facebook, Inc.
  9. *
  10. * This source code is licensed under the MIT license found in the
  11. * LICENSE file in the root directory of this source tree.
  12. *
  13. * @providesModule warning
  14. */
  15. var warning = function() {};
  16. {
  17. var printWarning = function printWarning(format, args) {
  18. var len = arguments.length;
  19. args = new Array(len > 2 ? len - 2 : 0);
  20. for (var key = 2; key < len; key++) {
  21. args[key - 2] = arguments[key];
  22. }
  23. var argIndex = 0;
  24. var message = 'Warning: ' +
  25. format.replace(/%s/g, function() {
  26. return args[argIndex++];
  27. });
  28. if (typeof console !== 'undefined') {
  29. console.error(message);
  30. }
  31. try {
  32. // --- Welcome to debugging React ---
  33. // This error was thrown as a convenience so that you can use this stack
  34. // to find the callsite that caused this warning to fire.
  35. throw new Error(message);
  36. } catch (x) {}
  37. };
  38. warning = function(condition, format, args) {
  39. var len = arguments.length;
  40. args = new Array(len > 2 ? len - 2 : 0);
  41. for (var key = 2; key < len; key++) {
  42. args[key - 2] = arguments[key];
  43. }
  44. if (format === undefined) {
  45. throw new Error(
  46. '`warning(condition, format, ...args)` requires a warning ' +
  47. 'message argument'
  48. );
  49. }
  50. if (!condition) {
  51. printWarning.apply(null, [format].concat(args));
  52. }
  53. };
  54. }
  55. var warning_1 = warning;
  56. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  57. function createCommonjsModule(fn, module) {
  58. return module = { exports: {} }, fn(module, module.exports), module.exports;
  59. }
  60. /**
  61. * Copyright (c) 2013-present, Facebook, Inc.
  62. *
  63. * This source code is licensed under the MIT license found in the
  64. * LICENSE file in the root directory of this source tree.
  65. *
  66. *
  67. */
  68. function makeEmptyFunction(arg) {
  69. return function () {
  70. return arg;
  71. };
  72. }
  73. /**
  74. * This function accepts and discards inputs; it has no side effects. This is
  75. * primarily useful idiomatically for overridable function endpoints which
  76. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  77. */
  78. var emptyFunction = function emptyFunction() {};
  79. emptyFunction.thatReturns = makeEmptyFunction;
  80. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  81. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  82. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  83. emptyFunction.thatReturnsThis = function () {
  84. return this;
  85. };
  86. emptyFunction.thatReturnsArgument = function (arg) {
  87. return arg;
  88. };
  89. var emptyFunction_1 = emptyFunction;
  90. /**
  91. * Copyright (c) 2013-present, Facebook, Inc.
  92. *
  93. * This source code is licensed under the MIT license found in the
  94. * LICENSE file in the root directory of this source tree.
  95. *
  96. */
  97. /**
  98. * Use invariant() to assert state which your program assumes to be true.
  99. *
  100. * Provide sprintf-style format (only %s is supported) and arguments
  101. * to provide information about what broke and what you were
  102. * expecting.
  103. *
  104. * The invariant message will be stripped in production, but the invariant
  105. * will remain to ensure logic does not differ in production.
  106. */
  107. var validateFormat = function validateFormat(format) {};
  108. {
  109. validateFormat = function validateFormat(format) {
  110. if (format === undefined) {
  111. throw new Error('invariant requires an error message argument');
  112. }
  113. };
  114. }
  115. function invariant(condition, format, a, b, c, d, e, f) {
  116. validateFormat(format);
  117. if (!condition) {
  118. var error;
  119. if (format === undefined) {
  120. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  121. } else {
  122. var args = [a, b, c, d, e, f];
  123. var argIndex = 0;
  124. error = new Error(format.replace(/%s/g, function () {
  125. return args[argIndex++];
  126. }));
  127. error.name = 'Invariant Violation';
  128. }
  129. error.framesToPop = 1; // we don't care about invariant's own frame
  130. throw error;
  131. }
  132. }
  133. var invariant_1 = invariant;
  134. /**
  135. * Similar to invariant but only logs a warning if the condition is not met.
  136. * This can be used to log issues in development environments in critical
  137. * paths. Removing the logging code for production environments will keep the
  138. * same logic and follow the same code paths.
  139. */
  140. var warning$1 = emptyFunction_1;
  141. {
  142. var printWarning$1 = function printWarning(format) {
  143. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  144. args[_key - 1] = arguments[_key];
  145. }
  146. var argIndex = 0;
  147. var message = 'Warning: ' + format.replace(/%s/g, function () {
  148. return args[argIndex++];
  149. });
  150. if (typeof console !== 'undefined') {
  151. console.error(message);
  152. }
  153. try {
  154. // --- Welcome to debugging React ---
  155. // This error was thrown as a convenience so that you can use this stack
  156. // to find the callsite that caused this warning to fire.
  157. throw new Error(message);
  158. } catch (x) {}
  159. };
  160. warning$1 = function warning(condition, format) {
  161. if (format === undefined) {
  162. throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
  163. }
  164. if (format.indexOf('Failed Composite propType: ') === 0) {
  165. return; // Ignore CompositeComponent proptype check.
  166. }
  167. if (!condition) {
  168. for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  169. args[_key2 - 2] = arguments[_key2];
  170. }
  171. printWarning$1.apply(undefined, [format].concat(args));
  172. }
  173. };
  174. }
  175. var warning_1$1 = warning$1;
  176. /*
  177. object-assign
  178. (c) Sindre Sorhus
  179. @license MIT
  180. */
  181. /* eslint-disable no-unused-vars */
  182. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  183. var hasOwnProperty = Object.prototype.hasOwnProperty;
  184. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  185. function toObject(val) {
  186. if (val === null || val === undefined) {
  187. throw new TypeError('Object.assign cannot be called with null or undefined');
  188. }
  189. return Object(val);
  190. }
  191. function shouldUseNative() {
  192. try {
  193. if (!Object.assign) {
  194. return false;
  195. }
  196. // Detect buggy property enumeration order in older V8 versions.
  197. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  198. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  199. test1[5] = 'de';
  200. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  201. return false;
  202. }
  203. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  204. var test2 = {};
  205. for (var i = 0; i < 10; i++) {
  206. test2['_' + String.fromCharCode(i)] = i;
  207. }
  208. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  209. return test2[n];
  210. });
  211. if (order2.join('') !== '0123456789') {
  212. return false;
  213. }
  214. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  215. var test3 = {};
  216. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  217. test3[letter] = letter;
  218. });
  219. if (Object.keys(Object.assign({}, test3)).join('') !==
  220. 'abcdefghijklmnopqrst') {
  221. return false;
  222. }
  223. return true;
  224. } catch (err) {
  225. // We don't expect any of the above to throw, but better to be safe.
  226. return false;
  227. }
  228. }
  229. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  230. var from;
  231. var to = toObject(target);
  232. var symbols;
  233. for (var s = 1; s < arguments.length; s++) {
  234. from = Object(arguments[s]);
  235. for (var key in from) {
  236. if (hasOwnProperty.call(from, key)) {
  237. to[key] = from[key];
  238. }
  239. }
  240. if (getOwnPropertySymbols) {
  241. symbols = getOwnPropertySymbols(from);
  242. for (var i = 0; i < symbols.length; i++) {
  243. if (propIsEnumerable.call(from, symbols[i])) {
  244. to[symbols[i]] = from[symbols[i]];
  245. }
  246. }
  247. }
  248. }
  249. return to;
  250. };
  251. /**
  252. * Copyright (c) 2013-present, Facebook, Inc.
  253. *
  254. * This source code is licensed under the MIT license found in the
  255. * LICENSE file in the root directory of this source tree.
  256. */
  257. var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
  258. var ReactPropTypesSecret_1 = ReactPropTypesSecret;
  259. {
  260. var invariant$1 = invariant_1;
  261. var warning$2 = warning_1$1;
  262. var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
  263. var loggedTypeFailures = {};
  264. }
  265. /**
  266. * Assert that the values match with the type specs.
  267. * Error messages are memorized and will only be shown once.
  268. *
  269. * @param {object} typeSpecs Map of name to a ReactPropType
  270. * @param {object} values Runtime values that need to be type-checked
  271. * @param {string} location e.g. "prop", "context", "child context"
  272. * @param {string} componentName Name of the component for error messages.
  273. * @param {?Function} getStack Returns the component stack.
  274. * @private
  275. */
  276. function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
  277. {
  278. for (var typeSpecName in typeSpecs) {
  279. if (typeSpecs.hasOwnProperty(typeSpecName)) {
  280. var error;
  281. // Prop type validation may throw. In case they do, we don't want to
  282. // fail the render phase where it didn't fail before. So we log it.
  283. // After these have been cleaned up, we'll let them throw.
  284. try {
  285. // This is intentionally an invariant that gets caught. It's the same
  286. // behavior as without this statement except with a better message.
  287. invariant$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]);
  288. error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
  289. } catch (ex) {
  290. error = ex;
  291. }
  292. warning$2(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
  293. if (error instanceof Error && !(error.message in loggedTypeFailures)) {
  294. // Only monitor this failure once because there tends to be a lot of the
  295. // same error.
  296. loggedTypeFailures[error.message] = true;
  297. var stack = getStack ? getStack() : '';
  298. warning$2(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
  299. }
  300. }
  301. }
  302. }
  303. }
  304. var checkPropTypes_1 = checkPropTypes;
  305. var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
  306. /* global Symbol */
  307. var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  308. var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
  309. /**
  310. * Returns the iterator method function contained on the iterable object.
  311. *
  312. * Be sure to invoke the function with the iterable as context:
  313. *
  314. * var iteratorFn = getIteratorFn(myIterable);
  315. * if (iteratorFn) {
  316. * var iterator = iteratorFn.call(myIterable);
  317. * ...
  318. * }
  319. *
  320. * @param {?object} maybeIterable
  321. * @return {?function}
  322. */
  323. function getIteratorFn(maybeIterable) {
  324. var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
  325. if (typeof iteratorFn === 'function') {
  326. return iteratorFn;
  327. }
  328. }
  329. /**
  330. * Collection of methods that allow declaration and validation of props that are
  331. * supplied to React components. Example usage:
  332. *
  333. * var Props = require('ReactPropTypes');
  334. * var MyArticle = React.createClass({
  335. * propTypes: {
  336. * // An optional string prop named "description".
  337. * description: Props.string,
  338. *
  339. * // A required enum prop named "category".
  340. * category: Props.oneOf(['News','Photos']).isRequired,
  341. *
  342. * // A prop named "dialog" that requires an instance of Dialog.
  343. * dialog: Props.instanceOf(Dialog).isRequired
  344. * },
  345. * render: function() { ... }
  346. * });
  347. *
  348. * A more formal specification of how these methods are used:
  349. *
  350. * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
  351. * decl := ReactPropTypes.{type}(.isRequired)?
  352. *
  353. * Each and every declaration produces a function with the same signature. This
  354. * allows the creation of custom validation functions. For example:
  355. *
  356. * var MyLink = React.createClass({
  357. * propTypes: {
  358. * // An optional string or URI prop named "href".
  359. * href: function(props, propName, componentName) {
  360. * var propValue = props[propName];
  361. * if (propValue != null && typeof propValue !== 'string' &&
  362. * !(propValue instanceof URI)) {
  363. * return new Error(
  364. * 'Expected a string or an URI for ' + propName + ' in ' +
  365. * componentName
  366. * );
  367. * }
  368. * }
  369. * },
  370. * render: function() {...}
  371. * });
  372. *
  373. * @internal
  374. */
  375. var ANONYMOUS = '<<anonymous>>';
  376. // Important!
  377. // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
  378. var ReactPropTypes = {
  379. array: createPrimitiveTypeChecker('array'),
  380. bool: createPrimitiveTypeChecker('boolean'),
  381. func: createPrimitiveTypeChecker('function'),
  382. number: createPrimitiveTypeChecker('number'),
  383. object: createPrimitiveTypeChecker('object'),
  384. string: createPrimitiveTypeChecker('string'),
  385. symbol: createPrimitiveTypeChecker('symbol'),
  386. any: createAnyTypeChecker(),
  387. arrayOf: createArrayOfTypeChecker,
  388. element: createElementTypeChecker(),
  389. instanceOf: createInstanceTypeChecker,
  390. node: createNodeChecker(),
  391. objectOf: createObjectOfTypeChecker,
  392. oneOf: createEnumTypeChecker,
  393. oneOfType: createUnionTypeChecker,
  394. shape: createShapeTypeChecker,
  395. exact: createStrictShapeTypeChecker,
  396. };
  397. /**
  398. * inlined Object.is polyfill to avoid requiring consumers ship their own
  399. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  400. */
  401. /*eslint-disable no-self-compare*/
  402. function is(x, y) {
  403. // SameValue algorithm
  404. if (x === y) {
  405. // Steps 1-5, 7-10
  406. // Steps 6.b-6.e: +0 != -0
  407. return x !== 0 || 1 / x === 1 / y;
  408. } else {
  409. // Step 6.a: NaN == NaN
  410. return x !== x && y !== y;
  411. }
  412. }
  413. /*eslint-enable no-self-compare*/
  414. /**
  415. * We use an Error-like object for backward compatibility as people may call
  416. * PropTypes directly and inspect their output. However, we don't use real
  417. * Errors anymore. We don't inspect their stack anyway, and creating them
  418. * is prohibitively expensive if they are created too often, such as what
  419. * happens in oneOfType() for any type before the one that matched.
  420. */
  421. function PropTypeError(message) {
  422. this.message = message;
  423. this.stack = '';
  424. }
  425. // Make `instanceof Error` still work for returned errors.
  426. PropTypeError.prototype = Error.prototype;
  427. function createChainableTypeChecker(validate) {
  428. {
  429. var manualPropTypeCallCache = {};
  430. var manualPropTypeWarningCount = 0;
  431. }
  432. function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
  433. componentName = componentName || ANONYMOUS;
  434. propFullName = propFullName || propName;
  435. if (secret !== ReactPropTypesSecret_1) {
  436. if (throwOnDirectAccess) {
  437. // New behavior only for users of `prop-types` package
  438. invariant_1(
  439. false,
  440. 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
  441. 'Use `PropTypes.checkPropTypes()` to call them. ' +
  442. 'Read more at http://fb.me/use-check-prop-types'
  443. );
  444. } else if (typeof console !== 'undefined') {
  445. // Old behavior for people using React.PropTypes
  446. var cacheKey = componentName + ':' + propName;
  447. if (
  448. !manualPropTypeCallCache[cacheKey] &&
  449. // Avoid spamming the console because they are often not actionable except for lib authors
  450. manualPropTypeWarningCount < 3
  451. ) {
  452. warning_1$1(
  453. false,
  454. 'You are manually calling a React.PropTypes validation ' +
  455. 'function for the `%s` prop on `%s`. This is deprecated ' +
  456. 'and will throw in the standalone `prop-types` package. ' +
  457. 'You may be seeing this warning due to a third-party PropTypes ' +
  458. 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.',
  459. propFullName,
  460. componentName
  461. );
  462. manualPropTypeCallCache[cacheKey] = true;
  463. manualPropTypeWarningCount++;
  464. }
  465. }
  466. }
  467. if (props[propName] == null) {
  468. if (isRequired) {
  469. if (props[propName] === null) {
  470. return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
  471. }
  472. return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
  473. }
  474. return null;
  475. } else {
  476. return validate(props, propName, componentName, location, propFullName);
  477. }
  478. }
  479. var chainedCheckType = checkType.bind(null, false);
  480. chainedCheckType.isRequired = checkType.bind(null, true);
  481. return chainedCheckType;
  482. }
  483. function createPrimitiveTypeChecker(expectedType) {
  484. function validate(props, propName, componentName, location, propFullName, secret) {
  485. var propValue = props[propName];
  486. var propType = getPropType(propValue);
  487. if (propType !== expectedType) {
  488. // `propValue` being instance of, say, date/regexp, pass the 'object'
  489. // check, but we can offer a more precise error message here rather than
  490. // 'of type `object`'.
  491. var preciseType = getPreciseType(propValue);
  492. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
  493. }
  494. return null;
  495. }
  496. return createChainableTypeChecker(validate);
  497. }
  498. function createAnyTypeChecker() {
  499. return createChainableTypeChecker(emptyFunction_1.thatReturnsNull);
  500. }
  501. function createArrayOfTypeChecker(typeChecker) {
  502. function validate(props, propName, componentName, location, propFullName) {
  503. if (typeof typeChecker !== 'function') {
  504. return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
  505. }
  506. var propValue = props[propName];
  507. if (!Array.isArray(propValue)) {
  508. var propType = getPropType(propValue);
  509. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
  510. }
  511. for (var i = 0; i < propValue.length; i++) {
  512. var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
  513. if (error instanceof Error) {
  514. return error;
  515. }
  516. }
  517. return null;
  518. }
  519. return createChainableTypeChecker(validate);
  520. }
  521. function createElementTypeChecker() {
  522. function validate(props, propName, componentName, location, propFullName) {
  523. var propValue = props[propName];
  524. if (!isValidElement(propValue)) {
  525. var propType = getPropType(propValue);
  526. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
  527. }
  528. return null;
  529. }
  530. return createChainableTypeChecker(validate);
  531. }
  532. function createInstanceTypeChecker(expectedClass) {
  533. function validate(props, propName, componentName, location, propFullName) {
  534. if (!(props[propName] instanceof expectedClass)) {
  535. var expectedClassName = expectedClass.name || ANONYMOUS;
  536. var actualClassName = getClassName(props[propName]);
  537. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
  538. }
  539. return null;
  540. }
  541. return createChainableTypeChecker(validate);
  542. }
  543. function createEnumTypeChecker(expectedValues) {
  544. if (!Array.isArray(expectedValues)) {
  545. warning_1$1(false, 'Invalid argument supplied to oneOf, expected an instance of array.');
  546. return emptyFunction_1.thatReturnsNull;
  547. }
  548. function validate(props, propName, componentName, location, propFullName) {
  549. var propValue = props[propName];
  550. for (var i = 0; i < expectedValues.length; i++) {
  551. if (is(propValue, expectedValues[i])) {
  552. return null;
  553. }
  554. }
  555. var valuesString = JSON.stringify(expectedValues);
  556. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
  557. }
  558. return createChainableTypeChecker(validate);
  559. }
  560. function createObjectOfTypeChecker(typeChecker) {
  561. function validate(props, propName, componentName, location, propFullName) {
  562. if (typeof typeChecker !== 'function') {
  563. return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
  564. }
  565. var propValue = props[propName];
  566. var propType = getPropType(propValue);
  567. if (propType !== 'object') {
  568. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
  569. }
  570. for (var key in propValue) {
  571. if (propValue.hasOwnProperty(key)) {
  572. var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  573. if (error instanceof Error) {
  574. return error;
  575. }
  576. }
  577. }
  578. return null;
  579. }
  580. return createChainableTypeChecker(validate);
  581. }
  582. function createUnionTypeChecker(arrayOfTypeCheckers) {
  583. if (!Array.isArray(arrayOfTypeCheckers)) {
  584. warning_1$1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.');
  585. return emptyFunction_1.thatReturnsNull;
  586. }
  587. for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
  588. var checker = arrayOfTypeCheckers[i];
  589. if (typeof checker !== 'function') {
  590. warning_1$1(
  591. false,
  592. 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
  593. 'received %s at index %s.',
  594. getPostfixForTypeWarning(checker),
  595. i
  596. );
  597. return emptyFunction_1.thatReturnsNull;
  598. }
  599. }
  600. function validate(props, propName, componentName, location, propFullName) {
  601. for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
  602. var checker = arrayOfTypeCheckers[i];
  603. if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
  604. return null;
  605. }
  606. }
  607. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
  608. }
  609. return createChainableTypeChecker(validate);
  610. }
  611. function createNodeChecker() {
  612. function validate(props, propName, componentName, location, propFullName) {
  613. if (!isNode(props[propName])) {
  614. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
  615. }
  616. return null;
  617. }
  618. return createChainableTypeChecker(validate);
  619. }
  620. function createShapeTypeChecker(shapeTypes) {
  621. function validate(props, propName, componentName, location, propFullName) {
  622. var propValue = props[propName];
  623. var propType = getPropType(propValue);
  624. if (propType !== 'object') {
  625. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
  626. }
  627. for (var key in shapeTypes) {
  628. var checker = shapeTypes[key];
  629. if (!checker) {
  630. continue;
  631. }
  632. var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  633. if (error) {
  634. return error;
  635. }
  636. }
  637. return null;
  638. }
  639. return createChainableTypeChecker(validate);
  640. }
  641. function createStrictShapeTypeChecker(shapeTypes) {
  642. function validate(props, propName, componentName, location, propFullName) {
  643. var propValue = props[propName];
  644. var propType = getPropType(propValue);
  645. if (propType !== 'object') {
  646. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
  647. }
  648. // We need to check all keys in case some are required but missing from
  649. // props.
  650. var allKeys = objectAssign({}, props[propName], shapeTypes);
  651. for (var key in allKeys) {
  652. var checker = shapeTypes[key];
  653. if (!checker) {
  654. return new PropTypeError(
  655. 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
  656. '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
  657. '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
  658. );
  659. }
  660. var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  661. if (error) {
  662. return error;
  663. }
  664. }
  665. return null;
  666. }
  667. return createChainableTypeChecker(validate);
  668. }
  669. function isNode(propValue) {
  670. switch (typeof propValue) {
  671. case 'number':
  672. case 'string':
  673. case 'undefined':
  674. return true;
  675. case 'boolean':
  676. return !propValue;
  677. case 'object':
  678. if (Array.isArray(propValue)) {
  679. return propValue.every(isNode);
  680. }
  681. if (propValue === null || isValidElement(propValue)) {
  682. return true;
  683. }
  684. var iteratorFn = getIteratorFn(propValue);
  685. if (iteratorFn) {
  686. var iterator = iteratorFn.call(propValue);
  687. var step;
  688. if (iteratorFn !== propValue.entries) {
  689. while (!(step = iterator.next()).done) {
  690. if (!isNode(step.value)) {
  691. return false;
  692. }
  693. }
  694. } else {
  695. // Iterator will provide entry [k,v] tuples rather than values.
  696. while (!(step = iterator.next()).done) {
  697. var entry = step.value;
  698. if (entry) {
  699. if (!isNode(entry[1])) {
  700. return false;
  701. }
  702. }
  703. }
  704. }
  705. } else {
  706. return false;
  707. }
  708. return true;
  709. default:
  710. return false;
  711. }
  712. }
  713. function isSymbol(propType, propValue) {
  714. // Native Symbol.
  715. if (propType === 'symbol') {
  716. return true;
  717. }
  718. // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
  719. if (propValue['@@toStringTag'] === 'Symbol') {
  720. return true;
  721. }
  722. // Fallback for non-spec compliant Symbols which are polyfilled.
  723. if (typeof Symbol === 'function' && propValue instanceof Symbol) {
  724. return true;
  725. }
  726. return false;
  727. }
  728. // Equivalent of `typeof` but with special handling for array and regexp.
  729. function getPropType(propValue) {
  730. var propType = typeof propValue;
  731. if (Array.isArray(propValue)) {
  732. return 'array';
  733. }
  734. if (propValue instanceof RegExp) {
  735. // Old webkits (at least until Android 4.0) return 'function' rather than
  736. // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
  737. // passes PropTypes.object.
  738. return 'object';
  739. }
  740. if (isSymbol(propType, propValue)) {
  741. return 'symbol';
  742. }
  743. return propType;
  744. }
  745. // This handles more types than `getPropType`. Only used for error messages.
  746. // See `createPrimitiveTypeChecker`.
  747. function getPreciseType(propValue) {
  748. if (typeof propValue === 'undefined' || propValue === null) {
  749. return '' + propValue;
  750. }
  751. var propType = getPropType(propValue);
  752. if (propType === 'object') {
  753. if (propValue instanceof Date) {
  754. return 'date';
  755. } else if (propValue instanceof RegExp) {
  756. return 'regexp';
  757. }
  758. }
  759. return propType;
  760. }
  761. // Returns a string that is postfixed to a warning about an invalid type.
  762. // For example, "undefined" or "of type array"
  763. function getPostfixForTypeWarning(value) {
  764. var type = getPreciseType(value);
  765. switch (type) {
  766. case 'array':
  767. case 'object':
  768. return 'an ' + type;
  769. case 'boolean':
  770. case 'date':
  771. case 'regexp':
  772. return 'a ' + type;
  773. default:
  774. return type;
  775. }
  776. }
  777. // Returns class name of the object, if any.
  778. function getClassName(propValue) {
  779. if (!propValue.constructor || !propValue.constructor.name) {
  780. return ANONYMOUS;
  781. }
  782. return propValue.constructor.name;
  783. }
  784. ReactPropTypes.checkPropTypes = checkPropTypes_1;
  785. ReactPropTypes.PropTypes = ReactPropTypes;
  786. return ReactPropTypes;
  787. };
  788. var propTypes = createCommonjsModule(function (module) {
  789. /**
  790. * Copyright (c) 2013-present, Facebook, Inc.
  791. *
  792. * This source code is licensed under the MIT license found in the
  793. * LICENSE file in the root directory of this source tree.
  794. */
  795. {
  796. var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
  797. Symbol.for &&
  798. Symbol.for('react.element')) ||
  799. 0xeac7;
  800. var isValidElement = function(object) {
  801. return typeof object === 'object' &&
  802. object !== null &&
  803. object.$$typeof === REACT_ELEMENT_TYPE;
  804. };
  805. // By explicitly using `prop-types` you are opting into new development behavior.
  806. // http://fb.me/prop-types-in-prod
  807. var throwOnDirectAccess = true;
  808. module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess);
  809. }
  810. });
  811. /**
  812. * Copyright 2014-2015, Facebook, Inc.
  813. * All rights reserved.
  814. *
  815. * This source code is licensed under the BSD-style license found in the
  816. * LICENSE file in the root directory of this source tree. An additional grant
  817. * of patent rights can be found in the PATENTS file in the same directory.
  818. */
  819. var warning$3 = function() {};
  820. {
  821. warning$3 = function(condition, format, args) {
  822. var len = arguments.length;
  823. args = new Array(len > 2 ? len - 2 : 0);
  824. for (var key = 2; key < len; key++) {
  825. args[key - 2] = arguments[key];
  826. }
  827. if (format === undefined) {
  828. throw new Error(
  829. '`warning(condition, format, ...args)` requires a warning ' +
  830. 'message argument'
  831. );
  832. }
  833. if (format.length < 10 || (/^[s\W]*$/).test(format)) {
  834. throw new Error(
  835. 'The warning format should be able to uniquely identify this ' +
  836. 'warning. Please, use a more descriptive format than: ' + format
  837. );
  838. }
  839. if (!condition) {
  840. var argIndex = 0;
  841. var message = 'Warning: ' +
  842. format.replace(/%s/g, function() {
  843. return args[argIndex++];
  844. });
  845. if (typeof console !== 'undefined') {
  846. console.error(message);
  847. }
  848. try {
  849. // This error was thrown as a convenience so that you can use this stack
  850. // to find the callsite that caused this warning to fire.
  851. throw new Error(message);
  852. } catch(x) {}
  853. }
  854. };
  855. }
  856. var warning_1$2 = warning$3;
  857. /**
  858. * Copyright (c) 2013-present, Facebook, Inc.
  859. *
  860. * This source code is licensed under the MIT license found in the
  861. * LICENSE file in the root directory of this source tree.
  862. */
  863. var invariant$2 = function(condition, format, a, b, c, d, e, f) {
  864. {
  865. if (format === undefined) {
  866. throw new Error('invariant requires an error message argument');
  867. }
  868. }
  869. if (!condition) {
  870. var error;
  871. if (format === undefined) {
  872. error = new Error(
  873. 'Minified exception occurred; use the non-minified dev environment ' +
  874. 'for the full error message and additional helpful warnings.'
  875. );
  876. } else {
  877. var args = [a, b, c, d, e, f];
  878. var argIndex = 0;
  879. error = new Error(
  880. format.replace(/%s/g, function() { return args[argIndex++]; })
  881. );
  882. error.name = 'Invariant Violation';
  883. }
  884. error.framesToPop = 1; // we don't care about invariant's own frame
  885. throw error;
  886. }
  887. };
  888. var invariant_1$1 = invariant$2;
  889. function isAbsolute(pathname) {
  890. return pathname.charAt(0) === '/';
  891. }
  892. // About 1.5x faster than the two-arg version of Array#splice()
  893. function spliceOne(list, index) {
  894. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
  895. list[i] = list[k];
  896. }
  897. list.pop();
  898. }
  899. // This implementation is based heavily on node's url.parse
  900. function resolvePathname(to) {
  901. var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  902. var toParts = to && to.split('/') || [];
  903. var fromParts = from && from.split('/') || [];
  904. var isToAbs = to && isAbsolute(to);
  905. var isFromAbs = from && isAbsolute(from);
  906. var mustEndAbs = isToAbs || isFromAbs;
  907. if (to && isAbsolute(to)) {
  908. // to is absolute
  909. fromParts = toParts;
  910. } else if (toParts.length) {
  911. // to is relative, drop the filename
  912. fromParts.pop();
  913. fromParts = fromParts.concat(toParts);
  914. }
  915. if (!fromParts.length) return '/';
  916. var hasTrailingSlash = void 0;
  917. if (fromParts.length) {
  918. var last = fromParts[fromParts.length - 1];
  919. hasTrailingSlash = last === '.' || last === '..' || last === '';
  920. } else {
  921. hasTrailingSlash = false;
  922. }
  923. var up = 0;
  924. for (var i = fromParts.length; i >= 0; i--) {
  925. var part = fromParts[i];
  926. if (part === '.') {
  927. spliceOne(fromParts, i);
  928. } else if (part === '..') {
  929. spliceOne(fromParts, i);
  930. up++;
  931. } else if (up) {
  932. spliceOne(fromParts, i);
  933. up--;
  934. }
  935. }
  936. if (!mustEndAbs) for (; up--; up) {
  937. fromParts.unshift('..');
  938. }if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift('');
  939. var result = fromParts.join('/');
  940. if (hasTrailingSlash && result.substr(-1) !== '/') result += '/';
  941. return result;
  942. }
  943. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  944. function valueEqual(a, b) {
  945. if (a === b) return true;
  946. if (a == null || b == null) return false;
  947. if (Array.isArray(a)) {
  948. return Array.isArray(b) && a.length === b.length && a.every(function (item, index) {
  949. return valueEqual(item, b[index]);
  950. });
  951. }
  952. var aType = typeof a === 'undefined' ? 'undefined' : _typeof(a);
  953. var bType = typeof b === 'undefined' ? 'undefined' : _typeof(b);
  954. if (aType !== bType) return false;
  955. if (aType === 'object') {
  956. var aValue = a.valueOf();
  957. var bValue = b.valueOf();
  958. if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue);
  959. var aKeys = Object.keys(a);
  960. var bKeys = Object.keys(b);
  961. if (aKeys.length !== bKeys.length) return false;
  962. return aKeys.every(function (key) {
  963. return valueEqual(a[key], b[key]);
  964. });
  965. }
  966. return false;
  967. }
  968. var parsePath = function parsePath(path) {
  969. var pathname = path || '/';
  970. var search = '';
  971. var hash = '';
  972. var hashIndex = pathname.indexOf('#');
  973. if (hashIndex !== -1) {
  974. hash = pathname.substr(hashIndex);
  975. pathname = pathname.substr(0, hashIndex);
  976. }
  977. var searchIndex = pathname.indexOf('?');
  978. if (searchIndex !== -1) {
  979. search = pathname.substr(searchIndex);
  980. pathname = pathname.substr(0, searchIndex);
  981. }
  982. return {
  983. pathname: pathname,
  984. search: search === '?' ? '' : search,
  985. hash: hash === '#' ? '' : hash
  986. };
  987. };
  988. var createPath = function createPath(location) {
  989. var pathname = location.pathname,
  990. search = location.search,
  991. hash = location.hash;
  992. var path = pathname || '/';
  993. if (search && search !== '?') path += search.charAt(0) === '?' ? search : '?' + search;
  994. if (hash && hash !== '#') path += hash.charAt(0) === '#' ? hash : '#' + hash;
  995. return path;
  996. };
  997. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  998. var createLocation = function createLocation(path, state, key, currentLocation) {
  999. var location = void 0;
  1000. if (typeof path === 'string') {
  1001. // Two-arg form: push(path, state)
  1002. location = parsePath(path);
  1003. location.state = state;
  1004. } else {
  1005. // One-arg form: push(location)
  1006. location = _extends({}, path);
  1007. if (location.pathname === undefined) location.pathname = '';
  1008. if (location.search) {
  1009. if (location.search.charAt(0) !== '?') location.search = '?' + location.search;
  1010. } else {
  1011. location.search = '';
  1012. }
  1013. if (location.hash) {
  1014. if (location.hash.charAt(0) !== '#') location.hash = '#' + location.hash;
  1015. } else {
  1016. location.hash = '';
  1017. }
  1018. if (state !== undefined && location.state === undefined) location.state = state;
  1019. }
  1020. try {
  1021. location.pathname = decodeURI(location.pathname);
  1022. } catch (e) {
  1023. if (e instanceof URIError) {
  1024. throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.');
  1025. } else {
  1026. throw e;
  1027. }
  1028. }
  1029. if (key) location.key = key;
  1030. if (currentLocation) {
  1031. // Resolve incomplete/relative pathname relative to current location.
  1032. if (!location.pathname) {
  1033. location.pathname = currentLocation.pathname;
  1034. } else if (location.pathname.charAt(0) !== '/') {
  1035. location.pathname = resolvePathname(location.pathname, currentLocation.pathname);
  1036. }
  1037. } else {
  1038. // When there is no prior location and pathname is empty, set it to /
  1039. if (!location.pathname) {
  1040. location.pathname = '/';
  1041. }
  1042. }
  1043. return location;
  1044. };
  1045. var locationsAreEqual = function locationsAreEqual(a, b) {
  1046. return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && valueEqual(a.state, b.state);
  1047. };
  1048. var createTransitionManager = function createTransitionManager() {
  1049. var prompt = null;
  1050. var setPrompt = function setPrompt(nextPrompt) {
  1051. warning_1$2(prompt == null, 'A history supports only one prompt at a time');
  1052. prompt = nextPrompt;
  1053. return function () {
  1054. if (prompt === nextPrompt) prompt = null;
  1055. };
  1056. };
  1057. var confirmTransitionTo = function confirmTransitionTo(location, action, getUserConfirmation, callback) {
  1058. // TODO: If another transition starts while we're still confirming
  1059. // the previous one, we may end up in a weird state. Figure out the
  1060. // best way to handle this.
  1061. if (prompt != null) {
  1062. var result = typeof prompt === 'function' ? prompt(location, action) : prompt;
  1063. if (typeof result === 'string') {
  1064. if (typeof getUserConfirmation === 'function') {
  1065. getUserConfirmation(result, callback);
  1066. } else {
  1067. warning_1$2(false, 'A history needs a getUserConfirmation function in order to use a prompt message');
  1068. callback(true);
  1069. }
  1070. } else {
  1071. // Return false from a transition hook to cancel the transition.
  1072. callback(result !== false);
  1073. }
  1074. } else {
  1075. callback(true);
  1076. }
  1077. };
  1078. var listeners = [];
  1079. var appendListener = function appendListener(fn) {
  1080. var isActive = true;
  1081. var listener = function listener() {
  1082. if (isActive) fn.apply(undefined, arguments);
  1083. };
  1084. listeners.push(listener);
  1085. return function () {
  1086. isActive = false;
  1087. listeners = listeners.filter(function (item) {
  1088. return item !== listener;
  1089. });
  1090. };
  1091. };
  1092. var notifyListeners = function notifyListeners() {
  1093. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1094. args[_key] = arguments[_key];
  1095. }
  1096. listeners.forEach(function (listener) {
  1097. return listener.apply(undefined, args);
  1098. });
  1099. };
  1100. return {
  1101. setPrompt: setPrompt,
  1102. confirmTransitionTo: confirmTransitionTo,
  1103. appendListener: appendListener,
  1104. notifyListeners: notifyListeners
  1105. };
  1106. };
  1107. var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
  1108. var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1109. var _extends$3 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  1110. var clamp = function clamp(n, lowerBound, upperBound) {
  1111. return Math.min(Math.max(n, lowerBound), upperBound);
  1112. };
  1113. /**
  1114. * Creates a history object that stores locations in memory.
  1115. */
  1116. var createMemoryHistory = function createMemoryHistory() {
  1117. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1118. var getUserConfirmation = props.getUserConfirmation,
  1119. _props$initialEntries = props.initialEntries,
  1120. initialEntries = _props$initialEntries === undefined ? ['/'] : _props$initialEntries,
  1121. _props$initialIndex = props.initialIndex,
  1122. initialIndex = _props$initialIndex === undefined ? 0 : _props$initialIndex,
  1123. _props$keyLength = props.keyLength,
  1124. keyLength = _props$keyLength === undefined ? 6 : _props$keyLength;
  1125. var transitionManager = createTransitionManager();
  1126. var setState = function setState(nextState) {
  1127. _extends$3(history, nextState);
  1128. history.length = history.entries.length;
  1129. transitionManager.notifyListeners(history.location, history.action);
  1130. };
  1131. var createKey = function createKey() {
  1132. return Math.random().toString(36).substr(2, keyLength);
  1133. };
  1134. var index = clamp(initialIndex, 0, initialEntries.length - 1);
  1135. var entries = initialEntries.map(function (entry) {
  1136. return typeof entry === 'string' ? createLocation(entry, undefined, createKey()) : createLocation(entry, undefined, entry.key || createKey());
  1137. });
  1138. // Public interface
  1139. var createHref = createPath;
  1140. var push = function push(path, state) {
  1141. warning_1$2(!((typeof path === 'undefined' ? 'undefined' : _typeof$2(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored');
  1142. var action = 'PUSH';
  1143. var location = createLocation(path, state, createKey(), history.location);
  1144. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1145. if (!ok) return;
  1146. var prevIndex = history.index;
  1147. var nextIndex = prevIndex + 1;
  1148. var nextEntries = history.entries.slice(0);
  1149. if (nextEntries.length > nextIndex) {
  1150. nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location);
  1151. } else {
  1152. nextEntries.push(location);
  1153. }
  1154. setState({
  1155. action: action,
  1156. location: location,
  1157. index: nextIndex,
  1158. entries: nextEntries
  1159. });
  1160. });
  1161. };
  1162. var replace = function replace(path, state) {
  1163. warning_1$2(!((typeof path === 'undefined' ? 'undefined' : _typeof$2(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored');
  1164. var action = 'REPLACE';
  1165. var location = createLocation(path, state, createKey(), history.location);
  1166. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1167. if (!ok) return;
  1168. history.entries[history.index] = location;
  1169. setState({ action: action, location: location });
  1170. });
  1171. };
  1172. var go = function go(n) {
  1173. var nextIndex = clamp(history.index + n, 0, history.entries.length - 1);
  1174. var action = 'POP';
  1175. var location = history.entries[nextIndex];
  1176. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1177. if (ok) {
  1178. setState({
  1179. action: action,
  1180. location: location,
  1181. index: nextIndex
  1182. });
  1183. } else {
  1184. // Mimic the behavior of DOM histories by
  1185. // causing a render after a cancelled POP.
  1186. setState();
  1187. }
  1188. });
  1189. };
  1190. var goBack = function goBack() {
  1191. return go(-1);
  1192. };
  1193. var goForward = function goForward() {
  1194. return go(1);
  1195. };
  1196. var canGo = function canGo(n) {
  1197. var nextIndex = history.index + n;
  1198. return nextIndex >= 0 && nextIndex < history.entries.length;
  1199. };
  1200. var block = function block() {
  1201. var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1202. return transitionManager.setPrompt(prompt);
  1203. };
  1204. var listen = function listen(listener) {
  1205. return transitionManager.appendListener(listener);
  1206. };
  1207. var history = {
  1208. length: entries.length,
  1209. action: 'POP',
  1210. location: entries[index],
  1211. index: index,
  1212. entries: entries,
  1213. createHref: createHref,
  1214. push: push,
  1215. replace: replace,
  1216. go: go,
  1217. goBack: goBack,
  1218. goForward: goForward,
  1219. canGo: canGo,
  1220. block: block,
  1221. listen: listen
  1222. };
  1223. return history;
  1224. };
  1225. var classCallCheck = function (instance, Constructor) {
  1226. if (!(instance instanceof Constructor)) {
  1227. throw new TypeError("Cannot call a class as a function");
  1228. }
  1229. };
  1230. var _extends$4 = Object.assign || function (target) {
  1231. for (var i = 1; i < arguments.length; i++) {
  1232. var source = arguments[i];
  1233. for (var key in source) {
  1234. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1235. target[key] = source[key];
  1236. }
  1237. }
  1238. }
  1239. return target;
  1240. };
  1241. var inherits = function (subClass, superClass) {
  1242. if (typeof superClass !== "function" && superClass !== null) {
  1243. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  1244. }
  1245. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1246. constructor: {
  1247. value: subClass,
  1248. enumerable: false,
  1249. writable: true,
  1250. configurable: true
  1251. }
  1252. });
  1253. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  1254. };
  1255. var objectWithoutProperties = function (obj, keys) {
  1256. var target = {};
  1257. for (var i in obj) {
  1258. if (keys.indexOf(i) >= 0) continue;
  1259. if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
  1260. target[i] = obj[i];
  1261. }
  1262. return target;
  1263. };
  1264. var possibleConstructorReturn = function (self, call) {
  1265. if (!self) {
  1266. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1267. }
  1268. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  1269. };
  1270. /**
  1271. * The public API for putting history on context.
  1272. */
  1273. var Router = function (_React$Component) {
  1274. inherits(Router, _React$Component);
  1275. function Router() {
  1276. var _temp, _this, _ret;
  1277. classCallCheck(this, Router);
  1278. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1279. args[_key] = arguments[_key];
  1280. }
  1281. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  1282. match: _this.computeMatch(_this.props.history.location.pathname)
  1283. }, _temp), possibleConstructorReturn(_this, _ret);
  1284. }
  1285. Router.prototype.getChildContext = function getChildContext() {
  1286. return {
  1287. router: _extends$4({}, this.context.router, {
  1288. history: this.props.history,
  1289. route: {
  1290. location: this.props.history.location,
  1291. match: this.state.match
  1292. }
  1293. })
  1294. };
  1295. };
  1296. Router.prototype.computeMatch = function computeMatch(pathname) {
  1297. return {
  1298. path: "/",
  1299. url: "/",
  1300. params: {},
  1301. isExact: pathname === "/"
  1302. };
  1303. };
  1304. Router.prototype.componentWillMount = function componentWillMount() {
  1305. var _this2 = this;
  1306. var _props = this.props,
  1307. children = _props.children,
  1308. history = _props.history;
  1309. invariant_1$1(children == null || React.Children.count(children) === 1, "A <Router> may have only one child element");
  1310. // Do this here so we can setState when a <Redirect> changes the
  1311. // location in componentWillMount. This happens e.g. when doing
  1312. // server rendering using a <StaticRouter>.
  1313. this.unlisten = history.listen(function () {
  1314. _this2.setState({
  1315. match: _this2.computeMatch(history.location.pathname)
  1316. });
  1317. });
  1318. };
  1319. Router.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  1320. warning_1(this.props.history === nextProps.history, "You cannot change <Router history>");
  1321. };
  1322. Router.prototype.componentWillUnmount = function componentWillUnmount() {
  1323. this.unlisten();
  1324. };
  1325. Router.prototype.render = function render() {
  1326. var children = this.props.children;
  1327. return children ? React.Children.only(children) : null;
  1328. };
  1329. return Router;
  1330. }(React.Component);
  1331. Router.propTypes = {
  1332. history: propTypes.object.isRequired,
  1333. children: propTypes.node
  1334. };
  1335. Router.contextTypes = {
  1336. router: propTypes.object
  1337. };
  1338. Router.childContextTypes = {
  1339. router: propTypes.object.isRequired
  1340. };
  1341. /**
  1342. * The public API for a <Router> that stores location in memory.
  1343. */
  1344. var MemoryRouter = function (_React$Component) {
  1345. inherits(MemoryRouter, _React$Component);
  1346. function MemoryRouter() {
  1347. var _temp, _this, _ret;
  1348. classCallCheck(this, MemoryRouter);
  1349. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1350. args[_key] = arguments[_key];
  1351. }
  1352. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = createMemoryHistory(_this.props), _temp), possibleConstructorReturn(_this, _ret);
  1353. }
  1354. MemoryRouter.prototype.componentWillMount = function componentWillMount() {
  1355. warning_1(!this.props.history, "<MemoryRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { MemoryRouter as Router }`.");
  1356. };
  1357. MemoryRouter.prototype.render = function render() {
  1358. return React.createElement(Router, { history: this.history, children: this.props.children });
  1359. };
  1360. return MemoryRouter;
  1361. }(React.Component);
  1362. MemoryRouter.propTypes = {
  1363. initialEntries: propTypes.array,
  1364. initialIndex: propTypes.number,
  1365. getUserConfirmation: propTypes.func,
  1366. keyLength: propTypes.number,
  1367. children: propTypes.node
  1368. };
  1369. /**
  1370. * The public API for prompting the user before navigating away
  1371. * from a screen with a component.
  1372. */
  1373. var Prompt = function (_React$Component) {
  1374. inherits(Prompt, _React$Component);
  1375. function Prompt() {
  1376. classCallCheck(this, Prompt);
  1377. return possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  1378. }
  1379. Prompt.prototype.enable = function enable(message) {
  1380. if (this.unblock) this.unblock();
  1381. this.unblock = this.context.router.history.block(message);
  1382. };
  1383. Prompt.prototype.disable = function disable() {
  1384. if (this.unblock) {
  1385. this.unblock();
  1386. this.unblock = null;
  1387. }
  1388. };
  1389. Prompt.prototype.componentWillMount = function componentWillMount() {
  1390. invariant_1$1(this.context.router, "You should not use <Prompt> outside a <Router>");
  1391. if (this.props.when) this.enable(this.props.message);
  1392. };
  1393. Prompt.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  1394. if (nextProps.when) {
  1395. if (!this.props.when || this.props.message !== nextProps.message) this.enable(nextProps.message);
  1396. } else {
  1397. this.disable();
  1398. }
  1399. };
  1400. Prompt.prototype.componentWillUnmount = function componentWillUnmount() {
  1401. this.disable();
  1402. };
  1403. Prompt.prototype.render = function render() {
  1404. return null;
  1405. };
  1406. return Prompt;
  1407. }(React.Component);
  1408. Prompt.propTypes = {
  1409. when: propTypes.bool,
  1410. message: propTypes.oneOfType([propTypes.func, propTypes.string]).isRequired
  1411. };
  1412. Prompt.defaultProps = {
  1413. when: true
  1414. };
  1415. Prompt.contextTypes = {
  1416. router: propTypes.shape({
  1417. history: propTypes.shape({
  1418. block: propTypes.func.isRequired
  1419. }).isRequired
  1420. }).isRequired
  1421. };
  1422. var isarray = Array.isArray || function (arr) {
  1423. return Object.prototype.toString.call(arr) == '[object Array]';
  1424. };
  1425. /**
  1426. * Expose `pathToRegexp`.
  1427. */
  1428. var pathToRegexp_1 = pathToRegexp;
  1429. var parse_1 = parse;
  1430. var compile_1 = compile;
  1431. var tokensToFunction_1 = tokensToFunction;
  1432. var tokensToRegExp_1 = tokensToRegExp;
  1433. /**
  1434. * The main path matching regexp utility.
  1435. *
  1436. * @type {RegExp}
  1437. */
  1438. var PATH_REGEXP = new RegExp([
  1439. // Match escaped characters that would otherwise appear in future matches.
  1440. // This allows the user to escape special characters that won't transform.
  1441. '(\\\\.)',
  1442. // Match Express-style parameters and un-named parameters with a prefix
  1443. // and optional suffixes. Matches appear as:
  1444. //
  1445. // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
  1446. // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
  1447. // "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
  1448. '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
  1449. ].join('|'), 'g');
  1450. /**
  1451. * Parse a string for the raw tokens.
  1452. *
  1453. * @param {string} str
  1454. * @param {Object=} options
  1455. * @return {!Array}
  1456. */
  1457. function parse (str, options) {
  1458. var tokens = [];
  1459. var key = 0;
  1460. var index = 0;
  1461. var path = '';
  1462. var defaultDelimiter = options && options.delimiter || '/';
  1463. var res;
  1464. while ((res = PATH_REGEXP.exec(str)) != null) {
  1465. var m = res[0];
  1466. var escaped = res[1];
  1467. var offset = res.index;
  1468. path += str.slice(index, offset);
  1469. index = offset + m.length;
  1470. // Ignore already escaped sequences.
  1471. if (escaped) {
  1472. path += escaped[1];
  1473. continue
  1474. }
  1475. var next = str[index];
  1476. var prefix = res[2];
  1477. var name = res[3];
  1478. var capture = res[4];
  1479. var group = res[5];
  1480. var modifier = res[6];
  1481. var asterisk = res[7];
  1482. // Push the current path onto the tokens.
  1483. if (path) {
  1484. tokens.push(path);
  1485. path = '';
  1486. }
  1487. var partial = prefix != null && next != null && next !== prefix;
  1488. var repeat = modifier === '+' || modifier === '*';
  1489. var optional = modifier === '?' || modifier === '*';
  1490. var delimiter = res[2] || defaultDelimiter;
  1491. var pattern = capture || group;
  1492. tokens.push({
  1493. name: name || key++,
  1494. prefix: prefix || '',
  1495. delimiter: delimiter,
  1496. optional: optional,
  1497. repeat: repeat,
  1498. partial: partial,
  1499. asterisk: !!asterisk,
  1500. pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
  1501. });
  1502. }
  1503. // Match any characters still remaining.
  1504. if (index < str.length) {
  1505. path += str.substr(index);
  1506. }
  1507. // If the path exists, push it onto the end.
  1508. if (path) {
  1509. tokens.push(path);
  1510. }
  1511. return tokens
  1512. }
  1513. /**
  1514. * Compile a string to a template function for the path.
  1515. *
  1516. * @param {string} str
  1517. * @param {Object=} options
  1518. * @return {!function(Object=, Object=)}
  1519. */
  1520. function compile (str, options) {
  1521. return tokensToFunction(parse(str, options))
  1522. }
  1523. /**
  1524. * Prettier encoding of URI path segments.
  1525. *
  1526. * @param {string}
  1527. * @return {string}
  1528. */
  1529. function encodeURIComponentPretty (str) {
  1530. return encodeURI(str).replace(/[\/?#]/g, function (c) {
  1531. return '%' + c.charCodeAt(0).toString(16).toUpperCase()
  1532. })
  1533. }
  1534. /**
  1535. * Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
  1536. *
  1537. * @param {string}
  1538. * @return {string}
  1539. */
  1540. function encodeAsterisk (str) {
  1541. return encodeURI(str).replace(/[?#]/g, function (c) {
  1542. return '%' + c.charCodeAt(0).toString(16).toUpperCase()
  1543. })
  1544. }
  1545. /**
  1546. * Expose a method for transforming tokens into the path function.
  1547. */
  1548. function tokensToFunction (tokens) {
  1549. // Compile all the tokens into regexps.
  1550. var matches = new Array(tokens.length);
  1551. // Compile all the patterns before compilation.
  1552. for (var i = 0; i < tokens.length; i++) {
  1553. if (typeof tokens[i] === 'object') {
  1554. matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$');
  1555. }
  1556. }
  1557. return function (obj, opts) {
  1558. var path = '';
  1559. var data = obj || {};
  1560. var options = opts || {};
  1561. var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
  1562. for (var i = 0; i < tokens.length; i++) {
  1563. var token = tokens[i];
  1564. if (typeof token === 'string') {
  1565. path += token;
  1566. continue
  1567. }
  1568. var value = data[token.name];
  1569. var segment;
  1570. if (value == null) {
  1571. if (token.optional) {
  1572. // Prepend partial segment prefixes.
  1573. if (token.partial) {
  1574. path += token.prefix;
  1575. }
  1576. continue
  1577. } else {
  1578. throw new TypeError('Expected "' + token.name + '" to be defined')
  1579. }
  1580. }
  1581. if (isarray(value)) {
  1582. if (!token.repeat) {
  1583. throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
  1584. }
  1585. if (value.length === 0) {
  1586. if (token.optional) {
  1587. continue
  1588. } else {
  1589. throw new TypeError('Expected "' + token.name + '" to not be empty')
  1590. }
  1591. }
  1592. for (var j = 0; j < value.length; j++) {
  1593. segment = encode(value[j]);
  1594. if (!matches[i].test(segment)) {
  1595. throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
  1596. }
  1597. path += (j === 0 ? token.prefix : token.delimiter) + segment;
  1598. }
  1599. continue
  1600. }
  1601. segment = token.asterisk ? encodeAsterisk(value) : encode(value);
  1602. if (!matches[i].test(segment)) {
  1603. throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
  1604. }
  1605. path += token.prefix + segment;
  1606. }
  1607. return path
  1608. }
  1609. }
  1610. /**
  1611. * Escape a regular expression string.
  1612. *
  1613. * @param {string} str
  1614. * @return {string}
  1615. */
  1616. function escapeString (str) {
  1617. return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
  1618. }
  1619. /**
  1620. * Escape the capturing group by escaping special characters and meaning.
  1621. *
  1622. * @param {string} group
  1623. * @return {string}
  1624. */
  1625. function escapeGroup (group) {
  1626. return group.replace(/([=!:$\/()])/g, '\\$1')
  1627. }
  1628. /**
  1629. * Attach the keys as a property of the regexp.
  1630. *
  1631. * @param {!RegExp} re
  1632. * @param {Array} keys
  1633. * @return {!RegExp}
  1634. */
  1635. function attachKeys (re, keys) {
  1636. re.keys = keys;
  1637. return re
  1638. }
  1639. /**
  1640. * Get the flags for a regexp from the options.
  1641. *
  1642. * @param {Object} options
  1643. * @return {string}
  1644. */
  1645. function flags (options) {
  1646. return options.sensitive ? '' : 'i'
  1647. }
  1648. /**
  1649. * Pull out keys from a regexp.
  1650. *
  1651. * @param {!RegExp} path
  1652. * @param {!Array} keys
  1653. * @return {!RegExp}
  1654. */
  1655. function regexpToRegexp (path, keys) {
  1656. // Use a negative lookahead to match only capturing groups.
  1657. var groups = path.source.match(/\((?!\?)/g);
  1658. if (groups) {
  1659. for (var i = 0; i < groups.length; i++) {
  1660. keys.push({
  1661. name: i,
  1662. prefix: null,
  1663. delimiter: null,
  1664. optional: false,
  1665. repeat: false,
  1666. partial: false,
  1667. asterisk: false,
  1668. pattern: null
  1669. });
  1670. }
  1671. }
  1672. return attachKeys(path, keys)
  1673. }
  1674. /**
  1675. * Transform an array into a regexp.
  1676. *
  1677. * @param {!Array} path
  1678. * @param {Array} keys
  1679. * @param {!Object} options
  1680. * @return {!RegExp}
  1681. */
  1682. function arrayToRegexp (path, keys, options) {
  1683. var parts = [];
  1684. for (var i = 0; i < path.length; i++) {
  1685. parts.push(pathToRegexp(path[i], keys, options).source);
  1686. }
  1687. var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
  1688. return attachKeys(regexp, keys)
  1689. }
  1690. /**
  1691. * Create a path regexp from string input.
  1692. *
  1693. * @param {string} path
  1694. * @param {!Array} keys
  1695. * @param {!Object} options
  1696. * @return {!RegExp}
  1697. */
  1698. function stringToRegexp (path, keys, options) {
  1699. return tokensToRegExp(parse(path, options), keys, options)
  1700. }
  1701. /**
  1702. * Expose a function for taking tokens and returning a RegExp.
  1703. *
  1704. * @param {!Array} tokens
  1705. * @param {(Array|Object)=} keys
  1706. * @param {Object=} options
  1707. * @return {!RegExp}
  1708. */
  1709. function tokensToRegExp (tokens, keys, options) {
  1710. if (!isarray(keys)) {
  1711. options = /** @type {!Object} */ (keys || options);
  1712. keys = [];
  1713. }
  1714. options = options || {};
  1715. var strict = options.strict;
  1716. var end = options.end !== false;
  1717. var route = '';
  1718. // Iterate over the tokens and create our regexp string.
  1719. for (var i = 0; i < tokens.length; i++) {
  1720. var token = tokens[i];
  1721. if (typeof token === 'string') {
  1722. route += escapeString(token);
  1723. } else {
  1724. var prefix = escapeString(token.prefix);
  1725. var capture = '(?:' + token.pattern + ')';
  1726. keys.push(token);
  1727. if (token.repeat) {
  1728. capture += '(?:' + prefix + capture + ')*';
  1729. }
  1730. if (token.optional) {
  1731. if (!token.partial) {
  1732. capture = '(?:' + prefix + '(' + capture + '))?';
  1733. } else {
  1734. capture = prefix + '(' + capture + ')?';
  1735. }
  1736. } else {
  1737. capture = prefix + '(' + capture + ')';
  1738. }
  1739. route += capture;
  1740. }
  1741. }
  1742. var delimiter = escapeString(options.delimiter || '/');
  1743. var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
  1744. // In non-strict mode we allow a slash at the end of match. If the path to
  1745. // match already ends with a slash, we remove it for consistency. The slash
  1746. // is valid at the end of a path match, not in the middle. This is important
  1747. // in non-ending mode, where "/test/" shouldn't match "/test//route".
  1748. if (!strict) {
  1749. route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
  1750. }
  1751. if (end) {
  1752. route += '$';
  1753. } else {
  1754. // In non-ending mode, we need the capturing groups to match as much as
  1755. // possible by using a positive lookahead to the end or next path segment.
  1756. route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
  1757. }
  1758. return attachKeys(new RegExp('^' + route, flags(options)), keys)
  1759. }
  1760. /**
  1761. * Normalize the given path string, returning a regular expression.
  1762. *
  1763. * An empty array can be passed in for the keys, which will hold the
  1764. * placeholder key descriptions. For example, using `/user/:id`, `keys` will
  1765. * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
  1766. *
  1767. * @param {(string|RegExp|Array)} path
  1768. * @param {(Array|Object)=} keys
  1769. * @param {Object=} options
  1770. * @return {!RegExp}
  1771. */
  1772. function pathToRegexp (path, keys, options) {
  1773. if (!isarray(keys)) {
  1774. options = /** @type {!Object} */ (keys || options);
  1775. keys = [];
  1776. }
  1777. options = options || {};
  1778. if (path instanceof RegExp) {
  1779. return regexpToRegexp(path, /** @type {!Array} */ (keys))
  1780. }
  1781. if (isarray(path)) {
  1782. return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
  1783. }
  1784. return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
  1785. }
  1786. pathToRegexp_1.parse = parse_1;
  1787. pathToRegexp_1.compile = compile_1;
  1788. pathToRegexp_1.tokensToFunction = tokensToFunction_1;
  1789. pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
  1790. var patternCache = {};
  1791. var cacheLimit = 10000;
  1792. var cacheCount = 0;
  1793. var compileGenerator = function compileGenerator(pattern) {
  1794. var cacheKey = pattern;
  1795. var cache = patternCache[cacheKey] || (patternCache[cacheKey] = {});
  1796. if (cache[pattern]) return cache[pattern];
  1797. var compiledGenerator = pathToRegexp_1.compile(pattern);
  1798. if (cacheCount < cacheLimit) {
  1799. cache[pattern] = compiledGenerator;
  1800. cacheCount++;
  1801. }
  1802. return compiledGenerator;
  1803. };
  1804. /**
  1805. * Public API for generating a URL pathname from a pattern and parameters.
  1806. */
  1807. var generatePath = function generatePath() {
  1808. var pattern = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "/";
  1809. var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1810. if (pattern === "/") {
  1811. return pattern;
  1812. }
  1813. var generator = compileGenerator(pattern);
  1814. return generator(params, { pretty: true });
  1815. };
  1816. /**
  1817. * The public API for updating the location programmatically
  1818. * with a component.
  1819. */
  1820. var Redirect = function (_React$Component) {
  1821. inherits(Redirect, _React$Component);
  1822. function Redirect() {
  1823. classCallCheck(this, Redirect);
  1824. return possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  1825. }
  1826. Redirect.prototype.isStatic = function isStatic() {
  1827. return this.context.router && this.context.router.staticContext;
  1828. };
  1829. Redirect.prototype.componentWillMount = function componentWillMount() {
  1830. invariant_1$1(this.context.router, "You should not use <Redirect> outside a <Router>");
  1831. if (this.isStatic()) this.perform();
  1832. };
  1833. Redirect.prototype.componentDidMount = function componentDidMount() {
  1834. if (!this.isStatic()) this.perform();
  1835. };
  1836. Redirect.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
  1837. var prevTo = createLocation(prevProps.to);
  1838. var nextTo = createLocation(this.props.to);
  1839. if (locationsAreEqual(prevTo, nextTo)) {
  1840. warning_1(false, "You tried to redirect to the same route you're currently on: " + ("\"" + nextTo.pathname + nextTo.search + "\""));
  1841. return;
  1842. }
  1843. this.perform();
  1844. };
  1845. Redirect.prototype.computeTo = function computeTo(_ref) {
  1846. var computedMatch = _ref.computedMatch,
  1847. to = _ref.to;
  1848. if (computedMatch) {
  1849. if (typeof to === "string") {
  1850. return generatePath(to, computedMatch.params);
  1851. } else {
  1852. return _extends$4({}, to, {
  1853. pathname: generatePath(to.pathname, computedMatch.params)
  1854. });
  1855. }
  1856. }
  1857. return to;
  1858. };
  1859. Redirect.prototype.perform = function perform() {
  1860. var history = this.context.router.history;
  1861. var push = this.props.push;
  1862. var to = this.computeTo(this.props);
  1863. if (push) {
  1864. history.push(to);
  1865. } else {
  1866. history.replace(to);
  1867. }
  1868. };
  1869. Redirect.prototype.render = function render() {
  1870. return null;
  1871. };
  1872. return Redirect;
  1873. }(React.Component);
  1874. Redirect.propTypes = {
  1875. computedMatch: propTypes.object, // private, from <Switch>
  1876. push: propTypes.bool,
  1877. from: propTypes.string,
  1878. to: propTypes.oneOfType([propTypes.string, propTypes.object]).isRequired
  1879. };
  1880. Redirect.defaultProps = {
  1881. push: false
  1882. };
  1883. Redirect.contextTypes = {
  1884. router: propTypes.shape({
  1885. history: propTypes.shape({
  1886. push: propTypes.func.isRequired,
  1887. replace: propTypes.func.isRequired
  1888. }).isRequired,
  1889. staticContext: propTypes.object
  1890. }).isRequired
  1891. };
  1892. var patternCache$1 = {};
  1893. var cacheLimit$1 = 10000;
  1894. var cacheCount$1 = 0;
  1895. var compilePath = function compilePath(pattern, options) {
  1896. var cacheKey = "" + options.end + options.strict + options.sensitive;
  1897. var cache = patternCache$1[cacheKey] || (patternCache$1[cacheKey] = {});
  1898. if (cache[pattern]) return cache[pattern];
  1899. var keys = [];
  1900. var re = pathToRegexp_1(pattern, keys, options);
  1901. var compiledPattern = { re: re, keys: keys };
  1902. if (cacheCount$1 < cacheLimit$1) {
  1903. cache[pattern] = compiledPattern;
  1904. cacheCount$1++;
  1905. }
  1906. return compiledPattern;
  1907. };
  1908. /**
  1909. * Public API for matching a URL pathname to a path pattern.
  1910. */
  1911. var matchPath = function matchPath(pathname) {
  1912. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1913. var parent = arguments[2];
  1914. if (typeof options === "string") options = { path: options };
  1915. var _options = options,
  1916. path = _options.path,
  1917. _options$exact = _options.exact,
  1918. exact = _options$exact === undefined ? false : _options$exact,
  1919. _options$strict = _options.strict,
  1920. strict = _options$strict === undefined ? false : _options$strict,
  1921. _options$sensitive = _options.sensitive,
  1922. sensitive = _options$sensitive === undefined ? false : _options$sensitive;
  1923. if (path == null) return parent;
  1924. var _compilePath = compilePath(path, { end: exact, strict: strict, sensitive: sensitive }),
  1925. re = _compilePath.re,
  1926. keys = _compilePath.keys;
  1927. var match = re.exec(pathname);
  1928. if (!match) return null;
  1929. var url = match[0],
  1930. values = match.slice(1);
  1931. var isExact = pathname === url;
  1932. if (exact && !isExact) return null;
  1933. return {
  1934. path: path, // the path pattern used to match
  1935. url: path === "/" && url === "" ? "/" : url, // the matched portion of the URL
  1936. isExact: isExact, // whether or not we matched exactly
  1937. params: keys.reduce(function (memo, key, index) {
  1938. memo[key.name] = values[index];
  1939. return memo;
  1940. }, {})
  1941. };
  1942. };
  1943. var isEmptyChildren = function isEmptyChildren(children) {
  1944. return React.Children.count(children) === 0;
  1945. };
  1946. /**
  1947. * The public API for matching a single path and rendering.
  1948. */
  1949. var Route = function (_React$Component) {
  1950. inherits(Route, _React$Component);
  1951. function Route() {
  1952. var _temp, _this, _ret;
  1953. classCallCheck(this, Route);
  1954. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1955. args[_key] = arguments[_key];
  1956. }
  1957. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  1958. match: _this.computeMatch(_this.props, _this.context.router)
  1959. }, _temp), possibleConstructorReturn(_this, _ret);
  1960. }
  1961. Route.prototype.getChildContext = function getChildContext() {
  1962. return {
  1963. router: _extends$4({}, this.context.router, {
  1964. route: {
  1965. location: this.props.location || this.context.router.route.location,
  1966. match: this.state.match
  1967. }
  1968. })
  1969. };
  1970. };
  1971. Route.prototype.computeMatch = function computeMatch(_ref, router) {
  1972. var computedMatch = _ref.computedMatch,
  1973. location = _ref.location,
  1974. path = _ref.path,
  1975. strict = _ref.strict,
  1976. exact = _ref.exact,
  1977. sensitive = _ref.sensitive;
  1978. if (computedMatch) return computedMatch; // <Switch> already computed the match for us
  1979. invariant_1$1(router, "You should not use <Route> or withRouter() outside a <Router>");
  1980. var route = router.route;
  1981. var pathname = (location || route.location).pathname;
  1982. return matchPath(pathname, { path: path, strict: strict, exact: exact, sensitive: sensitive }, route.match);
  1983. };
  1984. Route.prototype.componentWillMount = function componentWillMount() {
  1985. warning_1(!(this.props.component && this.props.render), "You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored");
  1986. warning_1(!(this.props.component && this.props.children && !isEmptyChildren(this.props.children)), "You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored");
  1987. warning_1(!(this.props.render && this.props.children && !isEmptyChildren(this.props.children)), "You should not use <Route render> and <Route children> in the same route; <Route children> will be ignored");
  1988. };
  1989. Route.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
  1990. warning_1(!(nextProps.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.');
  1991. warning_1(!(!nextProps.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.');
  1992. this.setState({
  1993. match: this.computeMatch(nextProps, nextContext.router)
  1994. });
  1995. };
  1996. Route.prototype.render = function render() {
  1997. var match = this.state.match;
  1998. var _props = this.props,
  1999. children = _props.children,
  2000. component = _props.component,
  2001. render = _props.render;
  2002. var _context$router = this.context.router,
  2003. history = _context$router.history,
  2004. route = _context$router.route,
  2005. staticContext = _context$router.staticContext;
  2006. var location = this.props.location || route.location;
  2007. var props = { match: match, location: location, history: history, staticContext: staticContext };
  2008. if (component) return match ? React.createElement(component, props) : null;
  2009. if (render) return match ? render(props) : null;
  2010. if (typeof children === "function") return children(props);
  2011. if (children && !isEmptyChildren(children)) return React.Children.only(children);
  2012. return null;
  2013. };
  2014. return Route;
  2015. }(React.Component);
  2016. Route.propTypes = {
  2017. computedMatch: propTypes.object, // private, from <Switch>
  2018. path: propTypes.string,
  2019. exact: propTypes.bool,
  2020. strict: propTypes.bool,
  2021. sensitive: propTypes.bool,
  2022. component: propTypes.func,
  2023. render: propTypes.func,
  2024. children: propTypes.oneOfType([propTypes.func, propTypes.node]),
  2025. location: propTypes.object
  2026. };
  2027. Route.contextTypes = {
  2028. router: propTypes.shape({
  2029. history: propTypes.object.isRequired,
  2030. route: propTypes.object.isRequired,
  2031. staticContext: propTypes.object
  2032. })
  2033. };
  2034. Route.childContextTypes = {
  2035. router: propTypes.object.isRequired
  2036. };
  2037. var addLeadingSlash$1 = function addLeadingSlash(path) {
  2038. return path.charAt(0) === "/" ? path : "/" + path;
  2039. };
  2040. var addBasename = function addBasename(basename, location) {
  2041. if (!basename) return location;
  2042. return _extends$4({}, location, {
  2043. pathname: addLeadingSlash$1(basename) + location.pathname
  2044. });
  2045. };
  2046. var stripBasename$1 = function stripBasename(basename, location) {
  2047. if (!basename) return location;
  2048. var base = addLeadingSlash$1(basename);
  2049. if (location.pathname.indexOf(base) !== 0) return location;
  2050. return _extends$4({}, location, {
  2051. pathname: location.pathname.substr(base.length)
  2052. });
  2053. };
  2054. var createURL = function createURL(location) {
  2055. return typeof location === "string" ? location : createPath(location);
  2056. };
  2057. var staticHandler = function staticHandler(methodName) {
  2058. return function () {
  2059. invariant_1$1(false, "You cannot %s with <StaticRouter>", methodName);
  2060. };
  2061. };
  2062. var noop = function noop() {};
  2063. /**
  2064. * The public top-level API for a "static" <Router>, so-called because it
  2065. * can't actually change the current location. Instead, it just records
  2066. * location changes in a context object. Useful mainly in testing and
  2067. * server-rendering scenarios.
  2068. */
  2069. var StaticRouter = function (_React$Component) {
  2070. inherits(StaticRouter, _React$Component);
  2071. function StaticRouter() {
  2072. var _temp, _this, _ret;
  2073. classCallCheck(this, StaticRouter);
  2074. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  2075. args[_key] = arguments[_key];
  2076. }
  2077. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.createHref = function (path) {
  2078. return addLeadingSlash$1(_this.props.basename + createURL(path));
  2079. }, _this.handlePush = function (location) {
  2080. var _this$props = _this.props,
  2081. basename = _this$props.basename,
  2082. context = _this$props.context;
  2083. context.action = "PUSH";
  2084. context.location = addBasename(basename, createLocation(location));
  2085. context.url = createURL(context.location);
  2086. }, _this.handleReplace = function (location) {
  2087. var _this$props2 = _this.props,
  2088. basename = _this$props2.basename,
  2089. context = _this$props2.context;
  2090. context.action = "REPLACE";
  2091. context.location = addBasename(basename, createLocation(location));
  2092. context.url = createURL(context.location);
  2093. }, _this.handleListen = function () {
  2094. return noop;
  2095. }, _this.handleBlock = function () {
  2096. return noop;
  2097. }, _temp), possibleConstructorReturn(_this, _ret);
  2098. }
  2099. StaticRouter.prototype.getChildContext = function getChildContext() {
  2100. return {
  2101. router: {
  2102. staticContext: this.props.context
  2103. }
  2104. };
  2105. };
  2106. StaticRouter.prototype.componentWillMount = function componentWillMount() {
  2107. warning_1(!this.props.history, "<StaticRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { StaticRouter as Router }`.");
  2108. };
  2109. StaticRouter.prototype.render = function render() {
  2110. var _props = this.props,
  2111. basename = _props.basename,
  2112. context = _props.context,
  2113. location = _props.location,
  2114. props = objectWithoutProperties(_props, ["basename", "context", "location"]);
  2115. var history = {
  2116. createHref: this.createHref,
  2117. action: "POP",
  2118. location: stripBasename$1(basename, createLocation(location)),
  2119. push: this.handlePush,
  2120. replace: this.handleReplace,
  2121. go: staticHandler("go"),
  2122. goBack: staticHandler("goBack"),
  2123. goForward: staticHandler("goForward"),
  2124. listen: this.handleListen,
  2125. block: this.handleBlock
  2126. };
  2127. return React.createElement(Router, _extends$4({}, props, { history: history }));
  2128. };
  2129. return StaticRouter;
  2130. }(React.Component);
  2131. StaticRouter.propTypes = {
  2132. basename: propTypes.string,
  2133. context: propTypes.object.isRequired,
  2134. location: propTypes.oneOfType([propTypes.string, propTypes.object])
  2135. };
  2136. StaticRouter.defaultProps = {
  2137. basename: "",
  2138. location: "/"
  2139. };
  2140. StaticRouter.childContextTypes = {
  2141. router: propTypes.object.isRequired
  2142. };
  2143. /**
  2144. * The public API for rendering the first <Route> that matches.
  2145. */
  2146. var Switch = function (_React$Component) {
  2147. inherits(Switch, _React$Component);
  2148. function Switch() {
  2149. classCallCheck(this, Switch);
  2150. return possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  2151. }
  2152. Switch.prototype.componentWillMount = function componentWillMount() {
  2153. invariant_1$1(this.context.router, "You should not use <Switch> outside a <Router>");
  2154. };
  2155. Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  2156. warning_1(!(nextProps.location && !this.props.location), '<Switch> 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.');
  2157. warning_1(!(!nextProps.location && this.props.location), '<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.');
  2158. };
  2159. Switch.prototype.render = function render() {
  2160. var route = this.context.router.route;
  2161. var children = this.props.children;
  2162. var location = this.props.location || route.location;
  2163. var match = void 0,
  2164. child = void 0;
  2165. React.Children.forEach(children, function (element) {
  2166. if (match == null && React.isValidElement(element)) {
  2167. var _element$props = element.props,
  2168. pathProp = _element$props.path,
  2169. exact = _element$props.exact,
  2170. strict = _element$props.strict,
  2171. sensitive = _element$props.sensitive,
  2172. from = _element$props.from;
  2173. var path = pathProp || from;
  2174. child = element;
  2175. match = matchPath(location.pathname, { path: path, exact: exact, strict: strict, sensitive: sensitive }, route.match);
  2176. }
  2177. });
  2178. return match ? React.cloneElement(child, { location: location, computedMatch: match }) : null;
  2179. };
  2180. return Switch;
  2181. }(React.Component);
  2182. Switch.contextTypes = {
  2183. router: propTypes.shape({
  2184. route: propTypes.object.isRequired
  2185. }).isRequired
  2186. };
  2187. Switch.propTypes = {
  2188. children: propTypes.node,
  2189. location: propTypes.object
  2190. };
  2191. var hoistNonReactStatics = createCommonjsModule(function (module, exports) {
  2192. /**
  2193. * Copyright 2015, Yahoo! Inc.
  2194. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  2195. */
  2196. (function (global, factory) {
  2197. module.exports = factory();
  2198. }(commonjsGlobal, (function () {
  2199. var REACT_STATICS = {
  2200. childContextTypes: true,
  2201. contextTypes: true,
  2202. defaultProps: true,
  2203. displayName: true,
  2204. getDefaultProps: true,
  2205. getDerivedStateFromProps: true,
  2206. mixins: true,
  2207. propTypes: true,
  2208. type: true
  2209. };
  2210. var KNOWN_STATICS = {
  2211. name: true,
  2212. length: true,
  2213. prototype: true,
  2214. caller: true,
  2215. callee: true,
  2216. arguments: true,
  2217. arity: true
  2218. };
  2219. var defineProperty = Object.defineProperty;
  2220. var getOwnPropertyNames = Object.getOwnPropertyNames;
  2221. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  2222. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  2223. var getPrototypeOf = Object.getPrototypeOf;
  2224. var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
  2225. return function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
  2226. if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components
  2227. if (objectPrototype) {
  2228. var inheritedComponent = getPrototypeOf(sourceComponent);
  2229. if (inheritedComponent && inheritedComponent !== objectPrototype) {
  2230. hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
  2231. }
  2232. }
  2233. var keys = getOwnPropertyNames(sourceComponent);
  2234. if (getOwnPropertySymbols) {
  2235. keys = keys.concat(getOwnPropertySymbols(sourceComponent));
  2236. }
  2237. for (var i = 0; i < keys.length; ++i) {
  2238. var key = keys[i];
  2239. if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) {
  2240. var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
  2241. try { // Avoid failures from read-only properties
  2242. defineProperty(targetComponent, key, descriptor);
  2243. } catch (e) {}
  2244. }
  2245. }
  2246. return targetComponent;
  2247. }
  2248. return targetComponent;
  2249. };
  2250. })));
  2251. });
  2252. /**
  2253. * A public higher-order component to access the imperative API
  2254. */
  2255. var withRouter = function withRouter(Component) {
  2256. var C = function C(props) {
  2257. var wrappedComponentRef = props.wrappedComponentRef,
  2258. remainingProps = objectWithoutProperties(props, ["wrappedComponentRef"]);
  2259. return React.createElement(Route, {
  2260. children: function children(routeComponentProps) {
  2261. return React.createElement(Component, _extends$4({}, remainingProps, routeComponentProps, {
  2262. ref: wrappedComponentRef
  2263. }));
  2264. }
  2265. });
  2266. };
  2267. C.displayName = "withRouter(" + (Component.displayName || Component.name) + ")";
  2268. C.WrappedComponent = Component;
  2269. C.propTypes = {
  2270. wrappedComponentRef: propTypes.func
  2271. };
  2272. return hoistNonReactStatics(C, Component);
  2273. };
  2274. exports.MemoryRouter = MemoryRouter;
  2275. exports.Prompt = Prompt;
  2276. exports.Redirect = Redirect;
  2277. exports.Route = Route;
  2278. exports.Router = Router;
  2279. exports.StaticRouter = StaticRouter;
  2280. exports.Switch = Switch;
  2281. exports.generatePath = generatePath;
  2282. exports.matchPath = matchPath;
  2283. exports.withRouter = withRouter;
  2284. Object.defineProperty(exports, '__esModule', { value: true });
  2285. })));