1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.contextTypes = undefined;
|
7 |
|
8 | var _extends2 = require('babel-runtime/helpers/extends');
|
9 |
|
10 | var _extends3 = _interopRequireDefault(_extends2);
|
11 |
|
12 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
13 |
|
14 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
15 |
|
16 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
17 |
|
18 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
19 |
|
20 | var _createClass2 = require('babel-runtime/helpers/createClass');
|
21 |
|
22 | var _createClass3 = _interopRequireDefault(_createClass2);
|
23 |
|
24 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
25 |
|
26 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
27 |
|
28 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
29 |
|
30 | var _inherits3 = _interopRequireDefault(_inherits2);
|
31 |
|
32 | var _react = require('react');
|
33 |
|
34 | var _react2 = _interopRequireDefault(_react);
|
35 |
|
36 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37 |
|
38 | var contextTypes = exports.contextTypes = {
|
39 | page: _react2.default.PropTypes.object
|
40 | }; /**
|
41 | * @copyright 2016-present, Sitegen team
|
42 | */
|
43 |
|
44 | var CollectionContext = function (_React$Component) {
|
45 | (0, _inherits3.default)(CollectionContext, _React$Component);
|
46 |
|
47 | function CollectionContext() {
|
48 | (0, _classCallCheck3.default)(this, CollectionContext);
|
49 | return (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(CollectionContext).apply(this, arguments));
|
50 | }
|
51 |
|
52 | (0, _createClass3.default)(CollectionContext, [{
|
53 | key: 'render',
|
54 | value: function render() {
|
55 | var _props = this.props;
|
56 | var Component = _props.Component;
|
57 | var page = _props.page;
|
58 | var props = _props.props;
|
59 |
|
60 | page = page.map(function (item) {
|
61 | return (0, _extends3.default)({}, item, {
|
62 | path: _createPath(props.route, props.routes, item.path)
|
63 | });
|
64 | });
|
65 | return _react2.default.createElement(Component, (0, _extends3.default)({}, props, { page: page }));
|
66 | }
|
67 | }, {
|
68 | key: 'getChildContext',
|
69 | value: function getChildContext() {
|
70 | var _props2 = this.props;
|
71 | var pageNumber = _props2.pageNumber;
|
72 | var pageCount = _props2.pageCount;
|
73 | var _props2$props = _props2.props;
|
74 | var routes = _props2$props.routes;
|
75 | var route = _props2$props.route;
|
76 |
|
77 | return {
|
78 | page: {
|
79 | collection: { pageNumber: pageNumber, pageCount: pageCount },
|
80 | routes: routes,
|
81 | route: route,
|
82 | createPath: function createPath() {
|
83 | for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
|
84 | rest[_key] = arguments[_key];
|
85 | }
|
86 |
|
87 | return _createPath.apply(undefined, [route, routes].concat(rest));
|
88 | }
|
89 | }
|
90 | };
|
91 | }
|
92 | }]);
|
93 | return CollectionContext;
|
94 | }(_react2.default.Component);
|
95 |
|
96 | CollectionContext.contextTypes = contextTypes;
|
97 | CollectionContext.childContextTypes = contextTypes;
|
98 | exports.default = CollectionContext;
|
99 |
|
100 |
|
101 | function _createPath(route, routes) {
|
102 | var basepath = [];
|
103 | for (var i = 0; i < routes.length; i++) {
|
104 | basepath.push(routes[i].path);
|
105 | if (routes[i] === route) {
|
106 | break;
|
107 | }
|
108 | }
|
109 | basepath = basepath.join('');
|
110 |
|
111 | for (var _len2 = arguments.length, rest = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
112 | rest[_key2 - 2] = arguments[_key2];
|
113 | }
|
114 |
|
115 | if (rest.length > 0) {
|
116 | return [basepath].concat(rest).join('/');
|
117 | } else {
|
118 | return basepath;
|
119 | }
|
120 | }
|
121 | //# sourceMappingURL=data:application/json;base64,eyJ2Z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