UNPKG

ultimate-pagination

Version:

Universal pagination model generation algorithm that can be used to build a UI component

2 lines 4.31 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ultimatePagination=t():e.ultimatePagination=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},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=3)}([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";var r=n(0);t.createFirstEllipsis=function(e){return{type:r.ITEM_TYPES.ELLIPSIS,key:r.ITEM_KEYS.FIRST_ELLIPSIS,value:e,isActive:!1}},t.createSecondEllipsis=function(e){return{type:r.ITEM_TYPES.ELLIPSIS,key:r.ITEM_KEYS.SECOND_ELLIPSIS,value:e,isActive:!1}},t.createFirstPageLink=function(e){var t=e.currentPage;return{type:r.ITEM_TYPES.FIRST_PAGE_LINK,key:r.ITEM_KEYS.FIRST_PAGE_LINK,value:1,isActive:1===t}},t.createPreviousPageLink=function(e){var t=e.currentPage;return{type:r.ITEM_TYPES.PREVIOUS_PAGE_LINK,key:r.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:r.ITEM_TYPES.NEXT_PAGE_LINK,key:r.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:r.ITEM_TYPES.LAST_PAGE_LINK,key:r.ITEM_KEYS.LAST_PAGE_LINK,value:n,isActive:t===n}},t.createPageFunctionFactory=function(e){var t=e.currentPage;return function(e){return{type:r.ITEM_TYPES.PAGE,key:e,value:e,isActive:e===t}}}},function(e,t,n){"use strict";function r(e,t){for(var n=[],r=e;r<=t;r++)n.push(r);return n}t.createRange=r},function(e,t,n){"use strict";function r(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 r=null==e.boundaryPagesRange?1:Number(e.boundaryPagesRange);if(isNaN(r))throw new Error("getPaginationModel(): boundaryPagesRange should be a number");if(r<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),P=Boolean(e.hideFirstAndLastPageLinks),s=Boolean(e.hideEllipsis),E=s?0:1,g=[],c=i.createPageFunctionFactory(e);if(P||g.push(i.createFirstPageLink(e)),u||g.push(i.createPreviousPageLink(e)),1+2*E+2*o+2*r>=t){var l=a.createRange(1,t).map(c);g.push.apply(g,l)}else{var I=1,_=r,S=a.createRange(I,_).map(c),p=t+1-r,L=t,f=a.createRange(p,L).map(c),T=Math.min(Math.max(n-o,_+E+1),p-E-2*o-1),d=T+2*o,v=a.createRange(T,d).map(c);if(g.push.apply(g,S),!s){var N=T-1,h=N===_+1,b=h?c:i.createFirstEllipsis,A=b(N);g.push(A)}if(g.push.apply(g,v),!s){var M=d+1,y=M===p-1,K=y?c:i.createSecondEllipsis,m=K(M);g.push(m)}g.push.apply(g,f)}return u||g.push(i.createNextPageLink(e)),P||g.push(i.createLastPageLink(e)),g}var a=n(2),i=n(1);t.getPaginationModel=r;var o=n(0);t.ITEM_TYPES=o.ITEM_TYPES,t.ITEM_KEYS=o.ITEM_KEYS}])}); //# sourceMappingURL=ultimate-pagination.min.js.map