UNPKG

buefy

Version:

Lightweight UI components for Vue.js (v3) based on Bulma

3 lines (2 loc) 11.5 kB
/*! Buefy v3.0.2 | MIT License | github.com/buefy/buefy */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Pagination={},e.Vue)}(this,(function(e,t){"use strict";let n={defaultIconPack:"mdi",defaultIconComponent:null,defaultIconPrev:"chevron-left",defaultIconNext:"chevron-right",defaultLinkTags:["a","button","input","router-link","nuxt-link","n-link","RouterLink","NuxtLink","NLink"]};var a=(e,t)=>{const n=e.__vccOpts||e;for(const[e,a]of t)n[e]=a;return n};var i=a(t.defineComponent({name:"BPaginationButton",props:{page:{type:Object,required:!0},tag:{type:[String,Object],default:"a",validator:e=>"object"==typeof e||n.defaultLinkTags.indexOf(e)>=0},disabled:{type:Boolean,default:!1}},computed:{href(){return"a"===this.tag?"#":void 0},isDisabled(){return this.disabled||this.page.disabled},disabledOrUndefined(){return this.isDisabled||void 0}}}),[["render",function(e,n,a,i,o,l){return t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.tag),t.mergeProps({role:"button",href:e.href,disabled:e.disabledOrUndefined,class:["pagination-link",{"is-current":e.page.isCurrent,[e.page.class]:!0}]},e.$attrs,{onClick:t.withModifiers(e.page.click,["prevent"]),"aria-label":e.page["aria-label"],"aria-current":e.page.isCurrent||void 0}),{default:t.withCtx((()=>[t.renderSlot(e.$slots,"default",{},(()=>[t.createTextVNode(t.toDisplayString(e.page.number),1)]))])),_:3},16,["href","disabled","class","onClick","aria-label","aria-current"])}]]);const o={sizes:{default:"mdi-24px","is-small":null,"is-medium":"mdi-36px","is-large":"mdi-48px"},iconPrefix:"mdi-"},l=()=>{const e="fa-";return{sizes:{default:null,"is-small":null,"is-medium":e+"lg","is-large":e+"2x"},iconPrefix:e,internalIcons:{information:"info-circle",alert:"exclamation-triangle","alert-circle":"exclamation-circle","chevron-right":"angle-right","chevron-left":"angle-left","chevron-down":"angle-down","eye-off":"eye-slash","menu-down":"caret-down","menu-up":"caret-up","close-circle":"times-circle"}}};var r=a(t.defineComponent({name:"BIcon",props:{type:[String,Object],component:String,pack:String,icon:{type:String,required:!0},size:String,customSize:String,customClass:String,both:Boolean},computed:{iconConfig(){return{mdi:o,fa:l(),fas:l(),far:l(),fad:l(),fab:l(),fal:l(),"fa-solid":l(),"fa-regular":l(),"fa-light":l(),"fa-thin":l(),"fa-duotone":l(),"fa-brands":l()}[this.newPack]},iconPrefix(){return this.iconConfig&&this.iconConfig.iconPrefix?this.iconConfig.iconPrefix:""},newIcon(){return`${this.iconPrefix}${this.getEquivalentIconOf(this.icon)}`},newPack(){return this.pack||n.defaultIconPack},newType(){if(!this.type)return;let e=[];if("string"==typeof this.type)e=this.type.split("-");else for(const t in this.type)if(this.type[t]){e=t.split("-");break}if(e.length<=1)return;const[,...t]=e;return`has-text-${t.join("-")}`},newCustomSize(){return this.customSize||this.customSizeByPack},customSizeByPack(){if(this.iconConfig&&this.iconConfig.sizes){if(this.size&&void 0!==this.iconConfig.sizes[this.size])return this.iconConfig.sizes[this.size];if(this.iconConfig.sizes.default)return this.iconConfig.sizes.default}return null},useIconComponent(){return this.component||n.defaultIconComponent}},methods:{getEquivalentIconOf(e){if(!this.both)return e;if(null==this.iconConfig)return e;const t=this.iconConfig;return t&&t.internalIcons&&t.internalIcons[e]?t.internalIcons[e]:e}}}),[["render",function(e,n,a,i,o,l){return t.openBlock(),t.createElementBlock("span",{class:t.normalizeClass(["icon",[e.newType,e.size]])},[e.useIconComponent?(t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.useIconComponent),{key:1,icon:[e.newPack,e.newIcon],size:e.newCustomSize,class:t.normalizeClass([e.customClass])},null,8,["icon","size","class"])):(t.openBlock(),t.createElementBlock("i",{key:0,class:t.normalizeClass([e.newPack,e.newIcon,e.newCustomSize,e.customClass])},null,2))],2)}]]);var s=t.defineComponent({name:"BPagination",components:{BIcon:r,BPaginationButton:i},props:{total:[Number,String],perPage:{type:[Number,String],default:20},modelValue:{type:[Number,String],default:1},rangeBefore:{type:[Number,String],default:1},rangeAfter:{type:[Number,String],default:1},size:String,simple:Boolean,rounded:Boolean,order:String,iconPack:String,iconPrev:{type:String,default:()=>n.defaultIconPrev},iconNext:{type:String,default:()=>n.defaultIconNext},ariaNextLabel:String,ariaPreviousLabel:String,ariaPageLabel:String,ariaCurrentLabel:String,pageInput:{type:Boolean,default:!1},pageInputPosition:String,debouncePageInput:[Number,String]},data(){return{inputValue:this.modelValue,debounceHandlePageInput:void 0}},emits:{change:e=>!0,"update:modelValue":e=>!0},computed:{rootClasses(){return[this.order,this.size,this.pageInputPosition,{"is-simple":this.simple,"is-rounded":this.rounded,"has-input":this.pageInput}]},beforeCurrent(){return parseInt(this.rangeBefore+"")},afterCurrent(){return parseInt(this.rangeAfter+"")},pageCount(){return Math.ceil(+this.total/+this.perPage)},firstItem(){const e=+this.modelValue*+this.perPage-+this.perPage+1;return e>=0?e:0},hasPrev(){return+this.modelValue>1},hasFirst(){return+this.modelValue>=2+this.beforeCurrent},hasFirstEllipsis(){return+this.modelValue>=this.beforeCurrent+4},hasLast(){return+this.modelValue<=this.pageCount-(1+this.afterCurrent)},hasLastEllipsis(){return+this.modelValue<this.pageCount-(2+this.afterCurrent)},hasNext(){return+this.modelValue<this.pageCount},pagesInRange(){if(this.simple)return;let e=Math.max(1,+this.modelValue-this.beforeCurrent);e-1==2&&e--;let t=Math.min(+this.modelValue+this.afterCurrent,this.pageCount);this.pageCount-t===2&&t++;const n=[];for(let a=e;a<=t;a++)n.push(this.getPage(a));return n}},watch:{pageCount(e){this.modelValue>e&&this.last()},modelValue(e){this.inputValue=e},debouncePageInput:{handler(e){this.debounceHandlePageInput=function(e,t){let n;return function(...a){const i=this;clearTimeout(n),n=setTimeout((function(){n=void 0,e.apply(i,a)}),t)}}(this.handleOnInputPageChange,e)},immediate:!0}},methods:{prev(e){this.changePage(+this.modelValue-1,e)},next(e){this.changePage(+this.modelValue+1,e)},first(e){this.changePage(1,e)},last(e){this.changePage(this.pageCount,e)},changePage(e,t){this.modelValue===e||e<1||e>this.pageCount||(this.$emit("update:modelValue",e),this.$emit("change",e),t&&t.target&&this.$nextTick((()=>t.target.focus())))},getPage(e,t={}){return{number:e,isCurrent:this.modelValue===e,click:t=>this.changePage(e,t),input:(e,t)=>this.changePage(+t,e),disabled:t.disabled||!1,class:t.class||"","aria-label":t["aria-label"]||this.getAriaPageLabel(e,this.modelValue===e)}},getAriaPageLabel(e,t){return!this.ariaPageLabel||t&&this.ariaCurrentLabel?this.ariaPageLabel&&t&&this.ariaCurrentLabel?this.ariaCurrentLabel+", "+this.ariaPageLabel+" "+e+".":null:this.ariaPageLabel+" "+e+"."},handleOnInputPageChange(e){this.getPage(+this.inputValue).input(e,this.inputValue)},handleOnInputDebounce(e){this.debouncePageInput?this.debounceHandlePageInput(e):this.handleOnInputPageChange(e)},handleOnKeyPress(e){const t=e.which||e.keyCode;return t>=48&&t<=57||e.preventDefault()},handleAllowableInputPageRange(e){const t=e.target;+t.value>0&&+t.value<=this.pageCount?this.handleOnInputValue(e):(this.inputValue=1,this.inputValue="")},handleOnInputValue(e){const t=+e.target.value;this.inputValue=t,Number.isInteger(this.inputValue)?this.handleOnInputDebounce(e):this.inputValue=this.modelValue}}});const u={class:"control pagination-input"},c=["value","size","maxlength"],p={key:4,class:"info"},g={key:5,class:"pagination-list"},d={key:0},h={key:1},m=[t.createElementVNode("span",{class:"pagination-ellipsis"},"…",-1)],f={key:2},k=[t.createElementVNode("span",{class:"pagination-ellipsis"},"…",-1)],b={key:3};var P=a(s,[["render",function(e,n,a,i,o,l){const r=t.resolveComponent("b-icon"),s=t.resolveComponent("BPaginationButton");return t.openBlock(),t.createElementBlock("nav",{class:t.normalizeClass(["pagination",e.rootClasses])},[e.$slots.previous?t.renderSlot(e.$slots,"previous",{key:0,page:e.getPage(+e.modelValue-1,{disabled:!e.hasPrev,class:"pagination-previous","aria-label":e.ariaPreviousLabel})},(()=>[t.createVNode(r,{icon:e.iconPrev,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])):(t.openBlock(),t.createBlock(s,{key:1,class:"pagination-previous",disabled:!e.hasPrev,page:e.getPage(+e.modelValue-1),"aria-label":e.ariaPreviousLabel},{default:t.withCtx((()=>[t.createVNode(r,{icon:e.iconPrev,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])),_:1},8,["disabled","page","aria-label"])),e.$slots.next?t.renderSlot(e.$slots,"next",{key:2,page:e.getPage(+e.modelValue+1,{disabled:!e.hasNext,class:"pagination-next","aria-label":e.ariaNextLabel})},(()=>[t.createVNode(r,{icon:e.iconNext,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])):(t.openBlock(),t.createBlock(s,{key:3,class:"pagination-next",disabled:!e.hasNext,page:e.getPage(+e.modelValue+1),"aria-label":e.ariaNextLabel},{default:t.withCtx((()=>[t.createVNode(r,{icon:e.iconNext,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])),_:1},8,["disabled","page","aria-label"])),t.createElementVNode("div",u,[e.pageInput?(t.openBlock(),t.createElementBlock("input",{key:0,class:"input",value:e.inputValue,onInput:n[0]||(n[0]=(...t)=>e.handleAllowableInputPageRange&&e.handleAllowableInputPageRange(...t)),onKeypress:n[1]||(n[1]=(...t)=>e.handleOnKeyPress&&e.handleOnKeyPress(...t)),size:e.pageCount.toString().length,maxlength:e.pageCount.toString().length},null,40,c)):t.createCommentVNode("v-if",!0)]),e.simple?(t.openBlock(),t.createElementBlock("small",p,[1==e.perPage?(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createTextVNode(t.toDisplayString(e.firstItem)+" / "+t.toDisplayString(e.total),1)],64)):(t.openBlock(),t.createElementBlock(t.Fragment,{key:1},[t.createTextVNode(t.toDisplayString(e.firstItem)+"-"+t.toDisplayString(Math.min(+e.modelValue*+e.perPage,+e.total))+" / "+t.toDisplayString(e.total),1)],64))])):(t.openBlock(),t.createElementBlock("ul",g,[t.createCommentVNode("First"),e.hasFirst?(t.openBlock(),t.createElementBlock("li",d,[e.$slots.default?t.renderSlot(e.$slots,"default",{key:0,page:e.getPage(1)}):(t.openBlock(),t.createBlock(s,{key:1,page:e.getPage(1)},null,8,["page"]))])):t.createCommentVNode("v-if",!0),e.hasFirstEllipsis?(t.openBlock(),t.createElementBlock("li",h,[...m])):t.createCommentVNode("v-if",!0),t.createCommentVNode("Pages"),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.pagesInRange,(n=>(t.openBlock(),t.createElementBlock("li",{key:n.number},[e.$slots.default?t.renderSlot(e.$slots,"default",{key:0,page:n}):(t.openBlock(),t.createBlock(s,{key:1,page:n},null,8,["page"]))])))),128)),t.createCommentVNode("Last"),e.hasLastEllipsis?(t.openBlock(),t.createElementBlock("li",f,[...k])):t.createCommentVNode("v-if",!0),e.hasLast?(t.openBlock(),t.createElementBlock("li",b,[e.$slots.default?t.renderSlot(e.$slots,"default",{key:0,page:e.getPage(e.pageCount)}):(t.openBlock(),t.createBlock(s,{key:1,page:e.getPage(e.pageCount)},null,8,["page"]))])):t.createCommentVNode("v-if",!0)]))],2)}]]);const C=(e,t,n)=>{const a=t.name;if(null==a)throw new Error("Buefy.registerComponent: missing component name");e.component(a,t)},y={install(e){C(e,P),C(e,i)}};e.BPagination=P,e.BPaginationButton=i,e.default=y,Object.defineProperty(e,"__esModule",{value:!0})}));