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) • 18.1 kB
JavaScript
import{DomHandler as e,UniqueComponentId as t}from"primevue/utils";import a from"primevue/basecomponent";import n 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/dropdown";import C from"primevue/inputnumber";import T from"primevue/icons/angledoubleright";import A from"primevue/icons/angleright";import I from"primevue/icons/angleleft";var N={name:"BasePaginator",extends:a,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:n,provide:function(){return{$parentInstance:this}}},O={name:"CurrentPageReport",hostName:"Paginator",extends:a,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}}};O.render=function(e,t,a,n,l,p){return r(),o("span",i({class:e.cx("current")},e.ptm("current")),s(p.text),17)};var S={name:"FirstPageLink",hostName:"Paginator",extends:a,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}};S.render=function(e,t,a,n,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("firstPageButton"),type:"button"},g.getPTOptions("firstPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(a.template||"AngleDoubleLeftIcon"),i({class:e.cx("firstPageIcon")},g.getPTOptions("firstPageIcon")),null,16,["class"]))],16)),[[d]])};var $={name:"JumpToPageDropdown",hostName:"Paginator",extends:a,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:{JTPDropdown:x}};$.render=function(e,t,a,n,o,i){var s=g("JTPDropdown");return r(),u(s,{modelValue:a.page,options:i.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":t[0]||(t[0]=function(e){return i.onChange(e)}),class:d(e.cx("jumpToPageDropdown")),disabled:a.disabled,unstyled:e.unstyled,pt:e.ptm("jumpToPageDropdown"),"data-pc-section":"jumptopagedropdown","data-pc-group-section":"pagedropdown"},m({_:2},[a.templates.jumptopagedropdownicon?{name:"dropdownicon",fn:f((function(e){return[(r(),u(c(a.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:a,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,a,n,o,i){var s=g("JTPInput");return r(),u(s,{ref:"jtpInput",modelValue:o.d_page,class:d(e.cx("jumpToPageInput")),"aria-label":i.inputArialabel,disabled:a.disabled,"onUpdate:modelValue":i.onChange,unstyled:e.unstyled,pt:e.ptm("jumpToPageInput"),"data-pc-section":"jumptopageinput"},null,8,["modelValue","class","aria-label","disabled","onUpdate:modelValue","unstyled","pt"])};var D={name:"LastPageLink",hostName:"Paginator",extends:a,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}};D.render=function(e,t,a,n,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("lastPageButton"),type:"button"},g.getPTOptions("lastPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(a.template||"AngleDoubleRightIcon"),i({class:e.cx("lastPageIcon")},g.getPTOptions("lastPageIcon")),null,16,["class"]))],16)),[[d]])};var _={name:"NextPageLink",hostName:"Paginator",extends:a,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},components:{AngleRightIcon:A},directives:{ripple:L}};_.render=function(e,t,a,n,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("nextPageButton"),type:"button"},g.getPTOptions("nextPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(a.template||"AngleRightIcon"),i({class:e.cx("nextPageIcon")},g.getPTOptions("nextPageIcon")),null,16,["class"]))],16)),[[d]])};var j={name:"PageLinks",hostName:"Paginator",extends:a,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}},B=["aria-label","aria-current","onClick","data-p-highlight"];j.render=function(e,t,a,n,u,c){var g=l("ripple");return r(),o("span",i({class:e.cx("pages")},e.ptm("pages")),[(r(!0),o(h,null,P(a.value,(function(t){return p((r(),o("button",i({key:t,class:e.cx("pageButton",{pageLink:t}),type:"button","aria-label":c.ariaPageLabel(t),"aria-current":t-1===a.page?"page":void 0,onClick:function(e){return c.onPageLinkClick(e,t)}},c.getPTOptions(t-1,"pageButton"),{"data-p-highlight":t-1===a.page}),[b(s(t),1)],16,B)),[[g]])})),128))],16)};var F={name:"PrevPageLink",hostName:"Paginator",extends:a,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},components:{AngleLeftIcon:I},directives:{ripple:L}};F.render=function(e,t,a,n,s,g){var d=l("ripple");return p((r(),o("button",i({class:e.cx("previousPageButton"),type:"button"},g.getPTOptions("previousPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(c(a.template||"AngleLeftIcon"),i({class:e.cx("previousPageIcon")},g.getPTOptions("previousPageIcon")),null,16,["class"]))],16)),[[d]])};var E={name:"RowsPerPageDropdown",hostName:"Paginator",extends:a,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:{RPPDropdown:x}};function J(){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 V(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function M(e){if(Array.isArray(e))return q(e)}function U(e){return U="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},U(e)}function z(e,t){return K(e)||G(e,t)||W(e,t)||H()}function H(){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 W(e,t){if(e){if("string"==typeof e)return q(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?q(e,t):void 0}}function q(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function G(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var n,r,o,i,s=[],l=!0,p=!1;try{if(o=(a=a.call(e)).next,0===t){if(Object(a)!==a)return;l=!1}else for(;!(l=(n=o.call(a)).done)&&(s.push(n.value),s.length!==t);l=!0);}catch(e){p=!0,r=e}finally{try{if(!l&&null!=a.return&&(i=a.return(),Object(i)!==i))return}finally{if(p)throw r}}return s}}function K(e){if(Array.isArray(e))return e}E.render=function(e,t,a,n,o,i){var s=g("RPPDropdown");return r(),u(s,{modelValue:a.rows,options:i.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":t[0]||(t[0]=function(e){return i.onChange(e)}),class:d(e.cx("rowPerPageDropdown")),disabled:a.disabled,unstyled:e.unstyled,pt:e.ptm("rowPerPageDropdown"),"data-pc-section":"rowperpagedropdown","data-pc-group-section":"pagedropdown"},m({_:2},[a.templates.rowsperpagedropdownicon?{name:"dropdownicon",fn:f((function(e){return[(r(),u(c(a.templates.rowsperpagedropdownicon),{class:d(e.class)},null,8,["class"]))]})),key:"0"}:void 0]),1032,["modelValue","options","class","disabled","unstyled","pt"])};var Q={name:"Paginator",extends:N,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 a={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",a)}},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 a;this.styleElement=document.createElement("style"),this.styleElement.type="text/css",e.setAttribute(this.styleElement,"nonce",null===(a=this.$primevue)||void 0===a||null===(a=a.config)||void 0===a||null===(a=a.csp)||void 0===a?void 0:a.nonce),document.head.appendChild(this.styleElement);var n="",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=z(s[i],2),u=p[0],c=z(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,")"):"",n+="default"===c?"\n @media screen ".concat(l," {\n .paginator[").concat(this.attributeSelector,"],\n .p-paginator-default{\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=n}},hasBreakpoints:function(){return"object"===U(this.template)},setPaginatorAttribute:function(){var e,t=this;this.$refs.paginator&&this.$refs.paginator.length>=0&&(e=this.$refs.paginator,M(e)||V(e)||W(e)||J()).forEach((function(e){e.setAttribute(t.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),a=Math.max(0,Math.ceil(this.page-t/2)),n=Math.min(e-1,a+t-1);return[a=Math.max(0,a-(this.pageLinkSize-(n-a+1))),n]},pageLinks:function(){for(var e=[],t=this.calculatePageLinkBoundaries,a=t[1],n=t[0];n<=a;n++)e.push(n+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:O,FirstPageLink:S,LastPageLink:D,NextPageLink:_,PageLinks:j,PrevPageLink:F,RowsPerPageDropdown:E,JumpToPageDropdown:$,JumpToPageInput:R}};Q.render=function(e,t,a,n,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.ptm("paginatorWrapper"))),[(r(!0),o(h,null,P(l.templateItems,(function(a,n){return r(),o("div",i({key:n,ref_for:!0,ref:"paginator",class:e.cx("paginator",{key:n})},e.ptm("root"),{"data-pc-name":"paginator"}),[e.$slots.start?(r(),o("div",i({key:0,class:e.cx("start")},e.ptm("start")),[v(e.$slots,"start",{state:l.currentState})],16)):w("",!0),(r(!0),o(h,null,P(a,(function(a){return r(),o(h,{key:a},["FirstPageLink"===a?(r(),u(p,{key:0,"aria-label":l.getAriaLabel("firstPageLabel"),template: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"===a?(r(),u(c,{key:1,"aria-label":l.getAriaLabel("prevPageLabel"),template: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"===a?(r(),u(d,{key:2,"aria-label":l.getAriaLabel("nextPageLabel"),template: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"===a?(r(),u(m,{key:3,"aria-label":l.getAriaLabel("lastPageLabel"),template: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"===a?(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"===a?(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"===a&&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"===a?(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"===a?(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("end")},e.ptm("end")),[v(e.$slots,"end",{state:l.currentState})],16)):w("",!0)],16)})),128))],16)):w("",!0)};export{Q as default};