1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _constants = require("./constants.js");
|
11 |
|
12 | var _utils = require("./utils.js");
|
13 |
|
14 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
15 |
|
16 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17 |
|
18 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
19 |
|
20 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
21 |
|
22 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
23 |
|
24 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
25 |
|
26 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
27 |
|
28 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
29 |
|
30 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
31 |
|
32 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
33 |
|
34 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
35 |
|
36 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
37 |
|
38 | var initialState = {
|
39 | currentPage: 1
|
40 | };
|
41 |
|
42 | var PaginationStatefulContainer =
|
43 |
|
44 | function (_React$Component) {
|
45 | _inherits(PaginationStatefulContainer, _React$Component);
|
46 |
|
47 | function PaginationStatefulContainer() {
|
48 | var _getPrototypeOf2;
|
49 |
|
50 | var _this;
|
51 |
|
52 | _classCallCheck(this, PaginationStatefulContainer);
|
53 |
|
54 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
55 | args[_key] = arguments[_key];
|
56 | }
|
57 |
|
58 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(PaginationStatefulContainer)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
59 |
|
60 | _defineProperty(_assertThisInitialized(_this), "state", _this.props.initialState || initialState);
|
61 |
|
62 | _defineProperty(_assertThisInitialized(_this), "onPageChange", function (_ref) {
|
63 | var nextPage = _ref.nextPage;
|
64 | var _this$props = _this.props,
|
65 | numPages = _this$props.numPages,
|
66 | onPageChange = _this$props.onPageChange;
|
67 | var currentPage = _this.state.currentPage;
|
68 | var clamped = (0, _utils.clamp)(nextPage, 1, numPages);
|
69 |
|
70 | if (clamped !== currentPage) {
|
71 | onPageChange && onPageChange({
|
72 | nextPage: clamped,
|
73 | prevPage: currentPage
|
74 | });
|
75 |
|
76 | _this.internalSetState(_constants.STATE_CHANGE_TYPE.changePage, {
|
77 | currentPage: clamped
|
78 | });
|
79 | }
|
80 | });
|
81 |
|
82 | return _this;
|
83 | }
|
84 |
|
85 | _createClass(PaginationStatefulContainer, [{
|
86 | key: "internalSetState",
|
87 |
|
88 | value: function internalSetState(changeType, changes) {
|
89 | var stateReducer = this.props.stateReducer;
|
90 |
|
91 | if (stateReducer) {
|
92 | this.setState(stateReducer(changeType, changes, this.state));
|
93 | } else {
|
94 | this.setState(changes);
|
95 | }
|
96 | }
|
97 | }, {
|
98 | key: "render",
|
99 | value: function render() {
|
100 | var currentPage = this.state.currentPage;
|
101 | var children = this.props.children;
|
102 | return children({
|
103 | currentPage: currentPage,
|
104 | onPageChange: this.onPageChange
|
105 | });
|
106 | }
|
107 | }]);
|
108 |
|
109 | return PaginationStatefulContainer;
|
110 | }(React.Component);
|
111 |
|
112 | exports.default = PaginationStatefulContainer;
|
113 |
|
114 | _defineProperty(PaginationStatefulContainer, "defaultProps", {
|
115 | initialState: initialState,
|
116 | stateReducer: function stateReducer(changeType, changes) {
|
117 | return changes;
|
118 | }
|
119 | }); |
\ | No newline at end of file |