primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 17.9 kB
JavaScript
import{DomHandler as e,UniqueComponentId as t}from"primevue/utils";import n from"primevue/basecomponent";import a from"primevue/paginator/style";import{openBlock as r,createElementBlock as o,mergeProps as i,toDisplayString as s,resolveDirective as l,withDirectives as p,createBlock as u,resolveDynamicComponent as c,resolveComponent as g,normalizeClass as d,createSlots as m,withCtx as f,Fragment as h,renderList as P,createTextVNode as b,normalizeProps as y,renderSlot as v,createCommentVNode as w}from"vue";import k from"primevue/icons/angledoubleleft";import L from"primevue/ripple";import x from"primevue/select";import C from"primevue/inputnumber";import T from"primevue/icons/angledoubleright";import S from"primevue/icons/angleright";import $ from"primevue/icons/angleleft";var A={name:"BasePaginator",extends:n,props:{totalRecords:{type:Number,default:0},rows:{type:Number,default:0},first:{type:Number,default:0},pageLinkSize:{type:Number,default:5},rowsPerPageOptions:{type:Array,default:null},template:{type:[Object,String],default:"FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"},currentPageReportTemplate:{type:null,default:"({currentPage} of {totalPages})"},alwaysShow:{type:Boolean,default:!0}},style:a,provide:function(){return{$pcPaginator:this,$parentInstance:this}}},I={name:"CurrentPageReport",hostName:"Paginator",extends:n,props:{pageCount:{type:Number,default:0},currentPage:{type:Number,default:0},page:{type:Number,default:0},first:{type:Number,default:0},rows:{type:Number,default:0},totalRecords:{type:Number,default:0},template:{type:String,default:"({currentPage} of {totalPages})"}},computed:{text:function(){var e=this.template.replace("{currentPage}",this.currentPage).replace("{totalPages}",this.pageCount).replace("{first}",this.pageCount>0?this.first+1:0).replace("{last}",Math.min(this.first+this.rows,this.totalRecords)).replace("{rows}",this.rows).replace("{totalRecords}",this.totalRecords);return e}}};I.render=function(e,t,n,a,l,p){return r(),o("span",i({class:e.cx("current")},e.ptm("current")),s(p.text),17)};var N={name:"FirstPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},components:{AngleDoubleLeftIcon:k},directives:{ripple:L}};N.render=function(e,t,n,a,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("first"),type:"button"},g.getPTOptions("first"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(n.template||"AngleDoubleLeftIcon"),i({class:e.cx("firstIcon")},g.getPTOptions("firstIcon")),null,16,["class"]))],16)),[[d]])};var O={name:"JumpToPageDropdown",hostName:"Paginator",extends:n,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean,templates:null},methods:{onChange:function(e){this.$emit("page-change",e)}},computed:{pageOptions:function(){for(var e=[],t=0;t<this.pageCount;t++)e.push({label:String(t+1),value:t});return e}},components:{JTPSelect:x}};O.render=function(e,t,n,a,o,i){var s=g("JTPSelect");return r(),u(s,{modelValue:n.page,options:i.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":t[0]||(t[0]=function(e){return i.onChange(e)}),class:d(e.cx("pcJumpToPageDropdown")),disabled:n.disabled,unstyled:e.unstyled,pt:e.ptm("pcJumpToPageDropdown"),"data-pc-group-section":"pagedropdown"},m({_:2},[n.templates.jumptopagedropdownicon?{name:"dropdownicon",fn:f((function(e){return[(r(),u(c(n.templates.jumptopagedropdownicon),{class:d(e.class)},null,8,["class"]))]})),key:"0"}:void 0]),1032,["modelValue","options","class","disabled","unstyled","pt"])};var R={name:"JumpToPageInput",hostName:"Paginator",extends:n,inheritAttrs:!1,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean},data:function(){return{d_page:this.page}},watch:{page:function(e){this.d_page=e}},methods:{onChange:function(e){e!==this.page&&(this.d_page=e,this.$emit("page-change",e-1))}},computed:{inputArialabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.jumpToPageInputLabel:void 0}},components:{JTPInput:C}};R.render=function(e,t,n,a,o,i){var s=g("JTPInput");return r(),u(s,{ref:"jtpInput",modelValue:o.d_page,class:d(e.cx("pcJumpToPageInput")),"aria-label":i.inputArialabel,disabled:n.disabled,"onUpdate:modelValue":i.onChange,unstyled:e.unstyled,pt:e.ptm("pcJumpToPageInput")},null,8,["modelValue","class","aria-label","disabled","onUpdate:modelValue","unstyled","pt"])};var _={name:"LastPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},components:{AngleDoubleRightIcon:T},directives:{ripple:L}};_.render=function(e,t,n,a,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("last"),type:"button"},g.getPTOptions("last"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(n.template||"AngleDoubleRightIcon"),i({class:e.cx("lastIcon")},g.getPTOptions("lastIcon")),null,16,["class"]))],16)),[[d]])};var D={name:"NextPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},components:{AngleRightIcon:S},directives:{ripple:L}};D.render=function(e,t,n,a,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("next"),type:"button"},g.getPTOptions("next"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(n.template||"AngleRightIcon"),i({class:e.cx("nextIcon")},g.getPTOptions("nextIcon")),null,16,["class"]))],16)),[[d]])};var j={name:"PageLinks",hostName:"Paginator",extends:n,inheritAttrs:!1,emits:["click"],props:{value:Array,page:Number},methods:{getPTOptions:function(e,t){return this.ptm(t,{context:{active:e===this.page}})},onPageLinkClick:function(e,t){this.$emit("click",{originalEvent:e,value:t})},ariaPageLabel:function(e){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.pageLabel.replace(/{page}/g,e):void 0}},directives:{ripple:L}},F=["aria-label","aria-current","onClick","data-p-highlight"];j.render=function(e,t,n,a,u,c){var g=l("ripple");return r(),o("span",i({class:e.cx("pages")},e.ptm("pages")),[(r(!0),o(h,null,P(n.value,(function(t){return p((r(),o("button",i({key:t,class:e.cx("page",{pageLink:t}),type:"button","aria-label":c.ariaPageLabel(t),"aria-current":t-1===n.page?"page":void 0,onClick:function(e){return c.onPageLinkClick(e,t)},ref_for:!0},c.getPTOptions(t-1,"page"),{"data-p-highlight":t-1===n.page}),[b(s(t),1)],16,F)),[[g]])})),128))],16)};var J={name:"PrevPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},components:{AngleLeftIcon:$},directives:{ripple:L}};J.render=function(e,t,n,a,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("prev"),type:"button"},g.getPTOptions("prev"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(n.template||"AngleLeftIcon"),i({class:e.cx("prevIcon")},g.getPTOptions("prevIcon")),null,16,["class"]))],16)),[[d]])};var E={name:"RowsPerPageDropdown",hostName:"Paginator",extends:n,emits:["rows-change"],props:{options:Array,rows:Number,disabled:Boolean,templates:null},methods:{onChange:function(e){this.$emit("rows-change",e)}},computed:{rowsOptions:function(){var e=[];if(this.options)for(var t=0;t<this.options.length;t++)e.push({label:String(this.options[t]),value:this.options[t]});return e}},components:{RPPSelect:x}};function V(e){return function(e){if(Array.isArray(e))return z(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||U(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function B(e){return B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},B(e)}function M(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var a,r,o,i,s=[],l=!0,p=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(a=o.call(n)).done)&&(s.push(a.value),s.length!==t);l=!0);}catch(e){p=!0,r=e}finally{try{if(!l&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(p)throw r}}return s}}(e,t)||U(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e,t){if(e){if("string"==typeof e)return z(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?z(e,t):void 0}}function z(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}E.render=function(e,t,n,a,o,i){var s=g("RPPSelect");return r(),u(s,{modelValue:n.rows,options:i.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":t[0]||(t[0]=function(e){return i.onChange(e)}),class:d(e.cx("pcRowPerPageDropdown")),disabled:n.disabled,unstyled:e.unstyled,pt:e.ptm("pcRowPerPageDropdown"),"data-pc-group-section":"pagedropdown"},m({_:2},[n.templates.rowsperpagedropdownicon?{name:"dropdownicon",fn:f((function(e){return[(r(),u(c(n.templates.rowsperpagedropdownicon),{class:d(e.class)},null,8,["class"]))]})),key:"0"}:void 0]),1032,["modelValue","options","class","disabled","unstyled","pt"])};var H={name:"Paginator",extends:A,inheritAttrs:!1,emits:["update:first","update:rows","page"],data:function(){return{d_first:this.first,d_rows:this.rows}},watch:{first:function(e){this.d_first=e},rows:function(e){this.d_rows=e},totalRecords:function(e){this.page>0&&e&&this.d_first>=e&&this.changePage(this.pageCount-1)}},mounted:function(){this.setPaginatorAttribute(),this.createStyle()},methods:{changePage:function(e){var t=this.pageCount;if(e>=0&&e<t){this.d_first=this.d_rows*e;var n={page:e,first:this.d_first,rows:this.d_rows,pageCount:t};this.$emit("update:first",this.d_first),this.$emit("update:rows",this.d_rows),this.$emit("page",n)}},changePageToFirst:function(e){this.isFirstPage||this.changePage(0),e.preventDefault()},changePageToPrev:function(e){this.changePage(this.page-1),e.preventDefault()},changePageLink:function(e){this.changePage(e.value-1),e.originalEvent.preventDefault()},changePageToNext:function(e){this.changePage(this.page+1),e.preventDefault()},changePageToLast:function(e){this.isLastPage||this.changePage(this.pageCount-1),e.preventDefault()},onRowChange:function(e){this.d_rows=e,this.changePage(this.page)},createStyle:function(){var t=this;if(this.hasBreakpoints()&&!this.isUnstyled){var n;this.styleElement=document.createElement("style"),this.styleElement.type="text/css",e.setAttribute(this.styleElement,"nonce",null===(n=this.$primevue)||void 0===n||null===(n=n.config)||void 0===n||null===(n=n.csp)||void 0===n?void 0:n.nonce),document.head.appendChild(this.styleElement);var a="",r=Object.keys(this.template),o={};r.sort((function(e,t){return parseInt(e)-parseInt(t)})).forEach((function(e){o[e]=t.template[e]}));for(var i=0,s=Object.entries(Object.entries(o));i<s.length;i++){var l,p=M(s[i],2),u=p[0],c=M(p[1],1)[0],g=void 0;g="default"!==c&&"string"==typeof Object.keys(o)[u-1]?Number(Object.keys(o)[u-1].slice(0,-2))+1+"px":Object.keys(o)[u-1],l=Object.entries(o)[u-1]?"and (min-width:".concat(g,")"):"",a+="default"===c?"\n @media screen ".concat(l," {\n .paginator[").concat(this.attributeSelector,"],\n display: flex;\n }\n }\n "):"\n.paginator[".concat(this.attributeSelector,"], .p-paginator-").concat(c," {\n display: none;\n}\n@media screen ").concat(l," and (max-width: ").concat(c,") {\n .paginator[").concat(this.attributeSelector,"], .p-paginator-").concat(c," {\n display: flex;\n }\n .paginator[").concat(this.attributeSelector,"],\n .p-paginator-default{\n display: none;\n }\n}\n ")}this.styleElement.innerHTML=a}},hasBreakpoints:function(){return"object"===B(this.template)},setPaginatorAttribute:function(){var e=this;this.$refs.paginator&&this.$refs.paginator.length>=0&&V(this.$refs.paginator).forEach((function(t){t.setAttribute(e.attributeSelector,"")}))},getAriaLabel:function(e){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria[e]:void 0}},computed:{templateItems:function(){var e={};if(this.hasBreakpoints()){for(var t in(e=this.template).default||(e.default="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"),e)e[t]=this.template[t].split(" ").map((function(e){return e.trim()}));return e}return e.default=this.template.split(" ").map((function(e){return e.trim()})),e},page:function(){return Math.floor(this.d_first/this.d_rows)},pageCount:function(){return Math.ceil(this.totalRecords/this.d_rows)},isFirstPage:function(){return 0===this.page},isLastPage:function(){return this.page===this.pageCount-1},calculatePageLinkBoundaries:function(){var e=this.pageCount,t=Math.min(this.pageLinkSize,e),n=Math.max(0,Math.ceil(this.page-t/2)),a=Math.min(e-1,n+t-1);return[n=Math.max(0,n-(this.pageLinkSize-(a-n+1))),a]},pageLinks:function(){for(var e=[],t=this.calculatePageLinkBoundaries,n=t[1],a=t[0];a<=n;a++)e.push(a+1);return e},currentState:function(){return{page:this.page,first:this.d_first,rows:this.d_rows}},empty:function(){return 0===this.pageCount},currentPage:function(){return this.pageCount>0?this.page+1:0},attributeSelector:function(){return t()}},components:{CurrentPageReport:I,FirstPageLink:N,LastPageLink:_,NextPageLink:D,PageLinks:j,PrevPageLink:J,RowsPerPageDropdown:E,JumpToPageDropdown:O,JumpToPageInput:R}};H.render=function(e,t,n,a,s,l){var p=g("FirstPageLink"),c=g("PrevPageLink"),d=g("NextPageLink"),m=g("LastPageLink"),f=g("PageLinks"),b=g("CurrentPageReport"),k=g("RowsPerPageDropdown"),L=g("JumpToPageDropdown"),x=g("JumpToPageInput");return e.alwaysShow||l.pageLinks&&l.pageLinks.length>1?(r(),o("nav",y(i({key:0},e.ptmi("paginatorContainer"))),[(r(!0),o(h,null,P(l.templateItems,(function(n,a){return r(),o("div",i({key:a,ref_for:!0,ref:"paginator",class:e.cx("paginator",{key:a})},e.ptm("root")),[e.$slots.start?(r(),o("div",i({key:0,class:e.cx("contentStart"),ref_for:!0},e.ptm("contentStart")),[v(e.$slots,"start",{state:l.currentState})],16)):w("",!0),(r(!0),o(h,null,P(n,(function(n){return r(),o(h,{key:n},["FirstPageLink"===n?(r(),u(p,{key:0,"aria-label":l.getAriaLabel("firstPageLabel"),template:e.$slots.firsticon||e.$slots.firstpagelinkicon,onClick:t[0]||(t[0]=function(e){return l.changePageToFirst(e)}),disabled:l.isFirstPage||l.empty,unstyled:e.unstyled,pt:e.pt},null,8,["aria-label","template","disabled","unstyled","pt"])):"PrevPageLink"===n?(r(),u(c,{key:1,"aria-label":l.getAriaLabel("prevPageLabel"),template:e.$slots.previcon||e.$slots.prevpagelinkicon,onClick:t[1]||(t[1]=function(e){return l.changePageToPrev(e)}),disabled:l.isFirstPage||l.empty,unstyled:e.unstyled,pt:e.pt},null,8,["aria-label","template","disabled","unstyled","pt"])):"NextPageLink"===n?(r(),u(d,{key:2,"aria-label":l.getAriaLabel("nextPageLabel"),template:e.$slots.nexticon||e.$slots.nextpagelinkicon,onClick:t[2]||(t[2]=function(e){return l.changePageToNext(e)}),disabled:l.isLastPage||l.empty,unstyled:e.unstyled,pt:e.pt},null,8,["aria-label","template","disabled","unstyled","pt"])):"LastPageLink"===n?(r(),u(m,{key:3,"aria-label":l.getAriaLabel("lastPageLabel"),template:e.$slots.lasticon||e.$slots.lastpagelinkicon,onClick:t[3]||(t[3]=function(e){return l.changePageToLast(e)}),disabled:l.isLastPage||l.empty,unstyled:e.unstyled,pt:e.pt},null,8,["aria-label","template","disabled","unstyled","pt"])):"PageLinks"===n?(r(),u(f,{key:4,"aria-label":l.getAriaLabel("pageLabel"),value:l.pageLinks,page:l.page,onClick:t[4]||(t[4]=function(e){return l.changePageLink(e)}),pt:e.pt},null,8,["aria-label","value","page","pt"])):"CurrentPageReport"===n?(r(),u(b,{key:5,"aria-live":"polite",template:e.currentPageReportTemplate,currentPage:l.currentPage,page:l.page,pageCount:l.pageCount,first:s.d_first,rows:s.d_rows,totalRecords:e.totalRecords,unstyled:e.unstyled,pt:e.pt},null,8,["template","currentPage","page","pageCount","first","rows","totalRecords","unstyled","pt"])):"RowsPerPageDropdown"===n&&e.rowsPerPageOptions?(r(),u(k,{key:6,"aria-label":l.getAriaLabel("rowsPerPageLabel"),rows:s.d_rows,options:e.rowsPerPageOptions,onRowsChange:t[5]||(t[5]=function(e){return l.onRowChange(e)}),disabled:l.empty,templates:e.$slots,unstyled:e.unstyled,pt:e.pt},null,8,["aria-label","rows","options","disabled","templates","unstyled","pt"])):"JumpToPageDropdown"===n?(r(),u(L,{key:7,"aria-label":l.getAriaLabel("jumpToPageDropdownLabel"),page:l.page,pageCount:l.pageCount,onPageChange:t[6]||(t[6]=function(e){return l.changePage(e)}),disabled:l.empty,templates:e.$slots,unstyled:e.unstyled,pt:e.pt},null,8,["aria-label","page","pageCount","disabled","templates","unstyled","pt"])):"JumpToPageInput"===n?(r(),u(x,{key:8,page:l.currentPage,onPageChange:t[7]||(t[7]=function(e){return l.changePage(e)}),disabled:l.empty,unstyled:e.unstyled,pt:e.pt},null,8,["page","disabled","unstyled","pt"])):w("",!0)],64)})),128)),e.$slots.end?(r(),o("div",i({key:1,class:e.cx("contentEnd"),ref_for:!0},e.ptm("contentEnd")),[v(e.$slots,"end",{state:l.currentState})],16)):w("",!0)],16)})),128))],16)):w("",!0)};export{H as default};