primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 17.3 kB
JavaScript
"use strict";var e=require("primevue/basecomponent"),t=require("primevue/utils"),a=require("vue"),n=require("primevue/icons/angledoubleleft"),o=require("primevue/ripple"),r=require("primevue/dropdown"),i=require("primevue/inputnumber"),s=require("primevue/icons/angledoubleright"),l=require("primevue/icons/angleright"),p=require("primevue/icons/angleleft");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=g(e),u=g(n),d=g(o),m=g(r),h=g(i),P=g(s),f=g(l),k=g(p),b={name:"CurrentPageReport",extends:c.default,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(){return 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)}}};b.render=function(e,t,n,o,r,i){return a.openBlock(),a.createElementBlock("span",a.mergeProps({class:"p-paginator-current"},e.ptm("current")),a.toDisplayString(i.text),17)};var v={name:"FirstPageLink",extends:c.default,props:{template:{type:Function,default:null}},methods:{getPTOptions(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},computed:{containerClass(){return["p-paginator-first p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},components:{AngleDoubleLeftIcon:u.default},directives:{ripple:d.default}};v.render=function(e,t,n,o,r,i){const s=a.resolveDirective("ripple");return a.withDirectives((a.openBlock(),a.createElementBlock("button",a.mergeProps({class:i.containerClass,type:"button"},i.getPTOptions("firstPageButton")),[(a.openBlock(),a.createBlock(a.resolveDynamicComponent(n.template||"AngleDoubleLeftIcon"),a.mergeProps({class:"p-paginator-icon"},i.getPTOptions("firstPageIcon")),null,16))],16)),[[s]])};var y={name:"JumpToPageDropdown",extends:c.default,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean},methods:{onChange(e){this.$emit("page-change",e)}},computed:{pageOptions(){let e=[];for(let t=0;t<this.pageCount;t++)e.push({label:String(t+1),value:t});return e}},components:{JTPDropdown:m.default}};y.render=function(e,t,n,o,r,i){const s=a.resolveComponent("JTPDropdown");return a.openBlock(),a.createBlock(s,{modelValue:n.page,options:i.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":t[0]||(t[0]=e=>i.onChange(e)),class:"p-paginator-page-options",disabled:n.disabled,pt:e.ptm("JTPDropdown")},null,8,["modelValue","options","disabled","pt"])};var L={name:"JumpToPageInput",extends:c.default,inheritAttrs:!1,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean},data(){return{d_page:this.page}},watch:{page(e){this.d_page=e}},methods:{onChange(e){e!==this.page&&(this.d_page=e,this.$emit("page-change",e-1))}},computed:{inputArialabel(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.jumpToPageInputLabel:void 0}},components:{JTPInput:h.default}};L.render=function(e,t,n,o,r,i){const s=a.resolveComponent("JTPInput");return a.openBlock(),a.createBlock(s,{ref:"jtpInput",modelValue:r.d_page,class:"p-paginator-page-input","aria-label":i.inputArialabel,disabled:n.disabled,"onUpdate:modelValue":i.onChange,pt:e.ptm("JTPInput")},null,8,["modelValue","aria-label","disabled","onUpdate:modelValue","pt"])};var C={name:"LastPageLink",extends:c.default,props:{template:{type:Function,default:null}},methods:{getPTOptions(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},computed:{containerClass(){return["p-paginator-last p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},components:{AngleDoubleRightIcon:P.default},directives:{ripple:d.default}};C.render=function(e,t,n,o,r,i){const s=a.resolveDirective("ripple");return a.withDirectives((a.openBlock(),a.createElementBlock("button",a.mergeProps({class:i.containerClass,type:"button"},i.getPTOptions("lastPageButton")),[(a.openBlock(),a.createBlock(a.resolveDynamicComponent(n.template||"AngleDoubleRightIcon"),a.mergeProps({class:"p-paginator-icon"},i.getPTOptions("lastPageIcon")),null,16))],16)),[[s]])};var B={name:"NextPageLink",extends:c.default,props:{template:{type:Function,default:null}},methods:{getPTOptions(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},computed:{containerClass(){return["p-paginator-next p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},components:{AngleRightIcon:f.default},directives:{ripple:d.default}};B.render=function(e,t,n,o,r,i){const s=a.resolveDirective("ripple");return a.withDirectives((a.openBlock(),a.createElementBlock("button",a.mergeProps({class:i.containerClass,type:"button"},i.getPTOptions("nextPageButton")),[(a.openBlock(),a.createBlock(a.resolveDynamicComponent(n.template||"AngleRightIcon"),a.mergeProps({class:"p-paginator-icon"},i.getPTOptions("nextPageIcon")),null,16))],16)),[[s]])};var w={name:"PageLinks",extends:c.default,inheritAttrs:!1,emits:["click"],props:{value:Array,page:Number},methods:{getPTOptions(e,t){return this.ptm(t,{context:{active:e===this.page}})},onPageLinkClick(e,t){this.$emit("click",{originalEvent:e,value:t})},ariaPageLabel(e){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.pageLabel.replace(/{page}/g,e):void 0}},directives:{ripple:d.default}};const x=["aria-label","aria-current","onClick"];w.render=function(e,t,n,o,r,i){const s=a.resolveDirective("ripple");return a.openBlock(),a.createElementBlock("span",a.mergeProps({class:"p-paginator-pages"},e.ptm("pages")),[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(n.value,(e=>a.withDirectives((a.openBlock(),a.createElementBlock("button",a.mergeProps({key:e,class:["p-paginator-page p-paginator-element p-link",{"p-highlight":e-1===n.page}],type:"button","aria-label":i.ariaPageLabel(e),"aria-current":e-1===n.page?"page":void 0,onClick:t=>i.onPageLinkClick(t,e)},i.getPTOptions(e-1,"pageButton")),[a.createTextVNode(a.toDisplayString(e),1)],16,x)),[[s]]))),128))],16)};var T={name:"PrevPageLink",extends:c.default,props:{template:{type:Function,default:null}},methods:{getPTOptions(e){return this.ptm(e,{context:{disabled:this.$attrs.disabled}})}},computed:{containerClass(){return["p-paginator-prev p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},components:{AngleLeftIcon:k.default},directives:{ripple:d.default}};T.render=function(e,t,n,o,r,i){const s=a.resolveDirective("ripple");return a.withDirectives((a.openBlock(),a.createElementBlock("button",a.mergeProps({class:i.containerClass,type:"button"},i.getPTOptions("prevPageButton")),[(a.openBlock(),a.createBlock(a.resolveDynamicComponent(n.template||"AngleLeftIcon"),a.mergeProps({class:"p-paginator-icon"},i.getPTOptions("prevPageIcon")),null,16))],16)),[[s]])};var $={name:"RowsPerPageDropdown",extends:c.default,emits:["rows-change"],props:{options:Array,rows:Number,disabled:Boolean},methods:{onChange(e){this.$emit("rows-change",e)}},computed:{rowsOptions(){let e=[];if(this.options)for(let t=0;t<this.options.length;t++)e.push({label:String(this.options[t]),value:this.options[t]});return e}},components:{RPPDropdown:m.default}};$.render=function(e,t,n,o,r,i){const s=a.resolveComponent("RPPDropdown");return a.openBlock(),a.createBlock(s,{modelValue:n.rows,options:i.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":t[0]||(t[0]=e=>i.onChange(e)),class:"p-paginator-rpp-options",disabled:n.disabled,pt:e.ptm("RPPDropdown")},null,8,["modelValue","options","disabled","pt"])};var D={name:"Paginator",extends:c.default,emits:["update:first","update:rows","page"],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}},data(){return{d_first:this.first,d_rows:this.rows}},watch:{first(e){this.d_first=e},rows(e){this.d_rows=e},totalRecords(e){this.page>0&&e&&this.d_first>=e&&this.changePage(this.pageCount-1)}},mounted(){this.setPaginatorAttribute(),this.createStyle()},methods:{changePage(e){const t=this.pageCount;if(e>=0&&e<t){this.d_first=this.d_rows*e;const 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(e){this.isFirstPage||this.changePage(0),e.preventDefault()},changePageToPrev(e){this.changePage(this.page-1),e.preventDefault()},changePageLink(e){this.changePage(e.value-1),e.originalEvent.preventDefault()},changePageToNext(e){this.changePage(this.page+1),e.preventDefault()},changePageToLast(e){this.isLastPage||this.changePage(this.pageCount-1),e.preventDefault()},onRowChange(e){this.d_rows=e,this.changePage(this.page)},createStyle(){if(this.hasBreakpoints()){this.styleElement=document.createElement("style"),this.styleElement.type="text/css",document.head.appendChild(this.styleElement);let e="";const t=Object.keys(this.template),a={};t.sort(((e,t)=>parseInt(e)-parseInt(t))).forEach((e=>{a[e]=this.template[e]}));for(const[t,[n]]of Object.entries(Object.entries(a))){const o=Object.entries(a)[t-1]?`and (min-width:${Object.keys(a)[t-1]})`:"";e+="default"===n?`\n screen ${o} {\n .paginator[${this.attributeSelector}],\n .p-paginator-default{\n display: flex !important;\n }\n }\n `:`\n .paginator[${this.attributeSelector}], .p-paginator-${n} {\n display: none !important;\n }\n screen ${o} and (max-width: ${n}) {\n .paginator[${this.attributeSelector}], .p-paginator-${n} {\n display: flex !important;\n }\n .paginator[${this.attributeSelector}],\n .p-paginator-default{\n display: none !important;\n }\n }\n `}this.styleElement.innerHTML=e}},hasBreakpoints(){return"object"==typeof this.template},getPaginatorClasses(e){return[{"p-paginator-default":!this.hasBreakpoints(),[`p-paginator-${e}`]:this.hasBreakpoints()}]},setPaginatorAttribute(){this.$refs.paginator&&this.$refs.paginator.length>=0&&[...this.$refs.paginator].forEach((e=>{e.setAttribute(this.attributeSelector,"")}))},getAriaLabel(e){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria[e]:void 0}},computed:{templateItems(){let e={};if(this.hasBreakpoints()){e=this.template,e.default||(e.default="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown");for(const t in e)e[t]=this.template[t].split(" ").map((e=>e.trim()));return e}return e.default=this.template.split(" ").map((e=>e.trim())),e},page(){return Math.floor(this.d_first/this.d_rows)},pageCount(){return Math.ceil(this.totalRecords/this.d_rows)},isFirstPage(){return 0===this.page},isLastPage(){return this.page===this.pageCount-1},calculatePageLinkBoundaries(){const e=this.pageCount,t=Math.min(this.pageLinkSize,e);let a=Math.max(0,Math.ceil(this.page-t/2)),n=Math.min(e-1,a+t-1);const o=this.pageLinkSize-(n-a+1);return a=Math.max(0,a-o),[a,n]},pageLinks(){let e=[],t=this.calculatePageLinkBoundaries,a=t[0],n=t[1];for(var o=a;o<=n;o++)e.push(o+1);return e},currentState(){return{page:this.page,first:this.d_first,rows:this.d_rows}},empty(){return 0===this.pageCount},currentPage(){return this.pageCount>0?this.page+1:0},attributeSelector:()=>t.UniqueComponentId()},components:{CurrentPageReport:b,FirstPageLink:v,LastPageLink:C,NextPageLink:B,PageLinks:w,PrevPageLink:T,RowsPerPageDropdown:$,JumpToPageDropdown:y,JumpToPageInput:L}};!function(e,t){void 0===t&&(t={});var a=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===a&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.p-paginator-default {\n display: flex;\n}\n.p-paginator {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-wrap: wrap;\n}\n.p-paginator-left-content {\n margin-right: auto;\n}\n.p-paginator-right-content {\n margin-left: auto;\n}\n.p-paginator-page,\n.p-paginator-next,\n.p-paginator-last,\n.p-paginator-first,\n.p-paginator-prev,\n.p-paginator-current {\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n line-height: 1;\n user-select: none;\n overflow: hidden;\n position: relative;\n}\n.p-paginator-element:focus {\n z-index: 1;\n position: relative;\n}\n"),D.render=function(e,t,n,o,r,i){const s=a.resolveComponent("FirstPageLink"),l=a.resolveComponent("PrevPageLink"),p=a.resolveComponent("NextPageLink"),g=a.resolveComponent("LastPageLink"),c=a.resolveComponent("PageLinks"),u=a.resolveComponent("CurrentPageReport"),d=a.resolveComponent("RowsPerPageDropdown"),m=a.resolveComponent("JumpToPageDropdown"),h=a.resolveComponent("JumpToPageInput");return n.alwaysShow||i.pageLinks&&i.pageLinks.length>1?(a.openBlock(),a.createElementBlock("nav",a.normalizeProps(a.mergeProps({key:0},e.ptm("root"))),[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(i.templateItems,((o,P)=>(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:P,ref_for:!0,ref:"paginator",class:["p-paginator p-component",i.getPaginatorClasses(P)]},e.ptm("paginator")),[e.$slots.start?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:0,class:"p-paginator-left-content"},e.ptm("left")),[a.renderSlot(e.$slots,"start",{state:i.currentState})],16)):a.createCommentVNode("",!0),(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(o,(o=>(a.openBlock(),a.createElementBlock(a.Fragment,{key:o},["FirstPageLink"===o?(a.openBlock(),a.createBlock(s,{key:0,"aria-label":i.getAriaLabel("firstPageLabel"),template:e.$slots.firstpagelinkicon,onClick:t[0]||(t[0]=e=>i.changePageToFirst(e)),disabled:i.isFirstPage||i.empty,pt:e.pt},null,8,["aria-label","template","disabled","pt"])):"PrevPageLink"===o?(a.openBlock(),a.createBlock(l,{key:1,"aria-label":i.getAriaLabel("prevPageLabel"),template:e.$slots.prevpagelinkicon,onClick:t[1]||(t[1]=e=>i.changePageToPrev(e)),disabled:i.isFirstPage||i.empty,pt:e.pt},null,8,["aria-label","template","disabled","pt"])):"NextPageLink"===o?(a.openBlock(),a.createBlock(p,{key:2,"aria-label":i.getAriaLabel("nextPageLabel"),template:e.$slots.nextpagelinkicon,onClick:t[2]||(t[2]=e=>i.changePageToNext(e)),disabled:i.isLastPage||i.empty,pt:e.pt},null,8,["aria-label","template","disabled","pt"])):"LastPageLink"===o?(a.openBlock(),a.createBlock(g,{key:3,"aria-label":i.getAriaLabel("lastPageLabel"),template:e.$slots.lastpagelinkicon,onClick:t[3]||(t[3]=e=>i.changePageToLast(e)),disabled:i.isLastPage||i.empty,pt:e.pt},null,8,["aria-label","template","disabled","pt"])):"PageLinks"===o?(a.openBlock(),a.createBlock(c,{key:4,"aria-label":i.getAriaLabel("pageLabel"),value:i.pageLinks,page:i.page,onClick:t[4]||(t[4]=e=>i.changePageLink(e)),pt:e.pt},null,8,["aria-label","value","page","pt"])):"CurrentPageReport"===o?(a.openBlock(),a.createBlock(u,{key:5,"aria-live":"polite",template:n.currentPageReportTemplate,currentPage:i.currentPage,page:i.page,pageCount:i.pageCount,first:r.d_first,rows:r.d_rows,totalRecords:n.totalRecords,pt:e.pt},null,8,["template","currentPage","page","pageCount","first","rows","totalRecords","pt"])):"RowsPerPageDropdown"===o&&n.rowsPerPageOptions?(a.openBlock(),a.createBlock(d,{key:6,"aria-label":i.getAriaLabel("rowsPerPageLabel"),rows:r.d_rows,options:n.rowsPerPageOptions,onRowsChange:t[5]||(t[5]=e=>i.onRowChange(e)),disabled:i.empty,pt:e.pt},null,8,["aria-label","rows","options","disabled","pt"])):"JumpToPageDropdown"===o?(a.openBlock(),a.createBlock(m,{key:7,"aria-label":i.getAriaLabel("jumpToPageDropdownLabel"),page:i.page,pageCount:i.pageCount,onPageChange:t[6]||(t[6]=e=>i.changePage(e)),disabled:i.empty,pt:e.pt},null,8,["aria-label","page","pageCount","disabled","pt"])):"JumpToPageInput"===o?(a.openBlock(),a.createBlock(h,{key:8,page:i.currentPage,onPageChange:t[7]||(t[7]=e=>i.changePage(e)),disabled:i.empty,pt:e.pt},null,8,["page","disabled","pt"])):a.createCommentVNode("",!0)],64)))),128)),e.$slots.end?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:1,class:"p-paginator-right-content"},e.ptm("end")),[a.renderSlot(e.$slots,"end",{state:i.currentState})],16)):a.createCommentVNode("",!0)],16)))),128))],16)):a.createCommentVNode("",!0)},module.exports=D;