1 |
3a515b92
|
cagy
|
(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 |
|
|
(global = global || self, factory(global.ReactRouterDOM = {}, global.React));
|
5 |
|
|
}(this, function (exports, React) { 'use strict';
|
6 |
|
|
|
7 |
|
|
var React__default = 'default' in React ? React['default'] : React;
|
8 |
|
|
|
9 |
|
|
function _inheritsLoose(subClass, superClass) {
|
10 |
|
|
subClass.prototype = Object.create(superClass.prototype);
|
11 |
|
|
subClass.prototype.constructor = subClass;
|
12 |
|
|
subClass.__proto__ = superClass;
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
16 |
|
|
|
17 |
|
|
function unwrapExports (x) {
|
18 |
|
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
function createCommonjsModule(fn, module) {
|
22 |
|
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
var reactIs_production_min = createCommonjsModule(function (module, exports) {
|
26 |
|
|
Object.defineProperty(exports,"__esModule",{value:!0});
|
27 |
|
|
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?Symbol.for("react.suspense_list"):
|
28 |
|
|
60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.fundamental"):60117,w=b?Symbol.for("react.responder"):60118;function x(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case h:return a;default:return u}}case t:case r:case d:return u}}}function y(a){return x(a)===m}exports.typeOf=x;exports.AsyncMode=l;
|
29 |
|
|
exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;exports.Fragment=e;exports.Lazy=t;exports.Memo=r;exports.Portal=d;exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p;
|
30 |
|
|
exports.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===v||a.$$typeof===w)};exports.isAsyncMode=function(a){return y(a)||x(a)===l};exports.isConcurrentMode=y;exports.isContextConsumer=function(a){return x(a)===k};exports.isContextProvider=function(a){return x(a)===h};
|
31 |
|
|
exports.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return x(a)===n};exports.isFragment=function(a){return x(a)===e};exports.isLazy=function(a){return x(a)===t};exports.isMemo=function(a){return x(a)===r};exports.isPortal=function(a){return x(a)===d};exports.isProfiler=function(a){return x(a)===g};exports.isStrictMode=function(a){return x(a)===f};exports.isSuspense=function(a){return x(a)===p};
|
32 |
|
|
});
|
33 |
|
|
|
34 |
|
|
unwrapExports(reactIs_production_min);
|
35 |
|
|
var reactIs_production_min_1 = reactIs_production_min.typeOf;
|
36 |
|
|
var reactIs_production_min_2 = reactIs_production_min.AsyncMode;
|
37 |
|
|
var reactIs_production_min_3 = reactIs_production_min.ConcurrentMode;
|
38 |
|
|
var reactIs_production_min_4 = reactIs_production_min.ContextConsumer;
|
39 |
|
|
var reactIs_production_min_5 = reactIs_production_min.ContextProvider;
|
40 |
|
|
var reactIs_production_min_6 = reactIs_production_min.Element;
|
41 |
|
|
var reactIs_production_min_7 = reactIs_production_min.ForwardRef;
|
42 |
|
|
var reactIs_production_min_8 = reactIs_production_min.Fragment;
|
43 |
|
|
var reactIs_production_min_9 = reactIs_production_min.Lazy;
|
44 |
|
|
var reactIs_production_min_10 = reactIs_production_min.Memo;
|
45 |
|
|
var reactIs_production_min_11 = reactIs_production_min.Portal;
|
46 |
|
|
var reactIs_production_min_12 = reactIs_production_min.Profiler;
|
47 |
|
|
var reactIs_production_min_13 = reactIs_production_min.StrictMode;
|
48 |
|
|
var reactIs_production_min_14 = reactIs_production_min.Suspense;
|
49 |
|
|
var reactIs_production_min_15 = reactIs_production_min.isValidElementType;
|
50 |
|
|
var reactIs_production_min_16 = reactIs_production_min.isAsyncMode;
|
51 |
|
|
var reactIs_production_min_17 = reactIs_production_min.isConcurrentMode;
|
52 |
|
|
var reactIs_production_min_18 = reactIs_production_min.isContextConsumer;
|
53 |
|
|
var reactIs_production_min_19 = reactIs_production_min.isContextProvider;
|
54 |
|
|
var reactIs_production_min_20 = reactIs_production_min.isElement;
|
55 |
|
|
var reactIs_production_min_21 = reactIs_production_min.isForwardRef;
|
56 |
|
|
var reactIs_production_min_22 = reactIs_production_min.isFragment;
|
57 |
|
|
var reactIs_production_min_23 = reactIs_production_min.isLazy;
|
58 |
|
|
var reactIs_production_min_24 = reactIs_production_min.isMemo;
|
59 |
|
|
var reactIs_production_min_25 = reactIs_production_min.isPortal;
|
60 |
|
|
var reactIs_production_min_26 = reactIs_production_min.isProfiler;
|
61 |
|
|
var reactIs_production_min_27 = reactIs_production_min.isStrictMode;
|
62 |
|
|
var reactIs_production_min_28 = reactIs_production_min.isSuspense;
|
63 |
|
|
|
64 |
|
|
var reactIs_development = createCommonjsModule(function (module, exports) {
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
{
|
69 |
|
|
(function() {
|
70 |
|
|
|
71 |
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
72 |
|
|
|
73 |
|
|
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
74 |
|
|
// nor polyfill, then a plain number is used for performance.
|
75 |
|
|
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
76 |
|
|
|
77 |
|
|
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
78 |
|
|
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
79 |
|
|
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
80 |
|
|
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
81 |
|
|
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
82 |
|
|
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
83 |
|
|
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
84 |
|
|
// TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
|
85 |
|
|
// (unstable) APIs that have been removed. Can we remove the symbols?
|
86 |
|
|
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
87 |
|
|
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
88 |
|
|
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
89 |
|
|
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
90 |
|
|
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
|
91 |
|
|
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
92 |
|
|
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
93 |
|
|
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
|
94 |
|
|
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
|
95 |
|
|
|
96 |
|
|
function isValidElementType(type) {
|
97 |
|
|
return typeof type === 'string' || typeof type === 'function' ||
|
98 |
|
|
// Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
99 |
|
|
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
/**
|
103 |
|
|
* Forked from fbjs/warning:
|
104 |
|
|
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
105 |
|
|
*
|
106 |
|
|
* Only change is we use console.warn instead of console.error,
|
107 |
|
|
* and do nothing when 'console' is not supported.
|
108 |
|
|
* This really simplifies the code.
|
109 |
|
|
* ---
|
110 |
|
|
* Similar to invariant but only logs a warning if the condition is not met.
|
111 |
|
|
* This can be used to log issues in development environments in critical
|
112 |
|
|
* paths. Removing the logging code for production environments will keep the
|
113 |
|
|
* same logic and follow the same code paths.
|
114 |
|
|
*/
|
115 |
|
|
|
116 |
|
|
var lowPriorityWarning = function () {};
|
117 |
|
|
|
118 |
|
|
{
|
119 |
|
|
var printWarning = function (format) {
|
120 |
|
|
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
121 |
|
|
args[_key - 1] = arguments[_key];
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
var argIndex = 0;
|
125 |
|
|
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
126 |
|
|
return args[argIndex++];
|
127 |
|
|
});
|
128 |
|
|
if (typeof console !== 'undefined') {
|
129 |
|
|
console.warn(message);
|
130 |
|
|
}
|
131 |
|
|
try {
|
132 |
|
|
// --- Welcome to debugging React ---
|
133 |
|
|
// This error was thrown as a convenience so that you can use this stack
|
134 |
|
|
// to find the callsite that caused this warning to fire.
|
135 |
|
|
throw new Error(message);
|
136 |
|
|
} catch (x) {}
|
137 |
|
|
};
|
138 |
|
|
|
139 |
|
|
lowPriorityWarning = function (condition, format) {
|
140 |
|
|
if (format === undefined) {
|
141 |
|
|
throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
|
142 |
|
|
}
|
143 |
|
|
if (!condition) {
|
144 |
|
|
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
145 |
|
|
args[_key2 - 2] = arguments[_key2];
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
printWarning.apply(undefined, [format].concat(args));
|
149 |
|
|
}
|
150 |
|
|
};
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
var lowPriorityWarning$1 = lowPriorityWarning;
|
154 |
|
|
|
155 |
|
|
function typeOf(object) {
|
156 |
|
|
if (typeof object === 'object' && object !== null) {
|
157 |
|
|
var $$typeof = object.$$typeof;
|
158 |
|
|
switch ($$typeof) {
|
159 |
|
|
case REACT_ELEMENT_TYPE:
|
160 |
|
|
var type = object.type;
|
161 |
|
|
|
162 |
|
|
switch (type) {
|
163 |
|
|
case REACT_ASYNC_MODE_TYPE:
|
164 |
|
|
case REACT_CONCURRENT_MODE_TYPE:
|
165 |
|
|
case REACT_FRAGMENT_TYPE:
|
166 |
|
|
case REACT_PROFILER_TYPE:
|
167 |
|
|
case REACT_STRICT_MODE_TYPE:
|
168 |
|
|
case REACT_SUSPENSE_TYPE:
|
169 |
|
|
return type;
|
170 |
|
|
default:
|
171 |
|
|
var $$typeofType = type && type.$$typeof;
|
172 |
|
|
|
173 |
|
|
switch ($$typeofType) {
|
174 |
|
|
case REACT_CONTEXT_TYPE:
|
175 |
|
|
case REACT_FORWARD_REF_TYPE:
|
176 |
|
|
case REACT_PROVIDER_TYPE:
|
177 |
|
|
return $$typeofType;
|
178 |
|
|
default:
|
179 |
|
|
return $$typeof;
|
180 |
|
|
}
|
181 |
|
|
}
|
182 |
|
|
case REACT_LAZY_TYPE:
|
183 |
|
|
case REACT_MEMO_TYPE:
|
184 |
|
|
case REACT_PORTAL_TYPE:
|
185 |
|
|
return $$typeof;
|
186 |
|
|
}
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
return undefined;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
// AsyncMode is deprecated along with isAsyncMode
|
193 |
|
|
var AsyncMode = REACT_ASYNC_MODE_TYPE;
|
194 |
|
|
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
|
195 |
|
|
var ContextConsumer = REACT_CONTEXT_TYPE;
|
196 |
|
|
var ContextProvider = REACT_PROVIDER_TYPE;
|
197 |
|
|
var Element = REACT_ELEMENT_TYPE;
|
198 |
|
|
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
199 |
|
|
var Fragment = REACT_FRAGMENT_TYPE;
|
200 |
|
|
var Lazy = REACT_LAZY_TYPE;
|
201 |
|
|
var Memo = REACT_MEMO_TYPE;
|
202 |
|
|
var Portal = REACT_PORTAL_TYPE;
|
203 |
|
|
var Profiler = REACT_PROFILER_TYPE;
|
204 |
|
|
var StrictMode = REACT_STRICT_MODE_TYPE;
|
205 |
|
|
var Suspense = REACT_SUSPENSE_TYPE;
|
206 |
|
|
|
207 |
|
|
var hasWarnedAboutDeprecatedIsAsyncMode = false;
|
208 |
|
|
|
209 |
|
|
// AsyncMode should be deprecated
|
210 |
|
|
function isAsyncMode(object) {
|
211 |
|
|
{
|
212 |
|
|
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
213 |
|
|
hasWarnedAboutDeprecatedIsAsyncMode = true;
|
214 |
|
|
lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
|
215 |
|
|
}
|
216 |
|
|
}
|
217 |
|
|
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
218 |
|
|
}
|
219 |
|
|
function isConcurrentMode(object) {
|
220 |
|
|
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
|
221 |
|
|
}
|
222 |
|
|
function isContextConsumer(object) {
|
223 |
|
|
return typeOf(object) === REACT_CONTEXT_TYPE;
|
224 |
|
|
}
|
225 |
|
|
function isContextProvider(object) {
|
226 |
|
|
return typeOf(object) === REACT_PROVIDER_TYPE;
|
227 |
|
|
}
|
228 |
|
|
function isElement(object) {
|
229 |
|
|
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
230 |
|
|
}
|
231 |
|
|
function isForwardRef(object) {
|
232 |
|
|
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
233 |
|
|
}
|
234 |
|
|
function isFragment(object) {
|
235 |
|
|
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
236 |
|
|
}
|
237 |
|
|
function isLazy(object) {
|
238 |
|
|
return typeOf(object) === REACT_LAZY_TYPE;
|
239 |
|
|
}
|
240 |
|
|
function isMemo(object) {
|
241 |
|
|
return typeOf(object) === REACT_MEMO_TYPE;
|
242 |
|
|
}
|
243 |
|
|
function isPortal(object) {
|
244 |
|
|
return typeOf(object) === REACT_PORTAL_TYPE;
|
245 |
|
|
}
|
246 |
|
|
function isProfiler(object) {
|
247 |
|
|
return typeOf(object) === REACT_PROFILER_TYPE;
|
248 |
|
|
}
|
249 |
|
|
function isStrictMode(object) {
|
250 |
|
|
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
251 |
|
|
}
|
252 |
|
|
function isSuspense(object) {
|
253 |
|
|
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
exports.typeOf = typeOf;
|
257 |
|
|
exports.AsyncMode = AsyncMode;
|
258 |
|
|
exports.ConcurrentMode = ConcurrentMode;
|
259 |
|
|
exports.ContextConsumer = ContextConsumer;
|
260 |
|
|
exports.ContextProvider = ContextProvider;
|
261 |
|
|
exports.Element = Element;
|
262 |
|
|
exports.ForwardRef = ForwardRef;
|
263 |
|
|
exports.Fragment = Fragment;
|
264 |
|
|
exports.Lazy = Lazy;
|
265 |
|
|
exports.Memo = Memo;
|
266 |
|
|
exports.Portal = Portal;
|
267 |
|
|
exports.Profiler = Profiler;
|
268 |
|
|
exports.StrictMode = StrictMode;
|
269 |
|
|
exports.Suspense = Suspense;
|
270 |
|
|
exports.isValidElementType = isValidElementType;
|
271 |
|
|
exports.isAsyncMode = isAsyncMode;
|
272 |
|
|
exports.isConcurrentMode = isConcurrentMode;
|
273 |
|
|
exports.isContextConsumer = isContextConsumer;
|
274 |
|
|
exports.isContextProvider = isContextProvider;
|
275 |
|
|
exports.isElement = isElement;
|
276 |
|
|
exports.isForwardRef = isForwardRef;
|
277 |
|
|
exports.isFragment = isFragment;
|
278 |
|
|
exports.isLazy = isLazy;
|
279 |
|
|
exports.isMemo = isMemo;
|
280 |
|
|
exports.isPortal = isPortal;
|
281 |
|
|
exports.isProfiler = isProfiler;
|
282 |
|
|
exports.isStrictMode = isStrictMode;
|
283 |
|
|
exports.isSuspense = isSuspense;
|
284 |
|
|
})();
|
285 |
|
|
}
|
286 |
|
|
});
|
287 |
|
|
|
288 |
|
|
unwrapExports(reactIs_development);
|
289 |
|
|
var reactIs_development_1 = reactIs_development.typeOf;
|
290 |
|
|
var reactIs_development_2 = reactIs_development.AsyncMode;
|
291 |
|
|
var reactIs_development_3 = reactIs_development.ConcurrentMode;
|
292 |
|
|
var reactIs_development_4 = reactIs_development.ContextConsumer;
|
293 |
|
|
var reactIs_development_5 = reactIs_development.ContextProvider;
|
294 |
|
|
var reactIs_development_6 = reactIs_development.Element;
|
295 |
|
|
var reactIs_development_7 = reactIs_development.ForwardRef;
|
296 |
|
|
var reactIs_development_8 = reactIs_development.Fragment;
|
297 |
|
|
var reactIs_development_9 = reactIs_development.Lazy;
|
298 |
|
|
var reactIs_development_10 = reactIs_development.Memo;
|
299 |
|
|
var reactIs_development_11 = reactIs_development.Portal;
|
300 |
|
|
var reactIs_development_12 = reactIs_development.Profiler;
|
301 |
|
|
var reactIs_development_13 = reactIs_development.StrictMode;
|
302 |
|
|
var reactIs_development_14 = reactIs_development.Suspense;
|
303 |
|
|
var reactIs_development_15 = reactIs_development.isValidElementType;
|
304 |
|
|
var reactIs_development_16 = reactIs_development.isAsyncMode;
|
305 |
|
|
var reactIs_development_17 = reactIs_development.isConcurrentMode;
|
306 |
|
|
var reactIs_development_18 = reactIs_development.isContextConsumer;
|
307 |
|
|
var reactIs_development_19 = reactIs_development.isContextProvider;
|
308 |
|
|
var reactIs_development_20 = reactIs_development.isElement;
|
309 |
|
|
var reactIs_development_21 = reactIs_development.isForwardRef;
|
310 |
|
|
var reactIs_development_22 = reactIs_development.isFragment;
|
311 |
|
|
var reactIs_development_23 = reactIs_development.isLazy;
|
312 |
|
|
var reactIs_development_24 = reactIs_development.isMemo;
|
313 |
|
|
var reactIs_development_25 = reactIs_development.isPortal;
|
314 |
|
|
var reactIs_development_26 = reactIs_development.isProfiler;
|
315 |
|
|
var reactIs_development_27 = reactIs_development.isStrictMode;
|
316 |
|
|
var reactIs_development_28 = reactIs_development.isSuspense;
|
317 |
|
|
|
318 |
|
|
var reactIs = createCommonjsModule(function (module) {
|
319 |
|
|
|
320 |
|
|
{
|
321 |
|
|
module.exports = reactIs_development;
|
322 |
|
|
}
|
323 |
|
|
});
|
324 |
|
|
var reactIs_1 = reactIs.isValidElementType;
|
325 |
|
|
|
326 |
|
|
/*
|
327 |
|
|
object-assign
|
328 |
|
|
(c) Sindre Sorhus
|
329 |
|
|
@license MIT
|
330 |
|
|
*/
|
331 |
|
|
/* eslint-disable no-unused-vars */
|
332 |
|
|
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
333 |
|
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
334 |
|
|
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
335 |
|
|
|
336 |
|
|
function toObject(val) {
|
337 |
|
|
if (val === null || val === undefined) {
|
338 |
|
|
throw new TypeError('Object.assign cannot be called with null or undefined');
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
return Object(val);
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
function shouldUseNative() {
|
345 |
|
|
try {
|
346 |
|
|
if (!Object.assign) {
|
347 |
|
|
return false;
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
// Detect buggy property enumeration order in older V8 versions.
|
351 |
|
|
|
352 |
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
353 |
|
|
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
|
354 |
|
|
test1[5] = 'de';
|
355 |
|
|
if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
356 |
|
|
return false;
|
357 |
|
|
}
|
358 |
|
|
|
359 |
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
360 |
|
|
var test2 = {};
|
361 |
|
|
for (var i = 0; i < 10; i++) {
|
362 |
|
|
test2['_' + String.fromCharCode(i)] = i;
|
363 |
|
|
}
|
364 |
|
|
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
365 |
|
|
return test2[n];
|
366 |
|
|
});
|
367 |
|
|
if (order2.join('') !== '0123456789') {
|
368 |
|
|
return false;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
372 |
|
|
var test3 = {};
|
373 |
|
|
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
374 |
|
|
test3[letter] = letter;
|
375 |
|
|
});
|
376 |
|
|
if (Object.keys(Object.assign({}, test3)).join('') !==
|
377 |
|
|
'abcdefghijklmnopqrst') {
|
378 |
|
|
return false;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
return true;
|
382 |
|
|
} catch (err) {
|
383 |
|
|
// We don't expect any of the above to throw, but better to be safe.
|
384 |
|
|
return false;
|
385 |
|
|
}
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
389 |
|
|
var from;
|
390 |
|
|
var to = toObject(target);
|
391 |
|
|
var symbols;
|
392 |
|
|
|
393 |
|
|
for (var s = 1; s < arguments.length; s++) {
|
394 |
|
|
from = Object(arguments[s]);
|
395 |
|
|
|
396 |
|
|
for (var key in from) {
|
397 |
|
|
if (hasOwnProperty.call(from, key)) {
|
398 |
|
|
to[key] = from[key];
|
399 |
|
|
}
|
400 |
|
|
}
|
401 |
|
|
|
402 |
|
|
if (getOwnPropertySymbols) {
|
403 |
|
|
symbols = getOwnPropertySymbols(from);
|
404 |
|
|
for (var i = 0; i < symbols.length; i++) {
|
405 |
|
|
if (propIsEnumerable.call(from, symbols[i])) {
|
406 |
|
|
to[symbols[i]] = from[symbols[i]];
|
407 |
|
|
}
|
408 |
|
|
}
|
409 |
|
|
}
|
410 |
|
|
}
|
411 |
|
|
|
412 |
|
|
return to;
|
413 |
|
|
};
|
414 |
|
|
|
415 |
|
|
/**
|
416 |
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
417 |
|
|
*
|
418 |
|
|
* This source code is licensed under the MIT license found in the
|
419 |
|
|
* LICENSE file in the root directory of this source tree.
|
420 |
|
|
*/
|
421 |
|
|
|
422 |
|
|
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
423 |
|
|
|
424 |
|
|
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
|
425 |
|
|
|
426 |
|
|
var printWarning = function() {};
|
427 |
|
|
|
428 |
|
|
{
|
429 |
|
|
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
430 |
|
|
var loggedTypeFailures = {};
|
431 |
|
|
var has = Function.call.bind(Object.prototype.hasOwnProperty);
|
432 |
|
|
|
433 |
|
|
printWarning = function(text) {
|
434 |
|
|
var message = 'Warning: ' + text;
|
435 |
|
|
if (typeof console !== 'undefined') {
|
436 |
|
|
console.error(message);
|
437 |
|
|
}
|
438 |
|
|
try {
|
439 |
|
|
// --- Welcome to debugging React ---
|
440 |
|
|
// This error was thrown as a convenience so that you can use this stack
|
441 |
|
|
// to find the callsite that caused this warning to fire.
|
442 |
|
|
throw new Error(message);
|
443 |
|
|
} catch (x) {}
|
444 |
|
|
};
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
/**
|
448 |
|
|
* Assert that the values match with the type specs.
|
449 |
|
|
* Error messages are memorized and will only be shown once.
|
450 |
|
|
*
|
451 |
|
|
* @param {object} typeSpecs Map of name to a ReactPropType
|
452 |
|
|
* @param {object} values Runtime values that need to be type-checked
|
453 |
|
|
* @param {string} location e.g. "prop", "context", "child context"
|
454 |
|
|
* @param {string} componentName Name of the component for error messages.
|
455 |
|
|
* @param {?Function} getStack Returns the component stack.
|
456 |
|
|
* @private
|
457 |
|
|
*/
|
458 |
|
|
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
459 |
|
|
{
|
460 |
|
|
for (var typeSpecName in typeSpecs) {
|
461 |
|
|
if (has(typeSpecs, typeSpecName)) {
|
462 |
|
|
var error;
|
463 |
|
|
// Prop type validation may throw. In case they do, we don't want to
|
464 |
|
|
// fail the render phase where it didn't fail before. So we log it.
|
465 |
|
|
// After these have been cleaned up, we'll let them throw.
|
466 |
|
|
try {
|
467 |
|
|
// This is intentionally an invariant that gets caught. It's the same
|
468 |
|
|
// behavior as without this statement except with a better message.
|
469 |
|
|
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
470 |
|
|
var err = Error(
|
471 |
|
|
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
472 |
|
|
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
473 |
|
|
);
|
474 |
|
|
err.name = 'Invariant Violation';
|
475 |
|
|
throw err;
|
476 |
|
|
}
|
477 |
|
|
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
|
478 |
|
|
} catch (ex) {
|
479 |
|
|
error = ex;
|
480 |
|
|
}
|
481 |
|
|
if (error && !(error instanceof Error)) {
|
482 |
|
|
printWarning(
|
483 |
|
|
(componentName || 'React class') + ': type specification of ' +
|
484 |
|
|
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
485 |
|
|
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
486 |
|
|
'You may have forgotten to pass an argument to the type checker ' +
|
487 |
|
|
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
488 |
|
|
'shape all require an argument).'
|
489 |
|
|
);
|
490 |
|
|
}
|
491 |
|
|
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
492 |
|
|
// Only monitor this failure once because there tends to be a lot of the
|
493 |
|
|
// same error.
|
494 |
|
|
loggedTypeFailures[error.message] = true;
|
495 |
|
|
|
496 |
|
|
var stack = getStack ? getStack() : '';
|
497 |
|
|
|
498 |
|
|
printWarning(
|
499 |
|
|
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
500 |
|
|
);
|
501 |
|
|
}
|
502 |
|
|
}
|
503 |
|
|
}
|
504 |
|
|
}
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
/**
|
508 |
|
|
* Resets warning cache when testing.
|
509 |
|
|
*
|
510 |
|
|
* @private
|
511 |
|
|
*/
|
512 |
|
|
checkPropTypes.resetWarningCache = function() {
|
513 |
|
|
{
|
514 |
|
|
loggedTypeFailures = {};
|
515 |
|
|
}
|
516 |
|
|
};
|
517 |
|
|
|
518 |
|
|
var checkPropTypes_1 = checkPropTypes;
|
519 |
|
|
|
520 |
|
|
var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
|
521 |
|
|
var printWarning$1 = function() {};
|
522 |
|
|
|
523 |
|
|
{
|
524 |
|
|
printWarning$1 = function(text) {
|
525 |
|
|
var message = 'Warning: ' + text;
|
526 |
|
|
if (typeof console !== 'undefined') {
|
527 |
|
|
console.error(message);
|
528 |
|
|
}
|
529 |
|
|
try {
|
530 |
|
|
// --- Welcome to debugging React ---
|
531 |
|
|
// This error was thrown as a convenience so that you can use this stack
|
532 |
|
|
// to find the callsite that caused this warning to fire.
|
533 |
|
|
throw new Error(message);
|
534 |
|
|
} catch (x) {}
|
535 |
|
|
};
|
536 |
|
|
}
|
537 |
|
|
|
538 |
|
|
function emptyFunctionThatReturnsNull() {
|
539 |
|
|
return null;
|
540 |
|
|
}
|
541 |
|
|
|
542 |
|
|
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
543 |
|
|
/* global Symbol */
|
544 |
|
|
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
545 |
|
|
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
546 |
|
|
|
547 |
|
|
/**
|
548 |
|
|
* Returns the iterator method function contained on the iterable object.
|
549 |
|
|
*
|
550 |
|
|
* Be sure to invoke the function with the iterable as context:
|
551 |
|
|
*
|
552 |
|
|
* var iteratorFn = getIteratorFn(myIterable);
|
553 |
|
|
* if (iteratorFn) {
|
554 |
|
|
* var iterator = iteratorFn.call(myIterable);
|
555 |
|
|
* ...
|
556 |
|
|
* }
|
557 |
|
|
*
|
558 |
|
|
* @param {?object} maybeIterable
|
559 |
|
|
* @return {?function}
|
560 |
|
|
*/
|
561 |
|
|
function getIteratorFn(maybeIterable) {
|
562 |
|
|
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
563 |
|
|
if (typeof iteratorFn === 'function') {
|
564 |
|
|
return iteratorFn;
|
565 |
|
|
}
|
566 |
|
|
}
|
567 |
|
|
|
568 |
|
|
/**
|
569 |
|
|
* Collection of methods that allow declaration and validation of props that are
|
570 |
|
|
* supplied to React components. Example usage:
|
571 |
|
|
*
|
572 |
|
|
* var Props = require('ReactPropTypes');
|
573 |
|
|
* var MyArticle = React.createClass({
|
574 |
|
|
* propTypes: {
|
575 |
|
|
* // An optional string prop named "description".
|
576 |
|
|
* description: Props.string,
|
577 |
|
|
*
|
578 |
|
|
* // A required enum prop named "category".
|
579 |
|
|
* category: Props.oneOf(['News','Photos']).isRequired,
|
580 |
|
|
*
|
581 |
|
|
* // A prop named "dialog" that requires an instance of Dialog.
|
582 |
|
|
* dialog: Props.instanceOf(Dialog).isRequired
|
583 |
|
|
* },
|
584 |
|
|
* render: function() { ... }
|
585 |
|
|
* });
|
586 |
|
|
*
|
587 |
|
|
* A more formal specification of how these methods are used:
|
588 |
|
|
*
|
589 |
|
|
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
590 |
|
|
* decl := ReactPropTypes.{type}(.isRequired)?
|
591 |
|
|
*
|
592 |
|
|
* Each and every declaration produces a function with the same signature. This
|
593 |
|
|
* allows the creation of custom validation functions. For example:
|
594 |
|
|
*
|
595 |
|
|
* var MyLink = React.createClass({
|
596 |
|
|
* propTypes: {
|
597 |
|
|
* // An optional string or URI prop named "href".
|
598 |
|
|
* href: function(props, propName, componentName) {
|
599 |
|
|
* var propValue = props[propName];
|
600 |
|
|
* if (propValue != null && typeof propValue !== 'string' &&
|
601 |
|
|
* !(propValue instanceof URI)) {
|
602 |
|
|
* return new Error(
|
603 |
|
|
* 'Expected a string or an URI for ' + propName + ' in ' +
|
604 |
|
|
* componentName
|
605 |
|
|
* );
|
606 |
|
|
* }
|
607 |
|
|
* }
|
608 |
|
|
* },
|
609 |
|
|
* render: function() {...}
|
610 |
|
|
* });
|
611 |
|
|
*
|
612 |
|
|
* @internal
|
613 |
|
|
*/
|
614 |
|
|
|
615 |
|
|
var ANONYMOUS = '<<anonymous>>';
|
616 |
|
|
|
617 |
|
|
// Important!
|
618 |
|
|
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
619 |
|
|
var ReactPropTypes = {
|
620 |
|
|
array: createPrimitiveTypeChecker('array'),
|
621 |
|
|
bool: createPrimitiveTypeChecker('boolean'),
|
622 |
|
|
func: createPrimitiveTypeChecker('function'),
|
623 |
|
|
number: createPrimitiveTypeChecker('number'),
|
624 |
|
|
object: createPrimitiveTypeChecker('object'),
|
625 |
|
|
string: createPrimitiveTypeChecker('string'),
|
626 |
|
|
symbol: createPrimitiveTypeChecker('symbol'),
|
627 |
|
|
|
628 |
|
|
any: createAnyTypeChecker(),
|
629 |
|
|
arrayOf: createArrayOfTypeChecker,
|
630 |
|
|
element: createElementTypeChecker(),
|
631 |
|
|
elementType: createElementTypeTypeChecker(),
|
632 |
|
|
instanceOf: createInstanceTypeChecker,
|
633 |
|
|
node: createNodeChecker(),
|
634 |
|
|
objectOf: createObjectOfTypeChecker,
|
635 |
|
|
oneOf: createEnumTypeChecker,
|
636 |
|
|
oneOfType: createUnionTypeChecker,
|
637 |
|
|
shape: createShapeTypeChecker,
|
638 |
|
|
exact: createStrictShapeTypeChecker,
|
639 |
|
|
};
|
640 |
|
|
|
641 |
|
|
/**
|
642 |
|
|
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
643 |
|
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
644 |
|
|
*/
|
645 |
|
|
/*eslint-disable no-self-compare*/
|
646 |
|
|
function is(x, y) {
|
647 |
|
|
// SameValue algorithm
|
648 |
|
|
if (x === y) {
|
649 |
|
|
// Steps 1-5, 7-10
|
650 |
|
|
// Steps 6.b-6.e: +0 != -0
|
651 |
|
|
return x !== 0 || 1 / x === 1 / y;
|
652 |
|
|
} else {
|
653 |
|
|
// Step 6.a: NaN == NaN
|
654 |
|
|
return x !== x && y !== y;
|
655 |
|
|
}
|
656 |
|
|
}
|
657 |
|
|
/*eslint-enable no-self-compare*/
|
658 |
|
|
|
659 |
|
|
/**
|
660 |
|
|
* We use an Error-like object for backward compatibility as people may call
|
661 |
|
|
* PropTypes directly and inspect their output. However, we don't use real
|
662 |
|
|
* Errors anymore. We don't inspect their stack anyway, and creating them
|
663 |
|
|
* is prohibitively expensive if they are created too often, such as what
|
664 |
|
|
* happens in oneOfType() for any type before the one that matched.
|
665 |
|
|
*/
|
666 |
|
|
function PropTypeError(message) {
|
667 |
|
|
this.message = message;
|
668 |
|
|
this.stack = '';
|
669 |
|
|
}
|
670 |
|
|
// Make `instanceof Error` still work for returned errors.
|
671 |
|
|
PropTypeError.prototype = Error.prototype;
|
672 |
|
|
|
673 |
|
|
function createChainableTypeChecker(validate) {
|
674 |
|
|
{
|
675 |
|
|
var manualPropTypeCallCache = {};
|
676 |
|
|
var manualPropTypeWarningCount = 0;
|
677 |
|
|
}
|
678 |
|
|
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
679 |
|
|
componentName = componentName || ANONYMOUS;
|
680 |
|
|
propFullName = propFullName || propName;
|
681 |
|
|
|
682 |
|
|
if (secret !== ReactPropTypesSecret_1) {
|
683 |
|
|
if (throwOnDirectAccess) {
|
684 |
|
|
// New behavior only for users of `prop-types` package
|
685 |
|
|
var err = new Error(
|
686 |
|
|
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
687 |
|
|
'Use `PropTypes.checkPropTypes()` to call them. ' +
|
688 |
|
|
'Read more at http://fb.me/use-check-prop-types'
|
689 |
|
|
);
|
690 |
|
|
err.name = 'Invariant Violation';
|
691 |
|
|
throw err;
|
692 |
|
|
} else if ( typeof console !== 'undefined') {
|
693 |
|
|
// Old behavior for people using React.PropTypes
|
694 |
|
|
var cacheKey = componentName + ':' + propName;
|
695 |
|
|
if (
|
696 |
|
|
!manualPropTypeCallCache[cacheKey] &&
|
697 |
|
|
// Avoid spamming the console because they are often not actionable except for lib authors
|
698 |
|
|
manualPropTypeWarningCount < 3
|
699 |
|
|
) {
|
700 |
|
|
printWarning$1(
|
701 |
|
|
'You are manually calling a React.PropTypes validation ' +
|
702 |
|
|
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
703 |
|
|
'and will throw in the standalone `prop-types` package. ' +
|
704 |
|
|
'You may be seeing this warning due to a third-party PropTypes ' +
|
705 |
|
|
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
706 |
|
|
);
|
707 |
|
|
manualPropTypeCallCache[cacheKey] = true;
|
708 |
|
|
manualPropTypeWarningCount++;
|
709 |
|
|
}
|
710 |
|
|
}
|
711 |
|
|
}
|
712 |
|
|
if (props[propName] == null) {
|
713 |
|
|
if (isRequired) {
|
714 |
|
|
if (props[propName] === null) {
|
715 |
|
|
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
716 |
|
|
}
|
717 |
|
|
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
718 |
|
|
}
|
719 |
|
|
return null;
|
720 |
|
|
} else {
|
721 |
|
|
return validate(props, propName, componentName, location, propFullName);
|
722 |
|
|
}
|
723 |
|
|
}
|
724 |
|
|
|
725 |
|
|
var chainedCheckType = checkType.bind(null, false);
|
726 |
|
|
chainedCheckType.isRequired = checkType.bind(null, true);
|
727 |
|
|
|
728 |
|
|
return chainedCheckType;
|
729 |
|
|
}
|
730 |
|
|
|
731 |
|
|
function createPrimitiveTypeChecker(expectedType) {
|
732 |
|
|
function validate(props, propName, componentName, location, propFullName, secret) {
|
733 |
|
|
var propValue = props[propName];
|
734 |
|
|
var propType = getPropType(propValue);
|
735 |
|
|
if (propType !== expectedType) {
|
736 |
|
|
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
737 |
|
|
// check, but we can offer a more precise error message here rather than
|
738 |
|
|
// 'of type `object`'.
|
739 |
|
|
var preciseType = getPreciseType(propValue);
|
740 |
|
|
|
741 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
742 |
|
|
}
|
743 |
|
|
return null;
|
744 |
|
|
}
|
745 |
|
|
return createChainableTypeChecker(validate);
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
function createAnyTypeChecker() {
|
749 |
|
|
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
750 |
|
|
}
|
751 |
|
|
|
752 |
|
|
function createArrayOfTypeChecker(typeChecker) {
|
753 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
754 |
|
|
if (typeof typeChecker !== 'function') {
|
755 |
|
|
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
756 |
|
|
}
|
757 |
|
|
var propValue = props[propName];
|
758 |
|
|
if (!Array.isArray(propValue)) {
|
759 |
|
|
var propType = getPropType(propValue);
|
760 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
761 |
|
|
}
|
762 |
|
|
for (var i = 0; i < propValue.length; i++) {
|
763 |
|
|
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
|
764 |
|
|
if (error instanceof Error) {
|
765 |
|
|
return error;
|
766 |
|
|
}
|
767 |
|
|
}
|
768 |
|
|
return null;
|
769 |
|
|
}
|
770 |
|
|
return createChainableTypeChecker(validate);
|
771 |
|
|
}
|
772 |
|
|
|
773 |
|
|
function createElementTypeChecker() {
|
774 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
775 |
|
|
var propValue = props[propName];
|
776 |
|
|
if (!isValidElement(propValue)) {
|
777 |
|
|
var propType = getPropType(propValue);
|
778 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
779 |
|
|
}
|
780 |
|
|
return null;
|
781 |
|
|
}
|
782 |
|
|
return createChainableTypeChecker(validate);
|
783 |
|
|
}
|
784 |
|
|
|
785 |
|
|
function createElementTypeTypeChecker() {
|
786 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
787 |
|
|
var propValue = props[propName];
|
788 |
|
|
if (!reactIs.isValidElementType(propValue)) {
|
789 |
|
|
var propType = getPropType(propValue);
|
790 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
791 |
|
|
}
|
792 |
|
|
return null;
|
793 |
|
|
}
|
794 |
|
|
return createChainableTypeChecker(validate);
|
795 |
|
|
}
|
796 |
|
|
|
797 |
|
|
function createInstanceTypeChecker(expectedClass) {
|
798 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
799 |
|
|
if (!(props[propName] instanceof expectedClass)) {
|
800 |
|
|
var expectedClassName = expectedClass.name || ANONYMOUS;
|
801 |
|
|
var actualClassName = getClassName(props[propName]);
|
802 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
803 |
|
|
}
|
804 |
|
|
return null;
|
805 |
|
|
}
|
806 |
|
|
return createChainableTypeChecker(validate);
|
807 |
|
|
}
|
808 |
|
|
|
809 |
|
|
function createEnumTypeChecker(expectedValues) {
|
810 |
|
|
if (!Array.isArray(expectedValues)) {
|
811 |
|
|
{
|
812 |
|
|
if (arguments.length > 1) {
|
813 |
|
|
printWarning$1(
|
814 |
|
|
'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
|
815 |
|
|
'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
|
816 |
|
|
);
|
817 |
|
|
} else {
|
818 |
|
|
printWarning$1('Invalid argument supplied to oneOf, expected an array.');
|
819 |
|
|
}
|
820 |
|
|
}
|
821 |
|
|
return emptyFunctionThatReturnsNull;
|
822 |
|
|
}
|
823 |
|
|
|
824 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
825 |
|
|
var propValue = props[propName];
|
826 |
|
|
for (var i = 0; i < expectedValues.length; i++) {
|
827 |
|
|
if (is(propValue, expectedValues[i])) {
|
828 |
|
|
return null;
|
829 |
|
|
}
|
830 |
|
|
}
|
831 |
|
|
|
832 |
|
|
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
|
833 |
|
|
var type = getPreciseType(value);
|
834 |
|
|
if (type === 'symbol') {
|
835 |
|
|
return String(value);
|
836 |
|
|
}
|
837 |
|
|
return value;
|
838 |
|
|
});
|
839 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
840 |
|
|
}
|
841 |
|
|
return createChainableTypeChecker(validate);
|
842 |
|
|
}
|
843 |
|
|
|
844 |
|
|
function createObjectOfTypeChecker(typeChecker) {
|
845 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
846 |
|
|
if (typeof typeChecker !== 'function') {
|
847 |
|
|
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
848 |
|
|
}
|
849 |
|
|
var propValue = props[propName];
|
850 |
|
|
var propType = getPropType(propValue);
|
851 |
|
|
if (propType !== 'object') {
|
852 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
853 |
|
|
}
|
854 |
|
|
for (var key in propValue) {
|
855 |
|
|
if (has$1(propValue, key)) {
|
856 |
|
|
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
857 |
|
|
if (error instanceof Error) {
|
858 |
|
|
return error;
|
859 |
|
|
}
|
860 |
|
|
}
|
861 |
|
|
}
|
862 |
|
|
return null;
|
863 |
|
|
}
|
864 |
|
|
return createChainableTypeChecker(validate);
|
865 |
|
|
}
|
866 |
|
|
|
867 |
|
|
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
868 |
|
|
if (!Array.isArray(arrayOfTypeCheckers)) {
|
869 |
|
|
printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') ;
|
870 |
|
|
return emptyFunctionThatReturnsNull;
|
871 |
|
|
}
|
872 |
|
|
|
873 |
|
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
874 |
|
|
var checker = arrayOfTypeCheckers[i];
|
875 |
|
|
if (typeof checker !== 'function') {
|
876 |
|
|
printWarning$1(
|
877 |
|
|
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
878 |
|
|
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
|
879 |
|
|
);
|
880 |
|
|
return emptyFunctionThatReturnsNull;
|
881 |
|
|
}
|
882 |
|
|
}
|
883 |
|
|
|
884 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
885 |
|
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
886 |
|
|
var checker = arrayOfTypeCheckers[i];
|
887 |
|
|
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
|
888 |
|
|
return null;
|
889 |
|
|
}
|
890 |
|
|
}
|
891 |
|
|
|
892 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
893 |
|
|
}
|
894 |
|
|
return createChainableTypeChecker(validate);
|
895 |
|
|
}
|
896 |
|
|
|
897 |
|
|
function createNodeChecker() {
|
898 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
899 |
|
|
if (!isNode(props[propName])) {
|
900 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
901 |
|
|
}
|
902 |
|
|
return null;
|
903 |
|
|
}
|
904 |
|
|
return createChainableTypeChecker(validate);
|
905 |
|
|
}
|
906 |
|
|
|
907 |
|
|
function createShapeTypeChecker(shapeTypes) {
|
908 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
909 |
|
|
var propValue = props[propName];
|
910 |
|
|
var propType = getPropType(propValue);
|
911 |
|
|
if (propType !== 'object') {
|
912 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
913 |
|
|
}
|
914 |
|
|
for (var key in shapeTypes) {
|
915 |
|
|
var checker = shapeTypes[key];
|
916 |
|
|
if (!checker) {
|
917 |
|
|
continue;
|
918 |
|
|
}
|
919 |
|
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
920 |
|
|
if (error) {
|
921 |
|
|
return error;
|
922 |
|
|
}
|
923 |
|
|
}
|
924 |
|
|
return null;
|
925 |
|
|
}
|
926 |
|
|
return createChainableTypeChecker(validate);
|
927 |
|
|
}
|
928 |
|
|
|
929 |
|
|
function createStrictShapeTypeChecker(shapeTypes) {
|
930 |
|
|
function validate(props, propName, componentName, location, propFullName) {
|
931 |
|
|
var propValue = props[propName];
|
932 |
|
|
var propType = getPropType(propValue);
|
933 |
|
|
if (propType !== 'object') {
|
934 |
|
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
935 |
|
|
}
|
936 |
|
|
// We need to check all keys in case some are required but missing from
|
937 |
|
|
// props.
|
938 |
|
|
var allKeys = objectAssign({}, props[propName], shapeTypes);
|
939 |
|
|
for (var key in allKeys) {
|
940 |
|
|
var checker = shapeTypes[key];
|
941 |
|
|
if (!checker) {
|
942 |
|
|
return new PropTypeError(
|
943 |
|
|
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
944 |
|
|
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
945 |
|
|
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
946 |
|
|
);
|
947 |
|
|
}
|
948 |
|
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
949 |
|
|
if (error) {
|
950 |
|
|
return error;
|
951 |
|
|
}
|
952 |
|
|
}
|
953 |
|
|
return null;
|
954 |
|
|
}
|
955 |
|
|
|
956 |
|
|
return createChainableTypeChecker(validate);
|
957 |
|
|
}
|
958 |
|
|
|
959 |
|
|
function isNode(propValue) {
|
960 |
|
|
switch (typeof propValue) {
|
961 |
|
|
case 'number':
|
962 |
|
|
case 'string':
|
963 |
|
|
case 'undefined':
|
964 |
|
|
return true;
|
965 |
|
|
case 'boolean':
|
966 |
|
|
return !propValue;
|
967 |
|
|
case 'object':
|
968 |
|
|
if (Array.isArray(propValue)) {
|
969 |
|
|
return propValue.every(isNode);
|
970 |
|
|
}
|
971 |
|
|
if (propValue === null || isValidElement(propValue)) {
|
972 |
|
|
return true;
|
973 |
|
|
}
|
974 |
|
|
|
975 |
|
|
var iteratorFn = getIteratorFn(propValue);
|
976 |
|
|
if (iteratorFn) {
|
977 |
|
|
var iterator = iteratorFn.call(propValue);
|
978 |
|
|
var step;
|
979 |
|
|
if (iteratorFn !== propValue.entries) {
|
980 |
|
|
while (!(step = iterator.next()).done) {
|
981 |
|
|
if (!isNode(step.value)) {
|
982 |
|
|
return false;
|
983 |
|
|
}
|
984 |
|
|
}
|
985 |
|
|
} else {
|
986 |
|
|
// Iterator will provide entry [k,v] tuples rather than values.
|
987 |
|
|
while (!(step = iterator.next()).done) {
|
988 |
|
|
var entry = step.value;
|
989 |
|
|
if (entry) {
|
990 |
|
|
if (!isNode(entry[1])) {
|
991 |
|
|
return false;
|
992 |
|
|
}
|
993 |
|
|
}
|
994 |
|
|
}
|
995 |
|
|
}
|
996 |
|
|
} else {
|
997 |
|
|
return false;
|
998 |
|
|
}
|
999 |
|
|
|
1000 |
|
|
return true;
|
1001 |
|
|
default:
|
1002 |
|
|
return false;
|
1003 |
|
|
}
|
1004 |
|
|
}
|
1005 |
|
|
|
1006 |
|
|
function isSymbol(propType, propValue) {
|
1007 |
|
|
// Native Symbol.
|
1008 |
|
|
if (propType === 'symbol') {
|
1009 |
|
|
return true;
|
1010 |
|
|
}
|
1011 |
|
|
|
1012 |
|
|
// falsy value can't be a Symbol
|
1013 |
|
|
if (!propValue) {
|
1014 |
|
|
return false;
|
1015 |
|
|
}
|
1016 |
|
|
|
1017 |
|
|
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
1018 |
|
|
if (propValue['@@toStringTag'] === 'Symbol') {
|
1019 |
|
|
return true;
|
1020 |
|
|
}
|
1021 |
|
|
|
1022 |
|
|
// Fallback for non-spec compliant Symbols which are polyfilled.
|
1023 |
|
|
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
1024 |
|
|
return true;
|
1025 |
|
|
}
|
1026 |
|
|
|
1027 |
|
|
return false;
|
1028 |
|
|
}
|
1029 |
|
|
|
1030 |
|
|
// Equivalent of `typeof` but with special handling for array and regexp.
|
1031 |
|
|
function getPropType(propValue) {
|
1032 |
|
|
var propType = typeof propValue;
|
1033 |
|
|
if (Array.isArray(propValue)) {
|
1034 |
|
|
return 'array';
|
1035 |
|
|
}
|
1036 |
|
|
if (propValue instanceof RegExp) {
|
1037 |
|
|
// Old webkits (at least until Android 4.0) return 'function' rather than
|
1038 |
|
|
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
1039 |
|
|
// passes PropTypes.object.
|
1040 |
|
|
return 'object';
|
1041 |
|
|
}
|
1042 |
|
|
if (isSymbol(propType, propValue)) {
|
1043 |
|
|
return 'symbol';
|
1044 |
|
|
}
|
1045 |
|
|
return propType;
|
1046 |
|
|
}
|
1047 |
|
|
|
1048 |
|
|
// This handles more types than `getPropType`. Only used for error messages.
|
1049 |
|
|
// See `createPrimitiveTypeChecker`.
|
1050 |
|
|
function getPreciseType(propValue) {
|
1051 |
|
|
if (typeof propValue === 'undefined' || propValue === null) {
|
1052 |
|
|
return '' + propValue;
|
1053 |
|
|
}
|
1054 |
|
|
var propType = getPropType(propValue);
|
1055 |
|
|
if (propType === 'object') {
|
1056 |
|
|
if (propValue instanceof Date) {
|
1057 |
|
|
return 'date';
|
1058 |
|
|
} else if (propValue instanceof RegExp) {
|
1059 |
|
|
return 'regexp';
|
1060 |
|
|
}
|
1061 |
|
|
}
|
1062 |
|
|
return propType;
|
1063 |
|
|
}
|
1064 |
|
|
|
1065 |
|
|
// Returns a string that is postfixed to a warning about an invalid type.
|
1066 |
|
|
// For example, "undefined" or "of type array"
|
1067 |
|
|
function getPostfixForTypeWarning(value) {
|
1068 |
|
|
var type = getPreciseType(value);
|
1069 |
|
|
switch (type) {
|
1070 |
|
|
case 'array':
|
1071 |
|
|
case 'object':
|
1072 |
|
|
return 'an ' + type;
|
1073 |
|
|
case 'boolean':
|
1074 |
|
|
case 'date':
|
1075 |
|
|
case 'regexp':
|
1076 |
|
|
return 'a ' + type;
|
1077 |
|
|
default:
|
1078 |
|
|
return type;
|
1079 |
|
|
}
|
1080 |
|
|
}
|
1081 |
|
|
|
1082 |
|
|
// Returns class name of the object, if any.
|
1083 |
|
|
function getClassName(propValue) {
|
1084 |
|
|
if (!propValue.constructor || !propValue.constructor.name) {
|
1085 |
|
|
return ANONYMOUS;
|
1086 |
|
|
}
|
1087 |
|
|
return propValue.constructor.name;
|
1088 |
|
|
}
|
1089 |
|
|
|
1090 |
|
|
ReactPropTypes.checkPropTypes = checkPropTypes_1;
|
1091 |
|
|
ReactPropTypes.resetWarningCache = checkPropTypes_1.resetWarningCache;
|
1092 |
|
|
ReactPropTypes.PropTypes = ReactPropTypes;
|
1093 |
|
|
|
1094 |
|
|
return ReactPropTypes;
|
1095 |
|
|
};
|
1096 |
|
|
|
1097 |
|
|
var propTypes = createCommonjsModule(function (module) {
|
1098 |
|
|
/**
|
1099 |
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
1100 |
|
|
*
|
1101 |
|
|
* This source code is licensed under the MIT license found in the
|
1102 |
|
|
* LICENSE file in the root directory of this source tree.
|
1103 |
|
|
*/
|
1104 |
|
|
|
1105 |
|
|
{
|
1106 |
|
|
var ReactIs = reactIs;
|
1107 |
|
|
|
1108 |
|
|
// By explicitly using `prop-types` you are opting into new development behavior.
|
1109 |
|
|
// http://fb.me/prop-types-in-prod
|
1110 |
|
|
var throwOnDirectAccess = true;
|
1111 |
|
|
module.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess);
|
1112 |
|
|
}
|
1113 |
|
|
});
|
1114 |
|
|
|
1115 |
|
|
function _extends() {
|
1116 |
|
|
_extends = Object.assign || function (target) {
|
1117 |
|
|
for (var i = 1; i < arguments.length; i++) {
|
1118 |
|
|
var source = arguments[i];
|
1119 |
|
|
|
1120 |
|
|
for (var key in source) {
|
1121 |
|
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1122 |
|
|
target[key] = source[key];
|
1123 |
|
|
}
|
1124 |
|
|
}
|
1125 |
|
|
}
|
1126 |
|
|
|
1127 |
|
|
return target;
|
1128 |
|
|
};
|
1129 |
|
|
|
1130 |
|
|
return _extends.apply(this, arguments);
|
1131 |
|
|
}
|
1132 |
|
|
|
1133 |
|
|
function isAbsolute(pathname) {
|
1134 |
|
|
return pathname.charAt(0) === '/';
|
1135 |
|
|
}
|
1136 |
|
|
|
1137 |
|
|
// About 1.5x faster than the two-arg version of Array#splice()
|
1138 |
|
|
function spliceOne(list, index) {
|
1139 |
|
|
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
|
1140 |
|
|
list[i] = list[k];
|
1141 |
|
|
}
|
1142 |
|
|
|
1143 |
|
|
list.pop();
|
1144 |
|
|
}
|
1145 |
|
|
|
1146 |
|
|
// This implementation is based heavily on node's url.parse
|
1147 |
|
|
function resolvePathname(to) {
|
1148 |
|
|
var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
1149 |
|
|
|
1150 |
|
|
var toParts = to && to.split('/') || [];
|
1151 |
|
|
var fromParts = from && from.split('/') || [];
|
1152 |
|
|
|
1153 |
|
|
var isToAbs = to && isAbsolute(to);
|
1154 |
|
|
var isFromAbs = from && isAbsolute(from);
|
1155 |
|
|
var mustEndAbs = isToAbs || isFromAbs;
|
1156 |
|
|
|
1157 |
|
|
if (to && isAbsolute(to)) {
|
1158 |
|
|
// to is absolute
|
1159 |
|
|
fromParts = toParts;
|
1160 |
|
|
} else if (toParts.length) {
|
1161 |
|
|
// to is relative, drop the filename
|
1162 |
|
|
fromParts.pop();
|
1163 |
|
|
fromParts = fromParts.concat(toParts);
|
1164 |
|
|
}
|
1165 |
|
|
|
1166 |
|
|
if (!fromParts.length) return '/';
|
1167 |
|
|
|
1168 |
|
|
var hasTrailingSlash = void 0;
|
1169 |
|
|
if (fromParts.length) {
|
1170 |
|
|
var last = fromParts[fromParts.length - 1];
|
1171 |
|
|
hasTrailingSlash = last === '.' || last === '..' || last === '';
|
1172 |
|
|
} else {
|
1173 |
|
|
hasTrailingSlash = false;
|
1174 |
|
|
}
|
1175 |
|
|
|
1176 |
|
|
var up = 0;
|
1177 |
|
|
for (var i = fromParts.length; i >= 0; i--) {
|
1178 |
|
|
var part = fromParts[i];
|
1179 |
|
|
|
1180 |
|
|
if (part === '.') {
|
1181 |
|
|
spliceOne(fromParts, i);
|
1182 |
|
|
} else if (part === '..') {
|
1183 |
|
|
spliceOne(fromParts, i);
|
1184 |
|
|
up++;
|
1185 |
|
|
} else if (up) {
|
1186 |
|
|
spliceOne(fromParts, i);
|
1187 |
|
|
up--;
|
1188 |
|
|
}
|
1189 |
|
|
}
|
1190 |
|
|
|
1191 |
|
|
if (!mustEndAbs) for (; up--; up) {
|
1192 |
|
|
fromParts.unshift('..');
|
1193 |
|
|
}if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift('');
|
1194 |
|
|
|
1195 |
|
|
var result = fromParts.join('/');
|
1196 |
|
|
|
1197 |
|
|
if (hasTrailingSlash && result.substr(-1) !== '/') result += '/';
|
1198 |
|
|
|
1199 |
|
|
return result;
|
1200 |
|
|
}
|
1201 |
|
|
|
1202 |
|
|
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; };
|
1203 |
|
|
|
1204 |
|
|
function valueEqual(a, b) {
|
1205 |
|
|
if (a === b) return true;
|
1206 |
|
|
|
1207 |
|
|
if (a == null || b == null) return false;
|
1208 |
|
|
|
1209 |
|
|
if (Array.isArray(a)) {
|
1210 |
|
|
return Array.isArray(b) && a.length === b.length && a.every(function (item, index) {
|
1211 |
|
|
return valueEqual(item, b[index]);
|
1212 |
|
|
});
|
1213 |
|
|
}
|
1214 |
|
|
|
1215 |
|
|
var aType = typeof a === 'undefined' ? 'undefined' : _typeof(a);
|
1216 |
|
|
var bType = typeof b === 'undefined' ? 'undefined' : _typeof(b);
|
1217 |
|
|
|
1218 |
|
|
if (aType !== bType) return false;
|
1219 |
|
|
|
1220 |
|
|
if (aType === 'object') {
|
1221 |
|
|
var aValue = a.valueOf();
|
1222 |
|
|
var bValue = b.valueOf();
|
1223 |
|
|
|
1224 |
|
|
if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue);
|
1225 |
|
|
|
1226 |
|
|
var aKeys = Object.keys(a);
|
1227 |
|
|
var bKeys = Object.keys(b);
|
1228 |
|
|
|
1229 |
|
|
if (aKeys.length !== bKeys.length) return false;
|
1230 |
|
|
|
1231 |
|
|
return aKeys.every(function (key) {
|
1232 |
|
|
return valueEqual(a[key], b[key]);
|
1233 |
|
|
});
|
1234 |
|
|
}
|
1235 |
|
|
|
1236 |
|
|
return false;
|
1237 |
|
|
}
|
1238 |
|
|
|
1239 |
|
|
function warning(condition, message) {
|
1240 |
|
|
{
|
1241 |
|
|
if (condition) {
|
1242 |
|
|
return;
|
1243 |
|
|
}
|
1244 |
|
|
|
1245 |
|
|
var text = "Warning: " + message;
|
1246 |
|
|
|
1247 |
|
|
if (typeof console !== 'undefined') {
|
1248 |
|
|
console.warn(text);
|
1249 |
|
|
}
|
1250 |
|
|
|
1251 |
|
|
try {
|
1252 |
|
|
throw Error(text);
|
1253 |
|
|
} catch (x) {}
|
1254 |
|
|
}
|
1255 |
|
|
}
|
1256 |
|
|
|
1257 |
|
|
var prefix = 'Invariant failed';
|
1258 |
|
|
function invariant(condition, message) {
|
1259 |
|
|
if (condition) {
|
1260 |
|
|
return;
|
1261 |
|
|
}
|
1262 |
|
|
|
1263 |
|
|
{
|
1264 |
|
|
throw new Error(prefix + ": " + (message || ''));
|
1265 |
|
|
}
|
1266 |
|
|
}
|
1267 |
|
|
|
1268 |
|
|
function addLeadingSlash(path) {
|
1269 |
|
|
return path.charAt(0) === '/' ? path : '/' + path;
|
1270 |
|
|
}
|
1271 |
|
|
function stripLeadingSlash(path) {
|
1272 |
|
|
return path.charAt(0) === '/' ? path.substr(1) : path;
|
1273 |
|
|
}
|
1274 |
|
|
function hasBasename(path, prefix) {
|
1275 |
|
|
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
|
1276 |
|
|
}
|
1277 |
|
|
function stripBasename(path, prefix) {
|
1278 |
|
|
return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
|
1279 |
|
|
}
|
1280 |
|
|
function stripTrailingSlash(path) {
|
1281 |
|
|
return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path;
|
1282 |
|
|
}
|
1283 |
|
|
function parsePath(path) {
|
1284 |
|
|
var pathname = path || '/';
|
1285 |
|
|
var search = '';
|
1286 |
|
|
var hash = '';
|
1287 |
|
|
var hashIndex = pathname.indexOf('#');
|
1288 |
|
|
|
1289 |
|
|
if (hashIndex !== -1) {
|
1290 |
|
|
hash = pathname.substr(hashIndex);
|
1291 |
|
|
pathname = pathname.substr(0, hashIndex);
|
1292 |
|
|
}
|
1293 |
|
|
|
1294 |
|
|
var searchIndex = pathname.indexOf('?');
|
1295 |
|
|
|
1296 |
|
|
if (searchIndex !== -1) {
|
1297 |
|
|
search = pathname.substr(searchIndex);
|
1298 |
|
|
pathname = pathname.substr(0, searchIndex);
|
1299 |
|
|
}
|
1300 |
|
|
|
1301 |
|
|
return {
|
1302 |
|
|
pathname: pathname,
|
1303 |
|
|
search: search === '?' ? '' : search,
|
1304 |
|
|
hash: hash === '#' ? '' : hash
|
1305 |
|
|
};
|
1306 |
|
|
}
|
1307 |
|
|
function createPath(location) {
|
1308 |
|
|
var pathname = location.pathname,
|
1309 |
|
|
search = location.search,
|
1310 |
|
|
hash = location.hash;
|
1311 |
|
|
var path = pathname || '/';
|
1312 |
|
|
if (search && search !== '?') path += search.charAt(0) === '?' ? search : "?" + search;
|
1313 |
|
|
if (hash && hash !== '#') path += hash.charAt(0) === '#' ? hash : "#" + hash;
|
1314 |
|
|
return path;
|
1315 |
|
|
}
|
1316 |
|
|
|
1317 |
|
|
function createLocation(path, state, key, currentLocation) {
|
1318 |
|
|
var location;
|
1319 |
|
|
|
1320 |
|
|
if (typeof path === 'string') {
|
1321 |
|
|
// Two-arg form: push(path, state)
|
1322 |
|
|
location = parsePath(path);
|
1323 |
|
|
location.state = state;
|
1324 |
|
|
} else {
|
1325 |
|
|
// One-arg form: push(location)
|
1326 |
|
|
location = _extends({}, path);
|
1327 |
|
|
if (location.pathname === undefined) location.pathname = '';
|
1328 |
|
|
|
1329 |
|
|
if (location.search) {
|
1330 |
|
|
if (location.search.charAt(0) !== '?') location.search = '?' + location.search;
|
1331 |
|
|
} else {
|
1332 |
|
|
location.search = '';
|
1333 |
|
|
}
|
1334 |
|
|
|
1335 |
|
|
if (location.hash) {
|
1336 |
|
|
if (location.hash.charAt(0) !== '#') location.hash = '#' + location.hash;
|
1337 |
|
|
} else {
|
1338 |
|
|
location.hash = '';
|
1339 |
|
|
}
|
1340 |
|
|
|
1341 |
|
|
if (state !== undefined && location.state === undefined) location.state = state;
|
1342 |
|
|
}
|
1343 |
|
|
|
1344 |
|
|
try {
|
1345 |
|
|
location.pathname = decodeURI(location.pathname);
|
1346 |
|
|
} catch (e) {
|
1347 |
|
|
if (e instanceof URIError) {
|
1348 |
|
|
throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.');
|
1349 |
|
|
} else {
|
1350 |
|
|
throw e;
|
1351 |
|
|
}
|
1352 |
|
|
}
|
1353 |
|
|
|
1354 |
|
|
if (key) location.key = key;
|
1355 |
|
|
|
1356 |
|
|
if (currentLocation) {
|
1357 |
|
|
// Resolve incomplete/relative pathname relative to current location.
|
1358 |
|
|
if (!location.pathname) {
|
1359 |
|
|
location.pathname = currentLocation.pathname;
|
1360 |
|
|
} else if (location.pathname.charAt(0) !== '/') {
|
1361 |
|
|
location.pathname = resolvePathname(location.pathname, currentLocation.pathname);
|
1362 |
|
|
}
|
1363 |
|
|
} else {
|
1364 |
|
|
// When there is no prior location and pathname is empty, set it to /
|
1365 |
|
|
if (!location.pathname) {
|
1366 |
|
|
location.pathname = '/';
|
1367 |
|
|
}
|
1368 |
|
|
}
|
1369 |
|
|
|
1370 |
|
|
return location;
|
1371 |
|
|
}
|
1372 |
|
|
function locationsAreEqual(a, b) {
|
1373 |
|
|
return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && valueEqual(a.state, b.state);
|
1374 |
|
|
}
|
1375 |
|
|
|
1376 |
|
|
function createTransitionManager() {
|
1377 |
|
|
var prompt = null;
|
1378 |
|
|
|
1379 |
|
|
function setPrompt(nextPrompt) {
|
1380 |
|
|
warning(prompt == null, 'A history supports only one prompt at a time') ;
|
1381 |
|
|
prompt = nextPrompt;
|
1382 |
|
|
return function () {
|
1383 |
|
|
if (prompt === nextPrompt) prompt = null;
|
1384 |
|
|
};
|
1385 |
|
|
}
|
1386 |
|
|
|
1387 |
|
|
function confirmTransitionTo(location, action, getUserConfirmation, callback) {
|
1388 |
|
|
// TODO: If another transition starts while we're still confirming
|
1389 |
|
|
// the previous one, we may end up in a weird state. Figure out the
|
1390 |
|
|
// best way to handle this.
|
1391 |
|
|
if (prompt != null) {
|
1392 |
|
|
var result = typeof prompt === 'function' ? prompt(location, action) : prompt;
|
1393 |
|
|
|
1394 |
|
|
if (typeof result === 'string') {
|
1395 |
|
|
if (typeof getUserConfirmation === 'function') {
|
1396 |
|
|
getUserConfirmation(result, callback);
|
1397 |
|
|
} else {
|
1398 |
|
|
warning(false, 'A history needs a getUserConfirmation function in order to use a prompt message') ;
|
1399 |
|
|
callback(true);
|
1400 |
|
|
}
|
1401 |
|
|
} else {
|
1402 |
|
|
// Return false from a transition hook to cancel the transition.
|
1403 |
|
|
callback(result !== false);
|
1404 |
|
|
}
|
1405 |
|
|
} else {
|
1406 |
|
|
callback(true);
|
1407 |
|
|
}
|
1408 |
|
|
}
|
1409 |
|
|
|
1410 |
|
|
var listeners = [];
|
1411 |
|
|
|
1412 |
|
|
function appendListener(fn) {
|
1413 |
|
|
var isActive = true;
|
1414 |
|
|
|
1415 |
|
|
function listener() {
|
1416 |
|
|
if (isActive) fn.apply(void 0, arguments);
|
1417 |
|
|
}
|
1418 |
|
|
|
1419 |
|
|
listeners.push(listener);
|
1420 |
|
|
return function () {
|
1421 |
|
|
isActive = false;
|
1422 |
|
|
listeners = listeners.filter(function (item) {
|
1423 |
|
|
return item !== listener;
|
1424 |
|
|
});
|
1425 |
|
|
};
|
1426 |
|
|
}
|
1427 |
|
|
|
1428 |
|
|
function notifyListeners() {
|
1429 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
1430 |
|
|
args[_key] = arguments[_key];
|
1431 |
|
|
}
|
1432 |
|
|
|
1433 |
|
|
listeners.forEach(function (listener) {
|
1434 |
|
|
return listener.apply(void 0, args);
|
1435 |
|
|
});
|
1436 |
|
|
}
|
1437 |
|
|
|
1438 |
|
|
return {
|
1439 |
|
|
setPrompt: setPrompt,
|
1440 |
|
|
confirmTransitionTo: confirmTransitionTo,
|
1441 |
|
|
appendListener: appendListener,
|
1442 |
|
|
notifyListeners: notifyListeners
|
1443 |
|
|
};
|
1444 |
|
|
}
|
1445 |
|
|
|
1446 |
|
|
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
1447 |
|
|
function getConfirmation(message, callback) {
|
1448 |
|
|
callback(window.confirm(message)); // eslint-disable-line no-alert
|
1449 |
|
|
}
|
1450 |
|
|
/**
|
1451 |
|
|
* Returns true if the HTML5 history API is supported. Taken from Modernizr.
|
1452 |
|
|
*
|
1453 |
|
|
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE
|
1454 |
|
|
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
|
1455 |
|
|
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586
|
1456 |
|
|
*/
|
1457 |
|
|
|
1458 |
|
|
function supportsHistory() {
|
1459 |
|
|
var ua = window.navigator.userAgent;
|
1460 |
|
|
if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) return false;
|
1461 |
|
|
return window.history && 'pushState' in window.history;
|
1462 |
|
|
}
|
1463 |
|
|
/**
|
1464 |
|
|
* Returns true if browser fires popstate on hash change.
|
1465 |
|
|
* IE10 and IE11 do not.
|
1466 |
|
|
*/
|
1467 |
|
|
|
1468 |
|
|
function supportsPopStateOnHashChange() {
|
1469 |
|
|
return window.navigator.userAgent.indexOf('Trident') === -1;
|
1470 |
|
|
}
|
1471 |
|
|
/**
|
1472 |
|
|
* Returns false if using go(n) with hash history causes a full page reload.
|
1473 |
|
|
*/
|
1474 |
|
|
|
1475 |
|
|
function supportsGoWithoutReloadUsingHash() {
|
1476 |
|
|
return window.navigator.userAgent.indexOf('Firefox') === -1;
|
1477 |
|
|
}
|
1478 |
|
|
/**
|
1479 |
|
|
* Returns true if a given popstate event is an extraneous WebKit event.
|
1480 |
|
|
* Accounts for the fact that Chrome on iOS fires real popstate events
|
1481 |
|
|
* containing undefined state when pressing the back button.
|
1482 |
|
|
*/
|
1483 |
|
|
|
1484 |
|
|
function isExtraneousPopstateEvent(event) {
|
1485 |
|
|
event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1;
|
1486 |
|
|
}
|
1487 |
|
|
|
1488 |
|
|
var PopStateEvent = 'popstate';
|
1489 |
|
|
var HashChangeEvent = 'hashchange';
|
1490 |
|
|
|
1491 |
|
|
function getHistoryState() {
|
1492 |
|
|
try {
|
1493 |
|
|
return window.history.state || {};
|
1494 |
|
|
} catch (e) {
|
1495 |
|
|
// IE 11 sometimes throws when accessing window.history.state
|
1496 |
|
|
// See https://github.com/ReactTraining/history/pull/289
|
1497 |
|
|
return {};
|
1498 |
|
|
}
|
1499 |
|
|
}
|
1500 |
|
|
/**
|
1501 |
|
|
* Creates a history object that uses the HTML5 history API including
|
1502 |
|
|
* pushState, replaceState, and the popstate event.
|
1503 |
|
|
*/
|
1504 |
|
|
|
1505 |
|
|
|
1506 |
|
|
function createBrowserHistory(props) {
|
1507 |
|
|
if (props === void 0) {
|
1508 |
|
|
props = {};
|
1509 |
|
|
}
|
1510 |
|
|
|
1511 |
|
|
!canUseDOM ? invariant(false, 'Browser history needs a DOM') : void 0;
|
1512 |
|
|
var globalHistory = window.history;
|
1513 |
|
|
var canUseHistory = supportsHistory();
|
1514 |
|
|
var needsHashChangeListener = !supportsPopStateOnHashChange();
|
1515 |
|
|
var _props = props,
|
1516 |
|
|
_props$forceRefresh = _props.forceRefresh,
|
1517 |
|
|
forceRefresh = _props$forceRefresh === void 0 ? false : _props$forceRefresh,
|
1518 |
|
|
_props$getUserConfirm = _props.getUserConfirmation,
|
1519 |
|
|
getUserConfirmation = _props$getUserConfirm === void 0 ? getConfirmation : _props$getUserConfirm,
|
1520 |
|
|
_props$keyLength = _props.keyLength,
|
1521 |
|
|
keyLength = _props$keyLength === void 0 ? 6 : _props$keyLength;
|
1522 |
|
|
var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '';
|
1523 |
|
|
|
1524 |
|
|
function getDOMLocation(historyState) {
|
1525 |
|
|
var _ref = historyState || {},
|
1526 |
|
|
key = _ref.key,
|
1527 |
|
|
state = _ref.state;
|
1528 |
|
|
|
1529 |
|
|
var _window$location = window.location,
|
1530 |
|
|
pathname = _window$location.pathname,
|
1531 |
|
|
search = _window$location.search,
|
1532 |
|
|
hash = _window$location.hash;
|
1533 |
|
|
var path = pathname + search + hash;
|
1534 |
|
|
warning(!basename || hasBasename(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".') ;
|
1535 |
|
|
if (basename) path = stripBasename(path, basename);
|
1536 |
|
|
return createLocation(path, state, key);
|
1537 |
|
|
}
|
1538 |
|
|
|
1539 |
|
|
function createKey() {
|
1540 |
|
|
return Math.random().toString(36).substr(2, keyLength);
|
1541 |
|
|
}
|
1542 |
|
|
|
1543 |
|
|
var transitionManager = createTransitionManager();
|
1544 |
|
|
|
1545 |
|
|
function setState(nextState) {
|
1546 |
|
|
_extends(history, nextState);
|
1547 |
|
|
|
1548 |
|
|
history.length = globalHistory.length;
|
1549 |
|
|
transitionManager.notifyListeners(history.location, history.action);
|
1550 |
|
|
}
|
1551 |
|
|
|
1552 |
|
|
function handlePopState(event) {
|
1553 |
|
|
// Ignore extraneous popstate events in WebKit.
|
1554 |
|
|
if (isExtraneousPopstateEvent(event)) return;
|
1555 |
|
|
handlePop(getDOMLocation(event.state));
|
1556 |
|
|
}
|
1557 |
|
|
|
1558 |
|
|
function handleHashChange() {
|
1559 |
|
|
handlePop(getDOMLocation(getHistoryState()));
|
1560 |
|
|
}
|
1561 |
|
|
|
1562 |
|
|
var forceNextPop = false;
|
1563 |
|
|
|
1564 |
|
|
function handlePop(location) {
|
1565 |
|
|
if (forceNextPop) {
|
1566 |
|
|
forceNextPop = false;
|
1567 |
|
|
setState();
|
1568 |
|
|
} else {
|
1569 |
|
|
var action = 'POP';
|
1570 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
1571 |
|
|
if (ok) {
|
1572 |
|
|
setState({
|
1573 |
|
|
action: action,
|
1574 |
|
|
location: location
|
1575 |
|
|
});
|
1576 |
|
|
} else {
|
1577 |
|
|
revertPop(location);
|
1578 |
|
|
}
|
1579 |
|
|
});
|
1580 |
|
|
}
|
1581 |
|
|
}
|
1582 |
|
|
|
1583 |
|
|
function revertPop(fromLocation) {
|
1584 |
|
|
var toLocation = history.location; // TODO: We could probably make this more reliable by
|
1585 |
|
|
// keeping a list of keys we've seen in sessionStorage.
|
1586 |
|
|
// Instead, we just default to 0 for keys we don't know.
|
1587 |
|
|
|
1588 |
|
|
var toIndex = allKeys.indexOf(toLocation.key);
|
1589 |
|
|
if (toIndex === -1) toIndex = 0;
|
1590 |
|
|
var fromIndex = allKeys.indexOf(fromLocation.key);
|
1591 |
|
|
if (fromIndex === -1) fromIndex = 0;
|
1592 |
|
|
var delta = toIndex - fromIndex;
|
1593 |
|
|
|
1594 |
|
|
if (delta) {
|
1595 |
|
|
forceNextPop = true;
|
1596 |
|
|
go(delta);
|
1597 |
|
|
}
|
1598 |
|
|
}
|
1599 |
|
|
|
1600 |
|
|
var initialLocation = getDOMLocation(getHistoryState());
|
1601 |
|
|
var allKeys = [initialLocation.key]; // Public interface
|
1602 |
|
|
|
1603 |
|
|
function createHref(location) {
|
1604 |
|
|
return basename + createPath(location);
|
1605 |
|
|
}
|
1606 |
|
|
|
1607 |
|
|
function push(path, state) {
|
1608 |
|
|
warning(!(typeof 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') ;
|
1609 |
|
|
var action = 'PUSH';
|
1610 |
|
|
var location = createLocation(path, state, createKey(), history.location);
|
1611 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
1612 |
|
|
if (!ok) return;
|
1613 |
|
|
var href = createHref(location);
|
1614 |
|
|
var key = location.key,
|
1615 |
|
|
state = location.state;
|
1616 |
|
|
|
1617 |
|
|
if (canUseHistory) {
|
1618 |
|
|
globalHistory.pushState({
|
1619 |
|
|
key: key,
|
1620 |
|
|
state: state
|
1621 |
|
|
}, null, href);
|
1622 |
|
|
|
1623 |
|
|
if (forceRefresh) {
|
1624 |
|
|
window.location.href = href;
|
1625 |
|
|
} else {
|
1626 |
|
|
var prevIndex = allKeys.indexOf(history.location.key);
|
1627 |
|
|
var nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1);
|
1628 |
|
|
nextKeys.push(location.key);
|
1629 |
|
|
allKeys = nextKeys;
|
1630 |
|
|
setState({
|
1631 |
|
|
action: action,
|
1632 |
|
|
location: location
|
1633 |
|
|
});
|
1634 |
|
|
}
|
1635 |
|
|
} else {
|
1636 |
|
|
warning(state === undefined, 'Browser history cannot push state in browsers that do not support HTML5 history') ;
|
1637 |
|
|
window.location.href = href;
|
1638 |
|
|
}
|
1639 |
|
|
});
|
1640 |
|
|
}
|
1641 |
|
|
|
1642 |
|
|
function replace(path, state) {
|
1643 |
|
|
warning(!(typeof 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') ;
|
1644 |
|
|
var action = 'REPLACE';
|
1645 |
|
|
var location = createLocation(path, state, createKey(), history.location);
|
1646 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
1647 |
|
|
if (!ok) return;
|
1648 |
|
|
var href = createHref(location);
|
1649 |
|
|
var key = location.key,
|
1650 |
|
|
state = location.state;
|
1651 |
|
|
|
1652 |
|
|
if (canUseHistory) {
|
1653 |
|
|
globalHistory.replaceState({
|
1654 |
|
|
key: key,
|
1655 |
|
|
state: state
|
1656 |
|
|
}, null, href);
|
1657 |
|
|
|
1658 |
|
|
if (forceRefresh) {
|
1659 |
|
|
window.location.replace(href);
|
1660 |
|
|
} else {
|
1661 |
|
|
var prevIndex = allKeys.indexOf(history.location.key);
|
1662 |
|
|
if (prevIndex !== -1) allKeys[prevIndex] = location.key;
|
1663 |
|
|
setState({
|
1664 |
|
|
action: action,
|
1665 |
|
|
location: location
|
1666 |
|
|
});
|
1667 |
|
|
}
|
1668 |
|
|
} else {
|
1669 |
|
|
warning(state === undefined, 'Browser history cannot replace state in browsers that do not support HTML5 history') ;
|
1670 |
|
|
window.location.replace(href);
|
1671 |
|
|
}
|
1672 |
|
|
});
|
1673 |
|
|
}
|
1674 |
|
|
|
1675 |
|
|
function go(n) {
|
1676 |
|
|
globalHistory.go(n);
|
1677 |
|
|
}
|
1678 |
|
|
|
1679 |
|
|
function goBack() {
|
1680 |
|
|
go(-1);
|
1681 |
|
|
}
|
1682 |
|
|
|
1683 |
|
|
function goForward() {
|
1684 |
|
|
go(1);
|
1685 |
|
|
}
|
1686 |
|
|
|
1687 |
|
|
var listenerCount = 0;
|
1688 |
|
|
|
1689 |
|
|
function checkDOMListeners(delta) {
|
1690 |
|
|
listenerCount += delta;
|
1691 |
|
|
|
1692 |
|
|
if (listenerCount === 1 && delta === 1) {
|
1693 |
|
|
window.addEventListener(PopStateEvent, handlePopState);
|
1694 |
|
|
if (needsHashChangeListener) window.addEventListener(HashChangeEvent, handleHashChange);
|
1695 |
|
|
} else if (listenerCount === 0) {
|
1696 |
|
|
window.removeEventListener(PopStateEvent, handlePopState);
|
1697 |
|
|
if (needsHashChangeListener) window.removeEventListener(HashChangeEvent, handleHashChange);
|
1698 |
|
|
}
|
1699 |
|
|
}
|
1700 |
|
|
|
1701 |
|
|
var isBlocked = false;
|
1702 |
|
|
|
1703 |
|
|
function block(prompt) {
|
1704 |
|
|
if (prompt === void 0) {
|
1705 |
|
|
prompt = false;
|
1706 |
|
|
}
|
1707 |
|
|
|
1708 |
|
|
var unblock = transitionManager.setPrompt(prompt);
|
1709 |
|
|
|
1710 |
|
|
if (!isBlocked) {
|
1711 |
|
|
checkDOMListeners(1);
|
1712 |
|
|
isBlocked = true;
|
1713 |
|
|
}
|
1714 |
|
|
|
1715 |
|
|
return function () {
|
1716 |
|
|
if (isBlocked) {
|
1717 |
|
|
isBlocked = false;
|
1718 |
|
|
checkDOMListeners(-1);
|
1719 |
|
|
}
|
1720 |
|
|
|
1721 |
|
|
return unblock();
|
1722 |
|
|
};
|
1723 |
|
|
}
|
1724 |
|
|
|
1725 |
|
|
function listen(listener) {
|
1726 |
|
|
var unlisten = transitionManager.appendListener(listener);
|
1727 |
|
|
checkDOMListeners(1);
|
1728 |
|
|
return function () {
|
1729 |
|
|
checkDOMListeners(-1);
|
1730 |
|
|
unlisten();
|
1731 |
|
|
};
|
1732 |
|
|
}
|
1733 |
|
|
|
1734 |
|
|
var history = {
|
1735 |
|
|
length: globalHistory.length,
|
1736 |
|
|
action: 'POP',
|
1737 |
|
|
location: initialLocation,
|
1738 |
|
|
createHref: createHref,
|
1739 |
|
|
push: push,
|
1740 |
|
|
replace: replace,
|
1741 |
|
|
go: go,
|
1742 |
|
|
goBack: goBack,
|
1743 |
|
|
goForward: goForward,
|
1744 |
|
|
block: block,
|
1745 |
|
|
listen: listen
|
1746 |
|
|
};
|
1747 |
|
|
return history;
|
1748 |
|
|
}
|
1749 |
|
|
|
1750 |
|
|
var HashChangeEvent$1 = 'hashchange';
|
1751 |
|
|
var HashPathCoders = {
|
1752 |
|
|
hashbang: {
|
1753 |
|
|
encodePath: function encodePath(path) {
|
1754 |
|
|
return path.charAt(0) === '!' ? path : '!/' + stripLeadingSlash(path);
|
1755 |
|
|
},
|
1756 |
|
|
decodePath: function decodePath(path) {
|
1757 |
|
|
return path.charAt(0) === '!' ? path.substr(1) : path;
|
1758 |
|
|
}
|
1759 |
|
|
},
|
1760 |
|
|
noslash: {
|
1761 |
|
|
encodePath: stripLeadingSlash,
|
1762 |
|
|
decodePath: addLeadingSlash
|
1763 |
|
|
},
|
1764 |
|
|
slash: {
|
1765 |
|
|
encodePath: addLeadingSlash,
|
1766 |
|
|
decodePath: addLeadingSlash
|
1767 |
|
|
}
|
1768 |
|
|
};
|
1769 |
|
|
|
1770 |
|
|
function getHashPath() {
|
1771 |
|
|
// We can't use window.location.hash here because it's not
|
1772 |
|
|
// consistent across browsers - Firefox will pre-decode it!
|
1773 |
|
|
var href = window.location.href;
|
1774 |
|
|
var hashIndex = href.indexOf('#');
|
1775 |
|
|
return hashIndex === -1 ? '' : href.substring(hashIndex + 1);
|
1776 |
|
|
}
|
1777 |
|
|
|
1778 |
|
|
function pushHashPath(path) {
|
1779 |
|
|
window.location.hash = path;
|
1780 |
|
|
}
|
1781 |
|
|
|
1782 |
|
|
function replaceHashPath(path) {
|
1783 |
|
|
var hashIndex = window.location.href.indexOf('#');
|
1784 |
|
|
window.location.replace(window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + '#' + path);
|
1785 |
|
|
}
|
1786 |
|
|
|
1787 |
|
|
function createHashHistory(props) {
|
1788 |
|
|
if (props === void 0) {
|
1789 |
|
|
props = {};
|
1790 |
|
|
}
|
1791 |
|
|
|
1792 |
|
|
!canUseDOM ? invariant(false, 'Hash history needs a DOM') : void 0;
|
1793 |
|
|
var globalHistory = window.history;
|
1794 |
|
|
var canGoWithoutReload = supportsGoWithoutReloadUsingHash();
|
1795 |
|
|
var _props = props,
|
1796 |
|
|
_props$getUserConfirm = _props.getUserConfirmation,
|
1797 |
|
|
getUserConfirmation = _props$getUserConfirm === void 0 ? getConfirmation : _props$getUserConfirm,
|
1798 |
|
|
_props$hashType = _props.hashType,
|
1799 |
|
|
hashType = _props$hashType === void 0 ? 'slash' : _props$hashType;
|
1800 |
|
|
var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '';
|
1801 |
|
|
var _HashPathCoders$hashT = HashPathCoders[hashType],
|
1802 |
|
|
encodePath = _HashPathCoders$hashT.encodePath,
|
1803 |
|
|
decodePath = _HashPathCoders$hashT.decodePath;
|
1804 |
|
|
|
1805 |
|
|
function getDOMLocation() {
|
1806 |
|
|
var path = decodePath(getHashPath());
|
1807 |
|
|
warning(!basename || hasBasename(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".') ;
|
1808 |
|
|
if (basename) path = stripBasename(path, basename);
|
1809 |
|
|
return createLocation(path);
|
1810 |
|
|
}
|
1811 |
|
|
|
1812 |
|
|
var transitionManager = createTransitionManager();
|
1813 |
|
|
|
1814 |
|
|
function setState(nextState) {
|
1815 |
|
|
_extends(history, nextState);
|
1816 |
|
|
|
1817 |
|
|
history.length = globalHistory.length;
|
1818 |
|
|
transitionManager.notifyListeners(history.location, history.action);
|
1819 |
|
|
}
|
1820 |
|
|
|
1821 |
|
|
var forceNextPop = false;
|
1822 |
|
|
var ignorePath = null;
|
1823 |
|
|
|
1824 |
|
|
function handleHashChange() {
|
1825 |
|
|
var path = getHashPath();
|
1826 |
|
|
var encodedPath = encodePath(path);
|
1827 |
|
|
|
1828 |
|
|
if (path !== encodedPath) {
|
1829 |
|
|
// Ensure we always have a properly-encoded hash.
|
1830 |
|
|
replaceHashPath(encodedPath);
|
1831 |
|
|
} else {
|
1832 |
|
|
var location = getDOMLocation();
|
1833 |
|
|
var prevLocation = history.location;
|
1834 |
|
|
if (!forceNextPop && locationsAreEqual(prevLocation, location)) return; // A hashchange doesn't always == location change.
|
1835 |
|
|
|
1836 |
|
|
if (ignorePath === createPath(location)) return; // Ignore this change; we already setState in push/replace.
|
1837 |
|
|
|
1838 |
|
|
ignorePath = null;
|
1839 |
|
|
handlePop(location);
|
1840 |
|
|
}
|
1841 |
|
|
}
|
1842 |
|
|
|
1843 |
|
|
function handlePop(location) {
|
1844 |
|
|
if (forceNextPop) {
|
1845 |
|
|
forceNextPop = false;
|
1846 |
|
|
setState();
|
1847 |
|
|
} else {
|
1848 |
|
|
var action = 'POP';
|
1849 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
1850 |
|
|
if (ok) {
|
1851 |
|
|
setState({
|
1852 |
|
|
action: action,
|
1853 |
|
|
location: location
|
1854 |
|
|
});
|
1855 |
|
|
} else {
|
1856 |
|
|
revertPop(location);
|
1857 |
|
|
}
|
1858 |
|
|
});
|
1859 |
|
|
}
|
1860 |
|
|
}
|
1861 |
|
|
|
1862 |
|
|
function revertPop(fromLocation) {
|
1863 |
|
|
var toLocation = history.location; // TODO: We could probably make this more reliable by
|
1864 |
|
|
// keeping a list of paths we've seen in sessionStorage.
|
1865 |
|
|
// Instead, we just default to 0 for paths we don't know.
|
1866 |
|
|
|
1867 |
|
|
var toIndex = allPaths.lastIndexOf(createPath(toLocation));
|
1868 |
|
|
if (toIndex === -1) toIndex = 0;
|
1869 |
|
|
var fromIndex = allPaths.lastIndexOf(createPath(fromLocation));
|
1870 |
|
|
if (fromIndex === -1) fromIndex = 0;
|
1871 |
|
|
var delta = toIndex - fromIndex;
|
1872 |
|
|
|
1873 |
|
|
if (delta) {
|
1874 |
|
|
forceNextPop = true;
|
1875 |
|
|
go(delta);
|
1876 |
|
|
}
|
1877 |
|
|
} // Ensure the hash is encoded properly before doing anything else.
|
1878 |
|
|
|
1879 |
|
|
|
1880 |
|
|
var path = getHashPath();
|
1881 |
|
|
var encodedPath = encodePath(path);
|
1882 |
|
|
if (path !== encodedPath) replaceHashPath(encodedPath);
|
1883 |
|
|
var initialLocation = getDOMLocation();
|
1884 |
|
|
var allPaths = [createPath(initialLocation)]; // Public interface
|
1885 |
|
|
|
1886 |
|
|
function createHref(location) {
|
1887 |
|
|
return '#' + encodePath(basename + createPath(location));
|
1888 |
|
|
}
|
1889 |
|
|
|
1890 |
|
|
function push(path, state) {
|
1891 |
|
|
warning(state === undefined, 'Hash history cannot push state; it is ignored') ;
|
1892 |
|
|
var action = 'PUSH';
|
1893 |
|
|
var location = createLocation(path, undefined, undefined, history.location);
|
1894 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
1895 |
|
|
if (!ok) return;
|
1896 |
|
|
var path = createPath(location);
|
1897 |
|
|
var encodedPath = encodePath(basename + path);
|
1898 |
|
|
var hashChanged = getHashPath() !== encodedPath;
|
1899 |
|
|
|
1900 |
|
|
if (hashChanged) {
|
1901 |
|
|
// We cannot tell if a hashchange was caused by a PUSH, so we'd
|
1902 |
|
|
// rather setState here and ignore the hashchange. The caveat here
|
1903 |
|
|
// is that other hash histories in the page will consider it a POP.
|
1904 |
|
|
ignorePath = path;
|
1905 |
|
|
pushHashPath(encodedPath);
|
1906 |
|
|
var prevIndex = allPaths.lastIndexOf(createPath(history.location));
|
1907 |
|
|
var nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1);
|
1908 |
|
|
nextPaths.push(path);
|
1909 |
|
|
allPaths = nextPaths;
|
1910 |
|
|
setState({
|
1911 |
|
|
action: action,
|
1912 |
|
|
location: location
|
1913 |
|
|
});
|
1914 |
|
|
} else {
|
1915 |
|
|
warning(false, 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack') ;
|
1916 |
|
|
setState();
|
1917 |
|
|
}
|
1918 |
|
|
});
|
1919 |
|
|
}
|
1920 |
|
|
|
1921 |
|
|
function replace(path, state) {
|
1922 |
|
|
warning(state === undefined, 'Hash history cannot replace state; it is ignored') ;
|
1923 |
|
|
var action = 'REPLACE';
|
1924 |
|
|
var location = createLocation(path, undefined, undefined, history.location);
|
1925 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
1926 |
|
|
if (!ok) return;
|
1927 |
|
|
var path = createPath(location);
|
1928 |
|
|
var encodedPath = encodePath(basename + path);
|
1929 |
|
|
var hashChanged = getHashPath() !== encodedPath;
|
1930 |
|
|
|
1931 |
|
|
if (hashChanged) {
|
1932 |
|
|
// We cannot tell if a hashchange was caused by a REPLACE, so we'd
|
1933 |
|
|
// rather setState here and ignore the hashchange. The caveat here
|
1934 |
|
|
// is that other hash histories in the page will consider it a POP.
|
1935 |
|
|
ignorePath = path;
|
1936 |
|
|
replaceHashPath(encodedPath);
|
1937 |
|
|
}
|
1938 |
|
|
|
1939 |
|
|
var prevIndex = allPaths.indexOf(createPath(history.location));
|
1940 |
|
|
if (prevIndex !== -1) allPaths[prevIndex] = path;
|
1941 |
|
|
setState({
|
1942 |
|
|
action: action,
|
1943 |
|
|
location: location
|
1944 |
|
|
});
|
1945 |
|
|
});
|
1946 |
|
|
}
|
1947 |
|
|
|
1948 |
|
|
function go(n) {
|
1949 |
|
|
warning(canGoWithoutReload, 'Hash history go(n) causes a full page reload in this browser') ;
|
1950 |
|
|
globalHistory.go(n);
|
1951 |
|
|
}
|
1952 |
|
|
|
1953 |
|
|
function goBack() {
|
1954 |
|
|
go(-1);
|
1955 |
|
|
}
|
1956 |
|
|
|
1957 |
|
|
function goForward() {
|
1958 |
|
|
go(1);
|
1959 |
|
|
}
|
1960 |
|
|
|
1961 |
|
|
var listenerCount = 0;
|
1962 |
|
|
|
1963 |
|
|
function checkDOMListeners(delta) {
|
1964 |
|
|
listenerCount += delta;
|
1965 |
|
|
|
1966 |
|
|
if (listenerCount === 1 && delta === 1) {
|
1967 |
|
|
window.addEventListener(HashChangeEvent$1, handleHashChange);
|
1968 |
|
|
} else if (listenerCount === 0) {
|
1969 |
|
|
window.removeEventListener(HashChangeEvent$1, handleHashChange);
|
1970 |
|
|
}
|
1971 |
|
|
}
|
1972 |
|
|
|
1973 |
|
|
var isBlocked = false;
|
1974 |
|
|
|
1975 |
|
|
function block(prompt) {
|
1976 |
|
|
if (prompt === void 0) {
|
1977 |
|
|
prompt = false;
|
1978 |
|
|
}
|
1979 |
|
|
|
1980 |
|
|
var unblock = transitionManager.setPrompt(prompt);
|
1981 |
|
|
|
1982 |
|
|
if (!isBlocked) {
|
1983 |
|
|
checkDOMListeners(1);
|
1984 |
|
|
isBlocked = true;
|
1985 |
|
|
}
|
1986 |
|
|
|
1987 |
|
|
return function () {
|
1988 |
|
|
if (isBlocked) {
|
1989 |
|
|
isBlocked = false;
|
1990 |
|
|
checkDOMListeners(-1);
|
1991 |
|
|
}
|
1992 |
|
|
|
1993 |
|
|
return unblock();
|
1994 |
|
|
};
|
1995 |
|
|
}
|
1996 |
|
|
|
1997 |
|
|
function listen(listener) {
|
1998 |
|
|
var unlisten = transitionManager.appendListener(listener);
|
1999 |
|
|
checkDOMListeners(1);
|
2000 |
|
|
return function () {
|
2001 |
|
|
checkDOMListeners(-1);
|
2002 |
|
|
unlisten();
|
2003 |
|
|
};
|
2004 |
|
|
}
|
2005 |
|
|
|
2006 |
|
|
var history = {
|
2007 |
|
|
length: globalHistory.length,
|
2008 |
|
|
action: 'POP',
|
2009 |
|
|
location: initialLocation,
|
2010 |
|
|
createHref: createHref,
|
2011 |
|
|
push: push,
|
2012 |
|
|
replace: replace,
|
2013 |
|
|
go: go,
|
2014 |
|
|
goBack: goBack,
|
2015 |
|
|
goForward: goForward,
|
2016 |
|
|
block: block,
|
2017 |
|
|
listen: listen
|
2018 |
|
|
};
|
2019 |
|
|
return history;
|
2020 |
|
|
}
|
2021 |
|
|
|
2022 |
|
|
function clamp(n, lowerBound, upperBound) {
|
2023 |
|
|
return Math.min(Math.max(n, lowerBound), upperBound);
|
2024 |
|
|
}
|
2025 |
|
|
/**
|
2026 |
|
|
* Creates a history object that stores locations in memory.
|
2027 |
|
|
*/
|
2028 |
|
|
|
2029 |
|
|
|
2030 |
|
|
function createMemoryHistory(props) {
|
2031 |
|
|
if (props === void 0) {
|
2032 |
|
|
props = {};
|
2033 |
|
|
}
|
2034 |
|
|
|
2035 |
|
|
var _props = props,
|
2036 |
|
|
getUserConfirmation = _props.getUserConfirmation,
|
2037 |
|
|
_props$initialEntries = _props.initialEntries,
|
2038 |
|
|
initialEntries = _props$initialEntries === void 0 ? ['/'] : _props$initialEntries,
|
2039 |
|
|
_props$initialIndex = _props.initialIndex,
|
2040 |
|
|
initialIndex = _props$initialIndex === void 0 ? 0 : _props$initialIndex,
|
2041 |
|
|
_props$keyLength = _props.keyLength,
|
2042 |
|
|
keyLength = _props$keyLength === void 0 ? 6 : _props$keyLength;
|
2043 |
|
|
var transitionManager = createTransitionManager();
|
2044 |
|
|
|
2045 |
|
|
function setState(nextState) {
|
2046 |
|
|
_extends(history, nextState);
|
2047 |
|
|
|
2048 |
|
|
history.length = history.entries.length;
|
2049 |
|
|
transitionManager.notifyListeners(history.location, history.action);
|
2050 |
|
|
}
|
2051 |
|
|
|
2052 |
|
|
function createKey() {
|
2053 |
|
|
return Math.random().toString(36).substr(2, keyLength);
|
2054 |
|
|
}
|
2055 |
|
|
|
2056 |
|
|
var index = clamp(initialIndex, 0, initialEntries.length - 1);
|
2057 |
|
|
var entries = initialEntries.map(function (entry) {
|
2058 |
|
|
return typeof entry === 'string' ? createLocation(entry, undefined, createKey()) : createLocation(entry, undefined, entry.key || createKey());
|
2059 |
|
|
}); // Public interface
|
2060 |
|
|
|
2061 |
|
|
var createHref = createPath;
|
2062 |
|
|
|
2063 |
|
|
function push(path, state) {
|
2064 |
|
|
warning(!(typeof 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') ;
|
2065 |
|
|
var action = 'PUSH';
|
2066 |
|
|
var location = createLocation(path, state, createKey(), history.location);
|
2067 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
2068 |
|
|
if (!ok) return;
|
2069 |
|
|
var prevIndex = history.index;
|
2070 |
|
|
var nextIndex = prevIndex + 1;
|
2071 |
|
|
var nextEntries = history.entries.slice(0);
|
2072 |
|
|
|
2073 |
|
|
if (nextEntries.length > nextIndex) {
|
2074 |
|
|
nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location);
|
2075 |
|
|
} else {
|
2076 |
|
|
nextEntries.push(location);
|
2077 |
|
|
}
|
2078 |
|
|
|
2079 |
|
|
setState({
|
2080 |
|
|
action: action,
|
2081 |
|
|
location: location,
|
2082 |
|
|
index: nextIndex,
|
2083 |
|
|
entries: nextEntries
|
2084 |
|
|
});
|
2085 |
|
|
});
|
2086 |
|
|
}
|
2087 |
|
|
|
2088 |
|
|
function replace(path, state) {
|
2089 |
|
|
warning(!(typeof 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') ;
|
2090 |
|
|
var action = 'REPLACE';
|
2091 |
|
|
var location = createLocation(path, state, createKey(), history.location);
|
2092 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
2093 |
|
|
if (!ok) return;
|
2094 |
|
|
history.entries[history.index] = location;
|
2095 |
|
|
setState({
|
2096 |
|
|
action: action,
|
2097 |
|
|
location: location
|
2098 |
|
|
});
|
2099 |
|
|
});
|
2100 |
|
|
}
|
2101 |
|
|
|
2102 |
|
|
function go(n) {
|
2103 |
|
|
var nextIndex = clamp(history.index + n, 0, history.entries.length - 1);
|
2104 |
|
|
var action = 'POP';
|
2105 |
|
|
var location = history.entries[nextIndex];
|
2106 |
|
|
transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
|
2107 |
|
|
if (ok) {
|
2108 |
|
|
setState({
|
2109 |
|
|
action: action,
|
2110 |
|
|
location: location,
|
2111 |
|
|
index: nextIndex
|
2112 |
|
|
});
|
2113 |
|
|
} else {
|
2114 |
|
|
// Mimic the behavior of DOM histories by
|
2115 |
|
|
// causing a render after a cancelled POP.
|
2116 |
|
|
setState();
|
2117 |
|
|
}
|
2118 |
|
|
});
|
2119 |
|
|
}
|
2120 |
|
|
|
2121 |
|
|
function goBack() {
|
2122 |
|
|
go(-1);
|
2123 |
|
|
}
|
2124 |
|
|
|
2125 |
|
|
function goForward() {
|
2126 |
|
|
go(1);
|
2127 |
|
|
}
|
2128 |
|
|
|
2129 |
|
|
function canGo(n) {
|
2130 |
|
|
var nextIndex = history.index + n;
|
2131 |
|
|
return nextIndex >= 0 && nextIndex < history.entries.length;
|
2132 |
|
|
}
|
2133 |
|
|
|
2134 |
|
|
function block(prompt) {
|
2135 |
|
|
if (prompt === void 0) {
|
2136 |
|
|
prompt = false;
|
2137 |
|
|
}
|
2138 |
|
|
|
2139 |
|
|
return transitionManager.setPrompt(prompt);
|
2140 |
|
|
}
|
2141 |
|
|
|
2142 |
|
|
function listen(listener) {
|
2143 |
|
|
return transitionManager.appendListener(listener);
|
2144 |
|
|
}
|
2145 |
|
|
|
2146 |
|
|
var history = {
|
2147 |
|
|
length: entries.length,
|
2148 |
|
|
action: 'POP',
|
2149 |
|
|
location: entries[index],
|
2150 |
|
|
index: index,
|
2151 |
|
|
entries: entries,
|
2152 |
|
|
createHref: createHref,
|
2153 |
|
|
push: push,
|
2154 |
|
|
replace: replace,
|
2155 |
|
|
go: go,
|
2156 |
|
|
goBack: goBack,
|
2157 |
|
|
goForward: goForward,
|
2158 |
|
|
canGo: canGo,
|
2159 |
|
|
block: block,
|
2160 |
|
|
listen: listen
|
2161 |
|
|
};
|
2162 |
|
|
return history;
|
2163 |
|
|
}
|
2164 |
|
|
|
2165 |
|
|
function _inheritsLoose$1(subClass, superClass) {
|
2166 |
|
|
subClass.prototype = Object.create(superClass.prototype);
|
2167 |
|
|
subClass.prototype.constructor = subClass;
|
2168 |
|
|
subClass.__proto__ = superClass;
|
2169 |
|
|
}
|
2170 |
|
|
|
2171 |
|
|
var inheritsLoose = _inheritsLoose$1;
|
2172 |
|
|
|
2173 |
|
|
var key = '__global_unique_id__';
|
2174 |
|
|
|
2175 |
|
|
var gud = function() {
|
2176 |
|
|
return commonjsGlobal[key] = (commonjsGlobal[key] || 0) + 1;
|
2177 |
|
|
};
|
2178 |
|
|
|
2179 |
|
|
var MAX_SIGNED_31_BIT_INT = 1073741823;
|
2180 |
|
|
|
2181 |
|
|
function objectIs(x, y) {
|
2182 |
|
|
if (x === y) {
|
2183 |
|
|
return x !== 0 || 1 / x === 1 / y;
|
2184 |
|
|
} else {
|
2185 |
|
|
return x !== x && y !== y;
|
2186 |
|
|
}
|
2187 |
|
|
}
|
2188 |
|
|
|
2189 |
|
|
function createEventEmitter(value) {
|
2190 |
|
|
var handlers = [];
|
2191 |
|
|
return {
|
2192 |
|
|
on: function on(handler) {
|
2193 |
|
|
handlers.push(handler);
|
2194 |
|
|
},
|
2195 |
|
|
off: function off(handler) {
|
2196 |
|
|
handlers = handlers.filter(function (h) {
|
2197 |
|
|
return h !== handler;
|
2198 |
|
|
});
|
2199 |
|
|
},
|
2200 |
|
|
get: function get() {
|
2201 |
|
|
return value;
|
2202 |
|
|
},
|
2203 |
|
|
set: function set(newValue, changedBits) {
|
2204 |
|
|
value = newValue;
|
2205 |
|
|
handlers.forEach(function (handler) {
|
2206 |
|
|
return handler(value, changedBits);
|
2207 |
|
|
});
|
2208 |
|
|
}
|
2209 |
|
|
};
|
2210 |
|
|
}
|
2211 |
|
|
|
2212 |
|
|
function onlyChild(children) {
|
2213 |
|
|
return Array.isArray(children) ? children[0] : children;
|
2214 |
|
|
}
|
2215 |
|
|
|
2216 |
|
|
function createReactContext(defaultValue, calculateChangedBits) {
|
2217 |
|
|
var _Provider$childContex, _Consumer$contextType;
|
2218 |
|
|
|
2219 |
|
|
var contextProp = '__create-react-context-' + gud() + '__';
|
2220 |
|
|
|
2221 |
|
|
var Provider =
|
2222 |
|
|
/*#__PURE__*/
|
2223 |
|
|
function (_Component) {
|
2224 |
|
|
inheritsLoose(Provider, _Component);
|
2225 |
|
|
|
2226 |
|
|
function Provider() {
|
2227 |
|
|
var _this;
|
2228 |
|
|
|
2229 |
|
|
_this = _Component.apply(this, arguments) || this;
|
2230 |
|
|
_this.emitter = createEventEmitter(_this.props.value);
|
2231 |
|
|
return _this;
|
2232 |
|
|
}
|
2233 |
|
|
|
2234 |
|
|
var _proto = Provider.prototype;
|
2235 |
|
|
|
2236 |
|
|
_proto.getChildContext = function getChildContext() {
|
2237 |
|
|
var _ref;
|
2238 |
|
|
|
2239 |
|
|
return _ref = {}, _ref[contextProp] = this.emitter, _ref;
|
2240 |
|
|
};
|
2241 |
|
|
|
2242 |
|
|
_proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
2243 |
|
|
if (this.props.value !== nextProps.value) {
|
2244 |
|
|
var oldValue = this.props.value;
|
2245 |
|
|
var newValue = nextProps.value;
|
2246 |
|
|
var changedBits;
|
2247 |
|
|
|
2248 |
|
|
if (objectIs(oldValue, newValue)) {
|
2249 |
|
|
changedBits = 0;
|
2250 |
|
|
} else {
|
2251 |
|
|
changedBits = typeof calculateChangedBits === 'function' ? calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
|
2252 |
|
|
|
2253 |
|
|
{
|
2254 |
|
|
warning((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: ' + changedBits);
|
2255 |
|
|
}
|
2256 |
|
|
|
2257 |
|
|
changedBits |= 0;
|
2258 |
|
|
|
2259 |
|
|
if (changedBits !== 0) {
|
2260 |
|
|
this.emitter.set(nextProps.value, changedBits);
|
2261 |
|
|
}
|
2262 |
|
|
}
|
2263 |
|
|
}
|
2264 |
|
|
};
|
2265 |
|
|
|
2266 |
|
|
_proto.render = function render() {
|
2267 |
|
|
return this.props.children;
|
2268 |
|
|
};
|
2269 |
|
|
|
2270 |
|
|
return Provider;
|
2271 |
|
|
}(React.Component);
|
2272 |
|
|
|
2273 |
|
|
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = propTypes.object.isRequired, _Provider$childContex);
|
2274 |
|
|
|
2275 |
|
|
var Consumer =
|
2276 |
|
|
/*#__PURE__*/
|
2277 |
|
|
function (_Component2) {
|
2278 |
|
|
inheritsLoose(Consumer, _Component2);
|
2279 |
|
|
|
2280 |
|
|
function Consumer() {
|
2281 |
|
|
var _this2;
|
2282 |
|
|
|
2283 |
|
|
_this2 = _Component2.apply(this, arguments) || this;
|
2284 |
|
|
_this2.state = {
|
2285 |
|
|
value: _this2.getValue()
|
2286 |
|
|
};
|
2287 |
|
|
|
2288 |
|
|
_this2.onUpdate = function (newValue, changedBits) {
|
2289 |
|
|
var observedBits = _this2.observedBits | 0;
|
2290 |
|
|
|
2291 |
|
|
if ((observedBits & changedBits) !== 0) {
|
2292 |
|
|
_this2.setState({
|
2293 |
|
|
value: _this2.getValue()
|
2294 |
|
|
});
|
2295 |
|
|
}
|
2296 |
|
|
};
|
2297 |
|
|
|
2298 |
|
|
return _this2;
|
2299 |
|
|
}
|
2300 |
|
|
|
2301 |
|
|
var _proto2 = Consumer.prototype;
|
2302 |
|
|
|
2303 |
|
|
_proto2.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
2304 |
|
|
var observedBits = nextProps.observedBits;
|
2305 |
|
|
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits;
|
2306 |
|
|
};
|
2307 |
|
|
|
2308 |
|
|
_proto2.componentDidMount = function componentDidMount() {
|
2309 |
|
|
if (this.context[contextProp]) {
|
2310 |
|
|
this.context[contextProp].on(this.onUpdate);
|
2311 |
|
|
}
|
2312 |
|
|
|
2313 |
|
|
var observedBits = this.props.observedBits;
|
2314 |
|
|
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits;
|
2315 |
|
|
};
|
2316 |
|
|
|
2317 |
|
|
_proto2.componentWillUnmount = function componentWillUnmount() {
|
2318 |
|
|
if (this.context[contextProp]) {
|
2319 |
|
|
this.context[contextProp].off(this.onUpdate);
|
2320 |
|
|
}
|
2321 |
|
|
};
|
2322 |
|
|
|
2323 |
|
|
_proto2.getValue = function getValue() {
|
2324 |
|
|
if (this.context[contextProp]) {
|
2325 |
|
|
return this.context[contextProp].get();
|
2326 |
|
|
} else {
|
2327 |
|
|
return defaultValue;
|
2328 |
|
|
}
|
2329 |
|
|
};
|
2330 |
|
|
|
2331 |
|
|
_proto2.render = function render() {
|
2332 |
|
|
return onlyChild(this.props.children)(this.state.value);
|
2333 |
|
|
};
|
2334 |
|
|
|
2335 |
|
|
return Consumer;
|
2336 |
|
|
}(React.Component);
|
2337 |
|
|
|
2338 |
|
|
Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = propTypes.object, _Consumer$contextType);
|
2339 |
|
|
return {
|
2340 |
|
|
Provider: Provider,
|
2341 |
|
|
Consumer: Consumer
|
2342 |
|
|
};
|
2343 |
|
|
}
|
2344 |
|
|
|
2345 |
|
|
var index = React__default.createContext || createReactContext;
|
2346 |
|
|
|
2347 |
|
|
var isarray = Array.isArray || function (arr) {
|
2348 |
|
|
return Object.prototype.toString.call(arr) == '[object Array]';
|
2349 |
|
|
};
|
2350 |
|
|
|
2351 |
|
|
/**
|
2352 |
|
|
* Expose `pathToRegexp`.
|
2353 |
|
|
*/
|
2354 |
|
|
var pathToRegexp_1 = pathToRegexp;
|
2355 |
|
|
var parse_1 = parse;
|
2356 |
|
|
var compile_1 = compile;
|
2357 |
|
|
var tokensToFunction_1 = tokensToFunction;
|
2358 |
|
|
var tokensToRegExp_1 = tokensToRegExp;
|
2359 |
|
|
|
2360 |
|
|
/**
|
2361 |
|
|
* The main path matching regexp utility.
|
2362 |
|
|
*
|
2363 |
|
|
* @type {RegExp}
|
2364 |
|
|
*/
|
2365 |
|
|
var PATH_REGEXP = new RegExp([
|
2366 |
|
|
// Match escaped characters that would otherwise appear in future matches.
|
2367 |
|
|
// This allows the user to escape special characters that won't transform.
|
2368 |
|
|
'(\\\\.)',
|
2369 |
|
|
// Match Express-style parameters and un-named parameters with a prefix
|
2370 |
|
|
// and optional suffixes. Matches appear as:
|
2371 |
|
|
//
|
2372 |
|
|
// "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
|
2373 |
|
|
// "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
|
2374 |
|
|
// "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
|
2375 |
|
|
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
|
2376 |
|
|
].join('|'), 'g');
|
2377 |
|
|
|
2378 |
|
|
/**
|
2379 |
|
|
* Parse a string for the raw tokens.
|
2380 |
|
|
*
|
2381 |
|
|
* @param {string} str
|
2382 |
|
|
* @param {Object=} options
|
2383 |
|
|
* @return {!Array}
|
2384 |
|
|
*/
|
2385 |
|
|
function parse (str, options) {
|
2386 |
|
|
var tokens = [];
|
2387 |
|
|
var key = 0;
|
2388 |
|
|
var index = 0;
|
2389 |
|
|
var path = '';
|
2390 |
|
|
var defaultDelimiter = options && options.delimiter || '/';
|
2391 |
|
|
var res;
|
2392 |
|
|
|
2393 |
|
|
while ((res = PATH_REGEXP.exec(str)) != null) {
|
2394 |
|
|
var m = res[0];
|
2395 |
|
|
var escaped = res[1];
|
2396 |
|
|
var offset = res.index;
|
2397 |
|
|
path += str.slice(index, offset);
|
2398 |
|
|
index = offset + m.length;
|
2399 |
|
|
|
2400 |
|
|
// Ignore already escaped sequences.
|
2401 |
|
|
if (escaped) {
|
2402 |
|
|
path += escaped[1];
|
2403 |
|
|
continue
|
2404 |
|
|
}
|
2405 |
|
|
|
2406 |
|
|
var next = str[index];
|
2407 |
|
|
var prefix = res[2];
|
2408 |
|
|
var name = res[3];
|
2409 |
|
|
var capture = res[4];
|
2410 |
|
|
var group = res[5];
|
2411 |
|
|
var modifier = res[6];
|
2412 |
|
|
var asterisk = res[7];
|
2413 |
|
|
|
2414 |
|
|
// Push the current path onto the tokens.
|
2415 |
|
|
if (path) {
|
2416 |
|
|
tokens.push(path);
|
2417 |
|
|
path = '';
|
2418 |
|
|
}
|
2419 |
|
|
|
2420 |
|
|
var partial = prefix != null && next != null && next !== prefix;
|
2421 |
|
|
var repeat = modifier === '+' || modifier === '*';
|
2422 |
|
|
var optional = modifier === '?' || modifier === '*';
|
2423 |
|
|
var delimiter = res[2] || defaultDelimiter;
|
2424 |
|
|
var pattern = capture || group;
|
2425 |
|
|
|
2426 |
|
|
tokens.push({
|
2427 |
|
|
name: name || key++,
|
2428 |
|
|
prefix: prefix || '',
|
2429 |
|
|
delimiter: delimiter,
|
2430 |
|
|
optional: optional,
|
2431 |
|
|
repeat: repeat,
|
2432 |
|
|
partial: partial,
|
2433 |
|
|
asterisk: !!asterisk,
|
2434 |
|
|
pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
|
2435 |
|
|
});
|
2436 |
|
|
}
|
2437 |
|
|
|
2438 |
|
|
// Match any characters still remaining.
|
2439 |
|
|
if (index < str.length) {
|
2440 |
|
|
path += str.substr(index);
|
2441 |
|
|
}
|
2442 |
|
|
|
2443 |
|
|
// If the path exists, push it onto the end.
|
2444 |
|
|
if (path) {
|
2445 |
|
|
tokens.push(path);
|
2446 |
|
|
}
|
2447 |
|
|
|
2448 |
|
|
return tokens
|
2449 |
|
|
}
|
2450 |
|
|
|
2451 |
|
|
/**
|
2452 |
|
|
* Compile a string to a template function for the path.
|
2453 |
|
|
*
|
2454 |
|
|
* @param {string} str
|
2455 |
|
|
* @param {Object=} options
|
2456 |
|
|
* @return {!function(Object=, Object=)}
|
2457 |
|
|
*/
|
2458 |
|
|
function compile (str, options) {
|
2459 |
|
|
return tokensToFunction(parse(str, options))
|
2460 |
|
|
}
|
2461 |
|
|
|
2462 |
|
|
/**
|
2463 |
|
|
* Prettier encoding of URI path segments.
|
2464 |
|
|
*
|
2465 |
|
|
* @param {string}
|
2466 |
|
|
* @return {string}
|
2467 |
|
|
*/
|
2468 |
|
|
function encodeURIComponentPretty (str) {
|
2469 |
|
|
return encodeURI(str).replace(/[\/?#]/g, function (c) {
|
2470 |
|
|
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
|
2471 |
|
|
})
|
2472 |
|
|
}
|
2473 |
|
|
|
2474 |
|
|
/**
|
2475 |
|
|
* Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
|
2476 |
|
|
*
|
2477 |
|
|
* @param {string}
|
2478 |
|
|
* @return {string}
|
2479 |
|
|
*/
|
2480 |
|
|
function encodeAsterisk (str) {
|
2481 |
|
|
return encodeURI(str).replace(/[?#]/g, function (c) {
|
2482 |
|
|
return '%' + c.charCodeAt(0).toString(16).toUpperCase()
|
2483 |
|
|
})
|
2484 |
|
|
}
|
2485 |
|
|
|
2486 |
|
|
/**
|
2487 |
|
|
* Expose a method for transforming tokens into the path function.
|
2488 |
|
|
*/
|
2489 |
|
|
function tokensToFunction (tokens) {
|
2490 |
|
|
// Compile all the tokens into regexps.
|
2491 |
|
|
var matches = new Array(tokens.length);
|
2492 |
|
|
|
2493 |
|
|
// Compile all the patterns before compilation.
|
2494 |
|
|
for (var i = 0; i < tokens.length; i++) {
|
2495 |
|
|
if (typeof tokens[i] === 'object') {
|
2496 |
|
|
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$');
|
2497 |
|
|
}
|
2498 |
|
|
}
|
2499 |
|
|
|
2500 |
|
|
return function (obj, opts) {
|
2501 |
|
|
var path = '';
|
2502 |
|
|
var data = obj || {};
|
2503 |
|
|
var options = opts || {};
|
2504 |
|
|
var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
|
2505 |
|
|
|
2506 |
|
|
for (var i = 0; i < tokens.length; i++) {
|
2507 |
|
|
var token = tokens[i];
|
2508 |
|
|
|
2509 |
|
|
if (typeof token === 'string') {
|
2510 |
|
|
path += token;
|
2511 |
|
|
|
2512 |
|
|
continue
|
2513 |
|
|
}
|
2514 |
|
|
|
2515 |
|
|
var value = data[token.name];
|
2516 |
|
|
var segment;
|
2517 |
|
|
|
2518 |
|
|
if (value == null) {
|
2519 |
|
|
if (token.optional) {
|
2520 |
|
|
// Prepend partial segment prefixes.
|
2521 |
|
|
if (token.partial) {
|
2522 |
|
|
path += token.prefix;
|
2523 |
|
|
}
|
2524 |
|
|
|
2525 |
|
|
continue
|
2526 |
|
|
} else {
|
2527 |
|
|
throw new TypeError('Expected "' + token.name + '" to be defined')
|
2528 |
|
|
}
|
2529 |
|
|
}
|
2530 |
|
|
|
2531 |
|
|
if (isarray(value)) {
|
2532 |
|
|
if (!token.repeat) {
|
2533 |
|
|
throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
|
2534 |
|
|
}
|
2535 |
|
|
|
2536 |
|
|
if (value.length === 0) {
|
2537 |
|
|
if (token.optional) {
|
2538 |
|
|
continue
|
2539 |
|
|
} else {
|
2540 |
|
|
throw new TypeError('Expected "' + token.name + '" to not be empty')
|
2541 |
|
|
}
|
2542 |
|
|
}
|
2543 |
|
|
|
2544 |
|
|
for (var j = 0; j < value.length; j++) {
|
2545 |
|
|
segment = encode(value[j]);
|
2546 |
|
|
|
2547 |
|
|
if (!matches[i].test(segment)) {
|
2548 |
|
|
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
|
2549 |
|
|
}
|
2550 |
|
|
|
2551 |
|
|
path += (j === 0 ? token.prefix : token.delimiter) + segment;
|
2552 |
|
|
}
|
2553 |
|
|
|
2554 |
|
|
continue
|
2555 |
|
|
}
|
2556 |
|
|
|
2557 |
|
|
segment = token.asterisk ? encodeAsterisk(value) : encode(value);
|
2558 |
|
|
|
2559 |
|
|
if (!matches[i].test(segment)) {
|
2560 |
|
|
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
|
2561 |
|
|
}
|
2562 |
|
|
|
2563 |
|
|
path += token.prefix + segment;
|
2564 |
|
|
}
|
2565 |
|
|
|
2566 |
|
|
return path
|
2567 |
|
|
}
|
2568 |
|
|
}
|
2569 |
|
|
|
2570 |
|
|
/**
|
2571 |
|
|
* Escape a regular expression string.
|
2572 |
|
|
*
|
2573 |
|
|
* @param {string} str
|
2574 |
|
|
* @return {string}
|
2575 |
|
|
*/
|
2576 |
|
|
function escapeString (str) {
|
2577 |
|
|
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
|
2578 |
|
|
}
|
2579 |
|
|
|
2580 |
|
|
/**
|
2581 |
|
|
* Escape the capturing group by escaping special characters and meaning.
|
2582 |
|
|
*
|
2583 |
|
|
* @param {string} group
|
2584 |
|
|
* @return {string}
|
2585 |
|
|
*/
|
2586 |
|
|
function escapeGroup (group) {
|
2587 |
|
|
return group.replace(/([=!:$\/()])/g, '\\$1')
|
2588 |
|
|
}
|
2589 |
|
|
|
2590 |
|
|
/**
|
2591 |
|
|
* Attach the keys as a property of the regexp.
|
2592 |
|
|
*
|
2593 |
|
|
* @param {!RegExp} re
|
2594 |
|
|
* @param {Array} keys
|
2595 |
|
|
* @return {!RegExp}
|
2596 |
|
|
*/
|
2597 |
|
|
function attachKeys (re, keys) {
|
2598 |
|
|
re.keys = keys;
|
2599 |
|
|
return re
|
2600 |
|
|
}
|
2601 |
|
|
|
2602 |
|
|
/**
|
2603 |
|
|
* Get the flags for a regexp from the options.
|
2604 |
|
|
*
|
2605 |
|
|
* @param {Object} options
|
2606 |
|
|
* @return {string}
|
2607 |
|
|
*/
|
2608 |
|
|
function flags (options) {
|
2609 |
|
|
return options.sensitive ? '' : 'i'
|
2610 |
|
|
}
|
2611 |
|
|
|
2612 |
|
|
/**
|
2613 |
|
|
* Pull out keys from a regexp.
|
2614 |
|
|
*
|
2615 |
|
|
* @param {!RegExp} path
|
2616 |
|
|
* @param {!Array} keys
|
2617 |
|
|
* @return {!RegExp}
|
2618 |
|
|
*/
|
2619 |
|
|
function regexpToRegexp (path, keys) {
|
2620 |
|
|
// Use a negative lookahead to match only capturing groups.
|
2621 |
|
|
var groups = path.source.match(/\((?!\?)/g);
|
2622 |
|
|
|
2623 |
|
|
if (groups) {
|
2624 |
|
|
for (var i = 0; i < groups.length; i++) {
|
2625 |
|
|
keys.push({
|
2626 |
|
|
name: i,
|
2627 |
|
|
prefix: null,
|
2628 |
|
|
delimiter: null,
|
2629 |
|
|
optional: false,
|
2630 |
|
|
repeat: false,
|
2631 |
|
|
partial: false,
|
2632 |
|
|
asterisk: false,
|
2633 |
|
|
pattern: null
|
2634 |
|
|
});
|
2635 |
|
|
}
|
2636 |
|
|
}
|
2637 |
|
|
|
2638 |
|
|
return attachKeys(path, keys)
|
2639 |
|
|
}
|
2640 |
|
|
|
2641 |
|
|
/**
|
2642 |
|
|
* Transform an array into a regexp.
|
2643 |
|
|
*
|
2644 |
|
|
* @param {!Array} path
|
2645 |
|
|
* @param {Array} keys
|
2646 |
|
|
* @param {!Object} options
|
2647 |
|
|
* @return {!RegExp}
|
2648 |
|
|
*/
|
2649 |
|
|
function arrayToRegexp (path, keys, options) {
|
2650 |
|
|
var parts = [];
|
2651 |
|
|
|
2652 |
|
|
for (var i = 0; i < path.length; i++) {
|
2653 |
|
|
parts.push(pathToRegexp(path[i], keys, options).source);
|
2654 |
|
|
}
|
2655 |
|
|
|
2656 |
|
|
var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
|
2657 |
|
|
|
2658 |
|
|
return attachKeys(regexp, keys)
|
2659 |
|
|
}
|
2660 |
|
|
|
2661 |
|
|
/**
|
2662 |
|
|
* Create a path regexp from string input.
|
2663 |
|
|
*
|
2664 |
|
|
* @param {string} path
|
2665 |
|
|
* @param {!Array} keys
|
2666 |
|
|
* @param {!Object} options
|
2667 |
|
|
* @return {!RegExp}
|
2668 |
|
|
*/
|
2669 |
|
|
function stringToRegexp (path, keys, options) {
|
2670 |
|
|
return tokensToRegExp(parse(path, options), keys, options)
|
2671 |
|
|
}
|
2672 |
|
|
|
2673 |
|
|
/**
|
2674 |
|
|
* Expose a function for taking tokens and returning a RegExp.
|
2675 |
|
|
*
|
2676 |
|
|
* @param {!Array} tokens
|
2677 |
|
|
* @param {(Array|Object)=} keys
|
2678 |
|
|
* @param {Object=} options
|
2679 |
|
|
* @return {!RegExp}
|
2680 |
|
|
*/
|
2681 |
|
|
function tokensToRegExp (tokens, keys, options) {
|
2682 |
|
|
if (!isarray(keys)) {
|
2683 |
|
|
options = /** @type {!Object} */ (keys || options);
|
2684 |
|
|
keys = [];
|
2685 |
|
|
}
|
2686 |
|
|
|
2687 |
|
|
options = options || {};
|
2688 |
|
|
|
2689 |
|
|
var strict = options.strict;
|
2690 |
|
|
var end = options.end !== false;
|
2691 |
|
|
var route = '';
|
2692 |
|
|
|
2693 |
|
|
// Iterate over the tokens and create our regexp string.
|
2694 |
|
|
for (var i = 0; i < tokens.length; i++) {
|
2695 |
|
|
var token = tokens[i];
|
2696 |
|
|
|
2697 |
|
|
if (typeof token === 'string') {
|
2698 |
|
|
route += escapeString(token);
|
2699 |
|
|
} else {
|
2700 |
|
|
var prefix = escapeString(token.prefix);
|
2701 |
|
|
var capture = '(?:' + token.pattern + ')';
|
2702 |
|
|
|
2703 |
|
|
keys.push(token);
|
2704 |
|
|
|
2705 |
|
|
if (token.repeat) {
|
2706 |
|
|
capture += '(?:' + prefix + capture + ')*';
|
2707 |
|
|
}
|
2708 |
|
|
|
2709 |
|
|
if (token.optional) {
|
2710 |
|
|
if (!token.partial) {
|
2711 |
|
|
capture = '(?:' + prefix + '(' + capture + '))?';
|
2712 |
|
|
} else {
|
2713 |
|
|
capture = prefix + '(' + capture + ')?';
|
2714 |
|
|
}
|
2715 |
|
|
} else {
|
2716 |
|
|
capture = prefix + '(' + capture + ')';
|
2717 |
|
|
}
|
2718 |
|
|
|
2719 |
|
|
route += capture;
|
2720 |
|
|
}
|
2721 |
|
|
}
|
2722 |
|
|
|
2723 |
|
|
var delimiter = escapeString(options.delimiter || '/');
|
2724 |
|
|
var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
|
2725 |
|
|
|
2726 |
|
|
// In non-strict mode we allow a slash at the end of match. If the path to
|
2727 |
|
|
// match already ends with a slash, we remove it for consistency. The slash
|
2728 |
|
|
// is valid at the end of a path match, not in the middle. This is important
|
2729 |
|
|
// in non-ending mode, where "/test/" shouldn't match "/test//route".
|
2730 |
|
|
if (!strict) {
|
2731 |
|
|
route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
|
2732 |
|
|
}
|
2733 |
|
|
|
2734 |
|
|
if (end) {
|
2735 |
|
|
route += '$';
|
2736 |
|
|
} else {
|
2737 |
|
|
// In non-ending mode, we need the capturing groups to match as much as
|
2738 |
|
|
// possible by using a positive lookahead to the end or next path segment.
|
2739 |
|
|
route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
|
2740 |
|
|
}
|
2741 |
|
|
|
2742 |
|
|
return attachKeys(new RegExp('^' + route, flags(options)), keys)
|
2743 |
|
|
}
|
2744 |
|
|
|
2745 |
|
|
/**
|
2746 |
|
|
* Normalize the given path string, returning a regular expression.
|
2747 |
|
|
*
|
2748 |
|
|
* An empty array can be passed in for the keys, which will hold the
|
2749 |
|
|
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
2750 |
|
|
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
2751 |
|
|
*
|
2752 |
|
|
* @param {(string|RegExp|Array)} path
|
2753 |
|
|
* @param {(Array|Object)=} keys
|
2754 |
|
|
* @param {Object=} options
|
2755 |
|
|
* @return {!RegExp}
|
2756 |
|
|
*/
|
2757 |
|
|
function pathToRegexp (path, keys, options) {
|
2758 |
|
|
if (!isarray(keys)) {
|
2759 |
|
|
options = /** @type {!Object} */ (keys || options);
|
2760 |
|
|
keys = [];
|
2761 |
|
|
}
|
2762 |
|
|
|
2763 |
|
|
options = options || {};
|
2764 |
|
|
|
2765 |
|
|
if (path instanceof RegExp) {
|
2766 |
|
|
return regexpToRegexp(path, /** @type {!Array} */ (keys))
|
2767 |
|
|
}
|
2768 |
|
|
|
2769 |
|
|
if (isarray(path)) {
|
2770 |
|
|
return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
|
2771 |
|
|
}
|
2772 |
|
|
|
2773 |
|
|
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
|
2774 |
|
|
}
|
2775 |
|
|
pathToRegexp_1.parse = parse_1;
|
2776 |
|
|
pathToRegexp_1.compile = compile_1;
|
2777 |
|
|
pathToRegexp_1.tokensToFunction = tokensToFunction_1;
|
2778 |
|
|
pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
|
2779 |
|
|
|
2780 |
|
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
2781 |
|
|
if (source == null) return {};
|
2782 |
|
|
var target = {};
|
2783 |
|
|
var sourceKeys = Object.keys(source);
|
2784 |
|
|
var key, i;
|
2785 |
|
|
|
2786 |
|
|
for (i = 0; i < sourceKeys.length; i++) {
|
2787 |
|
|
key = sourceKeys[i];
|
2788 |
|
|
if (excluded.indexOf(key) >= 0) continue;
|
2789 |
|
|
target[key] = source[key];
|
2790 |
|
|
}
|
2791 |
|
|
|
2792 |
|
|
return target;
|
2793 |
|
|
}
|
2794 |
|
|
|
2795 |
|
|
/**
|
2796 |
|
|
* Copyright 2015, Yahoo! Inc.
|
2797 |
|
|
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
|
2798 |
|
|
*/
|
2799 |
|
|
|
2800 |
|
|
var REACT_STATICS = {
|
2801 |
|
|
childContextTypes: true,
|
2802 |
|
|
contextType: true,
|
2803 |
|
|
contextTypes: true,
|
2804 |
|
|
defaultProps: true,
|
2805 |
|
|
displayName: true,
|
2806 |
|
|
getDefaultProps: true,
|
2807 |
|
|
getDerivedStateFromError: true,
|
2808 |
|
|
getDerivedStateFromProps: true,
|
2809 |
|
|
mixins: true,
|
2810 |
|
|
propTypes: true,
|
2811 |
|
|
type: true
|
2812 |
|
|
};
|
2813 |
|
|
|
2814 |
|
|
var KNOWN_STATICS = {
|
2815 |
|
|
name: true,
|
2816 |
|
|
length: true,
|
2817 |
|
|
prototype: true,
|
2818 |
|
|
caller: true,
|
2819 |
|
|
callee: true,
|
2820 |
|
|
arguments: true,
|
2821 |
|
|
arity: true
|
2822 |
|
|
};
|
2823 |
|
|
|
2824 |
|
|
var FORWARD_REF_STATICS = {
|
2825 |
|
|
'$$typeof': true,
|
2826 |
|
|
render: true,
|
2827 |
|
|
defaultProps: true,
|
2828 |
|
|
displayName: true,
|
2829 |
|
|
propTypes: true
|
2830 |
|
|
};
|
2831 |
|
|
|
2832 |
|
|
var MEMO_STATICS = {
|
2833 |
|
|
'$$typeof': true,
|
2834 |
|
|
compare: true,
|
2835 |
|
|
defaultProps: true,
|
2836 |
|
|
displayName: true,
|
2837 |
|
|
propTypes: true,
|
2838 |
|
|
type: true
|
2839 |
|
|
};
|
2840 |
|
|
|
2841 |
|
|
var TYPE_STATICS = {};
|
2842 |
|
|
TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS;
|
2843 |
|
|
|
2844 |
|
|
function getStatics(component) {
|
2845 |
|
|
if (reactIs.isMemo(component)) {
|
2846 |
|
|
return MEMO_STATICS;
|
2847 |
|
|
}
|
2848 |
|
|
return TYPE_STATICS[component['$$typeof']] || REACT_STATICS;
|
2849 |
|
|
}
|
2850 |
|
|
|
2851 |
|
|
var defineProperty = Object.defineProperty;
|
2852 |
|
|
var getOwnPropertyNames = Object.getOwnPropertyNames;
|
2853 |
|
|
var getOwnPropertySymbols$1 = Object.getOwnPropertySymbols;
|
2854 |
|
|
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
2855 |
|
|
var getPrototypeOf = Object.getPrototypeOf;
|
2856 |
|
|
var objectPrototype = Object.prototype;
|
2857 |
|
|
|
2858 |
|
|
function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
2859 |
|
|
if (typeof sourceComponent !== 'string') {
|
2860 |
|
|
// don't hoist over string (html) components
|
2861 |
|
|
|
2862 |
|
|
if (objectPrototype) {
|
2863 |
|
|
var inheritedComponent = getPrototypeOf(sourceComponent);
|
2864 |
|
|
if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
2865 |
|
|
hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
2866 |
|
|
}
|
2867 |
|
|
}
|
2868 |
|
|
|
2869 |
|
|
var keys = getOwnPropertyNames(sourceComponent);
|
2870 |
|
|
|
2871 |
|
|
if (getOwnPropertySymbols$1) {
|
2872 |
|
|
keys = keys.concat(getOwnPropertySymbols$1(sourceComponent));
|
2873 |
|
|
}
|
2874 |
|
|
|
2875 |
|
|
var targetStatics = getStatics(targetComponent);
|
2876 |
|
|
var sourceStatics = getStatics(sourceComponent);
|
2877 |
|
|
|
2878 |
|
|
for (var i = 0; i < keys.length; ++i) {
|
2879 |
|
|
var key = keys[i];
|
2880 |
|
|
if (!KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
|
2881 |
|
|
var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
2882 |
|
|
try {
|
2883 |
|
|
// Avoid failures from read-only properties
|
2884 |
|
|
defineProperty(targetComponent, key, descriptor);
|
2885 |
|
|
} catch (e) {}
|
2886 |
|
|
}
|
2887 |
|
|
}
|
2888 |
|
|
|
2889 |
|
|
return targetComponent;
|
2890 |
|
|
}
|
2891 |
|
|
|
2892 |
|
|
return targetComponent;
|
2893 |
|
|
}
|
2894 |
|
|
|
2895 |
|
|
var hoistNonReactStatics_cjs = hoistNonReactStatics;
|
2896 |
|
|
|
2897 |
|
|
var createNamedContext = function createNamedContext(name) {
|
2898 |
|
|
var context = index();
|
2899 |
|
|
context.displayName = name;
|
2900 |
|
|
return context;
|
2901 |
|
|
};
|
2902 |
|
|
|
2903 |
|
|
var context =
|
2904 |
|
|
/*#__PURE__*/
|
2905 |
|
|
createNamedContext("Router");
|
2906 |
|
|
/**
|
2907 |
|
|
* The public API for putting history on context.
|
2908 |
|
|
*/
|
2909 |
|
|
|
2910 |
|
|
var Router =
|
2911 |
|
|
/*#__PURE__*/
|
2912 |
|
|
function (_React$Component) {
|
2913 |
|
|
_inheritsLoose(Router, _React$Component);
|
2914 |
|
|
|
2915 |
|
|
Router.computeRootMatch = function computeRootMatch(pathname) {
|
2916 |
|
|
return {
|
2917 |
|
|
path: "/",
|
2918 |
|
|
url: "/",
|
2919 |
|
|
params: {},
|
2920 |
|
|
isExact: pathname === "/"
|
2921 |
|
|
};
|
2922 |
|
|
};
|
2923 |
|
|
|
2924 |
|
|
function Router(props) {
|
2925 |
|
|
var _this;
|
2926 |
|
|
|
2927 |
|
|
_this = _React$Component.call(this, props) || this;
|
2928 |
|
|
_this.state = {
|
2929 |
|
|
location: props.history.location
|
2930 |
|
|
}; // This is a bit of a hack. We have to start listening for location
|
2931 |
|
|
// changes here in the constructor in case there are any <Redirect>s
|
2932 |
|
|
// on the initial render. If there are, they will replace/push when
|
2933 |
|
|
// they mount and since cDM fires in children before parents, we may
|
2934 |
|
|
// get a new location before the <Router> is mounted.
|
2935 |
|
|
|
2936 |
|
|
_this._isMounted = false;
|
2937 |
|
|
_this._pendingLocation = null;
|
2938 |
|
|
|
2939 |
|
|
if (!props.staticContext) {
|
2940 |
|
|
_this.unlisten = props.history.listen(function (location) {
|
2941 |
|
|
if (_this._isMounted) {
|
2942 |
|
|
_this.setState({
|
2943 |
|
|
location: location
|
2944 |
|
|
});
|
2945 |
|
|
} else {
|
2946 |
|
|
_this._pendingLocation = location;
|
2947 |
|
|
}
|
2948 |
|
|
});
|
2949 |
|
|
}
|
2950 |
|
|
|
2951 |
|
|
return _this;
|
2952 |
|
|
}
|
2953 |
|
|
|
2954 |
|
|
var _proto = Router.prototype;
|
2955 |
|
|
|
2956 |
|
|
_proto.componentDidMount = function componentDidMount() {
|
2957 |
|
|
this._isMounted = true;
|
2958 |
|
|
|
2959 |
|
|
if (this._pendingLocation) {
|
2960 |
|
|
this.setState({
|
2961 |
|
|
location: this._pendingLocation
|
2962 |
|
|
});
|
2963 |
|
|
}
|
2964 |
|
|
};
|
2965 |
|
|
|
2966 |
|
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
2967 |
|
|
if (this.unlisten) this.unlisten();
|
2968 |
|
|
};
|
2969 |
|
|
|
2970 |
|
|
_proto.render = function render() {
|
2971 |
|
|
return React__default.createElement(context.Provider, {
|
2972 |
|
|
children: this.props.children || null,
|
2973 |
|
|
value: {
|
2974 |
|
|
history: this.props.history,
|
2975 |
|
|
location: this.state.location,
|
2976 |
|
|
match: Router.computeRootMatch(this.state.location.pathname),
|
2977 |
|
|
staticContext: this.props.staticContext
|
2978 |
|
|
}
|
2979 |
|
|
});
|
2980 |
|
|
};
|
2981 |
|
|
|
2982 |
|
|
return Router;
|
2983 |
|
|
}(React__default.Component);
|
2984 |
|
|
|
2985 |
|
|
{
|
2986 |
|
|
Router.propTypes = {
|
2987 |
|
|
children: propTypes.node,
|
2988 |
|
|
history: propTypes.object.isRequired,
|
2989 |
|
|
staticContext: propTypes.object
|
2990 |
|
|
};
|
2991 |
|
|
|
2992 |
|
|
Router.prototype.componentDidUpdate = function (prevProps) {
|
2993 |
|
|
warning(prevProps.history === this.props.history, "You cannot change <Router history>") ;
|
2994 |
|
|
};
|
2995 |
|
|
}
|
2996 |
|
|
/**
|
2997 |
|
|
* The public API for a <Router> that stores location in memory.
|
2998 |
|
|
*/
|
2999 |
|
|
|
3000 |
|
|
|
3001 |
|
|
var MemoryRouter =
|
3002 |
|
|
/*#__PURE__*/
|
3003 |
|
|
function (_React$Component) {
|
3004 |
|
|
_inheritsLoose(MemoryRouter, _React$Component);
|
3005 |
|
|
|
3006 |
|
|
function MemoryRouter() {
|
3007 |
|
|
var _this;
|
3008 |
|
|
|
3009 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3010 |
|
|
args[_key] = arguments[_key];
|
3011 |
|
|
}
|
3012 |
|
|
|
3013 |
|
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
3014 |
|
|
_this.history = createMemoryHistory(_this.props);
|
3015 |
|
|
return _this;
|
3016 |
|
|
}
|
3017 |
|
|
|
3018 |
|
|
var _proto = MemoryRouter.prototype;
|
3019 |
|
|
|
3020 |
|
|
_proto.render = function render() {
|
3021 |
|
|
return React__default.createElement(Router, {
|
3022 |
|
|
history: this.history,
|
3023 |
|
|
children: this.props.children
|
3024 |
|
|
});
|
3025 |
|
|
};
|
3026 |
|
|
|
3027 |
|
|
return MemoryRouter;
|
3028 |
|
|
}(React__default.Component);
|
3029 |
|
|
|
3030 |
|
|
{
|
3031 |
|
|
MemoryRouter.propTypes = {
|
3032 |
|
|
initialEntries: propTypes.array,
|
3033 |
|
|
initialIndex: propTypes.number,
|
3034 |
|
|
getUserConfirmation: propTypes.func,
|
3035 |
|
|
keyLength: propTypes.number,
|
3036 |
|
|
children: propTypes.node
|
3037 |
|
|
};
|
3038 |
|
|
|
3039 |
|
|
MemoryRouter.prototype.componentDidMount = function () {
|
3040 |
|
|
warning(!this.props.history, "<MemoryRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { MemoryRouter as Router }`.") ;
|
3041 |
|
|
};
|
3042 |
|
|
}
|
3043 |
|
|
|
3044 |
|
|
var Lifecycle =
|
3045 |
|
|
/*#__PURE__*/
|
3046 |
|
|
function (_React$Component) {
|
3047 |
|
|
_inheritsLoose(Lifecycle, _React$Component);
|
3048 |
|
|
|
3049 |
|
|
function Lifecycle() {
|
3050 |
|
|
return _React$Component.apply(this, arguments) || this;
|
3051 |
|
|
}
|
3052 |
|
|
|
3053 |
|
|
var _proto = Lifecycle.prototype;
|
3054 |
|
|
|
3055 |
|
|
_proto.componentDidMount = function componentDidMount() {
|
3056 |
|
|
if (this.props.onMount) this.props.onMount.call(this, this);
|
3057 |
|
|
};
|
3058 |
|
|
|
3059 |
|
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
3060 |
|
|
if (this.props.onUpdate) this.props.onUpdate.call(this, this, prevProps);
|
3061 |
|
|
};
|
3062 |
|
|
|
3063 |
|
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
3064 |
|
|
if (this.props.onUnmount) this.props.onUnmount.call(this, this);
|
3065 |
|
|
};
|
3066 |
|
|
|
3067 |
|
|
_proto.render = function render() {
|
3068 |
|
|
return null;
|
3069 |
|
|
};
|
3070 |
|
|
|
3071 |
|
|
return Lifecycle;
|
3072 |
|
|
}(React__default.Component);
|
3073 |
|
|
/**
|
3074 |
|
|
* The public API for prompting the user before navigating away from a screen.
|
3075 |
|
|
*/
|
3076 |
|
|
|
3077 |
|
|
|
3078 |
|
|
function Prompt(_ref) {
|
3079 |
|
|
var message = _ref.message,
|
3080 |
|
|
_ref$when = _ref.when,
|
3081 |
|
|
when = _ref$when === void 0 ? true : _ref$when;
|
3082 |
|
|
return React__default.createElement(context.Consumer, null, function (context) {
|
3083 |
|
|
!context ? invariant(false, "You should not use <Prompt> outside a <Router>") : void 0;
|
3084 |
|
|
if (!when || context.staticContext) return null;
|
3085 |
|
|
var method = context.history.block;
|
3086 |
|
|
return React__default.createElement(Lifecycle, {
|
3087 |
|
|
onMount: function onMount(self) {
|
3088 |
|
|
self.release = method(message);
|
3089 |
|
|
},
|
3090 |
|
|
onUpdate: function onUpdate(self, prevProps) {
|
3091 |
|
|
if (prevProps.message !== message) {
|
3092 |
|
|
self.release();
|
3093 |
|
|
self.release = method(message);
|
3094 |
|
|
}
|
3095 |
|
|
},
|
3096 |
|
|
onUnmount: function onUnmount(self) {
|
3097 |
|
|
self.release();
|
3098 |
|
|
},
|
3099 |
|
|
message: message
|
3100 |
|
|
});
|
3101 |
|
|
});
|
3102 |
|
|
}
|
3103 |
|
|
|
3104 |
|
|
{
|
3105 |
|
|
var messageType = propTypes.oneOfType([propTypes.func, propTypes.string]);
|
3106 |
|
|
Prompt.propTypes = {
|
3107 |
|
|
when: propTypes.bool,
|
3108 |
|
|
message: messageType.isRequired
|
3109 |
|
|
};
|
3110 |
|
|
}
|
3111 |
|
|
|
3112 |
|
|
var cache = {};
|
3113 |
|
|
var cacheLimit = 10000;
|
3114 |
|
|
var cacheCount = 0;
|
3115 |
|
|
|
3116 |
|
|
function compilePath(path) {
|
3117 |
|
|
if (cache[path]) return cache[path];
|
3118 |
|
|
var generator = pathToRegexp_1.compile(path);
|
3119 |
|
|
|
3120 |
|
|
if (cacheCount < cacheLimit) {
|
3121 |
|
|
cache[path] = generator;
|
3122 |
|
|
cacheCount++;
|
3123 |
|
|
}
|
3124 |
|
|
|
3125 |
|
|
return generator;
|
3126 |
|
|
}
|
3127 |
|
|
/**
|
3128 |
|
|
* Public API for generating a URL pathname from a path and parameters.
|
3129 |
|
|
*/
|
3130 |
|
|
|
3131 |
|
|
|
3132 |
|
|
function generatePath(path, params) {
|
3133 |
|
|
if (path === void 0) {
|
3134 |
|
|
path = "/";
|
3135 |
|
|
}
|
3136 |
|
|
|
3137 |
|
|
if (params === void 0) {
|
3138 |
|
|
params = {};
|
3139 |
|
|
}
|
3140 |
|
|
|
3141 |
|
|
return path === "/" ? path : compilePath(path)(params, {
|
3142 |
|
|
pretty: true
|
3143 |
|
|
});
|
3144 |
|
|
}
|
3145 |
|
|
/**
|
3146 |
|
|
* The public API for navigating programmatically with a component.
|
3147 |
|
|
*/
|
3148 |
|
|
|
3149 |
|
|
|
3150 |
|
|
function Redirect(_ref) {
|
3151 |
|
|
var computedMatch = _ref.computedMatch,
|
3152 |
|
|
to = _ref.to,
|
3153 |
|
|
_ref$push = _ref.push,
|
3154 |
|
|
push = _ref$push === void 0 ? false : _ref$push;
|
3155 |
|
|
return React__default.createElement(context.Consumer, null, function (context) {
|
3156 |
|
|
!context ? invariant(false, "You should not use <Redirect> outside a <Router>") : void 0;
|
3157 |
|
|
var history = context.history,
|
3158 |
|
|
staticContext = context.staticContext;
|
3159 |
|
|
var method = push ? history.push : history.replace;
|
3160 |
|
|
var location = createLocation(computedMatch ? typeof to === "string" ? generatePath(to, computedMatch.params) : _extends({}, to, {
|
3161 |
|
|
pathname: generatePath(to.pathname, computedMatch.params)
|
3162 |
|
|
}) : to); // When rendering in a static context,
|
3163 |
|
|
// set the new location immediately.
|
3164 |
|
|
|
3165 |
|
|
if (staticContext) {
|
3166 |
|
|
method(location);
|
3167 |
|
|
return null;
|
3168 |
|
|
}
|
3169 |
|
|
|
3170 |
|
|
return React__default.createElement(Lifecycle, {
|
3171 |
|
|
onMount: function onMount() {
|
3172 |
|
|
method(location);
|
3173 |
|
|
},
|
3174 |
|
|
onUpdate: function onUpdate(self, prevProps) {
|
3175 |
|
|
var prevLocation = createLocation(prevProps.to);
|
3176 |
|
|
|
3177 |
|
|
if (!locationsAreEqual(prevLocation, _extends({}, location, {
|
3178 |
|
|
key: prevLocation.key
|
3179 |
|
|
}))) {
|
3180 |
|
|
method(location);
|
3181 |
|
|
}
|
3182 |
|
|
},
|
3183 |
|
|
to: to
|
3184 |
|
|
});
|
3185 |
|
|
});
|
3186 |
|
|
}
|
3187 |
|
|
|
3188 |
|
|
{
|
3189 |
|
|
Redirect.propTypes = {
|
3190 |
|
|
push: propTypes.bool,
|
3191 |
|
|
from: propTypes.string,
|
3192 |
|
|
to: propTypes.oneOfType([propTypes.string, propTypes.object]).isRequired
|
3193 |
|
|
};
|
3194 |
|
|
}
|
3195 |
|
|
|
3196 |
|
|
var cache$1 = {};
|
3197 |
|
|
var cacheLimit$1 = 10000;
|
3198 |
|
|
var cacheCount$1 = 0;
|
3199 |
|
|
|
3200 |
|
|
function compilePath$1(path, options) {
|
3201 |
|
|
var cacheKey = "" + options.end + options.strict + options.sensitive;
|
3202 |
|
|
var pathCache = cache$1[cacheKey] || (cache$1[cacheKey] = {});
|
3203 |
|
|
if (pathCache[path]) return pathCache[path];
|
3204 |
|
|
var keys = [];
|
3205 |
|
|
var regexp = pathToRegexp_1(path, keys, options);
|
3206 |
|
|
var result = {
|
3207 |
|
|
regexp: regexp,
|
3208 |
|
|
keys: keys
|
3209 |
|
|
};
|
3210 |
|
|
|
3211 |
|
|
if (cacheCount$1 < cacheLimit$1) {
|
3212 |
|
|
pathCache[path] = result;
|
3213 |
|
|
cacheCount$1++;
|
3214 |
|
|
}
|
3215 |
|
|
|
3216 |
|
|
return result;
|
3217 |
|
|
}
|
3218 |
|
|
/**
|
3219 |
|
|
* Public API for matching a URL pathname to a path.
|
3220 |
|
|
*/
|
3221 |
|
|
|
3222 |
|
|
|
3223 |
|
|
function matchPath(pathname, options) {
|
3224 |
|
|
if (options === void 0) {
|
3225 |
|
|
options = {};
|
3226 |
|
|
}
|
3227 |
|
|
|
3228 |
|
|
if (typeof options === "string" || Array.isArray(options)) {
|
3229 |
|
|
options = {
|
3230 |
|
|
path: options
|
3231 |
|
|
};
|
3232 |
|
|
}
|
3233 |
|
|
|
3234 |
|
|
var _options = options,
|
3235 |
|
|
path = _options.path,
|
3236 |
|
|
_options$exact = _options.exact,
|
3237 |
|
|
exact = _options$exact === void 0 ? false : _options$exact,
|
3238 |
|
|
_options$strict = _options.strict,
|
3239 |
|
|
strict = _options$strict === void 0 ? false : _options$strict,
|
3240 |
|
|
_options$sensitive = _options.sensitive,
|
3241 |
|
|
sensitive = _options$sensitive === void 0 ? false : _options$sensitive;
|
3242 |
|
|
var paths = [].concat(path);
|
3243 |
|
|
return paths.reduce(function (matched, path) {
|
3244 |
|
|
if (!path && path !== "") return null;
|
3245 |
|
|
if (matched) return matched;
|
3246 |
|
|
|
3247 |
|
|
var _compilePath = compilePath$1(path, {
|
3248 |
|
|
end: exact,
|
3249 |
|
|
strict: strict,
|
3250 |
|
|
sensitive: sensitive
|
3251 |
|
|
}),
|
3252 |
|
|
regexp = _compilePath.regexp,
|
3253 |
|
|
keys = _compilePath.keys;
|
3254 |
|
|
|
3255 |
|
|
var match = regexp.exec(pathname);
|
3256 |
|
|
if (!match) return null;
|
3257 |
|
|
var url = match[0],
|
3258 |
|
|
values = match.slice(1);
|
3259 |
|
|
var isExact = pathname === url;
|
3260 |
|
|
if (exact && !isExact) return null;
|
3261 |
|
|
return {
|
3262 |
|
|
path: path,
|
3263 |
|
|
// the path used to match
|
3264 |
|
|
url: path === "/" && url === "" ? "/" : url,
|
3265 |
|
|
// the matched portion of the URL
|
3266 |
|
|
isExact: isExact,
|
3267 |
|
|
// whether or not we matched exactly
|
3268 |
|
|
params: keys.reduce(function (memo, key, index) {
|
3269 |
|
|
memo[key.name] = values[index];
|
3270 |
|
|
return memo;
|
3271 |
|
|
}, {})
|
3272 |
|
|
};
|
3273 |
|
|
}, null);
|
3274 |
|
|
}
|
3275 |
|
|
|
3276 |
|
|
function isEmptyChildren(children) {
|
3277 |
|
|
return React__default.Children.count(children) === 0;
|
3278 |
|
|
}
|
3279 |
|
|
|
3280 |
|
|
function evalChildrenDev(children, props, path) {
|
3281 |
|
|
var value = children(props);
|
3282 |
|
|
warning(value !== undefined, "You returned `undefined` from the `children` function of " + ("<Route" + (path ? " path=\"" + path + "\"" : "") + ">, but you ") + "should have returned a React element or `null`") ;
|
3283 |
|
|
return value || null;
|
3284 |
|
|
}
|
3285 |
|
|
/**
|
3286 |
|
|
* The public API for matching a single path and rendering.
|
3287 |
|
|
*/
|
3288 |
|
|
|
3289 |
|
|
|
3290 |
|
|
var Route =
|
3291 |
|
|
/*#__PURE__*/
|
3292 |
|
|
function (_React$Component) {
|
3293 |
|
|
_inheritsLoose(Route, _React$Component);
|
3294 |
|
|
|
3295 |
|
|
function Route() {
|
3296 |
|
|
return _React$Component.apply(this, arguments) || this;
|
3297 |
|
|
}
|
3298 |
|
|
|
3299 |
|
|
var _proto = Route.prototype;
|
3300 |
|
|
|
3301 |
|
|
_proto.render = function render() {
|
3302 |
|
|
var _this = this;
|
3303 |
|
|
|
3304 |
|
|
return React__default.createElement(context.Consumer, null, function (context$1) {
|
3305 |
|
|
!context$1 ? invariant(false, "You should not use <Route> outside a <Router>") : void 0;
|
3306 |
|
|
var location = _this.props.location || context$1.location;
|
3307 |
|
|
var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
|
3308 |
|
|
: _this.props.path ? matchPath(location.pathname, _this.props) : context$1.match;
|
3309 |
|
|
|
3310 |
|
|
var props = _extends({}, context$1, {
|
3311 |
|
|
location: location,
|
3312 |
|
|
match: match
|
3313 |
|
|
});
|
3314 |
|
|
|
3315 |
|
|
var _this$props = _this.props,
|
3316 |
|
|
children = _this$props.children,
|
3317 |
|
|
component = _this$props.component,
|
3318 |
|
|
render = _this$props.render; // Preact uses an empty array as children by
|
3319 |
|
|
// default, so use null if that's the case.
|
3320 |
|
|
|
3321 |
|
|
if (Array.isArray(children) && children.length === 0) {
|
3322 |
|
|
children = null;
|
3323 |
|
|
}
|
3324 |
|
|
|
3325 |
|
|
return React__default.createElement(context.Provider, {
|
3326 |
|
|
value: props
|
3327 |
|
|
}, props.match ? children ? typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : children : component ? React__default.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : null);
|
3328 |
|
|
});
|
3329 |
|
|
};
|
3330 |
|
|
|
3331 |
|
|
return Route;
|
3332 |
|
|
}(React__default.Component);
|
3333 |
|
|
|
3334 |
|
|
{
|
3335 |
|
|
Route.propTypes = {
|
3336 |
|
|
children: propTypes.oneOfType([propTypes.func, propTypes.node]),
|
3337 |
|
|
component: function component(props, propName) {
|
3338 |
|
|
if (props[propName] && !reactIs_1(props[propName])) {
|
3339 |
|
|
return new Error("Invalid prop 'component' supplied to 'Route': the prop is not a valid React component");
|
3340 |
|
|
}
|
3341 |
|
|
},
|
3342 |
|
|
exact: propTypes.bool,
|
3343 |
|
|
location: propTypes.object,
|
3344 |
|
|
path: propTypes.oneOfType([propTypes.string, propTypes.arrayOf(propTypes.string)]),
|
3345 |
|
|
render: propTypes.func,
|
3346 |
|
|
sensitive: propTypes.bool,
|
3347 |
|
|
strict: propTypes.bool
|
3348 |
|
|
};
|
3349 |
|
|
|
3350 |
|
|
Route.prototype.componentDidMount = function () {
|
3351 |
|
|
warning(!(this.props.children && !isEmptyChildren(this.props.children) && this.props.component), "You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored") ;
|
3352 |
|
|
warning(!(this.props.children && !isEmptyChildren(this.props.children) && this.props.render), "You should not use <Route render> and <Route children> in the same route; <Route render> will be ignored") ;
|
3353 |
|
|
warning(!(this.props.component && this.props.render), "You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored") ;
|
3354 |
|
|
};
|
3355 |
|
|
|
3356 |
|
|
Route.prototype.componentDidUpdate = function (prevProps) {
|
3357 |
|
|
warning(!(this.props.location && !prevProps.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.') ;
|
3358 |
|
|
warning(!(!this.props.location && prevProps.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.') ;
|
3359 |
|
|
};
|
3360 |
|
|
}
|
3361 |
|
|
|
3362 |
|
|
function addLeadingSlash$1(path) {
|
3363 |
|
|
return path.charAt(0) === "/" ? path : "/" + path;
|
3364 |
|
|
}
|
3365 |
|
|
|
3366 |
|
|
function addBasename(basename, location) {
|
3367 |
|
|
if (!basename) return location;
|
3368 |
|
|
return _extends({}, location, {
|
3369 |
|
|
pathname: addLeadingSlash$1(basename) + location.pathname
|
3370 |
|
|
});
|
3371 |
|
|
}
|
3372 |
|
|
|
3373 |
|
|
function stripBasename$1(basename, location) {
|
3374 |
|
|
if (!basename) return location;
|
3375 |
|
|
var base = addLeadingSlash$1(basename);
|
3376 |
|
|
if (location.pathname.indexOf(base) !== 0) return location;
|
3377 |
|
|
return _extends({}, location, {
|
3378 |
|
|
pathname: location.pathname.substr(base.length)
|
3379 |
|
|
});
|
3380 |
|
|
}
|
3381 |
|
|
|
3382 |
|
|
function createURL(location) {
|
3383 |
|
|
return typeof location === "string" ? location : createPath(location);
|
3384 |
|
|
}
|
3385 |
|
|
|
3386 |
|
|
function staticHandler(methodName) {
|
3387 |
|
|
return function () {
|
3388 |
|
|
invariant(false, "You cannot %s with <StaticRouter>") ;
|
3389 |
|
|
};
|
3390 |
|
|
}
|
3391 |
|
|
|
3392 |
|
|
function noop() {}
|
3393 |
|
|
/**
|
3394 |
|
|
* The public top-level API for a "static" <Router>, so-called because it
|
3395 |
|
|
* can't actually change the current location. Instead, it just records
|
3396 |
|
|
* location changes in a context object. Useful mainly in testing and
|
3397 |
|
|
* server-rendering scenarios.
|
3398 |
|
|
*/
|
3399 |
|
|
|
3400 |
|
|
|
3401 |
|
|
var StaticRouter =
|
3402 |
|
|
/*#__PURE__*/
|
3403 |
|
|
function (_React$Component) {
|
3404 |
|
|
_inheritsLoose(StaticRouter, _React$Component);
|
3405 |
|
|
|
3406 |
|
|
function StaticRouter() {
|
3407 |
|
|
var _this;
|
3408 |
|
|
|
3409 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3410 |
|
|
args[_key] = arguments[_key];
|
3411 |
|
|
}
|
3412 |
|
|
|
3413 |
|
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
3414 |
|
|
|
3415 |
|
|
_this.handlePush = function (location) {
|
3416 |
|
|
return _this.navigateTo(location, "PUSH");
|
3417 |
|
|
};
|
3418 |
|
|
|
3419 |
|
|
_this.handleReplace = function (location) {
|
3420 |
|
|
return _this.navigateTo(location, "REPLACE");
|
3421 |
|
|
};
|
3422 |
|
|
|
3423 |
|
|
_this.handleListen = function () {
|
3424 |
|
|
return noop;
|
3425 |
|
|
};
|
3426 |
|
|
|
3427 |
|
|
_this.handleBlock = function () {
|
3428 |
|
|
return noop;
|
3429 |
|
|
};
|
3430 |
|
|
|
3431 |
|
|
return _this;
|
3432 |
|
|
}
|
3433 |
|
|
|
3434 |
|
|
var _proto = StaticRouter.prototype;
|
3435 |
|
|
|
3436 |
|
|
_proto.navigateTo = function navigateTo(location, action) {
|
3437 |
|
|
var _this$props = this.props,
|
3438 |
|
|
_this$props$basename = _this$props.basename,
|
3439 |
|
|
basename = _this$props$basename === void 0 ? "" : _this$props$basename,
|
3440 |
|
|
_this$props$context = _this$props.context,
|
3441 |
|
|
context = _this$props$context === void 0 ? {} : _this$props$context;
|
3442 |
|
|
context.action = action;
|
3443 |
|
|
context.location = addBasename(basename, createLocation(location));
|
3444 |
|
|
context.url = createURL(context.location);
|
3445 |
|
|
};
|
3446 |
|
|
|
3447 |
|
|
_proto.render = function render() {
|
3448 |
|
|
var _this$props2 = this.props,
|
3449 |
|
|
_this$props2$basename = _this$props2.basename,
|
3450 |
|
|
basename = _this$props2$basename === void 0 ? "" : _this$props2$basename,
|
3451 |
|
|
_this$props2$context = _this$props2.context,
|
3452 |
|
|
context = _this$props2$context === void 0 ? {} : _this$props2$context,
|
3453 |
|
|
_this$props2$location = _this$props2.location,
|
3454 |
|
|
location = _this$props2$location === void 0 ? "/" : _this$props2$location,
|
3455 |
|
|
rest = _objectWithoutPropertiesLoose(_this$props2, ["basename", "context", "location"]);
|
3456 |
|
|
|
3457 |
|
|
var history = {
|
3458 |
|
|
createHref: function createHref(path) {
|
3459 |
|
|
return addLeadingSlash$1(basename + createURL(path));
|
3460 |
|
|
},
|
3461 |
|
|
action: "POP",
|
3462 |
|
|
location: stripBasename$1(basename, createLocation(location)),
|
3463 |
|
|
push: this.handlePush,
|
3464 |
|
|
replace: this.handleReplace,
|
3465 |
|
|
go: staticHandler(),
|
3466 |
|
|
goBack: staticHandler(),
|
3467 |
|
|
goForward: staticHandler(),
|
3468 |
|
|
listen: this.handleListen,
|
3469 |
|
|
block: this.handleBlock
|
3470 |
|
|
};
|
3471 |
|
|
return React__default.createElement(Router, _extends({}, rest, {
|
3472 |
|
|
history: history,
|
3473 |
|
|
staticContext: context
|
3474 |
|
|
}));
|
3475 |
|
|
};
|
3476 |
|
|
|
3477 |
|
|
return StaticRouter;
|
3478 |
|
|
}(React__default.Component);
|
3479 |
|
|
|
3480 |
|
|
{
|
3481 |
|
|
StaticRouter.propTypes = {
|
3482 |
|
|
basename: propTypes.string,
|
3483 |
|
|
context: propTypes.object,
|
3484 |
|
|
location: propTypes.oneOfType([propTypes.string, propTypes.object])
|
3485 |
|
|
};
|
3486 |
|
|
|
3487 |
|
|
StaticRouter.prototype.componentDidMount = function () {
|
3488 |
|
|
warning(!this.props.history, "<StaticRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { StaticRouter as Router }`.") ;
|
3489 |
|
|
};
|
3490 |
|
|
}
|
3491 |
|
|
/**
|
3492 |
|
|
* The public API for rendering the first <Route> that matches.
|
3493 |
|
|
*/
|
3494 |
|
|
|
3495 |
|
|
|
3496 |
|
|
var Switch =
|
3497 |
|
|
/*#__PURE__*/
|
3498 |
|
|
function (_React$Component) {
|
3499 |
|
|
_inheritsLoose(Switch, _React$Component);
|
3500 |
|
|
|
3501 |
|
|
function Switch() {
|
3502 |
|
|
return _React$Component.apply(this, arguments) || this;
|
3503 |
|
|
}
|
3504 |
|
|
|
3505 |
|
|
var _proto = Switch.prototype;
|
3506 |
|
|
|
3507 |
|
|
_proto.render = function render() {
|
3508 |
|
|
var _this = this;
|
3509 |
|
|
|
3510 |
|
|
return React__default.createElement(context.Consumer, null, function (context) {
|
3511 |
|
|
!context ? invariant(false, "You should not use <Switch> outside a <Router>") : void 0;
|
3512 |
|
|
var location = _this.props.location || context.location;
|
3513 |
|
|
var element, match; // We use React.Children.forEach instead of React.Children.toArray().find()
|
3514 |
|
|
// here because toArray adds keys to all child elements and we do not want
|
3515 |
|
|
// to trigger an unmount/remount for two <Route>s that render the same
|
3516 |
|
|
// component at different URLs.
|
3517 |
|
|
|
3518 |
|
|
React__default.Children.forEach(_this.props.children, function (child) {
|
3519 |
|
|
if (match == null && React__default.isValidElement(child)) {
|
3520 |
|
|
element = child;
|
3521 |
|
|
var path = child.props.path || child.props.from;
|
3522 |
|
|
match = path ? matchPath(location.pathname, _extends({}, child.props, {
|
3523 |
|
|
path: path
|
3524 |
|
|
})) : context.match;
|
3525 |
|
|
}
|
3526 |
|
|
});
|
3527 |
|
|
return match ? React__default.cloneElement(element, {
|
3528 |
|
|
location: location,
|
3529 |
|
|
computedMatch: match
|
3530 |
|
|
}) : null;
|
3531 |
|
|
});
|
3532 |
|
|
};
|
3533 |
|
|
|
3534 |
|
|
return Switch;
|
3535 |
|
|
}(React__default.Component);
|
3536 |
|
|
|
3537 |
|
|
{
|
3538 |
|
|
Switch.propTypes = {
|
3539 |
|
|
children: propTypes.node,
|
3540 |
|
|
location: propTypes.object
|
3541 |
|
|
};
|
3542 |
|
|
|
3543 |
|
|
Switch.prototype.componentDidUpdate = function (prevProps) {
|
3544 |
|
|
warning(!(this.props.location && !prevProps.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.') ;
|
3545 |
|
|
warning(!(!this.props.location && prevProps.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.') ;
|
3546 |
|
|
};
|
3547 |
|
|
}
|
3548 |
|
|
/**
|
3549 |
|
|
* A public higher-order component to access the imperative API
|
3550 |
|
|
*/
|
3551 |
|
|
|
3552 |
|
|
|
3553 |
|
|
function withRouter(Component) {
|
3554 |
|
|
var displayName = "withRouter(" + (Component.displayName || Component.name) + ")";
|
3555 |
|
|
|
3556 |
|
|
var C = function C(props) {
|
3557 |
|
|
var wrappedComponentRef = props.wrappedComponentRef,
|
3558 |
|
|
remainingProps = _objectWithoutPropertiesLoose(props, ["wrappedComponentRef"]);
|
3559 |
|
|
|
3560 |
|
|
return React__default.createElement(context.Consumer, null, function (context) {
|
3561 |
|
|
!context ? invariant(false, "You should not use <" + displayName + " /> outside a <Router>") : void 0;
|
3562 |
|
|
return React__default.createElement(Component, _extends({}, remainingProps, context, {
|
3563 |
|
|
ref: wrappedComponentRef
|
3564 |
|
|
}));
|
3565 |
|
|
});
|
3566 |
|
|
};
|
3567 |
|
|
|
3568 |
|
|
C.displayName = displayName;
|
3569 |
|
|
C.WrappedComponent = Component;
|
3570 |
|
|
|
3571 |
|
|
{
|
3572 |
|
|
C.propTypes = {
|
3573 |
|
|
wrappedComponentRef: propTypes.oneOfType([propTypes.string, propTypes.func, propTypes.object])
|
3574 |
|
|
};
|
3575 |
|
|
}
|
3576 |
|
|
|
3577 |
|
|
return hoistNonReactStatics_cjs(C, Component);
|
3578 |
|
|
}
|
3579 |
|
|
|
3580 |
|
|
var useContext = React__default.useContext;
|
3581 |
|
|
|
3582 |
|
|
function useHistory() {
|
3583 |
|
|
{
|
3584 |
|
|
!(typeof useContext === "function") ? invariant(false, "You must use React >= 16.8 in order to use useHistory()") : void 0;
|
3585 |
|
|
}
|
3586 |
|
|
|
3587 |
|
|
return useContext(context).history;
|
3588 |
|
|
}
|
3589 |
|
|
|
3590 |
|
|
function useLocation() {
|
3591 |
|
|
{
|
3592 |
|
|
!(typeof useContext === "function") ? invariant(false, "You must use React >= 16.8 in order to use useLocation()") : void 0;
|
3593 |
|
|
}
|
3594 |
|
|
|
3595 |
|
|
return useContext(context).location;
|
3596 |
|
|
}
|
3597 |
|
|
|
3598 |
|
|
function useParams() {
|
3599 |
|
|
{
|
3600 |
|
|
!(typeof useContext === "function") ? invariant(false, "You must use React >= 16.8 in order to use useParams()") : void 0;
|
3601 |
|
|
}
|
3602 |
|
|
|
3603 |
|
|
var match = useContext(context).match;
|
3604 |
|
|
return match ? match.params : {};
|
3605 |
|
|
}
|
3606 |
|
|
|
3607 |
|
|
function useRouteMatch(path) {
|
3608 |
|
|
{
|
3609 |
|
|
!(typeof useContext === "function") ? invariant(false, "You must use React >= 16.8 in order to use useRouteMatch()") : void 0;
|
3610 |
|
|
}
|
3611 |
|
|
|
3612 |
|
|
return path ? matchPath(useLocation().pathname, path) : useContext(context).match;
|
3613 |
|
|
}
|
3614 |
|
|
|
3615 |
|
|
{
|
3616 |
|
|
if (typeof window !== "undefined") {
|
3617 |
|
|
var global$1 = window;
|
3618 |
|
|
var key$1 = "__react_router_build__";
|
3619 |
|
|
var buildNames = {
|
3620 |
|
|
cjs: "CommonJS",
|
3621 |
|
|
esm: "ES modules",
|
3622 |
|
|
umd: "UMD"
|
3623 |
|
|
};
|
3624 |
|
|
|
3625 |
|
|
if (global$1[key$1] && global$1[key$1] !== "esm") {
|
3626 |
|
|
var initialBuildName = buildNames[global$1[key$1]];
|
3627 |
|
|
var secondaryBuildName = buildNames["esm"]; // TODO: Add link to article that explains in detail how to avoid
|
3628 |
|
|
// loading 2 different builds.
|
3629 |
|
|
|
3630 |
|
|
throw new Error("You are loading the " + secondaryBuildName + " build of React Router " + ("on a page that is already running the " + initialBuildName + " ") + "build, so things won't work right.");
|
3631 |
|
|
}
|
3632 |
|
|
|
3633 |
|
|
global$1[key$1] = "esm";
|
3634 |
|
|
}
|
3635 |
|
|
}
|
3636 |
|
|
|
3637 |
|
|
/**
|
3638 |
|
|
* The public API for a <Router> that uses HTML5 history.
|
3639 |
|
|
*/
|
3640 |
|
|
|
3641 |
|
|
var BrowserRouter =
|
3642 |
|
|
/*#__PURE__*/
|
3643 |
|
|
function (_React$Component) {
|
3644 |
|
|
_inheritsLoose(BrowserRouter, _React$Component);
|
3645 |
|
|
|
3646 |
|
|
function BrowserRouter() {
|
3647 |
|
|
var _this;
|
3648 |
|
|
|
3649 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3650 |
|
|
args[_key] = arguments[_key];
|
3651 |
|
|
}
|
3652 |
|
|
|
3653 |
|
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
3654 |
|
|
_this.history = createBrowserHistory(_this.props);
|
3655 |
|
|
return _this;
|
3656 |
|
|
}
|
3657 |
|
|
|
3658 |
|
|
var _proto = BrowserRouter.prototype;
|
3659 |
|
|
|
3660 |
|
|
_proto.render = function render() {
|
3661 |
|
|
return React__default.createElement(Router, {
|
3662 |
|
|
history: this.history,
|
3663 |
|
|
children: this.props.children
|
3664 |
|
|
});
|
3665 |
|
|
};
|
3666 |
|
|
|
3667 |
|
|
return BrowserRouter;
|
3668 |
|
|
}(React__default.Component);
|
3669 |
|
|
|
3670 |
|
|
{
|
3671 |
|
|
BrowserRouter.propTypes = {
|
3672 |
|
|
basename: propTypes.string,
|
3673 |
|
|
children: propTypes.node,
|
3674 |
|
|
forceRefresh: propTypes.bool,
|
3675 |
|
|
getUserConfirmation: propTypes.func,
|
3676 |
|
|
keyLength: propTypes.number
|
3677 |
|
|
};
|
3678 |
|
|
|
3679 |
|
|
BrowserRouter.prototype.componentDidMount = function () {
|
3680 |
|
|
warning(!this.props.history, "<BrowserRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { BrowserRouter as Router }`.") ;
|
3681 |
|
|
};
|
3682 |
|
|
}
|
3683 |
|
|
|
3684 |
|
|
/**
|
3685 |
|
|
* The public API for a <Router> that uses window.location.hash.
|
3686 |
|
|
*/
|
3687 |
|
|
|
3688 |
|
|
var HashRouter =
|
3689 |
|
|
/*#__PURE__*/
|
3690 |
|
|
function (_React$Component) {
|
3691 |
|
|
_inheritsLoose(HashRouter, _React$Component);
|
3692 |
|
|
|
3693 |
|
|
function HashRouter() {
|
3694 |
|
|
var _this;
|
3695 |
|
|
|
3696 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3697 |
|
|
args[_key] = arguments[_key];
|
3698 |
|
|
}
|
3699 |
|
|
|
3700 |
|
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
3701 |
|
|
_this.history = createHashHistory(_this.props);
|
3702 |
|
|
return _this;
|
3703 |
|
|
}
|
3704 |
|
|
|
3705 |
|
|
var _proto = HashRouter.prototype;
|
3706 |
|
|
|
3707 |
|
|
_proto.render = function render() {
|
3708 |
|
|
return React__default.createElement(Router, {
|
3709 |
|
|
history: this.history,
|
3710 |
|
|
children: this.props.children
|
3711 |
|
|
});
|
3712 |
|
|
};
|
3713 |
|
|
|
3714 |
|
|
return HashRouter;
|
3715 |
|
|
}(React__default.Component);
|
3716 |
|
|
|
3717 |
|
|
{
|
3718 |
|
|
HashRouter.propTypes = {
|
3719 |
|
|
basename: propTypes.string,
|
3720 |
|
|
children: propTypes.node,
|
3721 |
|
|
getUserConfirmation: propTypes.func,
|
3722 |
|
|
hashType: propTypes.oneOf(["hashbang", "noslash", "slash"])
|
3723 |
|
|
};
|
3724 |
|
|
|
3725 |
|
|
HashRouter.prototype.componentDidMount = function () {
|
3726 |
|
|
warning(!this.props.history, "<HashRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { HashRouter as Router }`.") ;
|
3727 |
|
|
};
|
3728 |
|
|
}
|
3729 |
|
|
|
3730 |
|
|
var resolveToLocation = function resolveToLocation(to, currentLocation) {
|
3731 |
|
|
return typeof to === "function" ? to(currentLocation) : to;
|
3732 |
|
|
};
|
3733 |
|
|
var normalizeToLocation = function normalizeToLocation(to, currentLocation) {
|
3734 |
|
|
return typeof to === "string" ? createLocation(to, null, null, currentLocation) : to;
|
3735 |
|
|
};
|
3736 |
|
|
|
3737 |
|
|
var forwardRefShim = function forwardRefShim(C) {
|
3738 |
|
|
return C;
|
3739 |
|
|
};
|
3740 |
|
|
|
3741 |
|
|
var forwardRef = React__default.forwardRef;
|
3742 |
|
|
|
3743 |
|
|
if (typeof forwardRef === "undefined") {
|
3744 |
|
|
forwardRef = forwardRefShim;
|
3745 |
|
|
}
|
3746 |
|
|
|
3747 |
|
|
function isModifiedEvent(event) {
|
3748 |
|
|
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
3749 |
|
|
}
|
3750 |
|
|
|
3751 |
|
|
var LinkAnchor = forwardRef(function (_ref, forwardedRef) {
|
3752 |
|
|
var innerRef = _ref.innerRef,
|
3753 |
|
|
navigate = _ref.navigate,
|
3754 |
|
|
_onClick = _ref.onClick,
|
3755 |
|
|
rest = _objectWithoutPropertiesLoose(_ref, ["innerRef", "navigate", "onClick"]);
|
3756 |
|
|
|
3757 |
|
|
var target = rest.target;
|
3758 |
|
|
|
3759 |
|
|
var props = _extends({}, rest, {
|
3760 |
|
|
onClick: function onClick(event) {
|
3761 |
|
|
try {
|
3762 |
|
|
if (_onClick) _onClick(event);
|
3763 |
|
|
} catch (ex) {
|
3764 |
|
|
event.preventDefault();
|
3765 |
|
|
throw ex;
|
3766 |
|
|
}
|
3767 |
|
|
|
3768 |
|
|
if (!event.defaultPrevented && // onClick prevented default
|
3769 |
|
|
event.button === 0 && ( // ignore everything but left clicks
|
3770 |
|
|
!target || target === "_self") && // let browser handle "target=_blank" etc.
|
3771 |
|
|
!isModifiedEvent(event) // ignore clicks with modifier keys
|
3772 |
|
|
) {
|
3773 |
|
|
event.preventDefault();
|
3774 |
|
|
navigate();
|
3775 |
|
|
}
|
3776 |
|
|
}
|
3777 |
|
|
}); // React 15 compat
|
3778 |
|
|
|
3779 |
|
|
|
3780 |
|
|
if (forwardRefShim !== forwardRef) {
|
3781 |
|
|
props.ref = forwardedRef || innerRef;
|
3782 |
|
|
} else {
|
3783 |
|
|
props.ref = innerRef;
|
3784 |
|
|
}
|
3785 |
|
|
|
3786 |
|
|
return React__default.createElement("a", props);
|
3787 |
|
|
});
|
3788 |
|
|
|
3789 |
|
|
{
|
3790 |
|
|
LinkAnchor.displayName = "LinkAnchor";
|
3791 |
|
|
}
|
3792 |
|
|
/**
|
3793 |
|
|
* The public API for rendering a history-aware <a>.
|
3794 |
|
|
*/
|
3795 |
|
|
|
3796 |
|
|
|
3797 |
|
|
var Link = forwardRef(function (_ref2, forwardedRef) {
|
3798 |
|
|
var _ref2$component = _ref2.component,
|
3799 |
|
|
component = _ref2$component === void 0 ? LinkAnchor : _ref2$component,
|
3800 |
|
|
replace = _ref2.replace,
|
3801 |
|
|
to = _ref2.to,
|
3802 |
|
|
innerRef = _ref2.innerRef,
|
3803 |
|
|
rest = _objectWithoutPropertiesLoose(_ref2, ["component", "replace", "to", "innerRef"]);
|
3804 |
|
|
|
3805 |
|
|
return React__default.createElement(context.Consumer, null, function (context) {
|
3806 |
|
|
!context ? invariant(false, "You should not use <Link> outside a <Router>") : void 0;
|
3807 |
|
|
var history = context.history;
|
3808 |
|
|
var location = normalizeToLocation(resolveToLocation(to, context.location), context.location);
|
3809 |
|
|
var href = location ? history.createHref(location) : "";
|
3810 |
|
|
|
3811 |
|
|
var props = _extends({}, rest, {
|
3812 |
|
|
href: href,
|
3813 |
|
|
navigate: function navigate() {
|
3814 |
|
|
var location = resolveToLocation(to, context.location);
|
3815 |
|
|
var method = replace ? history.replace : history.push;
|
3816 |
|
|
method(location);
|
3817 |
|
|
}
|
3818 |
|
|
}); // React 15 compat
|
3819 |
|
|
|
3820 |
|
|
|
3821 |
|
|
if (forwardRefShim !== forwardRef) {
|
3822 |
|
|
props.ref = forwardedRef || innerRef;
|
3823 |
|
|
} else {
|
3824 |
|
|
props.innerRef = innerRef;
|
3825 |
|
|
}
|
3826 |
|
|
|
3827 |
|
|
return React__default.createElement(component, props);
|
3828 |
|
|
});
|
3829 |
|
|
});
|
3830 |
|
|
|
3831 |
|
|
{
|
3832 |
|
|
var toType = propTypes.oneOfType([propTypes.string, propTypes.object, propTypes.func]);
|
3833 |
|
|
var refType = propTypes.oneOfType([propTypes.string, propTypes.func, propTypes.shape({
|
3834 |
|
|
current: propTypes.any
|
3835 |
|
|
})]);
|
3836 |
|
|
Link.displayName = "Link";
|
3837 |
|
|
Link.propTypes = {
|
3838 |
|
|
innerRef: refType,
|
3839 |
|
|
onClick: propTypes.func,
|
3840 |
|
|
replace: propTypes.bool,
|
3841 |
|
|
target: propTypes.string,
|
3842 |
|
|
to: toType.isRequired
|
3843 |
|
|
};
|
3844 |
|
|
}
|
3845 |
|
|
|
3846 |
|
|
var forwardRefShim$1 = function forwardRefShim(C) {
|
3847 |
|
|
return C;
|
3848 |
|
|
};
|
3849 |
|
|
|
3850 |
|
|
var forwardRef$1 = React__default.forwardRef;
|
3851 |
|
|
|
3852 |
|
|
if (typeof forwardRef$1 === "undefined") {
|
3853 |
|
|
forwardRef$1 = forwardRefShim$1;
|
3854 |
|
|
}
|
3855 |
|
|
|
3856 |
|
|
function joinClassnames() {
|
3857 |
|
|
for (var _len = arguments.length, classnames = new Array(_len), _key = 0; _key < _len; _key++) {
|
3858 |
|
|
classnames[_key] = arguments[_key];
|
3859 |
|
|
}
|
3860 |
|
|
|
3861 |
|
|
return classnames.filter(function (i) {
|
3862 |
|
|
return i;
|
3863 |
|
|
}).join(" ");
|
3864 |
|
|
}
|
3865 |
|
|
/**
|
3866 |
|
|
* A <Link> wrapper that knows if it's "active" or not.
|
3867 |
|
|
*/
|
3868 |
|
|
|
3869 |
|
|
|
3870 |
|
|
var NavLink = forwardRef$1(function (_ref, forwardedRef) {
|
3871 |
|
|
var _ref$ariaCurrent = _ref["aria-current"],
|
3872 |
|
|
ariaCurrent = _ref$ariaCurrent === void 0 ? "page" : _ref$ariaCurrent,
|
3873 |
|
|
_ref$activeClassName = _ref.activeClassName,
|
3874 |
|
|
activeClassName = _ref$activeClassName === void 0 ? "active" : _ref$activeClassName,
|
3875 |
|
|
activeStyle = _ref.activeStyle,
|
3876 |
|
|
classNameProp = _ref.className,
|
3877 |
|
|
exact = _ref.exact,
|
3878 |
|
|
isActiveProp = _ref.isActive,
|
3879 |
|
|
locationProp = _ref.location,
|
3880 |
|
|
strict = _ref.strict,
|
3881 |
|
|
styleProp = _ref.style,
|
3882 |
|
|
to = _ref.to,
|
3883 |
|
|
innerRef = _ref.innerRef,
|
3884 |
|
|
rest = _objectWithoutPropertiesLoose(_ref, ["aria-current", "activeClassName", "activeStyle", "className", "exact", "isActive", "location", "strict", "style", "to", "innerRef"]);
|
3885 |
|
|
|
3886 |
|
|
return React__default.createElement(context.Consumer, null, function (context) {
|
3887 |
|
|
!context ? invariant(false, "You should not use <NavLink> outside a <Router>") : void 0;
|
3888 |
|
|
var currentLocation = locationProp || context.location;
|
3889 |
|
|
var toLocation = normalizeToLocation(resolveToLocation(to, currentLocation), currentLocation);
|
3890 |
|
|
var path = toLocation.pathname; // Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202
|
3891 |
|
|
|
3892 |
|
|
var escapedPath = path && path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
3893 |
|
|
var match = escapedPath ? matchPath(currentLocation.pathname, {
|
3894 |
|
|
path: escapedPath,
|
3895 |
|
|
exact: exact,
|
3896 |
|
|
strict: strict
|
3897 |
|
|
}) : null;
|
3898 |
|
|
var isActive = !!(isActiveProp ? isActiveProp(match, currentLocation) : match);
|
3899 |
|
|
var className = isActive ? joinClassnames(classNameProp, activeClassName) : classNameProp;
|
3900 |
|
|
var style = isActive ? _extends({}, styleProp, {}, activeStyle) : styleProp;
|
3901 |
|
|
|
3902 |
|
|
var props = _extends({
|
3903 |
|
|
"aria-current": isActive && ariaCurrent || null,
|
3904 |
|
|
className: className,
|
3905 |
|
|
style: style,
|
3906 |
|
|
to: toLocation
|
3907 |
|
|
}, rest); // React 15 compat
|
3908 |
|
|
|
3909 |
|
|
|
3910 |
|
|
if (forwardRefShim$1 !== forwardRef$1) {
|
3911 |
|
|
props.ref = forwardedRef || innerRef;
|
3912 |
|
|
} else {
|
3913 |
|
|
props.innerRef = innerRef;
|
3914 |
|
|
}
|
3915 |
|
|
|
3916 |
|
|
return React__default.createElement(Link, props);
|
3917 |
|
|
});
|
3918 |
|
|
});
|
3919 |
|
|
|
3920 |
|
|
{
|
3921 |
|
|
NavLink.displayName = "NavLink";
|
3922 |
|
|
var ariaCurrentType = propTypes.oneOf(["page", "step", "location", "date", "time", "true"]);
|
3923 |
|
|
NavLink.propTypes = _extends({}, Link.propTypes, {
|
3924 |
|
|
"aria-current": ariaCurrentType,
|
3925 |
|
|
activeClassName: propTypes.string,
|
3926 |
|
|
activeStyle: propTypes.object,
|
3927 |
|
|
className: propTypes.string,
|
3928 |
|
|
exact: propTypes.bool,
|
3929 |
|
|
isActive: propTypes.func,
|
3930 |
|
|
location: propTypes.object,
|
3931 |
|
|
strict: propTypes.bool,
|
3932 |
|
|
style: propTypes.object
|
3933 |
|
|
});
|
3934 |
|
|
}
|
3935 |
|
|
|
3936 |
|
|
exports.BrowserRouter = BrowserRouter;
|
3937 |
|
|
exports.HashRouter = HashRouter;
|
3938 |
|
|
exports.Link = Link;
|
3939 |
|
|
exports.MemoryRouter = MemoryRouter;
|
3940 |
|
|
exports.NavLink = NavLink;
|
3941 |
|
|
exports.Prompt = Prompt;
|
3942 |
|
|
exports.Redirect = Redirect;
|
3943 |
|
|
exports.Route = Route;
|
3944 |
|
|
exports.Router = Router;
|
3945 |
|
|
exports.StaticRouter = StaticRouter;
|
3946 |
|
|
exports.Switch = Switch;
|
3947 |
|
|
exports.__RouterContext = context;
|
3948 |
|
|
exports.generatePath = generatePath;
|
3949 |
|
|
exports.matchPath = matchPath;
|
3950 |
|
|
exports.useHistory = useHistory;
|
3951 |
|
|
exports.useLocation = useLocation;
|
3952 |
|
|
exports.useParams = useParams;
|
3953 |
|
|
exports.useRouteMatch = useRouteMatch;
|
3954 |
|
|
exports.withRouter = withRouter;
|
3955 |
|
|
|
3956 |
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
3957 |
|
|
|
3958 |
|
|
}));
|
3959 |
|
|
//# sourceMappingURL=react-router-dom.js.map
|