react-ultimate-pagination
Advanced tools
Comparing version 0.9.0 to 1.0.0
@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["reactUltimatePagination"] = factory(root["React"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) { | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -25,5 +25,5 @@ /******/ // The module cache | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ exports: {}, | ||
/******/ id: moduleId, | ||
/******/ loaded: false | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
@@ -35,3 +35,3 @@ /******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.loaded = true; | ||
/******/ module.l = true; | ||
/******/ | ||
@@ -49,2 +49,28 @@ /******/ // Return the exports of the module | ||
/******/ | ||
/******/ // identity function for calling harmony imports with the correct context | ||
/******/ __webpack_require__.i = function(value) { return value; }; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { | ||
/******/ configurable: false, | ||
/******/ enumerable: true, | ||
/******/ get: getter | ||
/******/ }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
@@ -54,3 +80,3 @@ /******/ __webpack_require__.p = ""; | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(0); | ||
/******/ return __webpack_require__(__webpack_require__.s = 5); | ||
/******/ }) | ||
@@ -60,234 +86,318 @@ /************************************************************************/ | ||
/* 0 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ITEM_TYPES = exports.createUltimatePagination = undefined; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _react = __webpack_require__(1); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _ultimatePagination = __webpack_require__(2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var renderItemComponentFunctionFactory = function renderItemComponentFunctionFactory(itemTypeToComponent, currentPage, onChange) { | ||
var onItemClickFunctionFactory = function onItemClickFunctionFactory(value) { | ||
return function () { | ||
if (onChange && currentPage !== value) { | ||
onChange(value); | ||
} | ||
}; | ||
}; | ||
return function (item) { | ||
var ItemComponent = itemTypeToComponent[item.type]; | ||
var onItemClick = onItemClickFunctionFactory(item.value); | ||
return _react2.default.createElement(ItemComponent, _extends({ onClick: onItemClick }, item)); | ||
}; | ||
}; | ||
var createUltimatePagination = exports.createUltimatePagination = function createUltimatePagination(_ref) { | ||
var itemTypeToComponent = _ref.itemTypeToComponent, | ||
_ref$WrapperComponent = _ref.WrapperComponent, | ||
WrapperComponent = _ref$WrapperComponent === undefined ? 'div' : _ref$WrapperComponent; | ||
var UltimatePaginationComponent = function UltimatePaginationComponent(_ref2) { | ||
var currentPage = _ref2.currentPage, | ||
totalPages = _ref2.totalPages, | ||
onChange = _ref2.onChange; | ||
var paginationModel = (0, _ultimatePagination.getPaginationModel)({ currentPage: currentPage, totalPages: totalPages }); | ||
var renderItemComponent = renderItemComponentFunctionFactory(itemTypeToComponent, currentPage, onChange); | ||
return _react2.default.createElement( | ||
WrapperComponent, | ||
null, | ||
paginationModel.map(renderItemComponent) | ||
); | ||
}; | ||
UltimatePaginationComponent.propTypes = { | ||
currentPage: _react2.default.PropTypes.number.isRequired, | ||
totalPages: _react2.default.PropTypes.number.isRequired, | ||
onChange: _react2.default.PropTypes.func | ||
}; | ||
return UltimatePaginationComponent; | ||
}; | ||
exports.ITEM_TYPES = _ultimatePagination.ITEM_TYPES; | ||
"use strict"; | ||
/***/ }, | ||
exports.ITEM_TYPES = { | ||
PAGE: 'PAGE', | ||
ELLIPSIS: 'ELLIPSIS', | ||
FIRST_PAGE_LINK: 'FIRST_PAGE_LINK', | ||
PREVIOUS_PAGE_LINK: 'PREVIOUS_PAGE_LINK', | ||
NEXT_PAGE_LINK: 'NEXT_PAGE_LINK', | ||
LAST_PAGE_LINK: 'LAST_PAGE_LINK' | ||
}; | ||
exports.ITEM_KEYS = { | ||
FIRST_ELLIPSIS: -1, | ||
SECOND_ELLIPSIS: -2, | ||
FIRST_PAGE_LINK: -3, | ||
PREVIOUS_PAGE_LINK: -4, | ||
NEXT_PAGE_LINK: -5, | ||
LAST_PAGE_LINK: -6 | ||
}; | ||
//# sourceMappingURL=ultimate-pagination-constants.js.map | ||
/***/ }), | ||
/* 1 */ | ||
/***/ function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_1__; | ||
"use strict"; | ||
/***/ }, | ||
var ultimate_pagination_utils_1 = __webpack_require__(4); | ||
var ultimate_pagination_item_factories_1 = __webpack_require__(3); | ||
function getPaginationModel(options) { | ||
if (options == null) { | ||
throw new Error('getPaginationModel(): options object should be a passed'); | ||
} | ||
var totalPages = Number(options.totalPages); | ||
if (isNaN(totalPages)) { | ||
throw new Error('getPaginationModel(): totalPages should be a number'); | ||
} | ||
if (totalPages < 0) { | ||
throw new Error('getPaginationModel(): totalPages shouldn\'t be a negative number'); | ||
} | ||
var currentPage = Number(options.currentPage); | ||
if (isNaN(currentPage)) { | ||
throw new Error('getPaginationModel(): currentPage should be a number'); | ||
} | ||
if (currentPage < 0) { | ||
throw new Error('getPaginationModel(): currentPage shouldn\'t be a negative number'); | ||
} | ||
if (currentPage > totalPages) { | ||
throw new Error('getPaginationModel(): currentPage shouldn\'t be greater than totalPages'); | ||
} | ||
var boundaryPagesRange = (options.boundaryPagesRange == null ? 1 : Number(options.boundaryPagesRange)); | ||
if (isNaN(boundaryPagesRange)) { | ||
throw new Error('getPaginationModel(): boundaryPagesRange should be a number'); | ||
} | ||
if (boundaryPagesRange < 0) { | ||
throw new Error('getPaginationModel(): boundaryPagesRange shouldn\'t be a negative number'); | ||
} | ||
var siblingPagesRange = (options.siblingPagesRange == null ? 1 : Number(options.siblingPagesRange)); | ||
if (isNaN(siblingPagesRange)) { | ||
throw new Error('getPaginationModel(): siblingPagesRange should be a number'); | ||
} | ||
if (siblingPagesRange < 0) { | ||
throw new Error('getPaginationModel(): siblingPagesRange shouldn\'t be a negative number'); | ||
} | ||
var hidePreviousAndNextPageLinks = Boolean(options.hidePreviousAndNextPageLinks); | ||
var hideFirstAndLastPageLinks = Boolean(options.hideFirstAndLastPageLinks); | ||
var hideEllipsis = Boolean(options.hideEllipsis); | ||
var ellipsisSize = (hideEllipsis ? 0 : 1); | ||
var paginationModel = []; | ||
var createPage = ultimate_pagination_item_factories_1.createPageFunctionFactory(options); | ||
if (!hideFirstAndLastPageLinks) { | ||
paginationModel.push(ultimate_pagination_item_factories_1.createFirstPageLink(options)); | ||
} | ||
if (!hidePreviousAndNextPageLinks) { | ||
paginationModel.push(ultimate_pagination_item_factories_1.createPreviousPageLink(options)); | ||
} | ||
// Simplify generation of pages if number of available items is equal or greater than total pages to show | ||
if (1 + 2 * ellipsisSize + 2 * siblingPagesRange + 2 * boundaryPagesRange >= totalPages) { | ||
var allPages = ultimate_pagination_utils_1.createRange(1, totalPages).map(createPage); | ||
paginationModel.push.apply(paginationModel, allPages); | ||
} | ||
else { | ||
// Calculate group of first pages | ||
var firstPagesStart = 1; | ||
var firstPagesEnd = boundaryPagesRange; | ||
var firstPages = ultimate_pagination_utils_1.createRange(firstPagesStart, firstPagesEnd).map(createPage); | ||
// Calculate group of last pages | ||
var lastPagesStart = totalPages + 1 - boundaryPagesRange; | ||
var lastPagesEnd = totalPages; | ||
var lastPages = ultimate_pagination_utils_1.createRange(lastPagesStart, lastPagesEnd).map(createPage); | ||
// Calculate group of main pages | ||
var mainPagesStart = Math.min(Math.max(currentPage - siblingPagesRange, firstPagesEnd + ellipsisSize + 1), lastPagesStart - ellipsisSize - 2 * siblingPagesRange - 1); | ||
var mainPagesEnd = mainPagesStart + 2 * siblingPagesRange; | ||
var mainPages = ultimate_pagination_utils_1.createRange(mainPagesStart, mainPagesEnd).map(createPage); | ||
// Add group of first pages | ||
paginationModel.push.apply(paginationModel, firstPages); | ||
if (!hideEllipsis) { | ||
// Calculate and add ellipsis before group of main pages | ||
var firstEllipsisPageNumber = mainPagesStart - 1; | ||
var showPageInsteadOfFirstEllipsis = (firstEllipsisPageNumber === firstPagesEnd + 1); | ||
var createFirstEllipsisOrPage = showPageInsteadOfFirstEllipsis ? createPage : ultimate_pagination_item_factories_1.createFirstEllipsis; | ||
var firstEllipsis = createFirstEllipsisOrPage(firstEllipsisPageNumber); | ||
paginationModel.push(firstEllipsis); | ||
} | ||
// Add group of main pages | ||
paginationModel.push.apply(paginationModel, mainPages); | ||
if (!hideEllipsis) { | ||
// Calculate and add ellipsis after group of main pages | ||
var secondEllipsisPageNumber = mainPagesEnd + 1; | ||
var showPageInsteadOfSecondEllipsis = (secondEllipsisPageNumber === lastPagesStart - 1); | ||
var createSecondEllipsisOrPage = showPageInsteadOfSecondEllipsis ? createPage : ultimate_pagination_item_factories_1.createSecondEllipsis; | ||
var secondEllipsis = createSecondEllipsisOrPage(secondEllipsisPageNumber); | ||
paginationModel.push(secondEllipsis); | ||
} | ||
// Add group of last pages | ||
paginationModel.push.apply(paginationModel, lastPages); | ||
} | ||
if (!hidePreviousAndNextPageLinks) { | ||
paginationModel.push(ultimate_pagination_item_factories_1.createNextPageLink(options)); | ||
} | ||
if (!hideFirstAndLastPageLinks) { | ||
paginationModel.push(ultimate_pagination_item_factories_1.createLastPageLink(options)); | ||
} | ||
return paginationModel; | ||
} | ||
exports.getPaginationModel = getPaginationModel; | ||
var ultimate_pagination_constants_1 = __webpack_require__(0); | ||
exports.ITEM_TYPES = ultimate_pagination_constants_1.ITEM_TYPES; | ||
exports.ITEM_KEYS = ultimate_pagination_constants_1.ITEM_KEYS; | ||
//# sourceMappingURL=ultimate-pagination.js.map | ||
/***/ }), | ||
/* 2 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports) { | ||
"use strict"; | ||
var ultimate_pagination_utils_1 = __webpack_require__(3); | ||
var ultimate_pagination_item_factories_1 = __webpack_require__(4); | ||
function getPaginationModel(options) { | ||
var currentPage = options.currentPage, totalPages = options.totalPages; | ||
var paginationModel = []; | ||
var createPage = ultimate_pagination_item_factories_1.createPageFunctionFactory(options); | ||
// Calculate group of central pages | ||
var mainPagesStart = Math.max(2, Math.max(currentPage - 1, 3) - Math.max(0, currentPage + 3 - totalPages)); | ||
var mainPagesEnd = Math.min(totalPages - 1, Math.min(currentPage + 1, totalPages - 2) + Math.max(0, 4 - currentPage)); | ||
var mainPages = ultimate_pagination_utils_1.createRange(mainPagesStart, mainPagesEnd).map(createPage); | ||
paginationModel.push(ultimate_pagination_item_factories_1.createFirstPageLink(options)); | ||
paginationModel.push(ultimate_pagination_item_factories_1.createPreviousPageLink(options)); | ||
// Always add the first page | ||
paginationModel.push(createPage(1)); | ||
// Show '...' or second page between the last page and main pages group if needed | ||
if (mainPagesStart > 3) { | ||
paginationModel.push(ultimate_pagination_item_factories_1.createFirstEllipsis(mainPagesStart - 1)); | ||
} | ||
else if (mainPagesStart !== 2) { | ||
paginationModel.push(createPage(2)); | ||
} | ||
// Add pages +/- from the current page | ||
paginationModel.push.apply(paginationModel, mainPages); | ||
// Show '...' or penult page between main pages group and the last page if needed | ||
if (mainPagesEnd < totalPages - 2) { | ||
paginationModel.push(ultimate_pagination_item_factories_1.createSecondEllipsis(mainPagesEnd + 1)); | ||
} | ||
else if (mainPagesEnd !== totalPages - 1) { | ||
paginationModel.push(createPage(totalPages - 1)); | ||
} | ||
if (totalPages > 1) { | ||
paginationModel.push(createPage(totalPages)); | ||
} | ||
paginationModel.push(ultimate_pagination_item_factories_1.createNextPageLink(options)); | ||
paginationModel.push(ultimate_pagination_item_factories_1.createLastPageLink(options)); | ||
return paginationModel; | ||
} | ||
exports.getPaginationModel = getPaginationModel; | ||
var ultimate_pagination_constants_1 = __webpack_require__(5); | ||
exports.ITEM_TYPES = ultimate_pagination_constants_1.ITEM_TYPES; | ||
exports.ITEM_KEYS = ultimate_pagination_constants_1.ITEM_KEYS; | ||
//# sourceMappingURL=ultimate-pagination.js.map | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_2__; | ||
/***/ }, | ||
/***/ }), | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function createRange(start, end) { | ||
var range = []; | ||
for (var i = start; i <= end; i++) { | ||
range.push(i); | ||
} | ||
return range; | ||
} | ||
exports.createRange = createRange; | ||
//# sourceMappingURL=ultimate-pagination-utils.js.map | ||
"use strict"; | ||
/***/ }, | ||
var ultimate_pagination_constants_1 = __webpack_require__(0); | ||
exports.createFirstEllipsis = function (pageNumber) { | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.ELLIPSIS, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.FIRST_ELLIPSIS, | ||
value: pageNumber, | ||
isActive: false | ||
}; | ||
}; | ||
exports.createSecondEllipsis = function (pageNumber) { | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.ELLIPSIS, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.SECOND_ELLIPSIS, | ||
value: pageNumber, | ||
isActive: false | ||
}; | ||
}; | ||
exports.createFirstPageLink = function (options) { | ||
var currentPage = options.currentPage; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.FIRST_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.FIRST_PAGE_LINK, | ||
value: 1, | ||
isActive: currentPage === 1 | ||
}; | ||
}; | ||
exports.createPreviousPageLink = function (options) { | ||
var currentPage = options.currentPage; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.PREVIOUS_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.PREVIOUS_PAGE_LINK, | ||
value: Math.max(1, currentPage - 1), | ||
isActive: currentPage === 1 | ||
}; | ||
}; | ||
exports.createNextPageLink = function (options) { | ||
var currentPage = options.currentPage, totalPages = options.totalPages; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.NEXT_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.NEXT_PAGE_LINK, | ||
value: Math.min(totalPages, currentPage + 1), | ||
isActive: currentPage === totalPages | ||
}; | ||
}; | ||
exports.createLastPageLink = function (options) { | ||
var currentPage = options.currentPage, totalPages = options.totalPages; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.LAST_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.LAST_PAGE_LINK, | ||
value: totalPages, | ||
isActive: currentPage === totalPages | ||
}; | ||
}; | ||
exports.createPageFunctionFactory = function (options) { | ||
var currentPage = options.currentPage; | ||
return function (pageNumber) { | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.PAGE, | ||
key: pageNumber, | ||
value: pageNumber, | ||
isActive: pageNumber === currentPage | ||
}; | ||
}; | ||
}; | ||
//# sourceMappingURL=ultimate-pagination-item-factories.js.map | ||
/***/ }), | ||
/* 4 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
var ultimate_pagination_constants_1 = __webpack_require__(5); | ||
exports.createFirstEllipsis = function (pageNumber) { | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.ELLIPSIS, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.FIRST_ELLIPSIS, | ||
value: pageNumber, | ||
isActive: false | ||
}; | ||
}; | ||
exports.createSecondEllipsis = function (pageNumber) { | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.ELLIPSIS, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.SECOND_ELLISPIS, | ||
value: pageNumber, | ||
isActive: false | ||
}; | ||
}; | ||
exports.createFirstPageLink = function (options) { | ||
var currentPage = options.currentPage; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.FIRST_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.FIRST_PAGE_LINK, | ||
value: 1, | ||
isActive: currentPage === 1 | ||
}; | ||
}; | ||
exports.createPreviousPageLink = function (options) { | ||
var currentPage = options.currentPage; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.PREVIOUS_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.PREVIOUS_PAGE_LINK, | ||
value: Math.max(1, currentPage - 1), | ||
isActive: currentPage === 1 | ||
}; | ||
}; | ||
exports.createNextPageLink = function (options) { | ||
var currentPage = options.currentPage, totalPages = options.totalPages; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.NEXT_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.NEXT_PAGE_LINK, | ||
value: Math.min(totalPages, currentPage + 1), | ||
isActive: currentPage === totalPages | ||
}; | ||
}; | ||
exports.createLastPageLink = function (options) { | ||
var currentPage = options.currentPage, totalPages = options.totalPages; | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.LAST_PAGE_LINK, | ||
key: ultimate_pagination_constants_1.ITEM_KEYS.LAST_PAGE_LINK, | ||
value: totalPages, | ||
isActive: currentPage === totalPages | ||
}; | ||
}; | ||
exports.createPageFunctionFactory = function (options) { | ||
var currentPage = options.currentPage; | ||
return function (pageNumber) { | ||
return { | ||
type: ultimate_pagination_constants_1.ITEM_TYPES.PAGE, | ||
key: pageNumber, | ||
value: pageNumber, | ||
isActive: pageNumber === currentPage | ||
}; | ||
}; | ||
}; | ||
//# sourceMappingURL=ultimate-pagination-item-factories.js.map | ||
"use strict"; | ||
/***/ }, | ||
function createRange(start, end) { | ||
var range = []; | ||
for (var i = start; i <= end; i++) { | ||
range.push(i); | ||
} | ||
return range; | ||
} | ||
exports.createRange = createRange; | ||
//# sourceMappingURL=ultimate-pagination-utils.js.map | ||
/***/ }), | ||
/* 5 */ | ||
/***/ function(module, exports) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
exports.ITEM_TYPES = { | ||
PAGE: 'PAGE', | ||
ELLIPSIS: 'ELLIPSIS', | ||
FIRST_PAGE_LINK: 'FIRST_PAGE_LINK', | ||
PREVIOUS_PAGE_LINK: 'PREVIOUS_PAGE_LINK', | ||
NEXT_PAGE_LINK: 'NEXT_PAGE_LINK', | ||
LAST_PAGE_LINK: 'LAST_PAGE_LINK' | ||
}; | ||
exports.ITEM_KEYS = { | ||
FIRST_ELLIPSIS: -1, | ||
SECOND_ELLISPIS: -2, | ||
FIRST_PAGE_LINK: -3, | ||
PREVIOUS_PAGE_LINK: -4, | ||
NEXT_PAGE_LINK: -5, | ||
LAST_PAGE_LINK: -6 | ||
}; | ||
//# sourceMappingURL=ultimate-pagination-constants.js.map | ||
"use strict"; | ||
/***/ } | ||
/******/ ]) | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
; | ||
exports.ITEM_TYPES = exports.createUltimatePagination = undefined; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _react = __webpack_require__(2); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _ultimatePagination = __webpack_require__(1); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var renderItemComponentFunctionFactory = function renderItemComponentFunctionFactory(itemTypeToComponent, currentPage, onChange) { | ||
var onItemClickFunctionFactory = function onItemClickFunctionFactory(value) { | ||
return function () { | ||
if (onChange && currentPage !== value) { | ||
onChange(value); | ||
} | ||
}; | ||
}; | ||
return function (item) { | ||
var ItemComponent = itemTypeToComponent[item.type]; | ||
var onItemClick = onItemClickFunctionFactory(item.value); | ||
return _react2.default.createElement(ItemComponent, _extends({ onClick: onItemClick }, item)); | ||
}; | ||
}; | ||
var createUltimatePagination = exports.createUltimatePagination = function createUltimatePagination(_ref) { | ||
var itemTypeToComponent = _ref.itemTypeToComponent, | ||
_ref$WrapperComponent = _ref.WrapperComponent, | ||
WrapperComponent = _ref$WrapperComponent === undefined ? 'div' : _ref$WrapperComponent; | ||
var UltimatePaginationComponent = function UltimatePaginationComponent(props) { | ||
var currentPage = props.currentPage, | ||
totalPages = props.totalPages, | ||
boundaryPagesRange = props.boundaryPagesRange, | ||
siblingPagesRange = props.siblingPagesRange, | ||
hideEllipsis = props.hideEllipsis, | ||
hidePreviousAndNextPageLinks = props.hidePreviousAndNextPageLinks, | ||
hideFirstAndLastPageLinks = props.hideFirstAndLastPageLinks, | ||
onChange = props.onChange; | ||
var paginationModel = (0, _ultimatePagination.getPaginationModel)({ | ||
currentPage: currentPage, | ||
totalPages: totalPages, | ||
boundaryPagesRange: boundaryPagesRange, | ||
siblingPagesRange: siblingPagesRange, | ||
hideEllipsis: hideEllipsis, | ||
hidePreviousAndNextPageLinks: hidePreviousAndNextPageLinks, | ||
hideFirstAndLastPageLinks: hideFirstAndLastPageLinks | ||
}); | ||
var renderItemComponent = renderItemComponentFunctionFactory(itemTypeToComponent, currentPage, onChange); | ||
return _react2.default.createElement( | ||
WrapperComponent, | ||
null, | ||
paginationModel.map(renderItemComponent) | ||
); | ||
}; | ||
UltimatePaginationComponent.propTypes = { | ||
currentPage: _react2.default.PropTypes.number.isRequired, | ||
totalPages: _react2.default.PropTypes.number.isRequired, | ||
boundaryPagesRange: _react2.default.PropTypes.number, | ||
siblingPagesRange: _react2.default.PropTypes.number, | ||
hideEllipsis: _react2.default.PropTypes.bool, | ||
hidePreviousAndNextPageLinks: _react2.default.PropTypes.bool, | ||
hideFirstAndLastPageLinks: _react2.default.PropTypes.bool, | ||
onChange: _react2.default.PropTypes.func | ||
}; | ||
return UltimatePaginationComponent; | ||
}; | ||
exports.ITEM_TYPES = _ultimatePagination.ITEM_TYPES; | ||
/***/ }) | ||
/******/ ]); | ||
}); | ||
//# sourceMappingURL=react-ultimate-pagination.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.reactUltimatePagination=t(require("react")):e.reactUltimatePagination=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.ITEM_TYPES=t.createUltimatePagination=void 0;var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=r(5),u=n(i),o=r(4),c=function(e,t,r){var n=function(e){return function(){r&&t!==e&&r(e)}};return function(t){var r=e[t.type],i=n(t.value);return u.default.createElement(r,a({onClick:i},t))}};t.createUltimatePagination=function(e){var t=e.itemTypeToComponent,r=e.WrapperComponent,n=void 0===r?"div":r,a=function(e){var r=e.currentPage,a=e.totalPages,i=e.onChange,E=(0,o.getPaginationModel)({currentPage:r,totalPages:a}),P=c(t,r,i);return u.default.createElement(n,null,E.map(P))};return a.propTypes={currentPage:u.default.PropTypes.number.isRequired,totalPages:u.default.PropTypes.number.isRequired,onChange:u.default.PropTypes.func},a};t.ITEM_TYPES=o.ITEM_TYPES},function(e,t){"use strict";t.ITEM_TYPES={PAGE:"PAGE",ELLIPSIS:"ELLIPSIS",FIRST_PAGE_LINK:"FIRST_PAGE_LINK",PREVIOUS_PAGE_LINK:"PREVIOUS_PAGE_LINK",NEXT_PAGE_LINK:"NEXT_PAGE_LINK",LAST_PAGE_LINK:"LAST_PAGE_LINK"},t.ITEM_KEYS={FIRST_ELLIPSIS:-1,SECOND_ELLISPIS:-2,FIRST_PAGE_LINK:-3,PREVIOUS_PAGE_LINK:-4,NEXT_PAGE_LINK:-5,LAST_PAGE_LINK:-6}},function(e,t,r){"use strict";var n=r(1);t.createFirstEllipsis=function(e){return{type:n.ITEM_TYPES.ELLIPSIS,key:n.ITEM_KEYS.FIRST_ELLIPSIS,value:e,isActive:!1}},t.createSecondEllipsis=function(e){return{type:n.ITEM_TYPES.ELLIPSIS,key:n.ITEM_KEYS.SECOND_ELLISPIS,value:e,isActive:!1}},t.createFirstPageLink=function(e){var t=e.currentPage;return{type:n.ITEM_TYPES.FIRST_PAGE_LINK,key:n.ITEM_KEYS.FIRST_PAGE_LINK,value:1,isActive:1===t}},t.createPreviousPageLink=function(e){var t=e.currentPage;return{type:n.ITEM_TYPES.PREVIOUS_PAGE_LINK,key:n.ITEM_KEYS.PREVIOUS_PAGE_LINK,value:Math.max(1,t-1),isActive:1===t}},t.createNextPageLink=function(e){var t=e.currentPage,r=e.totalPages;return{type:n.ITEM_TYPES.NEXT_PAGE_LINK,key:n.ITEM_KEYS.NEXT_PAGE_LINK,value:Math.min(r,t+1),isActive:t===r}},t.createLastPageLink=function(e){var t=e.currentPage,r=e.totalPages;return{type:n.ITEM_TYPES.LAST_PAGE_LINK,key:n.ITEM_KEYS.LAST_PAGE_LINK,value:r,isActive:t===r}},t.createPageFunctionFactory=function(e){var t=e.currentPage;return function(e){return{type:n.ITEM_TYPES.PAGE,key:e,value:e,isActive:e===t}}}},function(e,t){"use strict";function r(e,t){for(var r=[],n=e;n<=t;n++)r.push(n);return r}t.createRange=r},function(e,t,r){"use strict";function n(e){var t=e.currentPage,r=e.totalPages,n=[],u=i.createPageFunctionFactory(e),o=Math.max(2,Math.max(t-1,3)-Math.max(0,t+3-r)),c=Math.min(r-1,Math.min(t+1,r-2)+Math.max(0,4-t)),E=a.createRange(o,c).map(u);return n.push(i.createFirstPageLink(e)),n.push(i.createPreviousPageLink(e)),n.push(u(1)),o>3?n.push(i.createFirstEllipsis(o-1)):2!==o&&n.push(u(2)),n.push.apply(n,E),c<r-2?n.push(i.createSecondEllipsis(c+1)):c!==r-1&&n.push(u(r-1)),r>1&&n.push(u(r)),n.push(i.createNextPageLink(e)),n.push(i.createLastPageLink(e)),n}var a=r(3),i=r(2);t.getPaginationModel=n;var u=r(1);t.ITEM_TYPES=u.ITEM_TYPES,t.ITEM_KEYS=u.ITEM_KEYS},function(t,r){t.exports=e}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.reactUltimatePagination=t(require("react")):e.reactUltimatePagination=t(e.React)}(this,function(e){return function(e){function t(a){if(n[a])return n[a].exports;var r=n[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,a){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:a})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t,n){"use strict";t.ITEM_TYPES={PAGE:"PAGE",ELLIPSIS:"ELLIPSIS",FIRST_PAGE_LINK:"FIRST_PAGE_LINK",PREVIOUS_PAGE_LINK:"PREVIOUS_PAGE_LINK",NEXT_PAGE_LINK:"NEXT_PAGE_LINK",LAST_PAGE_LINK:"LAST_PAGE_LINK"},t.ITEM_KEYS={FIRST_ELLIPSIS:-1,SECOND_ELLIPSIS:-2,FIRST_PAGE_LINK:-3,PREVIOUS_PAGE_LINK:-4,NEXT_PAGE_LINK:-5,LAST_PAGE_LINK:-6}},function(e,t,n){"use strict";function a(e){if(null==e)throw new Error("getPaginationModel(): options object should be a passed");var t=Number(e.totalPages);if(isNaN(t))throw new Error("getPaginationModel(): totalPages should be a number");if(t<0)throw new Error("getPaginationModel(): totalPages shouldn't be a negative number");var n=Number(e.currentPage);if(isNaN(n))throw new Error("getPaginationModel(): currentPage should be a number");if(n<0)throw new Error("getPaginationModel(): currentPage shouldn't be a negative number");if(n>t)throw new Error("getPaginationModel(): currentPage shouldn't be greater than totalPages");var a=null==e.boundaryPagesRange?1:Number(e.boundaryPagesRange);if(isNaN(a))throw new Error("getPaginationModel(): boundaryPagesRange should be a number");if(a<0)throw new Error("getPaginationModel(): boundaryPagesRange shouldn't be a negative number");var o=null==e.siblingPagesRange?1:Number(e.siblingPagesRange);if(isNaN(o))throw new Error("getPaginationModel(): siblingPagesRange should be a number");if(o<0)throw new Error("getPaginationModel(): siblingPagesRange shouldn't be a negative number");var u=Boolean(e.hidePreviousAndNextPageLinks),s=Boolean(e.hideFirstAndLastPageLinks),P=Boolean(e.hideEllipsis),g=P?0:1,l=[],c=i.createPageFunctionFactory(e);if(s||l.push(i.createFirstPageLink(e)),u||l.push(i.createPreviousPageLink(e)),1+2*g+2*o+2*a>=t){var E=r.createRange(1,t).map(c);l.push.apply(l,E)}else{var p=1,d=a,f=r.createRange(p,d).map(c),_=t+1-a,I=t,L=r.createRange(_,I).map(c),T=Math.min(Math.max(n-o,d+g+1),_-g-2*o-1),S=T+2*o,v=r.createRange(T,S).map(c);if(l.push.apply(l,f),!P){var b=T-1,h=b===d+1,y=h?c:i.createFirstEllipsis,N=y(b);l.push(N)}if(l.push.apply(l,v),!P){var A=S+1,M=A===_-1,m=M?c:i.createSecondEllipsis,R=m(A);l.push(R)}l.push.apply(l,L)}return u||l.push(i.createNextPageLink(e)),s||l.push(i.createLastPageLink(e)),l}var r=n(4),i=n(3);t.getPaginationModel=a;var o=n(0);t.ITEM_TYPES=o.ITEM_TYPES,t.ITEM_KEYS=o.ITEM_KEYS},function(t,n){t.exports=e},function(e,t,n){"use strict";var a=n(0);t.createFirstEllipsis=function(e){return{type:a.ITEM_TYPES.ELLIPSIS,key:a.ITEM_KEYS.FIRST_ELLIPSIS,value:e,isActive:!1}},t.createSecondEllipsis=function(e){return{type:a.ITEM_TYPES.ELLIPSIS,key:a.ITEM_KEYS.SECOND_ELLIPSIS,value:e,isActive:!1}},t.createFirstPageLink=function(e){var t=e.currentPage;return{type:a.ITEM_TYPES.FIRST_PAGE_LINK,key:a.ITEM_KEYS.FIRST_PAGE_LINK,value:1,isActive:1===t}},t.createPreviousPageLink=function(e){var t=e.currentPage;return{type:a.ITEM_TYPES.PREVIOUS_PAGE_LINK,key:a.ITEM_KEYS.PREVIOUS_PAGE_LINK,value:Math.max(1,t-1),isActive:1===t}},t.createNextPageLink=function(e){var t=e.currentPage,n=e.totalPages;return{type:a.ITEM_TYPES.NEXT_PAGE_LINK,key:a.ITEM_KEYS.NEXT_PAGE_LINK,value:Math.min(n,t+1),isActive:t===n}},t.createLastPageLink=function(e){var t=e.currentPage,n=e.totalPages;return{type:a.ITEM_TYPES.LAST_PAGE_LINK,key:a.ITEM_KEYS.LAST_PAGE_LINK,value:n,isActive:t===n}},t.createPageFunctionFactory=function(e){var t=e.currentPage;return function(e){return{type:a.ITEM_TYPES.PAGE,key:e,value:e,isActive:e===t}}}},function(e,t,n){"use strict";function a(e,t){for(var n=[],a=e;a<=t;a++)n.push(a);return n}t.createRange=a},function(e,t,n){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.ITEM_TYPES=t.createUltimatePagination=void 0;var r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},i=n(2),o=a(i),u=n(1),s=function(e,t,n){var a=function(e){return function(){n&&t!==e&&n(e)}};return function(t){var n=e[t.type],i=a(t.value);return o.default.createElement(n,r({onClick:i},t))}};t.createUltimatePagination=function(e){var t=e.itemTypeToComponent,n=e.WrapperComponent,a=void 0===n?"div":n,r=function(e){var n=e.currentPage,r=e.totalPages,i=e.boundaryPagesRange,P=e.siblingPagesRange,g=e.hideEllipsis,l=e.hidePreviousAndNextPageLinks,c=e.hideFirstAndLastPageLinks,E=e.onChange,p=(0,u.getPaginationModel)({currentPage:n,totalPages:r,boundaryPagesRange:i,siblingPagesRange:P,hideEllipsis:g,hidePreviousAndNextPageLinks:l,hideFirstAndLastPageLinks:c}),d=s(t,n,E);return o.default.createElement(a,null,p.map(d))};return r.propTypes={currentPage:o.default.PropTypes.number.isRequired,totalPages:o.default.PropTypes.number.isRequired,boundaryPagesRange:o.default.PropTypes.number,siblingPagesRange:o.default.PropTypes.number,hideEllipsis:o.default.PropTypes.bool,hidePreviousAndNextPageLinks:o.default.PropTypes.bool,hideFirstAndLastPageLinks:o.default.PropTypes.bool,onChange:o.default.PropTypes.func},r};t.ITEM_TYPES=u.ITEM_TYPES}])}); | ||
//# sourceMappingURL=react-ultimate-pagination.min.js.map |
@@ -39,8 +39,22 @@ 'use strict'; | ||
var UltimatePaginationComponent = function UltimatePaginationComponent(_ref2) { | ||
var currentPage = _ref2.currentPage, | ||
totalPages = _ref2.totalPages, | ||
onChange = _ref2.onChange; | ||
var UltimatePaginationComponent = function UltimatePaginationComponent(props) { | ||
var currentPage = props.currentPage, | ||
totalPages = props.totalPages, | ||
boundaryPagesRange = props.boundaryPagesRange, | ||
siblingPagesRange = props.siblingPagesRange, | ||
hideEllipsis = props.hideEllipsis, | ||
hidePreviousAndNextPageLinks = props.hidePreviousAndNextPageLinks, | ||
hideFirstAndLastPageLinks = props.hideFirstAndLastPageLinks, | ||
onChange = props.onChange; | ||
var paginationModel = (0, _ultimatePagination.getPaginationModel)({ currentPage: currentPage, totalPages: totalPages }); | ||
var paginationModel = (0, _ultimatePagination.getPaginationModel)({ | ||
currentPage: currentPage, | ||
totalPages: totalPages, | ||
boundaryPagesRange: boundaryPagesRange, | ||
siblingPagesRange: siblingPagesRange, | ||
hideEllipsis: hideEllipsis, | ||
hidePreviousAndNextPageLinks: hidePreviousAndNextPageLinks, | ||
hideFirstAndLastPageLinks: hideFirstAndLastPageLinks | ||
}); | ||
var renderItemComponent = renderItemComponentFunctionFactory(itemTypeToComponent, currentPage, onChange); | ||
@@ -57,2 +71,7 @@ return _react2.default.createElement( | ||
totalPages: _react2.default.PropTypes.number.isRequired, | ||
boundaryPagesRange: _react2.default.PropTypes.number, | ||
siblingPagesRange: _react2.default.PropTypes.number, | ||
hideEllipsis: _react2.default.PropTypes.bool, | ||
hidePreviousAndNextPageLinks: _react2.default.PropTypes.bool, | ||
hideFirstAndLastPageLinks: _react2.default.PropTypes.bool, | ||
onChange: _react2.default.PropTypes.func | ||
@@ -59,0 +78,0 @@ }; |
{ | ||
"name": "react-ultimate-pagination", | ||
"version": "0.9.0", | ||
"version": "1.0.0", | ||
"description": "React.js pagination component based on ultimate-pagination", | ||
@@ -39,3 +39,3 @@ "main": "lib/react-ultimate-pagination.js", | ||
"react-dom": "^15.0.1", | ||
"ultimate-pagination": "0.8.0" | ||
"ultimate-pagination": "1.0.0" | ||
}, | ||
@@ -48,5 +48,5 @@ "devDependencies": { | ||
"babel-preset-react": "^6.5.0", | ||
"npm-run-all": "^1.8.0", | ||
"webpack": "^1.13.0" | ||
"npm-run-all": "^4.0.1", | ||
"webpack": "^2.2.1" | ||
} | ||
} |
@@ -106,2 +106,7 @@ [](https://github.com/ultimate-pagination/react-ultimate-pagination) | ||
- **totalPages**: *number* - total number of pages | ||
- **boundaryPagesRange**: *number, optional, default: 1* - number of always visible pages at the beginning and end | ||
- **siblingPagesRange**: *number, optional, default: 1* - number of always visible pages before and after the current one | ||
- **hideEllipsis**: *bool, optional, default: false* - boolean flag to hide ellipsis | ||
- **hidePreviousAndNextPageLinks**: *bool, optional, default: false* - boolean flag to hide previous and next page links | ||
- **hideFirstAndLastPageLink**: *bool, optional, default: false* - boolean flag to hide first and last page links | ||
- **onChange**: *function* - callback that will be called with new page when it should be changed by user interaction (*optional*) | ||
@@ -108,0 +113,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
91489
452
1
116
1
+ Addedultimate-pagination@1.0.0(transitive)
- Removedultimate-pagination@0.8.0(transitive)
Updatedultimate-pagination@1.0.0