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) 19.9 kB
import{UniqueComponentId as t}from"primevue/utils";import e from"primevue/basecomponent";import{useStyle as n}from"primevue/usestyle";import{openBlock as a,createElementBlock as r,mergeProps as i,toDisplayString as o,resolveDirective as s,withDirectives as p,createBlock as l,resolveDynamicComponent as u,resolveComponent as g,normalizeClass as c,Fragment as d,renderList as m,createTextVNode as f,normalizeProps as h,renderSlot as P,createCommentVNode as b}from"vue";import y from"primevue/icons/angledoubleleft";import v from"primevue/ripple";import w from"primevue/dropdown";import k from"primevue/inputnumber";import L from"primevue/icons/angledoubleright";import x from"primevue/icons/angleright";import T from"primevue/icons/angleleft";function C(t){return C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},C(t)}function S(t,e,n){return(e=I(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function I(t){var e=A(t,"string");return"symbol"===C(e)?e:String(e)}function A(t,e){if("object"!==C(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var a=n.call(t,e||"default");if("object"!==C(a))return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var N={paginator:function(t){var e=t.instance,n=t.key;return["p-paginator p-component",S({"p-paginator-default":!e.hasBreakpoints()},"p-paginator-".concat(n),e.hasBreakpoints())]},start:"p-paginator-left-content",end:"p-paginator-right-content",firstPageButton:function(t){return["p-paginator-first p-paginator-element p-link",{"p-disabled":t.instance.$attrs.disabled}]},firstPageIcon:"p-paginator-icon",previousPageButton:function(t){return["p-paginator-prev p-paginator-element p-link",{"p-disabled":t.instance.$attrs.disabled}]},previousPageIcon:"p-paginator-icon",nextPageButton:function(t){return["p-paginator-next p-paginator-element p-link",{"p-disabled":t.instance.$attrs.disabled}]},nextPageIcon:"p-paginator-icon",lastPageButton:function(t){return["p-paginator-last p-paginator-element p-link",{"p-disabled":t.instance.$attrs.disabled}]},lastPageIcon:"p-paginator-icon",pages:"p-paginator-pages",pageButton:function(t){return["p-paginator-page p-paginator-element p-link",{"p-highlight":t.pageLink-1===t.props.page}]},current:"p-paginator-current",rowPerPageDropdown:"p-paginator-rpp-options",jumpToPageDropdown:"p-paginator-page-options",jumpToPageInput:"p-paginator-page-input"},$=n("\n.p-paginator-default {\n display: flex;\n}\n\n.p-paginator {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-wrap: wrap;\n}\n\n.p-paginator-left-content {\n margin-right: auto;\n}\n\n.p-paginator-right-content {\n margin-left: auto;\n}\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\n.p-paginator-element:focus {\n z-index: 1;\n position: relative;\n}\n",{name:"paginator",manual:!0}),O={name:"BasePaginator",extends:e,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}},css:{classes:N,loadStyle:$.load},provide:function(){return{$parentInstance:this}}},R={name:"CurrentPageReport",hostName:"Paginator",extends:e,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 t=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 t}}};R.render=function(t,e,n,s,p,l){return a(),r("span",i({class:t.cx("current")},t.ptm("current")),o(l.text),17)};var D={name:"FirstPageLink",hostName:"Paginator",extends:e,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleDoubleLeftIcon:y},directives:{ripple:v}};D.render=function(t,e,n,o,g,c){var d=s("ripple");return p((a(),r("button",i({class:t.cx("firstPageButton"),type:"button"},c.getPTOptions("firstPageButton")),[(a(),l(u(n.template||"AngleDoubleLeftIcon"),i({class:t.cx("firstPageIcon")},c.getPTOptions("firstPageIcon")),null,16,["class"]))],16)),[[d]])};var j={name:"JumpToPageDropdown",hostName:"Paginator",extends:e,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean},methods:{onChange:function(t){this.$emit("page-change",t)}},computed:{pageOptions:function(){for(var t=[],e=0;e<this.pageCount;e++)t.push({label:String(e+1),value:e});return t}},components:{JTPDropdown:w}};j.render=function(t,e,n,r,i,o){var s=g("JTPDropdown");return a(),l(s,{modelValue:n.page,options:o.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":e[0]||(e[0]=function(t){return o.onChange(t)}),class:c(t.cx("jumpToPageDropdown")),disabled:n.disabled,unstyled:t.unstyled,pt:t.ptm("jumpToPageDropdown"),"data-pc-section":"jumptopagedropdown"},null,8,["modelValue","options","class","disabled","unstyled","pt"])};var B={name:"JumpToPageInput",hostName:"Paginator",extends:e,inheritAttrs:!1,emits:["page-change"],props:{page:Number,pageCount:Number,disabled:Boolean},data:function(){return{d_page:this.page}},watch:{page:function(t){this.d_page=t}},methods:{onChange:function(t){t!==this.page&&(this.d_page=t,this.$emit("page-change",t-1))}},computed:{inputArialabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.jumpToPageInputLabel:void 0}},components:{JTPInput:k}};B.render=function(t,e,n,r,i,o){var s=g("JTPInput");return a(),l(s,{ref:"jtpInput",modelValue:i.d_page,class:c(t.cx("jumpToPageInput")),"aria-label":o.inputArialabel,disabled:n.disabled,"onUpdate:modelValue":o.onChange,unstyled:t.unstyled,pt:t.ptm("jumpToPageInput"),"data-pc-section":"jumptopageinput"},null,8,["modelValue","class","aria-label","disabled","onUpdate:modelValue","unstyled","pt"])};var _={name:"LastPageLink",hostName:"Paginator",extends:e,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleDoubleRightIcon:L},directives:{ripple:v}};_.render=function(t,e,n,o,g,c){var d=s("ripple");return p((a(),r("button",i({class:t.cx("lastPageButton"),type:"button"},c.getPTOptions("lastPageButton")),[(a(),l(u(n.template||"AngleDoubleRightIcon"),i({class:t.cx("lastPageIcon")},c.getPTOptions("lastPageIcon")),null,16,["class"]))],16)),[[d]])};var F={name:"NextPageLink",hostName:"Paginator",extends:e,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleRightIcon:x},directives:{ripple:v}};F.render=function(t,e,n,o,g,c){var d=s("ripple");return p((a(),r("button",i({class:t.cx("nextPageButton"),type:"button"},c.getPTOptions("nextPageButton")),[(a(),l(u(n.template||"AngleRightIcon"),i({class:t.cx("nextPageIcon")},c.getPTOptions("nextPageIcon")),null,16,["class"]))],16)),[[d]])};var E={name:"PageLinks",hostName:"Paginator",extends:e,inheritAttrs:!1,emits:["click"],props:{value:Array,page:Number},methods:{getPTOptions:function(t,e){return this.ptm(e,{context:{active:t===this.page}})},onPageLinkClick:function(t,e){this.$emit("click",{originalEvent:t,value:e})},ariaPageLabel:function(t){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.pageLabel.replace(/{page}/g,t):void 0}},directives:{ripple:v}},J=["aria-label","aria-current","onClick","data-p-highlight"];E.render=function(t,e,n,l,u,g){var c=s("ripple");return a(),r("span",i({class:t.cx("pages")},t.ptm("pages")),[(a(!0),r(d,null,m(n.value,(function(e){return p((a(),r("button",i({key:e,class:t.cx("pageButton",{pageLink:e}),type:"button","aria-label":g.ariaPageLabel(e),"aria-current":e-1===n.page?"page":void 0,onClick:function(t){return g.onPageLinkClick(t,e)}},g.getPTOptions(e-1,"pageButton"),{"data-p-highlight":e-1===n.page}),[f(o(e),1)],16,J)),[[c]])})),128))],16)};var V={name:"PrevPageLink",hostName:"Paginator",extends:e,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleLeftIcon:T},directives:{ripple:v}};V.render=function(t,e,n,o,g,c){var d=s("ripple");return p((a(),r("button",i({class:t.cx("previousPageButton"),type:"button"},c.getPTOptions("previousPageButton")),[(a(),l(u(n.template||"AngleLeftIcon"),i({class:t.cx("previousPageIcon")},c.getPTOptions("previousPageIcon")),null,16,["class"]))],16)),[[d]])};var M={name:"RowsPerPageDropdown",hostName:"Paginator",extends:e,emits:["rows-change"],props:{options:Array,rows:Number,disabled:Boolean},methods:{onChange:function(t){this.$emit("rows-change",t)}},computed:{rowsOptions:function(){var t=[];if(this.options)for(var e=0;e<this.options.length;e++)t.push({label:String(this.options[e]),value:this.options[e]});return t}},components:{RPPDropdown:w}};function U(){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 z(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function H(t){if(Array.isArray(t))return Q(t)}function W(t){return W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(t)}function q(t,e){return Y(t)||X(t,e)||K(t,e)||G()}function G(){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 K(t,e){if(t){if("string"==typeof t)return Q(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Q(t,e):void 0}}function Q(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,a=new Array(e);n<e;n++)a[n]=t[n];return a}function X(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var a,r,i,o,s=[],p=!0,l=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;p=!1}else for(;!(p=(a=i.call(n)).done)&&(s.push(a.value),s.length!==e);p=!0);}catch(t){l=!0,r=t}finally{try{if(!p&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw r}}return s}}function Y(t){if(Array.isArray(t))return t}M.render=function(t,e,n,r,i,o){var s=g("RPPDropdown");return a(),l(s,{modelValue:n.rows,options:o.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":e[0]||(e[0]=function(t){return o.onChange(t)}),class:c(t.cx("rowPerPageDropdown")),disabled:n.disabled,unstyled:t.unstyled,pt:t.ptm("rowPerPageDropdown"),"data-pc-section":"rowperpagedropdown"},null,8,["modelValue","options","class","disabled","unstyled","pt"])};var Z={name:"Paginator",extends:O,emits:["update:first","update:rows","page"],data:function(){return{d_first:this.first,d_rows:this.rows}},watch:{first:function(t){this.d_first=t},rows:function(t){this.d_rows=t},totalRecords:function(t){this.page>0&&t&&this.d_first>=t&&this.changePage(this.pageCount-1)}},mounted:function(){this.setPaginatorAttribute(),this.createStyle()},methods:{changePage:function(t){var e=this.pageCount;if(t>=0&&t<e){this.d_first=this.d_rows*t;var n={page:t,first:this.d_first,rows:this.d_rows,pageCount:e};this.$emit("update:first",this.d_first),this.$emit("update:rows",this.d_rows),this.$emit("page",n)}},changePageToFirst:function(t){this.isFirstPage||this.changePage(0),t.preventDefault()},changePageToPrev:function(t){this.changePage(this.page-1),t.preventDefault()},changePageLink:function(t){this.changePage(t.value-1),t.originalEvent.preventDefault()},changePageToNext:function(t){this.changePage(this.page+1),t.preventDefault()},changePageToLast:function(t){this.isLastPage||this.changePage(this.pageCount-1),t.preventDefault()},onRowChange:function(t){this.d_rows=t,this.changePage(this.page)},createStyle:function(){var t=this;if(this.hasBreakpoints()&&!this.isUnstyled){this.styleElement=document.createElement("style"),this.styleElement.type="text/css",document.head.appendChild(this.styleElement);var e="",n=Object.keys(this.template),a={};n.sort((function(t,e){return parseInt(t)-parseInt(e)})).forEach((function(e){a[e]=t.template[e]}));for(var r=0,i=Object.entries(Object.entries(a));r<i.length;r++){var o=q(i[r],2),s=o[0],p=q(o[1],1)[0],l=Object.entries(a)[s-1]?"and (min-width:".concat(Object.keys(a)[s-1],")"):"";e+="default"===p?"\n @media screen ".concat(l," {\n .paginator[").concat(this.attributeSelector,"],\n .p-paginator-default{\n display: flex !important;\n }\n }\n "):"\n .paginator[".concat(this.attributeSelector,"], .p-paginator-").concat(p," {\n display: none !important;\n }\n @media screen ").concat(l," and (max-width: ").concat(p,") {\n .paginator[").concat(this.attributeSelector,"], .p-paginator-").concat(p," {\n display: flex !important;\n }\n .paginator[").concat(this.attributeSelector,"],\n .p-paginator-default{\n display: none !important;\n }\n }\n ")}this.styleElement.innerHTML=e}},hasBreakpoints:function(){return"object"===W(this.template)},setPaginatorAttribute:function(){var t,e=this;this.$refs.paginator&&this.$refs.paginator.length>=0&&(t=this.$refs.paginator,H(t)||z(t)||K(t)||U()).forEach((function(t){t.setAttribute(e.attributeSelector,"")}))},getAriaLabel:function(t){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria[t]:void 0}},computed:{templateItems:function(){var t={};if(this.hasBreakpoints()){for(var e in(t=this.template).default||(t.default="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"),t)t[e]=this.template[e].split(" ").map((function(t){return t.trim()}));return t}return t.default=this.template.split(" ").map((function(t){return t.trim()})),t},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 t=this.pageCount,e=Math.min(this.pageLinkSize,t),n=Math.max(0,Math.ceil(this.page-e/2)),a=Math.min(t-1,n+e-1);return[n=Math.max(0,n-(this.pageLinkSize-(a-n+1))),a]},pageLinks:function(){for(var t=[],e=this.calculatePageLinkBoundaries,n=e[1],a=e[0];a<=n;a++)t.push(a+1);return t},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:R,FirstPageLink:D,LastPageLink:_,NextPageLink:F,PageLinks:E,PrevPageLink:V,RowsPerPageDropdown:M,JumpToPageDropdown:j,JumpToPageInput:B}};Z.render=function(t,e,n,o,s,p){var u=g("FirstPageLink"),c=g("PrevPageLink"),f=g("NextPageLink"),y=g("LastPageLink"),v=g("PageLinks"),w=g("CurrentPageReport"),k=g("RowsPerPageDropdown"),L=g("JumpToPageDropdown"),x=g("JumpToPageInput");return t.alwaysShow||p.pageLinks&&p.pageLinks.length>1?(a(),r("nav",h(i({key:0},t.ptm("paginatorWrapper"))),[(a(!0),r(d,null,m(p.templateItems,(function(n,o){return a(),r("div",i({key:o,ref_for:!0,ref:"paginator",class:t.cx("paginator",{key:o})},t.ptm("root"),{"data-pc-name":"paginator"}),[t.$slots.start?(a(),r("div",i({key:0,class:t.cx("start")},t.ptm("start")),[P(t.$slots,"start",{state:p.currentState})],16)):b("",!0),(a(!0),r(d,null,m(n,(function(n){return a(),r(d,{key:n},["FirstPageLink"===n?(a(),l(u,{key:0,"aria-label":p.getAriaLabel("firstPageLabel"),template:t.$slots.firstpagelinkicon,onClick:e[0]||(e[0]=function(t){return p.changePageToFirst(t)}),disabled:p.isFirstPage||p.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"PrevPageLink"===n?(a(),l(c,{key:1,"aria-label":p.getAriaLabel("prevPageLabel"),template:t.$slots.prevpagelinkicon,onClick:e[1]||(e[1]=function(t){return p.changePageToPrev(t)}),disabled:p.isFirstPage||p.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"NextPageLink"===n?(a(),l(f,{key:2,"aria-label":p.getAriaLabel("nextPageLabel"),template:t.$slots.nextpagelinkicon,onClick:e[2]||(e[2]=function(t){return p.changePageToNext(t)}),disabled:p.isLastPage||p.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"LastPageLink"===n?(a(),l(y,{key:3,"aria-label":p.getAriaLabel("lastPageLabel"),template:t.$slots.lastpagelinkicon,onClick:e[3]||(e[3]=function(t){return p.changePageToLast(t)}),disabled:p.isLastPage||p.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"PageLinks"===n?(a(),l(v,{key:4,"aria-label":p.getAriaLabel("pageLabel"),value:p.pageLinks,page:p.page,onClick:e[4]||(e[4]=function(t){return p.changePageLink(t)}),pt:t.pt},null,8,["aria-label","value","page","pt"])):"CurrentPageReport"===n?(a(),l(w,{key:5,"aria-live":"polite",template:t.currentPageReportTemplate,currentPage:p.currentPage,page:p.page,pageCount:p.pageCount,first:s.d_first,rows:s.d_rows,totalRecords:t.totalRecords,pt:t.pt},null,8,["template","currentPage","page","pageCount","first","rows","totalRecords","pt"])):"RowsPerPageDropdown"===n&&t.rowsPerPageOptions?(a(),l(k,{key:6,"aria-label":p.getAriaLabel("rowsPerPageLabel"),rows:s.d_rows,options:t.rowsPerPageOptions,onRowsChange:e[5]||(e[5]=function(t){return p.onRowChange(t)}),disabled:p.empty,unstyled:t.unstyled,pt:t.pt},null,8,["aria-label","rows","options","disabled","unstyled","pt"])):"JumpToPageDropdown"===n?(a(),l(L,{key:7,"aria-label":p.getAriaLabel("jumpToPageDropdownLabel"),page:p.page,pageCount:p.pageCount,onPageChange:e[6]||(e[6]=function(t){return p.changePage(t)}),disabled:p.empty,unstyled:t.unstyled,pt:t.pt},null,8,["aria-label","page","pageCount","disabled","unstyled","pt"])):"JumpToPageInput"===n?(a(),l(x,{key:8,page:p.currentPage,onPageChange:e[7]||(e[7]=function(t){return p.changePage(t)}),disabled:p.empty,unstyled:t.unstyled,pt:t.pt},null,8,["page","disabled","unstyled","pt"])):b("",!0)],64)})),128)),t.$slots.end?(a(),r("div",i({key:1,class:t.cx("end")},t.ptm("end")),[P(t.$slots,"end",{state:p.currentState})],16)):b("",!0)],16)})),128))],16)):b("",!0)};export{Z as default};