1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
4 |
|
|
|
5 |
|
|
var reactRouter = require('react-router');
|
6 |
|
|
var React = _interopDefault(require('react'));
|
7 |
|
|
var history = require('history');
|
8 |
|
|
var PropTypes = _interopDefault(require('prop-types'));
|
9 |
|
|
var warning = _interopDefault(require('tiny-warning'));
|
10 |
|
|
var invariant = _interopDefault(require('tiny-invariant'));
|
11 |
|
|
|
12 |
|
|
function _extends() {
|
13 |
|
|
_extends = Object.assign || function (target) {
|
14 |
|
|
for (var i = 1; i < arguments.length; i++) {
|
15 |
|
|
var source = arguments[i];
|
16 |
|
|
|
17 |
|
|
for (var key in source) {
|
18 |
|
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
19 |
|
|
target[key] = source[key];
|
20 |
|
|
}
|
21 |
|
|
}
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
return target;
|
25 |
|
|
};
|
26 |
|
|
|
27 |
|
|
return _extends.apply(this, arguments);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
function _inheritsLoose(subClass, superClass) {
|
31 |
|
|
subClass.prototype = Object.create(superClass.prototype);
|
32 |
|
|
subClass.prototype.constructor = subClass;
|
33 |
|
|
subClass.__proto__ = superClass;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
37 |
|
|
if (source == null) return {};
|
38 |
|
|
var target = {};
|
39 |
|
|
var sourceKeys = Object.keys(source);
|
40 |
|
|
var key, i;
|
41 |
|
|
|
42 |
|
|
for (i = 0; i < sourceKeys.length; i++) {
|
43 |
|
|
key = sourceKeys[i];
|
44 |
|
|
if (excluded.indexOf(key) >= 0) continue;
|
45 |
|
|
target[key] = source[key];
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
return target;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* The public API for a <Router> that uses HTML5 history.
|
53 |
|
|
*/
|
54 |
|
|
|
55 |
|
|
var BrowserRouter =
|
56 |
|
|
/*#__PURE__*/
|
57 |
|
|
function (_React$Component) {
|
58 |
|
|
_inheritsLoose(BrowserRouter, _React$Component);
|
59 |
|
|
|
60 |
|
|
function BrowserRouter() {
|
61 |
|
|
var _this;
|
62 |
|
|
|
63 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
64 |
|
|
args[_key] = arguments[_key];
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
68 |
|
|
_this.history = history.createBrowserHistory(_this.props);
|
69 |
|
|
return _this;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
var _proto = BrowserRouter.prototype;
|
73 |
|
|
|
74 |
|
|
_proto.render = function render() {
|
75 |
|
|
return React.createElement(reactRouter.Router, {
|
76 |
|
|
history: this.history,
|
77 |
|
|
children: this.props.children
|
78 |
|
|
});
|
79 |
|
|
};
|
80 |
|
|
|
81 |
|
|
return BrowserRouter;
|
82 |
|
|
}(React.Component);
|
83 |
|
|
|
84 |
|
|
{
|
85 |
|
|
BrowserRouter.propTypes = {
|
86 |
|
|
basename: PropTypes.string,
|
87 |
|
|
children: PropTypes.node,
|
88 |
|
|
forceRefresh: PropTypes.bool,
|
89 |
|
|
getUserConfirmation: PropTypes.func,
|
90 |
|
|
keyLength: PropTypes.number
|
91 |
|
|
};
|
92 |
|
|
|
93 |
|
|
BrowserRouter.prototype.componentDidMount = function () {
|
94 |
|
|
warning(!this.props.history, "<BrowserRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { BrowserRouter as Router }`.") ;
|
95 |
|
|
};
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
/**
|
99 |
|
|
* The public API for a <Router> that uses window.location.hash.
|
100 |
|
|
*/
|
101 |
|
|
|
102 |
|
|
var HashRouter =
|
103 |
|
|
/*#__PURE__*/
|
104 |
|
|
function (_React$Component) {
|
105 |
|
|
_inheritsLoose(HashRouter, _React$Component);
|
106 |
|
|
|
107 |
|
|
function HashRouter() {
|
108 |
|
|
var _this;
|
109 |
|
|
|
110 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
111 |
|
|
args[_key] = arguments[_key];
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
115 |
|
|
_this.history = history.createHashHistory(_this.props);
|
116 |
|
|
return _this;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
var _proto = HashRouter.prototype;
|
120 |
|
|
|
121 |
|
|
_proto.render = function render() {
|
122 |
|
|
return React.createElement(reactRouter.Router, {
|
123 |
|
|
history: this.history,
|
124 |
|
|
children: this.props.children
|
125 |
|
|
});
|
126 |
|
|
};
|
127 |
|
|
|
128 |
|
|
return HashRouter;
|
129 |
|
|
}(React.Component);
|
130 |
|
|
|
131 |
|
|
{
|
132 |
|
|
HashRouter.propTypes = {
|
133 |
|
|
basename: PropTypes.string,
|
134 |
|
|
children: PropTypes.node,
|
135 |
|
|
getUserConfirmation: PropTypes.func,
|
136 |
|
|
hashType: PropTypes.oneOf(["hashbang", "noslash", "slash"])
|
137 |
|
|
};
|
138 |
|
|
|
139 |
|
|
HashRouter.prototype.componentDidMount = function () {
|
140 |
|
|
warning(!this.props.history, "<HashRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { HashRouter as Router }`.") ;
|
141 |
|
|
};
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
var resolveToLocation = function resolveToLocation(to, currentLocation) {
|
145 |
|
|
return typeof to === "function" ? to(currentLocation) : to;
|
146 |
|
|
};
|
147 |
|
|
var normalizeToLocation = function normalizeToLocation(to, currentLocation) {
|
148 |
|
|
return typeof to === "string" ? history.createLocation(to, null, null, currentLocation) : to;
|
149 |
|
|
};
|
150 |
|
|
|
151 |
|
|
var forwardRefShim = function forwardRefShim(C) {
|
152 |
|
|
return C;
|
153 |
|
|
};
|
154 |
|
|
|
155 |
|
|
var forwardRef = React.forwardRef;
|
156 |
|
|
|
157 |
|
|
if (typeof forwardRef === "undefined") {
|
158 |
|
|
forwardRef = forwardRefShim;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
function isModifiedEvent(event) {
|
162 |
|
|
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
var LinkAnchor = forwardRef(function (_ref, forwardedRef) {
|
166 |
|
|
var innerRef = _ref.innerRef,
|
167 |
|
|
navigate = _ref.navigate,
|
168 |
|
|
_onClick = _ref.onClick,
|
169 |
|
|
rest = _objectWithoutPropertiesLoose(_ref, ["innerRef", "navigate", "onClick"]);
|
170 |
|
|
|
171 |
|
|
var target = rest.target;
|
172 |
|
|
|
173 |
|
|
var props = _extends({}, rest, {
|
174 |
|
|
onClick: function onClick(event) {
|
175 |
|
|
try {
|
176 |
|
|
if (_onClick) _onClick(event);
|
177 |
|
|
} catch (ex) {
|
178 |
|
|
event.preventDefault();
|
179 |
|
|
throw ex;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
if (!event.defaultPrevented && // onClick prevented default
|
183 |
|
|
event.button === 0 && ( // ignore everything but left clicks
|
184 |
|
|
!target || target === "_self") && // let browser handle "target=_blank" etc.
|
185 |
|
|
!isModifiedEvent(event) // ignore clicks with modifier keys
|
186 |
|
|
) {
|
187 |
|
|
event.preventDefault();
|
188 |
|
|
navigate();
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
}); // React 15 compat
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
if (forwardRefShim !== forwardRef) {
|
195 |
|
|
props.ref = forwardedRef || innerRef;
|
196 |
|
|
} else {
|
197 |
|
|
props.ref = innerRef;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
return React.createElement("a", props);
|
201 |
|
|
});
|
202 |
|
|
|
203 |
|
|
{
|
204 |
|
|
LinkAnchor.displayName = "LinkAnchor";
|
205 |
|
|
}
|
206 |
|
|
/**
|
207 |
|
|
* The public API for rendering a history-aware <a>.
|
208 |
|
|
*/
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
var Link = forwardRef(function (_ref2, forwardedRef) {
|
212 |
|
|
var _ref2$component = _ref2.component,
|
213 |
|
|
component = _ref2$component === void 0 ? LinkAnchor : _ref2$component,
|
214 |
|
|
replace = _ref2.replace,
|
215 |
|
|
to = _ref2.to,
|
216 |
|
|
innerRef = _ref2.innerRef,
|
217 |
|
|
rest = _objectWithoutPropertiesLoose(_ref2, ["component", "replace", "to", "innerRef"]);
|
218 |
|
|
|
219 |
|
|
return React.createElement(reactRouter.__RouterContext.Consumer, null, function (context) {
|
220 |
|
|
!context ? invariant(false, "You should not use <Link> outside a <Router>") : void 0;
|
221 |
|
|
var history = context.history;
|
222 |
|
|
var location = normalizeToLocation(resolveToLocation(to, context.location), context.location);
|
223 |
|
|
var href = location ? history.createHref(location) : "";
|
224 |
|
|
|
225 |
|
|
var props = _extends({}, rest, {
|
226 |
|
|
href: href,
|
227 |
|
|
navigate: function navigate() {
|
228 |
|
|
var location = resolveToLocation(to, context.location);
|
229 |
|
|
var method = replace ? history.replace : history.push;
|
230 |
|
|
method(location);
|
231 |
|
|
}
|
232 |
|
|
}); // React 15 compat
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
if (forwardRefShim !== forwardRef) {
|
236 |
|
|
props.ref = forwardedRef || innerRef;
|
237 |
|
|
} else {
|
238 |
|
|
props.innerRef = innerRef;
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
return React.createElement(component, props);
|
242 |
|
|
});
|
243 |
|
|
});
|
244 |
|
|
|
245 |
|
|
{
|
246 |
|
|
var toType = PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.func]);
|
247 |
|
|
var refType = PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.shape({
|
248 |
|
|
current: PropTypes.any
|
249 |
|
|
})]);
|
250 |
|
|
Link.displayName = "Link";
|
251 |
|
|
Link.propTypes = {
|
252 |
|
|
innerRef: refType,
|
253 |
|
|
onClick: PropTypes.func,
|
254 |
|
|
replace: PropTypes.bool,
|
255 |
|
|
target: PropTypes.string,
|
256 |
|
|
to: toType.isRequired
|
257 |
|
|
};
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
var forwardRefShim$1 = function forwardRefShim(C) {
|
261 |
|
|
return C;
|
262 |
|
|
};
|
263 |
|
|
|
264 |
|
|
var forwardRef$1 = React.forwardRef;
|
265 |
|
|
|
266 |
|
|
if (typeof forwardRef$1 === "undefined") {
|
267 |
|
|
forwardRef$1 = forwardRefShim$1;
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
function joinClassnames() {
|
271 |
|
|
for (var _len = arguments.length, classnames = new Array(_len), _key = 0; _key < _len; _key++) {
|
272 |
|
|
classnames[_key] = arguments[_key];
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
return classnames.filter(function (i) {
|
276 |
|
|
return i;
|
277 |
|
|
}).join(" ");
|
278 |
|
|
}
|
279 |
|
|
/**
|
280 |
|
|
* A <Link> wrapper that knows if it's "active" or not.
|
281 |
|
|
*/
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
var NavLink = forwardRef$1(function (_ref, forwardedRef) {
|
285 |
|
|
var _ref$ariaCurrent = _ref["aria-current"],
|
286 |
|
|
ariaCurrent = _ref$ariaCurrent === void 0 ? "page" : _ref$ariaCurrent,
|
287 |
|
|
_ref$activeClassName = _ref.activeClassName,
|
288 |
|
|
activeClassName = _ref$activeClassName === void 0 ? "active" : _ref$activeClassName,
|
289 |
|
|
activeStyle = _ref.activeStyle,
|
290 |
|
|
classNameProp = _ref.className,
|
291 |
|
|
exact = _ref.exact,
|
292 |
|
|
isActiveProp = _ref.isActive,
|
293 |
|
|
locationProp = _ref.location,
|
294 |
|
|
strict = _ref.strict,
|
295 |
|
|
styleProp = _ref.style,
|
296 |
|
|
to = _ref.to,
|
297 |
|
|
innerRef = _ref.innerRef,
|
298 |
|
|
rest = _objectWithoutPropertiesLoose(_ref, ["aria-current", "activeClassName", "activeStyle", "className", "exact", "isActive", "location", "strict", "style", "to", "innerRef"]);
|
299 |
|
|
|
300 |
|
|
return React.createElement(reactRouter.__RouterContext.Consumer, null, function (context) {
|
301 |
|
|
!context ? invariant(false, "You should not use <NavLink> outside a <Router>") : void 0;
|
302 |
|
|
var currentLocation = locationProp || context.location;
|
303 |
|
|
var toLocation = normalizeToLocation(resolveToLocation(to, currentLocation), currentLocation);
|
304 |
|
|
var path = toLocation.pathname; // Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202
|
305 |
|
|
|
306 |
|
|
var escapedPath = path && path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
307 |
|
|
var match = escapedPath ? reactRouter.matchPath(currentLocation.pathname, {
|
308 |
|
|
path: escapedPath,
|
309 |
|
|
exact: exact,
|
310 |
|
|
strict: strict
|
311 |
|
|
}) : null;
|
312 |
|
|
var isActive = !!(isActiveProp ? isActiveProp(match, currentLocation) : match);
|
313 |
|
|
var className = isActive ? joinClassnames(classNameProp, activeClassName) : classNameProp;
|
314 |
|
|
var style = isActive ? _extends({}, styleProp, {}, activeStyle) : styleProp;
|
315 |
|
|
|
316 |
|
|
var props = _extends({
|
317 |
|
|
"aria-current": isActive && ariaCurrent || null,
|
318 |
|
|
className: className,
|
319 |
|
|
style: style,
|
320 |
|
|
to: toLocation
|
321 |
|
|
}, rest); // React 15 compat
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
if (forwardRefShim$1 !== forwardRef$1) {
|
325 |
|
|
props.ref = forwardedRef || innerRef;
|
326 |
|
|
} else {
|
327 |
|
|
props.innerRef = innerRef;
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
return React.createElement(Link, props);
|
331 |
|
|
});
|
332 |
|
|
});
|
333 |
|
|
|
334 |
|
|
{
|
335 |
|
|
NavLink.displayName = "NavLink";
|
336 |
|
|
var ariaCurrentType = PropTypes.oneOf(["page", "step", "location", "date", "time", "true"]);
|
337 |
|
|
NavLink.propTypes = _extends({}, Link.propTypes, {
|
338 |
|
|
"aria-current": ariaCurrentType,
|
339 |
|
|
activeClassName: PropTypes.string,
|
340 |
|
|
activeStyle: PropTypes.object,
|
341 |
|
|
className: PropTypes.string,
|
342 |
|
|
exact: PropTypes.bool,
|
343 |
|
|
isActive: PropTypes.func,
|
344 |
|
|
location: PropTypes.object,
|
345 |
|
|
strict: PropTypes.bool,
|
346 |
|
|
style: PropTypes.object
|
347 |
|
|
});
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
Object.keys(reactRouter).forEach(function (k) {
|
351 |
|
|
if (k !== 'default') Object.defineProperty(exports, k, {
|
352 |
|
|
enumerable: true,
|
353 |
|
|
get: function () {
|
354 |
|
|
return reactRouter[k];
|
355 |
|
|
}
|
356 |
|
|
});
|
357 |
|
|
});
|
358 |
|
|
exports.BrowserRouter = BrowserRouter;
|
359 |
|
|
exports.HashRouter = HashRouter;
|
360 |
|
|
exports.Link = Link;
|
361 |
|
|
exports.NavLink = NavLink;
|
362 |
|
|
//# sourceMappingURL=react-router-dom.js.map
|