UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Actions CI](https://github.com/primefaces/primevue/wo

2 lines (1 loc) 14.7 kB
"use strict";var e=require("primevue/utils"),t=require("vue"),n=require("primevue/ripple"),a=require("primevue/dropdown"),o=require("primevue/inputnumber");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=r(n),s=r(a),l=r(o),p={name:"CurrentPageReport",inheritAttrs:!1,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)}}};const c={class:"p-paginator-current"};p.render=function(e,n,a,o,r,i){return t.openBlock(),t.createElementBlock("span",c,t.toDisplayString(i.text),1)};var g={name:"FirstPageLink",computed:{containerClass(){return["p-paginator-first p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:i.default}};const u=[t.createElementVNode("span",{class:"p-paginator-icon pi pi-angle-double-left"},null,-1)];g.render=function(e,n,a,o,r,i){const s=t.resolveDirective("ripple");return t.withDirectives((t.openBlock(),t.createElementBlock("button",{class:t.normalizeClass(i.containerClass),type:"button"},u,2)),[[s]])};var d={name:"JumpToPageDropdown",inheritAttrs:!1,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:s.default}};d.render=function(e,n,a,o,r,i){const s=t.resolveComponent("JTPDropdown");return t.openBlock(),t.createBlock(s,{modelValue:a.page,options:i.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":n[0]||(n[0]=e=>i.onChange(e)),class:"p-paginator-page-options",disabled:a.disabled},null,8,["modelValue","options","disabled"])};var m={name:"JumpToPageInput",inheritAttrs:!1,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean},methods:{onChange(e){this.$emit("page-change",e-1)}},components:{JTPInput:l.default}};m.render=function(e,n,a,o,r,i){const s=t.resolveComponent("JTPInput");return t.openBlock(),t.createBlock(s,{modelValue:a.page,"onUpdate:modelValue":n[0]||(n[0]=e=>i.onChange(e)),class:"p-paginator-page-input",disabled:a.disabled},null,8,["modelValue","disabled"])};var h={name:"LastPageLink",computed:{containerClass(){return["p-paginator-last p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:i.default}};const k=[t.createElementVNode("span",{class:"p-paginator-icon pi pi-angle-double-right"},null,-1)];h.render=function(e,n,a,o,r,i){const s=t.resolveDirective("ripple");return t.withDirectives((t.openBlock(),t.createElementBlock("button",{class:t.normalizeClass(i.containerClass),type:"button"},k,2)),[[s]])};var P={name:"NextPageLink",computed:{containerClass(){return["p-paginator-next p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:i.default}};const f=[t.createElementVNode("span",{class:"p-paginator-icon pi pi-angle-right"},null,-1)];P.render=function(e,n,a,o,r,i){const s=t.resolveDirective("ripple");return t.withDirectives((t.openBlock(),t.createElementBlock("button",{class:t.normalizeClass(i.containerClass),type:"button"},f,2)),[[s]])};var b={name:"PageLinks",inheritAttrs:!1,emits:["click"],props:{value:Array,page:Number},methods:{onPageLinkClick(e,t){this.$emit("click",{originalEvent:e,value:t})}},directives:{ripple:i.default}};const v={class:"p-paginator-pages"},w=["onClick"];b.render=function(e,n,a,o,r,i){const s=t.resolveDirective("ripple");return t.openBlock(),t.createElementBlock("span",v,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(a.value,(e=>t.withDirectives((t.openBlock(),t.createElementBlock("button",{key:e,class:t.normalizeClass(["p-paginator-page p-paginator-element p-link",{"p-highlight":e-1===a.page}]),type:"button",onClick:t=>i.onPageLinkClick(t,e)},[t.createTextVNode(t.toDisplayString(e),1)],10,w)),[[s]]))),128))])};var y={name:"PrevPageLink",computed:{containerClass(){return["p-paginator-prev p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:i.default}};const C=[t.createElementVNode("span",{class:"p-paginator-icon pi pi-angle-left"},null,-1)];y.render=function(e,n,a,o,r,i){const s=t.resolveDirective("ripple");return t.withDirectives((t.openBlock(),t.createElementBlock("button",{class:t.normalizeClass(i.containerClass),type:"button"},C,2)),[[s]])};var B={name:"RowsPerPageDropdown",inheritAttrs:!1,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:s.default}};B.render=function(e,n,a,o,r,i){const s=t.resolveComponent("RPPDropdown");return t.openBlock(),t.createBlock(s,{modelValue:a.rows,options:i.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":n[0]||(n[0]=e=>i.onChange(e)),class:"p-paginator-rpp-options",disabled:a.disabled},null,8,["modelValue","options","disabled"])};var L={name:"Paginator",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 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(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),n={};t.sort(((e,t)=>parseInt(e)-parseInt(t))).forEach((e=>{n[e]=this.template[e]}));for(const[t,[a]]of Object.entries(Object.entries(n))){const o=Object.entries(n)[t-1]?`and (min-width:${Object.keys(n)[t-1]})`:"";e+="default"===a?`\n @media screen ${o} {\n .paginator[${this.attributeSelector}],\n .p-paginator-default{\n display: flex !important;\n }\n }\n `:`\n .paginator[${this.attributeSelector}], .p-paginator-${a} {\n display: none !important;\n }\n @media screen ${o} and (max-width: ${a}) {\n .paginator[${this.attributeSelector}], .p-paginator-${a} {\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,"")}))}},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 n=Math.max(0,Math.ceil(this.page-t/2)),a=Math.min(e-1,n+t-1);const o=this.pageLinkSize-(a-n+1);return n=Math.max(0,n-o),[n,a]},pageLinks(){let e=[],t=this.calculatePageLinkBoundaries,n=t[0],a=t[1];for(var o=n;o<=a;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:()=>e.UniqueComponentId()},components:{CurrentPageReport:p,FirstPageLink:g,LastPageLink:h,NextPageLink:P,PageLinks:b,PrevPageLink:y,RowsPerPageDropdown:B,JumpToPageDropdown:d,JumpToPageInput:m}};const x={key:0},N={key:0,class:"p-paginator-left-content"},D={key:1,class:"p-paginator-right-content"};!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&a.firstChild?a.insertBefore(o,a.firstChild):a.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.p-paginator-default {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n}\n.p-paginator {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-wrap: wrap;\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: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n line-height: 1;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\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"),L.render=function(e,n,a,o,r,i){const s=t.resolveComponent("FirstPageLink"),l=t.resolveComponent("PrevPageLink"),p=t.resolveComponent("NextPageLink"),c=t.resolveComponent("LastPageLink"),g=t.resolveComponent("PageLinks"),u=t.resolveComponent("CurrentPageReport"),d=t.resolveComponent("RowsPerPageDropdown"),m=t.resolveComponent("JumpToPageDropdown"),h=t.resolveComponent("JumpToPageInput");return a.alwaysShow||i.pageLinks&&i.pageLinks.length>1?(t.openBlock(),t.createElementBlock("div",x,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(i.templateItems,((o,k)=>(t.openBlock(),t.createElementBlock("div",{key:k,ref_for:!0,ref:"paginator",class:t.normalizeClass(["p-paginator p-component",i.getPaginatorClasses(k)])},[e.$slots.start?(t.openBlock(),t.createElementBlock("div",N,[t.renderSlot(e.$slots,"start",{state:i.currentState})])):t.createCommentVNode("",!0),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o,(e=>(t.openBlock(),t.createElementBlock(t.Fragment,{key:e},["FirstPageLink"===e?(t.openBlock(),t.createBlock(s,{key:0,onClick:n[0]||(n[0]=e=>i.changePageToFirst(e)),disabled:i.isFirstPage||i.empty},null,8,["disabled"])):"PrevPageLink"===e?(t.openBlock(),t.createBlock(l,{key:1,onClick:n[1]||(n[1]=e=>i.changePageToPrev(e)),disabled:i.isFirstPage||i.empty},null,8,["disabled"])):"NextPageLink"===e?(t.openBlock(),t.createBlock(p,{key:2,onClick:n[2]||(n[2]=e=>i.changePageToNext(e)),disabled:i.isLastPage||i.empty},null,8,["disabled"])):"LastPageLink"===e?(t.openBlock(),t.createBlock(c,{key:3,onClick:n[3]||(n[3]=e=>i.changePageToLast(e)),disabled:i.isLastPage||i.empty},null,8,["disabled"])):"PageLinks"===e?(t.openBlock(),t.createBlock(g,{key:4,value:i.pageLinks,page:i.page,onClick:n[4]||(n[4]=e=>i.changePageLink(e))},null,8,["value","page"])):"CurrentPageReport"===e?(t.openBlock(),t.createBlock(u,{key:5,template:a.currentPageReportTemplate,currentPage:i.currentPage,page:i.page,pageCount:i.pageCount,first:r.d_first,rows:r.d_rows,totalRecords:a.totalRecords},null,8,["template","currentPage","page","pageCount","first","rows","totalRecords"])):"RowsPerPageDropdown"===e&&a.rowsPerPageOptions?(t.openBlock(),t.createBlock(d,{key:6,rows:r.d_rows,options:a.rowsPerPageOptions,onRowsChange:n[5]||(n[5]=e=>i.onRowChange(e)),disabled:i.empty},null,8,["rows","options","disabled"])):"JumpToPageDropdown"===e?(t.openBlock(),t.createBlock(m,{key:7,page:i.page,pageCount:i.pageCount,onPageChange:n[6]||(n[6]=e=>i.changePage(e)),disabled:i.empty},null,8,["page","pageCount","disabled"])):"JumpToPageInput"===e?(t.openBlock(),t.createBlock(h,{key:8,page:i.currentPage,onPageChange:n[7]||(n[7]=e=>i.changePage(e)),disabled:i.empty},null,8,["page","disabled"])):t.createCommentVNode("",!0)],64)))),128)),e.$slots.end?(t.openBlock(),t.createElementBlock("div",D,[t.renderSlot(e.$slots,"end",{state:i.currentState})])):t.createCommentVNode("",!0)],2)))),128))])):t.createCommentVNode("",!0)},module.exports=L;