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) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 10.9 kB
import{openBlock as e,createBlock as t,toDisplayString as a,resolveDirective as n,withDirectives as i,createVNode as r,Fragment as s,renderList as o,createTextVNode as p,resolveComponent as l,renderSlot as g,createCommentVNode as u}from"vue";import d from"primevue/ripple";import c from"primevue/dropdown";import h from"primevue/inputnumber";var m={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 P={class:"p-paginator-current"};m.render=function(n,i,r,s,o,p){return e(),t("span",P,a(p.text),1)};var f={name:"FirstPageLink",computed:{containerClass(){return["p-paginator-first p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:d}};const b=r("span",{class:"p-paginator-icon pi pi-angle-double-left"},null,-1);f.render=function(a,r,s,o,p,l){const g=n("ripple");return i((e(),t("button",{class:l.containerClass,type:"button"},[b],2)),[[g]])};var k={name:"LastPageLink",computed:{containerClass(){return["p-paginator-last p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:d}};const w=r("span",{class:"p-paginator-icon pi pi-angle-double-right"},null,-1);k.render=function(a,r,s,o,p,l){const g=n("ripple");return i((e(),t("button",{class:l.containerClass,type:"button"},[w],2)),[[g]])};var y={name:"NextPageLink",computed:{containerClass(){return["p-paginator-next p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:d}};const C=r("span",{class:"p-paginator-icon pi pi-angle-right"},null,-1);y.render=function(a,r,s,o,p,l){const g=n("ripple");return i((e(),t("button",{class:l.containerClass,type:"button"},[C],2)),[[g]])};var v={name:"PageLinks",inheritAttrs:!1,emits:["click"],props:{value:Array,page:Number},methods:{onPageLinkClick(e,t){this.$emit("click",{originalEvent:e,value:t})}},directives:{ripple:d}};const L={class:"p-paginator-pages"};v.render=function(r,l,g,u,d,c){const h=n("ripple");return e(),t("span",L,[(e(!0),t(s,null,o(g.value,(n=>i((e(),t("button",{key:n,class:["p-paginator-page p-paginator-element p-link",{"p-highlight":n-1===g.page}],type:"button",onClick:e=>c.onPageLinkClick(e,n)},[p(a(n),1)],10,["onClick"])),[[h]]))),128))])};var x={name:"PrevPageLink",computed:{containerClass(){return["p-paginator-prev p-paginator-element p-link",{"p-disabled":this.$attrs.disabled}]}},directives:{ripple:d}};const R=r("span",{class:"p-paginator-icon pi pi-angle-left"},null,-1);x.render=function(a,r,s,o,p,l){const g=n("ripple");return i((e(),t("button",{class:l.containerClass,type:"button"},[R],2)),[[g]])};var N={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:c}};N.render=function(a,n,i,r,s,o){const p=l("RPPDropdown");return e(),t(p,{modelValue:i.rows,options:o.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":n[1]||(n[1]=e=>o.onChange(e)),class:"p-paginator-rpp-options",disabled:i.disabled},null,8,["modelValue","options","disabled"])};var T={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:c}};T.render=function(a,n,i,r,s,o){const p=l("JTPDropdown");return e(),t(p,{modelValue:i.page,options:o.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":n[1]||(n[1]=e=>o.onChange(e)),class:"p-paginator-page-options",disabled:i.disabled},null,8,["modelValue","options","disabled"])};var _={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:h}};_.render=function(a,n,i,r,s,o){const p=l("JTPInput");return e(),t(p,{modelValue:i.page,"onUpdate:modelValue":n[1]||(n[1]=e=>o.onChange(e)),class:"p-paginator-page-input",disabled:i.disabled},null,8,["modelValue","disabled"])};var D={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: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)}},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)}},computed:{templateItems(){let e=[];return this.template.split(" ").map((t=>{e.push(t.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 i=this.pageLinkSize-(n-a+1);return a=Math.max(0,a-i),[a,n]},pageLinks(){let e=[],t=this.calculatePageLinkBoundaries,a=t[0],n=t[1];for(var i=a;i<=n;i++)e.push(i+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}},components:{CurrentPageReport:m,FirstPageLink:f,LastPageLink:k,NextPageLink:y,PageLinks:v,PrevPageLink:x,RowsPerPageDropdown:N,JumpToPageDropdown:T,JumpToPageInput:_}};const $={key:0,class:"p-paginator p-component"},S={key:0,class:"p-paginator-left-content"},J={key:1,class:"p-paginator-right-content"};!function(e,t){void 0===t&&(t={});var a=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===a&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}("\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\tmargin-right: auto;\n}\n.p-paginator-right-content {\n\tmargin-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"),D.render=function(a,n,i,r,p,d){const c=l("FirstPageLink"),h=l("PrevPageLink"),m=l("NextPageLink"),P=l("LastPageLink"),f=l("PageLinks"),b=l("CurrentPageReport"),k=l("RowsPerPageDropdown"),w=l("JumpToPageDropdown"),y=l("JumpToPageInput");return i.alwaysShow||d.pageLinks&&d.pageLinks.length>1?(e(),t("div",$,[a.$slots.start?(e(),t("div",S,[g(a.$slots,"start",{state:d.currentState})])):u("",!0),(e(!0),t(s,null,o(d.templateItems,(a=>(e(),t(s,{key:a},["FirstPageLink"===a?(e(),t(c,{key:0,onClick:n[1]||(n[1]=e=>d.changePageToFirst(e)),disabled:d.isFirstPage||d.empty},null,8,["disabled"])):"PrevPageLink"===a?(e(),t(h,{key:1,onClick:n[2]||(n[2]=e=>d.changePageToPrev(e)),disabled:d.isFirstPage||d.empty},null,8,["disabled"])):"NextPageLink"===a?(e(),t(m,{key:2,onClick:n[3]||(n[3]=e=>d.changePageToNext(e)),disabled:d.isLastPage||d.empty},null,8,["disabled"])):"LastPageLink"===a?(e(),t(P,{key:3,onClick:n[4]||(n[4]=e=>d.changePageToLast(e)),disabled:d.isLastPage||d.empty},null,8,["disabled"])):"PageLinks"===a?(e(),t(f,{key:4,value:d.pageLinks,page:d.page,onClick:n[5]||(n[5]=e=>d.changePageLink(e))},null,8,["value","page"])):"CurrentPageReport"===a?(e(),t(b,{key:5,template:i.currentPageReportTemplate,currentPage:d.currentPage,page:d.page,pageCount:d.pageCount,first:p.d_first,rows:p.d_rows,totalRecords:i.totalRecords},null,8,["template","currentPage","page","pageCount","first","rows","totalRecords"])):"RowsPerPageDropdown"===a&&i.rowsPerPageOptions?(e(),t(k,{key:6,rows:p.d_rows,options:i.rowsPerPageOptions,onRowsChange:n[6]||(n[6]=e=>d.onRowChange(e)),disabled:d.empty},null,8,["rows","options","disabled"])):"JumpToPageDropdown"===a?(e(),t(w,{key:7,page:d.page,pageCount:d.pageCount,onPageChange:n[7]||(n[7]=e=>d.changePage(e)),disabled:d.empty},null,8,["page","pageCount","disabled"])):"JumpToPageInput"===a?(e(),t(y,{key:8,page:d.currentPage,onPageChange:n[8]||(n[8]=e=>d.changePage(e)),disabled:d.empty},null,8,["page","disabled"])):u("",!0)],64)))),128)),a.$slots.end?(e(),t("div",J,[g(a.$slots,"end",{state:d.currentState})])):u("",!0)])):u("",!0)};export default D;