UNPKG

buefy

Version:

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

3 lines (2 loc) 15 kB
/*! Buefy v3.0.7 | 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"}}},s={checkboxOn:{type:"svg",viewBox:"0 0 1 1",path:"M 0.04038059,0.6267767 0.14644661,0.52071068 0.42928932,0.80355339 0.3232233,0.90961941 z M 0.21715729,0.80355339 0.85355339,0.16715729 0.95961941,0.2732233 0.3232233,0.90961941 z"},checkboxIndeterminate:{type:"svg",viewBox:"0 0 1 1",path:"M 0.15,0.4 L 0.85,0.4 L 0.85,0.6 L 0.15,0.6 Z"},chevronLeft:{type:"svg",path:"M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z"},chevronRight:{type:"svg",path:"M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z"},chevronDown:{type:"svg",path:"M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z"},chevronUp:{type:"svg",path:"M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z"},menuDown:{type:"svg",path:"M7,10L12,15L17,10H7Z"},menuUp:{type:"svg",path:"M7,14L12,9L17,14H7Z"},check:{type:"svg",path:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"},alertCircle:{type:"svg",path:"M13,13H11V7H13M13,17H11V15H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"},alert:{type:"svg",path:"M13,14H11V10H13M13,18H11V16H13M1,21H23L12,2L1,21Z"},information:{type:"svg",path:"M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"},close:{type:"svg",path:"M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"},closeCircle:{type:"svg",path:"M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z"},eye:{type:"svg",path:"M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z"},eyeOff:{type:"svg",path:"M11.83,9L15,12.16C15,12.11 15,12.05 15,12A3,3 0 0,0 12,9C11.94,9 11.89,9 11.83,9M7.53,9.8L9.08,11.35C9.03,11.56 9,11.77 9,12A3,3 0 0,0 12,15C12.22,15 12.44,14.97 12.65,14.92L14.2,16.47C13.53,16.8 12.79,17 12,17A5,5 0 0,1 7,12C7,11.21 7.2,10.47 7.53,9.8M2,4.27L4.28,6.55L4.73,7C3.08,8.3 1.78,10 1,12C2.73,16.39 7,19.5 12,19.5C13.55,19.5 15.03,19.18 16.38,18.6L16.81,19L19.73,22L21,20.73L3.27,3M12,7A5,5 0 0,1 17,12C17,12.64 16.87,13.26 16.64,13.82L19.57,16.75C21.07,15.5 22.27,13.86 23,12C21.27,7.61 17,4.5 12,4.5C10.6,4.5 9.26,4.75 8,5.2L10.17,7.35C10.74,7.13 11.35,7 12,7Z"}};function r(e){return s[e]}var c=t.defineComponent({name:"BIcon",props:{type:[String,Object],component:String,pack:String,icon:{type:String,required:!1,default:void 0},alias:String,size:String,customSize:String,customClass:String,both:Boolean},computed:{resolvedAlias(){var e;return this.alias&&null!=(e=r(this.alias))?e:null},isSvgAlias(){var e;return"svg"===(null==(e=this.resolvedAlias)?void 0:e.type)},isComponentAlias(){var e;return"component"===(null==(e=this.resolvedAlias)?void 0:e.type)},resolvedAliasSvg(){return this.resolvedAlias},resolvedAliasComponent(){return this.resolvedAlias},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(){var e;return`${this.iconPrefix}${this.getEquivalentIconOf(null!=(e=this.icon)?e:"")}`},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}}});const u=["viewBox"],p=["d"];var g=a(c,[["render",function(e,n,a,i,o,l){return t.openBlock(),t.createElementBlock("span",{class:t.normalizeClass(["icon",[e.newType,e.size]])},[e.isSvgAlias?(t.openBlock(),t.createElementBlock("svg",{key:0,viewBox:e.resolvedAliasSvg.viewBox||"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",class:t.normalizeClass(e.customClass),"aria-hidden":"true"},[t.createElementVNode("path",{fill:"currentColor",d:e.resolvedAliasSvg.path},null,8,p)],10,u)):e.isComponentAlias?(t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.resolvedAliasComponent.component),{key:1,icon:e.resolvedAliasComponent.icon,class:t.normalizeClass(e.customClass)},null,8,["icon","class"])):e.useIconComponent?(t.openBlock(),t.createBlock(t.resolveDynamicComponent(e.useIconComponent),{key:3,icon:[e.newPack,e.newIcon],size:e.newCustomSize,class:t.normalizeClass([e.customClass])},null,8,["icon","size","class"])):(t.openBlock(),t.createElementBlock("i",{key:2,class:t.normalizeClass([e.newPack,e.newIcon,e.newCustomSize,e.customClass])},null,2))],2)}]]);var d=t.defineComponent({name:"BPagination",components:{BIcon:g,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 h={class:"control pagination-input"},m=["value","size","maxlength"],f={key:4,class:"info"},C={key:5,class:"pagination-list"},k={key:0},v={key:1},L=[t.createElementVNode("span",{class:"pagination-ellipsis"},"…",-1)],b={key:2},y=[t.createElementVNode("span",{class:"pagination-ellipsis"},"…",-1)],P={key:3};var B=a(d,[["render",function(e,n,a,i,o,l){const s=t.resolveComponent("b-icon"),r=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(s,{icon:e.iconPrev,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])):(t.openBlock(),t.createBlock(r,{key:1,class:"pagination-previous",disabled:!e.hasPrev,page:e.getPage(+e.modelValue-1),"aria-label":e.ariaPreviousLabel},{default:t.withCtx((()=>[t.createVNode(s,{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(s,{icon:e.iconNext,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])):(t.openBlock(),t.createBlock(r,{key:3,class:"pagination-next",disabled:!e.hasNext,page:e.getPage(+e.modelValue+1),"aria-label":e.ariaNextLabel},{default:t.withCtx((()=>[t.createVNode(s,{icon:e.iconNext,pack:e.iconPack,both:"","aria-hidden":"true"},null,8,["icon","pack"])])),_:1},8,["disabled","page","aria-label"])),t.createElementVNode("div",h,[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,m)):t.createCommentVNode("v-if",!0)]),e.simple?(t.openBlock(),t.createElementBlock("small",f,[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",C,[t.createCommentVNode("First"),e.hasFirst?(t.openBlock(),t.createElementBlock("li",k,[e.$slots.default?t.renderSlot(e.$slots,"default",{key:0,page:e.getPage(1)}):(t.openBlock(),t.createBlock(r,{key:1,page:e.getPage(1)},null,8,["page"]))])):t.createCommentVNode("v-if",!0),e.hasFirstEllipsis?(t.openBlock(),t.createElementBlock("li",v,[...L])):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(r,{key:1,page:n},null,8,["page"]))])))),128)),t.createCommentVNode("Last"),e.hasLastEllipsis?(t.openBlock(),t.createElementBlock("li",b,[...y])):t.createCommentVNode("v-if",!0),e.hasLast?(t.openBlock(),t.createElementBlock("li",P,[e.$slots.default?t.renderSlot(e.$slots,"default",{key:0,page:e.getPage(e.pageCount)}):(t.openBlock(),t.createBlock(r,{key:1,page:e.getPage(e.pageCount)},null,8,["page"]))])):t.createCommentVNode("v-if",!0)]))],2)}]]);const V=(e,t,n)=>{const a=t.name;if(null==a)throw new Error("Buefy.registerComponent: missing component name");e.component(a,t)},x={install(e){V(e,B),V(e,i)}};e.BPagination=B,e.BPaginationButton=i,e.default=x,Object.defineProperty(e,"__esModule",{value:!0})}));