@vve/react-router 9.0.0-alpha.2 → 9.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/deactivatable-wrapper.js +10 -39
- package/lib/deactivatable-wrapper.js.map +1 -0
- package/lib/garden.js +47 -84
- package/lib/garden.js.map +1 -0
- package/lib/generate-path.js +3 -7
- package/lib/generate-path.js.map +1 -0
- package/lib/index.js +12 -10
- package/lib/index.js.map +1 -0
- package/lib/lifecycle.js +15 -47
- package/lib/lifecycle.js.map +1 -0
- package/lib/link.js +45 -82
- package/lib/link.js.map +1 -0
- package/lib/match-path.js +24 -32
- package/lib/match-path.js.map +1 -0
- package/lib/nav-link.js +25 -35
- package/lib/nav-link.js.map +1 -0
- package/lib/prompt.js +11 -12
- package/lib/prompt.js.map +1 -0
- package/lib/redirect.js +17 -24
- package/lib/redirect.js.map +1 -0
- package/lib/route.js +62 -104
- package/lib/route.js.map +1 -0
- package/lib/router-context.js +2 -1
- package/lib/router-context.js.map +1 -0
- package/lib/router.js +54 -91
- package/lib/router.js.map +1 -0
- package/lib/switch.js +66 -104
- package/lib/switch.js.map +1 -0
- package/lib/with-router.js +10 -12
- package/lib/with-router.js.map +1 -0
- package/package.json +4 -3
package/lib/router.js
CHANGED
|
@@ -1,110 +1,72 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
|
|
7
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
-
|
|
9
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
-
|
|
11
1
|
import React from 'react';
|
|
12
2
|
import PropTypes from 'prop-types';
|
|
13
|
-
import RouterContext from
|
|
3
|
+
import RouterContext from "./router-context";
|
|
4
|
+
var noop = a => a;
|
|
14
5
|
|
|
15
|
-
var noop = function noop(a) {
|
|
16
|
-
return a;
|
|
17
|
-
};
|
|
18
6
|
/**
|
|
19
7
|
* The public API for putting history on context.
|
|
20
8
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
url: '/',
|
|
34
|
-
params: {},
|
|
35
|
-
isExact: pathname === '/'
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}]);
|
|
39
|
-
|
|
40
|
-
function Router(props) {
|
|
41
|
-
var _this;
|
|
42
|
-
|
|
43
|
-
_classCallCheck(this, Router);
|
|
44
|
-
|
|
45
|
-
_this = _super.call(this, props);
|
|
46
|
-
_this.state = {
|
|
9
|
+
class Router extends React.Component {
|
|
10
|
+
static computeRootMatch(pathname) {
|
|
11
|
+
return {
|
|
12
|
+
path: '/',
|
|
13
|
+
url: '/',
|
|
14
|
+
params: {},
|
|
15
|
+
isExact: pathname === '/'
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
constructor(props) {
|
|
19
|
+
super(props);
|
|
20
|
+
this.state = {
|
|
47
21
|
location: props.history.location
|
|
48
|
-
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// This is a bit of a hack. We have to start listening for location
|
|
49
25
|
// changes here in the constructor in case there are any <Redirect>s
|
|
50
26
|
// on the initial render. If there are, they will replace/push when
|
|
51
27
|
// they mount and since cDM fires in children before parents, we may
|
|
52
28
|
// get a new location before the <Router> is mounted.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
location: location
|
|
29
|
+
this.isMountedForRouter = false;
|
|
30
|
+
this.pendingLocation = null;
|
|
31
|
+
this.unlisten = props.history.listen(location => {
|
|
32
|
+
if (this.isMountedForRouter) {
|
|
33
|
+
this.setState({
|
|
34
|
+
location
|
|
60
35
|
});
|
|
61
36
|
} else {
|
|
62
|
-
|
|
37
|
+
this.pendingLocation = location;
|
|
63
38
|
}
|
|
64
39
|
});
|
|
65
|
-
return _this;
|
|
66
40
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (this.pendingLocation) {
|
|
74
|
-
this.setState({
|
|
75
|
-
location: this.pendingLocation
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}, {
|
|
80
|
-
key: "componentWillUnmount",
|
|
81
|
-
value: function componentWillUnmount() {
|
|
82
|
-
if (this.unlisten) this.unlisten();
|
|
41
|
+
componentDidMount() {
|
|
42
|
+
this.isMountedForRouter = true;
|
|
43
|
+
if (this.pendingLocation) {
|
|
44
|
+
this.setState({
|
|
45
|
+
location: this.pendingLocation
|
|
46
|
+
});
|
|
83
47
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}(React.Component);
|
|
107
|
-
|
|
48
|
+
}
|
|
49
|
+
componentWillUnmount() {
|
|
50
|
+
if (this.unlisten) this.unlisten();
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
var _this$props = this.props,
|
|
54
|
+
history = _this$props.history,
|
|
55
|
+
children = _this$props.children,
|
|
56
|
+
genNextUrl = _this$props.genNextUrl,
|
|
57
|
+
linkExtendable = _this$props.linkExtendable;
|
|
58
|
+
var location = this.state.location;
|
|
59
|
+
return /*#__PURE__*/React.createElement(RouterContext.Provider, {
|
|
60
|
+
value: {
|
|
61
|
+
history,
|
|
62
|
+
location,
|
|
63
|
+
match: Router.computeRootMatch(location.pathname),
|
|
64
|
+
genNextUrl,
|
|
65
|
+
linkExtendable
|
|
66
|
+
}
|
|
67
|
+
}, children || null);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
108
70
|
Router.defaultProps = {
|
|
109
71
|
genNextUrl: noop,
|
|
110
72
|
linkExtendable: false
|
|
@@ -118,4 +80,5 @@ Router.propTypes = {
|
|
|
118
80
|
listen: PropTypes.func.isRequired
|
|
119
81
|
}).isRequired
|
|
120
82
|
};
|
|
121
|
-
export default Router;
|
|
83
|
+
export default Router;
|
|
84
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","names":["React","PropTypes","RouterContext","noop","a","Router","Component","computeRootMatch","pathname","path","url","params","isExact","constructor","props","state","location","history","isMountedForRouter","pendingLocation","unlisten","listen","setState","componentDidMount","componentWillUnmount","render","_this$props","children","genNextUrl","linkExtendable","createElement","Provider","value","match","defaultProps","propTypes","element","isRequired","func","bool","shape"],"sources":["../router.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport RouterContext from './router-context';\n\nconst noop = a => a;\n\n/**\n * The public API for putting history on context.\n */\nclass Router extends React.Component {\n static computeRootMatch(pathname) {\n return {\n path: '/',\n url: '/',\n params: {},\n isExact: pathname === '/',\n };\n }\n\n constructor(props) {\n super(props);\n\n this.state = {\n location: props.history.location,\n };\n\n // This is a bit of a hack. We have to start listening for location\n // changes here in the constructor in case there are any <Redirect>s\n // on the initial render. If there are, they will replace/push when\n // they mount and since cDM fires in children before parents, we may\n // get a new location before the <Router> is mounted.\n this.isMountedForRouter = false;\n this.pendingLocation = null;\n\n this.unlisten = props.history.listen((location) => {\n if (this.isMountedForRouter) {\n this.setState({ location });\n } else {\n this.pendingLocation = location;\n }\n });\n }\n\n componentDidMount() {\n this.isMountedForRouter = true;\n\n if (this.pendingLocation) {\n this.setState({ location: this.pendingLocation });\n }\n }\n\n componentWillUnmount() {\n if (this.unlisten) this.unlisten();\n }\n\n render() {\n const {\n history, children, genNextUrl, linkExtendable\n } = this.props;\n const { location } = this.state;\n return (\n <RouterContext.Provider\n value={{\n history,\n location,\n match: Router.computeRootMatch(location.pathname),\n genNextUrl,\n linkExtendable,\n }}\n >\n {children || null}\n </RouterContext.Provider>\n );\n }\n}\n\nRouter.defaultProps = {\n genNextUrl: noop,\n linkExtendable: false,\n};\n\nRouter.propTypes = {\n children: PropTypes.element.isRequired,\n genNextUrl: PropTypes.func,\n linkExtendable: PropTypes.bool,\n history: PropTypes.shape({\n location: PropTypes.shape({}),\n listen: PropTypes.func.isRequired,\n }).isRequired,\n};\n\nexport default Router;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAElC,OAAOC,aAAa;AAEpB,IAAMC,IAAI,GAAGC,CAAC,IAAIA,CAAC;;AAEnB;AACA;AACA;AACA,MAAMC,MAAM,SAASL,KAAK,CAACM,SAAS,CAAC;EACnC,OAAOC,gBAAgBA,CAACC,QAAQ,EAAE;IAChC,OAAO;MACLC,IAAI,EAAE,GAAG;MACTC,GAAG,EAAE,GAAG;MACRC,MAAM,EAAE,CAAC,CAAC;MACVC,OAAO,EAAEJ,QAAQ,KAAK;IACxB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,KAAK,EAAE5B,MAAM,CAACE,gBAAgB,CAACS,QAAQ,CAACR,QAAQ,CAAC;QACjDoB,UAAU;QACVC;MACF;IAAE,GAEDF,QAAQ,IAAI,IAAI,CACM;EAE7B;AACF;AAEAtB,MAAM,CAAC6B,YAAY,GAAG;EACpBN,UAAU,EAAEzB,IAAI;EAChB0B,cAAc,EAAE;AAClB,CAAC;AAEDxB,MAAM,CAAC8B,SAAS,GAAG;EACjBR,QAAQ,EAAE1B,SAAS,CAACmC,OAAO,CAACC,UAAU;EACtCT,UAAU,EAAE3B,SAAS,CAACqC,IAAI;EAC1BT,cAAc,EAAE5B,SAAS,CAACsC,IAAI;EAC9BtB,OAAO,EAAEhB,SAAS,CAACuC,KAAK,CAAC;IACvBxB,QAAQ,EAAEf,SAAS,CAACuC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7BnB,MAAM,EAAEpB,SAAS,CAACqC,IAAI,CAACD;EACzB,CAAC,CAAC,CAACA;AACL,CAAC;AAED,eAAehC,MAAM"}
|
package/lib/switch.js
CHANGED
|
@@ -1,130 +1,92 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
|
-
|
|
8
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
-
|
|
10
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
|
-
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
15
|
-
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
16
2
|
/* eslint-disable func-names */
|
|
17
3
|
import React, { Fragment } from 'react';
|
|
18
4
|
import PropTypes from 'prop-types';
|
|
19
5
|
import invariant from 'tiny-invariant';
|
|
20
6
|
import warning from 'tiny-warning';
|
|
21
7
|
import { parse } from 'qs';
|
|
22
|
-
import RouterContext from
|
|
23
|
-
import matchPath from
|
|
24
|
-
import DeactivatableWrapper from
|
|
25
|
-
|
|
8
|
+
import RouterContext from "./router-context";
|
|
9
|
+
import matchPath from "./match-path";
|
|
10
|
+
import DeactivatableWrapper from "./deactivatable-wrapper";
|
|
26
11
|
function decorateMatch(match, search) {
|
|
27
12
|
if (!match || !search) return match;
|
|
28
13
|
return _objectSpread(_objectSpread({}, match), {}, {
|
|
29
|
-
url:
|
|
14
|
+
url: `${match.url}${search}`,
|
|
30
15
|
query: parse(search.slice(1))
|
|
31
16
|
});
|
|
32
17
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var _super = _createSuper(Switch);
|
|
38
|
-
|
|
39
|
-
function Switch(props) {
|
|
40
|
-
var _this;
|
|
41
|
-
|
|
42
|
-
_classCallCheck(this, Switch);
|
|
43
|
-
|
|
44
|
-
_this = _super.call(this, props);
|
|
45
|
-
_this.retainRoutes = new Map();
|
|
46
|
-
return _this;
|
|
18
|
+
class Switch extends React.Component {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.retainRoutes = new Map();
|
|
47
22
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})), location.search) : context.match;
|
|
74
|
-
|
|
75
|
-
if (child.props.keepAlive) {
|
|
76
|
-
_this2.retainRoutes.set(path, child);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
var matchedRetain = false;
|
|
81
|
-
var routes = Array.from(_this2.retainRoutes.values()).map(function (ele) {
|
|
82
|
-
var active = ele.props.path === element.props.path;
|
|
83
|
-
var props = {
|
|
84
|
-
rrcActive: active
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
if (active) {
|
|
88
|
-
matchedRetain = true;
|
|
89
|
-
props.location = location;
|
|
90
|
-
props.computedMatch = match;
|
|
23
|
+
render() {
|
|
24
|
+
var _this$props = this.props,
|
|
25
|
+
givenLocation = _this$props.location,
|
|
26
|
+
children = _this$props.children;
|
|
27
|
+
return /*#__PURE__*/React.createElement(RouterContext.Consumer, null, context => {
|
|
28
|
+
invariant(context, 'You should not use <Switch> outside a <Router>');
|
|
29
|
+
var location = givenLocation || context.location;
|
|
30
|
+
var element;
|
|
31
|
+
var match;
|
|
32
|
+
|
|
33
|
+
// We use React.Children.forEach instead of React.Children.toArray().find()
|
|
34
|
+
// here because toArray adds keys to all child elements and we do not want
|
|
35
|
+
// to trigger an unmount/remount for two <Route>s that render the same
|
|
36
|
+
// component at different URLs.
|
|
37
|
+
React.Children.forEach(children, child => {
|
|
38
|
+
if (match == null && /*#__PURE__*/React.isValidElement(child)) {
|
|
39
|
+
element = child;
|
|
40
|
+
|
|
41
|
+
// @TODO what does 'from' mean?
|
|
42
|
+
var path = child.props.path || child.props.from;
|
|
43
|
+
match = path ? decorateMatch(matchPath(location.pathname, _objectSpread(_objectSpread({}, child.props), {}, {
|
|
44
|
+
path
|
|
45
|
+
})), location.search) : context.match;
|
|
46
|
+
if (child.props.keepAlive) {
|
|
47
|
+
this.retainRoutes.set(path, child);
|
|
91
48
|
}
|
|
92
|
-
|
|
93
|
-
return /*#__PURE__*/React.createElement(DeactivatableWrapper, {
|
|
94
|
-
key: ele.props.path,
|
|
95
|
-
active: active
|
|
96
|
-
}, /*#__PURE__*/React.cloneElement(ele, props));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
if (!matchedRetain && match) {
|
|
100
|
-
routes.push( /*#__PURE__*/React.createElement(DeactivatableWrapper, {
|
|
101
|
-
key: element.props.path || 'defaultRoute....',
|
|
102
|
-
active: true
|
|
103
|
-
}, /*#__PURE__*/React.cloneElement(element, {
|
|
104
|
-
location: location,
|
|
105
|
-
computedMatch: match,
|
|
106
|
-
rrcActive: true
|
|
107
|
-
})));
|
|
108
49
|
}
|
|
109
|
-
|
|
110
|
-
return /*#__PURE__*/React.createElement(Fragment, null, routes);
|
|
111
50
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
51
|
+
var matchedRetain = false;
|
|
52
|
+
var routes = Array.from(this.retainRoutes.values()).map(ele => {
|
|
53
|
+
var active = ele.props.path === element.props.path;
|
|
54
|
+
var props = {
|
|
55
|
+
rrcActive: active
|
|
56
|
+
};
|
|
57
|
+
if (active) {
|
|
58
|
+
matchedRetain = true;
|
|
59
|
+
props.location = location;
|
|
60
|
+
props.computedMatch = match;
|
|
61
|
+
}
|
|
62
|
+
return /*#__PURE__*/React.createElement(DeactivatableWrapper, {
|
|
63
|
+
key: ele.props.path,
|
|
64
|
+
active: active
|
|
65
|
+
}, /*#__PURE__*/React.cloneElement(ele, props));
|
|
66
|
+
});
|
|
67
|
+
if (!matchedRetain && match) {
|
|
68
|
+
routes.push( /*#__PURE__*/React.createElement(DeactivatableWrapper, {
|
|
69
|
+
key: element.props.path || 'defaultRoute....',
|
|
70
|
+
active: true
|
|
71
|
+
}, /*#__PURE__*/React.cloneElement(element, {
|
|
72
|
+
location,
|
|
73
|
+
computedMatch: match,
|
|
74
|
+
rrcActive: true
|
|
75
|
+
})));
|
|
76
|
+
}
|
|
77
|
+
return /*#__PURE__*/React.createElement(Fragment, null, routes);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
118
81
|
if (process.env.NODE_ENV !== 'production') {
|
|
119
82
|
Switch.propTypes = {
|
|
120
83
|
children: PropTypes.node,
|
|
121
84
|
location: PropTypes.object
|
|
122
85
|
};
|
|
123
|
-
|
|
124
86
|
Switch.prototype.componentDidUpdate = function (prevProps) {
|
|
125
87
|
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.');
|
|
126
88
|
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.');
|
|
127
89
|
};
|
|
128
90
|
}
|
|
129
|
-
|
|
130
|
-
|
|
91
|
+
export default Switch;
|
|
92
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","names":["React","Fragment","PropTypes","invariant","warning","parse","RouterContext","matchPath","DeactivatableWrapper","decorateMatch","match","search","_objectSpread","url","query","slice","Switch","Component","constructor","props","retainRoutes","Map","render","_this$props","givenLocation","location","children","createElement","Consumer","context","element","Children","forEach","child","isValidElement","path","from","pathname","keepAlive","set","matchedRetain","routes","Array","values","map","ele","active","rrcActive","computedMatch","key","cloneElement","push","process","env","NODE_ENV","propTypes","node","object","prototype","componentDidUpdate","prevProps"],"sources":["../switch.js"],"sourcesContent":["/* eslint-disable func-names */\nimport React, { Fragment } from 'react';\nimport PropTypes from 'prop-types';\nimport invariant from 'tiny-invariant';\nimport warning from 'tiny-warning';\nimport { parse } from 'qs';\n\nimport RouterContext from './router-context';\nimport matchPath from './match-path';\nimport DeactivatableWrapper from './deactivatable-wrapper';\n\nfunction decorateMatch(match, search) {\n if (!match || !search) return match;\n return {\n ...match,\n url: `${match.url}${search}`,\n query: parse(search.slice(1)),\n };\n}\n\nclass Switch extends React.Component {\n constructor(props) {\n super(props);\n this.retainRoutes = new Map();\n }\n\n render() {\n const { location: givenLocation, children } = this.props;\n return (\n <RouterContext.Consumer>\n {context => {\n invariant(context, 'You should not use <Switch> outside a <Router>');\n\n const location = givenLocation || context.location;\n\n let element;\n let match;\n\n // We use React.Children.forEach instead of React.Children.toArray().find()\n // here because toArray adds keys to all child elements and we do not want\n // to trigger an unmount/remount for two <Route>s that render the same\n // component at different URLs.\n React.Children.forEach(children, child => {\n if (match == null && React.isValidElement(child)) {\n element = child;\n\n // @TODO what does 'from' mean?\n const path = child.props.path || child.props.from;\n\n match = path ? decorateMatch(matchPath(location.pathname, { ...child.props, path }), location.search) : context.match;\n\n if (child.props.keepAlive) {\n this.retainRoutes.set(path, child);\n }\n }\n });\n\n let matchedRetain = false;\n const routes = Array.from(this.retainRoutes.values()).map(ele => {\n const active = ele.props.path === element.props.path;\n const props = { rrcActive: active };\n if (active) {\n matchedRetain = true;\n props.location = location;\n props.computedMatch = match;\n }\n return (\n <DeactivatableWrapper key={ele.props.path} active={active}>\n {React.cloneElement(ele, props)}\n </DeactivatableWrapper>\n );\n });\n if (!matchedRetain && match) {\n routes.push(\n <DeactivatableWrapper key={element.props.path || 'defaultRoute....'} active>\n {React.cloneElement(element, { location, computedMatch: match, rrcActive: true })}\n </DeactivatableWrapper>,\n );\n }\n return <Fragment>{routes}</Fragment>;\n }}\n </RouterContext.Consumer>\n );\n }\n}\n\nif (process.env.NODE_ENV !== 'production') {\n Switch.propTypes = {\n children: PropTypes.node,\n location: PropTypes.object,\n };\n\n Switch.prototype.componentDidUpdate = function(prevProps) {\n warning(\n !(this.props.location && !prevProps.location),\n '<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.',\n );\n\n warning(\n !(!this.props.location && prevProps.location),\n '<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.',\n );\n };\n}\n\nexport default Switch;\n"],"mappings":";AAAA;AACA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAOC,OAAO,MAAM,cAAc;AAClC,SAASC,KAAK,QAAQ,IAAI;AAE1B,OAAOC,aAAa;AACpB,OAAOC,SAAS;AAChB,OAAOC,oBAAoB;AAE3B,SAASC,aAAaA,CAACC,KAAK,EAAEC,MAAM,EAAE;EACpC,IAAI,CAACD,KAAK,IAAI,CAACC,MAAM,EAAE,OAAOD,KAAK;EACnC,OAAAE,aAAA,CAAAA,aAAA,KACKF,KAAK;IACRG,GAAG,EAAG,GAAEH,KAAK,CAACG,GAAI,GAAEF,MAAO,EAAC;IAC5BG,KAAK,EAAET,KAAK,CAACM,MAAM,CAACI,KAAK,CAAC,CAAC,CAAC;EAAC;AAEjC;AAEA,MAAMC,MAAM,SAAShB,KAAK,CAACiB,SAAS,CAAC;EACnCC,WAAWA,CA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B,CAAC;EAEDzC,MAAM,CAAC0C,SAAS,CAACC,kBAAkB,GAAG,UAASC,SAAS,EAAE;IACxDxD,OAAO,CACL,EAAE,IAAI,CAACe,KAAK,CAACM,QAAQ,IAAI,CAACmC,SAAS,CAACnC,QAAQ,CAAC,EAC7C,0KAA0K,CAC3K;IAEDrB,OAAO,CACL,EAAE,CAAC,IAAI,CAACe,KAAK,CAACM,QAAQ,IAAImC,SAAS,CAACnC,QAAQ,CAAC,EAC7C,sKAAsK,CACvK;EACH,CAAC;AACH;AAEA,eAAeT,MAAM"}
|
package/lib/with-router.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["wrappedComponentRef"];
|
|
3
4
|
import React from 'react';
|
|
4
5
|
import hoistStatics from 'hoist-non-react-statics';
|
|
5
6
|
import invariant from 'tiny-invariant';
|
|
6
|
-
import RouterContext from
|
|
7
|
+
import RouterContext from "./router-context";
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* A public higher-order component to access the imperative API
|
|
9
11
|
*/
|
|
10
|
-
|
|
11
12
|
function withRouter(Component) {
|
|
12
|
-
var displayName =
|
|
13
|
-
|
|
14
|
-
var C = function C(props) {
|
|
13
|
+
var displayName = `withRouter(${Component.displayName || Component.name})`;
|
|
14
|
+
var C = props => {
|
|
15
15
|
var wrappedComponentRef = props.wrappedComponentRef,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
invariant(context, "You should not use <".concat(displayName, " /> outside a <Router>"));
|
|
16
|
+
remainingProps = _objectWithoutProperties(props, _excluded);
|
|
17
|
+
return /*#__PURE__*/React.createElement(RouterContext.Consumer, null, context => {
|
|
18
|
+
invariant(context, `You should not use <${displayName} /> outside a <Router>`);
|
|
20
19
|
return /*#__PURE__*/React.createElement(Component, _extends({}, remainingProps, context, {
|
|
21
20
|
ref: wrappedComponentRef
|
|
22
21
|
}));
|
|
23
22
|
});
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
C.displayName = displayName;
|
|
27
25
|
C.WrappedComponent = Component;
|
|
28
26
|
return hoistStatics(C, Component);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
export default withRouter;
|
|
29
|
+
//# sourceMappingURL=with-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-router.js","names":["React","hoistStatics","invariant","RouterContext","withRouter","Component","displayName","name","C","props","wrappedComponentRef","remainingProps","_objectWithoutProperties","_excluded","createElement","Consumer","context","_extends","ref","WrappedComponent"],"sources":["../with-router.js"],"sourcesContent":["import React from 'react';\nimport hoistStatics from 'hoist-non-react-statics';\nimport invariant from 'tiny-invariant';\nimport RouterContext from './router-context';\n\n/**\n * A public higher-order component to access the imperative API\n */\nfunction withRouter(Component) {\n const displayName = `withRouter(${Component.displayName || Component.name})`;\n const C = (props) => {\n const { wrappedComponentRef, ...remainingProps } = props;\n\n return (\n <RouterContext.Consumer>\n {(context) => {\n invariant(\n context,\n `You should not use <${displayName} /> outside a <Router>`\n );\n return (\n <Component\n {...remainingProps}\n {...context}\n ref={wrappedComponentRef}\n />\n );\n }}\n </RouterContext.Consumer>\n );\n };\n\n C.displayName = displayName;\n C.WrappedComponent = Component;\n\n\n return hoistStatics(C, Component);\n}\n\nexport default withRouter;\n"],"mappings":";;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,YAAY,MAAM,yBAAyB;AAClD,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAOC,aAAa;;AAEpB;AACA;AACA;AACA,SAASC,UAAUA,CAACC,SAAS,EAAE;EAC7B,IAAMC,WAAW,GAAI,cAAaD,SAAS,CAACC,WAAW,IAAID,SAAS,CAACE,IAAK,GAAE;EAC5E,IAAMC,CAAC,GAAIC,KAAK,IAAK;IACnB,IAAQC,mBAAmB,GAAwBD,KAAK,CAAhDC,mBAAmB;MAAKC,cAAc,GAAAC,wBAAA,CAAKH,KAAK,EAAAI,SAAA;IAExD,oBACEb,KAAA,CAAAc,aAAA,CAACX,aAAa,CAACY,QAAQ,QACnBC,OAAO,IAAK;MACZd,SAAS,CACPc,OAAO,EACN,uBAAsBV,WAAY,wBAAuB,CAC3D;MACD,oBACEN,KAAA,CAAAc,aAAA,CAACT,SAAS,EAAAY,QAAA,KACJN,cAAc,EACdK,OAAO;QACXE,GAAG,EAAER;MAAoB,GACzB;IAEN,CAAC,CACsB;EAE7B,CAAC;EAEDF,CAAC,CAACF,WAAW,GAAGA,WAAW;EAC3BE,CAAC,CAACW,gBAAgB,GAAGd,SAAS;EAG9B,OAAOJ,YAAY,CAACO,CAAC,EAAEH,SAAS,CAAC;AACnC;AAEA,eAAeD,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vve/react-router",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.4",
|
|
4
4
|
"description": "react router for react-helper & with keep-alive",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"hoist-non-react-statics": "^3.3.0",
|
|
22
22
|
"path-to-regexp": "^1.7.0",
|
|
23
|
+
"@babel/runtime": "7.20.0",
|
|
23
24
|
"qs": "^6.7.0",
|
|
24
25
|
"react-is": "^16.6.0",
|
|
25
26
|
"react-lifecycles-compat": "^3.0.4",
|
|
26
27
|
"tiny-invariant": "^1.0.4",
|
|
27
28
|
"tiny-warning": "^1.0.2",
|
|
28
|
-
"@vve/create-react-context": "9.0.0-alpha.
|
|
29
|
+
"@vve/create-react-context": "9.0.0-alpha.4"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/fs-extra": "^9.0.11",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"gitHead": "f34305f0d8a335e0953d3a5df8a32a8d5507a6f0",
|
|
50
51
|
"scripts": {
|
|
51
52
|
"test": "exit 0",
|
|
52
|
-
"build": "
|
|
53
|
+
"build": "lecp",
|
|
53
54
|
"preversion": "npm test"
|
|
54
55
|
}
|
|
55
56
|
}
|