vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
2 lines (1 loc) • 12.4 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),u=require("./index-_gyicZFE.cjs"),ue=require("./useNestedProp-BJQoarHp.cjs"),Q=require("./usePrinter-BRTNfg7r.cjs"),se=require("./vue-ui-skeleton-KlT3Rmkn.cjs"),de=require("./useUserOptionState-BgepsfED.cjs"),ve=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),ce=["id"],pe=["height"],fe=["data-cell","height"],me={key:2,ref:"source",dir:"auto"},he={__name:"vue-ui-carousel-table",props:{config:{type:Object,default(){return{}}},dataset:{type:Object,default(){return{}}}},setup(b,{expose:W}){const{vue_ui_carousel_table:Y}=u.useConfig(),r=b,x=e.ref(u.createUid()),z=e.ref(!1),k=e.ref(!!r.dataset),Z=e.useSlots();e.onMounted(()=>{F()}),e.onMounted(()=>{Z["chart-background"]&&console.warn("VueUiCarouselTable does not support the #chart-background slot.")});function F(){u.objectIsEmpty(r.dataset)?u.error({componentName:"VueUiCarouselTable",type:"dataset"}):((!r.dataset.head||u.objectIsEmpty(r.dataset.head))&&(u.error({componentName:"VueUiCarouselTable",type:"datasetAttribute",property:"head"}),k.value=!1),(!r.dataset.body||u.objectIsEmpty(r.dataset.body))&&(u.error({componentName:"VueUiCarouselTable",type:"datasetAttribute",property:"body"}),k.value=!1))}const t=e.computed({get:()=>V(),set:o=>o}),{userOptionsVisible:A,setUserOptionsVisibility:P,keepUserOptionState:N}=de.useUserOptionState({config:t.value});function V(){return ue.useNestedProp({userConfig:r.config,defaultConfig:Y})}e.watch(()=>r.config,o=>{t.value=V(),A.value=!t.value.userOptions.showOnChartHover,F()},{deep:!0}),e.watch(()=>r.dataset,o=>{O()},{deep:!0});const{isPrinting:R,isImaging:M,generatePdf:_,generateImage:q}=Q.usePrinter({elementId:`carousel-table_${x.value}`,fileName:t.value.caption.text||"vue-ui-carousel-table"}),v=e.ref({showAnimation:t.value.animation.use}),l=e.ref(null),U=e.ref(null),C=e.ref(null),T=e.ref(null),$=e.ref(0),B=e.ref(0),S=e.ref(!1),w=e.ref(null),f=e.ref(null),y=e.ref(0);function O(){w.value&&(f.value={elements:w.value.getElementsByTagName("tr"),heights:Array.from(w.value.getElementsByTagName("tr")).map(o=>o.getBoundingClientRect().height)})}e.onMounted(O);const ee=e.computed(()=>!f.value||!f.value.heights.length?0:Math.max(...f.value.heights)+$.value+B.value),te=e.computed(()=>r.dataset.body?t.value.tbody.tr.visible<=r.dataset.body.length?t.value.tbody.tr.visible:r.dataset.body.length:0),oe=e.computed(()=>(t.value.tbody.tr.height+t.value.tbody.tr.td.padding.top+t.value.tbody.tr.td.padding.bottom+t.value.tbody.tr.border.size*2)*te.value+$.value+B.value),d=e.ref(0),m=e.ref(null),s=e.ref(0),h=e.ref(!1),H=e.ref(0);e.onMounted(()=>{C.value&&($.value=C.value.getBoundingClientRect().height),T.value&&(B.value=T.value.getBoundingClientRect().height),v.value.showAnimation&&f.value&&L()}),e.onMounted(()=>{if(l.value){let a=function(){const i=o.getBoundingClientRect().bottom;n.forEach(p=>{p.getBoundingClientRect().top<i?p.style.visibility="hidden":p.style.visibility="visible"})};const o=l.value.querySelector("thead"),n=Array.from(w.value.querySelectorAll("tr"));l.value.addEventListener("scroll",a),a(),e.onBeforeUnmount(()=>{l.value.removeEventListener("scroll",a)})}});function ae(o){z.value=o,H.value+=1}function L(){!m.value&&!h.value&&(t.value.animation.type==="scroll"?m.value=requestAnimationFrame(D):m.value=requestAnimationFrame(G))}function ne(){if(!l.value)return!1;const{scrollTop:o,scrollHeight:n,clientHeight:a}=l.value;return o+a>=n}function D(o){if(h.value)return;s.value||(s.value=o),o-s.value>=t.value.animation.speedMs&&(d.value+=f.value.heights[y.value],(ne()||y.value>=f.value.heights.length)&&(d.value=0,y.value=-1),y.value+=1,l.value&&l.value.scrollTo({top:d.value,behavior:"smooth"}),s.value=o),m.value=requestAnimationFrame(D)}function G(o){if(h.value)return;s.value||(s.value=o);const n=o-s.value,a=t.value.animation.speedMs/4/1e3;n>=a&&(d.value+=a,d.value>=l.value.scrollHeight-l.value.clientHeight&&(d.value=0),l.value&&l.value.scrollTo({top:d.value,behavior:"auto"}),s.value=o),m.value=requestAnimationFrame(G)}function c(){h.value=!0,cancelAnimationFrame(m.value),m.value=null}e.onBeforeUnmount(c);function g(){!h.value||!v.value.showAnimation||(h.value=!1,s.value=0,L())}function le(){t.value.animation.pauseOnHover&&c()}const I=e.ref(null);function re(){c(),clearTimeout(I.value)}function j(){clearTimeout(I.value),I.value=setTimeout(g,1e3)}e.watch(()=>t.value.animation.use,o=>{o?(v.value.showAnimation=!0,g()):(v.value.showAnimation=!1,c())}),e.watch(()=>t.value.animation.type,o=>{c(),d.value=0,y.value=0,l.value.scrollTo({top:0,behavior:"auto"}),g()});const ie=e.computed(()=>t.value.responsiveBreakpoint);e.onMounted(()=>{const o=new ResizeObserver(n=>{n.forEach(a=>{S.value=a.contentRect.width<ie.value}),$.value=C.value?C.value.getBoundingClientRect().height:0,B.value=T.value?T.value.getBoundingClientRect().height:0,y.value=0,e.nextTick(()=>{c(),s.value=0,d.value=0,O(),g()})});l.value&&o.observe(l.value)});function X(){_()}function J(){v.value.showAnimation=!v.value.showAnimation,v.value.showAnimation?g():c()}function K(){e.nextTick(()=>{const o=r.dataset.head.map((i,p)=>[[r.dataset.body[p]]]),n=[[t.value.caption.text],[r.dataset.head.map(i=>[i])]].concat(o),a=u.createCsvContent(n);u.downloadCsv({csvContent:a,title:t.value.caption.text||"vue-ui-carousel-table"})})}return W({pauseAnimation:c,resumeAnimation:g,toggleAnimation:J,generateCsv:K,generatePdf:X,generateImage:q}),(o,n)=>(e.openBlock(),e.createElementBlock("div",{class:"vue-ui-carousel-table",style:{position:"relative",overflow:"visible"},ref_key:"chartContainer",ref:U,onMouseenter:n[5]||(n[5]=()=>e.unref(P)(!0)),onMouseleave:n[6]||(n[6]=()=>e.unref(P)(!1))},[e.createElementVNode("div",{ref_key:"tableContainer",ref:l,id:`carousel-table_${x.value}`,style:e.normalizeStyle({height:e.unref(R)||e.unref(M)?"auto":`${Math.max(oe.value,ee.value)}px`,containerType:"inline-size",position:"relative",overflow:"auto",fontFamily:t.value.fontFamily}),class:e.normalizeClass({"vue-ui-responsive":S.value,"is-playing":t.value.scrollbar.hide||!h.value&&t.value.scrollbar.showOnlyOnHover}),onMouseover:n[0]||(n[0]=a=>le()),onMouseleave:n[1]||(n[1]=a=>g()),onTouchstart:n[2]||(n[2]=a=>re()),onTouchend:n[3]||(n[3]=a=>j()),onTouchcancel:n[4]||(n[4]=a=>j())},[k.value?(e.openBlock(),e.createElementBlock("table",{key:0,class:"vue-data-ui-carousel-table",style:e.normalizeStyle({...t.value.style,border:`${t.value.border.size}px solid ${t.value.border.color}`,width:"100%",borderCollapse:"collapse",backgroundColor:t.value.tbody.backgroundColor})},[e.createElementVNode("caption",{ref_key:"caption",ref:C,class:"vue-data-ui-carousel-table-caption",style:e.normalizeStyle({...t.value.caption.style,fontFamily:"inherit",position:"sticky",top:0,zIndex:2,paddingTop:t.value.caption.padding.top+"px",paddingRight:t.value.caption.padding.right+"px",paddingBottom:t.value.caption.padding.bottom+"px",paddingLeft:t.value.caption.padding.left+"px",boxShadow:S.value?t.value.thead.tr.style.boxShadow:"none",minHeight:"36px",display:o.$slots.caption||t.value.caption.text||t.value.userOptions.show?"":"none"})},[e.createTextVNode(e.toDisplayString(t.value.caption.text&&!o.$slots.caption?t.value.caption.text:"")+" ",1),e.renderSlot(o.$slots,"caption",{},void 0,!0)],4),e.createElementVNode("thead",{style:e.normalizeStyle({...t.value.thead.style,position:"sticky",top:`${o.$slots.caption||t.value.caption.text||t.value.userOptions.show?$.value:0}px`,zIndex:1})},[e.createElementVNode("tr",{ref_key:"tableRow",ref:T,role:"row",style:e.normalizeStyle({...t.value.thead.tr.style,border:t.value.thead.tr.border.size?`${t.value.thead.tr.border.size}px solid ${t.value.thead.tr.border.color}`:"none",boxShadow:S.value?"none":t.value.thead.tr.style.boxShadow}),height:`${t.value.thead.tr.height}px`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.dataset.head,(a,i)=>(e.openBlock(),e.createElementBlock("th",{role:"cell",key:`th_${i}`,style:e.normalizeStyle({...t.value.thead.tr.th.style,border:t.value.thead.tr.th.border.size?`${t.value.thead.tr.th.border.size}px solid ${t.value.thead.tr.th.border.color}`:"none",paddingTop:t.value.thead.tr.th.padding.top+"px",paddingRight:t.value.thead.tr.th.padding.right+"px",paddingBottom:t.value.thead.tr.th.padding.bottom+"px",paddingLeft:t.value.thead.tr.th.padding.left+"px"})},[e.createTextVNode(e.toDisplayString(o.$slots.th?"":a)+" ",1),e.renderSlot(o.$slots,"th",e.mergeProps({ref_for:!0},{th:a,colIndex:i}),void 0,!0)],4))),128))],12,pe)],4),b.dataset.body&&b.dataset.head?(e.openBlock(),e.createElementBlock("tbody",{key:0,ref_key:"tbody",ref:w,style:{clipPath:"inset(0,0,0,0)"}},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.dataset.body,(a,i)=>(e.openBlock(),e.createElementBlock("tr",{style:e.normalizeStyle({...t.value.tbody.tr.style,border:`${t.value.tbody.tr.border.size}px solid ${t.value.tbody.tr.border.color}`,verticalAlign:"middle"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a,(p,E)=>(e.openBlock(),e.createElementBlock("td",{role:"cell","data-cell":b.dataset.head[E]||"",style:e.normalizeStyle({...t.value.tbody.tr.td.style,border:`${t.value.tbody.tr.td.border.size}px solid ${t.value.tbody.tr.td.border.color}`,backgroundColor:e.unref(u.setOpacity)(t.value.tbody.tr.td.style.backgroundColor,i%2===0&&t.value.tbody.tr.td.alternateColor?t.value.tbody.tr.td.alternateOpacity*100:100),paddingTop:t.value.tbody.tr.td.padding.top+"px",paddingRight:t.value.tbody.tr.td.padding.right+"px",paddingBottom:t.value.tbody.tr.td.padding.bottom+"px",paddingLeft:t.value.tbody.tr.td.padding.left+"px",verticalAlign:"middle"}),height:`${t.value.tbody.tr.height}px`},[e.createTextVNode(e.toDisplayString(o.$slots.td?"":p)+" ",1),e.renderSlot(o.$slots,"td",e.mergeProps({ref_for:!0},{td:p,rowIndex:i,colIndex:E}),void 0,!0)],12,fe))),256))],4))),256))],512)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0)],46,ce),k.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(se.default,{key:0,config:{type:"table"}})),t.value.userOptions.show&&k.value&&(e.unref(N)||e.unref(A))?(e.openBlock(),e.createBlock(Q.UserOptions,{ref:"details",key:`user_option_${H.value}`,backgroundColor:t.value.style.backgroundColor,color:t.value.style.color,isPrinting:e.unref(R),isImaging:e.unref(M),uid:x.value,hasTooltip:!1,hasPdf:t.value.userOptions.buttons.pdf,hasImg:t.value.userOptions.buttons.img,hasXls:t.value.userOptions.buttons.csv,hasTable:!1,hasLabel:!1,hasAnimation:t.value.userOptions.buttons.animation,isAnimation:!v.value.showAnimation,hasFullscreen:t.value.userOptions.buttons.fullscreen,isFullscreen:z.value,chartElement:U.value,position:t.value.userOptions.position,titles:{...t.value.userOptions.buttonTitles},zIndex:3,offsetX:12,onGeneratePdf:X,onGenerateCsv:K,onGenerateImage:e.unref(q),onToggleAnimation:J,onToggleFullscreen:ae,style:e.normalizeStyle({visibility:e.unref(N)?e.unref(A)?"visible":"hidden":"visible"})},e.createSlots({_:2},[o.$slots.menuIcon?{name:"menuIcon",fn:e.withCtx(({isOpen:a,color:i})=>[e.renderSlot(o.$slots,"menuIcon",e.normalizeProps(e.guardReactiveProps({isOpen:a,color:i})),void 0,!0)]),key:"0"}:void 0,o.$slots.optionPdf?{name:"optionPdf",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionPdf",{},void 0,!0)]),key:"1"}:void 0,o.$slots.optionCsv?{name:"optionCsv",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionCsv",{},void 0,!0)]),key:"2"}:void 0,o.$slots.optionImg?{name:"optionImg",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionImg",{},void 0,!0)]),key:"3"}:void 0,o.$slots.optionAnimation?{name:"optionAnimation",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionAnimation",{},void 0,!0)]),key:"4"}:void 0,o.$slots.optionFullscreen?{name:"optionFullscreen",fn:e.withCtx(({toggleFullscreen:a,isFullscreen:i})=>[e.renderSlot(o.$slots,"optionFullscreen",e.normalizeProps(e.guardReactiveProps({toggleFullscreen:a,isFullscreen:i})),void 0,!0)]),key:"5"}:void 0]),1032,["backgroundColor","color","isPrinting","isImaging","uid","hasPdf","hasImg","hasXls","hasAnimation","isAnimation","hasFullscreen","isFullscreen","chartElement","position","titles","onGenerateImage","style"])):e.createCommentVNode("",!0),o.$slots.source?(e.openBlock(),e.createElementBlock("div",me,[e.renderSlot(o.$slots,"source",{},void 0,!0)],512)):e.createCommentVNode("",!0)],544))}},ge=ve._export_sfc(he,[["__scopeId","data-v-3823c499"]]);exports.default=ge;
;