2344 lines
75 KiB
JavaScript
2344 lines
75 KiB
JavaScript
(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
(factory((global.ReachRouter = {}),global.React));
|
|
}(this, (function (exports,React) { 'use strict';
|
|
|
|
React = React && React.hasOwnProperty('default') ? React['default'] : React;
|
|
|
|
/**
|
|
* Copyright 2014-2015, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
|
|
function unwrapExports (x) {
|
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
}
|
|
|
|
function createCommonjsModule(fn, module) {
|
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
}
|
|
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*
|
|
*/
|
|
|
|
function makeEmptyFunction(arg) {
|
|
return function () {
|
|
return arg;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* This function accepts and discards inputs; it has no side effects. This is
|
|
* primarily useful idiomatically for overridable function endpoints which
|
|
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
|
|
*/
|
|
var emptyFunction = function emptyFunction() {};
|
|
|
|
emptyFunction.thatReturns = makeEmptyFunction;
|
|
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
|
|
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
|
|
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
|
|
emptyFunction.thatReturnsThis = function () {
|
|
return this;
|
|
};
|
|
emptyFunction.thatReturnsArgument = function (arg) {
|
|
return arg;
|
|
};
|
|
|
|
var emptyFunction_1 = emptyFunction;
|
|
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* Use invariant() to assert state which your program assumes to be true.
|
|
*
|
|
* Provide sprintf-style format (only %s is supported) and arguments
|
|
* to provide information about what broke and what you were
|
|
* expecting.
|
|
*
|
|
* The invariant message will be stripped in production, but the invariant
|
|
* will remain to ensure logic does not differ in production.
|
|
*/
|
|
|
|
var validateFormat = function validateFormat(format) {};
|
|
|
|
{
|
|
validateFormat = function validateFormat(format) {
|
|
if (format === undefined) {
|
|
throw new Error('invariant requires an error message argument');
|
|
}
|
|
};
|
|
}
|
|
|
|
function invariant(condition, format, a, b, c, d, e, f) {
|
|
validateFormat(format);
|
|
|
|
if (!condition) {
|
|
var error;
|
|
if (format === undefined) {
|
|
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
|
} else {
|
|
var args = [a, b, c, d, e, f];
|
|
var argIndex = 0;
|
|
error = new Error(format.replace(/%s/g, function () {
|
|
return args[argIndex++];
|
|
}));
|
|
error.name = 'Invariant Violation';
|
|
}
|
|
|
|
error.framesToPop = 1; // we don't care about invariant's own frame
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
var invariant_1 = invariant;
|
|
|
|
/**
|
|
* Similar to invariant but only logs a warning if the condition is not met.
|
|
* This can be used to log issues in development environments in critical
|
|
* paths. Removing the logging code for production environments will keep the
|
|
* same logic and follow the same code paths.
|
|
*/
|
|
|
|
var warning$1 = emptyFunction_1;
|
|
|
|
{
|
|
var printWarning = function printWarning(format) {
|
|
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
args[_key - 1] = arguments[_key];
|
|
}
|
|
|
|
var argIndex = 0;
|
|
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
return args[argIndex++];
|
|
});
|
|
if (typeof console !== 'undefined') {
|
|
console.error(message);
|
|
}
|
|
try {
|
|
// --- Welcome to debugging React ---
|
|
// This error was thrown as a convenience so that you can use this stack
|
|
// to find the callsite that caused this warning to fire.
|
|
throw new Error(message);
|
|
} catch (x) {}
|
|
};
|
|
|
|
warning$1 = function warning(condition, format) {
|
|
if (format === undefined) {
|
|
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
}
|
|
|
|
if (format.indexOf('Failed Composite propType: ') === 0) {
|
|
return; // Ignore CompositeComponent proptype check.
|
|
}
|
|
|
|
if (!condition) {
|
|
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
args[_key2 - 2] = arguments[_key2];
|
|
}
|
|
|
|
printWarning.apply(undefined, [format].concat(args));
|
|
}
|
|
};
|
|
}
|
|
|
|
var warning_1$1 = warning$1;
|
|
|
|
/*
|
|
object-assign
|
|
(c) Sindre Sorhus
|
|
@license MIT
|
|
*/
|
|
/* eslint-disable no-unused-vars */
|
|
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
|
|
function toObject(val) {
|
|
if (val === null || val === undefined) {
|
|
throw new TypeError('Object.assign cannot be called with null or undefined');
|
|
}
|
|
|
|
return Object(val);
|
|
}
|
|
|
|
function shouldUseNative() {
|
|
try {
|
|
if (!Object.assign) {
|
|
return false;
|
|
}
|
|
|
|
// Detect buggy property enumeration order in older V8 versions.
|
|
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
|
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
|
|
test1[5] = 'de';
|
|
if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
|
return false;
|
|
}
|
|
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
var test2 = {};
|
|
for (var i = 0; i < 10; i++) {
|
|
test2['_' + String.fromCharCode(i)] = i;
|
|
}
|
|
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
|
return test2[n];
|
|
});
|
|
if (order2.join('') !== '0123456789') {
|
|
return false;
|
|
}
|
|
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
var test3 = {};
|
|
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
|
test3[letter] = letter;
|
|
});
|
|
if (Object.keys(Object.assign({}, test3)).join('') !==
|
|
'abcdefghijklmnopqrst') {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} catch (err) {
|
|
// We don't expect any of the above to throw, but better to be safe.
|
|
return false;
|
|
}
|
|
}
|
|
|
|
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
|
var from;
|
|
var to = toObject(target);
|
|
var symbols;
|
|
|
|
for (var s = 1; s < arguments.length; s++) {
|
|
from = Object(arguments[s]);
|
|
|
|
for (var key in from) {
|
|
if (hasOwnProperty.call(from, key)) {
|
|
to[key] = from[key];
|
|
}
|
|
}
|
|
|
|
if (getOwnPropertySymbols) {
|
|
symbols = getOwnPropertySymbols(from);
|
|
for (var i = 0; i < symbols.length; i++) {
|
|
if (propIsEnumerable.call(from, symbols[i])) {
|
|
to[symbols[i]] = from[symbols[i]];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return to;
|
|
};
|
|
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
|
|
|
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
|
|
|
|
{
|
|
var invariant$1 = invariant_1;
|
|
var warning$2 = warning_1$1;
|
|
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
|
var loggedTypeFailures = {};
|
|
}
|
|
|
|
/**
|
|
* Assert that the values match with the type specs.
|
|
* Error messages are memorized and will only be shown once.
|
|
*
|
|
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
* @param {object} values Runtime values that need to be type-checked
|
|
* @param {string} location e.g. "prop", "context", "child context"
|
|
* @param {string} componentName Name of the component for error messages.
|
|
* @param {?Function} getStack Returns the component stack.
|
|
* @private
|
|
*/
|
|
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
{
|
|
for (var typeSpecName in typeSpecs) {
|
|
if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
|
var error;
|
|
// Prop type validation may throw. In case they do, we don't want to
|
|
// fail the render phase where it didn't fail before. So we log it.
|
|
// After these have been cleaned up, we'll let them throw.
|
|
try {
|
|
// This is intentionally an invariant that gets caught. It's the same
|
|
// behavior as without this statement except with a better message.
|
|
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]);
|
|
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
|
|
} catch (ex) {
|
|
error = ex;
|
|
}
|
|
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);
|
|
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
// Only monitor this failure once because there tends to be a lot of the
|
|
// same error.
|
|
loggedTypeFailures[error.message] = true;
|
|
|
|
var stack = getStack ? getStack() : '';
|
|
|
|
warning$2(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var checkPropTypes_1 = checkPropTypes;
|
|
|
|
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
|
/* global Symbol */
|
|
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
|
|
/**
|
|
* Returns the iterator method function contained on the iterable object.
|
|
*
|
|
* Be sure to invoke the function with the iterable as context:
|
|
*
|
|
* var iteratorFn = getIteratorFn(myIterable);
|
|
* if (iteratorFn) {
|
|
* var iterator = iteratorFn.call(myIterable);
|
|
* ...
|
|
* }
|
|
*
|
|
* @param {?object} maybeIterable
|
|
* @return {?function}
|
|
*/
|
|
function getIteratorFn(maybeIterable) {
|
|
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
if (typeof iteratorFn === 'function') {
|
|
return iteratorFn;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Collection of methods that allow declaration and validation of props that are
|
|
* supplied to React components. Example usage:
|
|
*
|
|
* var Props = require('ReactPropTypes');
|
|
* var MyArticle = React.createClass({
|
|
* propTypes: {
|
|
* // An optional string prop named "description".
|
|
* description: Props.string,
|
|
*
|
|
* // A required enum prop named "category".
|
|
* category: Props.oneOf(['News','Photos']).isRequired,
|
|
*
|
|
* // A prop named "dialog" that requires an instance of Dialog.
|
|
* dialog: Props.instanceOf(Dialog).isRequired
|
|
* },
|
|
* render: function() { ... }
|
|
* });
|
|
*
|
|
* A more formal specification of how these methods are used:
|
|
*
|
|
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
|
* decl := ReactPropTypes.{type}(.isRequired)?
|
|
*
|
|
* Each and every declaration produces a function with the same signature. This
|
|
* allows the creation of custom validation functions. For example:
|
|
*
|
|
* var MyLink = React.createClass({
|
|
* propTypes: {
|
|
* // An optional string or URI prop named "href".
|
|
* href: function(props, propName, componentName) {
|
|
* var propValue = props[propName];
|
|
* if (propValue != null && typeof propValue !== 'string' &&
|
|
* !(propValue instanceof URI)) {
|
|
* return new Error(
|
|
* 'Expected a string or an URI for ' + propName + ' in ' +
|
|
* componentName
|
|
* );
|
|
* }
|
|
* }
|
|
* },
|
|
* render: function() {...}
|
|
* });
|
|
*
|
|
* @internal
|
|
*/
|
|
|
|
var ANONYMOUS = '<<anonymous>>';
|
|
|
|
// Important!
|
|
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
|
var ReactPropTypes = {
|
|
array: createPrimitiveTypeChecker('array'),
|
|
bool: createPrimitiveTypeChecker('boolean'),
|
|
func: createPrimitiveTypeChecker('function'),
|
|
number: createPrimitiveTypeChecker('number'),
|
|
object: createPrimitiveTypeChecker('object'),
|
|
string: createPrimitiveTypeChecker('string'),
|
|
symbol: createPrimitiveTypeChecker('symbol'),
|
|
|
|
any: createAnyTypeChecker(),
|
|
arrayOf: createArrayOfTypeChecker,
|
|
element: createElementTypeChecker(),
|
|
instanceOf: createInstanceTypeChecker,
|
|
node: createNodeChecker(),
|
|
objectOf: createObjectOfTypeChecker,
|
|
oneOf: createEnumTypeChecker,
|
|
oneOfType: createUnionTypeChecker,
|
|
shape: createShapeTypeChecker,
|
|
exact: createStrictShapeTypeChecker,
|
|
};
|
|
|
|
/**
|
|
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
*/
|
|
/*eslint-disable no-self-compare*/
|
|
function is(x, y) {
|
|
// SameValue algorithm
|
|
if (x === y) {
|
|
// Steps 1-5, 7-10
|
|
// Steps 6.b-6.e: +0 != -0
|
|
return x !== 0 || 1 / x === 1 / y;
|
|
} else {
|
|
// Step 6.a: NaN == NaN
|
|
return x !== x && y !== y;
|
|
}
|
|
}
|
|
/*eslint-enable no-self-compare*/
|
|
|
|
/**
|
|
* We use an Error-like object for backward compatibility as people may call
|
|
* PropTypes directly and inspect their output. However, we don't use real
|
|
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
* is prohibitively expensive if they are created too often, such as what
|
|
* happens in oneOfType() for any type before the one that matched.
|
|
*/
|
|
function PropTypeError(message) {
|
|
this.message = message;
|
|
this.stack = '';
|
|
}
|
|
// Make `instanceof Error` still work for returned errors.
|
|
PropTypeError.prototype = Error.prototype;
|
|
|
|
function createChainableTypeChecker(validate) {
|
|
{
|
|
var manualPropTypeCallCache = {};
|
|
var manualPropTypeWarningCount = 0;
|
|
}
|
|
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
componentName = componentName || ANONYMOUS;
|
|
propFullName = propFullName || propName;
|
|
|
|
if (secret !== ReactPropTypesSecret_1) {
|
|
if (throwOnDirectAccess) {
|
|
// New behavior only for users of `prop-types` package
|
|
invariant_1(
|
|
false,
|
|
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
'Use `PropTypes.checkPropTypes()` to call them. ' +
|
|
'Read more at http://fb.me/use-check-prop-types'
|
|
);
|
|
} else if ("development" !== 'production' && typeof console !== 'undefined') {
|
|
// Old behavior for people using React.PropTypes
|
|
var cacheKey = componentName + ':' + propName;
|
|
if (
|
|
!manualPropTypeCallCache[cacheKey] &&
|
|
// Avoid spamming the console because they are often not actionable except for lib authors
|
|
manualPropTypeWarningCount < 3
|
|
) {
|
|
warning_1$1(
|
|
false,
|
|
'You are manually calling a React.PropTypes validation ' +
|
|
'function for the `%s` prop on `%s`. This is deprecated ' +
|
|
'and will throw in the standalone `prop-types` package. ' +
|
|
'You may be seeing this warning due to a third-party PropTypes ' +
|
|
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.',
|
|
propFullName,
|
|
componentName
|
|
);
|
|
manualPropTypeCallCache[cacheKey] = true;
|
|
manualPropTypeWarningCount++;
|
|
}
|
|
}
|
|
}
|
|
if (props[propName] == null) {
|
|
if (isRequired) {
|
|
if (props[propName] === null) {
|
|
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
}
|
|
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
}
|
|
return null;
|
|
} else {
|
|
return validate(props, propName, componentName, location, propFullName);
|
|
}
|
|
}
|
|
|
|
var chainedCheckType = checkType.bind(null, false);
|
|
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
|
|
return chainedCheckType;
|
|
}
|
|
|
|
function createPrimitiveTypeChecker(expectedType) {
|
|
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
var propValue = props[propName];
|
|
var propType = getPropType(propValue);
|
|
if (propType !== expectedType) {
|
|
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
// check, but we can offer a more precise error message here rather than
|
|
// 'of type `object`'.
|
|
var preciseType = getPreciseType(propValue);
|
|
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createAnyTypeChecker() {
|
|
return createChainableTypeChecker(emptyFunction_1.thatReturnsNull);
|
|
}
|
|
|
|
function createArrayOfTypeChecker(typeChecker) {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
if (typeof typeChecker !== 'function') {
|
|
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
}
|
|
var propValue = props[propName];
|
|
if (!Array.isArray(propValue)) {
|
|
var propType = getPropType(propValue);
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
}
|
|
for (var i = 0; i < propValue.length; i++) {
|
|
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
|
|
if (error instanceof Error) {
|
|
return error;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createElementTypeChecker() {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
var propValue = props[propName];
|
|
if (!isValidElement(propValue)) {
|
|
var propType = getPropType(propValue);
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createInstanceTypeChecker(expectedClass) {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
if (!(props[propName] instanceof expectedClass)) {
|
|
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
var actualClassName = getClassName(props[propName]);
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createEnumTypeChecker(expectedValues) {
|
|
if (!Array.isArray(expectedValues)) {
|
|
warning_1$1(false, 'Invalid argument supplied to oneOf, expected an instance of array.');
|
|
return emptyFunction_1.thatReturnsNull;
|
|
}
|
|
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
var propValue = props[propName];
|
|
for (var i = 0; i < expectedValues.length; i++) {
|
|
if (is(propValue, expectedValues[i])) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
var valuesString = JSON.stringify(expectedValues);
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createObjectOfTypeChecker(typeChecker) {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
if (typeof typeChecker !== 'function') {
|
|
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
}
|
|
var propValue = props[propName];
|
|
var propType = getPropType(propValue);
|
|
if (propType !== 'object') {
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
}
|
|
for (var key in propValue) {
|
|
if (propValue.hasOwnProperty(key)) {
|
|
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
if (error instanceof Error) {
|
|
return error;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
warning_1$1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.');
|
|
return emptyFunction_1.thatReturnsNull;
|
|
}
|
|
|
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
var checker = arrayOfTypeCheckers[i];
|
|
if (typeof checker !== 'function') {
|
|
warning_1$1(
|
|
false,
|
|
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
|
'received %s at index %s.',
|
|
getPostfixForTypeWarning(checker),
|
|
i
|
|
);
|
|
return emptyFunction_1.thatReturnsNull;
|
|
}
|
|
}
|
|
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
var checker = arrayOfTypeCheckers[i];
|
|
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createNodeChecker() {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
if (!isNode(props[propName])) {
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createShapeTypeChecker(shapeTypes) {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
var propValue = props[propName];
|
|
var propType = getPropType(propValue);
|
|
if (propType !== 'object') {
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
}
|
|
for (var key in shapeTypes) {
|
|
var checker = shapeTypes[key];
|
|
if (!checker) {
|
|
continue;
|
|
}
|
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
if (error) {
|
|
return error;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function createStrictShapeTypeChecker(shapeTypes) {
|
|
function validate(props, propName, componentName, location, propFullName) {
|
|
var propValue = props[propName];
|
|
var propType = getPropType(propValue);
|
|
if (propType !== 'object') {
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
}
|
|
// We need to check all keys in case some are required but missing from
|
|
// props.
|
|
var allKeys = objectAssign({}, props[propName], shapeTypes);
|
|
for (var key in allKeys) {
|
|
var checker = shapeTypes[key];
|
|
if (!checker) {
|
|
return new PropTypeError(
|
|
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
|
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
|
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
|
);
|
|
}
|
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
if (error) {
|
|
return error;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
return createChainableTypeChecker(validate);
|
|
}
|
|
|
|
function isNode(propValue) {
|
|
switch (typeof propValue) {
|
|
case 'number':
|
|
case 'string':
|
|
case 'undefined':
|
|
return true;
|
|
case 'boolean':
|
|
return !propValue;
|
|
case 'object':
|
|
if (Array.isArray(propValue)) {
|
|
return propValue.every(isNode);
|
|
}
|
|
if (propValue === null || isValidElement(propValue)) {
|
|
return true;
|
|
}
|
|
|
|
var iteratorFn = getIteratorFn(propValue);
|
|
if (iteratorFn) {
|
|
var iterator = iteratorFn.call(propValue);
|
|
var step;
|
|
if (iteratorFn !== propValue.entries) {
|
|
while (!(step = iterator.next()).done) {
|
|
if (!isNode(step.value)) {
|
|
return false;
|
|
}
|
|
}
|
|
} else {
|
|
// Iterator will provide entry [k,v] tuples rather than values.
|
|
while (!(step = iterator.next()).done) {
|
|
var entry = step.value;
|
|
if (entry) {
|
|
if (!isNode(entry[1])) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function isSymbol(propType, propValue) {
|
|
// Native Symbol.
|
|
if (propType === 'symbol') {
|
|
return true;
|
|
}
|
|
|
|
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
return true;
|
|
}
|
|
|
|
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
function getPropType(propValue) {
|
|
var propType = typeof propValue;
|
|
if (Array.isArray(propValue)) {
|
|
return 'array';
|
|
}
|
|
if (propValue instanceof RegExp) {
|
|
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
// passes PropTypes.object.
|
|
return 'object';
|
|
}
|
|
if (isSymbol(propType, propValue)) {
|
|
return 'symbol';
|
|
}
|
|
return propType;
|
|
}
|
|
|
|
// This handles more types than `getPropType`. Only used for error messages.
|
|
// See `createPrimitiveTypeChecker`.
|
|
function getPreciseType(propValue) {
|
|
if (typeof propValue === 'undefined' || propValue === null) {
|
|
return '' + propValue;
|
|
}
|
|
var propType = getPropType(propValue);
|
|
if (propType === 'object') {
|
|
if (propValue instanceof Date) {
|
|
return 'date';
|
|
} else if (propValue instanceof RegExp) {
|
|
return 'regexp';
|
|
}
|
|
}
|
|
return propType;
|
|
}
|
|
|
|
// Returns a string that is postfixed to a warning about an invalid type.
|
|
// For example, "undefined" or "of type array"
|
|
function getPostfixForTypeWarning(value) {
|
|
var type = getPreciseType(value);
|
|
switch (type) {
|
|
case 'array':
|
|
case 'object':
|
|
return 'an ' + type;
|
|
case 'boolean':
|
|
case 'date':
|
|
case 'regexp':
|
|
return 'a ' + type;
|
|
default:
|
|
return type;
|
|
}
|
|
}
|
|
|
|
// Returns class name of the object, if any.
|
|
function getClassName(propValue) {
|
|
if (!propValue.constructor || !propValue.constructor.name) {
|
|
return ANONYMOUS;
|
|
}
|
|
return propValue.constructor.name;
|
|
}
|
|
|
|
ReactPropTypes.checkPropTypes = checkPropTypes_1;
|
|
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
|
|
return ReactPropTypes;
|
|
};
|
|
|
|
var propTypes = createCommonjsModule(function (module) {
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
{
|
|
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
|
|
Symbol.for &&
|
|
Symbol.for('react.element')) ||
|
|
0xeac7;
|
|
|
|
var isValidElement = function(object) {
|
|
return typeof object === 'object' &&
|
|
object !== null &&
|
|
object.$$typeof === REACT_ELEMENT_TYPE;
|
|
};
|
|
|
|
// By explicitly using `prop-types` you are opting into new development behavior.
|
|
// http://fb.me/prop-types-in-prod
|
|
var throwOnDirectAccess = true;
|
|
module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess);
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
/**
|
|
* Use invariant() to assert state which your program assumes to be true.
|
|
*
|
|
* Provide sprintf-style format (only %s is supported) and arguments
|
|
* to provide information about what broke and what you were
|
|
* expecting.
|
|
*
|
|
* The invariant message will be stripped in production, but the invariant
|
|
* will remain to ensure logic does not differ in production.
|
|
*/
|
|
|
|
var NODE_ENV = "development";
|
|
|
|
var invariant$2 = function(condition, format, a, b, c, d, e, f) {
|
|
if (NODE_ENV !== 'production') {
|
|
if (format === undefined) {
|
|
throw new Error('invariant requires an error message argument');
|
|
}
|
|
}
|
|
|
|
if (!condition) {
|
|
var error;
|
|
if (format === undefined) {
|
|
error = new Error(
|
|
'Minified exception occurred; use the non-minified dev environment ' +
|
|
'for the full error message and additional helpful warnings.'
|
|
);
|
|
} else {
|
|
var args = [a, b, c, d, e, f];
|
|
var argIndex = 0;
|
|
error = new Error(
|
|
format.replace(/%s/g, function() { return args[argIndex++]; })
|
|
);
|
|
error.name = 'Invariant Violation';
|
|
}
|
|
|
|
error.framesToPop = 1; // we don't care about invariant's own frame
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
var invariant_1$1 = invariant$2;
|
|
|
|
var key = '__global_unique_id__';
|
|
|
|
var gud = function() {
|
|
return commonjsGlobal[key] = (commonjsGlobal[key] || 0) + 1;
|
|
};
|
|
|
|
var implementation = createCommonjsModule(function (module, exports) {
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
|
|
var _react2 = _interopRequireDefault(React);
|
|
|
|
|
|
|
|
var _propTypes2 = _interopRequireDefault(propTypes);
|
|
|
|
|
|
|
|
var _gud2 = _interopRequireDefault(gud);
|
|
|
|
|
|
|
|
var _warning2 = _interopRequireDefault(warning_1$1);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
|
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
|
|
var MAX_SIGNED_31_BIT_INT = 1073741823;
|
|
|
|
// Inlined Object.is polyfill.
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
function objectIs(x, y) {
|
|
if (x === y) {
|
|
return x !== 0 || 1 / x === 1 / y;
|
|
} else {
|
|
return x !== x && y !== y;
|
|
}
|
|
}
|
|
|
|
function createEventEmitter(value) {
|
|
var handlers = [];
|
|
return {
|
|
on: function on(handler) {
|
|
handlers.push(handler);
|
|
},
|
|
off: function off(handler) {
|
|
handlers = handlers.filter(function (h) {
|
|
return h !== handler;
|
|
});
|
|
},
|
|
get: function get() {
|
|
return value;
|
|
},
|
|
set: function set(newValue, changedBits) {
|
|
value = newValue;
|
|
handlers.forEach(function (handler) {
|
|
return handler(value, changedBits);
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
function onlyChild(children) {
|
|
return Array.isArray(children) ? children[0] : children;
|
|
}
|
|
|
|
function createReactContext(defaultValue, calculateChangedBits) {
|
|
var _Provider$childContex, _Consumer$contextType;
|
|
|
|
var contextProp = '__create-react-context-' + (0, _gud2.default)() + '__';
|
|
|
|
var Provider = function (_Component) {
|
|
_inherits(Provider, _Component);
|
|
|
|
function Provider() {
|
|
var _temp, _this, _ret;
|
|
|
|
_classCallCheck(this, Provider);
|
|
|
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.emitter = createEventEmitter(_this.props.value), _temp), _possibleConstructorReturn(_this, _ret);
|
|
}
|
|
|
|
Provider.prototype.getChildContext = function getChildContext() {
|
|
var _ref;
|
|
|
|
return _ref = {}, _ref[contextProp] = this.emitter, _ref;
|
|
};
|
|
|
|
Provider.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
|
if (this.props.value !== nextProps.value) {
|
|
var oldValue = this.props.value;
|
|
var newValue = nextProps.value;
|
|
var changedBits = void 0;
|
|
|
|
if (objectIs(oldValue, newValue)) {
|
|
changedBits = 0; // No change
|
|
} else {
|
|
changedBits = typeof calculateChangedBits === 'function' ? calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
|
|
{
|
|
(0, _warning2.default)((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
|
|
}
|
|
|
|
changedBits |= 0;
|
|
|
|
if (changedBits !== 0) {
|
|
this.emitter.set(nextProps.value, changedBits);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
Provider.prototype.render = function render() {
|
|
return this.props.children;
|
|
};
|
|
|
|
return Provider;
|
|
}(React.Component);
|
|
|
|
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = _propTypes2.default.object.isRequired, _Provider$childContex);
|
|
|
|
var Consumer = function (_Component2) {
|
|
_inherits(Consumer, _Component2);
|
|
|
|
function Consumer() {
|
|
var _temp2, _this2, _ret2;
|
|
|
|
_classCallCheck(this, Consumer);
|
|
|
|
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
args[_key2] = arguments[_key2];
|
|
}
|
|
|
|
return _ret2 = (_temp2 = (_this2 = _possibleConstructorReturn(this, _Component2.call.apply(_Component2, [this].concat(args))), _this2), _this2.state = {
|
|
value: _this2.getValue()
|
|
}, _this2.onUpdate = function (newValue, changedBits) {
|
|
var observedBits = _this2.observedBits | 0;
|
|
if ((observedBits & changedBits) !== 0) {
|
|
_this2.setState({ value: _this2.getValue() });
|
|
}
|
|
}, _temp2), _possibleConstructorReturn(_this2, _ret2);
|
|
}
|
|
|
|
Consumer.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
|
var observedBits = nextProps.observedBits;
|
|
|
|
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default
|
|
: observedBits;
|
|
};
|
|
|
|
Consumer.prototype.componentDidMount = function componentDidMount() {
|
|
if (this.context[contextProp]) {
|
|
this.context[contextProp].on(this.onUpdate);
|
|
}
|
|
var observedBits = this.props.observedBits;
|
|
|
|
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default
|
|
: observedBits;
|
|
};
|
|
|
|
Consumer.prototype.componentWillUnmount = function componentWillUnmount() {
|
|
if (this.context[contextProp]) {
|
|
this.context[contextProp].off(this.onUpdate);
|
|
}
|
|
};
|
|
|
|
Consumer.prototype.getValue = function getValue() {
|
|
if (this.context[contextProp]) {
|
|
return this.context[contextProp].get();
|
|
} else {
|
|
return defaultValue;
|
|
}
|
|
};
|
|
|
|
Consumer.prototype.render = function render() {
|
|
return onlyChild(this.props.children)(this.state.value);
|
|
};
|
|
|
|
return Consumer;
|
|
}(React.Component);
|
|
|
|
Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = _propTypes2.default.object, _Consumer$contextType);
|
|
|
|
|
|
return {
|
|
Provider: Provider,
|
|
Consumer: Consumer
|
|
};
|
|
}
|
|
|
|
exports.default = _react2.default.createContext || createReactContext;
|
|
module.exports = exports['default'];
|
|
});
|
|
|
|
unwrapExports(implementation);
|
|
|
|
var lib = createCommonjsModule(function (module, exports) {
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
|
|
var _react2 = _interopRequireDefault(React);
|
|
|
|
|
|
|
|
var _implementation2 = _interopRequireDefault(implementation);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
exports.default = _react2.default.createContext || _implementation2.default;
|
|
module.exports = exports['default'];
|
|
});
|
|
|
|
var createContext = unwrapExports(lib);
|
|
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
function componentWillMount() {
|
|
// Call this.constructor.gDSFP to support sub-classes.
|
|
var state = this.constructor.getDerivedStateFromProps(this.props, this.state);
|
|
if (state !== null && state !== undefined) {
|
|
this.setState(state);
|
|
}
|
|
}
|
|
|
|
function componentWillReceiveProps(nextProps) {
|
|
// Call this.constructor.gDSFP to support sub-classes.
|
|
// Use the setState() updater to ensure state isn't stale in certain edge cases.
|
|
function updater(prevState) {
|
|
var state = this.constructor.getDerivedStateFromProps(nextProps, prevState);
|
|
return state !== null && state !== undefined ? state : null;
|
|
}
|
|
// Binding "this" is important for shallow renderer support.
|
|
this.setState(updater.bind(this));
|
|
}
|
|
|
|
function componentWillUpdate(nextProps, nextState) {
|
|
try {
|
|
var prevProps = this.props;
|
|
var prevState = this.state;
|
|
this.props = nextProps;
|
|
this.state = nextState;
|
|
this.__reactInternalSnapshotFlag = true;
|
|
this.__reactInternalSnapshot = this.getSnapshotBeforeUpdate(
|
|
prevProps,
|
|
prevState
|
|
);
|
|
} finally {
|
|
this.props = prevProps;
|
|
this.state = prevState;
|
|
}
|
|
}
|
|
|
|
// React may warn about cWM/cWRP/cWU methods being deprecated.
|
|
// Add a flag to suppress these warnings for this special case.
|
|
componentWillMount.__suppressDeprecationWarning = true;
|
|
componentWillReceiveProps.__suppressDeprecationWarning = true;
|
|
componentWillUpdate.__suppressDeprecationWarning = true;
|
|
|
|
function polyfill(Component) {
|
|
var prototype = Component.prototype;
|
|
|
|
if (!prototype || !prototype.isReactComponent) {
|
|
throw new Error('Can only polyfill class components');
|
|
}
|
|
|
|
if (
|
|
typeof Component.getDerivedStateFromProps !== 'function' &&
|
|
typeof prototype.getSnapshotBeforeUpdate !== 'function'
|
|
) {
|
|
return Component;
|
|
}
|
|
|
|
// If new component APIs are defined, "unsafe" lifecycles won't be called.
|
|
// Error if any of these lifecycles are present,
|
|
// Because they would work differently between older and newer (16.3+) versions of React.
|
|
var foundWillMountName = null;
|
|
var foundWillReceivePropsName = null;
|
|
var foundWillUpdateName = null;
|
|
if (typeof prototype.componentWillMount === 'function') {
|
|
foundWillMountName = 'componentWillMount';
|
|
} else if (typeof prototype.UNSAFE_componentWillMount === 'function') {
|
|
foundWillMountName = 'UNSAFE_componentWillMount';
|
|
}
|
|
if (typeof prototype.componentWillReceiveProps === 'function') {
|
|
foundWillReceivePropsName = 'componentWillReceiveProps';
|
|
} else if (typeof prototype.UNSAFE_componentWillReceiveProps === 'function') {
|
|
foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
|
|
}
|
|
if (typeof prototype.componentWillUpdate === 'function') {
|
|
foundWillUpdateName = 'componentWillUpdate';
|
|
} else if (typeof prototype.UNSAFE_componentWillUpdate === 'function') {
|
|
foundWillUpdateName = 'UNSAFE_componentWillUpdate';
|
|
}
|
|
if (
|
|
foundWillMountName !== null ||
|
|
foundWillReceivePropsName !== null ||
|
|
foundWillUpdateName !== null
|
|
) {
|
|
var componentName = Component.displayName || Component.name;
|
|
var newApiName =
|
|
typeof Component.getDerivedStateFromProps === 'function'
|
|
? 'getDerivedStateFromProps()'
|
|
: 'getSnapshotBeforeUpdate()';
|
|
|
|
throw Error(
|
|
'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
|
|
componentName +
|
|
' uses ' +
|
|
newApiName +
|
|
' but also contains the following legacy lifecycles:' +
|
|
(foundWillMountName !== null ? '\n ' + foundWillMountName : '') +
|
|
(foundWillReceivePropsName !== null
|
|
? '\n ' + foundWillReceivePropsName
|
|
: '') +
|
|
(foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '') +
|
|
'\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' +
|
|
'https://fb.me/react-async-component-lifecycle-hooks'
|
|
);
|
|
}
|
|
|
|
// React <= 16.2 does not support static getDerivedStateFromProps.
|
|
// As a workaround, use cWM and cWRP to invoke the new static lifecycle.
|
|
// Newer versions of React will ignore these lifecycles if gDSFP exists.
|
|
if (typeof Component.getDerivedStateFromProps === 'function') {
|
|
prototype.componentWillMount = componentWillMount;
|
|
prototype.componentWillReceiveProps = componentWillReceiveProps;
|
|
}
|
|
|
|
// React <= 16.2 does not support getSnapshotBeforeUpdate.
|
|
// As a workaround, use cWU to invoke the new lifecycle.
|
|
// Newer versions of React will ignore that lifecycle if gSBU exists.
|
|
if (typeof prototype.getSnapshotBeforeUpdate === 'function') {
|
|
if (typeof prototype.componentDidUpdate !== 'function') {
|
|
throw new Error(
|
|
'Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype'
|
|
);
|
|
}
|
|
|
|
prototype.componentWillUpdate = componentWillUpdate;
|
|
|
|
var componentDidUpdate = prototype.componentDidUpdate;
|
|
|
|
prototype.componentDidUpdate = function componentDidUpdatePolyfill(
|
|
prevProps,
|
|
prevState,
|
|
maybeSnapshot
|
|
) {
|
|
// 16.3+ will not execute our will-update method;
|
|
// It will pass a snapshot value to did-update though.
|
|
// Older versions will require our polyfilled will-update value.
|
|
// We need to handle both cases, but can't just check for the presence of "maybeSnapshot",
|
|
// Because for <= 15.x versions this might be a "prevContext" object.
|
|
// We also can't just check "__reactInternalSnapshot",
|
|
// Because get-snapshot might return a falsy value.
|
|
// So check for the explicit __reactInternalSnapshotFlag flag to determine behavior.
|
|
var snapshot = this.__reactInternalSnapshotFlag
|
|
? this.__reactInternalSnapshot
|
|
: maybeSnapshot;
|
|
|
|
componentDidUpdate.call(this, prevProps, prevState, snapshot);
|
|
};
|
|
}
|
|
|
|
return Component;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// startsWith(string, search) - Check if `string` starts with `search`
|
|
var startsWith = function startsWith(string, search) {
|
|
return string.substr(0, search.length) === search;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// pick(routes, uri)
|
|
//
|
|
// Ranks and picks the best route to match. Each segment gets the highest
|
|
// amount of points, then the type of segment gets an additional amount of
|
|
// points where
|
|
//
|
|
// static > dynamic > splat > root
|
|
//
|
|
// This way we don't have to worry about the order of our routes, let the
|
|
// computers do it.
|
|
//
|
|
// A route looks like this
|
|
//
|
|
// { path, default, value }
|
|
//
|
|
// And a returned match looks like:
|
|
//
|
|
// { route, params, uri }
|
|
//
|
|
// I know, I should use TypeScript not comments for these types.
|
|
var pick = function pick(routes, uri) {
|
|
var match = void 0;
|
|
var default_ = void 0;
|
|
|
|
var _uri$split = uri.split("?"),
|
|
uriPathname = _uri$split[0];
|
|
|
|
var uriSegments = segmentize(uriPathname);
|
|
var isRootUri = uriSegments[0] === "";
|
|
var ranked = rankRoutes(routes);
|
|
|
|
for (var i = 0, l = ranked.length; i < l; i++) {
|
|
var missed = false;
|
|
var route = ranked[i].route;
|
|
|
|
if (route.default) {
|
|
default_ = {
|
|
route: route,
|
|
params: {},
|
|
uri: uri
|
|
};
|
|
continue;
|
|
}
|
|
|
|
var routeSegments = segmentize(route.path);
|
|
var params = {};
|
|
var max = Math.max(uriSegments.length, routeSegments.length);
|
|
var index = 0;
|
|
|
|
for (; index < max; index++) {
|
|
var routeSegment = routeSegments[index];
|
|
var uriSegment = uriSegments[index];
|
|
|
|
var _isSplat = routeSegment === "*";
|
|
if (_isSplat) {
|
|
// Hit a splat, just grab the rest, and return a match
|
|
// uri: /files/documents/work
|
|
// route: /files/*
|
|
params["*"] = uriSegments.slice(index).map(decodeURIComponent).join("/");
|
|
break;
|
|
}
|
|
|
|
if (uriSegment === undefined) {
|
|
// URI is shorter than the route, no match
|
|
// uri: /users
|
|
// route: /users/:userId
|
|
missed = true;
|
|
break;
|
|
}
|
|
|
|
var dynamicMatch = paramRe.exec(routeSegment);
|
|
|
|
if (dynamicMatch && !isRootUri) {
|
|
var matchIsNotReserved = reservedNames.indexOf(dynamicMatch[1]) === -1;
|
|
!matchIsNotReserved ? invariant_1$1(false, "<Router> dynamic segment \"" + dynamicMatch[1] + "\" is a reserved name. Please use a different name in path \"" + route.path + "\".") : void 0;
|
|
var value = decodeURIComponent(uriSegment);
|
|
params[dynamicMatch[1]] = value;
|
|
} else if (routeSegment !== uriSegment) {
|
|
// Current segments don't match, not dynamic, not splat, so no match
|
|
// uri: /users/123/settings
|
|
// route: /users/:id/profile
|
|
missed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!missed) {
|
|
match = {
|
|
route: route,
|
|
params: params,
|
|
uri: "/" + uriSegments.slice(0, index).join("/")
|
|
};
|
|
break;
|
|
}
|
|
}
|
|
|
|
return match || default_ || null;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// match(path, uri) - Matches just one path to a uri, also lol
|
|
var match = function match(path, uri) {
|
|
return pick([{ path: path }], uri);
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// resolve(to, basepath)
|
|
//
|
|
// Resolves URIs as though every path is a directory, no files. Relative URIs
|
|
// in the browser can feel awkward because not only can you be "in a directory"
|
|
// you can be "at a file", too. For example
|
|
//
|
|
// browserSpecResolve('foo', '/bar/') => /bar/foo
|
|
// browserSpecResolve('foo', '/bar') => /foo
|
|
//
|
|
// But on the command line of a file system, it's not as complicated, you can't
|
|
// `cd` from a file, only directories. This way, links have to know less about
|
|
// their current path. To go deeper you can do this:
|
|
//
|
|
// <Link to="deeper"/>
|
|
// // instead of
|
|
// <Link to=`{${props.uri}/deeper}`/>
|
|
//
|
|
// Just like `cd`, if you want to go deeper from the command line, you do this:
|
|
//
|
|
// cd deeper
|
|
// # not
|
|
// cd $(pwd)/deeper
|
|
//
|
|
// By treating every path as a directory, linking to relative paths should
|
|
// require less contextual information and (fingers crossed) be more intuitive.
|
|
var resolve = function resolve(to, base) {
|
|
// /foo/bar, /baz/qux => /foo/bar
|
|
if (startsWith(to, "/")) {
|
|
return to;
|
|
}
|
|
|
|
var _to$split = to.split("?"),
|
|
toPathname = _to$split[0],
|
|
toQuery = _to$split[1];
|
|
|
|
var _base$split = base.split("?"),
|
|
basePathname = _base$split[0];
|
|
|
|
var toSegments = segmentize(toPathname);
|
|
var baseSegments = segmentize(basePathname);
|
|
|
|
// ?a=b, /users?b=c => /users?a=b
|
|
if (toSegments[0] === "") {
|
|
return addQuery(basePathname, toQuery);
|
|
}
|
|
|
|
// profile, /users/789 => /users/789/profile
|
|
if (!startsWith(toSegments[0], ".")) {
|
|
var pathname = baseSegments.concat(toSegments).join("/");
|
|
return addQuery((basePathname === "/" ? "" : "/") + pathname, toQuery);
|
|
}
|
|
|
|
// ./ /users/123 => /users/123
|
|
// ../ /users/123 => /users
|
|
// ../.. /users/123 => /
|
|
// ../../one /a/b/c/d => /a/b/one
|
|
// .././one /a/b/c/d => /a/b/c/one
|
|
var allSegments = baseSegments.concat(toSegments);
|
|
var segments = [];
|
|
for (var i = 0, l = allSegments.length; i < l; i++) {
|
|
var segment = allSegments[i];
|
|
if (segment === "..") segments.pop();else if (segment !== ".") segments.push(segment);
|
|
}
|
|
|
|
return addQuery("/" + segments.join("/"), toQuery);
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// insertParams(path, params)
|
|
var insertParams = function insertParams(path, params) {
|
|
var segments = segmentize(path);
|
|
return "/" + segments.map(function (segment) {
|
|
var match = paramRe.exec(segment);
|
|
return match ? params[match[1]] : segment;
|
|
}).join("/");
|
|
};
|
|
|
|
var validateRedirect = function validateRedirect(from, to) {
|
|
var filter = function filter(segment) {
|
|
return isDynamic(segment);
|
|
};
|
|
var fromString = segmentize(from).filter(filter).sort().join("/");
|
|
var toString = segmentize(to).filter(filter).sort().join("/");
|
|
return fromString === toString;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Junk
|
|
var paramRe = /^:(.+)/;
|
|
|
|
var SEGMENT_POINTS = 4;
|
|
var STATIC_POINTS = 3;
|
|
var DYNAMIC_POINTS = 2;
|
|
var SPLAT_PENALTY = 1;
|
|
var ROOT_POINTS = 1;
|
|
|
|
var isRootSegment = function isRootSegment(segment) {
|
|
return segment === "";
|
|
};
|
|
var isDynamic = function isDynamic(segment) {
|
|
return paramRe.test(segment);
|
|
};
|
|
var isSplat = function isSplat(segment) {
|
|
return segment === "*";
|
|
};
|
|
|
|
var rankRoute = function rankRoute(route, index) {
|
|
var score = route.default ? 0 : segmentize(route.path).reduce(function (score, segment) {
|
|
score += SEGMENT_POINTS;
|
|
if (isRootSegment(segment)) score += ROOT_POINTS;else if (isDynamic(segment)) score += DYNAMIC_POINTS;else if (isSplat(segment)) score -= SEGMENT_POINTS + SPLAT_PENALTY;else score += STATIC_POINTS;
|
|
return score;
|
|
}, 0);
|
|
return { route: route, score: score, index: index };
|
|
};
|
|
|
|
var rankRoutes = function rankRoutes(routes) {
|
|
return routes.map(rankRoute).sort(function (a, b) {
|
|
return a.score < b.score ? 1 : a.score > b.score ? -1 : a.index - b.index;
|
|
});
|
|
};
|
|
|
|
var segmentize = function segmentize(uri) {
|
|
return uri
|
|
// strip starting/ending slashes
|
|
.replace(/(^\/+|\/+$)/g, "").split("/");
|
|
};
|
|
|
|
var addQuery = function addQuery(pathname, query) {
|
|
return pathname + (query ? "?" + query : "");
|
|
};
|
|
|
|
var reservedNames = ["uri", "path"];
|
|
|
|
var classCallCheck = function (instance, Constructor) {
|
|
if (!(instance instanceof Constructor)) {
|
|
throw new TypeError("Cannot call a class as a function");
|
|
}
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
var inherits = function (subClass, superClass) {
|
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
|
}
|
|
|
|
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
constructor: {
|
|
value: subClass,
|
|
enumerable: false,
|
|
writable: true,
|
|
configurable: true
|
|
}
|
|
});
|
|
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
};
|
|
|
|
var objectWithoutProperties = function (obj, keys) {
|
|
var target = {};
|
|
|
|
for (var i in obj) {
|
|
if (keys.indexOf(i) >= 0) continue;
|
|
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
|
target[i] = obj[i];
|
|
}
|
|
|
|
return target;
|
|
};
|
|
|
|
var possibleConstructorReturn = function (self, call) {
|
|
if (!self) {
|
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
}
|
|
|
|
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
|
};
|
|
|
|
var getLocation = function getLocation(source) {
|
|
return _extends({}, source.location, {
|
|
state: source.history.state,
|
|
key: source.history.state && source.history.state.key || "initial"
|
|
});
|
|
};
|
|
|
|
var createHistory = function createHistory(source, options) {
|
|
var listeners = [];
|
|
var location = getLocation(source);
|
|
var transitioning = false;
|
|
var resolveTransition = function resolveTransition() {};
|
|
|
|
return {
|
|
get location() {
|
|
return location;
|
|
},
|
|
|
|
get transitioning() {
|
|
return transitioning;
|
|
},
|
|
|
|
_onTransitionComplete: function _onTransitionComplete() {
|
|
transitioning = false;
|
|
resolveTransition();
|
|
},
|
|
listen: function listen(listener) {
|
|
listeners.push(listener);
|
|
|
|
var popstateListener = function popstateListener() {
|
|
location = getLocation(source);
|
|
listener({ location: location, action: "POP" });
|
|
};
|
|
|
|
source.addEventListener("popstate", popstateListener);
|
|
|
|
return function () {
|
|
source.removeEventListener("popstate", popstateListener);
|
|
listeners = listeners.filter(function (fn) {
|
|
return fn !== listener;
|
|
});
|
|
};
|
|
},
|
|
navigate: function navigate(to) {
|
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
state = _ref.state,
|
|
_ref$replace = _ref.replace,
|
|
replace = _ref$replace === undefined ? false : _ref$replace;
|
|
|
|
state = _extends({}, state, { key: Date.now() + "" });
|
|
// try...catch iOS Safari limits to 100 pushState calls
|
|
try {
|
|
if (transitioning || replace) {
|
|
source.history.replaceState(state, null, to);
|
|
} else {
|
|
source.history.pushState(state, null, to);
|
|
}
|
|
} catch (e) {
|
|
source.location[replace ? "replace" : "assign"](to);
|
|
}
|
|
|
|
location = getLocation(source);
|
|
transitioning = true;
|
|
var transition = new Promise(function (res) {
|
|
return resolveTransition = res;
|
|
});
|
|
listeners.forEach(function (listener) {
|
|
return listener({ location: location, action: "PUSH" });
|
|
});
|
|
return transition;
|
|
}
|
|
};
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Stores history entries in memory for testing or other platforms like Native
|
|
var createMemorySource = function createMemorySource() {
|
|
var initialPathname = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "/";
|
|
|
|
var index = 0;
|
|
var stack = [{ pathname: initialPathname, search: "" }];
|
|
var states = [];
|
|
|
|
return {
|
|
get location() {
|
|
return stack[index];
|
|
},
|
|
addEventListener: function addEventListener(name, fn) {},
|
|
removeEventListener: function removeEventListener(name, fn) {},
|
|
|
|
history: {
|
|
get entries() {
|
|
return stack;
|
|
},
|
|
get index() {
|
|
return index;
|
|
},
|
|
get state() {
|
|
return states[index];
|
|
},
|
|
pushState: function pushState(state, _, uri) {
|
|
var _uri$split = uri.split("?"),
|
|
pathname = _uri$split[0],
|
|
_uri$split$ = _uri$split[1],
|
|
search = _uri$split$ === undefined ? "" : _uri$split$;
|
|
|
|
index++;
|
|
stack.push({ pathname: pathname, search: search });
|
|
states.push(state);
|
|
},
|
|
replaceState: function replaceState(state, _, uri) {
|
|
var _uri$split2 = uri.split("?"),
|
|
pathname = _uri$split2[0],
|
|
_uri$split2$ = _uri$split2[1],
|
|
search = _uri$split2$ === undefined ? "" : _uri$split2$;
|
|
|
|
stack[index] = { pathname: pathname, search: search };
|
|
states[index] = state;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// global history - uses window.history as the source if available, otherwise a
|
|
// memory history
|
|
var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
var getSource = function getSource() {
|
|
return canUseDOM ? window : createMemorySource();
|
|
};
|
|
|
|
var globalHistory = createHistory(getSource());
|
|
var navigate = globalHistory.navigate;
|
|
|
|
/* eslint-disable jsx-a11y/anchor-has-content */
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
var createNamedContext = function createNamedContext(name, defaultValue) {
|
|
var Ctx = createContext(defaultValue);
|
|
Ctx.Consumer.displayName = name + ".Consumer";
|
|
Ctx.Provider.displayName = name + ".Provider";
|
|
return Ctx;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Location Context/Provider
|
|
var LocationContext = createNamedContext("Location");
|
|
|
|
// sets up a listener if there isn't one already so apps don't need to be
|
|
// wrapped in some top level provider
|
|
var Location = function Location(_ref) {
|
|
var children = _ref.children;
|
|
return React.createElement(
|
|
LocationContext.Consumer,
|
|
null,
|
|
function (context) {
|
|
return context ? children(context) : React.createElement(
|
|
LocationProvider,
|
|
null,
|
|
children
|
|
);
|
|
}
|
|
);
|
|
};
|
|
|
|
var LocationProvider = function (_React$Component) {
|
|
inherits(LocationProvider, _React$Component);
|
|
|
|
function LocationProvider() {
|
|
var _temp, _this, _ret;
|
|
|
|
classCallCheck(this, LocationProvider);
|
|
|
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
|
|
context: _this.getContext(),
|
|
refs: { unlisten: null }
|
|
}, _temp), possibleConstructorReturn(_this, _ret);
|
|
}
|
|
|
|
LocationProvider.prototype.getContext = function getContext() {
|
|
var _props$history = this.props.history,
|
|
navigate$$1 = _props$history.navigate,
|
|
location = _props$history.location;
|
|
|
|
return { navigate: navigate$$1, location: location };
|
|
};
|
|
|
|
LocationProvider.prototype.componentDidCatch = function componentDidCatch(error, info) {
|
|
if (isRedirect(error)) {
|
|
var _navigate = this.props.history.navigate;
|
|
|
|
_navigate(error.uri, { replace: true });
|
|
} else {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
LocationProvider.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
if (prevState.context.location !== this.state.context.location) {
|
|
this.props.history._onTransitionComplete();
|
|
}
|
|
};
|
|
|
|
LocationProvider.prototype.componentDidMount = function componentDidMount() {
|
|
var _this2 = this;
|
|
|
|
var refs = this.state.refs,
|
|
history = this.props.history;
|
|
|
|
refs.unlisten = history.listen(function () {
|
|
Promise.resolve().then(function () {
|
|
// TODO: replace rAF with react deferred update API when it's ready https://github.com/facebook/react/issues/13306
|
|
requestAnimationFrame(function () {
|
|
if (!_this2.unmounted) {
|
|
_this2.setState(function () {
|
|
return { context: _this2.getContext() };
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
LocationProvider.prototype.componentWillUnmount = function componentWillUnmount() {
|
|
var refs = this.state.refs;
|
|
|
|
this.unmounted = true;
|
|
refs.unlisten();
|
|
};
|
|
|
|
LocationProvider.prototype.render = function render() {
|
|
var context = this.state.context,
|
|
children = this.props.children;
|
|
|
|
return React.createElement(
|
|
LocationContext.Provider,
|
|
{ value: context },
|
|
typeof children === "function" ? children(context) : children || null
|
|
);
|
|
};
|
|
|
|
return LocationProvider;
|
|
}(React.Component);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
LocationProvider.defaultProps = {
|
|
history: globalHistory
|
|
};
|
|
LocationProvider.propTypes = {
|
|
history: propTypes.object.isRequired
|
|
};
|
|
var ServerLocation = function ServerLocation(_ref2) {
|
|
var url = _ref2.url,
|
|
children = _ref2.children;
|
|
return React.createElement(
|
|
LocationContext.Provider,
|
|
{
|
|
value: {
|
|
location: {
|
|
pathname: url,
|
|
search: "",
|
|
hash: ""
|
|
},
|
|
navigate: function navigate$$1() {
|
|
throw new Error("You can't call navigate on the server.");
|
|
}
|
|
}
|
|
},
|
|
children
|
|
);
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Sets baseuri and basepath for nested routers and links
|
|
var BaseContext = createNamedContext("Base", { baseuri: "/", basepath: "/" });
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// The main event, welcome to the show everybody.
|
|
var Router = function Router(props) {
|
|
return React.createElement(
|
|
BaseContext.Consumer,
|
|
null,
|
|
function (baseContext) {
|
|
return React.createElement(
|
|
Location,
|
|
null,
|
|
function (locationContext) {
|
|
return React.createElement(RouterImpl, _extends({}, baseContext, locationContext, props));
|
|
}
|
|
);
|
|
}
|
|
);
|
|
};
|
|
|
|
var RouterImpl = function (_React$PureComponent) {
|
|
inherits(RouterImpl, _React$PureComponent);
|
|
|
|
function RouterImpl() {
|
|
classCallCheck(this, RouterImpl);
|
|
return possibleConstructorReturn(this, _React$PureComponent.apply(this, arguments));
|
|
}
|
|
|
|
RouterImpl.prototype.render = function render() {
|
|
var _props = this.props,
|
|
location = _props.location,
|
|
_navigate2 = _props.navigate,
|
|
basepath = _props.basepath,
|
|
primary = _props.primary,
|
|
children = _props.children,
|
|
baseuri = _props.baseuri,
|
|
_props$component = _props.component,
|
|
component = _props$component === undefined ? "div" : _props$component,
|
|
domProps = objectWithoutProperties(_props, ["location", "navigate", "basepath", "primary", "children", "baseuri", "component"]);
|
|
|
|
var routes = React.Children.map(children, createRoute(basepath));
|
|
var pathname = location.pathname;
|
|
|
|
|
|
var match$$1 = pick(routes, pathname);
|
|
|
|
if (match$$1) {
|
|
var params = match$$1.params,
|
|
uri = match$$1.uri,
|
|
route = match$$1.route,
|
|
element = match$$1.route.value;
|
|
|
|
// remove the /* from the end for child routes relative paths
|
|
|
|
basepath = route.default ? basepath : route.path.replace(/\*$/, "");
|
|
|
|
var props = _extends({}, params, {
|
|
uri: uri,
|
|
location: location,
|
|
navigate: function navigate$$1(to, options) {
|
|
return _navigate2(resolve(to, uri), options);
|
|
}
|
|
});
|
|
|
|
var clone = React.cloneElement(element, props, element.props.children ? React.createElement(
|
|
Router,
|
|
{ primary: primary },
|
|
element.props.children
|
|
) : undefined);
|
|
|
|
// using 'div' for < 16.3 support
|
|
var FocusWrapper = primary ? FocusHandler : component;
|
|
// don't pass any props to 'div'
|
|
var wrapperProps = primary ? _extends({ uri: uri, location: location, component: component }, domProps) : domProps;
|
|
|
|
return React.createElement(
|
|
BaseContext.Provider,
|
|
{ value: { baseuri: uri, basepath: basepath } },
|
|
React.createElement(
|
|
FocusWrapper,
|
|
wrapperProps,
|
|
clone
|
|
)
|
|
);
|
|
} else {
|
|
// Not sure if we want this, would require index routes at every level
|
|
// warning(
|
|
// false,
|
|
// `<Router basepath="${basepath}">\n\nNothing matched:\n\t${
|
|
// location.pathname
|
|
// }\n\nPaths checked: \n\t${routes
|
|
// .map(route => route.path)
|
|
// .join(
|
|
// "\n\t"
|
|
// )}\n\nTo get rid of this warning, add a default NotFound component as child of Router:
|
|
// \n\tlet NotFound = () => <div>Not Found!</div>
|
|
// \n\t<Router>\n\t <NotFound default/>\n\t {/* ... */}\n\t</Router>`
|
|
// );
|
|
return null;
|
|
}
|
|
};
|
|
|
|
return RouterImpl;
|
|
}(React.PureComponent);
|
|
|
|
RouterImpl.defaultProps = {
|
|
primary: true
|
|
};
|
|
|
|
|
|
var FocusContext = createNamedContext("Focus");
|
|
|
|
var FocusHandler = function FocusHandler(_ref3) {
|
|
var uri = _ref3.uri,
|
|
location = _ref3.location,
|
|
component = _ref3.component,
|
|
domProps = objectWithoutProperties(_ref3, ["uri", "location", "component"]);
|
|
return React.createElement(
|
|
FocusContext.Consumer,
|
|
null,
|
|
function (requestFocus) {
|
|
return React.createElement(FocusHandlerImpl, _extends({}, domProps, {
|
|
component: component,
|
|
requestFocus: requestFocus,
|
|
uri: uri,
|
|
location: location
|
|
}));
|
|
}
|
|
);
|
|
};
|
|
|
|
// don't focus on initial render
|
|
var initialRender = true;
|
|
var focusHandlerCount = 0;
|
|
|
|
var FocusHandlerImpl = function (_React$Component2) {
|
|
inherits(FocusHandlerImpl, _React$Component2);
|
|
|
|
function FocusHandlerImpl() {
|
|
var _temp2, _this4, _ret2;
|
|
|
|
classCallCheck(this, FocusHandlerImpl);
|
|
|
|
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
args[_key2] = arguments[_key2];
|
|
}
|
|
|
|
return _ret2 = (_temp2 = (_this4 = possibleConstructorReturn(this, _React$Component2.call.apply(_React$Component2, [this].concat(args))), _this4), _this4.state = {}, _this4.requestFocus = function (node) {
|
|
if (!_this4.state.shouldFocus) {
|
|
node.focus();
|
|
}
|
|
}, _temp2), possibleConstructorReturn(_this4, _ret2);
|
|
}
|
|
|
|
FocusHandlerImpl.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
|
var initial = prevState.uri == null;
|
|
if (initial) {
|
|
return _extends({
|
|
shouldFocus: true
|
|
}, nextProps);
|
|
} else {
|
|
var myURIChanged = nextProps.uri !== prevState.uri;
|
|
var navigatedUpToMe = prevState.location.pathname !== nextProps.location.pathname && nextProps.location.pathname === nextProps.uri;
|
|
return _extends({
|
|
shouldFocus: myURIChanged || navigatedUpToMe
|
|
}, nextProps);
|
|
}
|
|
};
|
|
|
|
FocusHandlerImpl.prototype.componentDidMount = function componentDidMount() {
|
|
focusHandlerCount++;
|
|
this.focus();
|
|
};
|
|
|
|
FocusHandlerImpl.prototype.componentWillUnmount = function componentWillUnmount() {
|
|
focusHandlerCount--;
|
|
if (focusHandlerCount === 0) {
|
|
initialRender = true;
|
|
}
|
|
};
|
|
|
|
FocusHandlerImpl.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
if (prevProps.location !== this.props.location && this.state.shouldFocus) {
|
|
this.focus();
|
|
}
|
|
};
|
|
|
|
FocusHandlerImpl.prototype.focus = function focus() {
|
|
|
|
var requestFocus = this.props.requestFocus;
|
|
|
|
|
|
if (requestFocus) {
|
|
requestFocus(this.node);
|
|
} else {
|
|
if (initialRender) {
|
|
initialRender = false;
|
|
} else {
|
|
// React polyfills [autofocus] and it fires earlier than cDM,
|
|
// so we were stealing focus away, this line prevents that.
|
|
if (!this.node.contains(document.activeElement)) {
|
|
this.node.focus();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
FocusHandlerImpl.prototype.render = function render() {
|
|
var _this5 = this;
|
|
|
|
var _props2 = this.props,
|
|
children = _props2.children,
|
|
style = _props2.style,
|
|
requestFocus = _props2.requestFocus,
|
|
_props2$role = _props2.role,
|
|
role = _props2$role === undefined ? "group" : _props2$role,
|
|
_props2$component = _props2.component,
|
|
Comp = _props2$component === undefined ? "div" : _props2$component,
|
|
uri = _props2.uri,
|
|
location = _props2.location,
|
|
domProps = objectWithoutProperties(_props2, ["children", "style", "requestFocus", "role", "component", "uri", "location"]);
|
|
|
|
return React.createElement(
|
|
Comp,
|
|
_extends({
|
|
style: _extends({ outline: "none" }, style),
|
|
tabIndex: "-1",
|
|
role: role,
|
|
ref: function ref(n) {
|
|
return _this5.node = n;
|
|
}
|
|
}, domProps),
|
|
React.createElement(
|
|
FocusContext.Provider,
|
|
{ value: this.requestFocus },
|
|
this.props.children
|
|
)
|
|
);
|
|
};
|
|
|
|
return FocusHandlerImpl;
|
|
}(React.Component);
|
|
|
|
polyfill(FocusHandlerImpl);
|
|
|
|
var k = function k() {};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
var forwardRef = React.forwardRef;
|
|
|
|
if (typeof forwardRef === "undefined") {
|
|
forwardRef = function forwardRef(C) {
|
|
return C;
|
|
};
|
|
}
|
|
|
|
var Link = forwardRef(function (_ref4, ref) {
|
|
var innerRef = _ref4.innerRef,
|
|
props = objectWithoutProperties(_ref4, ["innerRef"]);
|
|
return React.createElement(
|
|
BaseContext.Consumer,
|
|
null,
|
|
function (_ref5) {
|
|
var basepath = _ref5.basepath,
|
|
baseuri = _ref5.baseuri;
|
|
return React.createElement(
|
|
Location,
|
|
null,
|
|
function (_ref6) {
|
|
var location = _ref6.location,
|
|
navigate$$1 = _ref6.navigate;
|
|
var to = props.to,
|
|
state = props.state,
|
|
replace = props.replace,
|
|
_props$getProps = props.getProps,
|
|
getProps = _props$getProps === undefined ? k : _props$getProps,
|
|
anchorProps = objectWithoutProperties(props, ["to", "state", "replace", "getProps"]);
|
|
|
|
var href = resolve(to, baseuri);
|
|
var isCurrent = location.pathname === href;
|
|
var isPartiallyCurrent = startsWith(location.pathname, href);
|
|
|
|
return React.createElement("a", _extends({
|
|
ref: ref || innerRef,
|
|
"aria-current": isCurrent ? "page" : undefined
|
|
}, anchorProps, getProps({ isCurrent: isCurrent, isPartiallyCurrent: isPartiallyCurrent, href: href, location: location }), {
|
|
href: href,
|
|
onClick: function onClick(event) {
|
|
if (anchorProps.onClick) anchorProps.onClick(event);
|
|
if (shouldNavigate(event)) {
|
|
event.preventDefault();
|
|
navigate$$1(href, { state: state, replace: replace });
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
);
|
|
}
|
|
);
|
|
});
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
function RedirectRequest(uri) {
|
|
this.uri = uri;
|
|
}
|
|
|
|
var isRedirect = function isRedirect(o) {
|
|
return o instanceof RedirectRequest;
|
|
};
|
|
|
|
var redirectTo = function redirectTo(to) {
|
|
throw new RedirectRequest(to);
|
|
};
|
|
|
|
var RedirectImpl = function (_React$Component3) {
|
|
inherits(RedirectImpl, _React$Component3);
|
|
|
|
function RedirectImpl() {
|
|
classCallCheck(this, RedirectImpl);
|
|
return possibleConstructorReturn(this, _React$Component3.apply(this, arguments));
|
|
}
|
|
|
|
// Support React < 16 with this hook
|
|
RedirectImpl.prototype.componentDidMount = function componentDidMount() {
|
|
var _props3 = this.props,
|
|
navigate$$1 = _props3.navigate,
|
|
to = _props3.to,
|
|
from = _props3.from,
|
|
_props3$replace = _props3.replace,
|
|
replace = _props3$replace === undefined ? true : _props3$replace,
|
|
state = _props3.state,
|
|
noThrow = _props3.noThrow,
|
|
props = objectWithoutProperties(_props3, ["navigate", "to", "from", "replace", "state", "noThrow"]);
|
|
|
|
Promise.resolve().then(function () {
|
|
navigate$$1(insertParams(to, props), { replace: replace, state: state });
|
|
});
|
|
};
|
|
|
|
RedirectImpl.prototype.render = function render() {
|
|
var _props4 = this.props,
|
|
navigate$$1 = _props4.navigate,
|
|
to = _props4.to,
|
|
from = _props4.from,
|
|
replace = _props4.replace,
|
|
state = _props4.state,
|
|
noThrow = _props4.noThrow,
|
|
props = objectWithoutProperties(_props4, ["navigate", "to", "from", "replace", "state", "noThrow"]);
|
|
|
|
if (!noThrow) redirectTo(insertParams(to, props));
|
|
return null;
|
|
};
|
|
|
|
return RedirectImpl;
|
|
}(React.Component);
|
|
|
|
var Redirect = function Redirect(props) {
|
|
return React.createElement(
|
|
Location,
|
|
null,
|
|
function (locationContext) {
|
|
return React.createElement(RedirectImpl, _extends({}, locationContext, props));
|
|
}
|
|
);
|
|
};
|
|
|
|
Redirect.propTypes = {
|
|
from: propTypes.string,
|
|
to: propTypes.string.isRequired
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
var Match = function Match(_ref7) {
|
|
var path = _ref7.path,
|
|
children = _ref7.children;
|
|
return React.createElement(
|
|
BaseContext.Consumer,
|
|
null,
|
|
function (_ref8) {
|
|
var baseuri = _ref8.baseuri;
|
|
return React.createElement(
|
|
Location,
|
|
null,
|
|
function (_ref9) {
|
|
var navigate$$1 = _ref9.navigate,
|
|
location = _ref9.location;
|
|
|
|
var resolvedPath = resolve(path, baseuri);
|
|
var result = match(resolvedPath, location.pathname);
|
|
return children({
|
|
navigate: navigate$$1,
|
|
location: location,
|
|
match: result ? _extends({}, result.params, {
|
|
uri: result.uri,
|
|
path: path
|
|
}) : null
|
|
});
|
|
}
|
|
);
|
|
}
|
|
);
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Junk
|
|
var stripSlashes = function stripSlashes(str) {
|
|
return str.replace(/(^\/+|\/+$)/g, "");
|
|
};
|
|
|
|
var createRoute = function createRoute(basepath) {
|
|
return function (element) {
|
|
if (!element) {
|
|
return null;
|
|
}
|
|
|
|
!(element.props.path || element.props.default || element.type === Redirect) ? invariant_1$1(false, "<Router>: Children of <Router> must have a `path` or `default` prop, or be a `<Redirect>`. None found on element type `" + element.type + "`") : void 0;
|
|
|
|
!!(element.type === Redirect && (!element.props.from || !element.props.to)) ? invariant_1$1(false, "<Redirect from=\"" + element.props.from + " to=\"" + element.props.to + "\"/> requires both \"from\" and \"to\" props when inside a <Router>.") : void 0;
|
|
|
|
!!(element.type === Redirect && !validateRedirect(element.props.from, element.props.to)) ? invariant_1$1(false, "<Redirect from=\"" + element.props.from + " to=\"" + element.props.to + "\"/> has mismatched dynamic segments, ensure both paths have the exact same dynamic segments.") : void 0;
|
|
|
|
if (element.props.default) {
|
|
return { value: element, default: true };
|
|
}
|
|
|
|
var elementPath = element.type === Redirect ? element.props.from : element.props.path;
|
|
|
|
var path = elementPath === "/" ? basepath : stripSlashes(basepath) + "/" + stripSlashes(elementPath);
|
|
|
|
return {
|
|
value: element,
|
|
default: element.props.default,
|
|
path: element.props.children ? stripSlashes(path) + "/*" : path
|
|
};
|
|
};
|
|
};
|
|
|
|
var shouldNavigate = function shouldNavigate(event) {
|
|
return !event.defaultPrevented && event.button === 0 && !(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
};
|
|
|
|
exports.Link = Link;
|
|
exports.Location = Location;
|
|
exports.LocationProvider = LocationProvider;
|
|
exports.Match = Match;
|
|
exports.Redirect = Redirect;
|
|
exports.Router = Router;
|
|
exports.ServerLocation = ServerLocation;
|
|
exports.createHistory = createHistory;
|
|
exports.createMemorySource = createMemorySource;
|
|
exports.isRedirect = isRedirect;
|
|
exports.navigate = navigate;
|
|
exports.redirectTo = redirectTo;
|
|
exports.globalHistory = globalHistory;
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
})));
|