@vuu-ui/vuu-table 0.6.21 → 0.6.22-debug
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/cjs/index.js +2760 -1
- package/cjs/index.js.map +2 -2
- package/esm/index.js +2792 -1
- package/esm/index.js.map +2 -2
- package/index.css +513 -1
- package/index.css.map +1 -1
- package/package.json +5 -5
package/esm/index.js
CHANGED
|
@@ -1,2 +1,2793 @@
|
|
|
1
|
-
import{ContextMenuProvider as ns}from"@vuu-ui/vuu-popups";import{Button as os,useIdMemo as rs}from"@salt-ds/core";import{metadataKeys as Zn}from"@vuu-ui/vuu-utils";import{useCallback as qn}from"react";import eo from"classnames";import{isGroupColumn as Ze,isJsonColumn as An,isJsonGroup as Ln,metadataKeys as Kn,notHidden as kn}from"@vuu-ui/vuu-utils";import zn from"classnames";import{memo as Nn,useCallback as qe}from"react";import{getColumnPinStyle as hn,metadataKeys as yn}from"@vuu-ui/vuu-utils";import{EditableLabel as vn}from"@heswell/salt-lab";import wn from"classnames";import{memo as Mn,useCallback as Tn,useRef as Dn,useState as Xe}from"react";import{jsx as ie}from"react/jsx-runtime";var{KEY:Ye}=yn,ye=Mn(({className:e,column:t,onClick:n,row:o})=>{let r=Dn(null),{align:l,CellRenderer:s,key:i,pin:a,editable:m,resizing:c,valueFormatter:d}=t,[C,y]=Xe(!1),w=d(o[i]),[u,f]=Xe(w),g=()=>{var A;(A=r.current)==null||A.focus()},p=A=>{A.key==="Enter"&&y(!0)},v=Tn(()=>{n==null||n(t)},[t,n]),H=()=>{y(!0)},P=(A="",k="",b=!0,M=!1)=>{var D;y(!1),M?f(A):k!==A&&f(k),b===!1&&((D=r.current)==null||D.focus())},h=wn(e,{vuuAlignRight:l==="right",vuuPinFloating:a==="floating",vuuPinLeft:a==="left",vuuPinRight:a==="right","vuuTableCell-resizing":c})||void 0,x=hn(t);return m?ie("td",{className:h,"data-editable":!0,style:x,onKeyDown:p,children:ie(vn,{editing:C,value:u,onChange:f,onMouseDownCapture:g,onEnterEditMode:H,onExitEditMode:P,onKeyDown:p,ref:r,tabIndex:0},"title")}):ie("td",{className:h,style:x,onClick:v,children:s?ie(s,{column:t,row:o}):w})},xn);ye.displayName="TableCell";function xn(e,t){return e.column===t.column&&e.onClick===t.onClick&&e.row[Ye]===t.row[Ye]&&e.row[e.column.key]===t.row[t.column.key]}import{metadataKeys as Rn}from"@vuu-ui/vuu-utils";import{useCallback as Hn}from"react";import{jsx as ve,jsxs as En}from"react/jsx-runtime";var{DEPTH:Pn,IS_LEAF:Qe}=Rn,Sn=(e,t)=>{let{[Pn]:n,[Qe]:o}=t;if(o||n>e.length)return[null,n===null?0:n-1];if(n===0)return["$root",0];{let r=e[n-1];return[t[r.key],n-1]}},je=({column:e,onClick:t,row:n})=>{let{columns:o}=e,[r,l]=Sn(o,n),s=Hn(()=>{t==null||t(e)},[e,t]),i={left:e.pin=="left"?e.pinnedOffset:void 0},a=n[Qe],m=Array(l).fill(0).map((c,d)=>ve("span",{className:"vuuTableGroupCell-spacer"},d));return En("td",{className:"vuuTableGroupCell vuuPinLeft",onClick:a?void 0:s,style:i,children:[m,a?null:ve("span",{className:"vuuTableGroupCell-toggle","data-icon":"triangle-right"}),ve("span",{children:r})]})};import{jsx as et,jsxs as $n}from"react/jsx-runtime";var{IDX:In,IS_EXPANDED:Vn,SELECTED:Fn}=Kn,ae="vuuTableRow",ce=Nn(function({columns:t,height:n,index:o,onClick:r,onToggleGroup:l,virtualColSpan:s=0,row:i}){let{[In]:a,[Vn]:m,[Fn]:c}=i,d=zn(ae,{[`${ae}-even`]:a%2===0,[`${ae}-expanded`]:m,[`${ae}-preSelected`]:c===2}),C=a-o,y=qe(u=>{let f=u.shiftKey,g=u.ctrlKey||u.metaKey;r==null||r(i,f,g)},[r,i]),w=qe(u=>{(Ze(u)||Ln(u,i))&&(l==null||l(i,u))},[l,i]);return $n("tr",{"aria-selected":c===1?!0:void 0,"aria-rowindex":a,className:d,onClick:y,style:{transform:`translate(0px, ${C*n}px)`},children:[s>0?et("td",{colSpan:s}):null,t.filter(kn).map(u=>{let f=Ze(u),g=An(u);return et(f?je:ye,{column:u,onClick:f||g?w:void 0,row:i},u.name)})]})});import Yn from"classnames";import{useCallback as Te,useRef as it}from"react";import{useCallback as we,useRef as Wn}from"react";import{jsx as On}from"react/jsx-runtime";var tt=()=>{},Gn="vuuColumnResizer",ue=({onDrag:e,onDragEnd:t=tt,onDragStart:n=tt})=>{let o=Wn(0),r=we(i=>{i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault();let a=Math.round(i.clientX),m=a-o.current;o.current=a,m!==0&&e(i,m)},[e]),l=we(i=>{window.removeEventListener("mouseup",l),window.removeEventListener("mousemove",r),t(i)},[t,r]),s=we(i=>{n(i),o.current=Math.round(i.clientX),window.addEventListener("mouseup",l),window.addEventListener("mousemove",r),i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault()},[n,r,l]);return On("div",{className:Gn,onMouseDown:s})};import nt from"classnames";import{jsx as me,jsxs as Bn}from"react/jsx-runtime";var ot="vuuSortIndicator",rt=({sorted:e})=>{if(!e)return null;let t=typeof e=="number"?e<0?"dsc":"asc":e==="A"?"asc":"dsc";return typeof e=="number"?Bn("div",{className:nt(ot,"multi-col",t),children:[me("span",{"data-icon":`sorted-${t}`}),me("span",{className:"vuuSortPosition",children:Math.abs(e)})]}):me("div",{className:nt(ot,"single-col"),children:me("span",{"data-icon":`sorted-${t}`})})};import{useCallback as Me,useRef as st}from"react";var de=({column:e,onResize:t,rootRef:n})=>{let o=st(0),r=st(!1),{name:l}=e,s=Me(()=>{if(t&&n.current){let{width:m}=n.current.getBoundingClientRect();o.current=Math.round(m),r.current=!0,t==null||t("begin",l)}},[l,t,n]),i=Me((m,c)=>{if(n.current&&t){let{width:d}=n.current.getBoundingClientRect(),C=Math.round(d)+c;C!==o.current&&C>0&&(t("resize",l,C),o.current=C)}},[l,t,n]),a=Me(()=>{t&&(t("end",l,o.current),setTimeout(()=>{r.current=!1},100))},[l,t]);return{isResizing:r.current,onDrag:i,onDragStart:s,onDragEnd:a}};import{useContextMenu as Qn}from"@vuu-ui/vuu-popups";import{useContextMenu as Un}from"@vuu-ui/vuu-popups";import _n from"classnames";import{useCallback as Jn}from"react";import{jsx as Xn}from"react/jsx-runtime";var lt=({column:e,filter:t})=>{let n=Un(),o=Jn(r=>{r.stopPropagation(),n(r,"filter",{column:e,filter:t})},[e,t,n]);return e.filter?Xn("div",{className:_n("vuuFilterIndicator"),"data-icon":"filter",onClick:o}):null};import{jsx as j,jsxs as jn}from"react/jsx-runtime";var Q="vuuTable-headerCell",pe=({column:e,className:t,onClick:n,onDragStart:o,onResize:r,...l})=>{let s=it(null),{isResizing:i,...a}=de({column:e,onResize:r,rootRef:s}),m=Qn(),c=it(null),d=f=>{m(f,"header",{column:e})},C=Te(f=>!i&&(n==null?void 0:n(f)),[i,n]),y=Te(f=>{c.current=window.setTimeout(()=>{o==null||o(f),c.current=null},250)},[o]),w=Te(()=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),u=Yn(Q,t,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:e.endPin,[`${Q}-resizing`]:e.resizing,[`${Q}-right`]:e.align==="right"});return j("th",{className:u,...l,onClick:C,onContextMenu:d,onMouseDown:y,onMouseUp:w,ref:s,children:jn("div",{className:`${Q}-inner`,children:[j(lt,{column:e}),j("div",{className:`${Q}-label`,children:e.label}),j(rt,{sorted:e.sorted}),e.resizeable!==!1?j(ue,{...a}):null]})})};import{Fragment as oo,jsx as J,jsxs as no}from"react/jsx-runtime";var at="vuuTable",{RENDER_IDX:to}=Zn,ct=({columns:e,data:t,headerHeight:n,onHeaderCellDragEnd:o,rowHeight:r})=>{let l=qn(()=>{o==null||o()},[o]);return console.log("ColumnBasedTable render"),J(oo,{children:e.map((s,i)=>J("table",{className:eo(`${at}-table`,`${at}-columnBased`,{vuuPinLeft:s.pin==="left"}),"data-idx":i,id:`col-${i}`,style:{width:s.width,left:s.pinnedOffset,"--vuuTableHeaderHeight":`${n}px`,"--row-height":`${r}px`},children:no("tbody",{children:[J("tr",{children:J(pe,{column:s,"data-idx":i,onDragEnd:l},i)},"header"),t.map((a,m)=>J(ce,{columns:[s],height:r,index:m,row:a},a[to])),J("tr",{className:"vuuTable-filler"})]})},s.name))})};import{isNumericColumn as ro}from"@vuu-ui/vuu-utils";var ut=e=>(t,n)=>{let o=[];if(e===void 0)return o;if(t==="header")o.push(...so(n,e)),o.push(...ao(n,e)),o.push(...lo(n,e)),o.push(...io(n));else if(t==="filter"){let{column:r,filter:l}=n,s=(l==null?void 0:l.column)===(r==null?void 0:r.name);o.push({label:"Edit filter",action:"filter-edit",options:n}),o.push({label:"Remove filter",action:"filter-remove-column",options:n}),r&&!s&&o.push({label:"Remove all filters",action:"remove-filters",options:n})}return o};function so(e,{sort:{sortDefs:t}}){let{column:n}=e,o=[];if(n===void 0)return o;let r=t.length>0;return n.sorted==="A"?o.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):n.sorted==="D"?o.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof n.sorted=="number"?(n.sorted>0?o.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):o.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),r&&Math.abs(n.sorted)<t.length&&o.push({label:"Remove from sort",action:"sort-remove",options:e}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r?(o.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):o.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),o}function lo(e,t){let{column:n}=e;if(n===void 0||t.groupBy.length===0)return[];let{name:o,label:r=o}=n;return[{label:`Aggregate ${r}`,children:[{label:"Count",action:"agg-count",options:e}].concat(ro(n)?[{label:"Sum",action:"agg-sum",options:e},{label:"Avg",action:"agg-avg",options:e},{label:"High",action:"agg-high",options:e},{label:"Low",action:"agg-low",options:e}]:[])}]}var He=(e,t)=>({label:`Pin ${t}`,action:`column-pin-${t}`,options:e}),De=e=>He(e,"left"),xe=e=>He(e,"floating"),Re=e=>He(e,"right");function io(e){let{column:t}=e;if(t===void 0)return[];let{pin:n}=t,o=[{label:"Hide column",action:"column-hide",options:e},{label:"Remove column",action:"column-remove",options:e}];return n===void 0?o.push({label:"Pin column",children:[De(e),xe(e),Re(e)]}):n==="left"?o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[xe(e),Re(e)]}):n==="right"?o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[De(e),xe(e)]}):n==="floating"&&o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[De(e),Re(e)]}),o}function ao(e,{groupBy:t}){let{column:n}=e,o=[];if(n===void 0)return o;let{name:r,label:l=r}=n;return t.length===0?o.push({label:`Group by ${l}`,action:"group",options:e}):o.push({label:`Add ${l} to group by`,action:"group-add",options:e}),o}import{removeColumnFromFilter as co}from"@vuu-ui/vuu-filters";import{addGroupColumn as mt,addSortColumn as dt,AggregationType as uo,setAggregations as Z,setSortColumn as pt}from"@vuu-ui/vuu-utils";var mo=(e,t)=>{if(e.filterStruct&&t){let[n,o]=co(t,e.filterStruct);return{filter:o,filterStruct:n}}else return e},{Average:po,Count:fo,High:go,Low:Co,Sum:bo}=uo,ft=({dataSource:e,onPersistentColumnOperation:t})=>(o,r)=>{let l=r;if(l.column&&e){let{column:s}=l;switch(o){case"sort-asc":return e.sort=pt(e.sort,s,"A"),!0;case"sort-dsc":return e.sort=pt(e.sort,s,"D"),!0;case"sort-add-asc":return e.sort=dt(e.sort,s,"A"),!0;case"sort-add-dsc":return e.sort=dt(e.sort,s,"D"),!0;case"group":return e.groupBy=mt(e.groupBy,s),!0;case"group-add":return e.groupBy=mt(e.groupBy,s),!0;case"column-hide":return t({type:"hideColumns",columns:[s]}),!0;case"column-remove":return e.columns=e.columns.filter(i=>i!==s.name),!0;case"filter-remove-column":return e.filter=mo(e.filter,s),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=Z(e.aggregations,s,po),!0;case"agg-high":return e.aggregations=Z(e.aggregations,s,go),!0;case"agg-low":return e.aggregations=Z(e.aggregations,s,Co),!0;case"agg-count":return e.aggregations=Z(e.aggregations,s,fo),!0;case"agg-sum":return e.aggregations=Z(e.aggregations,s,bo),!0;case"column-pin-floating":return t({type:"pinColumn",column:s,pin:"floating"}),!0;case"column-pin-left":return t({type:"pinColumn",column:s,pin:"left"}),!0;case"column-pin-right":return t({type:"pinColumn",column:s,pin:"right"}),!0;case"column-unpin":return t({type:"pinColumn",column:s,pin:void 0}),!0;default:}}return!1};import{getColumnPinStyle as vo,isGroupColumn as wo,metadataKeys as Mo,notHidden as To,visibleColumnAtIndex as Do}from"@vuu-ui/vuu-utils";import{useCallback as ht,useMemo as xo}from"react";import gt from"classnames";import{useRef as ho}from"react";import{jsx as q,jsxs as bt}from"react/jsx-runtime";var G="vuuTable-groupHeaderCell",yo=e=>{let{column:t,className:n,onRemoveColumn:o}=e;return bt("div",{className:gt(`${G}-col`,n),role:"columnheader",children:[q("span",{className:`${G}-label`,children:t.name}),q("span",{className:`${G}-close`,"data-icon":"close-circle",onClick:()=>o==null?void 0:o(t)})]})},Ct=({column:e,className:t,onRemoveColumn:n,onResize:o,...r})=>{let l=ho(null),{isResizing:s,...i}=de({column:e,onResize:o,rootRef:l}),a=gt(G,t,{vuuPinLeft:e.pin==="left",[`${G}-right`]:e.align==="right",[`${G}-resizing`]:e.resizing,[`${G}-pending`]:e.groupConfirmed===!1}),{columns:m}=e;return q("th",{className:a,ref:l,...r,children:bt("div",{className:`${G}-inner`,children:[m.map(c=>q(yo,{column:c,onRemoveColumn:n},c.key)),e.resizeable!==!1?q(ue,{...i}):null]})})};import{jsx as F,jsxs as Pe}from"react/jsx-runtime";var yt="vuuTable",{RENDER_IDX:Ro}=Mo,vt=({columns:e,columnsWithinViewport:t,data:n,headings:o,onColumnResize:r,onHeaderCellDragStart:l,onContextMenu:s,onRemoveColumnFromGroupBy:i,onRowClick:a,onSort:m,onToggleGroup:c,virtualColSpan:d=0,rowCount:C,rowHeight:y})=>{let w=ht(g=>{l==null||l(g)},[l]),u=xo(()=>e.filter(To),[e]),f=ht(g=>{var x;let v=g.target.closest(".vuuTable-headerCell"),H=parseInt((x=v==null?void 0:v.dataset.idx)!=null?x:"-1"),P=Do(e,H),h=g.shiftKey;P&&m(P,h)},[e,m]);return Pe("table",{"aria-rowcount":C,className:`${yt}-table`,children:[F("colgroup",{children:u.map((g,p)=>F("col",{width:`${g.width}px`},p))}),Pe("thead",{children:[o.map((g,p)=>F("tr",{className:"vuuTable-heading",children:g.map(({label:v,span:H},P)=>F("th",{colSpan:H,className:"vuuTable-headingCell",children:v},P))},p)),F("tr",{children:u.map((g,p)=>{let v=vo(g);return wo(g)?F(Ct,{column:g,"data-idx":p,onRemoveColumn:i,onResize:r,style:v},p):F(pe,{column:g,"data-idx":p,onClick:f,onDragStart:w,onResize:r,style:v},p)})})]}),Pe("tbody",{onContextMenu:s,children:[n==null?void 0:n.map((g,p)=>F(ce,{columns:t,height:y,index:p,onClick:a,virtualColSpan:d,onToggleGroup:c,row:g},g[Ro])),F("tr",{className:`${yt}-filler`})]})]})};import{useContextMenu as _r}from"@vuu-ui/vuu-popups";import{applySort as Jr,buildColumnMap as Xr,isJsonGroup as Yr,metadataKeys as Qr,moveItem as jr}from"@vuu-ui/vuu-utils";import{useCallback as z,useEffect as jt,useMemo as Zr,useRef as Ge,useState as qr}from"react";import{isVuuFeatureAction as Ho,isVuuFeatureInvocation as Po}from"@vuu-ui/vuu-data";import{getFullRange as Se,metadataKeys as So,WindowRange as Eo}from"@vuu-ui/vuu-utils";import{useCallback as X,useEffect as fe,useMemo as Ao,useRef as ee,useState as Lo}from"react";var{SELECTED:te}=So;function wt({dataSource:e,onConfigChange:t,onFeatureEnabled:n,onFeatureInvocation:o,onSizeChange:r,onSubscribed:l,range:s={from:0,to:0},renderBufferSize:i=0,viewportRowCount:a}){let[,m]=Lo(null),c=ee(!0),d=ee(!1),C=ee({from:0,to:0}),y=ee(null),w=ee([]),u=Ao(()=>new Ee(Se(s)),[]),f=X(h=>{for(let x of h)u.add(x);w.current=u.data,d.current=!0},[u]),g=X(h=>{h.type==="subscribed"?l==null||l(h):h.type==="viewport-update"?(typeof h.size=="number"&&(r==null||r(h.size),u.setRowCount(h.size)),h.rows?f(h.rows):typeof h.size=="number"&&(w.current=u.data,d.current=!0)):Ho(h)?n==null||n(h):Po(h)?o==null||o(h):console.log(`useDataSource unexpected message ${h.type}`)},[u,n,o,r,l,f]);fe(()=>()=>{y.current&&(cancelAnimationFrame(y.current),y.current=null),c.current=!1},[]);let p=X(()=>{c.current&&(d.current&&(m({}),d.current=!1),y.current=requestAnimationFrame(p))},[m]);fe(()=>{y.current=requestAnimationFrame(p)},[p]);let v=X(h=>{let{from:x}=e.range,A={from:x,to:x+h},k=Se(A,i);e.range=C.current=k,e.emit("range",A),u.setRange(k)},[e,u,i]),H=X(h=>{let x=Se(h,i);e.range=C.current=x,u.setRange(x),e.emit("range",h)},[e,u,i]),P=X(()=>u.getSelectedRows(),[u]);return fe(()=>{e==null||e.subscribe({range:C.current},g)},[e,g,t]),fe(()=>{v(a)},[v,a]),{data:w.current,getSelectedRows:P,range:C.current,setRange:H,dataSource:e}}var Ee=class{constructor({from:t,to:n}){this.rowCount=0;this.setRowCount=t=>{t<this.data.length&&(this.data.length=t),this.rowCount=t};this.range=new Eo(t,n),this.data=new Array(n-t),this.rowCount=0}add(t){var o;let[n]=t;if(this.isWithinRange(n)){let r=n-this.range.from;this.data[r]=t;let l=t[te],s=(o=this.data[r-1])==null?void 0:o[te];s===0&&l?this.data[r-1][te]=2:s===2&&!l&&(this.data[r-1][te]=0)}}getAtIndex(t){return this.range.isWithin(t)&&this.data[t-this.range.from]!=null?this.data[t-this.range.from]:void 0}isWithinRange(t){return this.range.isWithin(t)}setRange({from:t,to:n}){if(t!==this.range.from||n!==this.range.to){let[o,r]=this.range.overlap(t,n),l=new Array(n-t);for(let s=o;s<r;s++){let i=this.getAtIndex(s);if(i){let a=s-t;l[a]=i}}this.data=l,this.range.from=t,this.range.to=n}}getSelectedRows(){return this.data.filter(t=>t[te]===1)}};import{useDragDrop as Ko}from"@heswell/salt-lab";import{useCallback as Mt,useLayoutEffect as ko,useRef as zo,useState as No}from"react";var Tt=({onDrop:e,tableContainerRef:t,tableLayout:n})=>{let[o,r]=No(n),l=zo(),s=Mt(()=>{console.log("handleDropSettle"),l.current=void 0,r("row")},[]),{draggable:i,draggedItemIndex:a,onMouseDown:m}=Ko({allowDragDrop:!0,draggableClassName:"table-column",orientation:"horizontal",containerRef:t,itemQuery:".vuuTable-table",onDrop:e,onDropSettle:s}),c=Mt(d=>{let{clientX:C,clientY:y}=d;console.log("useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable");let u=d.target.closest(".vuuTable-headerCell"),{dataset:{idx:f="-1"}}=u;l.current={clientX:C,clientY:y,idx:f},r("column")},[]);return ko(()=>{var d;if(o==="column"&&l.current&&!i){let{clientX:C,clientY:y,idx:w}=l.current,u=(d=t.current)==null?void 0:d.querySelector(`.vuuTable-table[data-idx="${w}"]`);if(u){let f={persist:()=>{},nativeEvent:{clientX:C,clientY:y,target:u}};m==null||m(f)}}},[i,m,t,o]),{draggable:i,draggedItemIndex:a,tableLayout:o,onHeaderCellDragStart:o==="row"?c:void 0}};import{withinRange as Oo}from"@vuu-ui/vuu-utils";import{useCallback as $,useEffect as Bo,useLayoutEffect as Uo,useMemo as _o,useRef as Fe}from"react";function Io(e,...t){let n=new Set(e);for(let o of t)for(let r of o)n.add(r);return n}var Ae="ArrowUp",Le="ArrowDown",Ke="ArrowLeft",ke="ArrowRight";var ze="Home",Ne="End",Ie="PageUp",Ve="PageDown";var Vo=new Set(["Enter","Delete"," "]),Fo=new Set(["Tab"]),$o=new Set(["ArrowRight","ArrowLeft"]),Dt=new Set([ze,Ne,Ie,Ve,Le,Ke,ke,Ae]),Wo=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),xi=Io(Vo,Dt,$o,Wo,Fo);var Go=["Home","End","PageUp","PageDown"],xt=e=>Go.includes(e),Rt=e=>Dt.has(e);var Ht=e=>`thead th:nth-child(${e+1})`,Jo=(e,t)=>`tbody > tr[aria-rowindex='${e}'] > td:nth-child(${t+1})`,Xo=[-1,-1];function Yo(e,[t,n],o,r){return e===Ae?t>-1?[t-1,n]:[t,n]:e===Le?t===-1?[0,n]:t===r-1?[t,n]:[t+1,n]:e===ke?n<o-1?[t,n+1]:[t,n]:e===Ke?n>0?[t,n-1]:[t,n]:[t,n]}var Pt=({columnCount:e=0,containerRef:t,disableHighlightOnFocus:n,data:o,requestScroll:r,rowCount:l=0,viewportRange:s})=>{var k;let{from:i,to:a}=s,m=Fe([-1,-1]),c=Fe(),d=Fe([-1,0]),C=$(([b,M])=>{var R;let D=b===-1?Ht(M):Jo(b,M);return(R=t.current)==null?void 0:R.querySelector(D)},[t]),y=b=>b==null?void 0:b.closest("th,td"),w=b=>{var M,D;if(b.tagName==="TH")return[-1,parseInt((M=b.dataset.idx)!=null?M:"-1",10)];{let R=b.closest("tr");if(R){let N=parseInt((D=R.ariaRowIndex)!=null?D:"-1",10),E=Array.from(R.childNodes).indexOf(b);return[N,E]}}return Xo},u=$(b=>{var M;if(t.current){let D=C(b);D?(D!==c.current&&((M=c.current)==null||M.setAttribute("tabindex",""),c.current=D,D.setAttribute("tabindex","0")),D.focus()):Oo(b[0],s)||(c.current=void 0,r==null||r({type:"scroll-page",direction:"up"}))}},[t,C,r,s]),f=$((b,M,D=!1)=>{let R=[b,M];d.current=R,u(R),D&&(m.current=R)},[u]),g=$(()=>{var b;(b=c.current)==null||b.setAttribute("tabindex",""),c.current=void 0},[]),p=$(async(b,M)=>{switch(b){case Ve:r==null||r({type:"scroll-page",direction:"down"});break;case Ie:r==null||r({type:"scroll-page",direction:"up"});break;case ze:r==null||r({type:"scroll-end",direction:"home"});break;case Ne:r==null||r({type:"scroll-end",direction:"end"});break}return M},[r]),v=$(()=>{var b;if(n!==!0&&(b=t.current)!=null&&b.contains(document.activeElement)){let M=y(document.activeElement);M&&(m.current=w(M))}},[n,t]),H=$(async b=>{let[M,D]=xt(b)?await p(b,d.current):Yo(b,d.current,e,l),[R,N]=d.current;(M!==R||D!==N)&&f(M,D,!0)},[e,p,l,f]),P=$(b=>{o.length>0&&Rt(b.key)&&(b.preventDefault(),b.stopPropagation(),H(b.key))},[o,H]),h=$(b=>{let M=b.target,D=y(M);if(D){let[R,N]=w(D);f(R,N)}},[f]),x=_o(()=>({onClick:h,onFocus:v,onKeyDown:P}),[h,v,P]);Uo(()=>{let{current:b}=d,M=b[0]>=i&&b[0]<=a;c.current&&!M?g():!c.current&&M&&u(b)},[u,i,a,g]);let A=((k=t.current)==null?void 0:k.firstChild)!=null;return Bo(()=>{var b;if(A&&c.current===void 0){let M=(b=t.current)==null?void 0:b.querySelector(Ht(0));M&&(M.setAttribute("tabindex","0"),c.current=M)}},[t,A]),x};import{useCallback as Zo,useRef as qo,useState as er}from"react";import{useCallback as Qo,useEffect as St,useRef as jo}from"react";var B=new Map,At=(e,t,n)=>{switch(n){case"height":return t.height;case"clientHeight":return e.clientHeight;case"clientWidth":return e.clientWidth;case"contentHeight":return t.contentHeight;case"contentWidth":return t.contentWidth;case"scrollHeight":return Math.ceil(e.scrollHeight);case"scrollWidth":return Math.ceil(e.scrollWidth);case"width":return t.width;default:return 0}},Et=new ResizeObserver(e=>{for(let t of e){let{target:n,borderBoxSize:o,contentBoxSize:r}=t,l=B.get(n);if(l){let[{blockSize:s,inlineSize:i}]=o,[{blockSize:a,inlineSize:m}]=r,{onResize:c,measurements:d}=l,C=!1;for(let[y,w]of Object.entries(d)){let u=At(n,{height:s,width:i,contentHeight:a,contentWidth:m},y);u!==w&&(C=!0,d[y]=u)}C&&c&&c(d)}}});function Lt(e,t,n,o=!1){let r=jo(t),l=Qo(s=>{let{width:i,height:a}=s.getBoundingClientRect(),{clientWidth:m,clientHeight:c}=s;return r.current.reduce((d,C)=>(d[C]=At(s,{width:i,height:a,contentHeight:c,contentWidth:m},C),d),{})},[]);St(()=>{let s=e.current;async function i(){B.set(s,{measurements:{}}),await document.fonts.ready;let a=B.get(s);if(a){let m=l(s);a.measurements=m,Et.observe(s),o&&n(m)}else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation","font-weight:bold; color:red;")}if(s){if(B.has(s))throw Error("useResizeObserver attemping to observe same element twice");i()}return()=>{s&&B.has(s)&&(Et.unobserve(s),B.delete(s))}},[l,e]),St(()=>{let s=e.current,i=B.get(s);if(i){if(r.current!==t){r.current=t;let a=l(s);i.measurements=a}i.onResize=n}},[t,l,e,n])}var tr=["clientHeight","clientWidth"],Kt=e=>Number.isFinite(e),kt=({defaultHeight:e=0,defaultWidth:t=0,height:n,width:o})=>{let r=qo(null),[l,s]=er({outer:{height:n!=null?n:"100%",width:o!=null?o:"100%"}}),i=Zo(({clientWidth:a,clientHeight:m})=>{s(c=>{let{inner:d,outer:C}=c;return Kt(m)&&Kt(a)&&(a!==(d==null?void 0:d.width)||m!==(d==null?void 0:d.height))?{outer:C,inner:{width:Math.floor(a)||t,height:Math.floor(m)||e}}:c})},[e,t]);return Lt(r,tr,i,!0),{containerRef:r,outerSize:l.outer,innerSize:l.inner}};import{deselectItem as nr,metadataKeys as or,selectItem as rr}from"@vuu-ui/vuu-utils";import{useCallback as sr,useRef as zt}from"react";var{IDX:lr,SELECTED:ir}=or,ar=[],Nt=({selectionModel:e,onSelectionChange:t})=>{let n=zt(-1),o=zt(ar);return sr((l,s,i)=>{let{[lr]:a,[ir]:m}=l,{current:c}=n,{current:d}=o,y=(m?nr:rr)(e,d,a,s,i,c);o.current=y,n.current=a,t&&t(y)},[t,e])};import{moveItem as cr}from"@heswell/salt-lab";import{applyFilterToColumns as ur,applyGroupByToColumns as mr,applySortToColumns as dr,findColumn as pr,getCellRenderer as fr,getColumnName as gr,getTableHeadings as Cr,getValueFormatter as br,isFilteredColumn as hr,isGroupColumn as yr,isPinned as vr,isTypeDescriptor as wr,logger as Mr,metadataKeys as Tr,sortPinnedColumns as It,stripFilterFromColumns as Dr}from"@vuu-ui/vuu-utils";import{useReducer as xr}from"react";var{info:$e}=Mr("useTableModel"),Rr=100,Vt=Tr.count,Hr=({serverDataType:e})=>e===void 0,Pr=e=>{var t,n;if(wr(e.type))return fr((n=(t=e.type)==null?void 0:t.renderer)==null?void 0:n.name)},Sr=(e,t,n)=>{var r;let o=t.indexOf(e.name);return o!==-1&&n[o]?n[o]:(r=e.serverDataType)!=null?r:"string"},Er=["int","long","double"],Ft=e=>e===void 0?void 0:Er.includes(e)?"right":"left",Ar=(e,t)=>{switch($e==null||$e(`GridModelReducer ${t.type}`),t.type){case"init":return Wt(t);case"moveColumn":return Kr(e,t);case"resizeColumn":return Nr(e,t);case"setTypes":return Ir(e,t);case"hideColumns":return kr(e,t);case"showColumns":return zr(e,t);case"pinColumn":return Vr(e,t);case"updateColumnProp":return ne(e,t);case"tableConfig":return Ot(e,t);default:return console.log(`unhandled action ${t.type}`),e}},$t=(e,t)=>{let[n,o]=xr(Ar,{tableConfig:e,dataSourceConfig:t},Wt);return{columns:n.columns,dispatchColumnAction:o,headings:n.headings}};function Wt({dataSourceConfig:e,tableConfig:t}){let n=t.columns.map(Gt(t)),o=n.some(vr)?It(n):n,r={columns:o,headings:Cr(o)};if(e){let{columns:l,...s}=e;return Ot(r,{type:"tableConfig",...s})}else return r}var Lr=(e,t)=>t==="uppercase"?e.toUpperCase():t==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,Gt=e=>(t,n)=>{let{columnDefaultWidth:o=Rr,columnFormatHeader:r}=e,{align:l=Ft(t.serverDataType),key:s,name:i,label:a=i,width:m=o,...c}=t,d={...c,align:l,CellRenderer:Pr(t),label:Lr(a,r),key:s!=null?s:n+Vt,name:i,originalIdx:n,valueFormatter:br(t),width:m};return yr(d)&&(d.columns=d.columns.map(C=>Gt(e)(C,C.key))),d};function Kr(e,{column:t,moveBy:n,moveTo:o}){let{columns:r}=e;if(typeof n=="number"){let l=r.indexOf(t),s=r.slice(),[i]=s.splice(l,1);return s.splice(l+n,0,i),{...e,columns:s}}else if(typeof o=="number"){let l=r.indexOf(t);return{...e,columns:cr(r,l,o)}}return e}function kr(e,{columns:t}){return t.some(n=>n.hidden!==!0)?t.reduce((n,o)=>o.hidden!==!0?ne(n,{type:"updateColumnProp",column:o,hidden:!0}):n,e):e}function zr(e,{columns:t}){return t.some(n=>n.hidden)?t.reduce((n,o)=>o.hidden?ne(n,{type:"updateColumnProp",column:o,hidden:!1}):n,e):e}function Nr(e,{column:t,phase:n,width:o}){let r="updateColumnProp",l=n!=="end";switch(n){case"begin":case"end":return ne(e,{type:r,column:t,resizing:l});case"resize":return ne(e,{type:r,column:t,width:o});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${n}`)}}function Ir(e,{columnNames:t,serverDataTypes:n}){let{columns:o}=e;if(o.some(Hr)){let r=o.map(l=>{var i;let s=Sr(l,t,n);return{...l,align:(i=l.align)!=null?i:Ft(s),serverDataType:s}});return{...e,columns:r}}else return e}function Vr(e,t){let{columns:n}=e,{column:o,pin:r}=t,l=n.find(s=>s.name===o.name);return l?(n=Y(n,{...l,pin:r}),n=It(n),{...e,columns:n}):e}function ne(e,t){let{columns:n}=e,{align:o,column:r,hidden:l,label:s,resizing:i,width:a}=t,m=n.find(c=>c.name===r.name);return m&&((o==="left"||o==="right")&&(n=Y(n,{...m,align:o})),typeof s=="string"&&(n=Y(n,{...m,label:s})),typeof i=="boolean"&&(n=Y(n,{...m,resizing:i})),typeof l=="boolean"&&(n=Y(n,{...m,hidden:l})),typeof a=="number"&&(n=Y(n,{...m,width:a}))),{...e,columns:n}}function Ot(e,{columns:t,confirmed:n,filter:o,groupBy:r,sort:l}){let s=t&&t.length>0,i=r!==void 0,a=typeof(o==null?void 0:o.filter)=="string",m=l&&l.sortDefs.length>0,c=e;return s&&(c={...e,columns:t.map((d,C)=>{let y=gr(d),w=C+Vt,u=pr(c.columns,y);if(u)return u.key===w?u:{...u,key:w};throw Error(`useTableModel column ${d} not found`)})}),i&&(c={...e,columns:mr(c.columns,r,n)}),m&&(c={...e,columns:dr(c.columns,l)}),a?c={...e,columns:ur(c.columns,o)}:c.columns.some(hr)&&(c={...e,columns:Dr(c.columns)}),c}function Y(e,t){return e.map(n=>n.name===t.name?t:n)}import{useCallback as oe,useRef as re}from"react";var Bt=e=>{let{scrollLeft:t,scrollTop:n}=e,{clientHeight:o,clientWidth:r,scrollHeight:l,scrollWidth:s}=e,i=t/(s-r),a=n/(l-o);return[i,a,t,n]},Fr=e=>{let{clientHeight:t,clientWidth:n,scrollHeight:o,scrollWidth:r}=e;return[r-n,o-t]},Ut=({onHorizontalScroll:e,onVerticalScroll:t,viewport:n})=>{let o=re({scrollTop:0,scrollLeft:0}),r=re(null),l=re(null),s=re(null),i=re(!1),{maxScrollContainerScrollHorizontal:a,maxScrollContainerScrollVertical:m}=n,c=oe((u,f)=>{let{current:g}=s;g&&g.scrollTo({top:f,left:u,behavior:"auto"})},[s]),d=oe(()=>{let{current:u}=s;if(u){let{current:f}=o,{scrollLeft:g,scrollTop:p}=u;f.scrollTop!==p&&(f.scrollTop=p,t==null||t(p)),f.scrollLeft!==g&&(f.scrollLeft=g,e==null||e(g))}},[e,t]),C=oe(()=>{let{current:u}=l,{current:f}=r;if(u&&f){let[g,p,v,H]=Bt(u);i.current=!0,f.scrollLeft=Math.round(g*a),f.scrollTop=Math.round(p*m),c(v,H)}},[a,m,l,r,c]),y=oe(()=>{let{current:u}=l,{current:f}=r,{current:g}=i;if(g)i.current=!1;else if(u&&f){let[p,v]=Bt(f),[H,P]=Fr(u),h=Math.round(p*H),x=Math.round(v*P);u.scrollTo({left:h,top:x,behavior:"auto"}),c(h,x)}},[l,r,c]),w=oe(u=>{let{current:f}=r;if(f){if(i.current=!1,u.type==="scroll-page"){let{clientHeight:g,scrollLeft:p,scrollTop:v}=f,{direction:H}=u,P=H==="down"?g:-g,h=Math.min(Math.max(0,v+P),n.maxScrollContainerScrollVertical);f.scrollTo({top:h,left:p,behavior:"auto"})}else if(u.type==="scroll-end"){let{direction:g}=u,p=g==="end"?n.maxScrollContainerScrollVertical:0;f.scrollTo({top:p,left:f.scrollLeft,behavior:"auto"})}}},[n.maxScrollContainerScrollVertical]);return{scrollbarContainerRef:r,onScrollbarContainerScroll:y,contentContainerRef:l,onContentContainerScroll:C,tableContainerRef:s,onTableContainerScroll:d,requestScroll:w}};import{useMemo as _t}from"react";var $r={fillerHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,scrollContentHeight:0,scrollbarSize:0,scrollContentWidth:0,totalHeaderHeight:0},Wr=e=>{let t=0,n=0,o=0;for(let r of e){let{hidden:l,pin:s,width:i}=r,a=l?0:i;s==="left"?t+=a:s==="right"?n+=a:o+=a}return{pinnedWidthLeft:t,pinnedWidthRight:n,unpinnedWidth:o}},Jt=({columns:e,headerHeight:t,headings:n,rowCount:o,rowHeight:r,size:l})=>{let{pinnedWidthLeft:s,pinnedWidthRight:i,unpinnedWidth:a}=_t(()=>Wr(e),[e]);return _t(()=>{var c;if(l){let d=n.length,C=15,y=o*r,w=s+a+i,u=y+t-(((c=l==null?void 0:l.height)!=null?c:0)-t-C),f=w-l.width+s,g=(l.height-t)/r,p=Number.isInteger(g)?g+1:Math.ceil(g);return{fillerHeight:(o-p)*r,maxScrollContainerScrollHorizontal:f,maxScrollContainerScrollVertical:u,pinnedWidthLeft:s,pinnedWidthRight:i,rowCount:p,scrollContentHeight:t+y+C,scrollbarSize:C,scrollContentWidth:w,totalHeaderHeight:t*(1+d)}}else return $r},[t,n.length,s,i,o,r,l,a])};import{getColumnsInViewport as Xt,itemsChanged as Gr}from"@vuu-ui/vuu-utils";import{useCallback as Yt,useEffect as Or,useMemo as Br,useRef as We,useState as Ur}from"react";var Qt=({columns:e,rowHeight:t,setRange:n,viewportMeasurements:o})=>{let r=We(-1),{rowCount:l,scrollContentWidth:s,maxScrollContainerScrollHorizontal:i}=o,a=s-i,m=We(0),[c,d]=Br(()=>Xt(e,m.current,m.current+a),[a,e]),C=We(d);Or(()=>{w(c)},[c]);let[y,w]=Ur(c),u=Yt(g=>{m.current=g;let[p,v]=Xt(e,g,g+a);Gr(y,p)&&(C.current=v,w(p))},[a,e,y]),f=Yt(g=>{let p=Math.floor(g/t);p!==r.current&&(r.current=p,n({from:p,to:p+l}))},[t,n,l]);return{columnsWithinViewport:y,onHorizontalScroll:u,onVerticalScroll:f,virtualColSpan:C.current}};var es=[],{KEY:ts,IS_EXPANDED:Zt,IS_LEAF:qt}=Qr,en=({config:e,dataSource:t,headerHeight:n,onConfigChange:o,onFeatureEnabled:r,onFeatureInvocation:l,onSelectionChange:s,renderBufferSize:i=0,rowHeight:a,selectionModel:m,tableLayout:c,...d})=>{var _e,Je;let[C,y]=qr(0),w=Ge(!1),u=Ge();if(u.current=t,t===void 0)throw Error("no data source provided to DataTable");let f=kt(d),g=z(T=>{y(T)},[]),{columns:p,dispatchColumnAction:v,headings:H}=$t(e,t.config),P=z(T=>{w.current=!0,v(T)},[v]),h=ft({dataSource:t,onPersistentColumnOperation:P}),x=Jt({columns:p,headerHeight:n,headings:H,rowCount:C,rowHeight:a,size:f.innerSize}),A=z(T=>{if(T.tableMeta){let{columns:S,dataTypes:K}=T.tableMeta;w.current=!0,v({type:"setTypes",columnNames:S,serverDataTypes:K})}},[v]),k=z(T=>{t.select(T),s==null||s(T)},[t,s]),b=Nt({onSelectionChange:k,selectionModel:m}),{data:M,getSelectedRows:D,range:R,setRange:N}=wt({dataSource:t,onFeatureEnabled:r,onFeatureInvocation:l,onSubscribed:A,onSizeChange:g,renderBufferSize:i,viewportRowCount:x.rowCount}),E=Ge();E.current=M;let le=z((T,S=!1,K)=>{t&&(t.sort=Jr(t.sort,T,S,K))},[t]),ge=z((T,S,K)=>{let L=p.find(I=>I.name===S);if(L)T==="end"&&(w.current=!0),v({type:"resizeColumn",phase:T,column:L,width:K});else throw Error(`useDataTable.handleColumnResize, column ${S} not found`)},[p,v]),Ce=z((T,S)=>{let K=Yr(S,T),L=T[ts];if(T[Zt]){if(t.closeTreeNode(L,!0),K){let I=p.indexOf(S);t.getRowsAtDepth(I+1).some(V=>V[Zt]||V[qt])||v({type:"hideColumns",columns:p.slice(I+2)})}}else if(t.openTreeNode(L),K){let I=t.getChildRows(L),O=p.indexOf(S)+1,V=[p[O]];I.some(_=>_[qt])&&V.push(p[O+1]),V.some(_=>_.hidden)&&v({type:"showColumns",columns:V})}},[p,t,v]),{onVerticalScroll:be,onHorizontalScroll:he,columnsWithinViewport:nn,virtualColSpan:on}=Qt({columns:p,rowHeight:a,setRange:N,viewportMeasurements:x}),{requestScroll:rn,...Be}=Ut({onHorizontalScroll:he,onVerticalScroll:be,viewport:x,viewportHeight:((Je=(_e=f.innerSize)==null?void 0:_e.height)!=null?Je:0)-n}),sn=Pt({columnCount:p.length,containerRef:f.containerRef,data:M,requestScroll:rn,rowCount:t==null?void 0:t.size,viewportRange:R}),ln=z(T=>{t&&t.groupBy.includes(T.name)&&(t.groupBy=t.groupBy.filter(S=>S!==T.name))},[t]),an=z((T,S)=>{let K=t.columns[T],L=jr(t.columns,K,S);L!==t.columns&&(t.columns=L,v({type:"tableConfig",columns:L}))},[t,v]),cn=Tt({onDrop:an,tableContainerRef:Be.tableContainerRef,tableLayout:c});jt(()=>{u.current&&(w.current=!0,v({type:"init",tableConfig:e,dataSourceConfig:u.current.config}))},[e,v]),jt(()=>{t.on("config",(T,S)=>{w.current=!0,v({type:"tableConfig",...T,confirmed:S})})},[t,v]),Zr(()=>{w.current&&(o==null||o({...e,columns:p}),w.current=!1)},[p,e,o]);let Ue=_r(),un=z(T=>{var V;let{current:S}=E,{current:K}=u,L=T.target,I=L==null?void 0:L.closest("td"),O=L==null?void 0:L.closest("tr");if(I&&O&&S&&K){let{columns:_,selectedRowsCount:mn}=K,dn=Xr(_),pn=parseInt((V=O.ariaRowIndex)!=null?V:"-1"),fn=Array.from(O.childNodes).indexOf(I),gn=S.find(([bn])=>bn===pn),Cn=_[fn];Ue(T,"grid",{columnMap:dn,columnName:Cn,row:gn,selectedRows:mn===0?es:D(),viewport:t==null?void 0:t.viewport})}},[t==null?void 0:t.viewport,D,Ue]);return{containerMeasurements:f,containerProps:sn,columns:p,columnsWithinViewport:nn,data:M,dispatchColumnAction:v,handleContextMenuAction:h,headings:H,onColumnResize:ge,onContextMenu:un,onRemoveColumnFromGroupBy:ln,onRowClick:b,onSort:le,onToggleGroup:Ce,virtualColSpan:on,scrollProps:Be,rowCount:C,viewportMeasurements:x,...cn}};import ss from"classnames";import{isDataLoading as ls}from"@vuu-ui/vuu-utils";import{jsx as U,jsxs as tn}from"react/jsx-runtime";var W="vuuTable",Ka=({allowConfigEditing:e=!1,className:t,config:n,dataSource:o,headerHeight:r=25,height:l,id:s,onConfigChange:i,onFeatureEnabled:a,onFeatureInvocation:m,onSelectionChange:c,onShowConfigEditor:d,renderBufferSize:C=0,rowHeight:y=20,selectionModel:w="extended",style:u,tableLayout:f="row",width:g,zebraStripes:p=!1,...v})=>{let H=rs(s),{containerMeasurements:{containerRef:P,innerSize:h,outerSize:x},containerProps:A,dispatchColumnAction:k,draggable:b,draggedItemIndex:M,handleContextMenuAction:D,scrollProps:R,tableLayout:N,viewportMeasurements:E,...le}=en({config:n,dataSource:o,renderBufferSize:C,headerHeight:r,height:l,onConfigChange:i,onFeatureEnabled:a,onFeatureInvocation:m,onSelectionChange:c,rowHeight:y,selectionModel:w,tableLayout:f,width:g}),ge={...x,"--content-height":`${E.scrollContentHeight}px`,"--content-width":`${E.scrollContentWidth}px`,"--filler-height":`${E.fillerHeight}px`,"--pinned-width-left":`${E.pinnedWidthLeft}px`,"--pinned-width-right":`${E.pinnedWidthRight}px`,"--header-height":`${r}px`,"--row-height":`${y}px`,"--scrollbar-size":`${E.scrollbarSize}px`,"--table-height":`${h==null?void 0:h.height}px`,"--table-width":`${h==null?void 0:h.width}px`,"--total-header-height":`${E==null?void 0:E.totalHeaderHeight}px`},Ce={left:E.pinnedWidthLeft-1,top:(E==null?void 0:E.totalHeaderHeight)-1},be=N==="column"?ct:vt,he=ss(W,t,{[`${W}-zebra`]:p,[`${W}-loading`]:ls(le.columns)});return U(ns,{menuActionHandler:D,menuBuilder:ut(o),children:tn("div",{...A,className:he,id:H,ref:P,style:ge,tabIndex:-1,children:[h?U("div",{className:`${W}-scrollbarContainer`,onScroll:R.onScrollbarContainerScroll,ref:R.scrollbarContainerRef,style:Ce,children:U("div",{className:`${W}-scrollContent`})}):null,h?tn("div",{className:`${W}-contentContainer`,onScroll:R.onContentContainerScroll,ref:R.contentContainerRef,...v,children:[U("div",{className:`${W}-scrollContent`}),U("div",{className:`${W}-tableContainer`,onScroll:R.onTableContainerScroll,ref:R.tableContainerRef,children:U(be,{...le,headerHeight:r,rowHeight:y})}),b]}):null,e&&h?U(os,{className:`${W}-settings`,"data-icon":"settings",onClick:d,variant:"secondary"}):null]})})};import is from"classnames";import{isJsonAttribute as as,metadataKeys as cs,registerComponent as us}from"@vuu-ui/vuu-utils";import{jsx as Oe,jsxs as gs}from"react/jsx-runtime";var se="vuuJsonCell",{IS_EXPANDED:ms,KEY:ds}=cs,ps=e=>{let t=e.lastIndexOf("|");return t===-1?"":e.slice(t+1)},fs=({column:e,row:t})=>{let{key:n}=e,o=t[n],r=!1;as(o)&&(o=o.slice(0,-1),r=!0);let l=ps(t[ds]),s=is({[`${se}-name`]:l===o,[`${se}-value`]:l!==o,[`${se}-group`]:r});if(r){let i=t[ms]?"minus-box":"plus-box";return gs("span",{className:s,children:[Oe("span",{className:`${se}-value`,children:o}),Oe("span",{className:`${se}-toggle`,"data-icon":i})]})}else return o?Oe("span",{className:s,children:o}):null};us("json",fs,"cell-renderer",{});export{Ka as Table,kt as useMeasuredContainer};
|
|
1
|
+
// src/Table.tsx
|
|
2
|
+
import { ContextMenuProvider } from "@vuu-ui/vuu-popups";
|
|
3
|
+
import { Button, useIdMemo } from "@salt-ds/core";
|
|
4
|
+
|
|
5
|
+
// src/ColumnBasedTable.tsx
|
|
6
|
+
import { metadataKeys as metadataKeys4 } from "@vuu-ui/vuu-utils";
|
|
7
|
+
import { useCallback as useCallback8 } from "react";
|
|
8
|
+
import cx6 from "classnames";
|
|
9
|
+
|
|
10
|
+
// src/TableRow.tsx
|
|
11
|
+
import {
|
|
12
|
+
isGroupColumn,
|
|
13
|
+
isJsonColumn,
|
|
14
|
+
isJsonGroup,
|
|
15
|
+
metadataKeys as metadataKeys3,
|
|
16
|
+
notHidden
|
|
17
|
+
} from "@vuu-ui/vuu-utils";
|
|
18
|
+
import cx2 from "classnames";
|
|
19
|
+
import { memo as memo2, useCallback as useCallback3 } from "react";
|
|
20
|
+
|
|
21
|
+
// src/TableCell.tsx
|
|
22
|
+
import { getColumnPinStyle, metadataKeys } from "@vuu-ui/vuu-utils";
|
|
23
|
+
import { EditableLabel } from "@heswell/salt-lab";
|
|
24
|
+
import cx from "classnames";
|
|
25
|
+
import { memo, useCallback, useRef, useState } from "react";
|
|
26
|
+
import { jsx } from "react/jsx-runtime";
|
|
27
|
+
var { KEY } = metadataKeys;
|
|
28
|
+
var TableCell = memo(
|
|
29
|
+
({ className: classNameProp, column, onClick, row }) => {
|
|
30
|
+
const labelFieldRef = useRef(null);
|
|
31
|
+
const {
|
|
32
|
+
align,
|
|
33
|
+
CellRenderer,
|
|
34
|
+
key,
|
|
35
|
+
pin,
|
|
36
|
+
editable,
|
|
37
|
+
resizing,
|
|
38
|
+
valueFormatter
|
|
39
|
+
} = column;
|
|
40
|
+
const [editing, setEditing] = useState(false);
|
|
41
|
+
const value = valueFormatter(row[key]);
|
|
42
|
+
const [editableValue, setEditableValue] = useState(value);
|
|
43
|
+
const handleTitleMouseDown = () => {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = labelFieldRef.current) == null ? void 0 : _a.focus();
|
|
46
|
+
};
|
|
47
|
+
const handleTitleKeyDown = (evt) => {
|
|
48
|
+
if (evt.key === "Enter") {
|
|
49
|
+
setEditing(true);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const handleClick = useCallback(() => {
|
|
53
|
+
onClick == null ? void 0 : onClick(column);
|
|
54
|
+
}, [column, onClick]);
|
|
55
|
+
const handleEnterEditMode = () => {
|
|
56
|
+
setEditing(true);
|
|
57
|
+
};
|
|
58
|
+
const handleExitEditMode = (originalValue = "", finalValue = "", allowDeactivation = true, editCancelled = false) => {
|
|
59
|
+
var _a;
|
|
60
|
+
setEditing(false);
|
|
61
|
+
if (editCancelled) {
|
|
62
|
+
setEditableValue(originalValue);
|
|
63
|
+
} else if (finalValue !== originalValue) {
|
|
64
|
+
setEditableValue(finalValue);
|
|
65
|
+
}
|
|
66
|
+
if (allowDeactivation === false) {
|
|
67
|
+
(_a = labelFieldRef.current) == null ? void 0 : _a.focus();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const className = cx(classNameProp, {
|
|
71
|
+
vuuAlignRight: align === "right",
|
|
72
|
+
vuuPinFloating: pin === "floating",
|
|
73
|
+
vuuPinLeft: pin === "left",
|
|
74
|
+
vuuPinRight: pin === "right",
|
|
75
|
+
"vuuTableCell-resizing": resizing
|
|
76
|
+
}) || void 0;
|
|
77
|
+
const pinnedStyle = getColumnPinStyle(column);
|
|
78
|
+
return editable ? /* @__PURE__ */ jsx(
|
|
79
|
+
"td",
|
|
80
|
+
{
|
|
81
|
+
className,
|
|
82
|
+
"data-editable": true,
|
|
83
|
+
style: pinnedStyle,
|
|
84
|
+
onKeyDown: handleTitleKeyDown,
|
|
85
|
+
children: /* @__PURE__ */ jsx(
|
|
86
|
+
EditableLabel,
|
|
87
|
+
{
|
|
88
|
+
editing,
|
|
89
|
+
value: editableValue,
|
|
90
|
+
onChange: setEditableValue,
|
|
91
|
+
onMouseDownCapture: handleTitleMouseDown,
|
|
92
|
+
onEnterEditMode: handleEnterEditMode,
|
|
93
|
+
onExitEditMode: handleExitEditMode,
|
|
94
|
+
onKeyDown: handleTitleKeyDown,
|
|
95
|
+
ref: labelFieldRef,
|
|
96
|
+
tabIndex: 0
|
|
97
|
+
},
|
|
98
|
+
"title"
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
) : /* @__PURE__ */ jsx("td", { className, style: pinnedStyle, onClick: handleClick, children: CellRenderer ? /* @__PURE__ */ jsx(CellRenderer, { column, row }) : value });
|
|
102
|
+
},
|
|
103
|
+
cellValuesAreEqual
|
|
104
|
+
);
|
|
105
|
+
TableCell.displayName = "TableCell";
|
|
106
|
+
function cellValuesAreEqual(prev, next) {
|
|
107
|
+
return prev.column === next.column && prev.onClick === next.onClick && prev.row[KEY] === next.row[KEY] && prev.row[prev.column.key] === next.row[next.column.key];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/TableGroupCell.tsx
|
|
111
|
+
import { metadataKeys as metadataKeys2 } from "@vuu-ui/vuu-utils";
|
|
112
|
+
import { useCallback as useCallback2 } from "react";
|
|
113
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
114
|
+
var { DEPTH, IS_LEAF } = metadataKeys2;
|
|
115
|
+
var getGroupValueAndOffset = (columns, row) => {
|
|
116
|
+
const { [DEPTH]: depth, [IS_LEAF]: isLeaf } = row;
|
|
117
|
+
if (isLeaf || depth > columns.length) {
|
|
118
|
+
return [null, depth === null ? 0 : depth - 1];
|
|
119
|
+
} else if (depth === 0) {
|
|
120
|
+
return ["$root", 0];
|
|
121
|
+
} else {
|
|
122
|
+
const column = columns[depth - 1];
|
|
123
|
+
return [row[column.key], depth - 1];
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var TableGroupCell = ({ column, onClick, row }) => {
|
|
127
|
+
const { columns } = column;
|
|
128
|
+
const [value, offset] = getGroupValueAndOffset(columns, row);
|
|
129
|
+
const handleClick = useCallback2(() => {
|
|
130
|
+
onClick == null ? void 0 : onClick(column);
|
|
131
|
+
}, [column, onClick]);
|
|
132
|
+
const style = {
|
|
133
|
+
left: column.pin == "left" ? column.pinnedOffset : void 0
|
|
134
|
+
};
|
|
135
|
+
const isLeaf = row[IS_LEAF];
|
|
136
|
+
const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-spacer" }, i));
|
|
137
|
+
return /* @__PURE__ */ jsxs(
|
|
138
|
+
"td",
|
|
139
|
+
{
|
|
140
|
+
className: "vuuTableGroupCell vuuPinLeft",
|
|
141
|
+
onClick: isLeaf ? void 0 : handleClick,
|
|
142
|
+
style,
|
|
143
|
+
children: [
|
|
144
|
+
spacers,
|
|
145
|
+
isLeaf ? null : /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-toggle", "data-icon": "triangle-right" }),
|
|
146
|
+
/* @__PURE__ */ jsx2("span", { children: value })
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/TableRow.tsx
|
|
153
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
154
|
+
var { IDX, IS_EXPANDED, SELECTED } = metadataKeys3;
|
|
155
|
+
var classBase = "vuuTableRow";
|
|
156
|
+
var TableRow = memo2(function Row({
|
|
157
|
+
columns,
|
|
158
|
+
height,
|
|
159
|
+
index,
|
|
160
|
+
onClick,
|
|
161
|
+
onToggleGroup,
|
|
162
|
+
virtualColSpan = 0,
|
|
163
|
+
row
|
|
164
|
+
}) {
|
|
165
|
+
const {
|
|
166
|
+
[IDX]: rowIndex,
|
|
167
|
+
[IS_EXPANDED]: isExpanded,
|
|
168
|
+
[SELECTED]: isSelected
|
|
169
|
+
} = row;
|
|
170
|
+
const className = cx2(classBase, {
|
|
171
|
+
[`${classBase}-even`]: rowIndex % 2 === 0,
|
|
172
|
+
[`${classBase}-expanded`]: isExpanded,
|
|
173
|
+
[`${classBase}-preSelected`]: isSelected === 2
|
|
174
|
+
});
|
|
175
|
+
const offset = rowIndex - index;
|
|
176
|
+
const handleRowClick = useCallback3(
|
|
177
|
+
(evt) => {
|
|
178
|
+
const rangeSelect = evt.shiftKey;
|
|
179
|
+
const keepExistingSelection = evt.ctrlKey || evt.metaKey;
|
|
180
|
+
onClick == null ? void 0 : onClick(row, rangeSelect, keepExistingSelection);
|
|
181
|
+
},
|
|
182
|
+
[onClick, row]
|
|
183
|
+
);
|
|
184
|
+
const handleGroupCellClick = useCallback3(
|
|
185
|
+
(column) => {
|
|
186
|
+
if (isGroupColumn(column) || isJsonGroup(column, row)) {
|
|
187
|
+
onToggleGroup == null ? void 0 : onToggleGroup(row, column);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
[onToggleGroup, row]
|
|
191
|
+
);
|
|
192
|
+
return /* @__PURE__ */ jsxs2(
|
|
193
|
+
"tr",
|
|
194
|
+
{
|
|
195
|
+
"aria-selected": isSelected === 1 ? true : void 0,
|
|
196
|
+
"aria-rowindex": rowIndex,
|
|
197
|
+
className,
|
|
198
|
+
onClick: handleRowClick,
|
|
199
|
+
style: {
|
|
200
|
+
transform: `translate(0px, ${offset * height}px)`
|
|
201
|
+
},
|
|
202
|
+
children: [
|
|
203
|
+
virtualColSpan > 0 ? /* @__PURE__ */ jsx3("td", { colSpan: virtualColSpan }) : null,
|
|
204
|
+
columns.filter(notHidden).map((column) => {
|
|
205
|
+
const isGroup = isGroupColumn(column);
|
|
206
|
+
const isJsonCell = isJsonColumn(column);
|
|
207
|
+
const Cell = isGroup ? TableGroupCell : TableCell;
|
|
208
|
+
return /* @__PURE__ */ jsx3(
|
|
209
|
+
Cell,
|
|
210
|
+
{
|
|
211
|
+
column,
|
|
212
|
+
onClick: isGroup || isJsonCell ? handleGroupCellClick : void 0,
|
|
213
|
+
row
|
|
214
|
+
},
|
|
215
|
+
column.name
|
|
216
|
+
);
|
|
217
|
+
})
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// src/TableHeaderCell.tsx
|
|
224
|
+
import cx5 from "classnames";
|
|
225
|
+
import { useCallback as useCallback7, useRef as useRef4 } from "react";
|
|
226
|
+
|
|
227
|
+
// src/ColumnResizer.tsx
|
|
228
|
+
import { useCallback as useCallback4, useRef as useRef2 } from "react";
|
|
229
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
230
|
+
var NOOP = () => void 0;
|
|
231
|
+
var baseClass = "vuuColumnResizer";
|
|
232
|
+
var ColumnResizer = ({
|
|
233
|
+
onDrag,
|
|
234
|
+
onDragEnd = NOOP,
|
|
235
|
+
onDragStart = NOOP
|
|
236
|
+
}) => {
|
|
237
|
+
const position = useRef2(0);
|
|
238
|
+
const onMouseMove = useCallback4(
|
|
239
|
+
(e) => {
|
|
240
|
+
if (e.stopPropagation) {
|
|
241
|
+
e.stopPropagation();
|
|
242
|
+
}
|
|
243
|
+
if (e.preventDefault) {
|
|
244
|
+
e.preventDefault();
|
|
245
|
+
}
|
|
246
|
+
const x = Math.round(e.clientX);
|
|
247
|
+
const moveBy = x - position.current;
|
|
248
|
+
position.current = x;
|
|
249
|
+
if (moveBy !== 0) {
|
|
250
|
+
onDrag(e, moveBy);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
[onDrag]
|
|
254
|
+
);
|
|
255
|
+
const onMouseUp = useCallback4(
|
|
256
|
+
(e) => {
|
|
257
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
258
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
259
|
+
onDragEnd(e);
|
|
260
|
+
},
|
|
261
|
+
[onDragEnd, onMouseMove]
|
|
262
|
+
);
|
|
263
|
+
const handleMouseDown = useCallback4(
|
|
264
|
+
(e) => {
|
|
265
|
+
onDragStart(e);
|
|
266
|
+
position.current = Math.round(e.clientX);
|
|
267
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
268
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
269
|
+
if (e.stopPropagation) {
|
|
270
|
+
e.stopPropagation();
|
|
271
|
+
}
|
|
272
|
+
if (e.preventDefault) {
|
|
273
|
+
e.preventDefault();
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
[onDragStart, onMouseMove, onMouseUp]
|
|
277
|
+
);
|
|
278
|
+
return /* @__PURE__ */ jsx4("div", { className: baseClass, onMouseDown: handleMouseDown });
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// src/SortIndicator.tsx
|
|
282
|
+
import cx3 from "classnames";
|
|
283
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
284
|
+
var classBase2 = "vuuSortIndicator";
|
|
285
|
+
var SortIndicator = ({ sorted }) => {
|
|
286
|
+
if (!sorted) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
const direction = typeof sorted === "number" ? sorted < 0 ? "dsc" : "asc" : sorted === "A" ? "asc" : "dsc";
|
|
290
|
+
return typeof sorted === "number" ? /* @__PURE__ */ jsxs3("div", { className: cx3(classBase2, "multi-col", direction), children: [
|
|
291
|
+
/* @__PURE__ */ jsx5("span", { "data-icon": `sorted-${direction}` }),
|
|
292
|
+
/* @__PURE__ */ jsx5("span", { className: "vuuSortPosition", children: Math.abs(sorted) })
|
|
293
|
+
] }) : /* @__PURE__ */ jsx5("div", { className: cx3(classBase2, "single-col"), children: /* @__PURE__ */ jsx5("span", { "data-icon": `sorted-${direction}` }) });
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/useTableColumnResize.tsx
|
|
297
|
+
import { useCallback as useCallback5, useRef as useRef3 } from "react";
|
|
298
|
+
var useTableColumnResize = ({
|
|
299
|
+
column,
|
|
300
|
+
onResize,
|
|
301
|
+
rootRef
|
|
302
|
+
}) => {
|
|
303
|
+
const widthRef = useRef3(0);
|
|
304
|
+
const isResizing = useRef3(false);
|
|
305
|
+
const { name } = column;
|
|
306
|
+
const handleResizeStart = useCallback5(() => {
|
|
307
|
+
if (onResize && rootRef.current) {
|
|
308
|
+
const { width } = rootRef.current.getBoundingClientRect();
|
|
309
|
+
widthRef.current = Math.round(width);
|
|
310
|
+
isResizing.current = true;
|
|
311
|
+
onResize == null ? void 0 : onResize("begin", name);
|
|
312
|
+
}
|
|
313
|
+
}, [name, onResize, rootRef]);
|
|
314
|
+
const handleResize = useCallback5(
|
|
315
|
+
(_evt, moveBy) => {
|
|
316
|
+
if (rootRef.current) {
|
|
317
|
+
if (onResize) {
|
|
318
|
+
const { width } = rootRef.current.getBoundingClientRect();
|
|
319
|
+
const newWidth = Math.round(width) + moveBy;
|
|
320
|
+
if (newWidth !== widthRef.current && newWidth > 0) {
|
|
321
|
+
onResize("resize", name, newWidth);
|
|
322
|
+
widthRef.current = newWidth;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
[name, onResize, rootRef]
|
|
328
|
+
);
|
|
329
|
+
const handleResizeEnd = useCallback5(() => {
|
|
330
|
+
if (onResize) {
|
|
331
|
+
onResize("end", name, widthRef.current);
|
|
332
|
+
setTimeout(() => {
|
|
333
|
+
isResizing.current = false;
|
|
334
|
+
}, 100);
|
|
335
|
+
}
|
|
336
|
+
}, [name, onResize]);
|
|
337
|
+
return {
|
|
338
|
+
isResizing: isResizing.current,
|
|
339
|
+
onDrag: handleResize,
|
|
340
|
+
onDragStart: handleResizeStart,
|
|
341
|
+
onDragEnd: handleResizeEnd
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/TableHeaderCell.tsx
|
|
346
|
+
import { useContextMenu as useContextMenu2 } from "@vuu-ui/vuu-popups";
|
|
347
|
+
|
|
348
|
+
// src/filter-indicator.tsx
|
|
349
|
+
import { useContextMenu } from "@vuu-ui/vuu-popups";
|
|
350
|
+
import cx4 from "classnames";
|
|
351
|
+
import { useCallback as useCallback6 } from "react";
|
|
352
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
353
|
+
var FilterIndicator = ({ column, filter }) => {
|
|
354
|
+
const showContextMenu = useContextMenu();
|
|
355
|
+
const handleClick = useCallback6(
|
|
356
|
+
(evt) => {
|
|
357
|
+
evt.stopPropagation();
|
|
358
|
+
showContextMenu(evt, "filter", { column, filter });
|
|
359
|
+
},
|
|
360
|
+
[column, filter, showContextMenu]
|
|
361
|
+
);
|
|
362
|
+
if (!column.filter) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
return /* @__PURE__ */ jsx6(
|
|
366
|
+
"div",
|
|
367
|
+
{
|
|
368
|
+
className: cx4("vuuFilterIndicator"),
|
|
369
|
+
"data-icon": "filter",
|
|
370
|
+
onClick: handleClick
|
|
371
|
+
}
|
|
372
|
+
);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// src/TableHeaderCell.tsx
|
|
376
|
+
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
377
|
+
var classBase3 = "vuuTable-headerCell";
|
|
378
|
+
var TableHeaderCell = ({
|
|
379
|
+
column,
|
|
380
|
+
className: classNameProp,
|
|
381
|
+
onClick,
|
|
382
|
+
onDragStart,
|
|
383
|
+
onResize,
|
|
384
|
+
...props
|
|
385
|
+
}) => {
|
|
386
|
+
const rootRef = useRef4(null);
|
|
387
|
+
const { isResizing, ...resizeProps } = useTableColumnResize({
|
|
388
|
+
column,
|
|
389
|
+
onResize,
|
|
390
|
+
rootRef
|
|
391
|
+
});
|
|
392
|
+
const showContextMenu = useContextMenu2();
|
|
393
|
+
const dragTimerRef = useRef4(null);
|
|
394
|
+
const handleContextMenu = (e) => {
|
|
395
|
+
showContextMenu(e, "header", { column });
|
|
396
|
+
};
|
|
397
|
+
const handleClick = useCallback7(
|
|
398
|
+
(evt) => !isResizing && (onClick == null ? void 0 : onClick(evt)),
|
|
399
|
+
[isResizing, onClick]
|
|
400
|
+
);
|
|
401
|
+
const handleMouseDown = useCallback7(
|
|
402
|
+
(evt) => {
|
|
403
|
+
dragTimerRef.current = window.setTimeout(() => {
|
|
404
|
+
onDragStart == null ? void 0 : onDragStart(evt);
|
|
405
|
+
dragTimerRef.current = null;
|
|
406
|
+
}, 250);
|
|
407
|
+
},
|
|
408
|
+
[onDragStart]
|
|
409
|
+
);
|
|
410
|
+
const handleMouseUp = useCallback7(() => {
|
|
411
|
+
if (dragTimerRef.current !== null) {
|
|
412
|
+
window.clearTimeout(dragTimerRef.current);
|
|
413
|
+
dragTimerRef.current = null;
|
|
414
|
+
}
|
|
415
|
+
}, []);
|
|
416
|
+
const className = cx5(classBase3, classNameProp, {
|
|
417
|
+
vuuPinFloating: column.pin === "floating",
|
|
418
|
+
vuuPinLeft: column.pin === "left",
|
|
419
|
+
vuuPinRight: column.pin === "right",
|
|
420
|
+
vuuEndPin: column.endPin,
|
|
421
|
+
[`${classBase3}-resizing`]: column.resizing,
|
|
422
|
+
[`${classBase3}-right`]: column.align === "right"
|
|
423
|
+
});
|
|
424
|
+
return /* @__PURE__ */ jsx7(
|
|
425
|
+
"th",
|
|
426
|
+
{
|
|
427
|
+
className,
|
|
428
|
+
...props,
|
|
429
|
+
onClick: handleClick,
|
|
430
|
+
onContextMenu: handleContextMenu,
|
|
431
|
+
onMouseDown: handleMouseDown,
|
|
432
|
+
onMouseUp: handleMouseUp,
|
|
433
|
+
ref: rootRef,
|
|
434
|
+
children: /* @__PURE__ */ jsxs4("div", { className: `${classBase3}-inner`, children: [
|
|
435
|
+
/* @__PURE__ */ jsx7(FilterIndicator, { column }),
|
|
436
|
+
/* @__PURE__ */ jsx7("div", { className: `${classBase3}-label`, children: column.label }),
|
|
437
|
+
/* @__PURE__ */ jsx7(SortIndicator, { sorted: column.sorted }),
|
|
438
|
+
column.resizeable !== false ? /* @__PURE__ */ jsx7(ColumnResizer, { ...resizeProps }) : null
|
|
439
|
+
] })
|
|
440
|
+
}
|
|
441
|
+
);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// src/ColumnBasedTable.tsx
|
|
445
|
+
import { Fragment, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
446
|
+
var classBase4 = "vuuTable";
|
|
447
|
+
var { RENDER_IDX } = metadataKeys4;
|
|
448
|
+
var ColumnBasedTable = ({
|
|
449
|
+
columns,
|
|
450
|
+
data,
|
|
451
|
+
headerHeight,
|
|
452
|
+
onHeaderCellDragEnd,
|
|
453
|
+
rowHeight
|
|
454
|
+
}) => {
|
|
455
|
+
const handleDragEnd = useCallback8(() => {
|
|
456
|
+
onHeaderCellDragEnd == null ? void 0 : onHeaderCellDragEnd();
|
|
457
|
+
}, [onHeaderCellDragEnd]);
|
|
458
|
+
console.log(`ColumnBasedTable render`);
|
|
459
|
+
return /* @__PURE__ */ jsx8(Fragment, { children: columns.map((column, i) => /* @__PURE__ */ jsx8(
|
|
460
|
+
"table",
|
|
461
|
+
{
|
|
462
|
+
className: cx6(`${classBase4}-table`, `${classBase4}-columnBased`, {
|
|
463
|
+
vuuPinLeft: column.pin === "left"
|
|
464
|
+
}),
|
|
465
|
+
"data-idx": i,
|
|
466
|
+
id: `col-${i}`,
|
|
467
|
+
style: {
|
|
468
|
+
width: column.width,
|
|
469
|
+
left: column.pinnedOffset,
|
|
470
|
+
"--vuuTableHeaderHeight": `${headerHeight}px`,
|
|
471
|
+
"--row-height": `${rowHeight}px`
|
|
472
|
+
},
|
|
473
|
+
children: /* @__PURE__ */ jsxs5("tbody", { children: [
|
|
474
|
+
/* @__PURE__ */ jsx8("tr", { children: /* @__PURE__ */ jsx8(
|
|
475
|
+
TableHeaderCell,
|
|
476
|
+
{
|
|
477
|
+
column,
|
|
478
|
+
"data-idx": i,
|
|
479
|
+
onDragEnd: handleDragEnd
|
|
480
|
+
},
|
|
481
|
+
i
|
|
482
|
+
) }, "header"),
|
|
483
|
+
data.map((row, j) => /* @__PURE__ */ jsx8(
|
|
484
|
+
TableRow,
|
|
485
|
+
{
|
|
486
|
+
columns: [column],
|
|
487
|
+
height: rowHeight,
|
|
488
|
+
index: j,
|
|
489
|
+
row
|
|
490
|
+
},
|
|
491
|
+
row[RENDER_IDX]
|
|
492
|
+
)),
|
|
493
|
+
/* @__PURE__ */ jsx8("tr", { className: "vuuTable-filler" })
|
|
494
|
+
] })
|
|
495
|
+
},
|
|
496
|
+
column.name
|
|
497
|
+
)) });
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// src/context-menu/buildContextMenuDescriptors.ts
|
|
501
|
+
import { isNumericColumn } from "@vuu-ui/vuu-utils";
|
|
502
|
+
var buildContextMenuDescriptors = (dataSource) => (location, options) => {
|
|
503
|
+
const descriptors = [];
|
|
504
|
+
if (dataSource === void 0) {
|
|
505
|
+
return descriptors;
|
|
506
|
+
}
|
|
507
|
+
if (location === "header") {
|
|
508
|
+
descriptors.push(
|
|
509
|
+
...buildSortMenuItems(options, dataSource)
|
|
510
|
+
);
|
|
511
|
+
descriptors.push(
|
|
512
|
+
...buildGroupMenuItems(options, dataSource)
|
|
513
|
+
);
|
|
514
|
+
descriptors.push(
|
|
515
|
+
...buildAggregationMenuItems(options, dataSource)
|
|
516
|
+
);
|
|
517
|
+
descriptors.push(...buildColumnDisplayMenuItems(options));
|
|
518
|
+
} else if (location === "filter") {
|
|
519
|
+
const { column, filter } = options;
|
|
520
|
+
const colIsOnlyFilter = (filter == null ? void 0 : filter.column) === (column == null ? void 0 : column.name);
|
|
521
|
+
descriptors.push({
|
|
522
|
+
label: "Edit filter",
|
|
523
|
+
action: "filter-edit",
|
|
524
|
+
options
|
|
525
|
+
});
|
|
526
|
+
descriptors.push({
|
|
527
|
+
label: "Remove filter",
|
|
528
|
+
action: "filter-remove-column",
|
|
529
|
+
options
|
|
530
|
+
});
|
|
531
|
+
if (column && !colIsOnlyFilter) {
|
|
532
|
+
descriptors.push({
|
|
533
|
+
label: `Remove all filters`,
|
|
534
|
+
action: "remove-filters",
|
|
535
|
+
options
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return descriptors;
|
|
540
|
+
};
|
|
541
|
+
function buildSortMenuItems(options, { sort: { sortDefs } }) {
|
|
542
|
+
const { column } = options;
|
|
543
|
+
const menuItems = [];
|
|
544
|
+
if (column === void 0) {
|
|
545
|
+
return menuItems;
|
|
546
|
+
}
|
|
547
|
+
const hasSort = sortDefs.length > 0;
|
|
548
|
+
if (column.sorted === "A") {
|
|
549
|
+
menuItems.push({
|
|
550
|
+
label: "Reverse Sort (DSC)",
|
|
551
|
+
action: "sort-dsc",
|
|
552
|
+
options
|
|
553
|
+
});
|
|
554
|
+
} else if (column.sorted === "D") {
|
|
555
|
+
menuItems.push({
|
|
556
|
+
label: "Reverse Sort (ASC)",
|
|
557
|
+
action: "sort-asc",
|
|
558
|
+
options
|
|
559
|
+
});
|
|
560
|
+
} else if (typeof column.sorted === "number") {
|
|
561
|
+
if (column.sorted > 0) {
|
|
562
|
+
menuItems.push({
|
|
563
|
+
label: "Reverse Sort (DSC)",
|
|
564
|
+
action: "sort-add-dsc",
|
|
565
|
+
options
|
|
566
|
+
});
|
|
567
|
+
} else {
|
|
568
|
+
menuItems.push({
|
|
569
|
+
label: "Reverse Sort (ASC)",
|
|
570
|
+
action: "sort-add-asc",
|
|
571
|
+
options
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
|
|
575
|
+
menuItems.push({
|
|
576
|
+
label: "Remove from sort",
|
|
577
|
+
action: "sort-remove",
|
|
578
|
+
options
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
menuItems.push({
|
|
582
|
+
label: "New Sort",
|
|
583
|
+
children: [
|
|
584
|
+
{ label: "Ascending", action: "sort-asc", options },
|
|
585
|
+
{ label: "Descending", action: "sort-dsc", options }
|
|
586
|
+
]
|
|
587
|
+
});
|
|
588
|
+
} else if (hasSort) {
|
|
589
|
+
menuItems.push({
|
|
590
|
+
label: "Add to sort",
|
|
591
|
+
children: [
|
|
592
|
+
{ label: "Ascending", action: "sort-add-asc", options },
|
|
593
|
+
{ label: "Descending", action: "sort-add-dsc", options }
|
|
594
|
+
]
|
|
595
|
+
});
|
|
596
|
+
menuItems.push({
|
|
597
|
+
label: "New Sort",
|
|
598
|
+
children: [
|
|
599
|
+
{ label: "Ascending", action: "sort-asc", options },
|
|
600
|
+
{ label: "Descending", action: "sort-dsc", options }
|
|
601
|
+
]
|
|
602
|
+
});
|
|
603
|
+
} else {
|
|
604
|
+
menuItems.push({
|
|
605
|
+
label: "Sort",
|
|
606
|
+
children: [
|
|
607
|
+
{ label: "Ascending", action: "sort-asc", options },
|
|
608
|
+
{ label: "Descending", action: "sort-dsc", options }
|
|
609
|
+
]
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
return menuItems;
|
|
613
|
+
}
|
|
614
|
+
function buildAggregationMenuItems(options, dataSource) {
|
|
615
|
+
const { column } = options;
|
|
616
|
+
if (column === void 0 || dataSource.groupBy.length === 0) {
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
const { name, label = name } = column;
|
|
620
|
+
return [
|
|
621
|
+
{
|
|
622
|
+
label: `Aggregate ${label}`,
|
|
623
|
+
children: [{ label: "Count", action: "agg-count", options }].concat(
|
|
624
|
+
isNumericColumn(column) ? [
|
|
625
|
+
{ label: "Sum", action: "agg-sum", options },
|
|
626
|
+
{ label: "Avg", action: "agg-avg", options },
|
|
627
|
+
{ label: "High", action: "agg-high", options },
|
|
628
|
+
{ label: "Low", action: "agg-low", options }
|
|
629
|
+
] : []
|
|
630
|
+
)
|
|
631
|
+
}
|
|
632
|
+
];
|
|
633
|
+
}
|
|
634
|
+
var pinColumn = (options, pinLocation) => ({
|
|
635
|
+
label: `Pin ${pinLocation}`,
|
|
636
|
+
action: `column-pin-${pinLocation}`,
|
|
637
|
+
options
|
|
638
|
+
});
|
|
639
|
+
var pinLeft = (options) => pinColumn(options, "left");
|
|
640
|
+
var pinFloating = (options) => pinColumn(options, "floating");
|
|
641
|
+
var pinRight = (options) => pinColumn(options, "right");
|
|
642
|
+
function buildColumnDisplayMenuItems(options) {
|
|
643
|
+
const { column } = options;
|
|
644
|
+
if (column === void 0) {
|
|
645
|
+
return [];
|
|
646
|
+
}
|
|
647
|
+
const { pin } = column;
|
|
648
|
+
const menuItems = [
|
|
649
|
+
{
|
|
650
|
+
label: `Hide column`,
|
|
651
|
+
action: "column-hide",
|
|
652
|
+
options
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
label: `Remove column`,
|
|
656
|
+
action: "column-remove",
|
|
657
|
+
options
|
|
658
|
+
}
|
|
659
|
+
];
|
|
660
|
+
if (pin === void 0) {
|
|
661
|
+
menuItems.push({
|
|
662
|
+
label: `Pin column`,
|
|
663
|
+
children: [pinLeft(options), pinFloating(options), pinRight(options)]
|
|
664
|
+
});
|
|
665
|
+
} else if (pin === "left") {
|
|
666
|
+
menuItems.push(
|
|
667
|
+
{ label: "Unpin column", action: "column-unpin", options },
|
|
668
|
+
{
|
|
669
|
+
label: `Pin column`,
|
|
670
|
+
children: [pinFloating(options), pinRight(options)]
|
|
671
|
+
}
|
|
672
|
+
);
|
|
673
|
+
} else if (pin === "right") {
|
|
674
|
+
menuItems.push(
|
|
675
|
+
{ label: "Unpin column", action: "column-unpin", options },
|
|
676
|
+
{
|
|
677
|
+
label: `Pin column`,
|
|
678
|
+
children: [pinLeft(options), pinFloating(options)]
|
|
679
|
+
}
|
|
680
|
+
);
|
|
681
|
+
} else if (pin === "floating") {
|
|
682
|
+
menuItems.push(
|
|
683
|
+
{ label: "Unpin column", action: "column-unpin", options },
|
|
684
|
+
{
|
|
685
|
+
label: `Pin column`,
|
|
686
|
+
children: [pinLeft(options), pinRight(options)]
|
|
687
|
+
}
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
return menuItems;
|
|
691
|
+
}
|
|
692
|
+
function buildGroupMenuItems(options, { groupBy }) {
|
|
693
|
+
const { column } = options;
|
|
694
|
+
const menuItems = [];
|
|
695
|
+
if (column === void 0) {
|
|
696
|
+
return menuItems;
|
|
697
|
+
}
|
|
698
|
+
const { name, label = name } = column;
|
|
699
|
+
if (groupBy.length === 0) {
|
|
700
|
+
menuItems.push({
|
|
701
|
+
label: `Group by ${label}`,
|
|
702
|
+
action: "group",
|
|
703
|
+
options
|
|
704
|
+
});
|
|
705
|
+
} else {
|
|
706
|
+
menuItems.push({
|
|
707
|
+
label: `Add ${label} to group by`,
|
|
708
|
+
action: "group-add",
|
|
709
|
+
options
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
return menuItems;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// src/context-menu/useContextMenu.ts
|
|
716
|
+
import { removeColumnFromFilter } from "@vuu-ui/vuu-filters";
|
|
717
|
+
import {
|
|
718
|
+
addGroupColumn,
|
|
719
|
+
addSortColumn,
|
|
720
|
+
AggregationType,
|
|
721
|
+
setAggregations,
|
|
722
|
+
setSortColumn
|
|
723
|
+
} from "@vuu-ui/vuu-utils";
|
|
724
|
+
var removeFilterColumn = (dataSourceFilter, column) => {
|
|
725
|
+
if (dataSourceFilter.filterStruct && column) {
|
|
726
|
+
const [filterStruct, filter] = removeColumnFromFilter(
|
|
727
|
+
column,
|
|
728
|
+
dataSourceFilter.filterStruct
|
|
729
|
+
);
|
|
730
|
+
return {
|
|
731
|
+
filter,
|
|
732
|
+
filterStruct
|
|
733
|
+
};
|
|
734
|
+
} else {
|
|
735
|
+
return dataSourceFilter;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
var { Average, Count, High, Low, Sum } = AggregationType;
|
|
739
|
+
var useContextMenu3 = ({
|
|
740
|
+
dataSource,
|
|
741
|
+
onPersistentColumnOperation
|
|
742
|
+
}) => {
|
|
743
|
+
const handleContextMenuAction = (type, options) => {
|
|
744
|
+
const gridOptions = options;
|
|
745
|
+
if (gridOptions.column && dataSource) {
|
|
746
|
+
const { column } = gridOptions;
|
|
747
|
+
switch (type) {
|
|
748
|
+
case "sort-asc":
|
|
749
|
+
return dataSource.sort = setSortColumn(dataSource.sort, column, "A"), true;
|
|
750
|
+
case "sort-dsc":
|
|
751
|
+
return dataSource.sort = setSortColumn(dataSource.sort, column, "D"), true;
|
|
752
|
+
case "sort-add-asc":
|
|
753
|
+
return dataSource.sort = addSortColumn(dataSource.sort, column, "A"), true;
|
|
754
|
+
case "sort-add-dsc":
|
|
755
|
+
return dataSource.sort = addSortColumn(dataSource.sort, column, "D"), true;
|
|
756
|
+
case "group":
|
|
757
|
+
return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
|
|
758
|
+
case "group-add":
|
|
759
|
+
return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
|
|
760
|
+
case "column-hide":
|
|
761
|
+
return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
|
|
762
|
+
case "column-remove":
|
|
763
|
+
return dataSource.columns = dataSource.columns.filter((name) => name !== column.name), true;
|
|
764
|
+
case "filter-remove-column":
|
|
765
|
+
return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
|
|
766
|
+
case "remove-filters":
|
|
767
|
+
return dataSource.filter = { filter: "" }, true;
|
|
768
|
+
case "agg-avg":
|
|
769
|
+
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Average), true;
|
|
770
|
+
case "agg-high":
|
|
771
|
+
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, High), true;
|
|
772
|
+
case "agg-low":
|
|
773
|
+
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Low), true;
|
|
774
|
+
case "agg-count":
|
|
775
|
+
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Count), true;
|
|
776
|
+
case "agg-sum":
|
|
777
|
+
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Sum), true;
|
|
778
|
+
case "column-pin-floating":
|
|
779
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
|
|
780
|
+
case "column-pin-left":
|
|
781
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
|
|
782
|
+
case "column-pin-right":
|
|
783
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
|
|
784
|
+
case "column-unpin":
|
|
785
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
|
|
786
|
+
default:
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
return false;
|
|
790
|
+
};
|
|
791
|
+
return handleContextMenuAction;
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
// src/RowBasedTable.tsx
|
|
795
|
+
import {
|
|
796
|
+
getColumnPinStyle as getColumnPinStyle2,
|
|
797
|
+
isGroupColumn as isGroupColumn2,
|
|
798
|
+
metadataKeys as metadataKeys5,
|
|
799
|
+
notHidden as notHidden2,
|
|
800
|
+
visibleColumnAtIndex
|
|
801
|
+
} from "@vuu-ui/vuu-utils";
|
|
802
|
+
import { useCallback as useCallback9, useMemo } from "react";
|
|
803
|
+
|
|
804
|
+
// src/TableGroupHeaderCell.tsx
|
|
805
|
+
import cx7 from "classnames";
|
|
806
|
+
import { useRef as useRef5 } from "react";
|
|
807
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
808
|
+
var classBase5 = "vuuTable-groupHeaderCell";
|
|
809
|
+
var ColHeader = (props) => {
|
|
810
|
+
const { column, className, onRemoveColumn } = props;
|
|
811
|
+
return /* @__PURE__ */ jsxs6("div", { className: cx7(`${classBase5}-col`, className), role: "columnheader", children: [
|
|
812
|
+
/* @__PURE__ */ jsx9("span", { className: `${classBase5}-label`, children: column.name }),
|
|
813
|
+
/* @__PURE__ */ jsx9(
|
|
814
|
+
"span",
|
|
815
|
+
{
|
|
816
|
+
className: `${classBase5}-close`,
|
|
817
|
+
"data-icon": "close-circle",
|
|
818
|
+
onClick: () => onRemoveColumn == null ? void 0 : onRemoveColumn(column)
|
|
819
|
+
}
|
|
820
|
+
)
|
|
821
|
+
] });
|
|
822
|
+
};
|
|
823
|
+
var TableGroupHeaderCell = ({
|
|
824
|
+
column: groupColumn,
|
|
825
|
+
className: classNameProp,
|
|
826
|
+
onRemoveColumn,
|
|
827
|
+
onResize,
|
|
828
|
+
...props
|
|
829
|
+
}) => {
|
|
830
|
+
const rootRef = useRef5(null);
|
|
831
|
+
const { isResizing, ...resizeProps } = useTableColumnResize({
|
|
832
|
+
column: groupColumn,
|
|
833
|
+
onResize,
|
|
834
|
+
rootRef
|
|
835
|
+
});
|
|
836
|
+
const className = cx7(classBase5, classNameProp, {
|
|
837
|
+
vuuPinLeft: groupColumn.pin === "left",
|
|
838
|
+
[`${classBase5}-right`]: groupColumn.align === "right",
|
|
839
|
+
[`${classBase5}-resizing`]: groupColumn.resizing,
|
|
840
|
+
[`${classBase5}-pending`]: groupColumn.groupConfirmed === false
|
|
841
|
+
});
|
|
842
|
+
const { columns } = groupColumn;
|
|
843
|
+
return /* @__PURE__ */ jsx9("th", { className, ref: rootRef, ...props, children: /* @__PURE__ */ jsxs6("div", { className: `${classBase5}-inner`, children: [
|
|
844
|
+
columns.map((column) => /* @__PURE__ */ jsx9(
|
|
845
|
+
ColHeader,
|
|
846
|
+
{
|
|
847
|
+
column,
|
|
848
|
+
onRemoveColumn
|
|
849
|
+
},
|
|
850
|
+
column.key
|
|
851
|
+
)),
|
|
852
|
+
groupColumn.resizeable !== false ? /* @__PURE__ */ jsx9(ColumnResizer, { ...resizeProps }) : null
|
|
853
|
+
] }) });
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/RowBasedTable.tsx
|
|
857
|
+
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
858
|
+
var classBase6 = "vuuTable";
|
|
859
|
+
var { RENDER_IDX: RENDER_IDX2 } = metadataKeys5;
|
|
860
|
+
var RowBasedTable = ({
|
|
861
|
+
columns,
|
|
862
|
+
columnsWithinViewport,
|
|
863
|
+
data,
|
|
864
|
+
headings,
|
|
865
|
+
onColumnResize,
|
|
866
|
+
onHeaderCellDragStart,
|
|
867
|
+
onContextMenu,
|
|
868
|
+
onRemoveColumnFromGroupBy,
|
|
869
|
+
onRowClick,
|
|
870
|
+
onSort,
|
|
871
|
+
onToggleGroup,
|
|
872
|
+
virtualColSpan = 0,
|
|
873
|
+
rowCount,
|
|
874
|
+
rowHeight
|
|
875
|
+
}) => {
|
|
876
|
+
const handleDragStart = useCallback9(
|
|
877
|
+
(evt) => {
|
|
878
|
+
onHeaderCellDragStart == null ? void 0 : onHeaderCellDragStart(evt);
|
|
879
|
+
},
|
|
880
|
+
[onHeaderCellDragStart]
|
|
881
|
+
);
|
|
882
|
+
const visibleColumns = useMemo(() => {
|
|
883
|
+
return columns.filter(notHidden2);
|
|
884
|
+
}, [columns]);
|
|
885
|
+
const handleHeaderClick = useCallback9(
|
|
886
|
+
(evt) => {
|
|
887
|
+
var _a;
|
|
888
|
+
const targetElement = evt.target;
|
|
889
|
+
const headerCell = targetElement.closest(
|
|
890
|
+
".vuuTable-headerCell"
|
|
891
|
+
);
|
|
892
|
+
const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.idx) != null ? _a : "-1");
|
|
893
|
+
const column = visibleColumnAtIndex(columns, colIdx);
|
|
894
|
+
const isAdditive = evt.shiftKey;
|
|
895
|
+
column && onSort(column, isAdditive);
|
|
896
|
+
},
|
|
897
|
+
[columns, onSort]
|
|
898
|
+
);
|
|
899
|
+
return /* @__PURE__ */ jsxs7("table", { "aria-rowcount": rowCount, className: `${classBase6}-table`, children: [
|
|
900
|
+
/* @__PURE__ */ jsx10("colgroup", { children: visibleColumns.map((column, i) => /* @__PURE__ */ jsx10("col", { width: `${column.width}px` }, i)) }),
|
|
901
|
+
/* @__PURE__ */ jsxs7("thead", { children: [
|
|
902
|
+
headings.map((colHeaders, i) => /* @__PURE__ */ jsx10("tr", { className: "vuuTable-heading", children: colHeaders.map(({ label, span }, j) => /* @__PURE__ */ jsx10("th", { colSpan: span, className: "vuuTable-headingCell", children: label }, j)) }, i)),
|
|
903
|
+
/* @__PURE__ */ jsx10("tr", { children: visibleColumns.map((column, i) => {
|
|
904
|
+
const style = getColumnPinStyle2(column);
|
|
905
|
+
return isGroupColumn2(column) ? /* @__PURE__ */ jsx10(
|
|
906
|
+
TableGroupHeaderCell,
|
|
907
|
+
{
|
|
908
|
+
column,
|
|
909
|
+
"data-idx": i,
|
|
910
|
+
onRemoveColumn: onRemoveColumnFromGroupBy,
|
|
911
|
+
onResize: onColumnResize,
|
|
912
|
+
style
|
|
913
|
+
},
|
|
914
|
+
i
|
|
915
|
+
) : /* @__PURE__ */ jsx10(
|
|
916
|
+
TableHeaderCell,
|
|
917
|
+
{
|
|
918
|
+
column,
|
|
919
|
+
"data-idx": i,
|
|
920
|
+
onClick: handleHeaderClick,
|
|
921
|
+
onDragStart: handleDragStart,
|
|
922
|
+
onResize: onColumnResize,
|
|
923
|
+
style
|
|
924
|
+
},
|
|
925
|
+
i
|
|
926
|
+
);
|
|
927
|
+
}) })
|
|
928
|
+
] }),
|
|
929
|
+
/* @__PURE__ */ jsxs7("tbody", { onContextMenu, children: [
|
|
930
|
+
data == null ? void 0 : data.map((row, i) => /* @__PURE__ */ jsx10(
|
|
931
|
+
TableRow,
|
|
932
|
+
{
|
|
933
|
+
columns: columnsWithinViewport,
|
|
934
|
+
height: rowHeight,
|
|
935
|
+
index: i,
|
|
936
|
+
onClick: onRowClick,
|
|
937
|
+
virtualColSpan,
|
|
938
|
+
onToggleGroup,
|
|
939
|
+
row
|
|
940
|
+
},
|
|
941
|
+
row[RENDER_IDX2]
|
|
942
|
+
)),
|
|
943
|
+
/* @__PURE__ */ jsx10("tr", { className: `${classBase6}-filler` })
|
|
944
|
+
] })
|
|
945
|
+
] });
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
// src/useDataTable.ts
|
|
949
|
+
import { useContextMenu as usePopupContextMenu } from "@vuu-ui/vuu-popups";
|
|
950
|
+
import {
|
|
951
|
+
applySort,
|
|
952
|
+
buildColumnMap,
|
|
953
|
+
isJsonGroup as isJsonGroup2,
|
|
954
|
+
metadataKeys as metadataKeys9,
|
|
955
|
+
moveItem as moveItem2
|
|
956
|
+
} from "@vuu-ui/vuu-utils";
|
|
957
|
+
import {
|
|
958
|
+
useCallback as useCallback18,
|
|
959
|
+
useEffect as useEffect5,
|
|
960
|
+
useMemo as useMemo6,
|
|
961
|
+
useRef as useRef14,
|
|
962
|
+
useState as useState6
|
|
963
|
+
} from "react";
|
|
964
|
+
|
|
965
|
+
// src/useDataSource.ts
|
|
966
|
+
import {
|
|
967
|
+
isVuuFeatureAction,
|
|
968
|
+
isVuuFeatureInvocation
|
|
969
|
+
} from "@vuu-ui/vuu-data";
|
|
970
|
+
import { getFullRange, metadataKeys as metadataKeys6, WindowRange } from "@vuu-ui/vuu-utils";
|
|
971
|
+
import { useCallback as useCallback10, useEffect, useMemo as useMemo2, useRef as useRef6, useState as useState2 } from "react";
|
|
972
|
+
var { SELECTED: SELECTED2 } = metadataKeys6;
|
|
973
|
+
function useDataSource({
|
|
974
|
+
dataSource,
|
|
975
|
+
onConfigChange,
|
|
976
|
+
onFeatureEnabled,
|
|
977
|
+
onFeatureInvocation,
|
|
978
|
+
onSizeChange,
|
|
979
|
+
onSubscribed,
|
|
980
|
+
range = { from: 0, to: 0 },
|
|
981
|
+
renderBufferSize = 0,
|
|
982
|
+
viewportRowCount
|
|
983
|
+
}) {
|
|
984
|
+
const [, forceUpdate] = useState2(null);
|
|
985
|
+
const isMounted = useRef6(true);
|
|
986
|
+
const hasUpdated = useRef6(false);
|
|
987
|
+
const rangeRef = useRef6({ from: 0, to: 0 });
|
|
988
|
+
const rafHandle = useRef6(null);
|
|
989
|
+
const data = useRef6([]);
|
|
990
|
+
const dataWindow = useMemo2(
|
|
991
|
+
() => new MovingWindow(getFullRange(range)),
|
|
992
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
993
|
+
[]
|
|
994
|
+
);
|
|
995
|
+
const setData = useCallback10(
|
|
996
|
+
(updates) => {
|
|
997
|
+
for (const row of updates) {
|
|
998
|
+
dataWindow.add(row);
|
|
999
|
+
}
|
|
1000
|
+
data.current = dataWindow.data;
|
|
1001
|
+
hasUpdated.current = true;
|
|
1002
|
+
},
|
|
1003
|
+
[dataWindow]
|
|
1004
|
+
);
|
|
1005
|
+
const datasourceMessageHandler = useCallback10(
|
|
1006
|
+
(message) => {
|
|
1007
|
+
if (message.type === "subscribed") {
|
|
1008
|
+
onSubscribed == null ? void 0 : onSubscribed(message);
|
|
1009
|
+
} else if (message.type === "viewport-update") {
|
|
1010
|
+
if (typeof message.size === "number") {
|
|
1011
|
+
onSizeChange == null ? void 0 : onSizeChange(message.size);
|
|
1012
|
+
dataWindow.setRowCount(message.size);
|
|
1013
|
+
}
|
|
1014
|
+
if (message.rows) {
|
|
1015
|
+
setData(message.rows);
|
|
1016
|
+
} else if (typeof message.size === "number") {
|
|
1017
|
+
data.current = dataWindow.data;
|
|
1018
|
+
hasUpdated.current = true;
|
|
1019
|
+
}
|
|
1020
|
+
} else if (isVuuFeatureAction(message)) {
|
|
1021
|
+
onFeatureEnabled == null ? void 0 : onFeatureEnabled(message);
|
|
1022
|
+
} else if (isVuuFeatureInvocation(message)) {
|
|
1023
|
+
onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
|
|
1024
|
+
} else {
|
|
1025
|
+
console.log(`useDataSource unexpected message ${message.type}`);
|
|
1026
|
+
}
|
|
1027
|
+
},
|
|
1028
|
+
[
|
|
1029
|
+
dataWindow,
|
|
1030
|
+
onFeatureEnabled,
|
|
1031
|
+
onFeatureInvocation,
|
|
1032
|
+
onSizeChange,
|
|
1033
|
+
onSubscribed,
|
|
1034
|
+
setData
|
|
1035
|
+
]
|
|
1036
|
+
);
|
|
1037
|
+
useEffect(
|
|
1038
|
+
() => () => {
|
|
1039
|
+
if (rafHandle.current) {
|
|
1040
|
+
cancelAnimationFrame(rafHandle.current);
|
|
1041
|
+
rafHandle.current = null;
|
|
1042
|
+
}
|
|
1043
|
+
isMounted.current = false;
|
|
1044
|
+
},
|
|
1045
|
+
[]
|
|
1046
|
+
);
|
|
1047
|
+
const refreshIfUpdated = useCallback10(() => {
|
|
1048
|
+
if (isMounted.current) {
|
|
1049
|
+
if (hasUpdated.current) {
|
|
1050
|
+
forceUpdate({});
|
|
1051
|
+
hasUpdated.current = false;
|
|
1052
|
+
}
|
|
1053
|
+
rafHandle.current = requestAnimationFrame(refreshIfUpdated);
|
|
1054
|
+
}
|
|
1055
|
+
}, [forceUpdate]);
|
|
1056
|
+
useEffect(() => {
|
|
1057
|
+
rafHandle.current = requestAnimationFrame(refreshIfUpdated);
|
|
1058
|
+
}, [refreshIfUpdated]);
|
|
1059
|
+
const adjustRange = useCallback10(
|
|
1060
|
+
(rowCount) => {
|
|
1061
|
+
const { from } = dataSource.range;
|
|
1062
|
+
const rowRange = { from, to: from + rowCount };
|
|
1063
|
+
const fullRange = getFullRange(rowRange, renderBufferSize);
|
|
1064
|
+
dataSource.range = rangeRef.current = fullRange;
|
|
1065
|
+
dataSource.emit("range", rowRange);
|
|
1066
|
+
dataWindow.setRange(fullRange);
|
|
1067
|
+
},
|
|
1068
|
+
[dataSource, dataWindow, renderBufferSize]
|
|
1069
|
+
);
|
|
1070
|
+
const setRange = useCallback10(
|
|
1071
|
+
(range2) => {
|
|
1072
|
+
const fullRange = getFullRange(range2, renderBufferSize);
|
|
1073
|
+
dataSource.range = rangeRef.current = fullRange;
|
|
1074
|
+
dataWindow.setRange(fullRange);
|
|
1075
|
+
dataSource.emit("range", range2);
|
|
1076
|
+
},
|
|
1077
|
+
[dataSource, dataWindow, renderBufferSize]
|
|
1078
|
+
);
|
|
1079
|
+
const getSelectedRows = useCallback10(() => {
|
|
1080
|
+
return dataWindow.getSelectedRows();
|
|
1081
|
+
}, [dataWindow]);
|
|
1082
|
+
useEffect(() => {
|
|
1083
|
+
dataSource == null ? void 0 : dataSource.subscribe(
|
|
1084
|
+
{
|
|
1085
|
+
range: rangeRef.current
|
|
1086
|
+
},
|
|
1087
|
+
datasourceMessageHandler
|
|
1088
|
+
);
|
|
1089
|
+
}, [dataSource, datasourceMessageHandler, onConfigChange]);
|
|
1090
|
+
useEffect(() => {
|
|
1091
|
+
adjustRange(viewportRowCount);
|
|
1092
|
+
}, [adjustRange, viewportRowCount]);
|
|
1093
|
+
return {
|
|
1094
|
+
data: data.current,
|
|
1095
|
+
getSelectedRows,
|
|
1096
|
+
range: rangeRef.current,
|
|
1097
|
+
setRange,
|
|
1098
|
+
dataSource
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
var MovingWindow = class {
|
|
1102
|
+
constructor({ from, to }) {
|
|
1103
|
+
this.rowCount = 0;
|
|
1104
|
+
this.setRowCount = (rowCount) => {
|
|
1105
|
+
if (rowCount < this.data.length) {
|
|
1106
|
+
this.data.length = rowCount;
|
|
1107
|
+
}
|
|
1108
|
+
this.rowCount = rowCount;
|
|
1109
|
+
};
|
|
1110
|
+
this.range = new WindowRange(from, to);
|
|
1111
|
+
this.data = new Array(to - from);
|
|
1112
|
+
this.rowCount = 0;
|
|
1113
|
+
}
|
|
1114
|
+
add(data) {
|
|
1115
|
+
var _a;
|
|
1116
|
+
const [index] = data;
|
|
1117
|
+
if (this.isWithinRange(index)) {
|
|
1118
|
+
const internalIndex = index - this.range.from;
|
|
1119
|
+
this.data[internalIndex] = data;
|
|
1120
|
+
const isSelected = data[SELECTED2];
|
|
1121
|
+
const preSelected = (_a = this.data[internalIndex - 1]) == null ? void 0 : _a[SELECTED2];
|
|
1122
|
+
if (preSelected === 0 && isSelected) {
|
|
1123
|
+
this.data[internalIndex - 1][SELECTED2] = 2;
|
|
1124
|
+
} else if (preSelected === 2 && !isSelected) {
|
|
1125
|
+
this.data[internalIndex - 1][SELECTED2] = 0;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
getAtIndex(index) {
|
|
1130
|
+
return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
|
|
1131
|
+
}
|
|
1132
|
+
isWithinRange(index) {
|
|
1133
|
+
return this.range.isWithin(index);
|
|
1134
|
+
}
|
|
1135
|
+
setRange({ from, to }) {
|
|
1136
|
+
if (from !== this.range.from || to !== this.range.to) {
|
|
1137
|
+
const [overlapFrom, overlapTo] = this.range.overlap(from, to);
|
|
1138
|
+
const newData = new Array(to - from);
|
|
1139
|
+
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
1140
|
+
const data = this.getAtIndex(i);
|
|
1141
|
+
if (data) {
|
|
1142
|
+
const index = i - from;
|
|
1143
|
+
newData[index] = data;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
this.data = newData;
|
|
1147
|
+
this.range.from = from;
|
|
1148
|
+
this.range.to = to;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
getSelectedRows() {
|
|
1152
|
+
return this.data.filter((row) => row[SELECTED2] === 1);
|
|
1153
|
+
}
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
// src/useDraggableColumn.ts
|
|
1157
|
+
import { useDragDrop } from "@heswell/salt-lab";
|
|
1158
|
+
import {
|
|
1159
|
+
useCallback as useCallback11,
|
|
1160
|
+
useLayoutEffect,
|
|
1161
|
+
useRef as useRef7,
|
|
1162
|
+
useState as useState3
|
|
1163
|
+
} from "react";
|
|
1164
|
+
var useDraggableColumn = ({
|
|
1165
|
+
onDrop,
|
|
1166
|
+
tableContainerRef,
|
|
1167
|
+
tableLayout: tableLayoutProp
|
|
1168
|
+
}) => {
|
|
1169
|
+
const [tableLayout, setTableLayout] = useState3(tableLayoutProp);
|
|
1170
|
+
const mousePosRef = useRef7();
|
|
1171
|
+
const handleDropSettle = useCallback11(() => {
|
|
1172
|
+
console.log(`handleDropSettle`);
|
|
1173
|
+
mousePosRef.current = void 0;
|
|
1174
|
+
setTableLayout("row");
|
|
1175
|
+
}, []);
|
|
1176
|
+
const { draggable, draggedItemIndex, onMouseDown } = useDragDrop({
|
|
1177
|
+
allowDragDrop: true,
|
|
1178
|
+
draggableClassName: "table-column",
|
|
1179
|
+
orientation: "horizontal",
|
|
1180
|
+
containerRef: tableContainerRef,
|
|
1181
|
+
itemQuery: ".vuuTable-table",
|
|
1182
|
+
onDrop,
|
|
1183
|
+
onDropSettle: handleDropSettle
|
|
1184
|
+
});
|
|
1185
|
+
const handleHeaderCellDragStart = useCallback11((evt) => {
|
|
1186
|
+
const { clientX, clientY } = evt;
|
|
1187
|
+
console.log(
|
|
1188
|
+
`useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable`
|
|
1189
|
+
);
|
|
1190
|
+
const sourceElement = evt.target;
|
|
1191
|
+
const thElement = sourceElement.closest(".vuuTable-headerCell");
|
|
1192
|
+
const {
|
|
1193
|
+
dataset: { idx = "-1" }
|
|
1194
|
+
} = thElement;
|
|
1195
|
+
mousePosRef.current = {
|
|
1196
|
+
clientX,
|
|
1197
|
+
clientY,
|
|
1198
|
+
idx
|
|
1199
|
+
};
|
|
1200
|
+
setTableLayout("column");
|
|
1201
|
+
}, []);
|
|
1202
|
+
useLayoutEffect(() => {
|
|
1203
|
+
var _a;
|
|
1204
|
+
if (tableLayout === "column" && mousePosRef.current && !draggable) {
|
|
1205
|
+
const { clientX, clientY, idx } = mousePosRef.current;
|
|
1206
|
+
const target = (_a = tableContainerRef.current) == null ? void 0 : _a.querySelector(
|
|
1207
|
+
`.vuuTable-table[data-idx="${idx}"]`
|
|
1208
|
+
);
|
|
1209
|
+
if (target) {
|
|
1210
|
+
const evt = {
|
|
1211
|
+
persist: () => void 0,
|
|
1212
|
+
nativeEvent: {
|
|
1213
|
+
clientX,
|
|
1214
|
+
clientY,
|
|
1215
|
+
target
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
onMouseDown == null ? void 0 : onMouseDown(evt);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}, [draggable, onMouseDown, tableContainerRef, tableLayout]);
|
|
1222
|
+
return {
|
|
1223
|
+
draggable,
|
|
1224
|
+
draggedItemIndex,
|
|
1225
|
+
tableLayout,
|
|
1226
|
+
onHeaderCellDragStart: tableLayout === "row" ? handleHeaderCellDragStart : void 0
|
|
1227
|
+
};
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
// src/useKeyboardNavigation.ts
|
|
1231
|
+
import { withinRange } from "@vuu-ui/vuu-utils";
|
|
1232
|
+
import {
|
|
1233
|
+
useCallback as useCallback12,
|
|
1234
|
+
useEffect as useEffect2,
|
|
1235
|
+
useLayoutEffect as useLayoutEffect2,
|
|
1236
|
+
useMemo as useMemo3,
|
|
1237
|
+
useRef as useRef8
|
|
1238
|
+
} from "react";
|
|
1239
|
+
|
|
1240
|
+
// src/keyUtils.ts
|
|
1241
|
+
function union(set1, ...sets) {
|
|
1242
|
+
const result = new Set(set1);
|
|
1243
|
+
for (let set of sets) {
|
|
1244
|
+
for (let element of set) {
|
|
1245
|
+
result.add(element);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return result;
|
|
1249
|
+
}
|
|
1250
|
+
var ArrowUp = "ArrowUp";
|
|
1251
|
+
var ArrowDown = "ArrowDown";
|
|
1252
|
+
var ArrowLeft = "ArrowLeft";
|
|
1253
|
+
var ArrowRight = "ArrowRight";
|
|
1254
|
+
var Home = "Home";
|
|
1255
|
+
var End = "End";
|
|
1256
|
+
var PageUp = "PageUp";
|
|
1257
|
+
var PageDown = "PageDown";
|
|
1258
|
+
var actionKeys = /* @__PURE__ */ new Set(["Enter", "Delete", " "]);
|
|
1259
|
+
var focusKeys = /* @__PURE__ */ new Set(["Tab"]);
|
|
1260
|
+
var arrowLeftRightKeys = /* @__PURE__ */ new Set(["ArrowRight", "ArrowLeft"]);
|
|
1261
|
+
var navigationKeys = /* @__PURE__ */ new Set([
|
|
1262
|
+
Home,
|
|
1263
|
+
End,
|
|
1264
|
+
PageUp,
|
|
1265
|
+
PageDown,
|
|
1266
|
+
ArrowDown,
|
|
1267
|
+
ArrowLeft,
|
|
1268
|
+
ArrowRight,
|
|
1269
|
+
ArrowUp
|
|
1270
|
+
]);
|
|
1271
|
+
var functionKeys = /* @__PURE__ */ new Set([
|
|
1272
|
+
"F1",
|
|
1273
|
+
"F2",
|
|
1274
|
+
"F3",
|
|
1275
|
+
"F4",
|
|
1276
|
+
"F5",
|
|
1277
|
+
"F6",
|
|
1278
|
+
"F7",
|
|
1279
|
+
"F8",
|
|
1280
|
+
"F9",
|
|
1281
|
+
"F10",
|
|
1282
|
+
"F11",
|
|
1283
|
+
"F12"
|
|
1284
|
+
]);
|
|
1285
|
+
var specialKeys = union(
|
|
1286
|
+
actionKeys,
|
|
1287
|
+
navigationKeys,
|
|
1288
|
+
arrowLeftRightKeys,
|
|
1289
|
+
functionKeys,
|
|
1290
|
+
focusKeys
|
|
1291
|
+
);
|
|
1292
|
+
var PageKeys = ["Home", "End", "PageUp", "PageDown"];
|
|
1293
|
+
var isPagingKey = (key) => PageKeys.includes(key);
|
|
1294
|
+
var isNavigationKey = (key) => {
|
|
1295
|
+
return navigationKeys.has(key);
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
// src/useKeyboardNavigation.ts
|
|
1299
|
+
var headerCellQuery = (colIdx) => `thead th:nth-child(${colIdx + 1})`;
|
|
1300
|
+
var dataCellQuery = (rowIdx, colIdx) => `tbody > tr[aria-rowindex='${rowIdx}'] > td:nth-child(${colIdx + 1})`;
|
|
1301
|
+
var NULL_CELL_POS = [-1, -1];
|
|
1302
|
+
function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
|
|
1303
|
+
if (key === ArrowUp) {
|
|
1304
|
+
if (rowIdx > -1) {
|
|
1305
|
+
return [rowIdx - 1, colIdx];
|
|
1306
|
+
} else {
|
|
1307
|
+
return [rowIdx, colIdx];
|
|
1308
|
+
}
|
|
1309
|
+
} else if (key === ArrowDown) {
|
|
1310
|
+
if (rowIdx === -1) {
|
|
1311
|
+
return [0, colIdx];
|
|
1312
|
+
} else if (rowIdx === rowCount - 1) {
|
|
1313
|
+
return [rowIdx, colIdx];
|
|
1314
|
+
} else {
|
|
1315
|
+
return [rowIdx + 1, colIdx];
|
|
1316
|
+
}
|
|
1317
|
+
} else if (key === ArrowRight) {
|
|
1318
|
+
if (colIdx < columnCount - 1) {
|
|
1319
|
+
return [rowIdx, colIdx + 1];
|
|
1320
|
+
} else {
|
|
1321
|
+
return [rowIdx, colIdx];
|
|
1322
|
+
}
|
|
1323
|
+
} else if (key === ArrowLeft) {
|
|
1324
|
+
if (colIdx > 0) {
|
|
1325
|
+
return [rowIdx, colIdx - 1];
|
|
1326
|
+
} else {
|
|
1327
|
+
return [rowIdx, colIdx];
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return [rowIdx, colIdx];
|
|
1331
|
+
}
|
|
1332
|
+
var useKeyboardNavigation = ({
|
|
1333
|
+
columnCount = 0,
|
|
1334
|
+
containerRef,
|
|
1335
|
+
disableHighlightOnFocus,
|
|
1336
|
+
data,
|
|
1337
|
+
requestScroll,
|
|
1338
|
+
rowCount = 0,
|
|
1339
|
+
viewportRange
|
|
1340
|
+
}) => {
|
|
1341
|
+
var _a;
|
|
1342
|
+
const { from: viewportFirstRow, to: viewportLastRow } = viewportRange;
|
|
1343
|
+
const focusedCellPos = useRef8([-1, -1]);
|
|
1344
|
+
const focusableCell = useRef8();
|
|
1345
|
+
const activeCellPos = useRef8([-1, 0]);
|
|
1346
|
+
const getTableCell = useCallback12(
|
|
1347
|
+
([rowIdx, colIdx]) => {
|
|
1348
|
+
var _a2;
|
|
1349
|
+
const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
|
|
1350
|
+
return (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
|
|
1351
|
+
cssQuery
|
|
1352
|
+
);
|
|
1353
|
+
},
|
|
1354
|
+
[containerRef]
|
|
1355
|
+
);
|
|
1356
|
+
const getFocusedCell = (element) => element == null ? void 0 : element.closest("th,td");
|
|
1357
|
+
const getTableCellPos = (tableCell) => {
|
|
1358
|
+
var _a2, _b;
|
|
1359
|
+
if (tableCell.tagName === "TH") {
|
|
1360
|
+
const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
|
|
1361
|
+
return [-1, colIdx];
|
|
1362
|
+
} else {
|
|
1363
|
+
const focusedRow = tableCell.closest("tr");
|
|
1364
|
+
if (focusedRow) {
|
|
1365
|
+
const rowIdx = parseInt((_b = focusedRow.ariaRowIndex) != null ? _b : "-1", 10);
|
|
1366
|
+
const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
|
|
1367
|
+
return [rowIdx, colIdx];
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
return NULL_CELL_POS;
|
|
1371
|
+
};
|
|
1372
|
+
const focusCell = useCallback12(
|
|
1373
|
+
(cellPos) => {
|
|
1374
|
+
var _a2;
|
|
1375
|
+
if (containerRef.current) {
|
|
1376
|
+
const activeCell = getTableCell(cellPos);
|
|
1377
|
+
if (activeCell) {
|
|
1378
|
+
if (activeCell !== focusableCell.current) {
|
|
1379
|
+
(_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
|
|
1380
|
+
focusableCell.current = activeCell;
|
|
1381
|
+
activeCell.setAttribute("tabindex", "0");
|
|
1382
|
+
}
|
|
1383
|
+
activeCell.focus();
|
|
1384
|
+
} else if (!withinRange(cellPos[0], viewportRange)) {
|
|
1385
|
+
focusableCell.current = void 0;
|
|
1386
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
},
|
|
1390
|
+
// TODO we recreate this function whenever viewportRange changes, which will
|
|
1391
|
+
// be often whilst scrolling - store range in a a ref ?
|
|
1392
|
+
[containerRef, getTableCell, requestScroll, viewportRange]
|
|
1393
|
+
);
|
|
1394
|
+
const setActiveCell = useCallback12(
|
|
1395
|
+
(rowIdx, colIdx, fromKeyboard = false) => {
|
|
1396
|
+
const pos = [rowIdx, colIdx];
|
|
1397
|
+
activeCellPos.current = pos;
|
|
1398
|
+
focusCell(pos);
|
|
1399
|
+
if (fromKeyboard) {
|
|
1400
|
+
focusedCellPos.current = pos;
|
|
1401
|
+
}
|
|
1402
|
+
},
|
|
1403
|
+
[focusCell]
|
|
1404
|
+
);
|
|
1405
|
+
const virtualizeActiveCell = useCallback12(() => {
|
|
1406
|
+
var _a2;
|
|
1407
|
+
(_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
|
|
1408
|
+
focusableCell.current = void 0;
|
|
1409
|
+
}, []);
|
|
1410
|
+
const nextPageItemIdx = useCallback12(
|
|
1411
|
+
async (key, cellPos) => {
|
|
1412
|
+
switch (key) {
|
|
1413
|
+
case PageDown:
|
|
1414
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
|
|
1415
|
+
break;
|
|
1416
|
+
case PageUp:
|
|
1417
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
|
|
1418
|
+
break;
|
|
1419
|
+
case Home:
|
|
1420
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
|
|
1421
|
+
break;
|
|
1422
|
+
case End:
|
|
1423
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
|
|
1424
|
+
break;
|
|
1425
|
+
}
|
|
1426
|
+
return cellPos;
|
|
1427
|
+
},
|
|
1428
|
+
[requestScroll]
|
|
1429
|
+
);
|
|
1430
|
+
const handleFocus = useCallback12(() => {
|
|
1431
|
+
var _a2;
|
|
1432
|
+
if (disableHighlightOnFocus !== true) {
|
|
1433
|
+
if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
|
|
1434
|
+
const focusedCell = getFocusedCell(document.activeElement);
|
|
1435
|
+
if (focusedCell) {
|
|
1436
|
+
focusedCellPos.current = getTableCellPos(focusedCell);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}, [disableHighlightOnFocus, containerRef]);
|
|
1441
|
+
const navigateChildItems = useCallback12(
|
|
1442
|
+
async (key) => {
|
|
1443
|
+
const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
|
|
1444
|
+
const [rowIdx, colIdx] = activeCellPos.current;
|
|
1445
|
+
if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
|
|
1446
|
+
setActiveCell(nextRowIdx, nextColIdx, true);
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
[columnCount, nextPageItemIdx, rowCount, setActiveCell]
|
|
1450
|
+
);
|
|
1451
|
+
const handleKeyDown = useCallback12(
|
|
1452
|
+
(e) => {
|
|
1453
|
+
if (data.length > 0 && isNavigationKey(e.key)) {
|
|
1454
|
+
e.preventDefault();
|
|
1455
|
+
e.stopPropagation();
|
|
1456
|
+
void navigateChildItems(e.key);
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
[data, navigateChildItems]
|
|
1460
|
+
);
|
|
1461
|
+
const handleClick = useCallback12(
|
|
1462
|
+
// Might not be a cell e.g the Settings button
|
|
1463
|
+
(evt) => {
|
|
1464
|
+
const target = evt.target;
|
|
1465
|
+
const focusedCell = getFocusedCell(target);
|
|
1466
|
+
if (focusedCell) {
|
|
1467
|
+
const [rowIdx, colIdx] = getTableCellPos(focusedCell);
|
|
1468
|
+
setActiveCell(rowIdx, colIdx);
|
|
1469
|
+
}
|
|
1470
|
+
},
|
|
1471
|
+
[setActiveCell]
|
|
1472
|
+
);
|
|
1473
|
+
const containerProps = useMemo3(() => {
|
|
1474
|
+
return {
|
|
1475
|
+
onClick: handleClick,
|
|
1476
|
+
onFocus: handleFocus,
|
|
1477
|
+
onKeyDown: handleKeyDown
|
|
1478
|
+
};
|
|
1479
|
+
}, [handleClick, handleFocus, handleKeyDown]);
|
|
1480
|
+
useLayoutEffect2(() => {
|
|
1481
|
+
const { current: cellPos } = activeCellPos;
|
|
1482
|
+
const withinViewport = cellPos[0] >= viewportFirstRow && cellPos[0] <= viewportLastRow;
|
|
1483
|
+
if (focusableCell.current && !withinViewport) {
|
|
1484
|
+
virtualizeActiveCell();
|
|
1485
|
+
} else if (!focusableCell.current && withinViewport) {
|
|
1486
|
+
focusCell(cellPos);
|
|
1487
|
+
}
|
|
1488
|
+
}, [focusCell, viewportFirstRow, viewportLastRow, virtualizeActiveCell]);
|
|
1489
|
+
const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
|
|
1490
|
+
useEffect2(() => {
|
|
1491
|
+
var _a2;
|
|
1492
|
+
if (fullyRendered && focusableCell.current === void 0) {
|
|
1493
|
+
const headerCell = (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
|
|
1494
|
+
headerCellQuery(0)
|
|
1495
|
+
);
|
|
1496
|
+
if (headerCell) {
|
|
1497
|
+
headerCell.setAttribute("tabindex", "0");
|
|
1498
|
+
focusableCell.current = headerCell;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}, [containerRef, fullyRendered]);
|
|
1502
|
+
return containerProps;
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
// src/useMeasuredContainer.ts
|
|
1506
|
+
import { useCallback as useCallback14, useRef as useRef10, useState as useState4 } from "react";
|
|
1507
|
+
|
|
1508
|
+
// src/useResizeObserver.ts
|
|
1509
|
+
import { useCallback as useCallback13, useEffect as useEffect3, useRef as useRef9 } from "react";
|
|
1510
|
+
var observedMap = /* @__PURE__ */ new Map();
|
|
1511
|
+
var getTargetSize = (element, size, dimension) => {
|
|
1512
|
+
switch (dimension) {
|
|
1513
|
+
case "height":
|
|
1514
|
+
return size.height;
|
|
1515
|
+
case "clientHeight":
|
|
1516
|
+
return element.clientHeight;
|
|
1517
|
+
case "clientWidth":
|
|
1518
|
+
return element.clientWidth;
|
|
1519
|
+
case "contentHeight":
|
|
1520
|
+
return size.contentHeight;
|
|
1521
|
+
case "contentWidth":
|
|
1522
|
+
return size.contentWidth;
|
|
1523
|
+
case "scrollHeight":
|
|
1524
|
+
return Math.ceil(element.scrollHeight);
|
|
1525
|
+
case "scrollWidth":
|
|
1526
|
+
return Math.ceil(element.scrollWidth);
|
|
1527
|
+
case "width":
|
|
1528
|
+
return size.width;
|
|
1529
|
+
default:
|
|
1530
|
+
return 0;
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
var resizeObserver = new ResizeObserver((entries) => {
|
|
1534
|
+
for (const entry of entries) {
|
|
1535
|
+
const { target, borderBoxSize, contentBoxSize } = entry;
|
|
1536
|
+
const observedTarget = observedMap.get(target);
|
|
1537
|
+
if (observedTarget) {
|
|
1538
|
+
const [{ blockSize: height, inlineSize: width }] = borderBoxSize;
|
|
1539
|
+
const [{ blockSize: contentHeight, inlineSize: contentWidth }] = contentBoxSize;
|
|
1540
|
+
const { onResize, measurements } = observedTarget;
|
|
1541
|
+
let sizeChanged = false;
|
|
1542
|
+
for (const [dimension, size] of Object.entries(measurements)) {
|
|
1543
|
+
const newSize = getTargetSize(
|
|
1544
|
+
target,
|
|
1545
|
+
{ height, width, contentHeight, contentWidth },
|
|
1546
|
+
dimension
|
|
1547
|
+
);
|
|
1548
|
+
if (newSize !== size) {
|
|
1549
|
+
sizeChanged = true;
|
|
1550
|
+
measurements[dimension] = newSize;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
if (sizeChanged) {
|
|
1554
|
+
onResize && onResize(measurements);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false) {
|
|
1560
|
+
const dimensionsRef = useRef9(dimensions);
|
|
1561
|
+
const measure = useCallback13((target) => {
|
|
1562
|
+
const { width, height } = target.getBoundingClientRect();
|
|
1563
|
+
const { clientWidth: contentWidth, clientHeight: contentHeight } = target;
|
|
1564
|
+
return dimensionsRef.current.reduce(
|
|
1565
|
+
(map, dim) => {
|
|
1566
|
+
map[dim] = getTargetSize(
|
|
1567
|
+
target,
|
|
1568
|
+
{ width, height, contentHeight, contentWidth },
|
|
1569
|
+
dim
|
|
1570
|
+
);
|
|
1571
|
+
return map;
|
|
1572
|
+
},
|
|
1573
|
+
{}
|
|
1574
|
+
);
|
|
1575
|
+
}, []);
|
|
1576
|
+
useEffect3(() => {
|
|
1577
|
+
const target = ref.current;
|
|
1578
|
+
async function registerObserver() {
|
|
1579
|
+
observedMap.set(target, { measurements: {} });
|
|
1580
|
+
await document.fonts.ready;
|
|
1581
|
+
const observedTarget = observedMap.get(target);
|
|
1582
|
+
if (observedTarget) {
|
|
1583
|
+
const measurements = measure(target);
|
|
1584
|
+
observedTarget.measurements = measurements;
|
|
1585
|
+
resizeObserver.observe(target);
|
|
1586
|
+
if (reportInitialSize) {
|
|
1587
|
+
onResize(measurements);
|
|
1588
|
+
}
|
|
1589
|
+
} else {
|
|
1590
|
+
console.log(
|
|
1591
|
+
`%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,
|
|
1592
|
+
"font-weight:bold; color:red;"
|
|
1593
|
+
);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
if (target) {
|
|
1597
|
+
if (observedMap.has(target)) {
|
|
1598
|
+
throw Error(
|
|
1599
|
+
"useResizeObserver attemping to observe same element twice"
|
|
1600
|
+
);
|
|
1601
|
+
}
|
|
1602
|
+
registerObserver();
|
|
1603
|
+
}
|
|
1604
|
+
return () => {
|
|
1605
|
+
if (target && observedMap.has(target)) {
|
|
1606
|
+
resizeObserver.unobserve(target);
|
|
1607
|
+
observedMap.delete(target);
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
}, [measure, ref]);
|
|
1611
|
+
useEffect3(() => {
|
|
1612
|
+
const target = ref.current;
|
|
1613
|
+
const record = observedMap.get(target);
|
|
1614
|
+
if (record) {
|
|
1615
|
+
if (dimensionsRef.current !== dimensions) {
|
|
1616
|
+
dimensionsRef.current = dimensions;
|
|
1617
|
+
const measurements = measure(target);
|
|
1618
|
+
record.measurements = measurements;
|
|
1619
|
+
}
|
|
1620
|
+
record.onResize = onResize;
|
|
1621
|
+
}
|
|
1622
|
+
}, [dimensions, measure, ref, onResize]);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// src/useMeasuredContainer.ts
|
|
1626
|
+
var ClientWidthHeight = ["clientHeight", "clientWidth"];
|
|
1627
|
+
var isNumber = (val) => Number.isFinite(val);
|
|
1628
|
+
var useMeasuredContainer = ({
|
|
1629
|
+
defaultHeight = 0,
|
|
1630
|
+
defaultWidth = 0,
|
|
1631
|
+
height,
|
|
1632
|
+
width
|
|
1633
|
+
}) => {
|
|
1634
|
+
const containerRef = useRef10(null);
|
|
1635
|
+
const [size, setSize] = useState4({
|
|
1636
|
+
outer: {
|
|
1637
|
+
height: height != null ? height : "100%",
|
|
1638
|
+
width: width != null ? width : "100%"
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
const onResize = useCallback14(
|
|
1642
|
+
({ clientWidth, clientHeight }) => {
|
|
1643
|
+
setSize((currentSize) => {
|
|
1644
|
+
const { inner, outer } = currentSize;
|
|
1645
|
+
return isNumber(clientHeight) && isNumber(clientWidth) && (clientWidth !== (inner == null ? void 0 : inner.width) || clientHeight !== (inner == null ? void 0 : inner.height)) ? {
|
|
1646
|
+
outer,
|
|
1647
|
+
inner: {
|
|
1648
|
+
width: Math.floor(clientWidth) || defaultWidth,
|
|
1649
|
+
height: Math.floor(clientHeight) || defaultHeight
|
|
1650
|
+
}
|
|
1651
|
+
} : currentSize;
|
|
1652
|
+
});
|
|
1653
|
+
},
|
|
1654
|
+
[defaultHeight, defaultWidth]
|
|
1655
|
+
);
|
|
1656
|
+
useResizeObserver(containerRef, ClientWidthHeight, onResize, true);
|
|
1657
|
+
return {
|
|
1658
|
+
containerRef,
|
|
1659
|
+
outerSize: size.outer,
|
|
1660
|
+
innerSize: size.inner
|
|
1661
|
+
};
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
// src/useSelection.ts
|
|
1665
|
+
import { deselectItem, metadataKeys as metadataKeys7, selectItem } from "@vuu-ui/vuu-utils";
|
|
1666
|
+
import { useCallback as useCallback15, useRef as useRef11 } from "react";
|
|
1667
|
+
var { IDX: IDX2, SELECTED: SELECTED3 } = metadataKeys7;
|
|
1668
|
+
var NO_SELECTION = [];
|
|
1669
|
+
var useSelection = ({
|
|
1670
|
+
selectionModel,
|
|
1671
|
+
onSelectionChange
|
|
1672
|
+
}) => {
|
|
1673
|
+
selectionModel === "extended" || selectionModel === "checkbox";
|
|
1674
|
+
const lastActiveRef = useRef11(-1);
|
|
1675
|
+
const selectedRef = useRef11(NO_SELECTION);
|
|
1676
|
+
const handleSelectionChange = useCallback15(
|
|
1677
|
+
(row, rangeSelect, keepExistingSelection) => {
|
|
1678
|
+
const { [IDX2]: idx, [SELECTED3]: isSelected } = row;
|
|
1679
|
+
const { current: active } = lastActiveRef;
|
|
1680
|
+
const { current: selected } = selectedRef;
|
|
1681
|
+
const selectOperation = isSelected ? deselectItem : selectItem;
|
|
1682
|
+
const newSelected = selectOperation(
|
|
1683
|
+
selectionModel,
|
|
1684
|
+
selected,
|
|
1685
|
+
idx,
|
|
1686
|
+
rangeSelect,
|
|
1687
|
+
keepExistingSelection,
|
|
1688
|
+
active
|
|
1689
|
+
);
|
|
1690
|
+
selectedRef.current = newSelected;
|
|
1691
|
+
lastActiveRef.current = idx;
|
|
1692
|
+
if (onSelectionChange) {
|
|
1693
|
+
onSelectionChange(newSelected);
|
|
1694
|
+
}
|
|
1695
|
+
},
|
|
1696
|
+
[onSelectionChange, selectionModel]
|
|
1697
|
+
);
|
|
1698
|
+
return handleSelectionChange;
|
|
1699
|
+
};
|
|
1700
|
+
|
|
1701
|
+
// src/useTableModel.ts
|
|
1702
|
+
import { moveItem } from "@heswell/salt-lab";
|
|
1703
|
+
import {
|
|
1704
|
+
applyFilterToColumns,
|
|
1705
|
+
applyGroupByToColumns,
|
|
1706
|
+
applySortToColumns,
|
|
1707
|
+
findColumn,
|
|
1708
|
+
getCellRenderer,
|
|
1709
|
+
getColumnName,
|
|
1710
|
+
getTableHeadings,
|
|
1711
|
+
getValueFormatter,
|
|
1712
|
+
isFilteredColumn,
|
|
1713
|
+
isGroupColumn as isGroupColumn3,
|
|
1714
|
+
isPinned,
|
|
1715
|
+
isTypeDescriptor,
|
|
1716
|
+
logger,
|
|
1717
|
+
metadataKeys as metadataKeys8,
|
|
1718
|
+
sortPinnedColumns,
|
|
1719
|
+
stripFilterFromColumns
|
|
1720
|
+
} from "@vuu-ui/vuu-utils";
|
|
1721
|
+
import { useReducer } from "react";
|
|
1722
|
+
var { info } = logger("useTableModel");
|
|
1723
|
+
var DEFAULT_COLUMN_WIDTH = 100;
|
|
1724
|
+
var KEY_OFFSET = metadataKeys8.count;
|
|
1725
|
+
var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
|
|
1726
|
+
var getCellRendererForColumn = (column) => {
|
|
1727
|
+
var _a, _b;
|
|
1728
|
+
if (isTypeDescriptor(column.type)) {
|
|
1729
|
+
return getCellRenderer((_b = (_a = column.type) == null ? void 0 : _a.renderer) == null ? void 0 : _b.name);
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
var getDataType = (column, columnNames, dataTypes) => {
|
|
1733
|
+
var _a;
|
|
1734
|
+
const index = columnNames.indexOf(column.name);
|
|
1735
|
+
if (index !== -1 && dataTypes[index]) {
|
|
1736
|
+
return dataTypes[index];
|
|
1737
|
+
} else {
|
|
1738
|
+
return (_a = column.serverDataType) != null ? _a : "string";
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
var numericTypes = ["int", "long", "double"];
|
|
1742
|
+
var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
|
|
1743
|
+
var columnReducer = (state, action) => {
|
|
1744
|
+
info == null ? void 0 : info(`GridModelReducer ${action.type}`);
|
|
1745
|
+
switch (action.type) {
|
|
1746
|
+
case "init":
|
|
1747
|
+
return init(action);
|
|
1748
|
+
case "moveColumn":
|
|
1749
|
+
return moveColumn(state, action);
|
|
1750
|
+
case "resizeColumn":
|
|
1751
|
+
return resizeColumn(state, action);
|
|
1752
|
+
case "setTypes":
|
|
1753
|
+
return setTypes(state, action);
|
|
1754
|
+
case "hideColumns":
|
|
1755
|
+
return hideColumns(state, action);
|
|
1756
|
+
case "showColumns":
|
|
1757
|
+
return showColumns(state, action);
|
|
1758
|
+
case "pinColumn":
|
|
1759
|
+
return pinColumn2(state, action);
|
|
1760
|
+
case "updateColumnProp":
|
|
1761
|
+
return updateColumnProp(state, action);
|
|
1762
|
+
case "tableConfig":
|
|
1763
|
+
return updateTableConfig(state, action);
|
|
1764
|
+
default:
|
|
1765
|
+
console.log(`unhandled action ${action.type}`);
|
|
1766
|
+
return state;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
var useTableModel = (tableConfig, dataSourceConfig) => {
|
|
1770
|
+
const [state, dispatchColumnAction] = useReducer(columnReducer, { tableConfig, dataSourceConfig }, init);
|
|
1771
|
+
return {
|
|
1772
|
+
columns: state.columns,
|
|
1773
|
+
dispatchColumnAction,
|
|
1774
|
+
headings: state.headings
|
|
1775
|
+
};
|
|
1776
|
+
};
|
|
1777
|
+
function init({ dataSourceConfig, tableConfig }) {
|
|
1778
|
+
const columns = tableConfig.columns.map(
|
|
1779
|
+
toKeyedColumWithDefaults(tableConfig)
|
|
1780
|
+
);
|
|
1781
|
+
const maybePinnedColumns = columns.some(isPinned) ? sortPinnedColumns(columns) : columns;
|
|
1782
|
+
const state = {
|
|
1783
|
+
columns: maybePinnedColumns,
|
|
1784
|
+
headings: getTableHeadings(maybePinnedColumns)
|
|
1785
|
+
};
|
|
1786
|
+
if (dataSourceConfig) {
|
|
1787
|
+
const { columns: columns2, ...rest } = dataSourceConfig;
|
|
1788
|
+
return updateTableConfig(state, {
|
|
1789
|
+
type: "tableConfig",
|
|
1790
|
+
...rest
|
|
1791
|
+
});
|
|
1792
|
+
} else {
|
|
1793
|
+
return state;
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
var getLabel = (label, columnFormatHeader) => {
|
|
1797
|
+
if (columnFormatHeader === "uppercase") {
|
|
1798
|
+
return label.toUpperCase();
|
|
1799
|
+
} else if (columnFormatHeader === "capitalize") {
|
|
1800
|
+
return label[0].toUpperCase() + label.slice(1).toLowerCase();
|
|
1801
|
+
}
|
|
1802
|
+
return label;
|
|
1803
|
+
};
|
|
1804
|
+
var toKeyedColumWithDefaults = (options) => (column, index) => {
|
|
1805
|
+
const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = options;
|
|
1806
|
+
const {
|
|
1807
|
+
align = getDefaultAlignment(column.serverDataType),
|
|
1808
|
+
key,
|
|
1809
|
+
name,
|
|
1810
|
+
label = name,
|
|
1811
|
+
width = columnDefaultWidth,
|
|
1812
|
+
...rest
|
|
1813
|
+
} = column;
|
|
1814
|
+
const keyedColumnWithDefaults = {
|
|
1815
|
+
...rest,
|
|
1816
|
+
align,
|
|
1817
|
+
CellRenderer: getCellRendererForColumn(column),
|
|
1818
|
+
label: getLabel(label, columnFormatHeader),
|
|
1819
|
+
key: key != null ? key : index + KEY_OFFSET,
|
|
1820
|
+
name,
|
|
1821
|
+
originalIdx: index,
|
|
1822
|
+
valueFormatter: getValueFormatter(column),
|
|
1823
|
+
width
|
|
1824
|
+
};
|
|
1825
|
+
if (isGroupColumn3(keyedColumnWithDefaults)) {
|
|
1826
|
+
keyedColumnWithDefaults.columns = keyedColumnWithDefaults.columns.map(
|
|
1827
|
+
(col) => toKeyedColumWithDefaults(options)(col, col.key)
|
|
1828
|
+
);
|
|
1829
|
+
}
|
|
1830
|
+
return keyedColumnWithDefaults;
|
|
1831
|
+
};
|
|
1832
|
+
function moveColumn(state, { column, moveBy, moveTo }) {
|
|
1833
|
+
const { columns } = state;
|
|
1834
|
+
if (typeof moveBy === "number") {
|
|
1835
|
+
const idx = columns.indexOf(column);
|
|
1836
|
+
const newColumns = columns.slice();
|
|
1837
|
+
const [movedColumns] = newColumns.splice(idx, 1);
|
|
1838
|
+
newColumns.splice(idx + moveBy, 0, movedColumns);
|
|
1839
|
+
return {
|
|
1840
|
+
...state,
|
|
1841
|
+
columns: newColumns
|
|
1842
|
+
};
|
|
1843
|
+
} else if (typeof moveTo === "number") {
|
|
1844
|
+
const index = columns.indexOf(column);
|
|
1845
|
+
return {
|
|
1846
|
+
...state,
|
|
1847
|
+
columns: moveItem(columns, index, moveTo)
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
return state;
|
|
1851
|
+
}
|
|
1852
|
+
function hideColumns(state, { columns }) {
|
|
1853
|
+
if (columns.some((col) => col.hidden !== true)) {
|
|
1854
|
+
return columns.reduce((s, c) => {
|
|
1855
|
+
if (c.hidden !== true) {
|
|
1856
|
+
return updateColumnProp(s, {
|
|
1857
|
+
type: "updateColumnProp",
|
|
1858
|
+
column: c,
|
|
1859
|
+
hidden: true
|
|
1860
|
+
});
|
|
1861
|
+
} else {
|
|
1862
|
+
return s;
|
|
1863
|
+
}
|
|
1864
|
+
}, state);
|
|
1865
|
+
} else {
|
|
1866
|
+
return state;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
function showColumns(state, { columns }) {
|
|
1870
|
+
if (columns.some((col) => col.hidden)) {
|
|
1871
|
+
return columns.reduce((s, c) => {
|
|
1872
|
+
if (c.hidden) {
|
|
1873
|
+
return updateColumnProp(s, {
|
|
1874
|
+
type: "updateColumnProp",
|
|
1875
|
+
column: c,
|
|
1876
|
+
hidden: false
|
|
1877
|
+
});
|
|
1878
|
+
} else {
|
|
1879
|
+
return s;
|
|
1880
|
+
}
|
|
1881
|
+
}, state);
|
|
1882
|
+
} else {
|
|
1883
|
+
return state;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
function resizeColumn(state, { column, phase, width }) {
|
|
1887
|
+
const type = "updateColumnProp";
|
|
1888
|
+
const resizing = phase !== "end";
|
|
1889
|
+
switch (phase) {
|
|
1890
|
+
case "begin":
|
|
1891
|
+
case "end":
|
|
1892
|
+
return updateColumnProp(state, { type, column, resizing });
|
|
1893
|
+
case "resize":
|
|
1894
|
+
return updateColumnProp(state, { type, column, width });
|
|
1895
|
+
default:
|
|
1896
|
+
throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
function setTypes(state, { columnNames, serverDataTypes }) {
|
|
1900
|
+
const { columns } = state;
|
|
1901
|
+
if (columns.some(columnWithoutDataType)) {
|
|
1902
|
+
const cols = columns.map((column) => {
|
|
1903
|
+
var _a;
|
|
1904
|
+
const serverDataType = getDataType(column, columnNames, serverDataTypes);
|
|
1905
|
+
return {
|
|
1906
|
+
...column,
|
|
1907
|
+
align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
|
|
1908
|
+
serverDataType
|
|
1909
|
+
};
|
|
1910
|
+
});
|
|
1911
|
+
return {
|
|
1912
|
+
...state,
|
|
1913
|
+
columns: cols
|
|
1914
|
+
};
|
|
1915
|
+
} else {
|
|
1916
|
+
return state;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
function pinColumn2(state, action) {
|
|
1920
|
+
let { columns } = state;
|
|
1921
|
+
const { column, pin } = action;
|
|
1922
|
+
const targetColumn = columns.find((col) => col.name === column.name);
|
|
1923
|
+
if (targetColumn) {
|
|
1924
|
+
columns = replaceColumn(columns, { ...targetColumn, pin });
|
|
1925
|
+
columns = sortPinnedColumns(columns);
|
|
1926
|
+
return {
|
|
1927
|
+
...state,
|
|
1928
|
+
columns
|
|
1929
|
+
};
|
|
1930
|
+
} else {
|
|
1931
|
+
return state;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
function updateColumnProp(state, action) {
|
|
1935
|
+
let { columns } = state;
|
|
1936
|
+
const { align, column, hidden, label, resizing, width } = action;
|
|
1937
|
+
const targetColumn = columns.find((col) => col.name === column.name);
|
|
1938
|
+
if (targetColumn) {
|
|
1939
|
+
if (align === "left" || align === "right") {
|
|
1940
|
+
columns = replaceColumn(columns, { ...targetColumn, align });
|
|
1941
|
+
}
|
|
1942
|
+
if (typeof label === "string") {
|
|
1943
|
+
columns = replaceColumn(columns, { ...targetColumn, label });
|
|
1944
|
+
}
|
|
1945
|
+
if (typeof resizing === "boolean") {
|
|
1946
|
+
columns = replaceColumn(columns, { ...targetColumn, resizing });
|
|
1947
|
+
}
|
|
1948
|
+
if (typeof hidden === "boolean") {
|
|
1949
|
+
columns = replaceColumn(columns, { ...targetColumn, hidden });
|
|
1950
|
+
}
|
|
1951
|
+
if (typeof width === "number") {
|
|
1952
|
+
columns = replaceColumn(columns, { ...targetColumn, width });
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
return {
|
|
1956
|
+
...state,
|
|
1957
|
+
columns
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1960
|
+
function updateTableConfig(state, { columns, confirmed, filter, groupBy, sort }) {
|
|
1961
|
+
const hasColumns = columns && columns.length > 0;
|
|
1962
|
+
const hasGroupBy = groupBy !== void 0;
|
|
1963
|
+
const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
|
|
1964
|
+
const hasSort = sort && sort.sortDefs.length > 0;
|
|
1965
|
+
let result = state;
|
|
1966
|
+
if (hasColumns) {
|
|
1967
|
+
result = {
|
|
1968
|
+
...state,
|
|
1969
|
+
columns: columns.map((colName, index) => {
|
|
1970
|
+
const columnName = getColumnName(colName);
|
|
1971
|
+
const key = index + KEY_OFFSET;
|
|
1972
|
+
const col = findColumn(result.columns, columnName);
|
|
1973
|
+
if (col) {
|
|
1974
|
+
if (col.key === key) {
|
|
1975
|
+
return col;
|
|
1976
|
+
} else {
|
|
1977
|
+
return {
|
|
1978
|
+
...col,
|
|
1979
|
+
key
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
throw Error(`useTableModel column ${colName} not found`);
|
|
1984
|
+
})
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
if (hasGroupBy) {
|
|
1988
|
+
result = {
|
|
1989
|
+
...state,
|
|
1990
|
+
columns: applyGroupByToColumns(result.columns, groupBy, confirmed)
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
if (hasSort) {
|
|
1994
|
+
result = {
|
|
1995
|
+
...state,
|
|
1996
|
+
columns: applySortToColumns(result.columns, sort)
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
if (hasFilter) {
|
|
2000
|
+
result = {
|
|
2001
|
+
...state,
|
|
2002
|
+
columns: applyFilterToColumns(result.columns, filter)
|
|
2003
|
+
};
|
|
2004
|
+
} else if (result.columns.some(isFilteredColumn)) {
|
|
2005
|
+
result = {
|
|
2006
|
+
...state,
|
|
2007
|
+
columns: stripFilterFromColumns(result.columns)
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
return result;
|
|
2011
|
+
}
|
|
2012
|
+
function replaceColumn(state, column) {
|
|
2013
|
+
return state.map((col) => col.name === column.name ? column : col);
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
// src/useTableScroll.ts
|
|
2017
|
+
import { useCallback as useCallback16, useRef as useRef12 } from "react";
|
|
2018
|
+
var getPctScroll = (container) => {
|
|
2019
|
+
const { scrollLeft, scrollTop } = container;
|
|
2020
|
+
const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
|
|
2021
|
+
const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
|
|
2022
|
+
const pctScrollTop = scrollTop / (scrollHeight - clientHeight);
|
|
2023
|
+
return [pctScrollLeft, pctScrollTop, scrollLeft, scrollTop];
|
|
2024
|
+
};
|
|
2025
|
+
var getMaxScroll = (container) => {
|
|
2026
|
+
const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
|
|
2027
|
+
return [scrollWidth - clientWidth, scrollHeight - clientHeight];
|
|
2028
|
+
};
|
|
2029
|
+
var useTableScroll = ({
|
|
2030
|
+
onHorizontalScroll,
|
|
2031
|
+
onVerticalScroll,
|
|
2032
|
+
viewport
|
|
2033
|
+
}) => {
|
|
2034
|
+
const scrollPosRef = useRef12({ scrollTop: 0, scrollLeft: 0 });
|
|
2035
|
+
const scrollbarContainerRef = useRef12(null);
|
|
2036
|
+
const contentContainerRef = useRef12(null);
|
|
2037
|
+
const tableContainerRef = useRef12(null);
|
|
2038
|
+
const contentContainerScrolledRef = useRef12(false);
|
|
2039
|
+
const {
|
|
2040
|
+
maxScrollContainerScrollHorizontal: maxScrollLeft,
|
|
2041
|
+
maxScrollContainerScrollVertical: maxScrollTop
|
|
2042
|
+
} = viewport;
|
|
2043
|
+
const scrollTable = useCallback16(
|
|
2044
|
+
(scrollLeft, scrollTop) => {
|
|
2045
|
+
const { current: tableContainer } = tableContainerRef;
|
|
2046
|
+
if (tableContainer) {
|
|
2047
|
+
tableContainer.scrollTo({
|
|
2048
|
+
top: scrollTop,
|
|
2049
|
+
left: scrollLeft,
|
|
2050
|
+
behavior: "auto"
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
},
|
|
2054
|
+
[tableContainerRef]
|
|
2055
|
+
);
|
|
2056
|
+
const handleTableContainerScroll = useCallback16(() => {
|
|
2057
|
+
const { current: tableContainer } = tableContainerRef;
|
|
2058
|
+
if (tableContainer) {
|
|
2059
|
+
const { current: scrollPos } = scrollPosRef;
|
|
2060
|
+
const { scrollLeft, scrollTop } = tableContainer;
|
|
2061
|
+
if (scrollPos.scrollTop !== scrollTop) {
|
|
2062
|
+
scrollPos.scrollTop = scrollTop;
|
|
2063
|
+
onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop);
|
|
2064
|
+
}
|
|
2065
|
+
if (scrollPos.scrollLeft !== scrollLeft) {
|
|
2066
|
+
scrollPos.scrollLeft = scrollLeft;
|
|
2067
|
+
onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
}, [onHorizontalScroll, onVerticalScroll]);
|
|
2071
|
+
const handleContentContainerScroll = useCallback16(() => {
|
|
2072
|
+
const { current: rootContainer } = contentContainerRef;
|
|
2073
|
+
const { current: scrollContainer } = scrollbarContainerRef;
|
|
2074
|
+
if (rootContainer && scrollContainer) {
|
|
2075
|
+
const [pctScrollLeft, pctScrollTop, scrollLeft, scrollTop] = getPctScroll(rootContainer);
|
|
2076
|
+
contentContainerScrolledRef.current = true;
|
|
2077
|
+
scrollContainer.scrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
|
|
2078
|
+
scrollContainer.scrollTop = Math.round(pctScrollTop * maxScrollTop);
|
|
2079
|
+
scrollTable(scrollLeft, scrollTop);
|
|
2080
|
+
}
|
|
2081
|
+
}, [
|
|
2082
|
+
maxScrollLeft,
|
|
2083
|
+
maxScrollTop,
|
|
2084
|
+
contentContainerRef,
|
|
2085
|
+
scrollbarContainerRef,
|
|
2086
|
+
scrollTable
|
|
2087
|
+
]);
|
|
2088
|
+
const handleScrollbarContainerScroll = useCallback16(() => {
|
|
2089
|
+
const { current: contentContainer } = contentContainerRef;
|
|
2090
|
+
const { current: scrollbarContainer } = scrollbarContainerRef;
|
|
2091
|
+
const { current: contentContainerScrolled } = contentContainerScrolledRef;
|
|
2092
|
+
if (contentContainerScrolled) {
|
|
2093
|
+
contentContainerScrolledRef.current = false;
|
|
2094
|
+
} else if (contentContainer && scrollbarContainer) {
|
|
2095
|
+
const [pctScrollLeft, pctScrollTop] = getPctScroll(scrollbarContainer);
|
|
2096
|
+
const [maxScrollLeft2, maxScrollTop2] = getMaxScroll(contentContainer);
|
|
2097
|
+
const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft2);
|
|
2098
|
+
const rootScrollTop = Math.round(pctScrollTop * maxScrollTop2);
|
|
2099
|
+
contentContainer.scrollTo({
|
|
2100
|
+
left: rootScrollLeft,
|
|
2101
|
+
top: rootScrollTop,
|
|
2102
|
+
behavior: "auto"
|
|
2103
|
+
});
|
|
2104
|
+
scrollTable(rootScrollLeft, rootScrollTop);
|
|
2105
|
+
}
|
|
2106
|
+
}, [contentContainerRef, scrollbarContainerRef, scrollTable]);
|
|
2107
|
+
const requestScroll = useCallback16(
|
|
2108
|
+
(scrollRequest) => {
|
|
2109
|
+
const { current: scrollbarContainer } = scrollbarContainerRef;
|
|
2110
|
+
if (scrollbarContainer) {
|
|
2111
|
+
contentContainerScrolledRef.current = false;
|
|
2112
|
+
if (scrollRequest.type === "scroll-page") {
|
|
2113
|
+
const { clientHeight, scrollLeft, scrollTop } = scrollbarContainer;
|
|
2114
|
+
const { direction } = scrollRequest;
|
|
2115
|
+
const scrollBy = direction === "down" ? clientHeight : -clientHeight;
|
|
2116
|
+
const newScrollTop = Math.min(
|
|
2117
|
+
Math.max(0, scrollTop + scrollBy),
|
|
2118
|
+
viewport.maxScrollContainerScrollVertical
|
|
2119
|
+
);
|
|
2120
|
+
scrollbarContainer.scrollTo({
|
|
2121
|
+
top: newScrollTop,
|
|
2122
|
+
left: scrollLeft,
|
|
2123
|
+
behavior: "auto"
|
|
2124
|
+
});
|
|
2125
|
+
} else if (scrollRequest.type === "scroll-end") {
|
|
2126
|
+
const { direction } = scrollRequest;
|
|
2127
|
+
const scrollTo = direction === "end" ? viewport.maxScrollContainerScrollVertical : 0;
|
|
2128
|
+
scrollbarContainer.scrollTo({
|
|
2129
|
+
top: scrollTo,
|
|
2130
|
+
left: scrollbarContainer.scrollLeft,
|
|
2131
|
+
behavior: "auto"
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
},
|
|
2136
|
+
[viewport.maxScrollContainerScrollVertical]
|
|
2137
|
+
);
|
|
2138
|
+
return {
|
|
2139
|
+
/** Ref to be assigned to ScrollbarContainer */
|
|
2140
|
+
scrollbarContainerRef,
|
|
2141
|
+
/** Scroll handler to be attached to ScrollbarContainer */
|
|
2142
|
+
onScrollbarContainerScroll: handleScrollbarContainerScroll,
|
|
2143
|
+
/** Ref to be assigned to ContentContainer */
|
|
2144
|
+
contentContainerRef,
|
|
2145
|
+
/** Scroll handler to be attached to ContentContainer */
|
|
2146
|
+
onContentContainerScroll: handleContentContainerScroll,
|
|
2147
|
+
/** Ref to be assigned to TableContainer */
|
|
2148
|
+
tableContainerRef,
|
|
2149
|
+
/** Scroll handler to be attached to TableContainer */
|
|
2150
|
+
onTableContainerScroll: handleTableContainerScroll,
|
|
2151
|
+
/** Scroll the table */
|
|
2152
|
+
requestScroll
|
|
2153
|
+
};
|
|
2154
|
+
};
|
|
2155
|
+
|
|
2156
|
+
// src/useTableViewport.ts
|
|
2157
|
+
import { useMemo as useMemo4 } from "react";
|
|
2158
|
+
var UNMEASURED_VIEWPORT = {
|
|
2159
|
+
fillerHeight: 0,
|
|
2160
|
+
maxScrollContainerScrollHorizontal: 0,
|
|
2161
|
+
maxScrollContainerScrollVertical: 0,
|
|
2162
|
+
pinnedWidthLeft: 0,
|
|
2163
|
+
pinnedWidthRight: 0,
|
|
2164
|
+
rowCount: 0,
|
|
2165
|
+
scrollContentHeight: 0,
|
|
2166
|
+
scrollbarSize: 0,
|
|
2167
|
+
scrollContentWidth: 0,
|
|
2168
|
+
totalHeaderHeight: 0
|
|
2169
|
+
};
|
|
2170
|
+
var measurePinnedColumns = (columns) => {
|
|
2171
|
+
let pinnedWidthLeft = 0;
|
|
2172
|
+
let pinnedWidthRight = 0;
|
|
2173
|
+
let unpinnedWidth = 0;
|
|
2174
|
+
for (const column of columns) {
|
|
2175
|
+
const { hidden, pin, width } = column;
|
|
2176
|
+
const visibleWidth = hidden ? 0 : width;
|
|
2177
|
+
if (pin === "left") {
|
|
2178
|
+
pinnedWidthLeft += visibleWidth;
|
|
2179
|
+
} else if (pin === "right") {
|
|
2180
|
+
pinnedWidthRight += visibleWidth;
|
|
2181
|
+
} else {
|
|
2182
|
+
unpinnedWidth += visibleWidth;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
return { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth };
|
|
2186
|
+
};
|
|
2187
|
+
var useTableViewport = ({
|
|
2188
|
+
columns,
|
|
2189
|
+
headerHeight,
|
|
2190
|
+
headings,
|
|
2191
|
+
rowCount,
|
|
2192
|
+
rowHeight,
|
|
2193
|
+
size
|
|
2194
|
+
}) => {
|
|
2195
|
+
const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo4(
|
|
2196
|
+
() => measurePinnedColumns(columns),
|
|
2197
|
+
[columns]
|
|
2198
|
+
);
|
|
2199
|
+
const viewportMeasurements = useMemo4(() => {
|
|
2200
|
+
var _a;
|
|
2201
|
+
if (size) {
|
|
2202
|
+
const headingsDepth = headings.length;
|
|
2203
|
+
const scrollbarSize = 15;
|
|
2204
|
+
const contentHeight = rowCount * rowHeight;
|
|
2205
|
+
const scrollContentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
|
|
2206
|
+
const maxScrollContainerScrollVertical = contentHeight + headerHeight - (((_a = size == null ? void 0 : size.height) != null ? _a : 0) - headerHeight - scrollbarSize);
|
|
2207
|
+
const maxScrollContainerScrollHorizontal = scrollContentWidth - size.width + pinnedWidthLeft;
|
|
2208
|
+
const visibleRows = (size.height - headerHeight) / rowHeight;
|
|
2209
|
+
const count = Number.isInteger(visibleRows) ? visibleRows + 1 : Math.ceil(visibleRows);
|
|
2210
|
+
return {
|
|
2211
|
+
fillerHeight: (rowCount - count) * rowHeight,
|
|
2212
|
+
maxScrollContainerScrollHorizontal,
|
|
2213
|
+
maxScrollContainerScrollVertical,
|
|
2214
|
+
pinnedWidthLeft,
|
|
2215
|
+
pinnedWidthRight,
|
|
2216
|
+
rowCount: count,
|
|
2217
|
+
scrollContentHeight: headerHeight + contentHeight + scrollbarSize,
|
|
2218
|
+
scrollbarSize,
|
|
2219
|
+
scrollContentWidth,
|
|
2220
|
+
totalHeaderHeight: headerHeight * (1 + headingsDepth)
|
|
2221
|
+
};
|
|
2222
|
+
} else {
|
|
2223
|
+
return UNMEASURED_VIEWPORT;
|
|
2224
|
+
}
|
|
2225
|
+
}, [
|
|
2226
|
+
headerHeight,
|
|
2227
|
+
headings.length,
|
|
2228
|
+
pinnedWidthLeft,
|
|
2229
|
+
pinnedWidthRight,
|
|
2230
|
+
rowCount,
|
|
2231
|
+
rowHeight,
|
|
2232
|
+
size,
|
|
2233
|
+
unpinnedWidth
|
|
2234
|
+
]);
|
|
2235
|
+
return viewportMeasurements;
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
// src/useVirtualViewport.ts
|
|
2239
|
+
import { getColumnsInViewport, itemsChanged } from "@vuu-ui/vuu-utils";
|
|
2240
|
+
import { useCallback as useCallback17, useEffect as useEffect4, useMemo as useMemo5, useRef as useRef13, useState as useState5 } from "react";
|
|
2241
|
+
var useVirtualViewport = ({
|
|
2242
|
+
columns,
|
|
2243
|
+
rowHeight,
|
|
2244
|
+
setRange,
|
|
2245
|
+
viewportMeasurements
|
|
2246
|
+
}) => {
|
|
2247
|
+
const firstRowRef = useRef13(-1);
|
|
2248
|
+
const {
|
|
2249
|
+
rowCount: viewportRowCount,
|
|
2250
|
+
scrollContentWidth: contentWidth,
|
|
2251
|
+
maxScrollContainerScrollHorizontal
|
|
2252
|
+
} = viewportMeasurements;
|
|
2253
|
+
const availableWidth = contentWidth - maxScrollContainerScrollHorizontal;
|
|
2254
|
+
const scrollLeftRef = useRef13(0);
|
|
2255
|
+
const [visibleColumns, preSpan] = useMemo5(
|
|
2256
|
+
() => getColumnsInViewport(
|
|
2257
|
+
columns,
|
|
2258
|
+
scrollLeftRef.current,
|
|
2259
|
+
scrollLeftRef.current + availableWidth
|
|
2260
|
+
),
|
|
2261
|
+
[availableWidth, columns]
|
|
2262
|
+
);
|
|
2263
|
+
const preSpanRef = useRef13(preSpan);
|
|
2264
|
+
useEffect4(() => {
|
|
2265
|
+
setColumnsWithinViewport(visibleColumns);
|
|
2266
|
+
}, [visibleColumns]);
|
|
2267
|
+
const [columnsWithinViewport, setColumnsWithinViewport] = useState5(visibleColumns);
|
|
2268
|
+
const handleHorizontalScroll = useCallback17(
|
|
2269
|
+
(scrollLeft) => {
|
|
2270
|
+
scrollLeftRef.current = scrollLeft;
|
|
2271
|
+
const [visibleColumns2, pre] = getColumnsInViewport(
|
|
2272
|
+
columns,
|
|
2273
|
+
scrollLeft,
|
|
2274
|
+
scrollLeft + availableWidth
|
|
2275
|
+
);
|
|
2276
|
+
if (itemsChanged(columnsWithinViewport, visibleColumns2)) {
|
|
2277
|
+
preSpanRef.current = pre;
|
|
2278
|
+
setColumnsWithinViewport(visibleColumns2);
|
|
2279
|
+
}
|
|
2280
|
+
},
|
|
2281
|
+
[availableWidth, columns, columnsWithinViewport]
|
|
2282
|
+
);
|
|
2283
|
+
const handleVerticalScroll = useCallback17(
|
|
2284
|
+
(scrollTop) => {
|
|
2285
|
+
const firstRow = Math.floor(scrollTop / rowHeight);
|
|
2286
|
+
if (firstRow !== firstRowRef.current) {
|
|
2287
|
+
firstRowRef.current = firstRow;
|
|
2288
|
+
setRange({ from: firstRow, to: firstRow + viewportRowCount });
|
|
2289
|
+
}
|
|
2290
|
+
},
|
|
2291
|
+
[rowHeight, setRange, viewportRowCount]
|
|
2292
|
+
);
|
|
2293
|
+
return {
|
|
2294
|
+
columnsWithinViewport,
|
|
2295
|
+
onHorizontalScroll: handleHorizontalScroll,
|
|
2296
|
+
onVerticalScroll: handleVerticalScroll,
|
|
2297
|
+
/** number of leading columns not rendered because of virtualization */
|
|
2298
|
+
virtualColSpan: preSpanRef.current
|
|
2299
|
+
};
|
|
2300
|
+
};
|
|
2301
|
+
|
|
2302
|
+
// src/useDataTable.ts
|
|
2303
|
+
var NO_ROWS = [];
|
|
2304
|
+
var { KEY: KEY2, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = metadataKeys9;
|
|
2305
|
+
var useDataTable = ({
|
|
2306
|
+
config,
|
|
2307
|
+
dataSource,
|
|
2308
|
+
headerHeight,
|
|
2309
|
+
onConfigChange,
|
|
2310
|
+
onFeatureEnabled,
|
|
2311
|
+
onFeatureInvocation,
|
|
2312
|
+
onSelectionChange,
|
|
2313
|
+
renderBufferSize = 0,
|
|
2314
|
+
rowHeight,
|
|
2315
|
+
selectionModel,
|
|
2316
|
+
tableLayout,
|
|
2317
|
+
...measuredProps
|
|
2318
|
+
}) => {
|
|
2319
|
+
var _a, _b;
|
|
2320
|
+
const [rowCount, setRowCount] = useState6(0);
|
|
2321
|
+
const expectConfigChangeRef = useRef14(false);
|
|
2322
|
+
const dataSourceRef = useRef14();
|
|
2323
|
+
dataSourceRef.current = dataSource;
|
|
2324
|
+
if (dataSource === void 0) {
|
|
2325
|
+
throw Error("no data source provided to DataTable");
|
|
2326
|
+
}
|
|
2327
|
+
const containerMeasurements = useMeasuredContainer(measuredProps);
|
|
2328
|
+
const onDataRowcountChange = useCallback18((size) => {
|
|
2329
|
+
setRowCount(size);
|
|
2330
|
+
}, []);
|
|
2331
|
+
const { columns, dispatchColumnAction, headings } = useTableModel(
|
|
2332
|
+
config,
|
|
2333
|
+
dataSource.config
|
|
2334
|
+
);
|
|
2335
|
+
const handlePersistentColumnOperation = useCallback18(
|
|
2336
|
+
(action) => {
|
|
2337
|
+
expectConfigChangeRef.current = true;
|
|
2338
|
+
dispatchColumnAction(action);
|
|
2339
|
+
},
|
|
2340
|
+
[dispatchColumnAction]
|
|
2341
|
+
);
|
|
2342
|
+
const handleContextMenuAction = useContextMenu3({
|
|
2343
|
+
dataSource,
|
|
2344
|
+
onPersistentColumnOperation: handlePersistentColumnOperation
|
|
2345
|
+
});
|
|
2346
|
+
const viewportMeasurements = useTableViewport({
|
|
2347
|
+
columns,
|
|
2348
|
+
headerHeight,
|
|
2349
|
+
headings,
|
|
2350
|
+
rowCount,
|
|
2351
|
+
rowHeight,
|
|
2352
|
+
size: containerMeasurements.innerSize
|
|
2353
|
+
});
|
|
2354
|
+
const onSubscribed = useCallback18(
|
|
2355
|
+
(subscription) => {
|
|
2356
|
+
if (subscription.tableMeta) {
|
|
2357
|
+
const { columns: columnNames, dataTypes: serverDataTypes } = subscription.tableMeta;
|
|
2358
|
+
expectConfigChangeRef.current = true;
|
|
2359
|
+
dispatchColumnAction({
|
|
2360
|
+
type: "setTypes",
|
|
2361
|
+
columnNames,
|
|
2362
|
+
serverDataTypes
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
},
|
|
2366
|
+
[dispatchColumnAction]
|
|
2367
|
+
);
|
|
2368
|
+
const handleSelectionChange = useCallback18(
|
|
2369
|
+
(selected) => {
|
|
2370
|
+
dataSource.select(selected);
|
|
2371
|
+
onSelectionChange == null ? void 0 : onSelectionChange(selected);
|
|
2372
|
+
},
|
|
2373
|
+
[dataSource, onSelectionChange]
|
|
2374
|
+
);
|
|
2375
|
+
const handleRowClick = useSelection({
|
|
2376
|
+
onSelectionChange: handleSelectionChange,
|
|
2377
|
+
selectionModel
|
|
2378
|
+
});
|
|
2379
|
+
const { data, getSelectedRows, range, setRange } = useDataSource({
|
|
2380
|
+
dataSource,
|
|
2381
|
+
onFeatureEnabled,
|
|
2382
|
+
onFeatureInvocation,
|
|
2383
|
+
onSubscribed,
|
|
2384
|
+
onSizeChange: onDataRowcountChange,
|
|
2385
|
+
renderBufferSize,
|
|
2386
|
+
viewportRowCount: viewportMeasurements.rowCount
|
|
2387
|
+
});
|
|
2388
|
+
const dataRef = useRef14();
|
|
2389
|
+
dataRef.current = data;
|
|
2390
|
+
const handleSort = useCallback18(
|
|
2391
|
+
(column, extendSort = false, sortType) => {
|
|
2392
|
+
if (dataSource) {
|
|
2393
|
+
dataSource.sort = applySort(
|
|
2394
|
+
dataSource.sort,
|
|
2395
|
+
column,
|
|
2396
|
+
extendSort,
|
|
2397
|
+
sortType
|
|
2398
|
+
);
|
|
2399
|
+
}
|
|
2400
|
+
},
|
|
2401
|
+
[dataSource]
|
|
2402
|
+
);
|
|
2403
|
+
const handleColumnResize = useCallback18(
|
|
2404
|
+
(phase, columnName, width) => {
|
|
2405
|
+
const column = columns.find((column2) => column2.name === columnName);
|
|
2406
|
+
if (column) {
|
|
2407
|
+
if (phase === "end") {
|
|
2408
|
+
expectConfigChangeRef.current = true;
|
|
2409
|
+
}
|
|
2410
|
+
dispatchColumnAction({
|
|
2411
|
+
type: "resizeColumn",
|
|
2412
|
+
phase,
|
|
2413
|
+
column,
|
|
2414
|
+
width
|
|
2415
|
+
});
|
|
2416
|
+
} else {
|
|
2417
|
+
throw Error(
|
|
2418
|
+
`useDataTable.handleColumnResize, column ${columnName} not found`
|
|
2419
|
+
);
|
|
2420
|
+
}
|
|
2421
|
+
},
|
|
2422
|
+
[columns, dispatchColumnAction]
|
|
2423
|
+
);
|
|
2424
|
+
const handleToggleGroup = useCallback18(
|
|
2425
|
+
(row, column) => {
|
|
2426
|
+
const isJson = isJsonGroup2(column, row);
|
|
2427
|
+
const key = row[KEY2];
|
|
2428
|
+
if (row[IS_EXPANDED2]) {
|
|
2429
|
+
dataSource.closeTreeNode(key, true);
|
|
2430
|
+
if (isJson) {
|
|
2431
|
+
const idx = columns.indexOf(column);
|
|
2432
|
+
const rows = dataSource.getRowsAtDepth(idx + 1);
|
|
2433
|
+
if (!rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
|
|
2434
|
+
dispatchColumnAction({
|
|
2435
|
+
type: "hideColumns",
|
|
2436
|
+
columns: columns.slice(idx + 2)
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
} else {
|
|
2441
|
+
dataSource.openTreeNode(key);
|
|
2442
|
+
if (isJson) {
|
|
2443
|
+
const childRows = dataSource.getChildRows(key);
|
|
2444
|
+
const idx = columns.indexOf(column) + 1;
|
|
2445
|
+
const columnsToShow = [columns[idx]];
|
|
2446
|
+
if (childRows.some((row2) => row2[IS_LEAF2])) {
|
|
2447
|
+
columnsToShow.push(columns[idx + 1]);
|
|
2448
|
+
}
|
|
2449
|
+
if (columnsToShow.some((col) => col.hidden)) {
|
|
2450
|
+
dispatchColumnAction({
|
|
2451
|
+
type: "showColumns",
|
|
2452
|
+
columns: columnsToShow
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
},
|
|
2458
|
+
[columns, dataSource, dispatchColumnAction]
|
|
2459
|
+
);
|
|
2460
|
+
const {
|
|
2461
|
+
onVerticalScroll,
|
|
2462
|
+
onHorizontalScroll,
|
|
2463
|
+
columnsWithinViewport,
|
|
2464
|
+
virtualColSpan
|
|
2465
|
+
} = useVirtualViewport({
|
|
2466
|
+
columns,
|
|
2467
|
+
rowHeight,
|
|
2468
|
+
setRange,
|
|
2469
|
+
viewportMeasurements
|
|
2470
|
+
});
|
|
2471
|
+
const { requestScroll, ...scrollProps } = useTableScroll({
|
|
2472
|
+
onHorizontalScroll,
|
|
2473
|
+
// onRangeChange: setRange,
|
|
2474
|
+
onVerticalScroll,
|
|
2475
|
+
viewport: viewportMeasurements,
|
|
2476
|
+
viewportHeight: ((_b = (_a = containerMeasurements.innerSize) == null ? void 0 : _a.height) != null ? _b : 0) - headerHeight
|
|
2477
|
+
});
|
|
2478
|
+
const containerProps = useKeyboardNavigation({
|
|
2479
|
+
columnCount: columns.length,
|
|
2480
|
+
containerRef: containerMeasurements.containerRef,
|
|
2481
|
+
data,
|
|
2482
|
+
requestScroll,
|
|
2483
|
+
rowCount: dataSource == null ? void 0 : dataSource.size,
|
|
2484
|
+
viewportRange: range
|
|
2485
|
+
});
|
|
2486
|
+
const handleRemoveColumnFromGroupBy = useCallback18(
|
|
2487
|
+
(column) => {
|
|
2488
|
+
if (dataSource && dataSource.groupBy.includes(column.name)) {
|
|
2489
|
+
dataSource.groupBy = dataSource.groupBy.filter(
|
|
2490
|
+
(columnName) => columnName !== column.name
|
|
2491
|
+
);
|
|
2492
|
+
}
|
|
2493
|
+
},
|
|
2494
|
+
[dataSource]
|
|
2495
|
+
);
|
|
2496
|
+
const handleDropColumn = useCallback18(
|
|
2497
|
+
(fromIndex, toIndex) => {
|
|
2498
|
+
const column = dataSource.columns[fromIndex];
|
|
2499
|
+
const columns2 = moveItem2(dataSource.columns, column, toIndex);
|
|
2500
|
+
if (columns2 !== dataSource.columns) {
|
|
2501
|
+
dataSource.columns = columns2;
|
|
2502
|
+
dispatchColumnAction({ type: "tableConfig", columns: columns2 });
|
|
2503
|
+
}
|
|
2504
|
+
},
|
|
2505
|
+
[dataSource, dispatchColumnAction]
|
|
2506
|
+
);
|
|
2507
|
+
const draggableHook = useDraggableColumn({
|
|
2508
|
+
onDrop: handleDropColumn,
|
|
2509
|
+
tableContainerRef: scrollProps.tableContainerRef,
|
|
2510
|
+
tableLayout
|
|
2511
|
+
});
|
|
2512
|
+
useEffect5(() => {
|
|
2513
|
+
if (dataSourceRef.current) {
|
|
2514
|
+
expectConfigChangeRef.current = true;
|
|
2515
|
+
dispatchColumnAction({
|
|
2516
|
+
type: "init",
|
|
2517
|
+
tableConfig: config,
|
|
2518
|
+
dataSourceConfig: dataSourceRef.current.config
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2521
|
+
}, [config, dispatchColumnAction]);
|
|
2522
|
+
useEffect5(() => {
|
|
2523
|
+
dataSource.on("config", (config2, confirmed) => {
|
|
2524
|
+
expectConfigChangeRef.current = true;
|
|
2525
|
+
dispatchColumnAction({
|
|
2526
|
+
type: "tableConfig",
|
|
2527
|
+
...config2,
|
|
2528
|
+
confirmed
|
|
2529
|
+
});
|
|
2530
|
+
});
|
|
2531
|
+
}, [dataSource, dispatchColumnAction]);
|
|
2532
|
+
useMemo6(() => {
|
|
2533
|
+
if (expectConfigChangeRef.current) {
|
|
2534
|
+
onConfigChange == null ? void 0 : onConfigChange({
|
|
2535
|
+
...config,
|
|
2536
|
+
columns
|
|
2537
|
+
});
|
|
2538
|
+
expectConfigChangeRef.current = false;
|
|
2539
|
+
}
|
|
2540
|
+
}, [columns, config, onConfigChange]);
|
|
2541
|
+
const showContextMenu = usePopupContextMenu();
|
|
2542
|
+
const onContextMenu = useCallback18(
|
|
2543
|
+
(evt) => {
|
|
2544
|
+
var _a2;
|
|
2545
|
+
const { current: currentData } = dataRef;
|
|
2546
|
+
const { current: currentDataSource } = dataSourceRef;
|
|
2547
|
+
const target = evt.target;
|
|
2548
|
+
const cellEl = target == null ? void 0 : target.closest("td");
|
|
2549
|
+
const rowEl = target == null ? void 0 : target.closest("tr");
|
|
2550
|
+
if (cellEl && rowEl && currentData && currentDataSource) {
|
|
2551
|
+
const { columns: columns2, selectedRowsCount } = currentDataSource;
|
|
2552
|
+
const columnMap = buildColumnMap(columns2);
|
|
2553
|
+
const rowIndex = parseInt((_a2 = rowEl.ariaRowIndex) != null ? _a2 : "-1");
|
|
2554
|
+
const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
|
|
2555
|
+
const row = currentData.find(([idx]) => idx === rowIndex);
|
|
2556
|
+
const columnName = columns2[cellIndex];
|
|
2557
|
+
showContextMenu(evt, "grid", {
|
|
2558
|
+
columnMap,
|
|
2559
|
+
columnName,
|
|
2560
|
+
row,
|
|
2561
|
+
selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
|
|
2562
|
+
viewport: dataSource == null ? void 0 : dataSource.viewport
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
},
|
|
2566
|
+
[dataSource == null ? void 0 : dataSource.viewport, getSelectedRows, showContextMenu]
|
|
2567
|
+
);
|
|
2568
|
+
return {
|
|
2569
|
+
containerMeasurements,
|
|
2570
|
+
containerProps,
|
|
2571
|
+
columns,
|
|
2572
|
+
columnsWithinViewport,
|
|
2573
|
+
data,
|
|
2574
|
+
dispatchColumnAction,
|
|
2575
|
+
handleContextMenuAction,
|
|
2576
|
+
headings,
|
|
2577
|
+
onColumnResize: handleColumnResize,
|
|
2578
|
+
onContextMenu,
|
|
2579
|
+
onRemoveColumnFromGroupBy: handleRemoveColumnFromGroupBy,
|
|
2580
|
+
onRowClick: handleRowClick,
|
|
2581
|
+
onSort: handleSort,
|
|
2582
|
+
onToggleGroup: handleToggleGroup,
|
|
2583
|
+
virtualColSpan,
|
|
2584
|
+
scrollProps,
|
|
2585
|
+
rowCount,
|
|
2586
|
+
viewportMeasurements,
|
|
2587
|
+
...draggableHook
|
|
2588
|
+
};
|
|
2589
|
+
};
|
|
2590
|
+
|
|
2591
|
+
// src/Table.tsx
|
|
2592
|
+
import cx8 from "classnames";
|
|
2593
|
+
import { isDataLoading } from "@vuu-ui/vuu-utils";
|
|
2594
|
+
import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2595
|
+
var classBase7 = "vuuTable";
|
|
2596
|
+
var Table = ({
|
|
2597
|
+
allowConfigEditing: showSettings = false,
|
|
2598
|
+
className: classNameProp,
|
|
2599
|
+
config,
|
|
2600
|
+
dataSource,
|
|
2601
|
+
headerHeight = 25,
|
|
2602
|
+
height,
|
|
2603
|
+
id: idProp,
|
|
2604
|
+
onConfigChange,
|
|
2605
|
+
onFeatureEnabled,
|
|
2606
|
+
onFeatureInvocation,
|
|
2607
|
+
onSelectionChange,
|
|
2608
|
+
onShowConfigEditor: onShowSettings,
|
|
2609
|
+
renderBufferSize = 0,
|
|
2610
|
+
rowHeight = 20,
|
|
2611
|
+
selectionModel = "extended",
|
|
2612
|
+
style: styleProp,
|
|
2613
|
+
tableLayout: tableLayoutProp = "row",
|
|
2614
|
+
width,
|
|
2615
|
+
zebraStripes = false,
|
|
2616
|
+
...props
|
|
2617
|
+
}) => {
|
|
2618
|
+
const id = useIdMemo(idProp);
|
|
2619
|
+
const {
|
|
2620
|
+
containerMeasurements: { containerRef, innerSize, outerSize },
|
|
2621
|
+
containerProps,
|
|
2622
|
+
dispatchColumnAction,
|
|
2623
|
+
draggable,
|
|
2624
|
+
draggedItemIndex,
|
|
2625
|
+
handleContextMenuAction,
|
|
2626
|
+
scrollProps,
|
|
2627
|
+
tableLayout,
|
|
2628
|
+
viewportMeasurements,
|
|
2629
|
+
...tableProps
|
|
2630
|
+
} = useDataTable({
|
|
2631
|
+
config,
|
|
2632
|
+
dataSource,
|
|
2633
|
+
renderBufferSize,
|
|
2634
|
+
headerHeight,
|
|
2635
|
+
height,
|
|
2636
|
+
onConfigChange,
|
|
2637
|
+
onFeatureEnabled,
|
|
2638
|
+
onFeatureInvocation,
|
|
2639
|
+
onSelectionChange,
|
|
2640
|
+
rowHeight,
|
|
2641
|
+
selectionModel,
|
|
2642
|
+
tableLayout: tableLayoutProp,
|
|
2643
|
+
width
|
|
2644
|
+
});
|
|
2645
|
+
const style = {
|
|
2646
|
+
...outerSize,
|
|
2647
|
+
"--content-height": `${viewportMeasurements.scrollContentHeight}px`,
|
|
2648
|
+
"--content-width": `${viewportMeasurements.scrollContentWidth}px`,
|
|
2649
|
+
"--filler-height": `${viewportMeasurements.fillerHeight}px`,
|
|
2650
|
+
"--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
|
|
2651
|
+
"--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
|
|
2652
|
+
"--header-height": `${headerHeight}px`,
|
|
2653
|
+
"--row-height": `${rowHeight}px`,
|
|
2654
|
+
"--scrollbar-size": `${viewportMeasurements.scrollbarSize}px`,
|
|
2655
|
+
"--table-height": `${innerSize == null ? void 0 : innerSize.height}px`,
|
|
2656
|
+
"--table-width": `${innerSize == null ? void 0 : innerSize.width}px`,
|
|
2657
|
+
"--total-header-height": `${viewportMeasurements == null ? void 0 : viewportMeasurements.totalHeaderHeight}px`
|
|
2658
|
+
};
|
|
2659
|
+
const scrollbarContainerStyle = {
|
|
2660
|
+
left: viewportMeasurements.pinnedWidthLeft - 1,
|
|
2661
|
+
// The -1 is to align the top border, might cause innaccuracy
|
|
2662
|
+
// It is compensated by a hardcoded adjustment in css
|
|
2663
|
+
// top: measurements.top - 1 + headerHeight,
|
|
2664
|
+
top: (viewportMeasurements == null ? void 0 : viewportMeasurements.totalHeaderHeight) - 1
|
|
2665
|
+
};
|
|
2666
|
+
const Table2 = tableLayout === "column" ? ColumnBasedTable : RowBasedTable;
|
|
2667
|
+
const className = cx8(classBase7, classNameProp, {
|
|
2668
|
+
[`${classBase7}-zebra`]: zebraStripes,
|
|
2669
|
+
[`${classBase7}-loading`]: isDataLoading(tableProps.columns)
|
|
2670
|
+
});
|
|
2671
|
+
return /* @__PURE__ */ jsx11(
|
|
2672
|
+
ContextMenuProvider,
|
|
2673
|
+
{
|
|
2674
|
+
menuActionHandler: handleContextMenuAction,
|
|
2675
|
+
menuBuilder: buildContextMenuDescriptors(dataSource),
|
|
2676
|
+
children: /* @__PURE__ */ jsxs8(
|
|
2677
|
+
"div",
|
|
2678
|
+
{
|
|
2679
|
+
...containerProps,
|
|
2680
|
+
className,
|
|
2681
|
+
id,
|
|
2682
|
+
ref: containerRef,
|
|
2683
|
+
style,
|
|
2684
|
+
tabIndex: -1,
|
|
2685
|
+
children: [
|
|
2686
|
+
innerSize ? /* @__PURE__ */ jsx11(
|
|
2687
|
+
"div",
|
|
2688
|
+
{
|
|
2689
|
+
className: `${classBase7}-scrollbarContainer`,
|
|
2690
|
+
onScroll: scrollProps.onScrollbarContainerScroll,
|
|
2691
|
+
ref: scrollProps.scrollbarContainerRef,
|
|
2692
|
+
style: scrollbarContainerStyle,
|
|
2693
|
+
children: /* @__PURE__ */ jsx11("div", { className: `${classBase7}-scrollContent` })
|
|
2694
|
+
}
|
|
2695
|
+
) : null,
|
|
2696
|
+
innerSize ? /* @__PURE__ */ jsxs8(
|
|
2697
|
+
"div",
|
|
2698
|
+
{
|
|
2699
|
+
className: `${classBase7}-contentContainer`,
|
|
2700
|
+
onScroll: scrollProps.onContentContainerScroll,
|
|
2701
|
+
ref: scrollProps.contentContainerRef,
|
|
2702
|
+
...props,
|
|
2703
|
+
children: [
|
|
2704
|
+
/* @__PURE__ */ jsx11("div", { className: `${classBase7}-scrollContent` }),
|
|
2705
|
+
/* @__PURE__ */ jsx11(
|
|
2706
|
+
"div",
|
|
2707
|
+
{
|
|
2708
|
+
className: `${classBase7}-tableContainer`,
|
|
2709
|
+
onScroll: scrollProps.onTableContainerScroll,
|
|
2710
|
+
ref: scrollProps.tableContainerRef,
|
|
2711
|
+
children: /* @__PURE__ */ jsx11(
|
|
2712
|
+
Table2,
|
|
2713
|
+
{
|
|
2714
|
+
...tableProps,
|
|
2715
|
+
headerHeight,
|
|
2716
|
+
rowHeight
|
|
2717
|
+
}
|
|
2718
|
+
)
|
|
2719
|
+
}
|
|
2720
|
+
),
|
|
2721
|
+
draggable
|
|
2722
|
+
]
|
|
2723
|
+
}
|
|
2724
|
+
) : null,
|
|
2725
|
+
showSettings && innerSize ? /* @__PURE__ */ jsx11(
|
|
2726
|
+
Button,
|
|
2727
|
+
{
|
|
2728
|
+
className: `${classBase7}-settings`,
|
|
2729
|
+
"data-icon": "settings",
|
|
2730
|
+
onClick: onShowSettings,
|
|
2731
|
+
variant: "secondary"
|
|
2732
|
+
}
|
|
2733
|
+
) : null
|
|
2734
|
+
]
|
|
2735
|
+
}
|
|
2736
|
+
)
|
|
2737
|
+
}
|
|
2738
|
+
);
|
|
2739
|
+
};
|
|
2740
|
+
|
|
2741
|
+
// src/cell-renderers/json-cell/JsonCell.tsx
|
|
2742
|
+
import cx9 from "classnames";
|
|
2743
|
+
import {
|
|
2744
|
+
isJsonAttribute,
|
|
2745
|
+
metadataKeys as metadataKeys10,
|
|
2746
|
+
registerComponent
|
|
2747
|
+
} from "@vuu-ui/vuu-utils";
|
|
2748
|
+
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2749
|
+
var classBase8 = "vuuJsonCell";
|
|
2750
|
+
var { IS_EXPANDED: IS_EXPANDED3, KEY: KEY3 } = metadataKeys10;
|
|
2751
|
+
var localKey = (key) => {
|
|
2752
|
+
const pos = key.lastIndexOf("|");
|
|
2753
|
+
if (pos === -1) {
|
|
2754
|
+
return "";
|
|
2755
|
+
} else {
|
|
2756
|
+
return key.slice(pos + 1);
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
var JsonCell = ({ column, row }) => {
|
|
2760
|
+
const {
|
|
2761
|
+
key: columnKey
|
|
2762
|
+
/*, type, valueFormatter */
|
|
2763
|
+
} = column;
|
|
2764
|
+
let value = row[columnKey];
|
|
2765
|
+
let isToggle = false;
|
|
2766
|
+
if (isJsonAttribute(value)) {
|
|
2767
|
+
value = value.slice(0, -1);
|
|
2768
|
+
isToggle = true;
|
|
2769
|
+
}
|
|
2770
|
+
const rowKey = localKey(row[KEY3]);
|
|
2771
|
+
const className = cx9({
|
|
2772
|
+
[`${classBase8}-name`]: rowKey === value,
|
|
2773
|
+
[`${classBase8}-value`]: rowKey !== value,
|
|
2774
|
+
[`${classBase8}-group`]: isToggle
|
|
2775
|
+
});
|
|
2776
|
+
if (isToggle) {
|
|
2777
|
+
const toggleIcon = row[IS_EXPANDED3] ? "minus-box" : "plus-box";
|
|
2778
|
+
return /* @__PURE__ */ jsxs9("span", { className, children: [
|
|
2779
|
+
/* @__PURE__ */ jsx12("span", { className: `${classBase8}-value`, children: value }),
|
|
2780
|
+
/* @__PURE__ */ jsx12("span", { className: `${classBase8}-toggle`, "data-icon": toggleIcon })
|
|
2781
|
+
] });
|
|
2782
|
+
} else if (value) {
|
|
2783
|
+
return /* @__PURE__ */ jsx12("span", { className, children: value });
|
|
2784
|
+
} else {
|
|
2785
|
+
return null;
|
|
2786
|
+
}
|
|
2787
|
+
};
|
|
2788
|
+
registerComponent("json", JsonCell, "cell-renderer", {});
|
|
2789
|
+
export {
|
|
2790
|
+
Table,
|
|
2791
|
+
useMeasuredContainer
|
|
2792
|
+
};
|
|
2
2793
|
//# sourceMappingURL=index.js.map
|