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) 20.3 kB
import{DomHandler as t,UniqueComponentId as e}from"primevue/utils";import n from"primevue/basecomponent";import{useStyle as a}from"primevue/usestyle";import{openBlock as r,createElementBlock as o,mergeProps as i,toDisplayString as p,resolveDirective as s,withDirectives as l,createBlock as u,resolveDynamicComponent as g,resolveComponent as c,normalizeClass as d,Fragment as m,renderList as f,createTextVNode as h,normalizeProps as P,renderSlot as b,createCommentVNode as y}from"vue";import v from"primevue/icons/angledoubleleft";import w from"primevue/ripple";import k from"primevue/dropdown";import L from"primevue/inputnumber";import x from"primevue/icons/angledoubleright";import T from"primevue/icons/angleright";import C from"primevue/icons/angleleft";function S(t){return S="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},S(t)}function I(t,e,n){return(e=A(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function A(t){var e=$(t,"string");return"symbol"===S(e)?e:String(e)}function $(t,e){if("object"!==S(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var a=n.call(t,e||"default");if("object"!==S(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",I({"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"},O=a("\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}),R={name:"BasePaginator",extends:n,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:O.load},provide:function(){return{$parentInstance:this}}},D={name:"CurrentPageReport",hostName:"Paginator",extends:n,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}}};D.render=function(t,e,n,a,s,l){return r(),o("span",i({class:t.cx("current")},t.ptm("current")),p(l.text),17)};var j={name:"FirstPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleDoubleLeftIcon:v},directives:{ripple:w}};j.render=function(t,e,n,a,p,c){var d=s("ripple");return l((r(),o("button",i({class:t.cx("firstPageButton"),type:"button"},c.getPTOptions("firstPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(g(n.template||"AngleDoubleLeftIcon"),i({class:t.cx("firstPageIcon")},c.getPTOptions("firstPageIcon")),null,16,["class"]))],16)),[[d]])};var B={name:"JumpToPageDropdown",hostName:"Paginator",extends:n,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:k}};B.render=function(t,e,n,a,o,i){var p=c("JTPDropdown");return r(),u(p,{modelValue:n.page,options:i.pageOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":e[0]||(e[0]=function(t){return i.onChange(t)}),class:d(t.cx("jumpToPageDropdown")),disabled:n.disabled,unstyled:t.unstyled,pt:t.ptm("jumpToPageDropdown"),"data-pc-section":"jumptopagedropdown","data-pc-group-section":"pagedropdown"},null,8,["modelValue","options","class","disabled","unstyled","pt"])};var _={name:"JumpToPageInput",hostName:"Paginator",extends:n,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:L}};_.render=function(t,e,n,a,o,i){var p=c("JTPInput");return r(),u(p,{ref:"jtpInput",modelValue:o.d_page,class:d(t.cx("jumpToPageInput")),"aria-label":i.inputArialabel,disabled:n.disabled,"onUpdate:modelValue":i.onChange,unstyled:t.unstyled,pt:t.ptm("jumpToPageInput"),"data-pc-section":"jumptopageinput"},null,8,["modelValue","class","aria-label","disabled","onUpdate:modelValue","unstyled","pt"])};var F={name:"LastPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleDoubleRightIcon:x},directives:{ripple:w}};F.render=function(t,e,n,a,p,c){var d=s("ripple");return l((r(),o("button",i({class:t.cx("lastPageButton"),type:"button"},c.getPTOptions("lastPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(g(n.template||"AngleDoubleRightIcon"),i({class:t.cx("lastPageIcon")},c.getPTOptions("lastPageIcon")),null,16,["class"]))],16)),[[d]])};var E={name:"NextPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleRightIcon:T},directives:{ripple:w}};E.render=function(t,e,n,a,p,c){var d=s("ripple");return l((r(),o("button",i({class:t.cx("nextPageButton"),type:"button"},c.getPTOptions("nextPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(g(n.template||"AngleRightIcon"),i({class:t.cx("nextPageIcon")},c.getPTOptions("nextPageIcon")),null,16,["class"]))],16)),[[d]])};var J={name:"PageLinks",hostName:"Paginator",extends:n,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:w}},V=["aria-label","aria-current","onClick","data-p-highlight"];J.render=function(t,e,n,a,u,g){var c=s("ripple");return r(),o("span",i({class:t.cx("pages")},t.ptm("pages")),[(r(!0),o(m,null,f(n.value,(function(e){return l((r(),o("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}),[h(p(e),1)],16,V)),[[c]])})),128))],16)};var M={name:"PrevPageLink",hostName:"Paginator",extends:n,props:{template:{type:Function,default:null}},methods:{getPTOptions:function(t){return this.ptm(t,{context:{disabled:this.$attrs.disabled}})}},components:{AngleLeftIcon:C},directives:{ripple:w}};M.render=function(t,e,n,a,p,c){var d=s("ripple");return l((r(),o("button",i({class:t.cx("previousPageButton"),type:"button"},c.getPTOptions("previousPageButton"),{"data-pc-group-section":"pagebutton"}),[(r(),u(g(n.template||"AngleLeftIcon"),i({class:t.cx("previousPageIcon")},c.getPTOptions("previousPageIcon")),null,16,["class"]))],16)),[[d]])};var U={name:"RowsPerPageDropdown",hostName:"Paginator",extends:n,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:k}};function z(){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 H(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function W(t){if(Array.isArray(t))return X(t)}function q(t){return q="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},q(t)}function G(t,e){return Z(t)||Y(t,e)||Q(t,e)||K()}function K(){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 Q(t,e){if(t){if("string"==typeof t)return X(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)?X(t,e):void 0}}function X(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 Y(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var a,r,o,i,p=[],s=!0,l=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(a=o.call(n)).done)&&(p.push(a.value),p.length!==e);s=!0);}catch(t){l=!0,r=t}finally{try{if(!s&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(l)throw r}}return p}}function Z(t){if(Array.isArray(t))return t}U.render=function(t,e,n,a,o,i){var p=c("RPPDropdown");return r(),u(p,{modelValue:n.rows,options:i.rowsOptions,optionLabel:"label",optionValue:"value","onUpdate:modelValue":e[0]||(e[0]=function(t){return i.onChange(t)}),class:d(t.cx("rowPerPageDropdown")),disabled:n.disabled,unstyled:t.unstyled,pt:t.ptm("rowPerPageDropdown"),"data-pc-section":"rowperpagedropdown","data-pc-group-section":"pagedropdown"},null,8,["modelValue","options","class","disabled","unstyled","pt"])};var tt={name:"Paginator",extends:R,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 e=this;if(this.hasBreakpoints()&&!this.isUnstyled){var n;this.styleElement=document.createElement("style"),this.styleElement.type="text/css",t.setAttribute(this.styleElement,"nonce",null===(n=this.$primevue)||void 0===n||null===(n=n.config)||void 0===n||null===(n=n.csp)||void 0===n?void 0:n.nonce),document.head.appendChild(this.styleElement);var a="",r=Object.keys(this.template),o={};r.sort((function(t,e){return parseInt(t)-parseInt(e)})).forEach((function(t){o[t]=e.template[t]}));for(var i=0,p=Object.entries(Object.entries(o));i<p.length;i++){var s=G(p[i],2),l=s[0],u=G(s[1],1)[0],g=Object.entries(o)[l-1]?"and (min-width:".concat(Object.keys(o)[l-1],")"):"";a+="default"===u?"\n @media screen ".concat(g," {\n .paginator[").concat(this.attributeSelector,"],\n .p-paginator-default{\n display: flex !important;\n }\n }\n "):"\n .paginator[".concat(this.attributeSelector,"], .p-paginator-").concat(u," {\n display: none !important;\n }\n @media screen ").concat(g," and (max-width: ").concat(u,") {\n .paginator[").concat(this.attributeSelector,"], .p-paginator-").concat(u," {\n display: flex !important;\n }\n .paginator[").concat(this.attributeSelector,"],\n .p-paginator-default{\n display: none !important;\n }\n }\n ")}this.styleElement.innerHTML=a}},hasBreakpoints:function(){return"object"===q(this.template)},setPaginatorAttribute:function(){var t,e=this;this.$refs.paginator&&this.$refs.paginator.length>=0&&(t=this.$refs.paginator,W(t)||H(t)||Q(t)||z()).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 e()}},components:{CurrentPageReport:D,FirstPageLink:j,LastPageLink:F,NextPageLink:E,PageLinks:J,PrevPageLink:M,RowsPerPageDropdown:U,JumpToPageDropdown:B,JumpToPageInput:_}};tt.render=function(t,e,n,a,p,s){var l=c("FirstPageLink"),g=c("PrevPageLink"),d=c("NextPageLink"),h=c("LastPageLink"),v=c("PageLinks"),w=c("CurrentPageReport"),k=c("RowsPerPageDropdown"),L=c("JumpToPageDropdown"),x=c("JumpToPageInput");return t.alwaysShow||s.pageLinks&&s.pageLinks.length>1?(r(),o("nav",P(i({key:0},t.ptm("paginatorWrapper"))),[(r(!0),o(m,null,f(s.templateItems,(function(n,a){return r(),o("div",i({key:a,ref_for:!0,ref:"paginator",class:t.cx("paginator",{key:a})},t.ptm("root"),{"data-pc-name":"paginator"}),[t.$slots.start?(r(),o("div",i({key:0,class:t.cx("start")},t.ptm("start")),[b(t.$slots,"start",{state:s.currentState})],16)):y("",!0),(r(!0),o(m,null,f(n,(function(n){return r(),o(m,{key:n},["FirstPageLink"===n?(r(),u(l,{key:0,"aria-label":s.getAriaLabel("firstPageLabel"),template:t.$slots.firstpagelinkicon,onClick:e[0]||(e[0]=function(t){return s.changePageToFirst(t)}),disabled:s.isFirstPage||s.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"PrevPageLink"===n?(r(),u(g,{key:1,"aria-label":s.getAriaLabel("prevPageLabel"),template:t.$slots.prevpagelinkicon,onClick:e[1]||(e[1]=function(t){return s.changePageToPrev(t)}),disabled:s.isFirstPage||s.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"NextPageLink"===n?(r(),u(d,{key:2,"aria-label":s.getAriaLabel("nextPageLabel"),template:t.$slots.nextpagelinkicon,onClick:e[2]||(e[2]=function(t){return s.changePageToNext(t)}),disabled:s.isLastPage||s.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"LastPageLink"===n?(r(),u(h,{key:3,"aria-label":s.getAriaLabel("lastPageLabel"),template:t.$slots.lastpagelinkicon,onClick:e[3]||(e[3]=function(t){return s.changePageToLast(t)}),disabled:s.isLastPage||s.empty,pt:t.pt},null,8,["aria-label","template","disabled","pt"])):"PageLinks"===n?(r(),u(v,{key:4,"aria-label":s.getAriaLabel("pageLabel"),value:s.pageLinks,page:s.page,onClick:e[4]||(e[4]=function(t){return s.changePageLink(t)}),pt:t.pt},null,8,["aria-label","value","page","pt"])):"CurrentPageReport"===n?(r(),u(w,{key:5,"aria-live":"polite",template:t.currentPageReportTemplate,currentPage:s.currentPage,page:s.page,pageCount:s.pageCount,first:p.d_first,rows:p.d_rows,totalRecords:t.totalRecords,pt:t.pt},null,8,["template","currentPage","page","pageCount","first","rows","totalRecords","pt"])):"RowsPerPageDropdown"===n&&t.rowsPerPageOptions?(r(),u(k,{key:6,"aria-label":s.getAriaLabel("rowsPerPageLabel"),rows:p.d_rows,options:t.rowsPerPageOptions,onRowsChange:e[5]||(e[5]=function(t){return s.onRowChange(t)}),disabled:s.empty,unstyled:t.unstyled,pt:t.pt},null,8,["aria-label","rows","options","disabled","unstyled","pt"])):"JumpToPageDropdown"===n?(r(),u(L,{key:7,"aria-label":s.getAriaLabel("jumpToPageDropdownLabel"),page:s.page,pageCount:s.pageCount,onPageChange:e[6]||(e[6]=function(t){return s.changePage(t)}),disabled:s.empty,unstyled:t.unstyled,pt:t.pt},null,8,["aria-label","page","pageCount","disabled","unstyled","pt"])):"JumpToPageInput"===n?(r(),u(x,{key:8,page:s.currentPage,onPageChange:e[7]||(e[7]=function(t){return s.changePage(t)}),disabled:s.empty,unstyled:t.unstyled,pt:t.pt},null,8,["page","disabled","unstyled","pt"])):y("",!0)],64)})),128)),t.$slots.end?(r(),o("div",i({key:1,class:t.cx("end")},t.ptm("end")),[b(t.$slots,"end",{state:s.currentState})],16)):y("",!0)],16)})),128))],16)):y("",!0)};export{tt as default};