vueye-table 2.0.0-alpha.12 → 2.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/core/VueyeTable/components/VueyeBody/VueyeBody.vue.d.ts +1 -0
- package/dist/components/core/VueyeTable/components/VueyeBody/api.d.ts +1 -0
- package/dist/components/core/VueyeTable/components/utils/VueyeCheckbox.vue.d.ts +2 -3
- package/dist/components/core/VueyeTable/composables/useBodyRows.d.ts +1 -0
- package/dist/components/core/VueyeTable/utils/body.d.ts +2 -2
- package/dist/vueye-table.js +390 -372
- package/dist/vueye-table.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/vueye-table.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f["vueye-table"]={},f.Vue))})(this,function(f,e){"use strict";function R(n){return n.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/(?:^|\s)\S/g,o=>o.toUpperCase()).trim().replace(/\s\s+/g," ")}function w(n){let o=1;return n.forEach(t=>{t.children&&(o=Math.max(o,w(t.children)+1))}),o}function V(n){let o=0;return n.forEach(t=>{t.children?o+=V(t.children):o++}),o}function $(n,o,t=[],l=0,r=0,c=""){return n.forEach(d=>{if(t[l]||(t[l]=[]),d.children){const{children:m,...s}=d,a=V(m);t[l].push({...s,colSpan:a,scope:"colgroup"}),$(m,o,t,l+1,r+1,`${c}${d.key}.`)}else{const m=o-r;t[l].push({...d,key:d.key,fullKey:`${c}${d.key}`,label:d.label,rowSpan:m,scope:"col",sortable:Object.prototype.hasOwnProperty.call(d,"sortable")?d.sortable:!0})}}),t}function P(n,o="",t=[]){return n.forEach(l=>{l.children?P(l.children,`${o}${l.key}.`,t):t.push(`${o}${l.key}`)}),t}function I(n){const o=w(n);return $(n,o).reduce((r,c)=>[...r,...c],[])}function S(n){const o=[];for(const t in n){const l=R(t),r={key:t,label:l};if(typeof n[t]=="object"&&n[t]!==null){const c=S(n[t]);c.length>0&&(r.children=c)}o.push(r)}return o}const A=(n,o)=>{const t=o.split(".");let l=n;for(let r=0;r<t.length;r++)if(l[t[r]])l=l[t[r]];else return;return l};function D(n,o){return n.map(t=>P(o).map(l=>({[l]:A(t,l)})).reduce((l,r)=>({...l,...r}),{}))}function O(n,o=0,t=n.length){return n.slice(o,t)}function C(n){const o={};for(const[t,l]of Object.entries(n))if(t.includes(".")){const[r,c]=t.split(".");o[r]||(o[r]={}),o[r][c]=l}else o[t]=l;for(const[t,l]of Object.entries(o))typeof l=="object"&&(o[t]=C(l));return o}function M(n){const o=[];for(const t in n)typeof n[t]=="object"?o.push(...M(n[t])):o.push(n[t]);return o}function L(n){return typeof n!="function"||typeof n!="object"}function Q(n){return(o,t,l)=>n(o,t,l)}function j(){return{itemValue:"id",columnHeaders:()=>[],data:()=>[],perPage:10,currentPage:1,perPageOptions:()=>[5,10,20,30],loading:!1,selected:null,selectMode:"all",caption:"",summary:"",filterQuery:"",filterBy:void 0,filterMethod:(n,o,t)=>n===""||n===void 0||t===void 0||t.length===0?!0:t==null?void 0:t.some(r=>{const c=o[r];return L(c)?c==null?void 0:c.toString().toLowerCase().includes(n.toLowerCase()):!1})}}const W={options:()=>[],modelValue:"",label:""},y=(n,o)=>{const t=n.__vccOpts||n;for(const[l,r]of o)t[l]=r;return t},Z={},G={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},q=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"m19 9l-7 6l-7-6"},null,-1)];function J(n,o){return e.openBlock(),e.createElementBlock("svg",G,q)}const X=y(Z,[["render",J]]),Y={class:"table__dropdown-wrapper"},x=["aria-expanded"],v={class:"py-1",role:"none"},ee=["onClick"],te=e.defineComponent({__name:"VueyeDropdown",props:e.mergeDefaults({options:{},modelValue:{},label:{},defaultValue:{}},W),emits:["update:modelValue"],setup(n,{emit:o}){const t=n,l=e.ref(!1),r=e.ref(-1),c=e.ref(null),d=e.ref(null),m=e.ref(!0),s=e.computed(()=>r.value===-1?t.options[0]:t.options[r.value]),a=`dropdown-label-${Math.random().toString(36).substring(2,9)}`;async function i(){var h,p;if(l.value=!l.value,l.value){await e.nextTick();const k=((h=c.value)==null?void 0:h.getBoundingClientRect())??{bottom:0},b=((p=d.value)==null?void 0:p.offsetHeight)??200;m.value=window.innerHeight-(k==null?void 0:k.bottom)>b}}function u(h){r.value=h,l.value=!1,o("update:modelValue",s.value.content)}return e.watchEffect(()=>{const h=t.options.findIndex(p=>p.content===t.modelValue);h!==-1&&(r.value=h),t.modelValue===void 0&&(r.value=-1)}),(h,p)=>(e.openBlock(),e.createElementBlock("div",Y,[e.createElementVNode("button",{type:"button",class:"table__dropdown-trigger",onClick:i,"aria-expanded":e.unref(l),"aria-haspopup":!0,ref_key:"buttonRef",ref:c},[e.createElementVNode("span",null,e.toDisplayString(e.unref(s).label),1),e.createVNode(X)],8,x),e.unref(l)?(e.openBlock(),e.createElementBlock("div",{key:0,class:"table__dropdown-overlay",onClick:i})):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("div",{class:e.normalizeClass(["table__dropdown-menu",{"table__dropdown-menu--top":!e.unref(m)}]),role:"menu","aria-orientation":"vertical","aria-labelledby":a,ref_key:"dropdownMenuRef",ref:d},[e.createElementVNode("div",v,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.options,(k,b)=>(e.openBlock(),e.createElementBlock("button",{key:b,class:e.normalizeClass([{"table__dropdown-menu-item--selected ":b===e.unref(r)},"table__dropdown-menu-item"]),role:"menuitem",onClick:B=>u(b)},e.toDisplayString(k.label),11,ee))),128))])],2),[[e.vShow,e.unref(l)]])]))}}),ne={loading:!1,bodyRows:()=>[],itemValue:"id",columnsLength:0},oe=["id","checked","indeterminate"],le=["for"],ae=e.createStaticVNode('<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.5"><path class="rounded-square" d="M2 12c0-4.714 0-7.071 1.464-8.536C4.93 2 7.286 2 12 2c4.714 0 7.071 0 8.535 1.464C22 4.93 22 7.286 22 12c0 4.714 0 7.071-1.465 8.535C19.072 22 16.714 22 12 22s-7.071 0-8.536-1.465C2 19.072 2 16.714 2 12Z"></path><path class="checkmark" stroke-linecap="round" stroke-linejoin="round" d="m8.5 12.5l2 2l5-5"></path><path class="indeterminate" stroke-linecap="round" stroke-linejoin="round" d="M6 12h12"></path></g></svg>',1),z=e.defineComponent({inheritAttrs:!1,__name:"VueyeCheckbox",props:{checked:Boolean,id:String,label:String,indeterminate:Boolean,modelValue:Boolean},emits:["change","update:modelValue"],setup(n,{emit:o}){const t=n,l=e.ref(t.modelValue),r=e.computed({get(){return t.modelValue},set(d){o("update:modelValue",d)}}),c=d=>{o("change",d)};return(d,m)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["table__checkbox",{"table__checkbox--checked":l.value,"table__checkbox--indeterminate":n.indeterminate}])},[e.withDirectives(e.createElementVNode("input",e.mergeProps({id:n.id,type:"checkbox",checked:l.value,"onUpdate:modelValue":m[0]||(m[0]=s=>e.isRef(r)?r.value=s:null),indeterminate:n.indeterminate,onChange:c,"aria-labelledby":"checkboxLabel"},d.$attrs),null,16,oe),[[e.vModelCheckbox,e.unref(r)]]),e.createElementVNode("label",{for:n.id,id:"checkboxLabel"},e.toDisplayString(n.label),9,le),ae],2))}}),ct="",re={class:"table__body"},se={key:0,class:"table__row table__row--loading"},ce=["colspan"],ie={key:1,class:"table__row table__row--empty"},de=["colspan"],pe=e.createElementVNode("div",{class:"text-center"},"No data available",-1),me={class:"table__row"},fe={class:"table__cell table_cell--checkbox"},ue={class:"table__cell"},ge=e.defineComponent({__name:"VueyeBody",props:e.mergeDefaults({loading:{type:Boolean},bodyRows:{},itemValue:{},columnsLength:{},selected:{}},ne),emits:["update:selected"],setup(n,{emit:o}){const t=n,l=e.computed(()=>Object.keys(t.bodyRows[0])),r=e.computed(()=>l.value.reduce((s,a)=>({...s,[a]:a.split(".").pop()??""}),{})),c=e.computed(()=>t.bodyRows.map(s=>({flat:s,nest:C(s)}))),d=e.computed(()=>c.value.map(s=>s.nest)),m=e.computed({get(){return t.selected},set(s){o("update:selected",s)}});return(s,a)=>e.renderSlot(s.$slots,"body",{rows:s.bodyRows},()=>[e.createElementVNode("tbody",re,[s.loading?(e.openBlock(),e.createElementBlock("tr",se,[e.createElementVNode("td",{colspan:s.columnsLength,class:"table__cell table__cell--loading"},[e.renderSlot(s.$slots,"loading",{},()=>[e.createTextVNode(" Loading... ")])],8,ce)])):s.bodyRows.length===0?(e.openBlock(),e.createElementBlock("tr",ie,[e.createElementVNode("td",{class:"table__cell",colspan:s.columnsLength},[e.renderSlot(s.$slots,"empty",{},()=>[pe])],8,de)])):e.renderSlot(s.$slots,"rows",{key:2,rows:e.unref(d)},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(c),i=>e.renderSlot(s.$slots,"row",{key:i[s.itemValue],row:i.nest},()=>[e.createElementVNode("tr",me,[s.selected?e.renderSlot(s.$slots,"checkbox",{key:0,row:i.nest},()=>[e.createElementVNode("td",fe,[e.createVNode(z,{modelValue:e.unref(m),"onUpdate:modelValue":a[0]||(a[0]=u=>e.isRef(m)?m.value=u:null),value:i.nest,"aria-label":"Select row"},null,8,["modelValue","value"])])]):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(l),u=>e.renderSlot(s.$slots,`itemCell.${u}`,{key:`${i[s.itemValue]}.${u}`,itemCell:i.nest},()=>[e.createElementVNode("td",ue,[e.renderSlot(s.$slots,`itemCellContent.${e.unref(r)[u]}`,{itemCellContent:i.nest},()=>[e.createTextVNode(e.toDisplayString(i.flat[u]),1)])])])),128))])])),128))])])])}}),he={columnHeaders:()=>[],selectable:!1,select:"none"},_e={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 16 16"},be=["opacity"],ke=["opacity"],ye=e.defineComponent({__name:"ArrowUpDownIcon",props:{down:Boolean},setup(n){const o=n,t=e.computed(()=>({up:o.down?.5:1,down:o.down?1:.5}));return(l,r)=>(e.openBlock(),e.createElementBlock("svg",_e,[e.createElementVNode("path",{opacity:e.unref(t).up,fill:"currentColor",fillRule:"evenodd",d:"M2.22 5.53a.75.75 0 0 1 0-1.06l2.25-2.25a.75.75 0 0 1 1.06 0l2.25 2.25a.75.75 0 0 1-1.06 1.06l-.97-.97v5.69a.75.75 0 0 1-1.5 0V4.56l-.97.97a.75.75 0 0 1-1.06 0",clipRule:"evenodd"},null,8,be),e.createElementVNode("path",{opacity:e.unref(t).down,fill:"currentColor",fillRule:"evenodd",d:"M13.78 10.47a.75.75 0 0 1 0 1.06l-2.25 2.25a.75.75 0 0 1-1.06 0l-2.25-2.25a.75.75 0 1 1 1.06-1.06l.97.97V5.75a.75.75 0 0 1 1.5 0v5.69l.97-.97a.75.75 0 0 1 1.06 0",clipRule:"evenodd"},null,8,ke)]))}}),we={class:"table__head"},Ve=["colspan","rowspan","scope"],$e=["onClick"],Pe=e.defineComponent({__name:"VueyeHead",props:e.mergeDefaults({columnHeaders:{},selectable:{type:Boolean},select:{}},he),emits:["update:select","sort"],setup(n,{emit:o}){const t=n,l=e.ref(""),r=e.ref(!1),c=a=>{a.sortable&&a.scope==="col"&&(l.value===a.fullKey?r.value=!r.value:(l.value=a.fullKey??"",r.value=!1),o("sort",{key:l.value,desc:r.value}))},d=e.computed(()=>t.selectable?[[{key:"checkbox",label:"",className:"checkbox",colSpan:1,rowSpan:t.columnHeaders.length,scope:"col"},...t.columnHeaders[0]],...t.columnHeaders.slice(1)]:t.columnHeaders),m=e.computed({get(){return t.select},set(a){o("update:select",a)}}),s=a=>{a.target.checked?m.value="all":m.value="none"};return(a,i)=>e.renderSlot(a.$slots,"headers",{headers:a.columnHeaders},()=>[e.createElementVNode("thead",we,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(d),(u,h)=>(e.openBlock(),e.createElementBlock("tr",{class:"table__row table__row",key:h},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(u,p=>e.renderSlot(a.$slots,`headerCell.${p.key}`,{key:p.key,headerItem:p},()=>[e.createElementVNode("th",{colspan:p.colSpan,rowspan:p.rowSpan,scope:p.scope,class:e.normalizeClass(["table__cell table__cell--head",p.className])},[p.key==="checkbox"&&a.selectable?e.renderSlot(a.$slots,"checkbox",{key:0},()=>[e.createVNode(z,{indeterminate:e.unref(m)==="indeterminate",type:"checkbox",checked:e.unref(m)==="all",onChange:s,"aria-label":"select all rows",class:"table__checkbox"},null,8,["indeterminate","checked"])]):e.renderSlot(a.$slots,`headerCellContent.${p.key}`,{key:1,headerItem:p},()=>[p.scope==="col"?(e.openBlock(),e.createElementBlock("button",{key:0,onClick:k=>c(p),class:"table__sort-button"},[e.createElementVNode("span",{class:e.normalizeClass(["table__label table__label--head",p.labelClassName])},e.toDisplayString(p.label),3),e.createVNode(ye,{class:e.normalizeClass([{"table__sort-icon--show":e.unref(l)===p.key},"table__sort-icon"]),down:e.unref(r)},null,8,["class","down"])],8,$e)):(e.openBlock(),e.createElementBlock("span",{key:1,class:e.normalizeClass(["table__label table__label--head",p.labelClassName])},e.toDisplayString(p.label),3))])],10,Ve)])),128))]))),128))])])}}),it="",Ce={},Be={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},Ee=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"m9 5l6 7l-6 7"},null,-1)];function Se(n,o){return e.openBlock(),e.createElementBlock("svg",Be,Ee)}const Ne=y(Ce,[["render",Se]]),Re={},De={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},Oe=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"m15 5l-6 7l6 7"},null,-1)];function Me(n,o){return e.openBlock(),e.createElementBlock("svg",De,Oe)}const Le=y(Re,[["render",Me]]),je={},ze={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},He=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5"},[e.createElementVNode("path",{d:"m11 19l6-7l-6-7"}),e.createElementVNode("path",{d:"m7 19l6-7l-6-7"})],-1)];function Te(n,o){return e.openBlock(),e.createElementBlock("svg",ze,He)}const Ke=y(je,[["render",Te]]),Ue={},Fe={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},Ie=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5"},[e.createElementVNode("path",{d:"m13 19l-6-7l6-7"}),e.createElementVNode("path",{d:"m17 19l-6-7l6-7"})],-1)];function Ae(n,o){return e.openBlock(),e.createElementBlock("svg",Fe,Ie)}const Qe=y(Ue,[["render",Ae]]),We={perPage:10,currentPage:1,total:0,perPageOptions:()=>[10,20,30,40,50]},Ze={class:"table__pagination-wrapper"},Ge={class:"table__pagination-details"},qe={class:"table__pagination-btn-list"},Je=["disabled"],Xe=["disabled"],Ye=["onClick","aria-label"],xe={key:1,class:"table__pagination-btn table__btn"},ve=["disabled"],et=["disabled"],tt=e.defineComponent({__name:"VueyePagination",props:e.mergeDefaults({perPage:{},currentPage:{},total:{},perPageOptions:{}},We),emits:["update:currentPage","update:perPage"],setup(n,{emit:o}){const t=n,l=e.computed(()=>Math.ceil(t.total/t.perPage)),r=e.computed(()=>t.perPageOptions.map(a=>({content:a,label:a.toString()}))),c=e.computed(()=>r.value.find(a=>a.content===t.perPage)),d=e.computed(()=>Array.from({length:l.value},(a,i)=>i+1).reduce((a,i)=>(i===1||i===t.total||i>=t.currentPage-2&&i<=t.currentPage+2?a.push(i):(i===t.currentPage-3||i===t.currentPage+3)&&a.push("..."),a),[]));function m(a){o("update:perPage",Number(a))}function s(a){a>=1&&a<=l.value&&o("update:currentPage",a)}return(a,i)=>(e.openBlock(),e.createElementBlock("div",Ze,[e.createVNode(e.unref(te),{options:e.unref(r),"default-value":e.unref(c),label:"Per page","onUpdate:modelValue":m},null,8,["options","default-value"]),e.createElementVNode("span",Ge,e.toDisplayString((a.currentPage-1)*a.perPage+1)+" - "+e.toDisplayString(a.currentPage*a.perPage>a.total?a.total:a.currentPage*a.perPage)+" of "+e.toDisplayString(a.total),1),e.createElementVNode("ul",qe,[e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[0]||(i[0]=u=>s(1)),disabled:a.currentPage===1,"aria-label":"First page"},[e.createVNode(Qe)],8,Je)]),e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[1]||(i[1]=u=>s(t.currentPage-1)),disabled:a.currentPage===1,"aria-label":"Previous page"},[e.createVNode(Le)],8,Xe)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(d),u=>(e.openBlock(),e.createElementBlock("li",{key:u},[typeof u=="number"?(e.openBlock(),e.createElementBlock("button",{key:0,class:e.normalizeClass(["table__pagination-btn table__btn",{"table__pagination-btn--current ":u===a.currentPage}]),onClick:h=>s(u),"aria-label":"Go to page "+u},e.toDisplayString(u),11,Ye)):(e.openBlock(),e.createElementBlock("span",xe,"..."))]))),128)),e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[2]||(i[2]=u=>s(a.currentPage+1)),disabled:a.currentPage===e.unref(l),"aria-label":"Next page"},[e.createVNode(Ne)],8,ve)]),e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[3]||(i[3]=u=>s(a.total)),disabled:a.currentPage===e.unref(l),"aria-label":"Last page"},[e.createVNode(Ke)],8,et)])])]))}});function nt(n){return{headerKeys:e.computed(()=>P(n.flat()))}}function H(n={},o){const t=e.ref({perPage:n.perPage||10,currentPage:n.currentPage||1});e.watchEffect(()=>{t.value.perPage=n.perPage||10,t.value.currentPage=n.currentPage||1});function l(c){t.value.currentPage=c,o("update:currentPage",c)}function r(c){t.value.perPage=c,o("update:perPage",c)}return{pagination:t,updateCurrentPage:l,updatePerPage:r}}function T(n,o,t){const l=e.ref(),r=e.ref(!1);function c({key:m,desc:s}){l.value=m,r.value=s}return{bodyRows:e.computed(()=>{const m=e.toValue(t).perPage*(e.toValue(t).currentPage-1),s=e.toValue(t).perPage*e.toValue(t).currentPage,a=D(e.toValue(n.data),e.toValue(o)),i=e.computed(()=>n.filterBy===void 0||n.filterBy.length===0?Object.keys(a[0]):n.filterBy),u=a.filter(h=>{var p;return(p=n.filterMethod)==null?void 0:p.call(n,n.filterQuery,h,e.toValue(i))});return l.value&&u.sort((h,p)=>{if(!l.value)return 0;const k=h[l.value],b=p[l.value];return k<b?r.value?1:-1:k>b?r.value?-1:1:0}),O(u,m,s)}),rowsCount:e.computed(()=>e.toValue(n.data).length),onSort:c}}function K(n){const o=e.unref(n)??[];return{headers:e.computed(()=>$(o,w(o))),headersCount:V(o)}}function U(n,o,t){const l=e.computed({get(){var c,d,m;return n.selected===null||((c=n.selected)==null?void 0:c.length)===0?"none":((d=n.selected)==null?void 0:d.length)===n.data.length||n.selectMode==="page"&&((m=n.selected)==null?void 0:m.length)===o.value.length?"all":"indeterminate"},set(c){c==="all"?n.selectMode==="page"?r.value=o.value.map(d=>C(d)):r.value=n.data:c==="none"&&(r.value=[])}}),r=e.computed({get(){return n.selected},set(c){t("update:selected",c)}});return{selectAll:l,selected:r}}const ot={class:"table__wrapper"},lt={key:0,class:"table__caption"},at={class:"table__summary"},rt=e.defineComponent({inheritAttrs:!1,__name:"VueyeTable",props:e.mergeDefaults({data:{},columnHeaders:{},itemValue:{},perPage:{},currentPage:{},perPageOptions:{},loading:{type:Boolean},selected:{},selectMode:{},caption:{},summary:{},filterQuery:{},filterBy:{},filterMethod:{type:Function}},j()),emits:["update:currentPage","update:perPage","update:loading","update:selected"],setup(n,{emit:o}){const t=n,l=e.computed(()=>t.columnHeaders.length===0?S(t.data[0]):t.columnHeaders),{headers:r,headersCount:c}=K(l),d=e.useSlots(),m=Object.keys(d).filter(g=>g.startsWith("headerCell")),s=Object.keys(d).filter(g=>g.startsWith("itemCell")),{pagination:a,updateCurrentPage:i,updatePerPage:u}=H(t,o),{bodyRows:h,rowsCount:p,onSort:k}=T(t,l,a),{selected:b,selectAll:B}=U(t,h,o);return(g,E)=>(e.openBlock(),e.createElementBlock("div",ot,[e.createElementVNode("table",{class:e.normalizeClass(g.$attrs.class??"table")},[e.renderSlot(g.$slots,"caption",{},()=>[g.caption?(e.openBlock(),e.createElementBlock("caption",lt,e.toDisplayString(g.caption),1)):e.createCommentVNode("",!0)]),e.createVNode(e.unref(Pe),{columnHeaders:e.unref(r),selectable:g.selected!==null,select:e.unref(B),"onUpdate:select":E[0]||(E[0]=_=>e.isRef(B)?B.value=_:null),onSort:e.unref(k)},e.createSlots({headers:e.withCtx(_=>[e.renderSlot(g.$slots,"headers",e.normalizeProps(e.guardReactiveProps(_)))]),_:2},[e.renderList(e.unref(m),_=>({name:_,fn:e.withCtx(N=>[e.renderSlot(g.$slots,_,e.normalizeProps(e.guardReactiveProps(N)))])}))]),1032,["columnHeaders","selectable","select","onSort"]),e.createVNode(e.unref(ge),{selected:e.unref(b),"onUpdate:selected":E[1]||(E[1]=_=>e.isRef(b)?b.value=_:null),bodyRows:e.unref(h),loading:g.loading,itemValue:g.itemValue,"columns-length":e.unref(c)},e.createSlots({checkbox:e.withCtx(_=>[e.renderSlot(g.$slots,"checkbox",e.normalizeProps(e.guardReactiveProps(_)))]),loading:e.withCtx(()=>[e.renderSlot(g.$slots,"loading")]),empty:e.withCtx(()=>[e.renderSlot(g.$slots,"empty")]),rows:e.withCtx(_=>[e.renderSlot(g.$slots,"rows",e.normalizeProps(e.guardReactiveProps(_)))]),row:e.withCtx(_=>[e.renderSlot(g.$slots,"row",e.normalizeProps(e.guardReactiveProps(_)))]),_:2},[e.renderList(e.unref(s),_=>({name:_,fn:e.withCtx(N=>[e.renderSlot(g.$slots,_,e.normalizeProps(e.guardReactiveProps(N)))])}))]),1032,["selected","bodyRows","loading","itemValue","columns-length"]),e.renderSlot(g.$slots,"summary",{},()=>[e.createElementVNode("caption",at,e.toDisplayString(g.summary),1)])],2),e.renderSlot(g.$slots,"pagination",{pagination:{...e.unref(a),perPageOptions:g.perPageOptions,total:e.unref(p)}},()=>[e.withDirectives(e.createVNode(e.unref(tt),{perPage:e.unref(a).perPage,currentPage:e.unref(a).currentPage,perPageOptions:g.perPageOptions,total:e.unref(p),"onUpdate:currentPage":e.unref(i),"onUpdate:perPage":e.unref(u),class:"table__pagination"},null,8,["perPage","currentPage","perPageOptions","total","onUpdate:currentPage","onUpdate:perPage"]),[[e.vShow,g.data.length>0]])])]))}}),ut="";function F(n){const o=[];for(const t of n){const l=t.children?F(t.children):void 0;o.push({...t,children:l})}return o}f.VueyeTable=rt,f.deepValues=M,f.defineColumnHeaders=I,f.defineFilterMethod=Q,f.defineTableColumnHeaders=F,f.depthCount=w,f.flatHeadersToRows=$,f.generateColumns=S,f.getBodyRows=D,f.getHeaderKeys=P,f.getVueyeTablePropDefaults=j,f.humanize=R,f.isPrimitive=L,f.leafCount=V,f.nestedObjectTransformer=C,f.paginateRows=O,f.useBodyRows=T,f.useHeaderKeys=nt,f.useHeaders=K,f.usePagination=H,f.useSelection=U,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f["vueye-table"]={},f.Vue))})(this,function(f,e){"use strict";function D(n){return n.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/(?:^|\s)\S/g,o=>o.toUpperCase()).trim().replace(/\s\s+/g," ")}function $(n){let o=1;return n.forEach(t=>{t.children&&(o=Math.max(o,$(t.children)+1))}),o}function P(n){let o=0;return n.forEach(t=>{t.children?o+=P(t.children):o++}),o}function C(n,o,t=[],l=0,r=0,s=""){return n.forEach(d=>{if(t[l]||(t[l]=[]),d.children){const{children:u,...c}=d,a=P(u);t[l].push({...c,colSpan:a,scope:"colgroup"}),C(u,o,t,l+1,r+1,`${s}${d.key}.`)}else{const u=o-r;t[l].push({...d,key:d.key,fullKey:`${s}${d.key}`,label:d.label,rowSpan:u,scope:"col",sortable:Object.prototype.hasOwnProperty.call(d,"sortable")?d.sortable:!0})}}),t}function w(n,o="",t=[]){return n.forEach(l=>{l.children?w(l.children,`${o}${l.key}.`,t):t.push(`${o}${l.key}`)}),t}function I(n){const o=$(n);return C(n,o).reduce((r,s)=>[...r,...s],[])}function B(n){const o=[];for(const t in n){const l=D(t),r={key:t,label:l};if(typeof n[t]=="object"&&n[t]!==null){const s=B(n[t]);s.length>0&&(r.children=s)}o.push(r)}return o}const Q=(n,o)=>{const t=o.split(".");let l=n;for(let r=0;r<t.length;r++)if(l[t[r]])l=l[t[r]];else return;return l};function K(n,o){return n.map(t=>o.map(s=>({[s]:Q(t,s)})).reduce((s,d)=>({...s,...d}),{}))}function L(n,o=0,t=n.length){return n.slice(o,t)}function E(n){const o={};for(const[t,l]of Object.entries(n))if(t.includes(".")){const[r,s]=t.split(".");o[r]||(o[r]={}),o[r][s]=l}else o[t]=l;for(const[t,l]of Object.entries(o))typeof l=="object"&&(o[t]=E(l));return o}function O(n){const o=[];for(const t in n)typeof n[t]=="object"?o.push(...O(n[t])):o.push(n[t]);return o}function H(n){return typeof n!="function"||typeof n!="object"}function W(n){return(o,t,l)=>n(o,t,l)}function M(){return{itemValue:"id",columnHeaders:()=>[],data:()=>[],perPage:10,currentPage:1,perPageOptions:()=>[5,10,20,30],loading:!1,selected:null,selectMode:"all",caption:"",summary:"",filterQuery:"",filterBy:void 0,filterMethod:(n,o,t)=>n===""||n===void 0||t===void 0||t.length===0?!0:t==null?void 0:t.some(r=>{const s=o[r];return H(s)?s==null?void 0:s.toString().toLowerCase().includes(n.toLowerCase()):!1})}}const Z={options:()=>[],modelValue:"",label:""},V=(n,o)=>{const t=n.__vccOpts||n;for(const[l,r]of o)t[l]=r;return t},G={},q={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},J=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"m19 9l-7 6l-7-6"},null,-1)];function X(n,o){return e.openBlock(),e.createElementBlock("svg",q,J)}const Y=V(G,[["render",X]]),x={class:"table__dropdown-wrapper"},v=["aria-expanded"],ee={class:"py-1",role:"none"},te=["onClick"],ne=e.defineComponent({__name:"VueyeDropdown",props:e.mergeDefaults({options:{},modelValue:{},label:{},defaultValue:{}},Z),emits:["update:modelValue"],setup(n,{emit:o}){const t=n,l=e.ref(!1),r=e.ref(-1),s=e.ref(null),d=e.ref(null),u=e.ref(!0),c=e.computed(()=>r.value===-1?t.options[0]:t.options[r.value]),a=`dropdown-label-${Math.random().toString(36).substring(2,9)}`;async function i(){var g,p;if(l.value=!l.value,l.value){await e.nextTick();const b=((g=s.value)==null?void 0:g.getBoundingClientRect())??{bottom:0},k=((p=d.value)==null?void 0:p.offsetHeight)??200;u.value=window.innerHeight-(b==null?void 0:b.bottom)>k}}function m(g){r.value=g,l.value=!1,o("update:modelValue",c.value.content)}return e.watchEffect(()=>{const g=t.options.findIndex(p=>p.content===t.modelValue);g!==-1&&(r.value=g),t.modelValue===void 0&&(r.value=-1)}),(g,p)=>(e.openBlock(),e.createElementBlock("div",x,[e.createElementVNode("button",{type:"button",class:"table__dropdown-trigger",onClick:i,"aria-expanded":e.unref(l),"aria-haspopup":!0,ref_key:"buttonRef",ref:s},[e.createElementVNode("span",null,e.toDisplayString(e.unref(c).label),1),e.createVNode(Y)],8,v),e.unref(l)?(e.openBlock(),e.createElementBlock("div",{key:0,class:"table__dropdown-overlay",onClick:i})):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("div",{class:e.normalizeClass(["table__dropdown-menu",{"table__dropdown-menu--top":!e.unref(u)}]),role:"menu","aria-orientation":"vertical","aria-labelledby":a,ref_key:"dropdownMenuRef",ref:d},[e.createElementVNode("div",ee,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(g.options,(b,k)=>(e.openBlock(),e.createElementBlock("button",{key:k,class:e.normalizeClass([{"table__dropdown-menu-item--selected ":k===e.unref(r)},"table__dropdown-menu-item"]),role:"menuitem",onClick:y=>m(k)},e.toDisplayString(b.label),11,te))),128))])],2),[[e.vShow,e.unref(l)]])]))}}),oe={loading:!1,bodyRows:()=>[],itemValue:"id",columnsLength:0},le=["id","checked","indeterminate"],ae=["for"],re=e.createStaticVNode('<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.5"><path class="rounded-square" d="M2 12c0-4.714 0-7.071 1.464-8.536C4.93 2 7.286 2 12 2c4.714 0 7.071 0 8.535 1.464C22 4.93 22 7.286 22 12c0 4.714 0 7.071-1.465 8.535C19.072 22 16.714 22 12 22s-7.071 0-8.536-1.465C2 19.072 2 16.714 2 12Z"></path><path class="checkmark" stroke-linecap="round" stroke-linejoin="round" d="m8.5 12.5l2 2l5-5"></path><path class="indeterminate" stroke-linecap="round" stroke-linejoin="round" d="M6 12h12"></path></g></svg>',1),j=e.defineComponent({inheritAttrs:!1,__name:"VueyeCheckbox",props:{checked:Boolean,id:String,label:String,indeterminate:Boolean,modelValue:[Boolean,Array]},emits:["change","update:modelValue"],setup(n,{emit:o}){const t=n,l=e.ref(t.modelValue),r=e.computed({get(){return t.modelValue},set(d){o("update:modelValue",d)}}),s=d=>{o("change",d)};return(d,u)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["table__checkbox",{"table__checkbox--checked":l.value,"table__checkbox--indeterminate":n.indeterminate}])},[e.withDirectives(e.createElementVNode("input",e.mergeProps({id:n.id,type:"checkbox",checked:l.value,"onUpdate:modelValue":u[0]||(u[0]=c=>e.isRef(r)?r.value=c:null),indeterminate:n.indeterminate,onChange:s,"aria-labelledby":"checkboxLabel"},d.$attrs),null,16,le),[[e.vModelCheckbox,e.unref(r)]]),e.createElementVNode("label",{for:n.id,id:"checkboxLabel"},e.toDisplayString(n.label),9,ae),re],2))}}),it="",se={class:"table__body"},ce={key:0,class:"table__row table__row--loading"},ie=["colspan"],de={key:1,class:"table__row table__row--empty"},pe=["colspan"],me=e.createElementVNode("div",{class:"text-center"},"No data available",-1),fe={class:"table__row"},ue={class:"table__cell table_cell--checkbox"},he={class:"table__cell"},ge=e.defineComponent({__name:"VueyeBody",props:e.mergeDefaults({loading:{type:Boolean},bodyRows:{},notListedKeys:{},itemValue:{},columnsLength:{},selected:{}},oe),emits:["update:selected"],setup(n,{emit:o}){const t=n,l=e.computed(()=>Object.keys(t.bodyRows[0]).filter(c=>!t.notListedKeys.includes(c))),r=e.computed(()=>l.value.reduce((c,a)=>({...c,[a]:a.split(".").pop()??""}),{})),s=e.computed(()=>t.bodyRows.map(c=>({flat:c,nest:E(c)}))),d=e.computed(()=>s.value.map(c=>c.nest)),u=e.computed({get(){return t.selected},set(c){o("update:selected",c)}});return(c,a)=>e.renderSlot(c.$slots,"body",{rows:c.bodyRows},()=>[e.createElementVNode("tbody",se,[c.loading?(e.openBlock(),e.createElementBlock("tr",ce,[e.createElementVNode("td",{colspan:c.columnsLength,class:"table__cell table__cell--loading"},[e.renderSlot(c.$slots,"loading",{},()=>[e.createTextVNode(" Loading... ")])],8,ie)])):c.bodyRows.length===0?(e.openBlock(),e.createElementBlock("tr",de,[e.createElementVNode("td",{class:"table__cell",colspan:c.columnsLength},[e.renderSlot(c.$slots,"empty",{},()=>[me])],8,pe)])):e.renderSlot(c.$slots,"rows",{key:2,rows:e.unref(d)},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(s),i=>e.renderSlot(c.$slots,"row",{key:i[c.itemValue],row:i.nest},()=>[e.createElementVNode("tr",fe,[c.selected?e.renderSlot(c.$slots,"checkbox",{key:0,row:i.nest},()=>[e.createElementVNode("td",ue,[e.createVNode(j,{modelValue:e.unref(u),"onUpdate:modelValue":a[0]||(a[0]=m=>e.isRef(u)?u.value=m:null),value:i.nest,"aria-label":"Select row"},null,8,["modelValue","value"])])]):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(l),m=>e.renderSlot(c.$slots,`itemCell.${m}`,{key:`${i[c.itemValue]}.${m}`,itemCell:i.nest},()=>[e.createElementVNode("td",he,[e.renderSlot(c.$slots,`itemCellContent.${e.unref(r)[m]}`,{itemCellContent:i.nest},()=>[e.createTextVNode(e.toDisplayString(i.flat[m]),1)])])])),128))])])),128))])])])}}),_e={columnHeaders:()=>[],selectable:!1,select:"none"},be={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 16 16"},ke=["opacity"],ye=["opacity"],we=e.defineComponent({__name:"ArrowUpDownIcon",props:{down:Boolean},setup(n){const o=n,t=e.computed(()=>({up:o.down?.5:1,down:o.down?1:.5}));return(l,r)=>(e.openBlock(),e.createElementBlock("svg",be,[e.createElementVNode("path",{opacity:e.unref(t).up,fill:"currentColor",fillRule:"evenodd",d:"M2.22 5.53a.75.75 0 0 1 0-1.06l2.25-2.25a.75.75 0 0 1 1.06 0l2.25 2.25a.75.75 0 0 1-1.06 1.06l-.97-.97v5.69a.75.75 0 0 1-1.5 0V4.56l-.97.97a.75.75 0 0 1-1.06 0",clipRule:"evenodd"},null,8,ke),e.createElementVNode("path",{opacity:e.unref(t).down,fill:"currentColor",fillRule:"evenodd",d:"M13.78 10.47a.75.75 0 0 1 0 1.06l-2.25 2.25a.75.75 0 0 1-1.06 0l-2.25-2.25a.75.75 0 1 1 1.06-1.06l.97.97V5.75a.75.75 0 0 1 1.5 0v5.69l.97-.97a.75.75 0 0 1 1.06 0",clipRule:"evenodd"},null,8,ye)]))}}),Ve={class:"table__head"},$e=["colspan","rowspan","scope"],Pe=["onClick"],Ce=e.defineComponent({__name:"VueyeHead",props:e.mergeDefaults({columnHeaders:{},selectable:{type:Boolean},select:{}},_e),emits:["update:select","sort"],setup(n,{emit:o}){const t=n,l=e.ref(""),r=e.ref(!1),s=a=>{a.sortable&&a.scope==="col"&&(l.value===a.fullKey?r.value=!r.value:(l.value=a.fullKey??"",r.value=!1),o("sort",{key:l.value,desc:r.value}))},d=e.computed(()=>t.selectable?[[{key:"checkbox",label:"",className:"checkbox",colSpan:1,rowSpan:t.columnHeaders.length,scope:"col"},...t.columnHeaders[0]],...t.columnHeaders.slice(1)]:t.columnHeaders),u=e.computed({get(){return t.select},set(a){o("update:select",a)}}),c=a=>{a.target.checked?u.value="all":u.value="none"};return(a,i)=>e.renderSlot(a.$slots,"headers",{headers:a.columnHeaders},()=>[e.createElementVNode("thead",Ve,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(d),(m,g)=>(e.openBlock(),e.createElementBlock("tr",{class:"table__row table__row",key:g},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(m,p=>e.renderSlot(a.$slots,`headerCell.${p.key}`,{key:p.key,headerItem:p},()=>[e.createElementVNode("th",{colspan:p.colSpan,rowspan:p.rowSpan,scope:p.scope,class:e.normalizeClass(["table__cell table__cell--head",p.className])},[p.key==="checkbox"&&a.selectable?e.renderSlot(a.$slots,"checkbox",{key:0},()=>[e.createVNode(j,{indeterminate:e.unref(u)==="indeterminate",type:"checkbox",checked:e.unref(u)==="all",onChange:c,"aria-label":"select all rows",class:"table__checkbox"},null,8,["indeterminate","checked"])]):e.renderSlot(a.$slots,`headerCellContent.${p.key}`,{key:1,headerItem:p},()=>[p.scope==="col"?(e.openBlock(),e.createElementBlock("button",{key:0,onClick:b=>s(p),class:"table__sort-button"},[e.createElementVNode("span",{class:e.normalizeClass(["table__label table__label--head",p.labelClassName])},e.toDisplayString(p.label),3),e.createVNode(we,{class:e.normalizeClass([{"table__sort-icon--show":e.unref(l)===p.key},"table__sort-icon"]),down:e.unref(r)},null,8,["class","down"])],8,Pe)):(e.openBlock(),e.createElementBlock("span",{key:1,class:e.normalizeClass(["table__label table__label--head",p.labelClassName])},e.toDisplayString(p.label),3))])],10,$e)])),128))]))),128))])])}}),dt="",Be={},Ee={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},Se=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"m9 5l6 7l-6 7"},null,-1)];function Ne(n,o){return e.openBlock(),e.createElementBlock("svg",Ee,Se)}const Re=V(Be,[["render",Ne]]),De={},Ke={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},Le=[e.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"m15 5l-6 7l6 7"},null,-1)];function Oe(n,o){return e.openBlock(),e.createElementBlock("svg",Ke,Le)}const He=V(De,[["render",Oe]]),Me={},je={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},ze=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5"},[e.createElementVNode("path",{d:"m11 19l6-7l-6-7"}),e.createElementVNode("path",{d:"m7 19l6-7l-6-7"})],-1)];function Te(n,o){return e.openBlock(),e.createElementBlock("svg",je,ze)}const Ue=V(Me,[["render",Te]]),Fe={},Ae={xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24"},Ie=[e.createElementVNode("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5"},[e.createElementVNode("path",{d:"m13 19l-6-7l6-7"}),e.createElementVNode("path",{d:"m17 19l-6-7l6-7"})],-1)];function Qe(n,o){return e.openBlock(),e.createElementBlock("svg",Ae,Ie)}const We=V(Fe,[["render",Qe]]),Ze={perPage:10,currentPage:1,total:0,perPageOptions:()=>[10,20,30,40,50]},Ge={class:"table__pagination-wrapper"},qe={class:"table__pagination-details"},Je={class:"table__pagination-btn-list"},Xe=["disabled"],Ye=["disabled"],xe=["onClick","aria-label"],ve={key:1,class:"table__pagination-btn table__btn"},et=["disabled"],tt=["disabled"],nt=e.defineComponent({__name:"VueyePagination",props:e.mergeDefaults({perPage:{},currentPage:{},total:{},perPageOptions:{}},Ze),emits:["update:currentPage","update:perPage"],setup(n,{emit:o}){const t=n,l=e.computed(()=>Math.ceil(t.total/t.perPage)),r=e.computed(()=>t.perPageOptions.map(a=>({content:a,label:a.toString()}))),s=e.computed(()=>r.value.find(a=>a.content===t.perPage)),d=e.computed(()=>Array.from({length:l.value},(a,i)=>i+1).reduce((a,i)=>(i===1||i===t.total||i>=t.currentPage-2&&i<=t.currentPage+2?a.push(i):(i===t.currentPage-3||i===t.currentPage+3)&&a.push("..."),a),[]));function u(a){o("update:perPage",Number(a))}function c(a){a>=1&&a<=l.value&&o("update:currentPage",a)}return(a,i)=>(e.openBlock(),e.createElementBlock("div",Ge,[e.createVNode(e.unref(ne),{options:e.unref(r),"default-value":e.unref(s),label:"Per page","onUpdate:modelValue":u},null,8,["options","default-value"]),e.createElementVNode("span",qe,e.toDisplayString((a.currentPage-1)*a.perPage+1)+" - "+e.toDisplayString(a.currentPage*a.perPage>a.total?a.total:a.currentPage*a.perPage)+" of "+e.toDisplayString(a.total),1),e.createElementVNode("ul",Je,[e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[0]||(i[0]=m=>c(1)),disabled:a.currentPage===1,"aria-label":"First page"},[e.createVNode(We)],8,Xe)]),e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[1]||(i[1]=m=>c(t.currentPage-1)),disabled:a.currentPage===1,"aria-label":"Previous page"},[e.createVNode(He)],8,Ye)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(d),m=>(e.openBlock(),e.createElementBlock("li",{key:m},[typeof m=="number"?(e.openBlock(),e.createElementBlock("button",{key:0,class:e.normalizeClass(["table__pagination-btn table__btn",{"table__pagination-btn--current ":m===a.currentPage}]),onClick:g=>c(m),"aria-label":"Go to page "+m},e.toDisplayString(m),11,xe)):(e.openBlock(),e.createElementBlock("span",ve,"..."))]))),128)),e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[2]||(i[2]=m=>c(a.currentPage+1)),disabled:a.currentPage===e.unref(l),"aria-label":"Next page"},[e.createVNode(Re)],8,et)]),e.createElementVNode("li",null,[e.createElementVNode("button",{class:"table__pagination-btn table__btn",onClick:i[3]||(i[3]=m=>c(a.total)),disabled:a.currentPage===e.unref(l),"aria-label":"Last page"},[e.createVNode(Ue)],8,tt)])])]))}});function ot(n){return{headerKeys:e.computed(()=>w(n.flat()))}}function z(n={},o){const t=e.ref({perPage:n.perPage||10,currentPage:n.currentPage||1});e.watchEffect(()=>{t.value.perPage=n.perPage||10,t.value.currentPage=n.currentPage||1}),e.watch(()=>t.value.perPage,(s,d)=>{s!==d&&l(1)});function l(s){t.value.currentPage=s,o("update:currentPage",s)}function r(s){t.value.perPage=s,o("update:perPage",s)}return{pagination:t,updateCurrentPage:l,updatePerPage:r}}function T(n,o,t){const l=e.ref(),r=e.ref(!1);function s({key:c,desc:a}){l.value=c,r.value=a}const d=e.computed(()=>{const c=B(e.toValue(n.data)[0]),a=w(c),i=w(e.toValue(o)),m=[],g=[...i];for(const p of a)i.includes(p)||(m.push(p),g.push(p));return{notListedKeys:m,allKeys:g}});return{bodyRows:e.computed(()=>{const c=e.toValue(t).perPage*(e.toValue(t).currentPage-1),a=e.toValue(t).perPage*e.toValue(t).currentPage,i=K(e.toValue(n.data),d.value.allKeys),m=e.computed(()=>n.filterBy===void 0||n.filterBy.length===0?Object.keys(i[0]):n.filterBy),g=i.filter(p=>{var b;return(b=n.filterMethod)==null?void 0:b.call(n,n.filterQuery,p,e.toValue(m))});return l.value&&g.sort((p,b)=>{if(!l.value)return 0;const k=p[l.value],y=b[l.value];return k<y?r.value?1:-1:k>y?r.value?-1:1:0}),L(g,c,a)}),notListedKeys:e.computed(()=>d.value.notListedKeys),rowsCount:e.computed(()=>e.toValue(n.data).length),onSort:s}}function U(n){const o=e.unref(n)??[];return{headers:e.computed(()=>C(o,$(o))),headersCount:P(o)}}function F(n,o,t){const l=e.computed({get(){var s,d,u;return n.selected===null||((s=n.selected)==null?void 0:s.length)===0?"none":((d=n.selected)==null?void 0:d.length)===n.data.length||n.selectMode==="page"&&((u=n.selected)==null?void 0:u.length)===o.value.length?"all":"indeterminate"},set(s){s==="all"?n.selectMode==="page"?r.value=o.value.map(d=>E(d)):r.value=n.data:s==="none"&&(r.value=[])}}),r=e.computed({get(){return n.selected},set(s){t("update:selected",s)}});return{selectAll:l,selected:r}}const lt={class:"table__wrapper"},at={key:0,class:"table__caption"},rt={class:"table__summary"},st=e.defineComponent({inheritAttrs:!1,__name:"VueyeTable",props:e.mergeDefaults({data:{},columnHeaders:{},itemValue:{},perPage:{},currentPage:{},perPageOptions:{},loading:{type:Boolean},selected:{},selectMode:{},caption:{},summary:{},filterQuery:{},filterBy:{},filterMethod:{type:Function}},M()),emits:["update:currentPage","update:perPage","update:loading","update:selected"],setup(n,{emit:o}){const t=n,l=e.computed(()=>t.columnHeaders.length===0?B(t.data[0]):t.columnHeaders),{headers:r,headersCount:s}=U(l),d=e.useSlots(),u=Object.keys(d).filter(h=>h.startsWith("headerCell")),c=Object.keys(d).filter(h=>h.startsWith("itemCell")),{pagination:a,updateCurrentPage:i,updatePerPage:m}=z(t,o),{bodyRows:g,rowsCount:p,notListedKeys:b,onSort:k}=T(t,l,a),{selected:y,selectAll:N}=F(t,g,o);return(h,S)=>(e.openBlock(),e.createElementBlock("div",lt,[e.createElementVNode("table",{class:e.normalizeClass(h.$attrs.class??"table")},[e.renderSlot(h.$slots,"caption",{},()=>[h.caption?(e.openBlock(),e.createElementBlock("caption",at,e.toDisplayString(h.caption),1)):e.createCommentVNode("",!0)]),e.createVNode(e.unref(Ce),{columnHeaders:e.unref(r),selectable:h.selected!==null,select:e.unref(N),"onUpdate:select":S[0]||(S[0]=_=>e.isRef(N)?N.value=_:null),onSort:e.unref(k)},e.createSlots({headers:e.withCtx(_=>[e.renderSlot(h.$slots,"headers",e.normalizeProps(e.guardReactiveProps(_)))]),_:2},[e.renderList(e.unref(u),_=>({name:_,fn:e.withCtx(R=>[e.renderSlot(h.$slots,_,e.normalizeProps(e.guardReactiveProps(R)))])}))]),1032,["columnHeaders","selectable","select","onSort"]),e.createVNode(e.unref(ge),{selected:e.unref(y),"onUpdate:selected":S[1]||(S[1]=_=>e.isRef(y)?y.value=_:null),bodyRows:e.unref(g),loading:h.loading,itemValue:h.itemValue,"columns-length":e.unref(s),"not-listed-keys":e.unref(b)},e.createSlots({checkbox:e.withCtx(_=>[e.renderSlot(h.$slots,"checkbox",e.normalizeProps(e.guardReactiveProps(_)))]),loading:e.withCtx(()=>[e.renderSlot(h.$slots,"loading")]),empty:e.withCtx(()=>[e.renderSlot(h.$slots,"empty")]),rows:e.withCtx(_=>[e.renderSlot(h.$slots,"rows",e.normalizeProps(e.guardReactiveProps(_)))]),row:e.withCtx(_=>[e.renderSlot(h.$slots,"row",e.normalizeProps(e.guardReactiveProps(_)))]),_:2},[e.renderList(e.unref(c),_=>({name:_,fn:e.withCtx(R=>[e.renderSlot(h.$slots,_,e.normalizeProps(e.guardReactiveProps(R)))])}))]),1032,["selected","bodyRows","loading","itemValue","columns-length","not-listed-keys"]),e.renderSlot(h.$slots,"summary",{},()=>[e.createElementVNode("caption",rt,e.toDisplayString(h.summary),1)])],2),e.renderSlot(h.$slots,"pagination",{pagination:{...e.unref(a),perPageOptions:h.perPageOptions,total:e.unref(p)}},()=>[e.withDirectives(e.createVNode(e.unref(nt),{perPage:e.unref(a).perPage,currentPage:e.unref(a).currentPage,perPageOptions:h.perPageOptions,total:e.unref(p),"onUpdate:currentPage":e.unref(i),"onUpdate:perPage":e.unref(m),class:"table__pagination"},null,8,["perPage","currentPage","perPageOptions","total","onUpdate:currentPage","onUpdate:perPage"]),[[e.vShow,h.data.length>0]])])]))}}),ht="";function A(n){const o=[];for(const t of n){const l=t.children?A(t.children):void 0;o.push({...t,children:l})}return o}f.VueyeTable=st,f.deepValues=O,f.defineColumnHeaders=I,f.defineFilterMethod=W,f.defineTableColumnHeaders=A,f.depthCount=$,f.flatHeadersToRows=C,f.generateColumns=B,f.getBodyRows=K,f.getHeaderKeys=w,f.getVueyeTablePropDefaults=M,f.humanize=D,f.isPrimitive=H,f.leafCount=P,f.nestedObjectTransformer=E,f.paginateRows=L,f.useBodyRows=T,f.useHeaderKeys=ot,f.useHeaders=U,f.usePagination=z,f.useSelection=F,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vueye-table",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Vue data table",
|
|
6
6
|
"author": "Brahim Boussadjra",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"types": "./dist/index.d.ts"
|
|
30
30
|
},
|
|
31
31
|
"./*": "./dist/vueye-table.js",
|
|
32
|
-
"./dist/
|
|
32
|
+
"./dist/default.css": "./dist/default.css"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@antfu/eslint-config": "^0.43.1",
|